diff --git a/packages/sdk-ts/src/service/TokenFactoryStatic.ts b/packages/sdk-ts/src/service/TokenFactoryStatic.ts index a7bd3e62c..92d79cd57 100644 --- a/packages/sdk-ts/src/service/TokenFactoryStatic.ts +++ b/packages/sdk-ts/src/service/TokenFactoryStatic.ts @@ -9,6 +9,7 @@ export class TokenFactoryStatic { public registry: TokenStatic[] public tokensByDenom: Record public tokensBySymbol: Record + public tokensByAddress: Record constructor(registry: TokenStatic[]) { this.registry = registry @@ -27,6 +28,16 @@ export class TokenFactoryStatic { return { ...list, [symbol]: [...(list[symbol] || []), token] } }, {} as Record) + + this.tokensByAddress = registry.reduce((list, token) => { + const address = token.address.toLowerCase() + + if (!address) { + return list + } + + return { ...list, [address]: [...(list[address] || []), token] } + }, {} as Record) } toToken(denom: string): TokenStatic | undefined { @@ -70,9 +81,11 @@ export class TokenFactoryStatic { return token || sortedTokens[0] } - getMetaByDenomOrAddress(denom: string): TokenStatic | undefined { - const formattedDenom = denom.toLowerCase() + getMetaByDenomOrAddress(denomOrAddress: string): TokenStatic | undefined { + const formattedDenom = denomOrAddress.toLowerCase() - return this.tokensByDenom[formattedDenom] + return ( + this.tokensByDenom[formattedDenom] || this.tokensByAddress[formattedDenom] + ) } }