From c026171bd176099a9bb36b0cb2aaec197aac64ae Mon Sep 17 00:00:00 2001 From: Apotheosis <0xapotheosis@gmail.com> Date: Thu, 17 Aug 2023 07:25:26 +1000 Subject: [PATCH] fix: filter sell assets by walletSupportsChain (#5088) * fix: filter sell assets by walletSupportsChain * perf: optimise space complexity --- .../MultiHopTrade/hooks/useSupportedAssets.tsx | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/components/MultiHopTrade/hooks/useSupportedAssets.tsx b/src/components/MultiHopTrade/hooks/useSupportedAssets.tsx index d5d9934da71..987e3912834 100644 --- a/src/components/MultiHopTrade/hooks/useSupportedAssets.tsx +++ b/src/components/MultiHopTrade/hooks/useSupportedAssets.tsx @@ -1,5 +1,8 @@ import type { AssetId } from '@shapeshiftoss/caip' +import { fromAssetId } from '@shapeshiftoss/caip' import { useEffect, useMemo, useState } from 'react' +import { useWallet } from 'hooks/useWallet/useWallet' +import { walletSupportsChain } from 'hooks/useWalletSupportsChain/useWalletSupportsChain' import type { Asset } from 'lib/asset-service' import { getSupportedBuyAssetIds, getSupportedSellAssetIds } from 'lib/swapper/swapper' import { getEnabledSwappers } from 'lib/swapper/utils' @@ -11,6 +14,7 @@ export const useSupportedAssets = () => { const sellAsset = useAppSelector(selectSellAsset) const sortedAssets = useAppSelector(selectAssetsSortedByMarketCapUserCurrencyBalanceAndName) const featureFlags = useAppSelector(selectFeatureFlags) + const wallet = useWallet().state.wallet const enabledSwappers = useMemo(() => getEnabledSwappers(featureFlags, false), [featureFlags]) @@ -22,9 +26,16 @@ export const useSupportedAssets = () => { useEffect(() => { ;(async () => { const assetIds = await getSupportedSellAssetIds(enabledSwappers) - setSupportedSellAssetIds(assetIds) + const filteredAssetIds = new Set() + assetIds.forEach(assetId => { + const chainId = fromAssetId(assetId).chainId + if (walletSupportsChain({ chainId, wallet })) { + filteredAssetIds.add(assetId) + } + }) + setSupportedSellAssetIds(filteredAssetIds) })() - }, [enabledSwappers, sortedAssets]) + }, [enabledSwappers, sortedAssets, wallet]) useEffect(() => { ;(async () => {