Skip to content

Commit

Permalink
fix: duplicate wallet result in Cmd+K search (#1636)
Browse files Browse the repository at this point in the history
  • Loading branch information
magiziz authored Jul 29, 2024
1 parent 295e74c commit 550aa55
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/entries/popup/components/CommandK/useSearchableENSOrAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { truncateAddress } from '~/core/utils/address';
import { isENSAddressFormat } from '~/core/utils/ethereum';
import { isLowerCaseMatch } from '~/core/utils/strings';

import { useContacts } from '../../hooks/useContacts';
import { useDebounce } from '../../hooks/useDebounce';
import { useWallets } from '../../hooks/useWallets';
import { useValidateInput } from '../WatchWallet/WatchWallet';
Expand Down Expand Up @@ -35,6 +36,13 @@ export const useSearchableENSorAddress = ({
const { isFetching, setIsFetching } = useCommandKStatus();
const { allWallets } = useWallets();

const contacts = useContacts();

const allWalletsWithContacts = React.useMemo(
() => [...allWallets, ...contacts],
[contacts, allWallets],
);

const query = searchQuery.trim();
const debouncedSearchQuery = useDebounce(query, 250);

Expand All @@ -47,7 +55,9 @@ export const useSearchableENSorAddress = ({
validation.address &&
!validation.error &&
!isFetchingSearchAssets &&
!allWallets.some((wallet) => wallet.address === validation.address) &&
!allWalletsWithContacts.some((wallet) =>
isLowerCaseMatch(wallet.address, validation.address),
) &&
!assets.some((asset) =>
isLowerCaseMatch(asset.address, validation.address),
)
Expand All @@ -74,7 +84,7 @@ export const useSearchableENSorAddress = ({
isFetchingSearchAssets,
currentPage,
assets,
allWallets,
allWalletsWithContacts,
validation.address,
validation.ensName,
validation.error,
Expand Down

0 comments on commit 550aa55

Please sign in to comment.