This commit is contained in:
eric
2026-03-10 07:23:18 -05:00
parent a1696c2d0b
commit e9c6ec4d84
4 changed files with 100 additions and 34 deletions

View File

@@ -6,7 +6,7 @@ import { useEffect, useRef, useState } from "react";
const COOKIE_NAME = "nomadvip_pay_order";
const POLL_INTERVAL = 2000;
const MAX_POLLS = 150;
const MAX_POLLS = 30;
const MAX_AGE_MS = 15 * 60 * 1000;
function getCookie(name: string): string | null {
@@ -31,10 +31,12 @@ function parsePayOrderCookie(raw: string | null): [string | null, boolean] {
return [orderId, true];
}
export function usePayStatusPoll(onPaid: () => void): boolean {
export function usePayStatusPoll(onPaid: () => void, onTimeout?: () => void): boolean {
const [polling, setPolling] = useState(false);
const onPaidRef = useRef(onPaid);
const onTimeoutRef = useRef(onTimeout);
onPaidRef.current = onPaid;
onTimeoutRef.current = onTimeout;
useEffect(() => {
const raw = getCookie(COOKIE_NAME);
@@ -52,6 +54,7 @@ export function usePayStatusPoll(onPaid: () => void): boolean {
clearInterval(timer);
clearCookie(COOKIE_NAME);
setPolling(false);
onTimeoutRef.current?.();
return;
}
try {