fix: update callback when market changes (#1934)

This commit is contained in:
John Walley 2022-11-16 04:08:39 +00:00 committed by GitHub
parent 178d4d50ba
commit 06ea58555e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -48,7 +48,18 @@ export const DepthChartContainer = ({ marketId }: DepthChartManagerProps) => {
buy: [], buy: [],
}); });
const updateDepthData = useRef( const {
data: market,
error: marketError,
loading: marketLoading,
} = useDataProvider({
dataProvider: marketProvider,
skipUpdates: true,
variables,
});
const updateDepthData = useMemo(
() =>
throttle(() => { throttle(() => {
if (!dataRef.current || !marketDataRef.current || !market) { if (!dataRef.current || !marketDataRef.current || !market) {
return; return;
@ -84,7 +95,8 @@ export const DepthChartContainer = ({ marketId }: DepthChartManagerProps) => {
deltaRef.current.buy = []; deltaRef.current.buy = [];
deltaRef.current.sell = []; deltaRef.current.sell = [];
setDepthData(dataRef.current); setDepthData(dataRef.current);
}, 1000) }, 1000),
[market]
); );
// Apply updates to the table // Apply updates to the table
@ -107,7 +119,7 @@ export const DepthChartContainer = ({ marketId }: DepthChartManagerProps) => {
if (delta.buy) { if (delta.buy) {
deltaRef.current.buy.push(...delta.buy); deltaRef.current.buy.push(...delta.buy);
} }
updateDepthData.current(); updateDepthData();
} }
return true; return true;
}, },
@ -120,16 +132,6 @@ export const DepthChartContainer = ({ marketId }: DepthChartManagerProps) => {
variables, variables,
}); });
const {
data: market,
error: marketError,
loading: marketLoading,
} = useDataProvider({
dataProvider: marketProvider,
skipUpdates: true,
variables,
});
const marketDataUpdate = useCallback( const marketDataUpdate = useCallback(
({ data }: { data: MarketData | null }) => { ({ data }: { data: MarketData | null }) => {
marketDataRef.current = data; marketDataRef.current = data;
@ -148,7 +150,7 @@ export const DepthChartContainer = ({ marketId }: DepthChartManagerProps) => {
variables, variables,
}); });
if (marketDataRef.current && marketData) { if (!marketDataRef.current && marketData) {
marketDataRef.current = marketData; marketDataRef.current = marketData;
} }