import { useState, useEffect, useCallback } from 'react'; import { useDubs } from '../provider'; import type { JackpotRound, JackpotLastWinner } from '../types'; export interface UseJackpotResult { round: JackpotRound | null; lastWinner: JackpotLastWinner | null; loading: boolean; error: Error | null; refetch: () => void; } export function useJackpot(): UseJackpotResult { const { client } = useDubs(); const [round, setRound] = useState(null); const [lastWinner, setLastWinner] = useState(null); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const fetch = useCallback(async () => { setLoading(true); setError(null); try { const result = await client.getJackpotCurrent(); setRound(result.round); setLastWinner(result.lastWinner); } catch (err) { setError(err instanceof Error ? err : new Error(String(err))); } finally { setLoading(false); } }, [client]); useEffect(() => { fetch(); }, [fetch]); return { round, lastWinner, loading, error, refetch: fetch }; }