From b63d0cec6bbdbbcbca33402d90bc8b5b3524dd7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20G=C5=82ownia?= Date: Tue, 4 Apr 2023 13:40:03 +0200 Subject: [PATCH] fix(market-depth): up to date market data, use fixed number of decimals in cummulative vol --- .../src/lib/cells/cumulative-vol-cell.tsx | 8 +++--- .../src/lib/orderbook-manager.tsx | 28 +++++++++---------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/libs/datagrid/src/lib/cells/cumulative-vol-cell.tsx b/libs/datagrid/src/lib/cells/cumulative-vol-cell.tsx index b5603d38a..2015a08e2 100644 --- a/libs/datagrid/src/lib/cells/cumulative-vol-cell.tsx +++ b/libs/datagrid/src/lib/cells/cumulative-vol-cell.tsx @@ -1,6 +1,6 @@ import { memo } from 'react'; import { BID_COLOR, ASK_COLOR } from './vol-cell'; -import { addDecimalsFormatNumber } from '@vegaprotocol/utils'; +import { addDecimalsFixedFormatNumber } from '@vegaprotocol/utils'; import { NumericCell } from './numeric-cell'; export interface CumulativeVolProps { @@ -55,7 +55,7 @@ export const CumulativeVol = memo( ( { throttle(() => { dataRef.current = { ...marketDataRef.current, - indicativePrice: marketDataRef.current?.indicativePrice - ? getPriceLevel( - marketDataRef.current.indicativePrice, - resolutionRef.current - ) - : undefined, + indicativePrice: + marketDataRef.current?.indicativePrice && + getPriceLevel( + marketDataRef.current.indicativePrice, + resolutionRef.current + ), midPrice: getMidPrice( rawDataRef.current?.depth.sell, rawDataRef.current?.depth.buy, @@ -148,13 +148,12 @@ export const OrderbookManager = ({ marketId }: OrderbookManagerProps) => { variables, }); - marketDataRef.current = marketData; + if (!marketDataRef.current && marketData) { + marketDataRef.current = marketData; + } useEffect(() => { const throttleRunner = updateOrderbookData.current; - if (!marketDataRef.current) { - return; - } if (!data) { dataRef.current = { rows: null }; setOrderbookData(dataRef.current); @@ -162,10 +161,9 @@ export const OrderbookManager = ({ marketId }: OrderbookManagerProps) => { } dataRef.current = { ...marketDataRef.current, - indicativePrice: getPriceLevel( - marketDataRef.current.indicativePrice, - resolution - ), + indicativePrice: + marketDataRef.current?.indicativePrice && + getPriceLevel(marketDataRef.current.indicativePrice, resolution), midPrice: getMidPrice(data.depth.sell, data.depth.buy, resolution), rows: compactRows(data.depth.sell, data.depth.buy, resolution), }; @@ -175,7 +173,7 @@ export const OrderbookManager = ({ marketId }: OrderbookManagerProps) => { return () => { throttleRunner.cancel(); }; - }, [data, marketData, resolution]); + }, [data, resolution]); useEffect(() => { resolutionRef.current = resolution;