Skip to content

fix: balance and token icons are unavailable when the bridge page is reopened #31343

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 28, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion ui/hooks/bridge/useLatestBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
formatChainIdToCaip,
formatChainIdToHex,
ChainId,
isNativeAddress,
} from '@metamask/bridge-controller';
import { useSelector } from 'react-redux';
import { getSelectedInternalAccount } from '../../selectors';
Expand All @@ -18,6 +19,7 @@ import {
getMultichainCurrentChainId,
} from '../../selectors/multichain';
import { getProviderConfig } from '../../../shared/modules/selectors/networks';
import { MULTICHAIN_NATIVE_CURRENCY_TO_CAIP19 } from '../../../shared/constants/multichain/assets';

/**
* Custom hook to fetch and format the latest balance of a given token or native asset.
Expand All @@ -32,6 +34,7 @@ const useLatestBalance = (
symbol: string;
string?: string;
chainId?: Hex | CaipChainId | ChainId;
assetId?: string;
} | null,
) => {
const { address: selectedAddress, id } = useMultichainSelector(
Expand All @@ -56,8 +59,11 @@ const useLatestBalance = (
// No need to fetch the balance for non-EVM tokens, use the balance provided by the
// multichain balances controller
if (isSolanaChainId(chainId) && token.decimals) {
const caipAssetType = isNativeAddress(token.address)
? MULTICHAIN_NATIVE_CURRENCY_TO_CAIP19.SOL
: token.assetId ?? token.address;
return Numeric.from(
nonEvmBalances?.[token.address]?.amount ?? token.string,
nonEvmBalances?.[caipAssetType]?.amount ?? token?.string,
10,
)
.shiftedBy(-1 * token.decimals)
Expand Down
4 changes: 2 additions & 2 deletions ui/pages/bridge/prepare/prepare-bridge-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,15 @@ const PrepareBridgePage = () => {
setToToken({
...destAsset,
chainId: destChainId,
image: destAsset.icon ?? '',
image: srcAsset.icon ?? destAsset.iconUrl ?? '',
address: destAsset.address,
}),
);
dispatch(
setFromToken({
...srcAsset,
chainId: srcChainId,
image: srcAsset.icon ?? '',
image: srcAsset.icon || srcAsset.iconUrl || '',
address: srcAsset.address,
}),
);
Expand Down
Loading