diff --git a/src/components/Header.tsx b/src/components/Header.tsx index 3ac011f..c1e9a00 100644 --- a/src/components/Header.tsx +++ b/src/components/Header.tsx @@ -87,7 +87,7 @@ export default function Header() { {/* Mobile-only view (Logo & Login) */} -
+
diff --git a/src/components/PrivyButton.tsx b/src/components/PrivyButton.tsx index 1ead80b..a69c317 100644 --- a/src/components/PrivyButton.tsx +++ b/src/components/PrivyButton.tsx @@ -67,7 +67,7 @@ export default function PrivyButton() { setSolBalance((balance / 1e9).toFixed(2)); } catch (error) { console.error("Failed to get balance:", error); - setSolBalance("Error"); + setSolBalance("0"); } } }; @@ -75,7 +75,7 @@ export default function PrivyButton() { useEffect(() => { const intervalId = setInterval(() => { fetchSolBalance(); - }, 5000); // 5000 milliseconds = 5 seconds + }, 15000); // 5000 milliseconds = 5 seconds // Cleanup function to clear the interval on unmount or when `ready` changes return () => clearInterval(intervalId); diff --git a/src/components/YourGames.tsx b/src/components/YourGames.tsx index 8e5976b..f002835 100644 --- a/src/components/YourGames.tsx +++ b/src/components/YourGames.tsx @@ -87,6 +87,7 @@ export default function YourGames({bets}:GameModalProps) { ) : (
{myBets.map((bet) => { + console.log(`Bet id:${bet.id}`); const game = games.find((g) => g.id === bet.id); if (!game) return null; diff --git a/src/data/shared.ts b/src/data/shared.ts index d40daa6..52fb071 100644 --- a/src/data/shared.ts +++ b/src/data/shared.ts @@ -1,9 +1,11 @@ import { Connection } from "@solana/web3.js"; -export const CLUSTER_URL = "https://api.devnet.solana.com"; -export const EXPLORER_ADDRESS_TEMPLATE = "https://explorer.solana.com/address/{address}?cluster=devnet"; -export const EXPLORER_TX_TEMPLATE = "https://explorer.solana.com/tx/{address}?cluster=devnet"; +// Replace this URL with your dedicated RPC endpoint +// You can get one from providers like QuickNode, Alchemy, Helius, or GenesysGo +export const CLUSTER_URL = "https://tiniest-cold-darkness.solana-mainnet.quiknode.pro/72332d636ff78d498b880bd8fdc3eb646c827da8/"; +export const EXPLORER_ADDRESS_TEMPLATE = "https://explorer.solana.com/address/{address}"; +export const EXPLORER_TX_TEMPLATE = "https://explorer.solana.com/tx/{address}"; export const connection = new Connection(CLUSTER_URL); - export const API_URL = "https://api.duelfi.io/v1/"; +export const VALIDATOR_URL = "https://validator.duelfi.io/"; diff --git a/src/idl/bets.ts b/src/idl/bets.ts index 76e79cc..a7bf1eb 100644 --- a/src/idl/bets.ts +++ b/src/idl/bets.ts @@ -5,7 +5,7 @@ * IDL can be found at `target/idl/bets.json`. */ export type Bets = { - "address": "JAf3ZkQ469okXAzA6BKJeKBb9ZkCtZanULaUsapskoyn", + "address": "Haj94DF925qNRgcoRwQfNsVLKgSmFhG4bjgtvusMkkpD", "metadata": { "name": "bets", "version": "0.1.0", @@ -223,6 +223,48 @@ export type Bets = { "type": "string" } ] + }, + { + "name": "refundBet", + "discriminator": [ + 209, + 182, + 226, + 96, + 55, + 121, + 83, + 183 + ], + "accounts": [ + { + "name": "betsList", + "writable": true + }, + { + "name": "betVault", + "writable": true + }, + { + "name": "owner", + "writable": true + }, + { + "name": "payer", + "writable": true, + "signer": true + }, + { + "name": "systemProgram", + "address": "11111111111111111111111111111111" + } + ], + "args": [ + { + "name": "owner", + "type": "pubkey" + } + ] } ], "accounts": [ @@ -312,7 +354,7 @@ export type Bets = { { "name": "feeCollector", "type": "string", - "value": "\"cocD4r4yNpHxPq7CzUebxEMyLki3X4d2Y3HcTX5ptUc\"" + "value": "\"9esrj2X33pr5og6fdkDMjaW6fdnnb9hT1cWshamxTdL4\"" }, { "name": "seed", diff --git a/src/idl/bets_idl.json b/src/idl/bets_idl.json index d1a1340..da57568 100644 --- a/src/idl/bets_idl.json +++ b/src/idl/bets_idl.json @@ -1,5 +1,5 @@ { - "address": "JAf3ZkQ469okXAzA6BKJeKBb9ZkCtZanULaUsapskoyn", + "address": "Haj94DF925qNRgcoRwQfNsVLKgSmFhG4bjgtvusMkkpD", "metadata": { "name": "bets", "version": "0.1.0", @@ -217,6 +217,48 @@ "type": "string" } ] + }, + { + "name": "refund_bet", + "discriminator": [ + 209, + 182, + 226, + 96, + 55, + 121, + 83, + 183 + ], + "accounts": [ + { + "name": "bets_list", + "writable": true + }, + { + "name": "bet_vault", + "writable": true + }, + { + "name": "owner", + "writable": true + }, + { + "name": "payer", + "writable": true, + "signer": true + }, + { + "name": "system_program", + "address": "11111111111111111111111111111111" + } + ], + "args": [ + { + "name": "owner", + "type": "pubkey" + } + ] } ], "accounts": [ @@ -306,7 +348,7 @@ { "name": "FEE_COLLECTOR", "type": "string", - "value": "\"cocD4r4yNpHxPq7CzUebxEMyLki3X4d2Y3HcTX5ptUc\"" + "value": "\"9esrj2X33pr5og6fdkDMjaW6fdnnb9hT1cWshamxTdL4\"" }, { "name": "SEED", @@ -314,4 +356,4 @@ "value": "\"anchor\"" } ] -} \ No newline at end of file +} \ No newline at end of file diff --git a/src/shared/constants.ts b/src/shared/constants.ts index 8a3a7bc..b7208be 100644 --- a/src/shared/constants.ts +++ b/src/shared/constants.ts @@ -1,6 +1,6 @@ import { Commitment, PublicKey } from "@solana/web3.js"; -export const FEE_COLLECTOR_PUBKEY = new PublicKey("cocD4r4yNpHxPq7CzUebxEMyLki3X4d2Y3HcTX5ptUc"); +export const FEE_COLLECTOR_PUBKEY = new PublicKey("9esrj2X33pr5og6fdkDMjaW6fdnnb9hT1cWshamxTdL4"); export const WAGER_PRIZE_MULT = 0.95; export const CONFIRMATION_THRESHOLD:Commitment = 'finalized'; diff --git a/src/shared/solana_helpers.ts b/src/shared/solana_helpers.ts index 65d113b..e10c189 100644 --- a/src/shared/solana_helpers.ts +++ b/src/shared/solana_helpers.ts @@ -1,4 +1,4 @@ -import { CLUSTER_URL, connection } from "@/data/shared"; +import { CLUSTER_URL, connection, VALIDATOR_URL } from "@/data/shared"; import { Bets } from "@/idl/bets"; import { AnchorProvider, BN, Program } from "@coral-xyz/anchor"; import { ConnectedSolanaWallet } from "@privy-io/react-auth"; @@ -8,52 +8,60 @@ import { Bet } from "@/types/Bet"; import { toast } from "sonner"; import { CONFIRMATION_THRESHOLD, FEE_COLLECTOR_PUBKEY } from "./constants"; -export const fetchOpenBets = async (wallets: ConnectedSolanaWallet): Promise => { - try { - if (!wallets) return []; +export async function fetchOpenBets(): Promise { - const wallet = { - publicKey: new PublicKey(wallets.address), - signTransaction: wallets.signTransaction, - signAllTransactions: wallets.signAllTransactions, - }; - const provider = new AnchorProvider(connection, wallet, { - preflightCommitment: CONFIRMATION_THRESHOLD, - }); + const response = await fetch(`${VALIDATOR_URL}fetchBets`); + const data = await response.json(); - const program = new Program(idl, provider); - const [bet_list_pda] = await PublicKey.findProgramAddress( - [Buffer.from("bets_list")], - program.programId - ); - // Fetch all open bet accounts - const bet_list = await program.account.betsList.fetch(bet_list_pda, CONFIRMATION_THRESHOLD); + return data; +} - // Extract required bet data - const formattedBets = await Promise.all( - bet_list.bets.map(async (bet) => { - const betAcc = await program.account.betVault.fetch(bet); - // console.log(betAcc.gameId); - return { - address: bet.toString(), - id: betAcc.gameId, - owner: betAcc.owner.toBase58(), - owner_id: betAcc.ownerId, - joiner: betAcc.joiner ? betAcc.joiner.toBase58() : "Open", - joiner_id: betAcc.joinerId, - wager: betAcc.wager.toNumber() / LAMPORTS_PER_SOL - }; - }) - ); +// export const fetchOpenBets = async (wallets: ConnectedSolanaWallet): Promise => { +// try { +// if (!wallets) return []; - // console.log(`Got ${formattedBets.length} bets`); +// const wallet = { +// publicKey: new PublicKey(wallets.address), +// signTransaction: wallets.signTransaction, +// signAllTransactions: wallets.signAllTransactions, +// }; +// const provider = new AnchorProvider(connection, wallet, { +// preflightCommitment: CONFIRMATION_THRESHOLD, +// }); - return formattedBets; - } catch (error) { - console.error("Error fetching open bets:", error); - } - return []; -}; +// const program = new Program(idl, provider); +// const [bet_list_pda] = await PublicKey.findProgramAddress( +// [Buffer.from("bets_list")], +// program.programId +// ); +// // Fetch all open bet accounts +// const bet_list = await program.account.betsList.fetch(bet_list_pda, CONFIRMATION_THRESHOLD); + +// // Extract required bet data +// const formattedBets = await Promise.all( +// bet_list.bets.map(async (bet) => { +// const betAcc = await program.account.betVault.fetch(bet); +// // console.log(betAcc.gameId); +// return { +// address: bet.toString(), +// id: betAcc.gameId, +// owner: betAcc.owner.toBase58(), +// owner_id: betAcc.ownerId, +// joiner: betAcc.joiner ? betAcc.joiner.toBase58() : "Open", +// joiner_id: betAcc.joinerId, +// wager: betAcc.wager.toNumber() / LAMPORTS_PER_SOL +// }; +// }) +// ); + +// // console.log(`Got ${formattedBets.length} bets`); + +// return formattedBets; +// } catch (error) { +// console.error("Error fetching open bets:", error); +// } +// return []; +// }; export async function getVaultByAddress(wallets: ConnectedSolanaWallet, address: string): Promise { try {