Skip to content

Commit

Permalink
Add null-guards for token balances (#519)
Browse files Browse the repository at this point in the history
* Add null-guards for token balances

* Change variable type

Co-authored-by: Sebastian <[email protected]>

* Catch any falsy value

---------

Co-authored-by: Sebastian <[email protected]>
  • Loading branch information
MidnightLightning and sebastianscatularo authored Nov 17, 2023
1 parent 3622cc3 commit fd298c1
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/hooks/useGetSourceParsedTokenAccounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -640,18 +640,16 @@ const createNFTParsedTokenAccountFromCovalent = (
covalent: CovalentData,
nft_data: CovalentNFTData
): NFTParsedTokenAccount => {
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,
amount: nft_data.token_balance ? 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,
Expand Down Expand Up @@ -689,7 +687,7 @@ export type CovalentNFTExternalData = {

export type CovalentNFTData = {
token_id: string;
token_balance: string;
token_balance: string | null;
external_data: CovalentNFTExternalData;
token_url: string;
};
Expand Down

0 comments on commit fd298c1

Please sign in to comment.