fix(payment): consume first recharge offer after payment

This commit is contained in:
2026-07-03 10:54:46 +08:00
parent bb6ebbae7e
commit 489554cd78
13 changed files with 137 additions and 27 deletions
+9 -1
View File
@@ -12,10 +12,15 @@ import { useEffect, useRef } from "react";
import { useChatDispatch } from "@/stores/chat/chat-context";
import { useUserDispatch } from "@/stores/user/user-context";
import { hasPendingChatUnlock } from "@/lib/navigation/chat_unlock_session";
import { usePaymentState } from "@/stores/payment/payment-context";
import {
usePaymentDispatch,
usePaymentState,
} from "@/stores/payment/payment-context";
import { getPaymentRepository } from "@/data/repositories/payment_repository";
export function PaymentSuccessSync() {
const paymentState = usePaymentState();
const paymentDispatch = usePaymentDispatch();
const userDispatch = useUserDispatch();
const chatDispatch = useChatDispatch();
const lastPaidKeyRef = useRef<string | null>(null);
@@ -26,10 +31,12 @@ export function PaymentSuccessSync() {
const paidKey = `${paymentState.currentOrderId}:${paymentState.orderStatus}`;
if (lastPaidKeyRef.current === paidKey) return;
lastPaidKeyRef.current = paidKey;
paymentDispatch({ type: "PaymentFirstRechargeConsumed" });
let cancelled = false;
const syncPaymentSuccess = async () => {
await getPaymentRepository().clearCachedPlans();
userDispatch({ type: "UserFetch" });
if (await hasPendingChatUnlock()) return;
if (cancelled) return;
@@ -45,6 +52,7 @@ export function PaymentSuccessSync() {
paymentState.currentOrderId,
paymentState.isPaid,
paymentState.orderStatus,
paymentDispatch,
userDispatch,
]);