Skip to content

Commit

Permalink
fix: filter sell assets by walletSupportsChain (#5088)
Browse files Browse the repository at this point in the history
* fix: filter sell assets by walletSupportsChain

* perf: optimise space complexity
  • Loading branch information
0xApotheosis authored Aug 16, 2023
1 parent 1800acd commit c026171
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/components/MultiHopTrade/hooks/useSupportedAssets.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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])

Expand All @@ -22,9 +26,16 @@ export const useSupportedAssets = () => {
useEffect(() => {
;(async () => {
const assetIds = await getSupportedSellAssetIds(enabledSwappers)
setSupportedSellAssetIds(assetIds)
const filteredAssetIds = new Set<AssetId>()
assetIds.forEach(assetId => {
const chainId = fromAssetId(assetId).chainId
if (walletSupportsChain({ chainId, wallet })) {
filteredAssetIds.add(assetId)
}
})
setSupportedSellAssetIds(filteredAssetIds)
})()
}, [enabledSwappers, sortedAssets])
}, [enabledSwappers, sortedAssets, wallet])

useEffect(() => {
;(async () => {
Expand Down

0 comments on commit c026171

Please sign in to comment.