This commit is contained in:
eric
2026-03-10 08:31:24 -05:00
parent 095a7fb260
commit 053482e9f3
4 changed files with 77 additions and 38 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 = 30;
const MAX_POLLS = 160;
const MAX_AGE_MS = 15 * 60 * 1000;
function getCookie(name: string): string | null {
@@ -31,7 +31,7 @@ function parsePayOrderCookie(raw: string | null): [string | null, boolean] {
return [orderId, true];
}
export function usePayStatusPoll(onPaid: () => void, onTimeout?: () => void): boolean {
export function usePayStatusPoll(onPaid: (orderId?: string) => void, onTimeout?: () => void): boolean {
const [polling, setPolling] = useState(false);
const onPaidRef = useRef(onPaid);
const onTimeoutRef = useRef(onTimeout);
@@ -64,7 +64,7 @@ export function usePayStatusPoll(onPaid: () => void, onTimeout?: () => void): bo
clearInterval(timer);
clearCookie(COOKIE_NAME);
setPolling(false);
onPaidRef.current();
onPaidRef.current(orderId);
}
} catch {
// 继续轮询