From 45feae52fbedb76b946883dea1d7da9d62f1b7d1 Mon Sep 17 00:00:00 2001 From: Alexandr Kazachenko Date: Mon, 16 Oct 2023 17:59:01 +0600 Subject: [PATCH] fix: search token by symbol for autoimporting --- .../src/hooks/tokens/useSearchNonExistentToken.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/libs/tokens/src/hooks/tokens/useSearchNonExistentToken.ts b/libs/tokens/src/hooks/tokens/useSearchNonExistentToken.ts index b592066ed6..5d5301873c 100644 --- a/libs/tokens/src/hooks/tokens/useSearchNonExistentToken.ts +++ b/libs/tokens/src/hooks/tokens/useSearchNonExistentToken.ts @@ -2,20 +2,18 @@ import { useAtomValue } from 'jotai' import { useMemo } from 'react' import { TokenWithLogo } from '@cowprotocol/common-const' -import { isAddress, isTruthy } from '@cowprotocol/common-utils' +import { isTruthy } from '@cowprotocol/common-utils' import { tokenListsUpdatingAtom } from '../../state/tokenLists/tokenListsStateAtom' -import { useTokensByAddressMap } from './useTokensByAddressMap' import { useSearchToken } from './useSearchToken' +import { useTokenBySymbolOrAddress } from './useTokenBySymbolOrAddress' -export function useSearchNonExistentToken(tokenAddress: string | null): TokenWithLogo | null { +export function useSearchNonExistentToken(tokenId: string | null): TokenWithLogo | null { const tokenListsUpdating = useAtomValue(tokenListsUpdatingAtom) - const allTokens = useTokensByAddressMap() - const isNotAddress = !isAddress(tokenAddress) - const existingToken = tokenAddress ? allTokens[tokenAddress.toLowerCase()] : null + const existingToken = useTokenBySymbolOrAddress(tokenId) - const inputTokenToSearch = tokenListsUpdating || existingToken || !tokenAddress || isNotAddress ? null : tokenAddress + const inputTokenToSearch = tokenListsUpdating || existingToken ? null : tokenId const foundToken = useSearchToken(inputTokenToSearch)