From 5e16815e23a934305414b4fd64be6ea5724ad8af Mon Sep 17 00:00:00 2001 From: Bartek Date: Mon, 22 Jul 2024 20:54:32 +0200 Subject: [PATCH] fixes --- .../src/hooks/useSelectedToken.ts | 25 +++++++------------ .../tests/e2e/specs/importToken.cy.ts | 6 ++--- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/packages/arb-token-bridge-ui/src/hooks/useSelectedToken.ts b/packages/arb-token-bridge-ui/src/hooks/useSelectedToken.ts index e82444bd6d..82ad0e882a 100644 --- a/packages/arb-token-bridge-ui/src/hooks/useSelectedToken.ts +++ b/packages/arb-token-bridge-ui/src/hooks/useSelectedToken.ts @@ -1,10 +1,6 @@ import { useCallback } from 'react' import useSWRImmutable from 'swr/immutable' -import { - useTokensFromLists, - useTokensFromUser -} from '../components/TransferPanel/TokenSearchUtils' import { useTokenFromSearchParams } from '../components/TransferPanel/TransferPanelUtils' import { ERC20BridgeToken, TokenType } from './arbTokenBridge.types' import { @@ -21,6 +17,7 @@ import { CommonAddress } from '../util/CommonAddressUtils' import { useNetworksRelationship } from './useNetworksRelationship' import { Provider } from '@ethersproject/providers' import { getChainIdFromProvider } from '@/token-bridge-sdk/utils' +import { useTokenLists } from './useTokenLists' const commonUSDC = { name: 'USD Coin', @@ -33,11 +30,10 @@ const commonUSDC = { export const useSelectedToken = () => { const { tokenFromSearchParams, setTokenQueryParam } = useTokenFromSearchParams() - const tokensFromLists = useTokensFromLists() - const tokensFromUser = useTokensFromUser() const [networks] = useNetworks() const { childChain, childChainProvider, parentChain, parentChainProvider } = useNetworksRelationship(networks) + const tokenList = useTokenLists(childChain.id) const fetcher: () => Promise = useCallback(async () => { @@ -53,30 +49,27 @@ export const useSelectedToken = () => { }) } - if (!tokensFromLists || !tokensFromUser) { + const tokens = tokenList.data?.flat() + + if (!tokens) { return null } - return ( - tokensFromLists[tokenFromSearchParams] || - tokensFromUser[tokenFromSearchParams] || - null - ) + return null }, [ childChainProvider, parentChainProvider, tokenFromSearchParams, - tokensFromLists, - tokensFromUser + tokenList.data ]) const { data } = useSWRImmutable( [ + 'useSelectedToken', parentChain.id, childChain.id, tokenFromSearchParams, - tokensFromLists, - tokensFromUser + tokenList.data ], fetcher ) diff --git a/packages/arb-token-bridge-ui/tests/e2e/specs/importToken.cy.ts b/packages/arb-token-bridge-ui/tests/e2e/specs/importToken.cy.ts index d74b4a4f7b..b2014b43d7 100644 --- a/packages/arb-token-bridge-ui/tests/e2e/specs/importToken.cy.ts +++ b/packages/arb-token-bridge-ui/tests/e2e/specs/importToken.cy.ts @@ -194,7 +194,7 @@ describe('Import token', () => { // waiting for metamask notification to disappear // eslint-disable-next-line - cy.wait(15_000) + cy.wait(30_000) // Modal is displayed cy.get('h2') @@ -235,7 +235,7 @@ describe('Import token', () => { // waiting for metamask notification to disappear // eslint-disable-next-line - cy.wait(15_000) + cy.wait(30_000) // Modal is displayed cy.get('h2') @@ -281,7 +281,7 @@ describe('Import token', () => { // make sure the import dialog appears // eslint-disable-next-line - cy.wait(15_000) + cy.wait(30_000) // Modal is displayed cy.get('h2').contains(/invalid token address/i)