fix: rename WrappedTokenInfo class (#7495)

* fix: rename WrappedTokenInfo class

* delete old wrappedTokenInfo file

* rename to TokenFromList

* move back to state/lists

* appease linter

* fix nftlistrow
This commit is contained in:
Kristie Huang 2023-11-06 16:15:41 -05:00 committed by GitHub
parent 5cbc56cf65
commit 769a7ab9b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 16 additions and 37 deletions

@ -17,7 +17,7 @@ import { ThemedText } from 'theme/components'
import { NumberType, useFormatter } from 'utils/formatNumbers' import { NumberType, useFormatter } from 'utils/formatNumbers'
import { useIsUserAddedToken } from '../../../hooks/Tokens' import { useIsUserAddedToken } from '../../../hooks/Tokens'
import { WrappedTokenInfo } from '../../../state/lists/wrappedTokenInfo' import { TokenFromList } from '../../../state/lists/tokenFromList'
import Column, { AutoColumn } from '../../Column' import Column, { AutoColumn } from '../../Column'
import CurrencyLogo from '../../Logo/CurrencyLogo' import CurrencyLogo from '../../Logo/CurrencyLogo'
import Row, { RowFixed } from '../../Row' import Row, { RowFixed } from '../../Row'
@ -86,7 +86,7 @@ const TagContainer = styled.div`
` `
function TokenTags({ currency }: { currency: Currency }) { function TokenTags({ currency }: { currency: Currency }) {
if (!(currency instanceof WrappedTokenInfo)) { if (!(currency instanceof TokenFromList)) {
return null return null
} }
@ -247,7 +247,7 @@ export default function CurrencyList({
}: { }: {
height: number height: number
currencies: Currency[] currencies: Currency[]
otherListTokens?: WrappedTokenInfo[] otherListTokens?: TokenFromList[]
selectedCurrency?: Currency | null selectedCurrency?: Currency | null
onCurrencySelect: (currency: Currency, hasWarning?: boolean) => void onCurrencySelect: (currency: Currency, hasWarning?: boolean) => void
otherCurrency?: Currency | null otherCurrency?: Currency | null

@ -27,8 +27,7 @@ import { useInfoExplorePageEnabled } from 'featureFlags/flags/infoExplore'
import { useInfoTDPEnabled } from 'featureFlags/flags/infoTDP' import { useInfoTDPEnabled } from 'featureFlags/flags/infoTDP'
import { TokenPriceQuery } from 'graphql/data/__generated__/types-and-hooks' import { TokenPriceQuery } from 'graphql/data/__generated__/types-and-hooks'
import { Chain, TokenQuery, TokenQueryData } from 'graphql/data/Token' import { Chain, TokenQuery, TokenQueryData } from 'graphql/data/Token'
import { QueryToken } from 'graphql/data/Token' import { getTokenDetailsURL, gqlToCurrency, InterfaceGqlChain, supportedChainIdFromGQLChain } from 'graphql/data/util'
import { getTokenDetailsURL, InterfaceGqlChain, supportedChainIdFromGQLChain } from 'graphql/data/util'
import { useOnGlobalChainSwitch } from 'hooks/useGlobalChainSwitch' import { useOnGlobalChainSwitch } from 'hooks/useGlobalChainSwitch'
import { UNKNOWN_TOKEN_SYMBOL, useTokenFromActiveNetwork } from 'lib/hooks/useCurrency' import { UNKNOWN_TOKEN_SYMBOL, useTokenFromActiveNetwork } from 'lib/hooks/useCurrency'
import { Swap } from 'pages/Swap' import { Swap } from 'pages/Swap'
@ -83,7 +82,7 @@ function useRelevantToken(
const queryToken = useMemo(() => { const queryToken = useMemo(() => {
if (!address) return undefined if (!address) return undefined
if (address === NATIVE_CHAIN_ID) return nativeOnChain(pageChainId) if (address === NATIVE_CHAIN_ID) return nativeOnChain(pageChainId)
if (tokenQueryData) return new QueryToken(address, tokenQueryData) if (tokenQueryData) return gqlToCurrency(tokenQueryData)
return undefined return undefined
}, [pageChainId, address, tokenQueryData]) }, [pageChainId, address, tokenQueryData])
// fetches on-chain token if query data is missing and page chain matches global chain (else fetch won't work) // fetches on-chain token if query data is missing and page chain matches global chain (else fetch won't work)

@ -1,9 +1,6 @@
import { DEFAULT_ERC20_DECIMALS } from 'constants/tokens'
import gql from 'graphql-tag' import gql from 'graphql-tag'
import { WrappedTokenInfo } from 'state/lists/wrappedTokenInfo'
import { TokenQuery } from './__generated__/types-and-hooks' import { TokenQuery } from './__generated__/types-and-hooks'
import { supportedChainIdFromGQLChain } from './util'
// The difference between Token and TokenProject: // The difference between Token and TokenProject:
// Token: an on-chain entity referring to a contract (e.g. uni token on ethereum 0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984) // Token: an on-chain entity referring to a contract (e.g. uni token on ethereum 0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984)
@ -104,20 +101,3 @@ gql`
export type { Chain, TokenQuery } from './__generated__/types-and-hooks' export type { Chain, TokenQuery } from './__generated__/types-and-hooks'
export type TokenQueryData = TokenQuery['token'] export type TokenQueryData = TokenQuery['token']
// TODO: Return a QueryToken from useTokenQuery instead of TokenQueryData to make it more usable in Currency-centric interfaces.
export class QueryToken extends WrappedTokenInfo {
constructor(address: string, data: NonNullable<TokenQueryData>, logoSrc?: string) {
const chainId = supportedChainIdFromGQLChain(data.chain)
if (chainId) {
super({
chainId,
address,
decimals: data.decimals ?? DEFAULT_ERC20_DECIMALS,
symbol: data.symbol ?? '',
name: data.name ?? '',
logoURI: logoSrc ?? data.project?.logoUrl ?? undefined,
})
}
}
}

@ -10,7 +10,7 @@ import { useAppSelector } from 'state/hooks'
import { isL2ChainId } from 'utils/chains' import { isL2ChainId } from 'utils/chains'
import { useAllLists, useCombinedActiveList, useCombinedTokenMapFromUrls } from '../state/lists/hooks' import { useAllLists, useCombinedActiveList, useCombinedTokenMapFromUrls } from '../state/lists/hooks'
import { WrappedTokenInfo } from '../state/lists/wrappedTokenInfo' import { TokenFromList } from '../state/lists/tokenFromList'
import { deserializeToken, useUserAddedTokens } from '../state/user/hooks' import { deserializeToken, useUserAddedTokens } from '../state/user/hooks'
import { useUnsupportedTokenList } from './../state/lists/hooks' import { useUnsupportedTokenList } from './../state/lists/hooks'
@ -138,7 +138,7 @@ export function useUnsupportedTokens(): { [address: string]: Token } {
return { ...unsupportedTokens, ...l2InferredBlockedTokens } return { ...unsupportedTokens, ...l2InferredBlockedTokens }
} }
export function useSearchInactiveTokenLists(search: string | undefined, minResults = 10): WrappedTokenInfo[] { export function useSearchInactiveTokenLists(search: string | undefined, minResults = 10): TokenFromList[] {
const lists = useAllLists() const lists = useAllLists()
const inactiveUrls = DEFAULT_INACTIVE_LIST_URLS const inactiveUrls = DEFAULT_INACTIVE_LIST_URLS
const { chainId } = useWeb3React() const { chainId } = useWeb3React()
@ -146,7 +146,7 @@ export function useSearchInactiveTokenLists(search: string | undefined, minResul
return useMemo(() => { return useMemo(() => {
if (!search || search.trim().length === 0) return [] if (!search || search.trim().length === 0) return []
const tokenFilter = getTokenFilter(search) const tokenFilter = getTokenFilter(search)
const result: WrappedTokenInfo[] = [] const result: TokenFromList[] = []
const addressSet: { [address: string]: true } = {} const addressSet: { [address: string]: true } = {}
for (const url of inactiveUrls) { for (const url of inactiveUrls) {
const list = lists[url]?.current const list = lists[url]?.current
@ -154,7 +154,7 @@ export function useSearchInactiveTokenLists(search: string | undefined, minResul
for (const tokenInfo of list.tokens) { for (const tokenInfo of list.tokens) {
if (tokenInfo.chainId === chainId && tokenFilter(tokenInfo)) { if (tokenInfo.chainId === chainId && tokenFilter(tokenInfo)) {
try { try {
const wrapped: WrappedTokenInfo = new WrappedTokenInfo(tokenInfo, list) const wrapped: TokenFromList = new TokenFromList(tokenInfo, list)
if (!(wrapped.address in activeTokens) && !addressSet[wrapped.address]) { if (!(wrapped.address in activeTokens) && !addressSet[wrapped.address]) {
addressSet[wrapped.address] = true addressSet[wrapped.address] = true
result.push(wrapped) result.push(wrapped)

@ -3,7 +3,7 @@ import { DEFAULT_COLOR } from 'constants/tokenColors'
import useTokenLogoSource from 'hooks/useAssetLogoSource' import useTokenLogoSource from 'hooks/useAssetLogoSource'
import { darken, lighten, rgb } from 'polished' import { darken, lighten, rgb } from 'polished'
import { useEffect, useState } from 'react' import { useEffect, useState } from 'react'
import { WrappedTokenInfo } from 'state/lists/wrappedTokenInfo' import { TokenFromList } from 'state/lists/tokenFromList'
import { useTheme } from 'styled-components' import { useTheme } from 'styled-components'
import { getColor } from 'utils/getColor' import { getColor } from 'utils/getColor'
import { hex } from 'wcag-contrast' import { hex } from 'wcag-contrast'
@ -35,7 +35,7 @@ function URIForEthToken(address: string) {
* @returns {Promise< | null>} A promise that resolves to a color string or null if color cannot be determined. * @returns {Promise< | null>} A promise that resolves to a color string or null if color cannot be determined.
*/ */
async function getColorFromToken(token: Token, primarySrc?: string): Promise<string | null> { async function getColorFromToken(token: Token, primarySrc?: string): Promise<string | null> {
const wrappedToken = token as WrappedTokenInfo const wrappedToken = token as TokenFromList
let color: string | null = null let color: string | null = null
try { try {

@ -3,7 +3,7 @@ import { useWeb3React } from '@web3-react/core'
import { useMemo } from 'react' import { useMemo } from 'react'
import { useCombinedActiveList } from 'state/lists/hooks' import { useCombinedActiveList } from 'state/lists/hooks'
/** Returns a WrappedTokenInfo from the active token lists when possible, or the passed token otherwise. */ /** Returns a TokenFromList from the active token lists when possible, or the passed token otherwise. */
export function useTokenInfoFromActiveList(currency: Currency) { export function useTokenInfoFromActiveList(currency: Currency) {
const { chainId } = useWeb3React() const { chainId } = useWeb3React()
const activeList = useCombinedActiveList() const activeList = useCombinedActiveList()

@ -1,7 +1,7 @@
import { TokenInfo, TokenList } from '@uniswap/token-lists' import { TokenInfo, TokenList } from '@uniswap/token-lists'
import { WrappedTokenInfo } from 'state/lists/wrappedTokenInfo' import { TokenFromList } from 'state/lists/tokenFromList'
type TokenMap = Readonly<{ [tokenAddress: string]: { token: WrappedTokenInfo; list?: TokenList } }> type TokenMap = Readonly<{ [tokenAddress: string]: { token: TokenFromList; list?: TokenList } }>
// TODO(WEB-2347): replace usage of the misnomered TokenAddressMap w/ ChainTokenMap from src/hooks/Tokens.ts // TODO(WEB-2347): replace usage of the misnomered TokenAddressMap w/ ChainTokenMap from src/hooks/Tokens.ts
export type TokenAddressMap = Readonly<{ [chainId: number]: TokenMap }> export type TokenAddressMap = Readonly<{ [chainId: number]: TokenMap }>
@ -18,7 +18,7 @@ export function tokensToChainTokenMap(tokens: TokenList | TokenInfo[]): TokenAdd
const [list, infos] = Array.isArray(tokens) ? [undefined, tokens] : [tokens, tokens.tokens] const [list, infos] = Array.isArray(tokens) ? [undefined, tokens] : [tokens, tokens.tokens]
const map = infos.reduce<Mutable<TokenAddressMap>>((map, info) => { const map = infos.reduce<Mutable<TokenAddressMap>>((map, info) => {
try { try {
const token = new WrappedTokenInfo(info, list) const token = new TokenFromList(info, list)
if (map[token.chainId]?.[token.address] !== undefined) { if (map[token.chainId]?.[token.address] !== undefined) {
console.warn(`Duplicate token skipped: ${token.address}`) console.warn(`Duplicate token skipped: ${token.address}`)
return map return map

@ -10,7 +10,7 @@ interface TagInfo extends TagDetails {
/** /**
* Token instances created from token info on a token list. * Token instances created from token info on a token list.
*/ */
export class WrappedTokenInfo implements Token { export class TokenFromList implements Token {
public readonly isNative = false as const public readonly isNative = false as const
public readonly isToken = true as const public readonly isToken = true as const
public readonly list?: TokenList public readonly list?: TokenList