Skip to content

Commit

Permalink
fix: Pass along decimal balance to swaps UI
Browse files Browse the repository at this point in the history
  • Loading branch information
gambinish committed Nov 25, 2024
1 parent ff635d2 commit 8afb9e6
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions ui/pages/asset/components/asset-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import { getMultichainShouldShowFiat } from '../../../selectors/multichain';
import { getPortfolioUrl } from '../../../helpers/utils/portfolio';
import AssetChart from './chart/asset-chart';
import TokenButtons from './token-buttons';
import { hexToDecimal } from '../../../../shared/modules/conversion.utils';

/** Information about a native or token asset */
export type Asset = (
Expand Down Expand Up @@ -151,6 +152,9 @@ const AssetPage = ({
? toChecksumHexAddress(asset.address)
: getNativeTokenAddress(chainId);

const tokenHexBalance =
selectedAccountTokenBalancesAcrossChains[chainId][address as Hex];

const balance = calculateTokenBalance({
isNative: type === AssetType.native,
chainId,
Expand Down Expand Up @@ -187,10 +191,10 @@ const AssetPage = ({
tokenMarketDetails.allTimeHigh > 0 ||
tokenMarketDetails.allTimeLow > 0);

// this is needed in order to assign the correct balances to TokenButtons before sending/swapping
// without this, the balances we be populated as zero until the user refreshes the screen: https://github.com/MetaMask/metamask-extension/issues/28509
// this is needed in order to assign the correct balances to TokenButtons before navigating to send/swap screens

asset.balance = {
value: '', // decimal value not needed
value: hexToDecimal(tokenHexBalance),
display: String(balance),
fiat: String(tokenFiatAmount),
};
Expand Down

0 comments on commit 8afb9e6

Please sign in to comment.