Skip to content

Commit

Permalink
Filter out favorites from all networks results
Browse files Browse the repository at this point in the history
  • Loading branch information
jinchung committed Dec 30, 2024
1 parent 55bd50e commit 78f7415
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/hooks/useSearchCurrencyList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const abcSort = (list: any[], key?: string) => {
const useSearchCurrencyList = (searchQuery: string) => {
const searching = useMemo(() => searchQuery !== '', [searchQuery]);

const { favoritesMetadata: favoriteMap } = useFavorites();
const { favorites: favoriteAddresses, favoritesMetadata: favoriteMap } = useFavorites();
const unfilteredFavorites = useMemo(() => {
return Object.values(favoriteMap)
.filter(token => token.networks[ChainId.mainnet])
Expand Down Expand Up @@ -104,9 +104,13 @@ const useSearchCurrencyList = (searchQuery: string) => {
})
.slice(0, MAX_VERIFIED_RESULTS);

return [...topResults];
const topResultsWithoutFavorites = topResults.filter(asset => {
return !favoriteAddresses.map(a => a?.toLowerCase()).includes(asset.address?.toLowerCase());
});

return [...topResultsWithoutFavorites];
},
[searchQuery]
[searchQuery, favoriteAddresses]
);

const { data: searchResultAssets, isFetching: loading } = useTokenSearchAllNetworks(
Expand Down

0 comments on commit 78f7415

Please sign in to comment.