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

@ -27,8 +27,7 @@ import { useInfoExplorePageEnabled } from 'featureFlags/flags/infoExplore'
import { useInfoTDPEnabled } from 'featureFlags/flags/infoTDP'
import { TokenPriceQuery } from 'graphql/data/__generated__/types-and-hooks'
import { Chain, TokenQuery, TokenQueryData } from 'graphql/data/Token'
import { QueryToken } from 'graphql/data/Token'
import { getTokenDetailsURL, InterfaceGqlChain, supportedChainIdFromGQLChain } from 'graphql/data/util'
import { getTokenDetailsURL, gqlToCurrency, InterfaceGqlChain, supportedChainIdFromGQLChain } from 'graphql/data/util'
import { useOnGlobalChainSwitch } from 'hooks/useGlobalChainSwitch'
import { UNKNOWN_TOKEN_SYMBOL, useTokenFromActiveNetwork } from 'lib/hooks/useCurrency'
import { Swap } from 'pages/Swap'
@ -83,7 +82,7 @@ function useRelevantToken(
const queryToken = useMemo(() => {
if (!address) return undefined
if (address === NATIVE_CHAIN_ID) return nativeOnChain(pageChainId)
if (tokenQueryData) return new QueryToken(address, tokenQueryData)
if (tokenQueryData) return gqlToCurrency(tokenQueryData)
return undefined
}, [pageChainId, address, tokenQueryData])
// 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 { WrappedTokenInfo } from 'state/lists/wrappedTokenInfo'
import { TokenQuery } from './__generated__/types-and-hooks'
import { supportedChainIdFromGQLChain } from './util'
// The difference between Token and TokenProject:
// 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 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 { 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 { useUnsupportedTokenList } from './../state/lists/hooks'
@ -138,7 +138,7 @@ export function useUnsupportedTokens(): { [address: string]: Token } {
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 inactiveUrls = DEFAULT_INACTIVE_LIST_URLS
const { chainId } = useWeb3React()
@ -146,7 +146,7 @@ export function useSearchInactiveTokenLists(search: string | undefined, minResul
return useMemo(() => {
if (!search || search.trim().length === 0) return []
const tokenFilter = getTokenFilter(search)
const result: WrappedTokenInfo[] = []
const result: TokenFromList[] = []
const addressSet: { [address: string]: true } = {}
for (const url of inactiveUrls) {
const list = lists[url]?.current
@ -154,7 +154,7 @@ export function useSearchInactiveTokenLists(search: string | undefined, minResul
for (const tokenInfo of list.tokens) {
if (tokenInfo.chainId === chainId && tokenFilter(tokenInfo)) {
try {
const wrapped: WrappedTokenInfo = new WrappedTokenInfo(tokenInfo, list)
const wrapped: TokenFromList = new TokenFromList(tokenInfo, list)
if (!(wrapped.address in activeTokens) && !addressSet[wrapped.address]) {
addressSet[wrapped.address] = true
result.push(wrapped)

@ -3,7 +3,7 @@ import { DEFAULT_COLOR } from 'constants/tokenColors'
import useTokenLogoSource from 'hooks/useAssetLogoSource'
import { darken, lighten, rgb } from 'polished'
import { useEffect, useState } from 'react'
import { WrappedTokenInfo } from 'state/lists/wrappedTokenInfo'
import { TokenFromList } from 'state/lists/tokenFromList'
import { useTheme } from 'styled-components'
import { getColor } from 'utils/getColor'
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.
*/
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
try {

@ -3,7 +3,7 @@ import { useWeb3React } from '@web3-react/core'
import { useMemo } from 'react'
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) {
const { chainId } = useWeb3React()
const activeList = useCombinedActiveList()

@ -1,7 +1,7 @@
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
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 map = infos.reduce<Mutable<TokenAddressMap>>((map, info) => {
try {
const token = new WrappedTokenInfo(info, list)
const token = new TokenFromList(info, list)
if (map[token.chainId]?.[token.address] !== undefined) {
console.warn(`Duplicate token skipped: ${token.address}`)
return map

@ -10,7 +10,7 @@ interface TagInfo extends TagDetails {
/**
* 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 isToken = true as const
public readonly list?: TokenList