diff --git a/next.config.ts b/next.config.ts index 167a872..33502da 100644 --- a/next.config.ts +++ b/next.config.ts @@ -3,7 +3,15 @@ import type { NextConfig } from "next"; const nextConfig: NextConfig = { /* config options here */ images: { - domains: ["pbs.twimg.com","vps.playpoolstudios.com", "api.duelfi.io"], // ✅ add Twitter's image domain + domains: ["pbs.twimg.com","vps.playpoolstudios.com", "api.duelfi.io", "validator.duelfi.io", "validatordev.duelfi.io"], // ✅ add Twitter's image domain + }, + async rewrites() { + return [ + { + source: '/api/:path*', + destination: 'https://api.duelfi.io/:path*', + }, + ]; }, }; diff --git a/package.json b/package.json index ff5a67d..57e4e28 100644 --- a/package.json +++ b/package.json @@ -3,9 +3,9 @@ "version": "0.1.0", "private": true, "scripts": { - "dev": "next dev -p 3031", + "dev": "next dev -p 3030", "build": "next build", - "start": "next start -p 3031", + "start": "next start -p 3030", "lint": "next lint" }, "dependencies": { diff --git a/src/components/GameModal.tsx b/src/components/GameModal.tsx index 971171c..5017d65 100644 --- a/src/components/GameModal.tsx +++ b/src/components/GameModal.tsx @@ -10,7 +10,7 @@ import { createBet } from "@/shared/solana_helpers"; import { Game } from "@/types/Game"; import { connection, EXPLORER_TX_TEMPLATE } from "@/data/shared"; import { CONFIRMATION_THRESHOLD } from "@/shared/constants"; - +import { fetchUserById, showNewGameNotification } from "@/shared/data_fetcher"; interface GameModalProps { isOpen: boolean; onClose: () => void; @@ -64,6 +64,7 @@ export default function GameModal({ isOpen, onClose }: GameModalProps) { setIsProcessing(true); toast.loading("Creating Game"); try { + const ownerProfile = await fetchUserById(user?.id ?? ""); const tx = await createBet(wallet, user?.id ?? "", selectedPrice, selectedGame.id, false); const url = EXPLORER_TX_TEMPLATE.replace("{address}", tx); if (tx.length > 5) { @@ -77,6 +78,8 @@ export default function GameModal({ isOpen, onClose }: GameModalProps) { }, }); + showNewGameNotification(ownerProfile?.username ?? "", selectedGame.name, selectedPrice.toString()); + }) } diff --git a/src/components/Header.tsx b/src/components/Header.tsx index c1ff8c5..1a8024f 100644 --- a/src/components/Header.tsx +++ b/src/components/Header.tsx @@ -25,9 +25,8 @@ export default function Header() { Logo diff --git a/src/components/Leaderboard.tsx b/src/components/Leaderboard.tsx index fdd2dc9..4df8ff2 100644 --- a/src/components/Leaderboard.tsx +++ b/src/components/Leaderboard.tsx @@ -22,7 +22,7 @@ export default function Leaderboard() { useEffect(() => { const fetchLeaderboard = async () => { try { - const response = await fetch("https://api.duelfi.io/v1/get_leaderboard.php"); + const response = await fetch("/api/v1/get_leaderboard.php"); const data = await response.json(); setLeaderboardData(data); } catch (error) { diff --git a/src/components/PrivyButton.tsx b/src/components/PrivyButton.tsx index 0d980f4..6f6a996 100644 --- a/src/components/PrivyButton.tsx +++ b/src/components/PrivyButton.tsx @@ -584,7 +584,11 @@ export default function PrivyButton() {

Connected Wallet

-

{solWallet}

+ +

+ {solWallet} + {solWallet.slice(0, 30)}...{solWallet.slice(-4)} +

{wallets.some(wallet => wallet.type === "solana" && wallet.address === solWallet && wallet.connectorType === "embedded") && ( diff --git a/src/components/YourGames.tsx b/src/components/YourGames.tsx index 7e45cd5..3e7ca6e 100644 --- a/src/components/YourGames.tsx +++ b/src/components/YourGames.tsx @@ -54,7 +54,7 @@ export default function YourGames({bets}:GameModalProps) { } }); try { - const tx = await closeBet(wallet, selectedBet.id, user?.id ?? "na"); + const tx = await closeBet(wallet, user?.id ?? "na", selectedBet.id); const url = EXPLORER_TX_TEMPLATE.replace("{address}", tx); connection.confirmTransaction(tx, CONFIRMATION_THRESHOLD).finally(()=>{ diff --git a/src/data/shared.ts b/src/data/shared.ts index 8d74e9d..e32c5b1 100644 --- a/src/data/shared.ts +++ b/src/data/shared.ts @@ -11,8 +11,8 @@ export const EXPLORER_ADDRESS_TEMPLATE = "https://explorer.solana.com/address/{a 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 API_BASE_URL = "https://api.duelfi.io/"; +export const API_URL = "/api/v1/"; +export const API_BASE_URL = "/api/"; export const VALIDATOR_URL = "https://validator.duelfi.io/"; export const VALIDATOR_URL_DEV = "https://validatordev.duelfi.io/"; diff --git a/src/shared/data_fetcher.ts b/src/shared/data_fetcher.ts index 8b117a4..ca59159 100644 --- a/src/shared/data_fetcher.ts +++ b/src/shared/data_fetcher.ts @@ -6,4 +6,11 @@ export async function fetchUserById(id: string) { if (!res.ok) return null; return await res.json(); } - \ No newline at end of file + +export async function showNewGameNotification(username:string, game:string, wager:string){ + try{ + await fetch(`${API_URL}send_telegram_notification.php?username=${username}&wager=${wager}&game=${game}`) + }catch(error){ + console.error("Error showing new game notification:", error); + } +} \ No newline at end of file diff --git a/src/shared/solana_helpers.ts b/src/shared/solana_helpers.ts index 98a66b4..4670cff 100644 --- a/src/shared/solana_helpers.ts +++ b/src/shared/solana_helpers.ts @@ -1,4 +1,4 @@ -import { CLUSTER_URL, connection, VALIDATOR_URL, VALIDATOR_URL_DEV } from "@/data/shared"; +import { CLUSTER_URL, connection, VALIDATOR_URL, VALIDATOR_URL_DEV } from "@/data/shared"; import { Bets } from "@/idl/bets"; import { AnchorProvider, BN, Program } from "@coral-xyz/anchor"; import { ConnectedSolanaWallet } from "@privy-io/react-auth"; @@ -134,7 +134,7 @@ export async function closeBet(wallets: ConnectedSolanaWallet, uid:string, betI } if (!chosenBet) { - console.error("Bet not found or not owned by the user"); + console.error(`Bet not found or not owned by the user\n${wallets.address}\n${betId}`); return ""; } @@ -207,6 +207,7 @@ export async function createBet(wallets: ConnectedSolanaWallet, uid: string, sel const txId = await connection.sendRawTransaction(signedTx.serialize()); console.log(`Transaction sent: ${txId}`); console.log(`Transaction confirmed: ${txId}`); + if (get_account_address) { const gameIdBytes = Buffer.from(selectedGame); // selectedGame is a string (game_id) const nonceBytes = new BN(nonce).toArrayLike(Buffer, "le", 8); // _nonce.to_le_bytes() @@ -239,6 +240,8 @@ export async function createBet(wallets: ConnectedSolanaWallet, uid: string, sel return ""; } + + export async function joinBet(wallets: ConnectedSolanaWallet, uid: string, gameId: string, address: string): Promise { const wallet = { publicKey: new PublicKey(wallets.address),