From e99b51135b50d690906e359c75f5e1fb31b64496 Mon Sep 17 00:00:00 2001 From: Aaron Cook Date: Thu, 3 Aug 2023 10:08:56 +0200 Subject: [PATCH] fix: `useAsync` dependency arrays (#2291) * fix: `useAsync` dependency arrays * fix: lint * fix: missing dependency --- .eslintrc.json | 8 +++++++- src/components/transactions/SingleTx/index.tsx | 1 + src/components/transactions/TxDetails/index.tsx | 1 + .../tx/ApprovalEditor/hooks/useApprovalInfos.ts | 1 + src/components/tx/SignOrExecuteForm/hooks.ts | 1 + src/components/tx/security/redefine/useRedefine.ts | 3 ++- src/components/tx/security/useRecipientModule.ts | 2 +- src/hooks/loadables/useLoadBalances.ts | 1 + src/hooks/loadables/useLoadSafeInfo.ts | 1 + src/hooks/loadables/useLoadSafeMessages.ts | 1 + src/hooks/loadables/useLoadSpendingLimits.ts | 3 ++- src/hooks/loadables/useLoadTxHistory.ts | 1 + src/hooks/loadables/useLoadTxQueue.ts | 1 + src/hooks/useGasPrice.ts | 3 ++- src/hooks/useIsValidExecution.ts | 2 +- src/hooks/useRemainingRelays.ts | 2 ++ src/hooks/useWalletCanRelay.ts | 2 +- 17 files changed, 27 insertions(+), 7 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 310d9826c9..6e7d15b87a 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -4,7 +4,13 @@ "@next/next/no-img-element": "off", "unused-imports/no-unused-imports-ts": "error", "@typescript-eslint/consistent-type-imports": "error", - "no-constant-condition": "warn" + "no-constant-condition": "warn", + "react-hooks/exhaustive-deps": [ + "warn", + { + "additionalHooks": "useAsync" + } + ] }, "ignorePatterns": ["node_modules/", ".next/", ".github/"], "plugins": ["unused-imports", "@typescript-eslint"] diff --git a/src/components/transactions/SingleTx/index.tsx b/src/components/transactions/SingleTx/index.tsx index f8e8d7fce4..07f9d33dad 100644 --- a/src/components/transactions/SingleTx/index.tsx +++ b/src/components/transactions/SingleTx/index.tsx @@ -52,6 +52,7 @@ const SingleTx = () => { return details }) }, + // eslint-disable-next-line react-hooks/exhaustive-deps [transactionId, safe.chainId, safe.txQueuedTag, safe.txHistoryTag, safeAddress], false, ) diff --git a/src/components/transactions/TxDetails/index.tsx b/src/components/transactions/TxDetails/index.tsx index 6878bcd1ca..8f57837278 100644 --- a/src/components/transactions/TxDetails/index.tsx +++ b/src/components/transactions/TxDetails/index.tsx @@ -129,6 +129,7 @@ const TxDetails = ({ async () => { return txDetails || getTransactionDetails(chainId, txSummary.id) }, + // eslint-disable-next-line react-hooks/exhaustive-deps [txDetails, chainId, txSummary.id, safe.txQueuedTag], false, ) diff --git a/src/components/tx/ApprovalEditor/hooks/useApprovalInfos.ts b/src/components/tx/ApprovalEditor/hooks/useApprovalInfos.ts index 664c2220ea..20ae67d8ed 100644 --- a/src/components/tx/ApprovalEditor/hooks/useApprovalInfos.ts +++ b/src/components/tx/ApprovalEditor/hooks/useApprovalInfos.ts @@ -52,6 +52,7 @@ export const useApprovalInfos = ( }), ) }, + // eslint-disable-next-line react-hooks/exhaustive-deps [hasApprovalSignatures, balances.items.length], false, // Do not clear data on balance updates ) diff --git a/src/components/tx/SignOrExecuteForm/hooks.ts b/src/components/tx/SignOrExecuteForm/hooks.ts index abf090c1a6..c5b6f7ccbd 100644 --- a/src/components/tx/SignOrExecuteForm/hooks.ts +++ b/src/components/tx/SignOrExecuteForm/hooks.ts @@ -163,6 +163,7 @@ export const useRecommendedNonce = (): number | undefined => { return getRecommendedNonce(safe.chainId, safeAddress) }, + // eslint-disable-next-line react-hooks/exhaustive-deps [safeAddress, safe.chainId, safe.txQueuedTag], // update when tx queue changes false, // keep old recommended nonce while refreshing to avoid skeleton ) diff --git a/src/components/tx/security/redefine/useRedefine.ts b/src/components/tx/security/redefine/useRedefine.ts index 96a7621a7e..7ed4b7d39a 100644 --- a/src/components/tx/security/redefine/useRedefine.ts +++ b/src/components/tx/security/redefine/useRedefine.ts @@ -94,7 +94,8 @@ export const useRedefine = ( threshold: safe.threshold, }) }, - [safe.chainId, safe.threshold, safeAddress, safeTransaction, wallet?.address, retryCounter], + // eslint-disable-next-line react-hooks/exhaustive-deps + [safe.chainId, safe.threshold, safeAddress, safeTransaction, wallet?.address, retryCounter, isFeatureEnabled], false, ) diff --git a/src/components/tx/security/useRecipientModule.ts b/src/components/tx/security/useRecipientModule.ts index 6a0804034b..dbfd50d26c 100644 --- a/src/components/tx/security/useRecipientModule.ts +++ b/src/components/tx/security/useRecipientModule.ts @@ -35,5 +35,5 @@ export const useRecipientModule = (safeTransaction: SafeTransaction | undefined) knownAddresses, provider: web3ReadOnly, }) - }, [safeTransaction, web3ReadOnly, safeLoaded, safe.chainId, knownAddresses, web3ReadOnly]) + }, [safeTransaction, web3ReadOnly, safeLoaded, safe.chainId, knownAddresses]) } diff --git a/src/hooks/loadables/useLoadBalances.ts b/src/hooks/loadables/useLoadBalances.ts index 1a627c351b..a48c455146 100644 --- a/src/hooks/loadables/useLoadBalances.ts +++ b/src/hooks/loadables/useLoadBalances.ts @@ -38,6 +38,7 @@ export const useLoadBalances = (): AsyncResult => { trusted: isTrustedTokenList, }) }, + // eslint-disable-next-line react-hooks/exhaustive-deps [safeAddress, chainId, currency, isTrustedTokenList, pollCount], false, // don't clear data between polls ) diff --git a/src/hooks/loadables/useLoadSafeInfo.ts b/src/hooks/loadables/useLoadSafeInfo.ts index 8a7d7348a0..4a694444b1 100644 --- a/src/hooks/loadables/useLoadSafeInfo.ts +++ b/src/hooks/loadables/useLoadSafeInfo.ts @@ -18,6 +18,7 @@ export const useLoadSafeInfo = (): AsyncResult => { const [data, error, loading] = useAsync(() => { if (!chainId || !address) return return getSafeInfo(chainId, address) + // eslint-disable-next-line react-hooks/exhaustive-deps }, [chainId, address, pollCount]) // Reset the counter when safe address/chainId changes diff --git a/src/hooks/loadables/useLoadSafeMessages.ts b/src/hooks/loadables/useLoadSafeMessages.ts index d7460a5ebd..767bf5a0aa 100644 --- a/src/hooks/loadables/useLoadSafeMessages.ts +++ b/src/hooks/loadables/useLoadSafeMessages.ts @@ -27,6 +27,7 @@ export const useLoadSafeMessages = (): AsyncResult => { } return getSafeMessages(safe.chainId, safeAddress) }, + // eslint-disable-next-line react-hooks/exhaustive-deps [ safeLoaded, safe.chainId, diff --git a/src/hooks/loadables/useLoadSpendingLimits.ts b/src/hooks/loadables/useLoadSpendingLimits.ts index 2727626d72..715cc21432 100644 --- a/src/hooks/loadables/useLoadSpendingLimits.ts +++ b/src/hooks/loadables/useLoadSpendingLimits.ts @@ -105,7 +105,8 @@ export const useLoadSpendingLimits = (): AsyncResult => { if (!provider || !safeLoaded || !safe.modules || !tokenInfoFromBalances) return return getSpendingLimits(provider, safe.modules, safeAddress, chainId, tokenInfoFromBalances) - }, [provider, safeLoaded, safe.modules?.length, safeAddress, chainId, safe.txHistoryTag, tokenInfoFromBalances]) + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [provider, safeLoaded, safe.modules, tokenInfoFromBalances, safeAddress, chainId, safe.txHistoryTag]) useEffect(() => { if (error) { diff --git a/src/hooks/loadables/useLoadTxHistory.ts b/src/hooks/loadables/useLoadTxHistory.ts index 90cb9dfc60..2d842c1f21 100644 --- a/src/hooks/loadables/useLoadTxHistory.ts +++ b/src/hooks/loadables/useLoadTxHistory.ts @@ -14,6 +14,7 @@ export const useLoadTxHistory = (): AsyncResult => { if (!safeLoaded) return return getTransactionHistory(chainId, safeAddress) }, + // eslint-disable-next-line react-hooks/exhaustive-deps [safeLoaded, chainId, safeAddress, txHistoryTag], false, ) diff --git a/src/hooks/loadables/useLoadTxQueue.ts b/src/hooks/loadables/useLoadTxQueue.ts index 1b06ebd265..8cbaeacf66 100644 --- a/src/hooks/loadables/useLoadTxQueue.ts +++ b/src/hooks/loadables/useLoadTxQueue.ts @@ -18,6 +18,7 @@ export const useLoadTxQueue = (): AsyncResult => { if (!safeLoaded) return return getTransactionQueue(chainId, safeAddress) }, + // eslint-disable-next-line react-hooks/exhaustive-deps [safeLoaded, chainId, safeAddress, reloadTag], false, ) diff --git a/src/hooks/useGasPrice.ts b/src/hooks/useGasPrice.ts index 4a7c3b91d1..0d5b3a4663 100644 --- a/src/hooks/useGasPrice.ts +++ b/src/hooks/useGasPrice.ts @@ -82,7 +82,8 @@ const useGasPrice = (): AsyncResult<{ maxPriorityFeePerGas: maxPrioFee, } }, - [gasPriceConfigs, provider, counter], + // eslint-disable-next-line react-hooks/exhaustive-deps + [gasPriceConfigs, provider, counter, isEIP1559], false, ) diff --git a/src/hooks/useIsValidExecution.ts b/src/hooks/useIsValidExecution.ts index c27bef3cc0..ab21620430 100644 --- a/src/hooks/useIsValidExecution.ts +++ b/src/hooks/useIsValidExecution.ts @@ -101,7 +101,7 @@ const useIsValidExecution = ( throw err } - }, [safeTx, wallet, gasLimit, safe, readOnlyProvider]) + }, [safeTx, wallet, gasLimit, safe, readOnlyProvider, isOwner]) return { isValidExecution, executionValidationError, isValidExecutionLoading } } diff --git a/src/hooks/useRemainingRelays.ts b/src/hooks/useRemainingRelays.ts index 27a5288502..7c301f82ef 100644 --- a/src/hooks/useRemainingRelays.ts +++ b/src/hooks/useRemainingRelays.ts @@ -14,6 +14,7 @@ export const useRelaysBySafe = () => { if (!safeAddress || !chain || !hasFeature(chain, FEATURES.RELAYING)) return return getRelays(chain.chainId, safeAddress) + // eslint-disable-next-line react-hooks/exhaustive-deps }, [chain, safeAddress, safe.txHistoryTag]) } @@ -32,5 +33,6 @@ export const useLeastRemainingRelays = (ownerAddresses: string[]) => { .catch(() => { return { remaining: 0, limit: MAX_HOUR_RELAYS } }) + // eslint-disable-next-line react-hooks/exhaustive-deps }, [chain, ownerAddresses, safe.txHistoryTag]) } diff --git a/src/hooks/useWalletCanRelay.ts b/src/hooks/useWalletCanRelay.ts index 9463e4e7a1..e7261e0226 100644 --- a/src/hooks/useWalletCanRelay.ts +++ b/src/hooks/useWalletCanRelay.ts @@ -23,7 +23,7 @@ const useWalletCanRelay = (tx: SafeTransaction | undefined) => { logError(Errors._106, err.message) return false }) - }, [hasEnoughSignatures, wallet]) + }, [hasEnoughSignatures, tx, wallet]) } export default useWalletCanRelay