From b628dc4501afec161f7a98fd997c0f0a80f7c258 Mon Sep 17 00:00:00 2001 From: Matt Holtzman Date: Wed, 9 Aug 2023 12:16:44 -0400 Subject: [PATCH] subscribe to rates for custom tokens as well --- main/externalData/assets/index.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/main/externalData/assets/index.ts b/main/externalData/assets/index.ts index 636782aa2..b3da49efb 100644 --- a/main/externalData/assets/index.ts +++ b/main/externalData/assets/index.ts @@ -18,6 +18,7 @@ export default function rates(pylon: Pylon, store: Store) { const storeApi = { getKnownTokens: (address?: Address) => ((address && store('main.tokens.known', address)) || []) as Token[], + getCustomTokens: () => (store('main.tokens.custom') || []) as Token[], setNativeCurrencyData: (chainId: number, currencyData: NativeCurrency) => store.setNativeCurrencyData('ethereum', chainId, currencyData), setNativeCurrencyRate: (chainId: number, rate: Rate) => @@ -67,7 +68,13 @@ export default function rates(pylon: Pylon, store: Store) { function updateSubscription(chains: number[], address?: Address) { const subscribedCurrencies = chains.map((chainId) => ({ type: AssetType.NativeCurrency, chainId })) const knownTokens = storeApi.getKnownTokens(address).filter((token) => chains.includes(token.chainId)) - const subscribedTokens = knownTokens.map((token) => ({ + const customTokens = storeApi + .getCustomTokens() + .filter( + (token) => !knownTokens.some((kt) => kt.address === token.address && kt.chainId === token.chainId) + ) + + const subscribedTokens = [...knownTokens, ...customTokens].map((token) => ({ type: AssetType.Token, chainId: token.chainId, address: token.address