Context
Follow-up improvements identified during PR #859 review by @tuliomir.
Improvements
1. Remove tokensBalance dependency from unknown token identification
Reference: comment
Currently, tokensBalance is used as a dependency in the unknownTokens memoized computation, but it is not actually needed to identify whether a token is unknown. Decoupling this would avoid unnecessary recomputations when only balances change.
Current code (src/components/ModalTokenImport.js):
const unknownTokens = useMemo(
() => walletUtils.fetchUnknownTokens(allTokens, registeredTokens, tokensBalance, hideZeroBalance),
[allTokens, registeredTokens, tokensBalance, hideZeroBalance]
);
2. Unify unknown tokens fetching to avoid duplicate calls
Reference: comment
Currently, unknownTokens and hasHiddenZeroBalanceTokens each call walletUtils.fetchUnknownTokens separately — once with hideZeroBalance and once without. Instead, we should fetch all unknown tokens once and then filter for zero balance, avoiding the duplicated logic.
Current code:
const unknownTokens = useMemo(
() => walletUtils.fetchUnknownTokens(allTokens, registeredTokens, tokensBalance, hideZeroBalance),
[allTokens, registeredTokens, tokensBalance, hideZeroBalance]
);
const hasHiddenZeroBalanceTokens = useMemo(() => {
if (!hideZeroBalance) return false;
const allUnknown = walletUtils.fetchUnknownTokens(allTokens, registeredTokens, tokensBalance, false);
// ...
});
Suggested approach: Compute all unknown tokens once (without zero-balance filtering), then derive both unknownTokens (filtered) and hasHiddenZeroBalanceTokens from that single result.
Context
Follow-up improvements identified during PR #859 review by @tuliomir.
Improvements
1. Remove
tokensBalancedependency from unknown token identificationReference: comment
Currently,
tokensBalanceis used as a dependency in theunknownTokensmemoized computation, but it is not actually needed to identify whether a token is unknown. Decoupling this would avoid unnecessary recomputations when only balances change.Current code (
src/components/ModalTokenImport.js):2. Unify unknown tokens fetching to avoid duplicate calls
Reference: comment
Currently,
unknownTokensandhasHiddenZeroBalanceTokenseach callwalletUtils.fetchUnknownTokensseparately — once withhideZeroBalanceand once without. Instead, we should fetch all unknown tokens once and then filter for zero balance, avoiding the duplicated logic.Current code:
Suggested approach: Compute all unknown tokens once (without zero-balance filtering), then derive both
unknownTokens(filtered) andhasHiddenZeroBalanceTokensfrom that single result.