Skip to content

Commit

Permalink
fix: allow empty token list (#239)
Browse files Browse the repository at this point in the history
* feat: export token list options

* fix: allow empty list
  • Loading branch information
zzmp authored Oct 6, 2022
1 parent ea28555 commit a32b348
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/hooks/useTokenList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import { validateTokens } from './validateTokenList'

export { useQueryTokens } from './useQueryTokens'

export const DEFAULT_TOKEN_LIST = 'https://gateway.ipfs.io/ipns/tokens.uniswap.org'
export const UNISWAP_TOKEN_LIST = 'https://gateway.ipfs.io/ipns/tokens.uniswap.org'
export const EMPTY_TOKEN_LIST = []

const MISSING_PROVIDER = Symbol()
const ChainTokenMapContext = createContext<ChainTokenMap | undefined | typeof MISSING_PROVIDER>(MISSING_PROVIDER)
Expand Down Expand Up @@ -54,7 +55,7 @@ export function useTokenMap(): TokenMap {
}

export function TokenListProvider({
list = DEFAULT_TOKEN_LIST,
list = UNISWAP_TOKEN_LIST,
children,
}: PropsWithChildren<{ list?: string | TokenInfo[] }>) {
// Error boundaries will not catch (non-rendering) async errors, but it should still be shown
Expand Down Expand Up @@ -92,7 +93,9 @@ export function TokenListProvider({
if (typeof list === 'string') {
tokens = await fetchTokenList(list, resolver)
} else {
tokens = await validateTokens(list)
// Empty lists will fail validation, but are valid (eg EMPTY_TOKEN_LIST)
// for integrators using their own token selection UI.
tokens = list.length > 0 ? await validateTokens(list) : EMPTY_TOKEN_LIST
}
// tokensToChainTokenMap also caches the fetched tokens, so it must be invoked even if stale.
const map = tokensToChainTokenMap(tokens)
Expand Down
1 change: 1 addition & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export type { FeeOptions } from 'hooks/swap/useSyncConvenienceFee'
export type { DefaultAddress, TokenDefaults } from 'hooks/swap/useSyncTokenDefaults'
export type { OnTxFail, OnTxSubmit, OnTxSuccess, TransactionEventHandlers } from 'hooks/transactions'
export type { OnConnectWalletClick, WidgetEventHandlers } from 'hooks/useSyncWidgetEventHandlers'
export { EMPTY_TOKEN_LIST, UNISWAP_TOKEN_LIST } from 'hooks/useTokenList'
export type { JsonRpcConnectionMap } from 'hooks/web3/useJsonRpcUrlsMap'
export type {
OnAmountChange,
Expand Down

1 comment on commit a32b348

@vercel
Copy link

@vercel vercel bot commented on a32b348 Oct 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

widgets – ./

widgets-uniswap.vercel.app
widgets-git-main-uniswap.vercel.app
widgets-seven-tau.vercel.app

Please sign in to comment.