diff --git a/src/lib/components/aggregate-fiat-estimate/aggregate-fiat-estimate.svelte b/src/lib/components/aggregate-fiat-estimate/aggregate-fiat-estimate.svelte index 5a02a8357..4bc162ce9 100644 --- a/src/lib/components/aggregate-fiat-estimate/aggregate-fiat-estimate.svelte +++ b/src/lib/components/aggregate-fiat-estimate/aggregate-fiat-estimate.svelte @@ -23,7 +23,12 @@ $: knownTokens = tokens.filter((token): token is TokenInfoWrapper => token !== undefined); $: knownSymbols = knownTokens.map((token) => token.info.symbol); - $: fiatEstimates.track(knownSymbols); + const fiatEstimatesStarted = fiatEstimates.started; + $: { + if ($fiatEstimatesStarted) { + fiatEstimates.track(knownSymbols); + } + } $: priceStore = fiatEstimates.price(knownSymbols); diff --git a/src/lib/utils/fiat-estimates/fiat-estimates.ts b/src/lib/utils/fiat-estimates/fiat-estimates.ts index 88c56693c..84f740606 100644 --- a/src/lib/utils/fiat-estimates/fiat-estimates.ts +++ b/src/lib/utils/fiat-estimates/fiat-estimates.ts @@ -54,6 +54,7 @@ function _validateSymbol(symbol: string): asserts symbol is SupportedSymbol { let connection: | ReturnType> | undefined; +const started = writable(false); const socketOpen = writable(false); /** Establish a websocket connection and allow tracking prices. */ @@ -65,6 +66,8 @@ export function start() { 'wss://stream.binance.com:9443/ws/radusdt@ticker', ); + started.set(true); + const { send, subscribe } = connection; /* @@ -95,6 +98,7 @@ export function start() { export function stop() { connection?.destroy(); socketOpen.set(false); + started.set(false); connection = undefined; } @@ -218,13 +222,14 @@ const price = (symbols: string[]) => symbols = symbols.map((symbol) => TOKEN_SUBSTITUTIONS[symbol] || symbol); // Return an object of all the prices for the given symbols. - return Object.fromEntries(symbols.map((symbol) => [symbol, $prices[symbol]])); + return Object.fromEntries(symbols.map((symbol) => [symbol, $prices[symbol] || 'pending'])); }), ); export default { start, stop, + started: { subscribe: started.subscribe }, track, untrack, price,