Skip to content

Commit

Permalink
render fiat balances
Browse files Browse the repository at this point in the history
  • Loading branch information
owencraston committed Jan 22, 2025
1 parent 98f9633 commit e47cae3
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions app/components/hooks/usePortfolioBalance/usePortfolioBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
selectMultichainSelectedAccountCachedBalance,
selectMultichainDefaultToken,
selectMultichainShouldShowFiat,
selectMultichainConversionRate,
} from '../../../selectors/multichain';
///: END:ONLY_INCLUDE_IF

Expand Down Expand Up @@ -91,6 +92,7 @@ const usePortfolioBalance = (): UsePortfolioBalanceHook => {
);
const { symbol } = useSelector(selectMultichainDefaultToken);
const shouldShowFiat = useSelector(selectMultichainShouldShowFiat);
const multichainConversionRate = useSelector(selectMultichainConversionRate);
///: END:ONLY_INCLUDE_IF

// Production balance calculation (EVM)
Expand Down Expand Up @@ -121,13 +123,29 @@ const usePortfolioBalance = (): UsePortfolioBalanceHook => {
};

///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps)
const getMultiChainFiatBalance = (
nativeTokenBalance: string,
conversionRate: number,
currency: string,
) => {
const multichainBalance = Number(nativeTokenBalance);
const fiatBalance = multichainBalance * conversionRate;
return renderFiat(fiatBalance, currency);
};

const getNonEvmDisplayBalance = () => {
if (!shouldShowFiat) {
const total =
totalFiatBalancesCrossChain[selectedInternalAccount?.address as string]
?.totalFiatBalance ?? 0;
return renderFiat(total, currentCurrency);
return `${multichainSelectedAccountCachedBalance} ${symbol}`;
}
if (multichainSelectedAccountCachedBalance && multichainConversionRate) {
return getMultiChainFiatBalance(
multichainSelectedAccountCachedBalance,
multichainConversionRate,
currentCurrency,
);
}

// default to native token symbol
return `${multichainSelectedAccountCachedBalance} ${symbol}`;
};
///: END:ONLY_INCLUDE_IF
Expand Down

0 comments on commit e47cae3

Please sign in to comment.