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 { Currency, ETHER, Token, currencyEquals } from '@uniswap/sdk-core'
import { useMemo } from 'react'
@ -46,11 +46,6 @@ function useTokensFromMap(tokenMap: TokenAddressMap, includeUserAdded: boolean):
}, [chainId, userAddedTokens, tokenMap, includeUserAdded])
}
export function useDefaultTokens(): { [address: string]: Token } {
const defaultList = useDefaultTokenList()
return useTokensFromMap(defaultList, false)
}
export function useAllTokens(): { [address: string]: Token } {
const allTokens = useCombinedActiveList()
return useTokensFromMap(allTokens, true)

@ -80,6 +80,8 @@ export function listToTokenMap(list: TokenList): TokenAddressMap {
return map
}
const TRANSFORMED_DEFAULT_TOKEN_LIST = listToTokenMap(DEFAULT_TOKEN_LIST)
export function useAllLists(): {
readonly [url: string]: {
readonly current: TokenList | null
@ -93,11 +95,11 @@ export function useAllLists(): {
function combineMaps(map1: TokenAddressMap, map2: TokenAddressMap): TokenAddressMap {
return {
1: { ...map1[1], ...map2[1] },
3: { ...map1[3], ...map2[3] },
4: { ...map1[4], ...map2[4] },
5: { ...map1[5], ...map2[5] },
42: { ...map1[42], ...map2[42] },
[ChainId.MAINNET]: { ...map1[ChainId.MAINNET], ...map2[ChainId.MAINNET] },
[ChainId.RINKEBY]: { ...map1[ChainId.RINKEBY], ...map2[ChainId.RINKEBY] },
[ChainId.ROPSTEN]: { ...map1[ChainId.ROPSTEN], ...map2[ChainId.ROPSTEN] },
[ChainId.KOVAN]: { ...map1[ChainId.KOVAN], ...map2[ChainId.KOVAN] },
[ChainId.GÖRLI]: { ...map1[ChainId.GÖRLI], ...map2[ChainId.GÖRLI] },
}
}
@ -145,8 +147,7 @@ export function useInactiveListUrls(): string[] {
export function useCombinedActiveList(): TokenAddressMap {
const activeListUrls = useActiveListUrls()
const activeTokens = useCombinedTokenMapFromUrls(activeListUrls)
const defaultTokenMap = listToTokenMap(DEFAULT_TOKEN_LIST)
return combineMaps(activeTokens, defaultTokenMap)
return combineMaps(activeTokens, TRANSFORMED_DEFAULT_TOKEN_LIST)
}
// all tokens from inactive lists
@ -155,11 +156,6 @@ export function useCombinedInactiveList(): TokenAddressMap {
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
export function useUnsupportedTokenList(): TokenAddressMap {
// get hard coded unsupported tokens