Skip to content

Commit

Permalink
subscribe to rates for custom tokens as well
Browse files Browse the repository at this point in the history
  • Loading branch information
mholtzman committed Aug 9, 2023
1 parent e3d9b83 commit b628dc4
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion main/externalData/assets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b628dc4

Please sign in to comment.