Skip to content

Commit

Permalink
fix(partnerConfig): fix removing wanted services
Browse files Browse the repository at this point in the history
  • Loading branch information
aeddaqqa committed Sep 17, 2024
1 parent 6bb2c33 commit 431eed7
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 32 deletions.
1 change: 0 additions & 1 deletion src/helpers/partnerConfigurationContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ export function reducer(state = initialState, action) {

case actionTypes.UPDATE_WANTED_SERVICES: {
const { wantedServices } = action.payload
if (!wantedServices || wantedServices.length < 1) return state
return {
...state,
stepsConfig: state.stepsConfig.map(item =>
Expand Down
54 changes: 30 additions & 24 deletions src/views/partners/ConfigurDistrubitor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,32 +36,36 @@ function ServiceChangesPreview({ added, removed }) {
const gasPrice = (await provider.getFeeData()).gasPrice
let total = 0n

if (added.length > 0) {
const addedServices = added.map(service => service.name)
const gasEst = BigInt(
await accountWriteContract.addWantedServices.estimateGas(addedServices),
)
const adjustedGasEst = (gasEst * 98n) / 100n
const cost = adjustedGasEst * gasPrice
total += cost
setCostDetails(prevDetails => ({
...prevDetails,
addCosts: { services: addedServices, totalCost: cost },
}))
}

if (removed.length > 0) {
const removedServices = removed.map(service => service.name)
const gasEst = BigInt(
await accountWriteContract.removeWantedServices.estimateGas(removedServices),
)
const adjustedGasEst = (gasEst * 98n) / 100n
const cost = adjustedGasEst * gasPrice
total += cost
setCostDetails(prevDetails => ({
...prevDetails,
removeCosts: { services: removedServices, totalCost: cost },
}))
if (removedServices.length > 0) {
const gasEst = BigInt(
await accountWriteContract.removeWantedServices.estimateGas(removedServices),
)
const adjustedGasEst = (gasEst * 98n) / 100n
const cost = adjustedGasEst * gasPrice
total += cost
setCostDetails(prevDetails => ({
...prevDetails,
removeCosts: { services: removedServices, totalCost: cost },
}))
}
}

if (added.length > 0) {
const addedServices = added.map(service => service.name)
if (addedServices.length > 0) {
const gasEst = BigInt(
await accountWriteContract.addWantedServices.estimateGas(addedServices),
)
const adjustedGasEst = (gasEst * 98n) / 100n
const cost = adjustedGasEst * gasPrice
total += cost
setCostDetails(prevDetails => ({
...prevDetails,
addCosts: { services: addedServices, totalCost: cost },
}))
}
}
setTotalCost(total)
}
Expand Down Expand Up @@ -204,6 +208,8 @@ const ConfigurDistrubitor = () => {
type: actionTypes.UPDATE_WANTED_SERVICES,
payload: { wantedServices: res },
})
setAdded([])
setRemoved([])
setLoading(false)
setEditing(false)
}
Expand Down
6 changes: 4 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
{
"compilerOptions": {
"target": "ES2020",
"target": "ES2018",
"lib": ["ES2018", "DOM"],
"jsx": "react",
"resolveJsonModule": true,
"moduleResolution": "node",
"esModuleInterop": true,
"skipLibCheck": true,
"typeRoots": ["node_modules/@types"],
"types": ["cypress", "node"],
"paths": {
"ethers": ["./node_modules/ethers"]
}
},
"include": ["src"],
"include": ["src", "cypress"],
"ts-node": {
"compilerOptions": {
"jsx": "react",
Expand Down
5 changes: 0 additions & 5 deletions webpack.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ module.exports = merge(common, {
singleton: true,
requiredVersion: deps['react-dom'],
},
ethers: {
singleton: true,
eager: true,
requiredVersion: deps['ethers'],
},
},
}),
],
Expand Down

0 comments on commit 431eed7

Please sign in to comment.