From 8afb9e65cc897e8304b89e9e49404604143b0dcf Mon Sep 17 00:00:00 2001 From: Nicholas Gambino Date: Mon, 25 Nov 2024 14:53:32 -0800 Subject: [PATCH] fix: Pass along decimal balance to swaps UI --- ui/pages/asset/components/asset-page.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/ui/pages/asset/components/asset-page.tsx b/ui/pages/asset/components/asset-page.tsx index 68d7f9d18e65..82a84e9bf434 100644 --- a/ui/pages/asset/components/asset-page.tsx +++ b/ui/pages/asset/components/asset-page.tsx @@ -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 = ( @@ -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, @@ -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), };