归一化钱包快照账号标识

在应用外部钱包快照前统一 trim owner ID,保持与 owner 绑定入口相同的边界规则。

补充带前后空白的同账号快照回归测试。
This commit is contained in:
2026-08-05 17:53:18 +08:00
parent a701058780
commit 327cf3d2a8
2 changed files with 21 additions and 1 deletions
@@ -182,4 +182,20 @@ describe('createProfileWalletStore', () => {
expect(store.getState().mudPointBalance).toBeNull();
expect(store.getState().mudPointBalanceStatus).toBe('idle');
});
test('normalizes a snapshot owner before matching it', () => {
const store = createProfileWalletStore({
getRechargeCenter: vi.fn(),
});
store.getState().setWalletOwner('user-a');
store
.getState()
.applyWalletBalanceSnapshot(' user-a ', balance(100));
expect(store.getState()).toMatchObject({
mudPointBalance: balance(100),
mudPointBalanceStatus: 'ready',
});
});
});
@@ -64,7 +64,11 @@ export function createProfileWalletStore(
});
},
applyWalletBalanceSnapshot: (ownerUserId, balance) => {
if (!ownerUserId || get().ownerUserId !== ownerUserId) {
const normalizedOwnerUserId = ownerUserId.trim();
if (
!normalizedOwnerUserId ||
get().ownerUserId !== normalizedOwnerUserId
) {
return;
}