Skip to content

Commit

Permalink
Gracefully handle denoms that aren't in the denom metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
webbushka committed Nov 1, 2023
1 parent 3df7984 commit 2a2cdb2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions src/utils/number/currencyFormat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 2a2cdb2

Please sign in to comment.