From 91d5f6ab30c95ddf8003cf608caf2c4a50989bca Mon Sep 17 00:00:00 2001 From: Josh Date: Sat, 10 Apr 2021 12:24:56 -0700 Subject: [PATCH] fix: token holdings summary table sums tokens correctly (#16464) --- explorer/src/components/account/OwnedTokensCard.tsx | 8 +++++--- explorer/src/components/account/TokenHistoryCard.tsx | 12 +++++++----- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/explorer/src/components/account/OwnedTokensCard.tsx b/explorer/src/components/account/OwnedTokensCard.tsx index f26eca308e..7deb04f7b7 100644 --- a/explorer/src/components/account/OwnedTokensCard.tsx +++ b/explorer/src/components/account/OwnedTokensCard.tsx @@ -151,12 +151,14 @@ function HoldingsSummaryTable({ tokens }: { tokens: TokenInfoWithPubkey[] }) { const mintAddress = token.mint.toBase58(); const totalByMint = mappedTokens.get(mintAddress); - let amount = new BigNumber(token.tokenAmount.uiAmountString); + let amount = token.tokenAmount.uiAmountString; if (totalByMint !== undefined) { - amount.plus(totalByMint); + amount = new BigNumber(totalByMint) + .plus(token.tokenAmount.uiAmountString) + .toString(); } - mappedTokens.set(mintAddress, amount.toString()); + mappedTokens.set(mintAddress, amount); } const detailsList: React.ReactNode[] = []; diff --git a/explorer/src/components/account/TokenHistoryCard.tsx b/explorer/src/components/account/TokenHistoryCard.tsx index 681686a621..1e5768c9e6 100644 --- a/explorer/src/components/account/TokenHistoryCard.tsx +++ b/explorer/src/components/account/TokenHistoryCard.tsx @@ -317,12 +317,14 @@ const FilterDropdown = ({ filter, toggle, show, tokens }: FilterProps) => { }; const filterOptions: string[] = [ALL_TOKENS]; - const nameLookup: { [mint: string]: string } = {}; + const nameLookup: Map = new Map(); tokens.forEach((token) => { - const pubkey = token.info.mint.toBase58(); - filterOptions.push(pubkey); - nameLookup[pubkey] = formatTokenName(pubkey, cluster, tokenRegistry); + const address = token.info.mint.toBase58(); + if (!nameLookup.has(address)) { + filterOptions.push(address); + nameLookup.set(address, formatTokenName(address, cluster, tokenRegistry)); + } }); return ( @@ -333,7 +335,7 @@ const FilterDropdown = ({ filter, toggle, show, tokens }: FilterProps) => { type="button" onClick={toggle} > - {filter === ALL_TOKENS ? "All Tokens" : nameLookup[filter]} + {filter === ALL_TOKENS ? "All Tokens" : nameLookup.get(filter)}