From 55487aedcacd885e591aded6b32bacd8c19f3548 Mon Sep 17 00:00:00 2001 From: Anastasiia Sokolova <63446892+sokolova-an@users.noreply.github.com> Date: Thu, 31 Oct 2024 12:21:16 +0100 Subject: [PATCH] fix: hide zero balance chains (#2563) --- .../AssetsPortfolioView/lib/tokensService.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/renderer/features/assets/AssetsPortfolioView/lib/tokensService.ts b/src/renderer/features/assets/AssetsPortfolioView/lib/tokensService.ts index 33d9fdbb6..e632668ae 100644 --- a/src/renderer/features/assets/AssetsPortfolioView/lib/tokensService.ts +++ b/src/renderer/features/assets/AssetsPortfolioView/lib/tokensService.ts @@ -93,9 +93,17 @@ function getChainWithBalance( } function hideZeroBalances(hideZeroBalance: boolean, activeTokensWithBalance: AssetByChains[]): AssetByChains[] { - return activeTokensWithBalance.filter((token) => { - return !hideZeroBalance || totalAmount(token.totalBalance) !== ZERO_BALANCE; - }); + if (!hideZeroBalance) return activeTokensWithBalance; + + return activeTokensWithBalance.reduce((acc, token) => { + if (totalAmount(token.totalBalance) === ZERO_BALANCE) return acc; + + const chains = token.chains.filter((chain) => { + return totalAmount(chain.balance) !== ZERO_BALANCE; + }); + + return [...acc, { ...token, chains }]; + }, []); } function sortTokensByBalance(