Skip to content

Commit 69833d9

Browse files
chore(runway): cherry-pick fix: (cp-7.47.0) allow formatting tokens to be done on either EVM or SOL chain (#15777)
- fix: (cp-7.47.0) allow formatting tokens to be done on either EVM or SOL chain (#15755)
1 parent 4e69ee3 commit 69833d9

2 files changed

Lines changed: 16 additions & 7 deletions

File tree

app/components/hooks/useGetFormattedTokensPerChain.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@ describe('useGetFormattedTokensPerChain', () => {
177177
},
178178
],
179179
},
180+
{
181+
chainId: 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp',
182+
tokensWithBalances: [],
183+
},
180184
],
181185
};
182186

app/components/hooks/useGetFormattedTokensPerChain.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
toHexadecimal,
1212
} from '../../util/number';
1313
import {
14-
selectChainId,
14+
selectEvmChainId,
1515
selectNetworkConfigurations,
1616
} from '../../selectors/networkController';
1717
import { selectTokenMarketPriceData } from '../../selectors/tokenRatesController';
@@ -21,6 +21,7 @@ import {
2121
} from '../../selectors/currencyRateController';
2222
import { isTestNet } from '../../util/networks';
2323
import { selectShowFiatInTestnets } from '../../selectors/settings';
24+
import { selectSelectedNonEvmNetworkChainId } from '../../selectors/multichainNetworkController';
2425
interface AllTokens {
2526
[chainId: string]: {
2627
[tokenAddress: string]: Token[];
@@ -89,9 +90,9 @@ export const useGetFormattedTokensPerChain = (
8990
} => {
9091
const stableAccounts = useStableReference(accounts);
9192
const stableAllChainIDs = useStableReference(allChainIDs);
93+
const currentEvmChainID = useSelector(selectEvmChainId);
94+
const currentSolChainID = useSelector(selectSelectedNonEvmNetworkChainId);
9295

93-
// TODO: [SOLANA] Revisit this before shipping, `selectAllTokenBalances` selector needs to most likely be replaced by a non evm supported version
94-
const currentChainId = useSelector(selectChainId);
9596
const importedTokens: AllTokens = useSelector(selectAllTokens);
9697
const allNetworks: Record<
9798
string,
@@ -110,17 +111,16 @@ export const useGetFormattedTokensPerChain = (
110111
const showFiatOnTestnets = useSelector(selectShowFiatInTestnets);
111112

112113
return useMemo(() => {
113-
//If the current network is a testnet, UI should display 0 unless conversions are enabled
114114
const validAccounts =
115115
stableAccounts.length > 0 &&
116116
stableAccounts.every((item) => item !== undefined);
117-
if (!validAccounts || (isTestNet(currentChainId) && !showFiatOnTestnets)) {
117+
if (!validAccounts) {
118118
return {};
119119
}
120120

121121
const networksToFormat = shouldAggregateAcrossChains
122122
? stableAllChainIDs
123-
: [currentChainId];
123+
: [currentEvmChainID, currentSolChainID];
124124

125125
function getTokenFiatBalances({
126126
tokens,
@@ -183,6 +183,10 @@ export const useGetFormattedTokensPerChain = (
183183
if (!allNetworks[singleChain]) {
184184
continue;
185185
}
186+
// Skip if should not show fiat on testnets
187+
if (isTestNet(singleChain) && !showFiatOnTestnets) {
188+
continue;
189+
}
186190

187191
const tokens: Token[] =
188192
importedTokens?.[singleChain]?.[account?.address] ?? [];
@@ -212,7 +216,8 @@ export const useGetFormattedTokensPerChain = (
212216
stableAccounts,
213217
stableAllChainIDs,
214218
allNetworks,
215-
currentChainId,
219+
currentEvmChainID,
220+
currentSolChainID,
216221
currentCurrency,
217222
currentTokenBalances,
218223
currencyRates,

0 commit comments

Comments
 (0)