Skip to content

Commit 87790df

Browse files
committed
Fix #28534 - Show correct swap value from asset details
1 parent 6e92ee4 commit 87790df

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

ui/pages/asset/components/asset-page.tsx

+13-5
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,21 @@ const AssetPage = ({
9292
const selectedAccount = useSelector(getSelectedAccount);
9393
const currency = useSelector(getCurrentCurrency);
9494
const conversionRate = useSelector(getConversionRate);
95-
const isBridgeChain = useSelector(getIsBridgeChain);
9695
const isBuyableChain = useSelector(getIsNativeTokenBuyable);
97-
const defaultSwapsToken = useSelector(getSwapsDefaultToken, isEqual);
96+
97+
const { chainId, type, symbol, name, image, decimals } = asset;
98+
99+
// These need to be specific to the asset and not the current chain
100+
const defaultSwapsToken = useSelector(
101+
(state) => getSwapsDefaultToken(state, chainId),
102+
isEqual,
103+
);
104+
const isSwapsChain = useSelector((state) => getIsSwapsChain(state, chainId));
105+
const isBridgeChain = useSelector((state) =>
106+
getIsBridgeChain(state, chainId),
107+
);
108+
98109
const account = useSelector(getSelectedInternalAccount, isEqual);
99-
const isSwapsChain = useSelector(getIsSwapsChain);
100110
const isSigningEnabled =
101111
account.methods.includes(EthMethod.SignTransaction) ||
102112
account.methods.includes(EthMethod.SignUserOperation);
@@ -112,8 +122,6 @@ const AssetPage = ({
112122
const selectedAccountTokenBalancesAcrossChains =
113123
tokenBalances[selectedAccount.address];
114124

115-
const { chainId, type, symbol, name, image, decimals } = asset;
116-
117125
const address =
118126
type === AssetType.token
119127
? toChecksumHexAddress(asset.address)

ui/selectors/selectors.js

+10-6
Original file line numberDiff line numberDiff line change
@@ -1530,10 +1530,12 @@ export function getWeb3ShimUsageStateForOrigin(state, origin) {
15301530
* selected account's ETH balance, as expected by the Swaps API.
15311531
*/
15321532

1533-
export function getSwapsDefaultToken(state) {
1533+
export function getSwapsDefaultToken(state, overrideChainId) {
15341534
const selectedAccount = getSelectedAccount(state);
15351535
const balance = selectedAccount?.balance;
1536-
const chainId = getCurrentChainId(state);
1536+
const currentChainId = getCurrentChainId(state);
1537+
1538+
const chainId = overrideChainId ?? currentChainId;
15371539
const defaultTokenObject = SWAPS_CHAINID_DEFAULT_TOKEN_MAP[chainId];
15381540

15391541
return {
@@ -1547,8 +1549,9 @@ export function getSwapsDefaultToken(state) {
15471549
};
15481550
}
15491551

1550-
export function getIsSwapsChain(state) {
1551-
const chainId = getCurrentChainId(state);
1552+
export function getIsSwapsChain(state, overrideChainId) {
1553+
const currentChainId = getCurrentChainId(state);
1554+
const chainId = overrideChainId ?? currentChainId;
15521555
const isNotDevelopment =
15531556
process.env.METAMASK_ENVIRONMENT !== 'development' &&
15541557
process.env.METAMASK_ENVIRONMENT !== 'testing';
@@ -1557,8 +1560,9 @@ export function getIsSwapsChain(state) {
15571560
: ALLOWED_DEV_SWAPS_CHAIN_IDS.includes(chainId);
15581561
}
15591562

1560-
export function getIsBridgeChain(state) {
1561-
const chainId = getCurrentChainId(state);
1563+
export function getIsBridgeChain(state, overrideChainId) {
1564+
const currentChainId = getCurrentChainId(state);
1565+
const chainId = overrideChainId ?? currentChainId;
15621566
return ALLOWED_BRIDGE_CHAIN_IDS.includes(chainId);
15631567
}
15641568

0 commit comments

Comments
 (0)