Skip to content

Commit

Permalink
fix: useAsync dependency arrays (#2291)
Browse files Browse the repository at this point in the history
* fix: `useAsync` dependency arrays

* fix: lint

* fix: missing dependency
  • Loading branch information
iamacook authored Aug 3, 2023
1 parent 1db9568 commit e99b511
Show file tree
Hide file tree
Showing 17 changed files with 27 additions and 7 deletions.
8 changes: 7 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
1 change: 1 addition & 0 deletions src/components/transactions/SingleTx/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
1 change: 1 addition & 0 deletions src/components/transactions/TxDetails/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
1 change: 1 addition & 0 deletions src/components/tx/ApprovalEditor/hooks/useApprovalInfos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
1 change: 1 addition & 0 deletions src/components/tx/SignOrExecuteForm/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
3 changes: 2 additions & 1 deletion src/components/tx/security/redefine/useRedefine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down
2 changes: 1 addition & 1 deletion src/components/tx/security/useRecipientModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
1 change: 1 addition & 0 deletions src/hooks/loadables/useLoadBalances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const useLoadBalances = (): AsyncResult<SafeBalanceResponse> => {
trusted: isTrustedTokenList,
})
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[safeAddress, chainId, currency, isTrustedTokenList, pollCount],
false, // don't clear data between polls
)
Expand Down
1 change: 1 addition & 0 deletions src/hooks/loadables/useLoadSafeInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const useLoadSafeInfo = (): AsyncResult<SafeInfo> => {
const [data, error, loading] = useAsync<SafeInfo>(() => {
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
Expand Down
1 change: 1 addition & 0 deletions src/hooks/loadables/useLoadSafeMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const useLoadSafeMessages = (): AsyncResult<SafeMessageListPage> => {
}
return getSafeMessages(safe.chainId, safeAddress)
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[
safeLoaded,
safe.chainId,
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/loadables/useLoadSpendingLimits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ export const useLoadSpendingLimits = (): AsyncResult<SpendingLimitState[]> => {
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) {
Expand Down
1 change: 1 addition & 0 deletions src/hooks/loadables/useLoadTxHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const useLoadTxHistory = (): AsyncResult<TransactionListPage> => {
if (!safeLoaded) return
return getTransactionHistory(chainId, safeAddress)
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[safeLoaded, chainId, safeAddress, txHistoryTag],
false,
)
Expand Down
1 change: 1 addition & 0 deletions src/hooks/loadables/useLoadTxQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const useLoadTxQueue = (): AsyncResult<TransactionListPage> => {
if (!safeLoaded) return
return getTransactionQueue(chainId, safeAddress)
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[safeLoaded, chainId, safeAddress, reloadTag],
false,
)
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/useGasPrice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useIsValidExecution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const useIsValidExecution = (

throw err
}
}, [safeTx, wallet, gasLimit, safe, readOnlyProvider])
}, [safeTx, wallet, gasLimit, safe, readOnlyProvider, isOwner])

return { isValidExecution, executionValidationError, isValidExecutionLoading }
}
Expand Down
2 changes: 2 additions & 0 deletions src/hooks/useRemainingRelays.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}

Expand All @@ -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])
}
2 changes: 1 addition & 1 deletion src/hooks/useWalletCanRelay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const useWalletCanRelay = (tx: SafeTransaction | undefined) => {
logError(Errors._106, err.message)
return false
})
}, [hasEnoughSignatures, wallet])
}, [hasEnoughSignatures, tx, wallet])
}

export default useWalletCanRelay

0 comments on commit e99b511

Please sign in to comment.