diff --git a/packages/shared/src/stores/createProfileWalletStore.test.ts b/packages/shared/src/stores/createProfileWalletStore.test.ts index 88c5da148..daba9d20f 100644 --- a/packages/shared/src/stores/createProfileWalletStore.test.ts +++ b/packages/shared/src/stores/createProfileWalletStore.test.ts @@ -296,7 +296,7 @@ describe('createProfileWalletStore', () => { const snapshot = store.getState().captureWalletBalanceSnapshot('user-b'); expect( - store.getState().applyWalletBalanceSnapshot(snapshot!, balance(37)), + store.getState().applyWalletBalanceSnapshot(snapshot, balance(37)), ).toBe(false); expect(store.getState().mudPointBalance).toBeNull(); }); diff --git a/packages/shared/src/stores/createProfileWalletStore.ts b/packages/shared/src/stores/createProfileWalletStore.ts index 211ba8800..c63c032c6 100644 --- a/packages/shared/src/stores/createProfileWalletStore.ts +++ b/packages/shared/src/stores/createProfileWalletStore.ts @@ -35,7 +35,7 @@ export type ProfileWalletStore = { ownerUserId: string, ) => ProfileWalletBalanceSnapshot | null; applyWalletBalanceSnapshot: ( - snapshot: ProfileWalletBalanceSnapshot, + snapshot: ProfileWalletBalanceSnapshot | null, balance: ProfileMudPointBalance, ) => boolean; onWalletBalanceMayHaveChanged: () => Promise; @@ -117,6 +117,11 @@ export function createProfileWalletStore( }; }, applyWalletBalanceSnapshot: (snapshot, balance) => { + // captureWalletBalanceSnapshot 在 owner 不匹配时返回 null;null 本身即「快照已失效」, + // 直接拒绝,避免把 capture 的可空返回喂回 apply 时解引用崩溃。 + if (!snapshot) { + return false; + } if ( get().ownerUserId !== snapshot.ownerUserId || ownerVersion !== snapshot.ownerVersion ||