From 5361d8963993d2e8680faed61e233446a31675df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=BE=B7=E5=AE=87?= Date: Sat, 3 Oct 2026 14:58:28 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E4=BC=9A=E5=91=98=E6=8A=A5=E4=BB=B7):=20?= =?UTF-8?q?=E6=A1=8C=E9=9D=A2=E7=AB=AF=E6=8A=A5=E4=BB=B7=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=BA=8F=E5=8F=B7=E5=AE=88=E5=8D=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - useAccountWallet.ts:requestMembershipQuote 记录请求令牌,只有最新请求可以写入报价、错误与 loading Co-authored-by: Junie --- .../features/app-shell/useAccountWallet.ts | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) 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); } }