diff --git a/src/components/Activities.tsx b/src/components/Activities.tsx index 9f4ce54..c07559c 100644 --- a/src/components/Activities.tsx +++ b/src/components/Activities.tsx @@ -1,6 +1,7 @@ import Image from "next/image"; import { useState, useEffect } from "react"; import { API_BASE_URL } from "@/data/shared"; +import { PlusCircleIcon, XCircleIcon, UserPlusIcon, TrophyIcon } from '@heroicons/react/24/outline'; interface Activity { id: string; @@ -85,18 +86,48 @@ export default function Activities() { switch (activity.type) { case "create": - return `${ownerUsername} Created a new ${activity.game} game${formattedAmount ? ` for ${formattedAmount}` : ""}`; + return <>{ownerUsername} created a {activity.game} game with a {formattedAmount} entry fee.; case "close": - return `${ownerUsername} Closed ${activity.game} game${formattedAmount ? ` for ${formattedAmount}` : ""}`; + return <>{ownerUsername} cancelled their {activity.game} game.; case "join": - return `${joinerUsername} Joined a ${activity.game} game`; + return <>{joinerUsername} joined {activity.game} with a {formattedAmount} entry fee.; case "won": - return `${ownerUsername} won the ${activity.game} game${formattedAmount ? ` and won ${formattedAmount}` : ""}`; + return <>{ownerUsername} won {formattedAmount} in {activity.game}!; default: return "Unknown activity"; } }; + const formatTimeAgo = (timestamp: string) => { + const date = new Date(timestamp + 'Z'); + const now = new Date(); + const diffInSeconds = Math.floor((now.getTime() - date.getTime()) / 1000); + const diffInMinutes = Math.floor(diffInSeconds / 60); + const diffInHours = Math.floor(diffInMinutes / 60); + const diffInDays = Math.floor(diffInHours / 24); + + if (diffInDays > 0) { + return date.toLocaleString(undefined, { + year: 'numeric', + month: 'short', + day: 'numeric', + hour: '2-digit', + minute: '2-digit', + hour12: true + }); + } + + if (diffInHours > 0) { + return `${diffInHours} hour${diffInHours === 1 ? '' : 's'} ago`; + } + + if (diffInMinutes > 0) { + return `${diffInMinutes} minute${diffInMinutes === 1 ? '' : 's'} ago`; + } + + return "less than 1 minute ago"; + }; + if (loading) { return (
@@ -115,7 +146,7 @@ export default function Activities() {

Recent Activities

- {activities.map((activity) => { + {[...activities].sort((a, b) => new Date(b.time).getTime() - new Date(a.time).getTime()).map((activity) => { const userId = activity.type === "join" ? activity.joiner_id : activity.owner_id; if (!userId) return null; @@ -129,19 +160,6 @@ export default function Activities() { key={activity.id} className="flex items-center gap-4 p-3 px-6 rounded-lg bg-[rgb(10,10,10)] border border-[rgb(30,30,30)] hover:border-[rgb(248,144,22)] transition-all duration-300" > -
-

{formatActivityMessage(activity)}

-

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

-
Profile new Set(prev).add(profileUrl)); }} /> +
+

{formatActivityMessage(activity)}

+

+ {formatTimeAgo(activity.time)} +

+
+
+ {activity.type === "create" && } + {activity.type === "close" && } + {activity.type === "join" && } + {activity.type === "won" && } +
); })} diff --git a/src/components/PriceSelection.tsx b/src/components/PriceSelection.tsx index 853e385..f9a26a2 100644 --- a/src/components/PriceSelection.tsx +++ b/src/components/PriceSelection.tsx @@ -6,7 +6,7 @@ interface PriceSelectionProps { } export function PriceSelection({ selectedPrice, onSelect }: PriceSelectionProps) { - const presets = [0.05, 0.1, 0.2, 0.5, 1.0]; + const presets = [0.01,0.05, 0.1, 0.2, 0.5, 1.0]; const [inputValue, setInputValue] = useState(""); const MIN_AMOUNT = 0.01; diff --git a/src/shared/data_fetcher.ts b/src/shared/data_fetcher.ts index 842302a..52459ba 100644 --- a/src/shared/data_fetcher.ts +++ b/src/shared/data_fetcher.ts @@ -11,7 +11,9 @@ export async function fetchUserById(id: string) { export async function showNewGameNotification(username:string, game:string, wager:string){ try{ const isDevnet = CLUSTER_URL === clusterApiUrl("devnet"); - await fetch(`${API_URL}send_telegram_notification.php?username=${username}&wager=${wager}&game=${game}&devnet=${isDevnet ? "1" : "0"}`) + const url = `${API_URL}send_telegram_notification.php?username=${username}&wager=${wager}&game=${game}&devnet=${isDevnet ? "1" : "0"}`; + console.log(url); + await fetch(url); }catch(error){ console.error("Error showing new game notification:", error); } diff --git a/src/shared/solana_helpers.ts b/src/shared/solana_helpers.ts index d8ebe04..3c6ee4b 100644 --- a/src/shared/solana_helpers.ts +++ b/src/shared/solana_helpers.ts @@ -232,10 +232,10 @@ export async function joinBet(wallets: ConnectedSolanaWallet, uid: string, gameI // Sign transaction with Privy const signedTx = await wallet.signTransaction(tx); - + const chosenBetVaultAcc = await program.account.betVault.fetch(betVaultPubkey); // Send transaction// Replace with correct RPC endpoint const txId = await connection.sendRawTransaction(signedTx.serialize()); - add_new_activity("join", "",uid, gameId, 0); + add_new_activity("join", "",uid, gameId, chosenBetVaultAcc.wager.toNumber() / LAMPORTS_PER_SOL); console.log(`Transaction ID: ${txId}`); return txId; } catch (error: unknown) {