From e477b7b1f3aef56873d019505e6305907b90503c Mon Sep 17 00:00:00 2001 From: Arkhip Vouba <80775286+57Ark@users.noreply.github.com> Date: Wed, 11 Dec 2024 16:07:34 +0100 Subject: [PATCH] fix: tickerSymbolByAddress --- src/tokens/token.ts | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/tokens/token.ts b/src/tokens/token.ts index 4e4b0e4..e973ae9 100644 --- a/src/tokens/token.ts +++ b/src/tokens/token.ts @@ -1762,18 +1762,27 @@ export const tickerInfoTokensByNetwork: Record< export const tickerTokensByNetwork: Record< NetworkType, - PartialRecord + PartialRecord> > = Object.fromEntries( Object.entries(tickerInfoTokensByNetwork).map(([network, data]) => { if (Object.values(data).length === 0) return [network, {}]; - const addrs = Object.fromEntries( - Object.values(data) - .map(d => d.map(val => [val.symbol, val.address])) - .flat(), + const addrs: PartialRecord> = {}; + + Object.values(data).forEach(d => + d.forEach(val => { + if (Object.keys(addrs).includes(val.symbol)) { + if (!addrs[val.symbol]?.includes(val.address)) { + addrs[val.symbol]?.push(val.address); + } + } else { + addrs[val.symbol] = [val.address]; + } + }), ); + return [network, addrs]; }), -) as Record>; +) as Record>>; export const tokenSymbolByAddress = TypedObjectUtils.entries( tokenDataByNetwork, @@ -1793,10 +1802,11 @@ export const tickerSymbolByAddress: Record = Object.fromEntries( Object.values(tickerTokensByNetwork) .map(en => - Object.entries(en).map(([symbol, addr]) => [ - addr.toLowerCase() as Address, - symbol, - ]), + Object.entries(en) + .map(([symbol, addresses]) => + addresses.map(addr => [addr.toLowerCase() as Address, symbol]), + ) + .flat(), ) .flat(), );