refund on timeout
This commit is contained in:
parent
71cf1f90d5
commit
b01e31f146
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
|
|
@ -18,6 +18,7 @@ export default function HeroSection() {
|
||||||
const [solWallet, setSolWallet] = useState<ConnectedSolanaWallet>();
|
const [solWallet, setSolWallet] = useState<ConnectedSolanaWallet>();
|
||||||
const [myActiveBet, setMyActiveBet] = useState<Bet>();
|
const [myActiveBet, setMyActiveBet] = useState<Bet>();
|
||||||
const [rematch, setRematch] = useState(false);
|
const [rematch, setRematch] = useState(false);
|
||||||
|
const [refund, setRefund] = useState(false);
|
||||||
const [lastActiveBet, setLastActiveBet] = useState<Bet>();
|
const [lastActiveBet, setLastActiveBet] = useState<Bet>();
|
||||||
const [rematchInProgress, setRematchInProgress] = useState(false);
|
const [rematchInProgress, setRematchInProgress] = useState(false);
|
||||||
const [rematchTxError, setRematchTxError] = useState(false);
|
const [rematchTxError, setRematchTxError] = useState(false);
|
||||||
|
|
@ -44,8 +45,10 @@ export default function HeroSection() {
|
||||||
|
|
||||||
},[rematch])
|
},[rematch])
|
||||||
|
|
||||||
|
|
||||||
const game_close_signal = (status: number) => {
|
const game_close_signal = (status: number) => {
|
||||||
setRematch(status == 1);
|
setRematch(status == 1);
|
||||||
|
setRefund(status == -1);
|
||||||
setMyActiveBet(undefined);
|
setMyActiveBet(undefined);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -62,11 +65,16 @@ export default function HeroSection() {
|
||||||
const filledBets = fetchedBets.filter((bet) => bet.owner_id && bet.joiner_id);
|
const filledBets = fetchedBets.filter((bet) => bet.owner_id && bet.joiner_id);
|
||||||
const activeBet = filledBets.find((bet) => bet.owner_id === user?.id || bet.joiner_id === user?.id);
|
const activeBet = filledBets.find((bet) => bet.owner_id === user?.id || bet.joiner_id === user?.id);
|
||||||
|
|
||||||
|
if(!activeBet && refund){ // if user got rid of the bet and still on a refund, set refund to false
|
||||||
|
setRefund(false);
|
||||||
|
}
|
||||||
|
|
||||||
if(rematch){
|
if(rematch){
|
||||||
setMyActiveBet(undefined);
|
setMyActiveBet(undefined);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setBets(filteredBets);
|
setBets(filteredBets);
|
||||||
|
|
||||||
if (!myActiveBet && lastActiveBet?.address !== activeBet?.address) {
|
if (!myActiveBet && lastActiveBet?.address !== activeBet?.address) {
|
||||||
setMyActiveBet(activeBet);
|
setMyActiveBet(activeBet);
|
||||||
setLastActiveBet(activeBet);
|
setLastActiveBet(activeBet);
|
||||||
|
|
@ -192,68 +200,6 @@ export default function HeroSection() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// const handleJoinRematch = async () => {
|
|
||||||
// console.log('rejoining rematch');
|
|
||||||
|
|
||||||
// if (!solWallet || !lastActiveBet?.owner_id || !lastActiveBet?.wager) return;
|
|
||||||
|
|
||||||
// setRematchInProgress(true);
|
|
||||||
// setRematchTxError(false);
|
|
||||||
|
|
||||||
// const maxAttempts = 50;
|
|
||||||
// let attempts = 0;
|
|
||||||
|
|
||||||
// const pollForMatchingBet = async (): Promise<Bet | null> => {
|
|
||||||
// try {
|
|
||||||
// const openBets = await fetchOpenBets(solWallet);
|
|
||||||
// const match = openBets.find(
|
|
||||||
// (bet) =>
|
|
||||||
// bet.owner_id === lastActiveBet.owner_id &&
|
|
||||||
// bet.wager === lastActiveBet.wager &&
|
|
||||||
// bet.address !== lastActiveBet.address // to ensure it's a new one
|
|
||||||
// );
|
|
||||||
// return match ?? null;
|
|
||||||
// } catch (err) {
|
|
||||||
// console.error("Error fetching bets:", err);
|
|
||||||
// return null;
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
|
|
||||||
// const tryJoin = async () => {
|
|
||||||
// while (attempts < maxAttempts) {
|
|
||||||
// const matchingBet = await pollForMatchingBet();
|
|
||||||
// if (matchingBet) {
|
|
||||||
// try {
|
|
||||||
// setRematchBetAddress(matchingBet.address);
|
|
||||||
// const tx = await joinBet(
|
|
||||||
// solWallet,
|
|
||||||
// user?.id ?? "",
|
|
||||||
// lastActiveBet.id ?? "tetris",
|
|
||||||
// matchingBet.address
|
|
||||||
// );
|
|
||||||
// console.log("Joined rematch:", tx);
|
|
||||||
// setRematch(false);
|
|
||||||
// return;
|
|
||||||
// } catch (err) {
|
|
||||||
// console.error("Join rematch failed:", err);
|
|
||||||
// setRematchTxError(true);
|
|
||||||
// return;
|
|
||||||
// } finally {
|
|
||||||
// setRematchInProgress(false);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// attempts++;
|
|
||||||
// await new Promise((res) => setTimeout(res, 5000));
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // Max attempts reached
|
|
||||||
// setRematchTxError(true);
|
|
||||||
// setRematchInProgress(false);
|
|
||||||
// };
|
|
||||||
|
|
||||||
// tryJoin();
|
|
||||||
// };
|
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -285,8 +231,13 @@ export default function HeroSection() {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{myActiveBet && !rematch ? (
|
{myActiveBet ? (
|
||||||
(myActiveBet.owner_id && myActiveBet.joiner_id) ? (
|
rematch ? (
|
||||||
|
<div className="w-full h-screen flex justify-center items-center bg-black">
|
||||||
|
<label>Loading...</label>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
myActiveBet.owner_id && myActiveBet.joiner_id ? (
|
||||||
<div className="w-full h-screen flex justify-center items-center bg-black">
|
<div className="w-full h-screen flex justify-center items-center bg-black">
|
||||||
<iframe
|
<iframe
|
||||||
ref={iframeRef}
|
ref={iframeRef}
|
||||||
|
|
@ -295,10 +246,12 @@ export default function HeroSection() {
|
||||||
allowFullScreen
|
allowFullScreen
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
) : <>
|
) : (
|
||||||
<div className="w-full h-screen flex justify-center items-center bg-black">
|
<div className="w-full h-screen flex justify-center items-center bg-black">
|
||||||
<label>Loading...</label>
|
<label>Loading...</label>
|
||||||
</div></>
|
</div>
|
||||||
|
)
|
||||||
|
)
|
||||||
) : (
|
) : (
|
||||||
<section className="flex flex-col items-center text-center py-16">
|
<section className="flex flex-col items-center text-center py-16">
|
||||||
<Image
|
<Image
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user