屏蔽跨账号钱包弹窗状态
为 AI Game Creator 钱包本地弹窗状态绑定账号 owner,并与共享钱包 owner 一起同步控制可见性。 账号切换时立即隐藏旧账单、充值与支付数据,并补充回归测试。
This commit is contained in:
@@ -43,8 +43,13 @@ export function useAccountWallet(currentUserId: string) {
|
||||
const [nativeRechargePayment, setNativeRechargePayment] =
|
||||
useState<PlatformProfileRechargeNativePaymentState | null>(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,
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user