fix: update callback when market changes (#1934)
This commit is contained in:
parent
178d4d50ba
commit
06ea58555e
@ -48,43 +48,55 @@ export const DepthChartContainer = ({ marketId }: DepthChartManagerProps) => {
|
|||||||
buy: [],
|
buy: [],
|
||||||
});
|
});
|
||||||
|
|
||||||
const updateDepthData = useRef(
|
const {
|
||||||
throttle(() => {
|
data: market,
|
||||||
if (!dataRef.current || !marketDataRef.current || !market) {
|
error: marketError,
|
||||||
return;
|
loading: marketLoading,
|
||||||
}
|
} = useDataProvider({
|
||||||
dataRef.current = {
|
dataProvider: marketProvider,
|
||||||
...dataRef.current,
|
skipUpdates: true,
|
||||||
midPrice: marketDataRef.current?.staticMidPrice
|
variables,
|
||||||
? formatMidPrice(
|
});
|
||||||
marketDataRef.current?.staticMidPrice,
|
|
||||||
market.decimalPlaces
|
const updateDepthData = useMemo(
|
||||||
)
|
() =>
|
||||||
: undefined,
|
throttle(() => {
|
||||||
data: {
|
if (!dataRef.current || !marketDataRef.current || !market) {
|
||||||
buy: deltaRef.current.buy
|
return;
|
||||||
? updateLevels(
|
}
|
||||||
dataRef.current.data.buy,
|
dataRef.current = {
|
||||||
deltaRef.current.buy,
|
...dataRef.current,
|
||||||
market.decimalPlaces,
|
midPrice: marketDataRef.current?.staticMidPrice
|
||||||
market.positionDecimalPlaces,
|
? formatMidPrice(
|
||||||
true
|
marketDataRef.current?.staticMidPrice,
|
||||||
|
market.decimalPlaces
|
||||||
)
|
)
|
||||||
: dataRef.current.data.buy,
|
: undefined,
|
||||||
sell: deltaRef.current.sell
|
data: {
|
||||||
? updateLevels(
|
buy: deltaRef.current.buy
|
||||||
dataRef.current.data.sell,
|
? updateLevels(
|
||||||
deltaRef.current.sell,
|
dataRef.current.data.buy,
|
||||||
market.decimalPlaces,
|
deltaRef.current.buy,
|
||||||
market.positionDecimalPlaces
|
market.decimalPlaces,
|
||||||
)
|
market.positionDecimalPlaces,
|
||||||
: dataRef.current.data.sell,
|
true
|
||||||
},
|
)
|
||||||
};
|
: dataRef.current.data.buy,
|
||||||
deltaRef.current.buy = [];
|
sell: deltaRef.current.sell
|
||||||
deltaRef.current.sell = [];
|
? updateLevels(
|
||||||
setDepthData(dataRef.current);
|
dataRef.current.data.sell,
|
||||||
}, 1000)
|
deltaRef.current.sell,
|
||||||
|
market.decimalPlaces,
|
||||||
|
market.positionDecimalPlaces
|
||||||
|
)
|
||||||
|
: dataRef.current.data.sell,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
deltaRef.current.buy = [];
|
||||||
|
deltaRef.current.sell = [];
|
||||||
|
setDepthData(dataRef.current);
|
||||||
|
}, 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user