Skip to content

Commit

Permalink
fix: update the tokenList cache in universal pages
Browse files Browse the repository at this point in the history
  • Loading branch information
chef-eric committed Sep 30, 2024
1 parent 166bb4a commit fc37fff
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions apps/web/src/config/constants/exchange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,4 @@ export const GENERIC_GAS_LIMIT_ORDER_EXECUTION = 500000n
export const LIMIT_ORDERS_DOCS_URL = 'https://docs.pancakeswap.finance/products/pancakeswap-exchange/limit-orders'

export const EXCHANGE_PAGE_PATHS = ['/swap', '/limit-orders', 'liquidity', '/add', '/find', '/remove', '/stable', '/v2']
export const UNIVERSAL_PAGE_PATHS = ['/liquidity/pools', '/liquidity/positions']
6 changes: 3 additions & 3 deletions apps/web/src/state/lists/updater.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getVersionUpgrade, VersionUpgrade } from '@pancakeswap/token-lists'
import { acceptListUpdate, updateListVersion, useFetchListCallback } from '@pancakeswap/token-lists/react'
import { useQuery } from '@tanstack/react-query'
import { EXCHANGE_PAGE_PATHS } from 'config/constants/exchange'
import { EXCHANGE_PAGE_PATHS, UNIVERSAL_PAGE_PATHS } from 'config/constants/exchange'
import { UNSUPPORTED_LIST_URLS } from 'config/constants/lists'
import { useActiveChainId } from 'hooks/useActiveChainId'
import { useRouter } from 'next/router'
Expand All @@ -21,7 +21,7 @@ export function UpdaterByChainId({ chainId }: { chainId: number }): null {
const [listState, dispatch] = useListState()
const router = useRouter()
const includeListUpdater = useMemo(() => {
return EXCHANGE_PAGE_PATHS.some((item) => {
return [...EXCHANGE_PAGE_PATHS, ...UNIVERSAL_PAGE_PATHS].some((item) => {
return router.pathname.startsWith(item)
})
}, [router.pathname])
Expand Down Expand Up @@ -61,7 +61,7 @@ export function UpdaterByChainId({ chainId }: { chainId: number }): null {
})

useQuery({
queryKey: ['token-list'],
queryKey: ['token-list', chainId],

queryFn: async () => {
return Promise.all(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useMemo } from 'react'
import { selectorByUrlsAtom } from 'state/lists/hooks'
import { SUGGESTED_BASES } from 'config/constants/exchange'
import { ChainId, ERC20Token, Native } from '@pancakeswap/sdk'
import { UpdaterByChainId } from 'state/lists/updater'
import type { TokenInfo } from '@pancakeswap/token-lists'
import {
PANCAKE_ARB_DEFAULT,
Expand Down Expand Up @@ -52,6 +53,8 @@ export const useTokensFromUrls = (urls: string[]) => {

export const useMultiChainsTokens = () => {
const { orderedChainIds } = useOrderChainIds()
orderedChainIds.forEach((chainId) => UpdaterByChainId({ chainId }))

const suggestedTokens = useMemo(
() => flatMap(orderedChainIds, (id) => [Native.onChain(id).wrapped].concat(SUGGESTED_BASES[id])),
[orderedChainIds],
Expand Down

0 comments on commit fc37fff

Please sign in to comment.