Skip to content

Commit

Permalink
Remove filtering of assetToSell from search currency lists (#5921)
Browse files Browse the repository at this point in the history
  • Loading branch information
jinchung authored Jul 9, 2024
1 parent f473b49 commit e15a077
Showing 1 changed file with 8 additions and 26 deletions.
34 changes: 8 additions & 26 deletions src/__swaps__/screens/Swap/hooks/useSearchCurrencyLists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
) || [];

Expand All @@ -65,9 +57,7 @@ const buildListSectionsData = ({
combinedData,
favoritesList,
filteredBridgeAssetAddress,
assetToSellAddress,
}: {
assetToSellAddress: string | undefined;
combinedData: {
bridgeAsset?: SearchAsset;
verifiedAssets?: SearchAsset[];
Expand All @@ -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);
}
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -314,7 +298,6 @@ export function useSearchCurrencyLists() {

return {
results: buildListSectionsData({
assetToSellAddress: state.assetToSellAddress,
combinedData: {
bridgeAsset: bridgeResult,
crosschainExactMatches: crosschainMatches,
Expand All @@ -334,7 +317,6 @@ export function useSearchCurrencyLists() {
memoizedData.filteredBridgeAsset,
query,
selectedOutputChainId.value,
state.assetToSellAddress,
unverifiedAssets,
verifiedAssets,
]);
Expand Down

0 comments on commit e15a077

Please sign in to comment.