From bc325b3865db0ce15b58794c640f89b7f815acfd Mon Sep 17 00:00:00 2001 From: Sewmina Date: Thu, 29 May 2025 09:12:19 +0530 Subject: [PATCH] activities imp --- src/components/Activities.tsx | 18 +++++++++++++++++- src/components/FirstVisitModal.tsx | 2 +- src/shared/data_fetcher.ts | 9 +++------ src/shared/solana_helpers.ts | 4 ++-- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/components/Activities.tsx b/src/components/Activities.tsx index b9d57ed..9f4ce54 100644 --- a/src/components/Activities.tsx +++ b/src/components/Activities.tsx @@ -67,7 +67,14 @@ export default function Activities() { } }; + // Initial fetch fetchActivities(); + + // Set up interval for periodic updates + const intervalId = setInterval(fetchActivities, 5000); + + // Cleanup function to clear the interval when component unmounts + return () => clearInterval(intervalId); }, []); const formatActivityMessage = (activity: Activity) => { @@ -124,7 +131,16 @@ export default function Activities() { >

{formatActivityMessage(activity)}

-

{new Date(activity.time).toLocaleString()}

+

+ {new Date(activity.time + 'Z').toLocaleString(undefined, { + year: 'numeric', + month: 'short', + day: 'numeric', + hour: '2-digit', + minute: '2-digit', + hour12: true + })} +

- Challenge your friends (or strangers) in a head-to-head skill games and earn from your victories! + Challenge your friends (or strangers) in head-to-head skill games and earn from your victories!

Create or join duels, set an entry fee, and the winner takes all. diff --git a/src/shared/data_fetcher.ts b/src/shared/data_fetcher.ts index 41f23f8..842302a 100644 --- a/src/shared/data_fetcher.ts +++ b/src/shared/data_fetcher.ts @@ -19,12 +19,9 @@ export async function showNewGameNotification(username:string, game:string, wage export async function add_new_activity(type:string, owner_id:string, joiner_id:string, game:string, amount:number ){ try{ - const isDevnet = CLUSTER_URL === clusterApiUrl("devnet"); - if(isDevnet){ - await fetch(`${API_URL}add_activity.php?type=${type}&owner_id=${owner_id}&joiner_id=${joiner_id}&game=${game}&amount=${amount}&devnet=${isDevnet ? "1" : "0"}`) - }else{ - await fetch(`${API_URL}add_activity.php?type=${type}&owner_id=${owner_id}&joiner_id=${joiner_id}&game=${game}&amount=${amount}`) - } + const url = `${API_URL}add_activity.php?type=${type}&owner_id=${owner_id}&joiner_id=${joiner_id}&game=${game}&amount=${amount}`; + console.log(url); + await fetch(url); }catch(error){ console.error("Error adding new activity:", error); } diff --git a/src/shared/solana_helpers.ts b/src/shared/solana_helpers.ts index b468932..d8ebe04 100644 --- a/src/shared/solana_helpers.ts +++ b/src/shared/solana_helpers.ts @@ -94,7 +94,7 @@ export async function closeBet(wallets: ConnectedSolanaWallet, uid:string, betI } const winner = new PublicKey(wallets.address); - + const chosenBetVaultAcc = await program.account.betVault.fetch(chosenBet); // Execute the closeBet transaction const tx = await program.methods @@ -113,7 +113,7 @@ export async function closeBet(wallets: ConnectedSolanaWallet, uid:string, betI // Send transaction// Replace with correct RPC endpoint const txId = await connection.sendRawTransaction(signedTx.serialize()); - add_new_activity("close", uid, "", game_id, 0); + add_new_activity("close", uid, chosenBetVaultAcc.joinerId, game_id, chosenBetVaultAcc.wager.toNumber() / LAMPORTS_PER_SOL); console.log(`Transaction: ${txId}`); return txId; } catch (error) {