fix(chat): isolate pending flows and cancel stale requests
This commit is contained in:
@@ -5,7 +5,10 @@ import { useEffect, useRef } from "react";
|
||||
import { shallowEqual } from "@xstate/react";
|
||||
|
||||
import { hasPendingChatUnlock } from "@/lib/navigation/chat_unlock_session";
|
||||
import { useChatDispatch } from "@/stores/chat/chat-context";
|
||||
import {
|
||||
useChatDispatch,
|
||||
useChatSelector,
|
||||
} from "@/stores/chat/chat-context";
|
||||
import { usePaymentSelector } from "@/stores/payment/payment-context";
|
||||
|
||||
export function ChatPaymentSuccessSync() {
|
||||
@@ -17,6 +20,7 @@ export function ChatPaymentSuccessSync() {
|
||||
}),
|
||||
shallowEqual,
|
||||
);
|
||||
const characterId = useChatSelector((state) => state.context.characterId);
|
||||
const chatDispatch = useChatDispatch();
|
||||
const lastPaidKeyRef = useRef<string | null>(null);
|
||||
|
||||
@@ -29,7 +33,7 @@ export function ChatPaymentSuccessSync() {
|
||||
|
||||
let cancelled = false;
|
||||
void (async () => {
|
||||
if (await hasPendingChatUnlock()) return;
|
||||
if (await hasPendingChatUnlock(characterId)) return;
|
||||
if (!cancelled) chatDispatch({ type: "ChatPaymentSucceeded" });
|
||||
})();
|
||||
|
||||
@@ -38,6 +42,7 @@ export function ChatPaymentSuccessSync() {
|
||||
};
|
||||
}, [
|
||||
chatDispatch,
|
||||
characterId,
|
||||
paymentState.currentOrderId,
|
||||
paymentState.isPaid,
|
||||
paymentState.orderStatus,
|
||||
|
||||
Reference in New Issue
Block a user