25699b6283
* feat(#1643): add grid set filter, amend filters in orders table * feat(#1643): strictly type variables in orders data provider * feat(#1643): add date range param to orders query * feat(#1643): add date range filter * feat(#1643): handle data provider updates after variables change in ag-grid infinite row model * feat(#1643): fix unit tests * feat(#1643): use DateRangeFilter in positions table instead of agDateColumnFilter * feat(#1643): add date range filter support to orders data provider * feat(#1643): fix update functions * feat(#1643): remove sortable from orders list columns * chore: remove console.log
66 lines
1.8 KiB
TypeScript
66 lines
1.8 KiB
TypeScript
import { useCallback, useMemo, useRef, useState } from 'react';
|
|
import throttle from 'lodash/throttle';
|
|
import {
|
|
addDecimalsFormatNumber,
|
|
t,
|
|
useDataProvider,
|
|
} from '@vegaprotocol/react-helpers';
|
|
import type {
|
|
MarketData,
|
|
MarketDataUpdateFieldsFragment,
|
|
SingleMarketFieldsFragment,
|
|
} from '@vegaprotocol/market-list';
|
|
import { marketDataProvider, marketProvider } from '@vegaprotocol/market-list';
|
|
import { HeaderStat } from '../header';
|
|
import * as constants from '../constants';
|
|
|
|
export const MarketVolume = ({ marketId }: { marketId: string }) => {
|
|
const [marketVolume, setMarketVolume] = useState<string>('-');
|
|
const variables = useMemo(
|
|
() => ({
|
|
marketId: marketId,
|
|
}),
|
|
[marketId]
|
|
);
|
|
const { data } = useDataProvider<SingleMarketFieldsFragment, never>({
|
|
dataProvider: marketProvider,
|
|
variables,
|
|
skip: !marketId,
|
|
});
|
|
|
|
const throttledSetMarketVolume = useRef(
|
|
throttle((volume: string) => {
|
|
setMarketVolume(volume);
|
|
}, constants.DEBOUNCE_UPDATE_TIME)
|
|
).current;
|
|
const update = useCallback(
|
|
({ data: marketData }: { data: MarketData | null }) => {
|
|
throttledSetMarketVolume(
|
|
marketData?.indicativeVolume &&
|
|
data?.positionDecimalPlaces !== undefined
|
|
? addDecimalsFormatNumber(
|
|
marketData.indicativeVolume,
|
|
data.positionDecimalPlaces
|
|
)
|
|
: '-'
|
|
);
|
|
return true;
|
|
},
|
|
[data?.positionDecimalPlaces, throttledSetMarketVolume]
|
|
);
|
|
|
|
useDataProvider<MarketData, MarketDataUpdateFieldsFragment>({
|
|
dataProvider: marketDataProvider,
|
|
update,
|
|
variables,
|
|
skip: !marketId || !data,
|
|
updateOnInit: true,
|
|
});
|
|
|
|
return (
|
|
<HeaderStat heading={t('Volume')} testId="market-volume">
|
|
<div>{marketVolume}</div>
|
|
</HeaderStat>
|
|
);
|
|
};
|