Skip to content

Commit

Permalink
fix: tickerSymbolByAddress
Browse files Browse the repository at this point in the history
  • Loading branch information
57Ark committed Dec 11, 2024
1 parent 7b8cd5f commit e477b7b
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions src/tokens/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1762,18 +1762,27 @@ export const tickerInfoTokensByNetwork: Record<

export const tickerTokensByNetwork: Record<
NetworkType,
PartialRecord<TickerToken, Address>
PartialRecord<TickerToken, Array<Address>>
> = 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<TickerToken, Array<Address>> = {};

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<NetworkType, PartialRecord<TickerToken, Address>>;
) as Record<NetworkType, PartialRecord<TickerToken, Array<Address>>>;

export const tokenSymbolByAddress = TypedObjectUtils.entries(
tokenDataByNetwork,
Expand All @@ -1793,10 +1802,11 @@ export const tickerSymbolByAddress: Record<Address, TickerToken> =
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(),
);
Expand Down

0 comments on commit e477b7b

Please sign in to comment.