diff --git a/src/components/GameModal.tsx b/src/components/GameModal.tsx index d7c3ed1..2a5d732 100644 --- a/src/components/GameModal.tsx +++ b/src/components/GameModal.tsx @@ -8,6 +8,7 @@ import { PriceSelection } from "./PriceSelection"; import { GameSelection } from "./GameSelection"; import { createBet } from "@/shared/solana_helpers"; import { Game } from "@/types/Game"; +import { EXPLORER_TX_TEMPLATE } from "@/data/shared"; interface GameModalProps { isOpen: boolean; @@ -41,7 +42,15 @@ export default function GameModal({ isOpen, onClose }: GameModalProps) { setIsProcessing(true); try { - await createBet(wallet, selectedPrice, selectedGame); + const tx = await createBet(wallet, selectedPrice, selectedGame); + const url = EXPLORER_TX_TEMPLATE.replace("{address}", tx); + toast.success(`Bet created successfully!`, { + action: { + label: "View TX", + onClick: () => window.open(url, "_blank"), + }, + }); + onClose(); } catch (error) { console.error("Error creating bet:", error); diff --git a/src/components/GameSelection.tsx b/src/components/GameSelection.tsx index b00267b..6177633 100644 --- a/src/components/GameSelection.tsx +++ b/src/components/GameSelection.tsx @@ -1,5 +1,5 @@ import Image from "next/image"; -import { Game } from "../data/games"; +import { Game } from "../types/Game"; interface GameSelectionProps { games: Game[]; diff --git a/src/components/YourGames.tsx b/src/components/YourGames.tsx index 1462454..92451bf 100644 --- a/src/components/YourGames.tsx +++ b/src/components/YourGames.tsx @@ -6,6 +6,8 @@ import { FiTrash } from "react-icons/fi"; import { useSolanaWallets } from "@privy-io/react-auth"; import { fetchOpenBets, closeBet } from "@/shared/solana_helpers"; import { Bet } from "../types/Bet"; +import { toast } from "sonner"; +import { EXPLORER_TX_TEMPLATE } from "@/data/shared"; export default function YourGames() { const { wallets, ready } = useSolanaWallets(); @@ -35,11 +37,19 @@ export default function YourGames() { if (!selectedBet) return; setIsProcessing(true); try { - await closeBet(wallets[0], selectedBet.id); + const tx = await closeBet(wallets[0], selectedBet.id); + const url = EXPLORER_TX_TEMPLATE.replace("{address}", tx); + + toast.success(`Closed the bet successfully!`, { + action: { + label: "View TX", + onClick: () => window.open(url, "_blank"), + }, + }); updateBets(); } catch (error) { console.error("Error closing bet:", error); - alert("Failed to close the bet. Please try again."); + toast.message("Failed to close the bet. Please try again."); } finally { setIsProcessing(false); setSelectedBet(null); diff --git a/src/data/shared.ts b/src/data/shared.ts index cbc19c4..ffcdda4 100644 --- a/src/data/shared.ts +++ b/src/data/shared.ts @@ -1 +1,3 @@ -export const CLUSTER_URL = "https://api.devnet.solana.com"; \ No newline at end of file +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"; diff --git a/src/shared/solana_helpers.ts b/src/shared/solana_helpers.ts index df4bce8..6c38817 100644 --- a/src/shared/solana_helpers.ts +++ b/src/shared/solana_helpers.ts @@ -56,7 +56,7 @@ export const fetchOpenBets = async (wallets: ConnectedSolanaWallet): Promise { try { const connection = new Connection(CLUSTER_URL); const wallet = { @@ -89,30 +89,38 @@ export const fetchOpenBets = async (wallets: ConnectedSolanaWallet): Promise{ const connection = new Connection(CLUSTER_URL); const wallet = { publicKey: new PublicKey(wallets.address), @@ -155,8 +163,8 @@ export async function createBet(wallets:ConnectedSolanaWallet,selectedPrice:numb // Send transaction// Replace with correct RPC endpoint const txId = await connection.sendRawTransaction(signedTx.serialize()); - toast.success(`Bet created successfully! TX: ${txId}`); console.log(`Transaction ID: ${txId}`); + return txId; } catch (error:unknown) { @@ -169,4 +177,6 @@ export async function createBet(wallets:ConnectedSolanaWallet,selectedPrice:numb console.error(error); } } + + return ""; } \ No newline at end of file