Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
brtkx committed Jul 22, 2024
1 parent 976617c commit 5e16815
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
25 changes: 9 additions & 16 deletions packages/arb-token-bridge-ui/src/hooks/useSelectedToken.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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',
Expand All @@ -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<ERC20BridgeToken | null> =
useCallback(async () => {
Expand All @@ -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<ERC20BridgeToken | null>(
[
'useSelectedToken',
parentChain.id,
childChain.id,
tokenFromSearchParams,
tokensFromLists,
tokensFromUser
tokenList.data
],
fetcher
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 5e16815

Please sign in to comment.