fix wechat virtual payment coin flow

This commit is contained in:
kdletters
2026-05-30 16:42:25 +08:00
parent e941ac4539
commit aaaba77c3a
8 changed files with 496 additions and 13 deletions

View File

@@ -337,6 +337,8 @@ type RechargePaymentResult = {
title: string;
message: string;
};
const WECHAT_PAY_RESULT_RECHECK_INTERVAL_MS = 250;
const WECHAT_PAY_RESULT_RECHECK_TIMEOUT_MS = 10000;
function getBarcodeDetectorConstructor(): BarcodeDetectorConstructorLike | null {
const maybeDetector = (globalThis as unknown as {
@@ -4588,7 +4590,7 @@ export function RpgEntryHomeView({
const handleWechatPayResult = useCallback(() => {
const payResult = readWechatPayResultFromHash();
if (!payResult) {
return;
return false;
}
if (
@@ -4596,7 +4598,7 @@ export function RpgEntryHomeView({
payResult.orderId &&
payResult.orderId !== pendingWechatRechargeOrderIdRef.current
) {
return;
return false;
}
setSubmittingRechargeProductId(null);
@@ -4661,6 +4663,7 @@ export function RpgEntryHomeView({
}
clearWechatPayResultHash();
return true;
}, [onRechargeSuccess, refreshRechargeState]);
const openRechargeModal = () => {
if (!authUi?.user) {
@@ -4823,6 +4826,39 @@ export function RpgEntryHomeView({
document.removeEventListener('visibilitychange', handleResume);
};
}, [handleWechatPayResult]);
useEffect(() => {
if (
rechargePaymentResult?.kind !== 'pending' ||
rechargePaymentResult.title !== '正在支付'
) {
return undefined;
}
const startedAt = Date.now();
let timer: number | null = null;
const pollPayResult = () => {
if (handleWechatPayResult()) {
return;
}
if (Date.now() - startedAt >= WECHAT_PAY_RESULT_RECHECK_TIMEOUT_MS) {
return;
}
timer = window.setTimeout(
pollPayResult,
WECHAT_PAY_RESULT_RECHECK_INTERVAL_MS,
);
};
timer = window.setTimeout(
pollPayResult,
WECHAT_PAY_RESULT_RECHECK_INTERVAL_MS,
);
return () => {
if (timer !== null) {
window.clearTimeout(timer);
}
};
}, [handleWechatPayResult, rechargePaymentResult?.kind, rechargePaymentResult?.title]);
const loadTaskCenter = useCallback(() => {
const requestId = ++taskCenterRequestIdRef.current;
setTaskCenterError(null);