fix: token holdings summary table sums tokens correctly (#16464)

This commit is contained in:
Josh 2021-04-10 12:24:56 -07:00 committed by GitHub
parent c4646b2bc3
commit 91d5f6ab30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 8 deletions

View File

@ -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[] = [];

View File

@ -317,12 +317,14 @@ const FilterDropdown = ({ filter, toggle, show, tokens }: FilterProps) => {
};
const filterOptions: string[] = [ALL_TOKENS];
const nameLookup: { [mint: string]: string } = {};
const nameLookup: Map<string, string> = 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)}
</button>
<div
className={`token-filter dropdown-menu-right dropdown-menu${