fix(market-depth): make market data up to date, use fixed number of decimals in cumulative vol (#3361)

This commit is contained in:
Bartłomiej Głownia 2023-04-07 19:34:51 +02:00 committed by GitHub
parent 9229e7f686
commit 7accb42793
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 19 deletions

View File

@ -1,6 +1,6 @@
import { memo } from 'react'; import { memo } from 'react';
import { BID_COLOR, ASK_COLOR } from './vol-cell'; import { BID_COLOR, ASK_COLOR } from './vol-cell';
import { addDecimalsFormatNumber } from '@vegaprotocol/utils'; import { addDecimalsFixedFormatNumber } from '@vegaprotocol/utils';
import { NumericCell } from './numeric-cell'; import { NumericCell } from './numeric-cell';
export interface CumulativeVolProps { export interface CumulativeVolProps {
@ -55,7 +55,7 @@ export const CumulativeVol = memo(
( (
<NumericCell <NumericCell
value={Number(indicativeVolume)} value={Number(indicativeVolume)}
valueFormatted={addDecimalsFormatNumber( valueFormatted={addDecimalsFixedFormatNumber(
indicativeVolume, indicativeVolume,
positionDecimalPlaces ?? 0 positionDecimalPlaces ?? 0
)} )}
@ -67,7 +67,7 @@ export const CumulativeVol = memo(
{ask ? ( {ask ? (
<NumericCell <NumericCell
value={ask} value={ask}
valueFormatted={addDecimalsFormatNumber( valueFormatted={addDecimalsFixedFormatNumber(
ask, ask,
positionDecimalPlaces ?? 0 positionDecimalPlaces ?? 0
)} )}
@ -77,7 +77,7 @@ export const CumulativeVol = memo(
{bid ? ( {bid ? (
<NumericCell <NumericCell
value={ask} value={ask}
valueFormatted={addDecimalsFormatNumber( valueFormatted={addDecimalsFixedFormatNumber(
bid, bid,
positionDecimalPlaces ?? 0 positionDecimalPlaces ?? 0
)} )}

View File

@ -48,12 +48,12 @@ export const OrderbookManager = ({ marketId }: OrderbookManagerProps) => {
throttle(() => { throttle(() => {
dataRef.current = { dataRef.current = {
...marketDataRef.current, ...marketDataRef.current,
indicativePrice: marketDataRef.current?.indicativePrice indicativePrice:
? getPriceLevel( marketDataRef.current?.indicativePrice &&
marketDataRef.current.indicativePrice, getPriceLevel(
resolutionRef.current marketDataRef.current.indicativePrice,
) resolutionRef.current
: undefined, ),
midPrice: getMidPrice( midPrice: getMidPrice(
rawDataRef.current?.depth.sell, rawDataRef.current?.depth.sell,
rawDataRef.current?.depth.buy, rawDataRef.current?.depth.buy,
@ -148,13 +148,12 @@ export const OrderbookManager = ({ marketId }: OrderbookManagerProps) => {
variables, variables,
}); });
marketDataRef.current = marketData; if (!marketDataRef.current && marketData) {
marketDataRef.current = marketData;
}
useEffect(() => { useEffect(() => {
const throttleRunner = updateOrderbookData.current; const throttleRunner = updateOrderbookData.current;
if (!marketDataRef.current) {
return;
}
if (!data) { if (!data) {
dataRef.current = { rows: null }; dataRef.current = { rows: null };
setOrderbookData(dataRef.current); setOrderbookData(dataRef.current);
@ -162,10 +161,9 @@ export const OrderbookManager = ({ marketId }: OrderbookManagerProps) => {
} }
dataRef.current = { dataRef.current = {
...marketDataRef.current, ...marketDataRef.current,
indicativePrice: getPriceLevel( indicativePrice:
marketDataRef.current.indicativePrice, marketDataRef.current?.indicativePrice &&
resolution getPriceLevel(marketDataRef.current.indicativePrice, resolution),
),
midPrice: getMidPrice(data.depth.sell, data.depth.buy, resolution), midPrice: getMidPrice(data.depth.sell, data.depth.buy, resolution),
rows: compactRows(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 () => { return () => {
throttleRunner.cancel(); throttleRunner.cancel();
}; };
}, [data, marketData, resolution]); }, [data, resolution]);
useEffect(() => { useEffect(() => {
resolutionRef.current = resolution; resolutionRef.current = resolution;