Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Token list should respect hideZeroBalance setting #29058

Merged
merged 18 commits into from
Dec 11, 2024
Merged
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 33 additions & 13 deletions ui/components/app/assets/token-list/token-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
getCurrencyRates,
getCurrentNetwork,
getIsTestnet,
getIsTokenNetworkFilterEqualCurrentNetwork,
getMarketData,
getNetworkConfigurationIdByChainId,
getNewTokensImported,
Expand Down Expand Up @@ -86,8 +87,12 @@ export default function TokenList({
const dispatch = useDispatch();
const currentNetwork = useSelector(getCurrentNetwork);
const allNetworks = useSelector(getNetworkConfigurationIdByChainId);
const { tokenSortConfig, tokenNetworkFilter, privacyMode } =
useSelector(getPreferences);
const {
tokenSortConfig,
tokenNetworkFilter,
privacyMode,
hideZeroBalanceTokens,
} = useSelector(getPreferences);
const selectedAccount = useSelector(getSelectedAccount);
const conversionRate = useSelector(getConversionRate);
const contractExchangeRates = useSelector(
Expand All @@ -96,6 +101,9 @@ export default function TokenList({
);
const newTokensImported = useSelector(getNewTokensImported);
const selectedAccountTokensChains = useFilteredAccountTokens(currentNetwork);
const isOnCurrentNetwork = useSelector(
getIsTokenNetworkFilterEqualCurrentNetwork,
);

const { tokenBalances } = useTokenBalances();
const selectedAccountTokenBalancesAcrossChains =
Expand All @@ -109,7 +117,7 @@ export default function TokenList({
const nativeBalances: Record<Hex, Hex> = useSelector(
getSelectedAccountNativeTokenCachedBalanceByChainId,
) as Record<Hex, Hex>;

const isTestnet = useSelector(getIsTestnet);
// Ensure newly added networks are included in the tokenNetworkFilter
useEffect(() => {
if (process.env.PORTFOLIO_VIEW) {
Expand Down Expand Up @@ -147,14 +155,28 @@ export default function TokenList({
currencyRates,
});

// Append processed token with balance and fiat amount
tokensWithBalance.push({
...token,
balance,
tokenFiatAmount,
chainId,
string: String(balance),
});
// Respect the "hide zero balance" setting (when true):
// - Native tokens should always display with zero balance when on the current network filter.
// - Native tokens should not display with zero balance when on all networks filter
// - ERC20 tokens with zero balances should respect the setting on both the current and all networks.

// Respect the "hide zero balance" setting (when false):
// - Native tokens should always display with zero balance when on the current network filter.
// - Native tokens should always display with zero balance when on all networks filter
// - ERC20 tokens always display with zero balance on both the current and all networks filter.
if (
!hideZeroBalanceTokens ||
balance !== '0' ||
(token.isNative && isOnCurrentNetwork)
) {
tokensWithBalance.push({
...token,
balance,
tokenFiatAmount,
chainId,
string: String(balance),
});
}
});
},
);
Expand Down Expand Up @@ -216,8 +238,6 @@ export default function TokenList({
console.log(t('loadingTokens'));
}

// Check if testnet
const isTestnet = useSelector(getIsTestnet);
const shouldShowFiat = useMultichainSelector(
getMultichainShouldShowFiat,
selectedAccount,
Expand Down
Loading