prod v1
This commit is contained in:
parent
be80ad0402
commit
968c2c9b8a
|
|
@ -54,14 +54,19 @@ export default function HeroSection() {
|
|||
|
||||
|
||||
const updateBets = async () => {
|
||||
if (!ready || wallets.length === 0) return;
|
||||
|
||||
const wallet = wallets.find((_wallet) => _wallet.type === "solana") || wallets[0];
|
||||
setSolWallet(wallet);
|
||||
if(ready){
|
||||
const wallet = wallets.find((_wallet) => _wallet.type === "solana") || wallets[0];
|
||||
setSolWallet(wallet);
|
||||
}
|
||||
|
||||
const fetchedBets = await fetchOpenBets();
|
||||
const filteredBets = fetchedBets.filter((bet) => !(bet.owner_id && bet.joiner_id));
|
||||
const filledBets = fetchedBets.filter((bet) => bet.owner_id && bet.joiner_id);
|
||||
setBets(filteredBets);
|
||||
|
||||
if (!ready || wallets.length === 0) return;
|
||||
|
||||
|
||||
let activeBet = filledBets.find((bet) => bet.owner_id === user?.id || bet.joiner_id === user?.id);
|
||||
|
||||
if(activeBet){
|
||||
|
|
@ -81,7 +86,6 @@ export default function HeroSection() {
|
|||
setMyActiveBet(undefined);
|
||||
return;
|
||||
}
|
||||
setBets(filteredBets);
|
||||
|
||||
if (!myActiveBet && lastActiveBet?.address !== activeBet?.address) {
|
||||
setMyActiveBet(activeBet);
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ interface GameModalProps {
|
|||
}
|
||||
|
||||
export default function YourGames({ bets }: GameModalProps) {
|
||||
const { wallets, ready } = useSolanaWallets();
|
||||
const { wallets } = useSolanaWallets();
|
||||
const [myBets, setMyBets] = useState<Bet[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const { user } = usePrivy();
|
||||
|
|
@ -62,14 +62,19 @@ export default function YourGames({ bets }: GameModalProps) {
|
|||
};
|
||||
|
||||
const updateBets = async () => {
|
||||
let wallet = wallets[0];
|
||||
wallets.forEach((_wallet) => {
|
||||
let filteredBets = bets;
|
||||
if(user){
|
||||
let wallet = wallets[0];
|
||||
wallets.forEach((_wallet) => {
|
||||
if (wallet.type === "solana") {
|
||||
wallet = _wallet;
|
||||
}
|
||||
});
|
||||
});
|
||||
filteredBets = bets.filter((bet) => bet.owner !== wallet.address);
|
||||
}else{
|
||||
console.log("No user found, showing all bets");
|
||||
}
|
||||
|
||||
const filteredBets = bets.filter((bet) => bet.owner !== wallet.address);
|
||||
const enrichedBets = await Promise.all(
|
||||
filteredBets.map(async (bet) => {
|
||||
const ownerProfile = await fetchUserById(bet.owner_id);
|
||||
|
|
@ -86,7 +91,6 @@ export default function YourGames({ bets }: GameModalProps) {
|
|||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (!ready) return;
|
||||
updateBets();
|
||||
const interval = setInterval(updateBets, 10000);
|
||||
return () => clearInterval(interval);
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import { useEffect, useState } from "react";
|
|||
import Image from "next/image";
|
||||
import { games } from "../data/games";
|
||||
import { FiTrash } from "react-icons/fi";
|
||||
import { useSolanaWallets } from "@privy-io/react-auth";
|
||||
import { usePrivy, useSolanaWallets } from "@privy-io/react-auth";
|
||||
import { closeBet } from "@/shared/solana_helpers";
|
||||
import { Bet } from "../types/Bet";
|
||||
import { toast } from "sonner";
|
||||
|
|
@ -13,6 +13,7 @@ interface GameModalProps {
|
|||
bets: Bet[];
|
||||
}
|
||||
export default function YourGames({bets}:GameModalProps) {
|
||||
const {user} = usePrivy();
|
||||
const { wallets, ready } = useSolanaWallets();
|
||||
const [myBets, setMyBets] = useState<Bet[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
|
@ -21,13 +22,16 @@ export default function YourGames({bets}:GameModalProps) {
|
|||
|
||||
// Fetch bets
|
||||
const updateBets = async () => {
|
||||
let wallet = wallets[0];
|
||||
wallets.forEach((_wallet) => {
|
||||
if (wallet.type === "solana") {
|
||||
wallet = _wallet;
|
||||
}
|
||||
});
|
||||
if(ready && user){
|
||||
let wallet = wallets[0];
|
||||
wallets.forEach((_wallet) => {
|
||||
if (wallet.type === "solana") {
|
||||
wallet = _wallet;
|
||||
}
|
||||
});
|
||||
setMyBets(bets.filter((bet) => bet.owner === wallet.address));
|
||||
|
||||
}
|
||||
setLoading(false);
|
||||
};
|
||||
|
||||
|
|
@ -78,13 +82,14 @@ export default function YourGames({bets}:GameModalProps) {
|
|||
|
||||
return (
|
||||
<section className="py-16 px-6">
|
||||
<h2 className="text-3xl font-bold text-white mb-6">Your Game</h2>
|
||||
|
||||
|
||||
{loading ? (
|
||||
<p className="text-gray-400">Loading...</p>
|
||||
) : myBets.length === 0 ? (
|
||||
) : !user || !ready || myBets.length === 0 ? (
|
||||
<></>
|
||||
) : (
|
||||
<><h2 className="text-3xl font-bold text-white mb-6">Your Game</h2>
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6">
|
||||
{myBets.map((bet) => {
|
||||
console.log(`Bet id:${bet.id}`);
|
||||
|
|
@ -122,6 +127,7 @@ export default function YourGames({bets}:GameModalProps) {
|
|||
);
|
||||
})}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* Confirmation Modal */}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@ import { Connection } from "@solana/web3.js";
|
|||
|
||||
// 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 CLUSTER_URL = "https://tiniest-cold-darkness.solana-mainnet.quiknode.pro/72332d636ff78d498b880bd8fdc3eb646c827da8/";
|
||||
// export const CLUSTER_URL = "https://go.getblock.io/908837801b534ae7a6f0869fc44cc567";
|
||||
export const CLUSTER_URL = "https://solana-mainnet.core.chainstack.com/c54e14eef17693283a0323efcc4ce731";
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ export async function fetchOpenBets(): Promise<Bet[]> {
|
|||
|
||||
const response = await fetch(`${VALIDATOR_URL}fetchBets`);
|
||||
const data = await response.json();
|
||||
|
||||
console.log(`Fetched ${data.length} open bets`);
|
||||
return data;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user