From 08953e36c01fcbf969295451239a7ebb4ac866e4 Mon Sep 17 00:00:00 2001 From: Daniel Sanchez Date: Fri, 21 May 2021 09:52:52 +0200 Subject: [PATCH] [Spending Limit] Integration PR (#2308) * Added spending limit reset function and call (#2262) * Added spending limit reset function and call * Fix: don't use DELEGATE_CALL in multisend tx and spending limits * Changed reset spending limit operation parameter from DELEGATE_CALL to CALL * Deleted operation parameter from MultiSendTx * Remove sort for Spent and ResetTime columns (#2295) * Fix spending limit enable check (#2299) * fix spending limit existence check Co-authored-by: juampibermani <30930241+juampibermani@users.noreply.github.com> Co-authored-by: katspaugh Co-authored-by: nicolas Co-authored-by: Fernando --- src/logic/safe/utils/spendingLimits.ts | 13 ++++++++++--- src/logic/safe/utils/upgradeSafe.test.ts | 2 -- src/logic/safe/utils/upgradeSafe.ts | 3 --- .../SpendingLimit/LimitsTable/dataFetcher.ts | 2 ++ .../Settings/SpendingLimit/NewLimitModal/Review.tsx | 8 +++++++- 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/logic/safe/utils/spendingLimits.ts b/src/logic/safe/utils/spendingLimits.ts index 4f8f2bca..969c3877 100644 --- a/src/logic/safe/utils/spendingLimits.ts +++ b/src/logic/safe/utils/spendingLimits.ts @@ -157,7 +157,6 @@ export const enableSpendingLimitModuleMultiSendTx = (safeAddress: string): Multi to: multiSendTx.to, value: Number(multiSendTx.valueInWei), data: multiSendTx.txData as string, - operation: DELEGATE_CALL, } } @@ -168,7 +167,16 @@ export const addSpendingLimitBeneficiaryMultiSendTx = (beneficiary: string): Mul to: SPENDING_LIMIT_MODULE_ADDRESS, value: 0, data: spendingLimitContract.methods.addDelegate(beneficiary).encodeABI(), - operation: DELEGATE_CALL, + } +} + +export const getResetSpendingLimitTx = (beneficiary: string, token: string): MultiSendTx => { + const spendingLimitContract = getSpendingLimitContract() + + return { + to: SPENDING_LIMIT_MODULE_ADDRESS, + value: 0, + data: spendingLimitContract.methods.resetAllowance(beneficiary, token).encodeABI(), } } @@ -210,7 +218,6 @@ export const setSpendingLimitMultiSendTx = (args: SpendingLimitTxParams): MultiS to: tx.to, value: Number(tx.valueInWei), data: tx.txData as string, - operation: DELEGATE_CALL, } } diff --git a/src/logic/safe/utils/upgradeSafe.test.ts b/src/logic/safe/utils/upgradeSafe.test.ts index 91d40db5..de5a0f1f 100644 --- a/src/logic/safe/utils/upgradeSafe.test.ts +++ b/src/logic/safe/utils/upgradeSafe.test.ts @@ -15,13 +15,11 @@ describe('Upgrade a Safe', () => { const updateSafeTxData = safeInstance.methods.changeMasterCopy(SAFE_MASTER_COPY_ADDRESS).encodeABI() const txs = [ { - operation: 0, to: safeAddress, value: 0, data: updateSafeTxData, }, { - operation: 0, to: safeAddress, value: 0, data: fallbackHandlerTxData, diff --git a/src/logic/safe/utils/upgradeSafe.ts b/src/logic/safe/utils/upgradeSafe.ts index 3bbe6336..e92e5b2c 100644 --- a/src/logic/safe/utils/upgradeSafe.ts +++ b/src/logic/safe/utils/upgradeSafe.ts @@ -10,7 +10,6 @@ import { getWeb3 } from 'src/logic/wallets/getWeb3' import { MultiSend } from 'src/types/contracts/MultiSend.d' export interface MultiSendTx { - operation: number to: string value: number data: string @@ -54,13 +53,11 @@ export const getUpgradeSafeTransactionHash = async (safeAddress: string): Promis const updateSafeTxData = safeInstance.methods.changeMasterCopy(SAFE_MASTER_COPY_ADDRESS).encodeABI() const txs = [ { - operation: 0, to: safeAddress, value: 0, data: updateSafeTxData, }, { - operation: 0, to: safeAddress, value: 0, data: fallbackHandlerTxData, diff --git a/src/routes/safe/components/Settings/SpendingLimit/LimitsTable/dataFetcher.ts b/src/routes/safe/components/Settings/SpendingLimit/LimitsTable/dataFetcher.ts index 501fe0bf..11fbbe66 100644 --- a/src/routes/safe/components/Settings/SpendingLimit/LimitsTable/dataFetcher.ts +++ b/src/routes/safe/components/Settings/SpendingLimit/LimitsTable/dataFetcher.ts @@ -55,6 +55,7 @@ export const generateColumns = (): List => { id: SPENDING_LIMIT_TABLE_SPENT_ID, label: 'Spent', order: false, + static: true, } const resetColumn: TableColumn = { @@ -64,6 +65,7 @@ export const generateColumns = (): List => { id: SPENDING_LIMIT_TABLE_RESET_TIME_ID, label: 'Reset Time', order: false, + static: true, } const actionsColumn: TableColumn = { diff --git a/src/routes/safe/components/Settings/SpendingLimit/NewLimitModal/Review.tsx b/src/routes/safe/components/Settings/SpendingLimit/NewLimitModal/Review.tsx index cb440977..573928c4 100644 --- a/src/routes/safe/components/Settings/SpendingLimit/NewLimitModal/Review.tsx +++ b/src/routes/safe/components/Settings/SpendingLimit/NewLimitModal/Review.tsx @@ -11,6 +11,7 @@ import { addSpendingLimitBeneficiaryMultiSendTx, currentMinutes, enableSpendingLimitModuleMultiSendTx, + getResetSpendingLimitTx, setSpendingLimitMultiSendTx, setSpendingLimitTx, spendingLimitMultiSendTx, @@ -80,7 +81,8 @@ const calculateSpendingLimitsTxData = ( resetBaseMin: number } } => { - const isSpendingLimitEnabled = spendingLimits !== null + // enabled if it's an array with at least one element + const isSpendingLimitEnabled = !!spendingLimits?.length const transactions: MultiSendTx[] = [] // is spendingLimit module enabled? -> if not, create the tx to enable it, and encode it @@ -98,6 +100,10 @@ const calculateSpendingLimitsTxData = ( transactions.push(addSpendingLimitBeneficiaryMultiSendTx(values.beneficiary)) } + if (existentSpendingLimit && existentSpendingLimit.spent !== '0') { + transactions.push(getResetSpendingLimitTx(existentSpendingLimit.delegate, txToken.address)) + } + // prepare the setAllowance tx const startTime = currentMinutes() - 30 const spendingLimitArgs = {