From 431eed774c1c633348e4a642ef83a040e23c6b3c Mon Sep 17 00:00:00 2001 From: aeddaqqa Date: Tue, 17 Sep 2024 10:50:40 +0100 Subject: [PATCH] fix(partnerConfig): fix removing wanted services --- src/helpers/partnerConfigurationContext.tsx | 1 - src/views/partners/ConfigurDistrubitor.tsx | 54 ++++++++++++--------- tsconfig.json | 6 ++- webpack.dev.js | 5 -- 4 files changed, 34 insertions(+), 32 deletions(-) diff --git a/src/helpers/partnerConfigurationContext.tsx b/src/helpers/partnerConfigurationContext.tsx index 8a1bfbd2..53c7faf6 100644 --- a/src/helpers/partnerConfigurationContext.tsx +++ b/src/helpers/partnerConfigurationContext.tsx @@ -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 => diff --git a/src/views/partners/ConfigurDistrubitor.tsx b/src/views/partners/ConfigurDistrubitor.tsx index e0f622bb..81c08005 100644 --- a/src/views/partners/ConfigurDistrubitor.tsx +++ b/src/views/partners/ConfigurDistrubitor.tsx @@ -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) } @@ -204,6 +208,8 @@ const ConfigurDistrubitor = () => { type: actionTypes.UPDATE_WANTED_SERVICES, payload: { wantedServices: res }, }) + setAdded([]) + setRemoved([]) setLoading(false) setEditing(false) } diff --git a/tsconfig.json b/tsconfig.json index c70fc070..219d46f1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -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", diff --git a/webpack.dev.js b/webpack.dev.js index f655a06e..8384ced6 100644 --- a/webpack.dev.js +++ b/webpack.dev.js @@ -36,11 +36,6 @@ module.exports = merge(common, { singleton: true, requiredVersion: deps['react-dom'], }, - ethers: { - singleton: true, - eager: true, - requiredVersion: deps['ethers'], - }, }, }), ],