From 3b6d26793ea3a32971b715efd719bce087d27353 Mon Sep 17 00:00:00 2001 From: Brooks Boyd Date: Tue, 14 Nov 2023 08:35:58 -0600 Subject: [PATCH 1/3] Add null-guards for token balances --- src/hooks/useGetSourceParsedTokenAccounts.ts | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/hooks/useGetSourceParsedTokenAccounts.ts b/src/hooks/useGetSourceParsedTokenAccounts.ts index 6f5f25159..f6d7d182c 100644 --- a/src/hooks/useGetSourceParsedTokenAccounts.ts +++ b/src/hooks/useGetSourceParsedTokenAccounts.ts @@ -640,18 +640,17 @@ const createNFTParsedTokenAccountFromCovalent = ( covalent: CovalentData, nft_data: CovalentNFTData ): NFTParsedTokenAccount => { + let amount = + nft_data.token_balance == null + ? "0" + : formatUnits(nft_data.token_balance, covalent.contract_decimals); return { publicKey: walletAddress, mintKey: covalent.contract_address, - amount: nft_data.token_balance, + amount: nft_data.token_balance == null ? "" : nft_data.token_balance, decimals: covalent.contract_decimals, - uiAmount: Number( - formatUnits(nft_data.token_balance, covalent.contract_decimals) - ), - uiAmountString: formatUnits( - nft_data.token_balance, - covalent.contract_decimals - ), + uiAmount: Number(amount), + uiAmountString: amount, symbol: covalent.contract_ticker_symbol, name: covalent.contract_name, logo: covalent.logo_url, @@ -689,7 +688,7 @@ export type CovalentNFTExternalData = { export type CovalentNFTData = { token_id: string; - token_balance: string; + token_balance: string | null; external_data: CovalentNFTExternalData; token_url: string; }; From b981ce867aea30fd09f350dd1c294394a98d661c Mon Sep 17 00:00:00 2001 From: Brooks Boyd Date: Tue, 14 Nov 2023 14:22:58 -0600 Subject: [PATCH 2/3] Change variable type Co-authored-by: Sebastian --- src/hooks/useGetSourceParsedTokenAccounts.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hooks/useGetSourceParsedTokenAccounts.ts b/src/hooks/useGetSourceParsedTokenAccounts.ts index f6d7d182c..eae9f86de 100644 --- a/src/hooks/useGetSourceParsedTokenAccounts.ts +++ b/src/hooks/useGetSourceParsedTokenAccounts.ts @@ -640,7 +640,7 @@ const createNFTParsedTokenAccountFromCovalent = ( covalent: CovalentData, nft_data: CovalentNFTData ): NFTParsedTokenAccount => { - let amount = + const amount = nft_data.token_balance == null ? "0" : formatUnits(nft_data.token_balance, covalent.contract_decimals); From 6dcc73ba974e9059c4f4c25761b7fda959bef1c9 Mon Sep 17 00:00:00 2001 From: Brooks Boyd Date: Tue, 14 Nov 2023 22:25:46 -0600 Subject: [PATCH 3/3] Catch any falsy value --- src/hooks/useGetSourceParsedTokenAccounts.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/hooks/useGetSourceParsedTokenAccounts.ts b/src/hooks/useGetSourceParsedTokenAccounts.ts index eae9f86de..f635dff3d 100644 --- a/src/hooks/useGetSourceParsedTokenAccounts.ts +++ b/src/hooks/useGetSourceParsedTokenAccounts.ts @@ -640,14 +640,13 @@ const createNFTParsedTokenAccountFromCovalent = ( covalent: CovalentData, nft_data: CovalentNFTData ): NFTParsedTokenAccount => { - const amount = - nft_data.token_balance == null - ? "0" - : formatUnits(nft_data.token_balance, covalent.contract_decimals); + const amount = nft_data.token_balance + ? formatUnits(nft_data.token_balance, covalent.contract_decimals) + : "0"; return { publicKey: walletAddress, mintKey: covalent.contract_address, - amount: nft_data.token_balance == null ? "" : nft_data.token_balance, + amount: nft_data.token_balance ? nft_data.token_balance : "", decimals: covalent.contract_decimals, uiAmount: Number(amount), uiAmountString: amount,