1+ import { useMemo } from 'react' ;
12import {
23 CaipAccountId ,
34 CaipAssetType ,
@@ -12,7 +13,10 @@ import { selectMultichainTokenListForAccountId } from '../../../selectors/multic
1213import I18n from '../../../../locales/i18n' ;
1314import { formatWithThreshold } from '../../../util/assets' ;
1415import { selectNetworkConfigurations } from '../../../selectors/networkController' ;
15- import { AllowedBridgeChainIds , NETWORK_TO_SHORT_NETWORK_NAME_MAP } from '../../../constants/bridge' ;
16+ import {
17+ AllowedBridgeChainIds ,
18+ NETWORK_TO_SHORT_NETWORK_NAME_MAP ,
19+ } from '../../../constants/bridge' ;
1620import { selectCurrentCurrency } from '../../../selectors/currencyRateController' ;
1721import { RootState } from '../../../reducers' ;
1822import { getNonEvmNetworkImageSourceByChainId } from '../../../util/networks/customNetworks' ;
@@ -78,7 +82,7 @@ export const useSnapAssetSelectorData = ({
7882 const networks = useSelector ( selectNetworkConfigurations ) ;
7983
8084 const assets = useSelector ( ( state : RootState ) =>
81- selectMultichainTokenListForAccountId ( state , account ?. id )
85+ selectMultichainTokenListForAccountId ( state , account ?. id ) ,
8286 ) as TokenWithFiatAmount [ ] ;
8387
8488 /**
@@ -125,7 +129,9 @@ export const useSnapAssetSelectorData = ({
125129 name : asset . name ,
126130 balance : formatAssetBalance ( asset . balance ) ,
127131 networkName,
128- networkIcon : getNonEvmNetworkImageSourceByChainId ( asset . chainId as CaipChainId ) ,
132+ networkIcon : getNonEvmNetworkImageSourceByChainId (
133+ asset . chainId as CaipChainId ,
134+ ) ,
129135 fiat : formatFiatBalance ( Number ( asset . secondary ) ) ,
130136 chainId : asset . chainId as CaipChainId ,
131137 address : asset . address as CaipAssetType ,
@@ -137,21 +143,26 @@ export const useSnapAssetSelectorData = ({
137143 . map ( ( chainId ) => chainId )
138144 . filter ( ( { chainId } ) => ( chainIds ? chainIds ?. includes ( chainId ) : true ) ) ;
139145
140- // Format the assets
141- const formattedAssets : SnapUIAsset [ ] = assets . map ( formatAsset ) ;
146+ const formattedAssets = useMemo ( ( ) => {
147+ // Filter the assets by the requested chain IDs
148+ const filteredAssets = assets . filter ( ( asset ) =>
149+ requestedChainIds . some ( ( { chainId, chain : { namespace, reference } } ) => {
150+ // Handles the "eip155:0" case
151+ if ( namespace === KnownCaipNamespace . Eip155 && reference === '0' ) {
152+ const { namespace : assetNamepace } = parseCaipChainId ( asset . chainId ) ;
153+ return assetNamepace === namespace ;
154+ }
142155
143- // Filter the assets by the requested chain IDs
144- const filteredAssets = formattedAssets . filter ( ( asset ) =>
145- requestedChainIds . some ( ( { chainId, chain : { namespace, reference } } ) => {
146- // Handles the "eip155:0" case
147- if ( namespace === KnownCaipNamespace . Eip155 && reference === '0' ) {
148- const { namespace : assetNamepace } = parseCaipChainId ( asset . chainId ) ;
149- return assetNamepace === namespace ;
150- }
156+ return chainId === asset . chainId ;
157+ } ) ,
158+ ) ;
151159
152- return chainId === asset . chainId ;
153- } ) ,
154- ) ;
160+ // Format the assets
161+ const formatted : SnapUIAsset [ ] = filteredAssets . map ( formatAsset ) ;
162+
163+ return formatted ;
164+ // eslint-disable-next-line react-hooks/exhaustive-deps
165+ } , [ assets ] ) ;
155166
156- return filteredAssets ;
167+ return formattedAssets ;
157168} ;
0 commit comments