From f8e308be1598cd258305bbb1a727ef477f26006c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=BE=B7=E5=AE=87?= Date: Wed, 5 Aug 2026 17:51:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B1=8F=E8=94=BD=E8=B7=A8=E8=B4=A6=E5=8F=B7?= =?UTF-8?q?=E9=92=B1=E5=8C=85=E5=BC=B9=E7=AA=97=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 为 AI Game Creator 钱包本地弹窗状态绑定账号 owner,并与共享钱包 owner 一起同步控制可见性。 账号切换时立即隐藏旧账单、充值与支付数据,并补充回归测试。 --- .../features/app-shell/useAccountWallet.ts | 28 +++++++++++++------ .../tests/walletStore.test.ts | 28 +++++++++++++++++++ 2 files changed, 47 insertions(+), 9 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 0cbe9fd66..7b57f9d96 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 @@ -43,8 +43,13 @@ export function useAccountWallet(currentUserId: string) { const [nativeRechargePayment, setNativeRechargePayment] = useState(null); const rechargeLifecycleRef = useRef(0); + const [walletUiOwnerUserId, setWalletUiOwnerUserId] = useState(currentUserId); const walletOwnerMatchesCurrentUser = Boolean(currentUserId) && ownerUserId === currentUserId; + const walletUiOwnerMatchesCurrentUser = + Boolean(currentUserId) && walletUiOwnerUserId === currentUserId; + const walletUiIsVisible = + walletOwnerMatchesCurrentUser && walletUiOwnerMatchesCurrentUser; const visibleMudPointBalance = walletOwnerMatchesCurrentUser ? mudPointBalance : null; @@ -74,6 +79,7 @@ export function useAccountWallet(currentUserId: string) { useEffect(() => { rechargeLifecycleRef.current += 1; + setWalletUiOwnerUserId(currentUserId); setWalletLedgerOpen(false); setWalletLedger(null); setWalletLedgerLoading(false); @@ -268,12 +274,12 @@ export function useAccountWallet(currentUserId: string) { mudPointBalanceError: visibleMudPointBalanceError, onWalletBalanceMayHaveChanged, resetWalletBalance, - walletLedgerOpen, + walletLedgerOpen: walletUiIsVisible && walletLedgerOpen, setWalletLedgerOpen, - walletLedger, - walletLedgerLoading, - walletLedgerError, - rechargeOpen, + walletLedger: walletUiIsVisible ? walletLedger : null, + walletLedgerLoading: walletUiIsVisible && walletLedgerLoading, + walletLedgerError: walletUiIsVisible ? walletLedgerError : null, + rechargeOpen: walletUiIsVisible && rechargeOpen, rechargeModalCenter: rechargeContent && visibleMudPointBalance ? { @@ -282,10 +288,14 @@ export function useAccountWallet(currentUserId: string) { mudPointBalance: visibleMudPointBalance, } : null, - rechargeLoading, - rechargeError, - submittingRechargeProductId, - nativeRechargePayment, + rechargeLoading: walletUiIsVisible && rechargeLoading, + rechargeError: walletUiIsVisible ? rechargeError : null, + submittingRechargeProductId: walletUiIsVisible + ? submittingRechargeProductId + : null, + nativeRechargePayment: walletUiIsVisible + ? nativeRechargePayment + : null, setNativeRechargePayment, loadWalletLedger, openWalletLedger, diff --git a/apps/ai-game-creator-shell/tests/walletStore.test.ts b/apps/ai-game-creator-shell/tests/walletStore.test.ts index 8d5c5b788..64b162f83 100644 --- a/apps/ai-game-creator-shell/tests/walletStore.test.ts +++ b/apps/ai-game-creator-shell/tests/walletStore.test.ts @@ -245,4 +245,32 @@ describe('useWalletStore', () => { mudPointBalance: detailedBalance(18), }); }); + + test('hides account-owned dialogs and data when the account changes', async () => { + clientApi.getClientProfileRechargeCenter.mockResolvedValue({ + walletBalance: 18, + mudPointBalance: detailedBalance(18), + }); + clientApi.getClientProfileWalletLedger.mockResolvedValue({ entries: [] }); + const { result, rerender } = renderHook( + ({ userId }) => useAccountWallet(userId), + { initialProps: { userId: 'user-a' } }, + ); + await act(async () => undefined); + await act(async () => { + result.current.openWalletLedger(); + result.current.openRecharge(); + }); + expect(result.current.walletLedgerOpen).toBe(true); + expect(result.current.rechargeOpen).toBe(true); + + await act(async () => { + rerender({ userId: 'user-b' }); + }); + + expect(result.current.walletLedgerOpen).toBe(false); + expect(result.current.walletLedger).toBeNull(); + expect(result.current.rechargeOpen).toBe(false); + expect(result.current.nativeRechargePayment).toBeNull(); + }); });