"use client"; import { useEffect, useState } from "react"; import Image from "next/image"; import { games } from "../data/games"; import { FiTrash } from "react-icons/fi"; import { useSolanaWallets } from "@privy-io/react-auth"; import { fetchOpenBets } from "@/shared/solana_helpers"; import {Bet} from "../types/Bet"; export default function YourGames() { const { wallets, ready } = useSolanaWallets(); const [openBets, setOpenBets] = useState([]); const [myBets, setMyBets] = useState([]); const [loading, setLoading] = useState(true); // Function to fetch open bets const updateBets= async ()=>{ const bets:Bet[] = await fetchOpenBets(wallets[0]); setMyBets(bets.filter((bet) => bet.owner === wallets[0].address)); setOpenBets(bets); setLoading(false); console.log(`Got ${bets.length} bets`); } // Auto-refresh every 10 seconds useEffect(() => { if (!ready) return; updateBets(); const interval = setInterval(updateBets, 10000); // Refresh every 10s return () => clearInterval(interval); // Cleanup on unmount }, [ready]); return (

Your Games

{loading ? (

Loading your games...

) : myBets.length === 0 ? <> :(
{myBets.map((bet) => { console.log(`Finding game for the id ${bet.id}`) const game = games.find((g) => g.id === bet.id); // Match game if (!game) return null; // Skip unmatched bets return (
{/* Game Thumbnail */}
{game.name}
{/* Game Info */}

{game.name}

Wager

{bet.wager} SOL

{/* Close Button (Trash Icon) */}
); })}
)}
); }