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 [myActiveBet, setMyActiveBet] = useState<Bet>();
|
||||
const [rematch, setRematch] = useState(false);
|
||||
const [refund, setRefund] = useState(false);
|
||||
const [lastActiveBet, setLastActiveBet] = useState<Bet>();
|
||||
const [rematchInProgress, setRematchInProgress] = useState(false);
|
||||
const [rematchTxError, setRematchTxError] = useState(false);
|
||||
|
|
@ -44,8 +45,10 @@ export default function HeroSection() {
|
|||
|
||||
},[rematch])
|
||||
|
||||
|
||||
const game_close_signal = (status: number) => {
|
||||
setRematch(status == 1);
|
||||
setRefund(status == -1);
|
||||
setMyActiveBet(undefined);
|
||||
};
|
||||
|
||||
|
|
@ -62,11 +65,16 @@ export default function HeroSection() {
|
|||
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);
|
||||
|
||||
if(!activeBet && refund){ // if user got rid of the bet and still on a refund, set refund to false
|
||||
setRefund(false);
|
||||
}
|
||||
|
||||
if(rematch){
|
||||
setMyActiveBet(undefined);
|
||||
return;
|
||||
}
|
||||
setBets(filteredBets);
|
||||
|
||||
if (!myActiveBet && lastActiveBet?.address !== activeBet?.address) {
|
||||
setMyActiveBet(activeBet);
|
||||
setLastActiveBet(activeBet);
|
||||
|
|
@ -191,69 +199,7 @@ export default function HeroSection() {
|
|||
console.error("Error during handleJoinRematch:", err);
|
||||
}
|
||||
};
|
||||
|
||||
// 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(() => {
|
||||
|
|
@ -285,20 +231,27 @@ export default function HeroSection() {
|
|||
|
||||
return (
|
||||
<>
|
||||
{myActiveBet && !rematch ? (
|
||||
(myActiveBet.owner_id && myActiveBet.joiner_id) ? (
|
||||
<div className="w-full h-screen flex justify-center items-center bg-black">
|
||||
<iframe
|
||||
ref={iframeRef}
|
||||
src={`/UnityBuild/${myActiveBet.id}/index.html?betId=${myActiveBet.id}&owner=${myActiveBet.owner_id}&joiner=${myActiveBet.joiner_id}&address=${myActiveBet.address}&uid=${user?.id}&pubkey=${solWallet?.address}&wager=${myActiveBet.wager * 1e8}`}
|
||||
className="w-full h-full"
|
||||
allowFullScreen
|
||||
/>
|
||||
</div>
|
||||
) : <>
|
||||
<div className="w-full h-screen flex justify-center items-center bg-black">
|
||||
<label>Loading...</label>
|
||||
</div></>
|
||||
{myActiveBet ? (
|
||||
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">
|
||||
<iframe
|
||||
ref={iframeRef}
|
||||
src={`/UnityBuild/${myActiveBet.id}/index.html?betId=${myActiveBet.id}&owner=${myActiveBet.owner_id}&joiner=${myActiveBet.joiner_id}&address=${myActiveBet.address}&uid=${user?.id}&pubkey=${solWallet?.address}&wager=${myActiveBet.wager * 1e8}`}
|
||||
className="w-full h-full"
|
||||
allowFullScreen
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<div className="w-full h-screen flex justify-center items-center bg-black">
|
||||
<label>Loading...</label>
|
||||
</div>
|
||||
)
|
||||
)
|
||||
) : (
|
||||
<section className="flex flex-col items-center text-center py-16">
|
||||
<Image
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user