Skip to content

Commit

Permalink
fix: search token by symbol for autoimporting
Browse files Browse the repository at this point in the history
  • Loading branch information
shoom3301 committed Oct 16, 2023
1 parent e02d368 commit 45feae5
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions libs/tokens/src/hooks/tokens/useSearchNonExistentToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 45feae5

Please sign in to comment.