prod v1
This commit is contained in:
parent
be80ad0402
commit
968c2c9b8a
|
|
@ -54,14 +54,19 @@ export default function HeroSection() {
|
||||||
|
|
||||||
|
|
||||||
const updateBets = async () => {
|
const updateBets = async () => {
|
||||||
if (!ready || wallets.length === 0) return;
|
if(ready){
|
||||||
|
const wallet = wallets.find((_wallet) => _wallet.type === "solana") || wallets[0];
|
||||||
const wallet = wallets.find((_wallet) => _wallet.type === "solana") || wallets[0];
|
setSolWallet(wallet);
|
||||||
setSolWallet(wallet);
|
}
|
||||||
|
|
||||||
const fetchedBets = await fetchOpenBets();
|
const fetchedBets = await fetchOpenBets();
|
||||||
const filteredBets = fetchedBets.filter((bet) => !(bet.owner_id && bet.joiner_id));
|
const filteredBets = fetchedBets.filter((bet) => !(bet.owner_id && bet.joiner_id));
|
||||||
const filledBets = 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);
|
let activeBet = filledBets.find((bet) => bet.owner_id === user?.id || bet.joiner_id === user?.id);
|
||||||
|
|
||||||
if(activeBet){
|
if(activeBet){
|
||||||
|
|
@ -81,7 +86,6 @@ export default function HeroSection() {
|
||||||
setMyActiveBet(undefined);
|
setMyActiveBet(undefined);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setBets(filteredBets);
|
|
||||||
|
|
||||||
if (!myActiveBet && lastActiveBet?.address !== activeBet?.address) {
|
if (!myActiveBet && lastActiveBet?.address !== activeBet?.address) {
|
||||||
setMyActiveBet(activeBet);
|
setMyActiveBet(activeBet);
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ interface GameModalProps {
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function YourGames({ bets }: GameModalProps) {
|
export default function YourGames({ bets }: GameModalProps) {
|
||||||
const { wallets, ready } = useSolanaWallets();
|
const { wallets } = useSolanaWallets();
|
||||||
const [myBets, setMyBets] = useState<Bet[]>([]);
|
const [myBets, setMyBets] = useState<Bet[]>([]);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const { user } = usePrivy();
|
const { user } = usePrivy();
|
||||||
|
|
@ -62,14 +62,19 @@ export default function YourGames({ bets }: GameModalProps) {
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateBets = async () => {
|
const updateBets = async () => {
|
||||||
let wallet = wallets[0];
|
let filteredBets = bets;
|
||||||
wallets.forEach((_wallet) => {
|
if(user){
|
||||||
|
let wallet = wallets[0];
|
||||||
|
wallets.forEach((_wallet) => {
|
||||||
if (wallet.type === "solana") {
|
if (wallet.type === "solana") {
|
||||||
wallet = _wallet;
|
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(
|
const enrichedBets = await Promise.all(
|
||||||
filteredBets.map(async (bet) => {
|
filteredBets.map(async (bet) => {
|
||||||
const ownerProfile = await fetchUserById(bet.owner_id);
|
const ownerProfile = await fetchUserById(bet.owner_id);
|
||||||
|
|
@ -86,7 +91,6 @@ export default function YourGames({ bets }: GameModalProps) {
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!ready) return;
|
|
||||||
updateBets();
|
updateBets();
|
||||||
const interval = setInterval(updateBets, 10000);
|
const interval = setInterval(updateBets, 10000);
|
||||||
return () => clearInterval(interval);
|
return () => clearInterval(interval);
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import { useEffect, useState } from "react";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import { games } from "../data/games";
|
import { games } from "../data/games";
|
||||||
import { FiTrash } from "react-icons/fi";
|
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 { closeBet } from "@/shared/solana_helpers";
|
||||||
import { Bet } from "../types/Bet";
|
import { Bet } from "../types/Bet";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
|
|
@ -13,6 +13,7 @@ interface GameModalProps {
|
||||||
bets: Bet[];
|
bets: Bet[];
|
||||||
}
|
}
|
||||||
export default function YourGames({bets}:GameModalProps) {
|
export default function YourGames({bets}:GameModalProps) {
|
||||||
|
const {user} = usePrivy();
|
||||||
const { wallets, ready } = useSolanaWallets();
|
const { wallets, ready } = useSolanaWallets();
|
||||||
const [myBets, setMyBets] = useState<Bet[]>([]);
|
const [myBets, setMyBets] = useState<Bet[]>([]);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
|
|
@ -21,13 +22,16 @@ export default function YourGames({bets}:GameModalProps) {
|
||||||
|
|
||||||
// Fetch bets
|
// Fetch bets
|
||||||
const updateBets = async () => {
|
const updateBets = async () => {
|
||||||
let wallet = wallets[0];
|
if(ready && user){
|
||||||
wallets.forEach((_wallet) => {
|
let wallet = wallets[0];
|
||||||
if (wallet.type === "solana") {
|
wallets.forEach((_wallet) => {
|
||||||
wallet = _wallet;
|
if (wallet.type === "solana") {
|
||||||
}
|
wallet = _wallet;
|
||||||
});
|
}
|
||||||
|
});
|
||||||
setMyBets(bets.filter((bet) => bet.owner === wallet.address));
|
setMyBets(bets.filter((bet) => bet.owner === wallet.address));
|
||||||
|
|
||||||
|
}
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -78,13 +82,14 @@ export default function YourGames({bets}:GameModalProps) {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section className="py-16 px-6">
|
<section className="py-16 px-6">
|
||||||
<h2 className="text-3xl font-bold text-white mb-6">Your Game</h2>
|
|
||||||
|
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<p className="text-gray-400">Loading...</p>
|
<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">
|
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6">
|
||||||
{myBets.map((bet) => {
|
{myBets.map((bet) => {
|
||||||
console.log(`Bet id:${bet.id}`);
|
console.log(`Bet id:${bet.id}`);
|
||||||
|
|
@ -122,6 +127,7 @@ export default function YourGames({bets}:GameModalProps) {
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Confirmation Modal */}
|
{/* Confirmation Modal */}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,9 @@ import { Connection } from "@solana/web3.js";
|
||||||
|
|
||||||
// Replace this URL with your dedicated RPC endpoint
|
// Replace this URL with your dedicated RPC endpoint
|
||||||
// You can get one from providers like QuickNode, Alchemy, Helius, or GenesysGo
|
// 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_ADDRESS_TEMPLATE = "https://explorer.solana.com/address/{address}";
|
||||||
export const EXPLORER_TX_TEMPLATE = "https://explorer.solana.com/tx/{address}";
|
export const EXPLORER_TX_TEMPLATE = "https://explorer.solana.com/tx/{address}";
|
||||||
export const connection = new Connection(CLUSTER_URL);
|
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 response = await fetch(`${VALIDATOR_URL}fetchBets`);
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
console.log(`Fetched ${data.length} open bets`);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user