Skip to content

Commit

Permalink
UX: Multichain: Fix useAccountTotalFiatBalance when getWeiHexFromDeci…
Browse files Browse the repository at this point in the history
…malValue returns undefined
  • Loading branch information
darkwing committed Oct 12, 2023
1 parent 574f745 commit 8d4ec74
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions ui/hooks/useAccountTotalFiatBalance.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const useAccountTotalFiatBalance = (
const cachedBalances = useSelector(getMetaMaskCachedBalances);
const balance = cachedBalances?.[address] ?? 0;
const nativeFiat = getValueFromWeiHex({
value: balance,
value: balance ?? 0,
toCurrency: currentCurrency,
conversionRate,
numberOfDecimals: 2,
Expand Down Expand Up @@ -82,13 +82,19 @@ export const useAccountTotalFiatBalance = (
const formattedFiat = formatCurrency(totalFiatBalance, currentCurrency);

// WEI Number which can be used with UserPreferencedCurrencyDisplay component
const totalWeiBalance = getWeiHexFromDecimalValue({
let totalWeiBalance = getWeiHexFromDecimalValue({
value: totalFiatBalance,
fromCurrency: currentCurrency,
conversionRate,
invertConversionRate: true,
});

// If we have a totalFiatBalance of "0" and conversionRate of "0",
// getWeiHexFromDecimalValue responds with "NaN"
if (totalWeiBalance === 'NaN') {
totalWeiBalance = '0x0';
}

return {
formattedFiat,
totalWeiBalance,
Expand Down

0 comments on commit 8d4ec74

Please sign in to comment.