fix(payment): consume first recharge offer after payment
This commit is contained in:
@@ -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,
|
||||
]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user