From e42e7bd7a6f4c58762a02848ac78e808949c3771 Mon Sep 17 00:00:00 2001 From: Monte Lai Date: Thu, 5 Dec 2024 23:17:33 +0800 Subject: [PATCH] fix: display other currency conversion for btc --- .../native-token/use-native-token-balance.ts | 9 +++++++- .../account-list-item/account-list-item.js | 3 +-- ui/hooks/useCurrencyDisplay.js | 1 + ui/selectors/multichain.ts | 23 +++++++------------ ui/selectors/selectors.js | 4 ++-- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/ui/components/app/assets/asset-list/native-token/use-native-token-balance.ts b/ui/components/app/assets/asset-list/native-token/use-native-token-balance.ts index a14e65ac572b..7e7c94e9e1dc 100644 --- a/ui/components/app/assets/asset-list/native-token/use-native-token-balance.ts +++ b/ui/components/app/assets/asset-list/native-token/use-native-token-balance.ts @@ -7,7 +7,11 @@ import { getMultichainSelectedAccountCachedBalance, getMultichainShouldShowFiat, } from '../../../../../selectors/multichain'; -import { getCurrentCurrency, getPreferences } from '../../../../../selectors'; +import { + getCurrentCurrency, + getPreferences, + getSelectedInternalAccount, +} from '../../../../../selectors'; import { useIsOriginalNativeTokenSymbol } from '../../../../../hooks/useIsOriginalNativeTokenSymbol'; import { PRIMARY, SECONDARY } from '../../../../../helpers/constants/common'; import { useUserPreferencedCurrency } from '../../../../../hooks/useUserPreferencedCurrency'; @@ -16,6 +20,7 @@ import { TokenWithBalance } from '../asset-list'; export const useNativeTokenBalance = () => { const showFiat = useSelector(getMultichainShouldShowFiat); + const account = useSelector(getSelectedInternalAccount); const primaryTokenImage = useSelector(getMultichainCurrencyImage); const { showNativeTokenAsMainBalance } = useSelector(getPreferences); const { chainId, ticker, type, rpcUrl } = useSelector( @@ -46,12 +51,14 @@ export const useNativeTokenBalance = () => { const [primaryCurrencyDisplay, primaryCurrencyProperties] = useCurrencyDisplay(balance, { + account, numberOfDecimals: primaryNumberOfDecimals, currency: primaryCurrency, }); const [secondaryCurrencyDisplay, secondaryCurrencyProperties] = useCurrencyDisplay(balance, { + account, numberOfDecimals: secondaryNumberOfDecimals, currency: secondaryCurrency, }); diff --git a/ui/components/multichain/account-list-item/account-list-item.js b/ui/components/multichain/account-list-item/account-list-item.js index 207b8fa0fe58..4ab71516ec40 100644 --- a/ui/components/multichain/account-list-item/account-list-item.js +++ b/ui/components/multichain/account-list-item/account-list-item.js @@ -366,8 +366,7 @@ const AccountListItem = ({ {shortenAddress(normalizeSafeAddress(account.address))} - {/* For non-EVM networks we always want to show tokens */} - {mappedOrderedTokenList.length > 1 || !isEvmNetwork ? ( + {mappedOrderedTokenList.length > 1 ? ( ) : ( { return state.metamask.rates; }; -function getNonEvmCachedBalance(state: MultichainState) { +function getNonEvmCachedBalance( + state: MultichainState, + account?: InternalAccount, +) { const balances = getMultichainBalances(state); - const account = getSelectedInternalAccount(state); + const selectedAccount = account ?? getSelectedInternalAccount(state); const network = getMultichainCurrentNetwork(state); // We assume that there's at least one asset type in and that is the native @@ -387,7 +380,7 @@ function getNonEvmCachedBalance(state: MultichainState) { network.chainId as MultichainNetworks ]?.[0]; - return balances?.[account.id]?.[asset]?.amount; + return balances?.[selectedAccount.id]?.[asset]?.amount ?? 0; } export function getImageForChainId(chainId: string) { diff --git a/ui/selectors/selectors.js b/ui/selectors/selectors.js index 2baaa1a0c931..dc6f7be35beb 100644 --- a/ui/selectors/selectors.js +++ b/ui/selectors/selectors.js @@ -104,7 +104,7 @@ import { import { BackgroundColor } from '../helpers/constants/design-system'; import { NOTIFICATION_DROP_LEDGER_FIREFOX } from '../../shared/notifications'; import { ENVIRONMENT_TYPE_POPUP } from '../../shared/constants/app'; -import { MultichainNativeAssets } from '../../shared/constants/multichain/assets'; +import { MULTICHAIN_NETWORK_TO_ASSET_TYPES } from '../../shared/constants/multichain/assets'; // TODO: Remove restricted import // eslint-disable-next-line import/no-restricted-paths import { BridgeFeatureFlagsKey } from '../../app/scripts/controllers/bridge/types'; @@ -291,7 +291,7 @@ export const getMetaMaskAccounts = createSelector( ...account, balance: multichainBalances?.[internalAccount.id]?.[ - MultichainNativeAssets[multichainNetwork.chainId] + MULTICHAIN_NETWORK_TO_ASSET_TYPES[multichainNetwork.chainId] ]?.amount ?? '0', }; }