fix: backtest submission shows no results — 4 bugs fixed
- ID mismatch: API generated a throwaway UUID while BacktestReplay generated its own internally. Frontend polled with wrong ID and never found the DB row. Now pre-generate ID in endpoint and pass it to BacktestReplay. - Field name: API returned 'backtest_id' but frontend read 'data.id'. Unified to 'id' everywhere. - No polling: useBacktestResult fired once and never refreshed. Added refetchInterval that polls every 2s while status is running. - Response shape: GET endpoint nested results under 'result' object but frontend expected flat fields. Flattened response to match BacktestResult type. - Added running/failed/completed status indicators in BacktestPanel.
This commit is contained in:
@@ -234,12 +234,17 @@ export function useTradingConfig() {
|
||||
});
|
||||
}
|
||||
|
||||
/** Fetch a backtest result by ID. */
|
||||
/** Fetch a backtest result by ID. Polls every 2s while status is pending/running. */
|
||||
export function useBacktestResult(id: string | undefined) {
|
||||
return useQuery<BacktestResult>({
|
||||
queryKey: ['backtest-result', id],
|
||||
queryFn: () => apiGet<BacktestResult>('trading', `/api/trading/backtest/${id}`),
|
||||
enabled: !!id,
|
||||
refetchInterval: (query) => {
|
||||
const status = query.state.data?.status;
|
||||
if (!status || status === 'running' || status === 'pending') return 2000;
|
||||
return false;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user