Skip to content

Commit

Permalink
Merge branch 'main' into ev/iss659
Browse files Browse the repository at this point in the history
  • Loading branch information
evvvritt committed Sep 13, 2023
2 parents 5b85977 + e4de309 commit b9a79f1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 6 additions & 1 deletion src/lib/utils/fiat-estimates/fiat-estimates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ function _validateSymbol(symbol: string): asserts symbol is SupportedSymbol {
let connection:
| ReturnType<typeof createSocket<typeof BinanceMessage, typeof BinanceCommand>>
| undefined;
const started = writable(false);
const socketOpen = writable(false);

/** Establish a websocket connection and allow tracking prices. */
Expand All @@ -65,6 +66,8 @@ export function start() {
'wss://stream.binance.com:9443/ws/radusdt@ticker',
);

started.set(true);

const { send, subscribe } = connection;

/*
Expand Down Expand Up @@ -95,6 +98,7 @@ export function start() {
export function stop() {
connection?.destroy();
socketOpen.set(false);
started.set(false);
connection = undefined;
}

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit b9a79f1

Please sign in to comment.