From 2a2cdb2f34672b56531e3292d81076ca02cd9e5f Mon Sep 17 00:00:00 2001 From: AJ Webb Date: Wed, 1 Nov 2023 05:08:26 -1000 Subject: [PATCH] Gracefully handle denoms that aren't in the denom metadata --- .../Components/AccountTables/Components/AccountAssets.tsx | 2 +- src/utils/number/currencyFormat.tsx | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Pages/Accounts/Components/AccountTables/Components/AccountAssets.tsx b/src/Pages/Accounts/Components/AccountTables/Components/AccountAssets.tsx index 4ca018c8..a1954e4c 100644 --- a/src/Pages/Accounts/Components/AccountTables/Components/AccountAssets.tsx +++ b/src/Pages/Accounts/Components/AccountTables/Components/AccountAssets.tsx @@ -29,7 +29,7 @@ export const AccountAssets = () => { const tableData = accountAssets.map((a) => ({ ...a, displayDenom: assetMetadata.find((md) => md.base === a.denom)?.display, - exponent: assetMetadata.find((md) => md.base === a.denom)?.denomUnits[1].exponent, + exponent: assetMetadata.find((md) => md.base === a.denom)?.denomUnits?.[1].exponent, })); // Table header values in order diff --git a/src/utils/number/currencyFormat.tsx b/src/utils/number/currencyFormat.tsx index f42eeb59..4631c0e8 100644 --- a/src/utils/number/currencyFormat.tsx +++ b/src/utils/number/currencyFormat.tsx @@ -16,10 +16,12 @@ export const currencyFormat = (value = 0, initialDenom: string, toBase = false) ); // If the value isn't a number, - // the initial and final denoms don't match a known conversion or - // the initial and final denoms are the same string, + // the initial and final denoms don't match a known conversion, + // the initial and final denoms are the same string or + // the denom units don't exist // just return the value - if (isNaN(value) || !denomInfo) return { amount: value, denom: initialDenom }; + if (isNaN(value) || !denomInfo || !denomInfo?.denomUnits) + return { amount: value, denom: initialDenom }; // pull the needed denom info const { base, display, denomUnits } = denomInfo;