import { useState, useEffect, useCallback, useMemo } from 'react'; import { useDubs } from '../provider'; import type { ArcadePool, ArcadePoolStats, ArcadeLeaderboardEntry } from '../types'; export interface UseArcadePoolResult { pool: ArcadePool | null; stats: ArcadePoolStats | null; leaderboard: ArcadeLeaderboardEntry[]; loading: boolean; error: Error | null; refetch: () => void; } export function useArcadePool(poolId: number | null): UseArcadePoolResult { const { client } = useDubs(); const [pool, setPool] = useState(null); const [stats, setStats] = useState(null); const [leaderboard, setLeaderboard] = useState([]); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const fetch = useCallback(async () => { if (!poolId) return; setLoading(true); setError(null); try { const [poolRes, lb] = await Promise.all([ client.getArcadePool(poolId), client.getArcadeLeaderboard(poolId), ]); setPool(poolRes.pool); setStats(poolRes.stats); setLeaderboard(lb); } catch (err) { setError(err instanceof Error ? err : new Error(String(err))); } finally { setLoading(false); } }, [client, poolId]); useEffect(() => { fetch(); }, [fetch]); return { pool, stats, leaderboard, loading, error, refetch: fetch }; }