diff --git a/apps/ai-game-creator-shell/src/features/app-shell/useAccountWallet.ts b/apps/ai-game-creator-shell/src/features/app-shell/useAccountWallet.ts index 5649adfde..454b8e955 100644 --- a/apps/ai-game-creator-shell/src/features/app-shell/useAccountWallet.ts +++ b/apps/ai-game-creator-shell/src/features/app-shell/useAccountWallet.ts @@ -64,6 +64,7 @@ export function useAccountWallet(currentUserId: string) { null, ); const rechargeLifecycleRef = useRef(0); + const membershipQuoteRequestRef = useRef(null); const walletLedgerLifecycleRef = useRef(0); const redeemLifecycleRef = useRef(0); const [walletUiOwnerUserId, setWalletUiOwnerUserId] = useState(currentUserId); @@ -395,32 +396,29 @@ export function useAccountWallet(currentUserId: string) { async function requestMembershipQuote(plan: ProfileMembershipPlan) { const rechargeLifecycle = rechargeLifecycleRef.current; const snapshotOwnerUserId = currentUserId; + const requestToken = Symbol('profile-membership-quote'); + membershipQuoteRequestRef.current = requestToken; + const isLatestQuoteRequest = () => + rechargeLifecycleRef.current === rechargeLifecycle && + currentUserIdRef.current === snapshotOwnerUserId && + membershipQuoteRequestRef.current === requestToken; setMembershipQuote(null); setMembershipQuoteError(null); setMembershipQuoteLoading(true); try { const quote = await getClientProfileMembershipUpgradeQuote(plan); - if ( - rechargeLifecycleRef.current !== rechargeLifecycle || - currentUserIdRef.current !== snapshotOwnerUserId - ) { + if (!isLatestQuoteRequest()) { return; } setMembershipQuote(quote); } catch (error) { - if ( - rechargeLifecycleRef.current === rechargeLifecycle && - currentUserIdRef.current === snapshotOwnerUserId - ) { + if (isLatestQuoteRequest()) { setMembershipQuoteError( error instanceof Error ? error.message : '读取升级报价失败', ); } } finally { - if ( - rechargeLifecycleRef.current === rechargeLifecycle && - currentUserIdRef.current === snapshotOwnerUserId - ) { + if (isLatestQuoteRequest()) { setMembershipQuoteLoading(false); } }