fix: sort candle data before displaying in chart

- Add sorting by timestamp in ascending order before setting chart data
- Fixes 'data must be asc ordered by time' error from lightweight-charts
- Ensures chart displays correctly even if API returns unsorted data
This commit is contained in:
Marko Djordjevic 2026-02-12 11:52:43 +01:00
parent 11f0759b0e
commit 17eb2ca745

View file

@ -136,13 +136,15 @@ const CandleChart = forwardRef<CandleChartHandle, CandleChartProps>(
useEffect(() => {
if (!seriesRef.current || candles.length === 0) return;
const chartData: CandlestickData[] = candles.map((candle) => ({
time: candle.time as Time,
open: candle.open,
high: candle.high,
low: candle.low,
close: candle.close,
}));
const chartData: CandlestickData[] = candles
.map((candle) => ({
time: candle.time as Time,
open: candle.open,
high: candle.high,
low: candle.low,
close: candle.close,
}))
.sort((a, b) => (a.time as number) - (b.time as number));
seriesRef.current.setData(chartData);
}, [candles]);