From 72b55b340188c6917770ace2c00b97900462dfcf Mon Sep 17 00:00:00 2001 From: Matt Holtzman Date: Tue, 14 Feb 2023 21:31:02 -0500 Subject: [PATCH 1/2] show custom token balances even if zero --- app/tray/Account/Balances/BalancesPreview/index.js | 2 +- main/externalData/balances/index.ts | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/tray/Account/Balances/BalancesPreview/index.js b/app/tray/Account/Balances/BalancesPreview/index.js index b809e823c..ba46c6a62 100644 --- a/app/tray/Account/Balances/BalancesPreview/index.js +++ b/app/tray/Account/Balances/BalancesPreview/index.js @@ -13,7 +13,7 @@ import { } from '../../../../../resources/domain/balance' import { matchFilter } from '../../../../../resources/utils' -import { ClusterBox, Cluster, ClusterRow, ClusterValue } from '../../../../../resources/Components/Cluster' +import { Cluster, ClusterRow, ClusterValue } from '../../../../../resources/Components/Cluster' import Balance from '../Balance' diff --git a/main/externalData/balances/index.ts b/main/externalData/balances/index.ts index f839c10b1..9adb9f4e7 100644 --- a/main/externalData/balances/index.ts +++ b/main/externalData/balances/index.ts @@ -223,13 +223,17 @@ export default function (store: Store) { function handleTokenBalanceUpdate(balances: TokenBalance[], address: Address) { // only update balances if any have changed const currentTokenBalances = storeApi.getTokenBalances(address) + const customTokens = new Set(storeApi.getCustomTokens().map(toTokenId)) + const isCustomToken = (balance: Balance) => customTokens.has(toTokenId(balance)) + const changedBalances = balances.filter((newBalance) => { const currentBalance = currentTokenBalances.find( (b) => b.address === newBalance.address && b.chainId === newBalance.chainId ) // do not add newly found tokens with a zero balance - const isNewBalance = !currentBalance && parseInt(newBalance.balance) !== 0 + const isNewBalance = + (!currentBalance && parseInt(newBalance.balance) !== 0) || isCustomToken(newBalance) const isChangedBalance = !!currentBalance && currentBalance.balance !== newBalance.balance return isNewBalance || isChangedBalance From 0be03b83161de2eb9d38c78502bbd800c7980df4 Mon Sep 17 00:00:00 2001 From: Matt Holtzman Date: Tue, 14 Feb 2023 21:32:08 -0500 Subject: [PATCH 2/2] rework booleans --- main/externalData/balances/index.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/main/externalData/balances/index.ts b/main/externalData/balances/index.ts index 9adb9f4e7..33a4522f0 100644 --- a/main/externalData/balances/index.ts +++ b/main/externalData/balances/index.ts @@ -232,11 +232,10 @@ export default function (store: Store) { ) // do not add newly found tokens with a zero balance - const isNewBalance = - (!currentBalance && parseInt(newBalance.balance) !== 0) || isCustomToken(newBalance) + const isNewBalance = !currentBalance && parseInt(newBalance.balance) !== 0 const isChangedBalance = !!currentBalance && currentBalance.balance !== newBalance.balance - return isNewBalance || isChangedBalance + return isNewBalance || isChangedBalance || isCustomToken(newBalance) }) if (changedBalances.length > 0) {