import { useState, useEffect, useCallback } from 'react'; import { useDubs } from '../provider'; import type { JackpotRoundResult } from '../types'; export interface UseJackpotHistoryResult { rounds: JackpotRoundResult[]; loading: boolean; error: Error | null; refetch: () => void; } export function useJackpotHistory(limit?: number): UseJackpotHistoryResult { const { client } = useDubs(); const [rounds, setRounds] = useState([]); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const fetch = useCallback(async () => { setLoading(true); setError(null); try { const result = await client.getJackpotHistory(limit); setRounds(result); } catch (err) { setError(err instanceof Error ? err : new Error(String(err))); } finally { setLoading(false); } }, [client, limit]); useEffect(() => { fetch(); }, [fetch]); return { rounds, loading, error, refetch: fetch }; }