From e15a077dcda531dea642afef7414ebba822387aa Mon Sep 17 00:00:00 2001 From: Jin Date: Tue, 9 Jul 2024 17:01:35 -0400 Subject: [PATCH] Remove filtering of assetToSell from search currency lists (#5921) --- .../Swap/hooks/useSearchCurrencyLists.ts | 34 +++++-------------- 1 file changed, 8 insertions(+), 26 deletions(-) diff --git a/src/__swaps__/screens/Swap/hooks/useSearchCurrencyLists.ts b/src/__swaps__/screens/Swap/hooks/useSearchCurrencyLists.ts index 7be2e4a2321..63c22e9dc9d 100644 --- a/src/__swaps__/screens/Swap/hooks/useSearchCurrencyLists.ts +++ b/src/__swaps__/screens/Swap/hooks/useSearchCurrencyLists.ts @@ -26,32 +26,24 @@ export interface AssetToBuySection { const MAX_UNVERIFIED_RESULTS = 8; const MAX_VERIFIED_RESULTS = 48; -const filterAssetsFromBridgeAndAssetToSell = ({ +const filterAssetsFromBridge = ({ assets, filteredBridgeAssetAddress, - assetToSellAddress, }: { assets: SearchAsset[] | undefined; filteredBridgeAssetAddress: string | undefined; - assetToSellAddress: string | undefined; -}): SearchAsset[] => - assets?.filter( - curatedAsset => - !isLowerCaseMatch(curatedAsset?.address, filteredBridgeAssetAddress) && !isLowerCaseMatch(curatedAsset?.address, assetToSellAddress) - ) || []; +}): SearchAsset[] => assets?.filter(curatedAsset => !isLowerCaseMatch(curatedAsset?.address, filteredBridgeAssetAddress)) || []; -const filterAssetsFromFavoritesBridgeAndAssetToSell = ({ +const filterAssetsFromFavoritesAndBridge = ({ assets, favoritesList, filteredBridgeAssetAddress, - assetToSellAddress, }: { assets: SearchAsset[] | undefined; favoritesList: SearchAsset[] | undefined; filteredBridgeAssetAddress: string | undefined; - assetToSellAddress: string | undefined; }): SearchAsset[] => - filterAssetsFromBridgeAndAssetToSell({ assets, filteredBridgeAssetAddress, assetToSellAddress })?.filter( + filterAssetsFromBridge({ assets, filteredBridgeAssetAddress })?.filter( curatedAsset => !favoritesList?.some(({ address }) => curatedAsset.address === address || curatedAsset.mainnetAddress === address) ) || []; @@ -65,9 +57,7 @@ const buildListSectionsData = ({ combinedData, favoritesList, filteredBridgeAssetAddress, - assetToSellAddress, }: { - assetToSellAddress: string | undefined; combinedData: { bridgeAsset?: SearchAsset; verifiedAssets?: SearchAsset[]; @@ -91,40 +81,36 @@ const buildListSectionsData = ({ } if (favoritesList?.length) { - const filteredFavorites = filterAssetsFromBridgeAndAssetToSell({ + const filteredFavorites = filterAssetsFromBridge({ assets: favoritesList, filteredBridgeAssetAddress, - assetToSellAddress, }); addSection('favorites', filteredFavorites); } if (combinedData.verifiedAssets?.length) { - const filteredVerified = filterAssetsFromFavoritesBridgeAndAssetToSell({ + const filteredVerified = filterAssetsFromFavoritesAndBridge({ assets: combinedData.verifiedAssets, favoritesList, filteredBridgeAssetAddress, - assetToSellAddress, }); addSection('verified', filteredVerified); } if (!formattedData.length && combinedData.crosschainExactMatches?.length) { - const filteredCrosschain = filterAssetsFromFavoritesBridgeAndAssetToSell({ + const filteredCrosschain = filterAssetsFromFavoritesAndBridge({ assets: combinedData.crosschainExactMatches, favoritesList, filteredBridgeAssetAddress, - assetToSellAddress, }); addSection('other_networks', filteredCrosschain); } if (combinedData.unverifiedAssets?.length) { - const filteredUnverified = filterAssetsFromFavoritesBridgeAndAssetToSell({ + const filteredUnverified = filterAssetsFromFavoritesAndBridge({ assets: combinedData.unverifiedAssets, favoritesList, filteredBridgeAssetAddress, - assetToSellAddress, }); addSection('unverified', filteredUnverified); } @@ -150,7 +136,6 @@ export function useSearchCurrencyLists() { const query = useSwapsStore(state => state.outputSearchQuery.trim().toLowerCase()); const [state, setState] = useState({ - assetToSellAddress: assetToSell.value?.[assetToSell.value?.chainId === ChainId.mainnet ? 'mainnetAddress' : 'address'], fromChainId: assetToSell.value ? assetToSell.value.chainId ?? ChainId.mainnet : undefined, isCrosschainSearch: assetToSell.value ? assetToSell.value.chainId !== selectedOutputChainId.value : false, toChainId: selectedOutputChainId.value ?? ChainId.mainnet, @@ -168,7 +153,6 @@ export function useSearchCurrencyLists() { (current, previous) => { if (previous && (current.isCrosschainSearch !== previous.isCrosschainSearch || current.toChainId !== previous.toChainId)) { runOnJS(debouncedStateSet)({ - assetToSellAddress: assetToSell.value?.[assetToSell.value?.chainId === ChainId.mainnet ? 'mainnetAddress' : 'address'], fromChainId: assetToSell.value ? assetToSell.value.chainId ?? ChainId.mainnet : undefined, isCrosschainSearch: current.isCrosschainSearch, toChainId: current.toChainId, @@ -314,7 +298,6 @@ export function useSearchCurrencyLists() { return { results: buildListSectionsData({ - assetToSellAddress: state.assetToSellAddress, combinedData: { bridgeAsset: bridgeResult, crosschainExactMatches: crosschainMatches, @@ -334,7 +317,6 @@ export function useSearchCurrencyLists() { memoizedData.filteredBridgeAsset, query, selectedOutputChainId.value, - state.assetToSellAddress, unverifiedAssets, verifiedAssets, ]);