diff --git a/packages/sdk/src/utils/token.ts b/packages/sdk/src/utils/token.ts index 5f22003fc7..cd089fc104 100644 --- a/packages/sdk/src/utils/token.ts +++ b/packages/sdk/src/utils/token.ts @@ -6,6 +6,7 @@ import { getERC20BytesContract } from '../builtin/internal/erc20bytes_processor' import { BigDecimal } from '../core/big-decimal' import { toBigDecimal } from './conversion' import { utils } from 'ethers' +import { PromiseOrValue } from '../builtin/internal/common' export interface TokenInfo { symbol: string @@ -19,7 +20,19 @@ export const NATIVE_ETH = { name: 'Native ETH', } -const TOKEN_INFOS = new Map() +const TOKEN_INFOS = new Map>() + +async function getTokenInfoPromise( + symbol: PromiseOrValue | string, + name: PromiseOrValue | string, + decimal: PromiseOrValue +): Promise { + return { + symbol: await symbol, + name: await name, + decimal: await decimal, + } +} export async function getERC20TokenInfo(tokenAddress: string, chainId = 1): Promise { const key = chainId + tokenAddress @@ -47,7 +60,8 @@ export async function getERC20TokenInfo(tokenAddress: string, chainId = 1): Prom } const decimal = await contract.decimals() - const info: TokenInfo = { name, symbol, decimal } + const info = getTokenInfoPromise(symbol, name, decimal) + TOKEN_INFOS.set(key, info) return info } catch (e) {