some list code cleanup

This commit is contained in:
Moody Salem 2021-04-30 22:56:19 -05:00
parent e9a432b58e
commit 91f3e21bd4
No known key found for this signature in database
GPG Key ID: 8CB5CD10385138DB
2 changed files with 9 additions and 18 deletions

@ -1,4 +1,4 @@
import { TokenAddressMap, useDefaultTokenList, useUnsupportedTokenList } from './../state/lists/hooks' import { TokenAddressMap, useUnsupportedTokenList } from './../state/lists/hooks'
import { parseBytes32String } from '@ethersproject/strings' import { parseBytes32String } from '@ethersproject/strings'
import { Currency, ETHER, Token, currencyEquals } from '@uniswap/sdk-core' import { Currency, ETHER, Token, currencyEquals } from '@uniswap/sdk-core'
import { useMemo } from 'react' import { useMemo } from 'react'
@ -46,11 +46,6 @@ function useTokensFromMap(tokenMap: TokenAddressMap, includeUserAdded: boolean):
}, [chainId, userAddedTokens, tokenMap, includeUserAdded]) }, [chainId, userAddedTokens, tokenMap, includeUserAdded])
} }
export function useDefaultTokens(): { [address: string]: Token } {
const defaultList = useDefaultTokenList()
return useTokensFromMap(defaultList, false)
}
export function useAllTokens(): { [address: string]: Token } { export function useAllTokens(): { [address: string]: Token } {
const allTokens = useCombinedActiveList() const allTokens = useCombinedActiveList()
return useTokensFromMap(allTokens, true) return useTokensFromMap(allTokens, true)

@ -80,6 +80,8 @@ export function listToTokenMap(list: TokenList): TokenAddressMap {
return map return map
} }
const TRANSFORMED_DEFAULT_TOKEN_LIST = listToTokenMap(DEFAULT_TOKEN_LIST)
export function useAllLists(): { export function useAllLists(): {
readonly [url: string]: { readonly [url: string]: {
readonly current: TokenList | null readonly current: TokenList | null
@ -93,11 +95,11 @@ export function useAllLists(): {
function combineMaps(map1: TokenAddressMap, map2: TokenAddressMap): TokenAddressMap { function combineMaps(map1: TokenAddressMap, map2: TokenAddressMap): TokenAddressMap {
return { return {
1: { ...map1[1], ...map2[1] }, [ChainId.MAINNET]: { ...map1[ChainId.MAINNET], ...map2[ChainId.MAINNET] },
3: { ...map1[3], ...map2[3] }, [ChainId.RINKEBY]: { ...map1[ChainId.RINKEBY], ...map2[ChainId.RINKEBY] },
4: { ...map1[4], ...map2[4] }, [ChainId.ROPSTEN]: { ...map1[ChainId.ROPSTEN], ...map2[ChainId.ROPSTEN] },
5: { ...map1[5], ...map2[5] }, [ChainId.KOVAN]: { ...map1[ChainId.KOVAN], ...map2[ChainId.KOVAN] },
42: { ...map1[42], ...map2[42] }, [ChainId.GÖRLI]: { ...map1[ChainId.GÖRLI], ...map2[ChainId.GÖRLI] },
} }
} }
@ -145,8 +147,7 @@ export function useInactiveListUrls(): string[] {
export function useCombinedActiveList(): TokenAddressMap { export function useCombinedActiveList(): TokenAddressMap {
const activeListUrls = useActiveListUrls() const activeListUrls = useActiveListUrls()
const activeTokens = useCombinedTokenMapFromUrls(activeListUrls) const activeTokens = useCombinedTokenMapFromUrls(activeListUrls)
const defaultTokenMap = listToTokenMap(DEFAULT_TOKEN_LIST) return combineMaps(activeTokens, TRANSFORMED_DEFAULT_TOKEN_LIST)
return combineMaps(activeTokens, defaultTokenMap)
} }
// all tokens from inactive lists // all tokens from inactive lists
@ -155,11 +156,6 @@ export function useCombinedInactiveList(): TokenAddressMap {
return useCombinedTokenMapFromUrls(allInactiveListUrls) return useCombinedTokenMapFromUrls(allInactiveListUrls)
} }
// used to hide warnings on import for default tokens
export function useDefaultTokenList(): TokenAddressMap {
return listToTokenMap(DEFAULT_TOKEN_LIST)
}
// list of tokens not supported on interface, used to show warnings and prevent swaps and adds // list of tokens not supported on interface, used to show warnings and prevent swaps and adds
export function useUnsupportedTokenList(): TokenAddressMap { export function useUnsupportedTokenList(): TokenAddressMap {
// get hard coded unsupported tokens // get hard coded unsupported tokens