From b431eb6074acfb02fba1acfd5af3439e5497ecb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=BE=B7=E5=AE=87?= Date: Sun, 4 Oct 2026 15:55:38 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E9=92=B1=E5=8C=85=20store):=20?= =?UTF-8?q?=E6=8A=BD=E5=87=BA=E4=BD=99=E9=A2=9D=E5=B0=B1=E7=BB=AA=E6=80=81?= =?UTF-8?q?=E7=BB=9F=E4=B8=80=E6=9E=84=E9=80=A0=EF=BC=8C=E6=B6=88=E9=99=A4?= =?UTF-8?q?=E9=87=8D=E5=A4=8D=20set?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - applyWalletBalanceSnapshot 与刷新循环各自重复「resolve 视图 + 写 4 个 ready 字段」 - 抽出 readyWalletBalanceState 统一派生 totalPoints / status / error,两条路径不再有漂移风险 - 行为不变(注:本文件既有的 rejects a snapshot from another owner 用例在改动前后均失败,与本次无关) --- .../src/stores/createProfileWalletStore.ts | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/packages/shared/src/stores/createProfileWalletStore.ts b/packages/shared/src/stores/createProfileWalletStore.ts index a2ec1eeeb..211ba8800 100644 --- a/packages/shared/src/stores/createProfileWalletStore.ts +++ b/packages/shared/src/stores/createProfileWalletStore.ts @@ -49,6 +49,20 @@ const EMPTY_WALLET_STATE = { mudPointBalanceError: '', } as const; +/** + * 余额读取成功后的统一就绪态:快照应用与刷新循环共用同一段派生逻辑, + * 避免 `totalPoints` 与 ready 字段在两条路径上各自漂移。 + */ +function readyWalletBalanceState(balance: ProfileMudPointBalance) { + const mudPointBalance = resolveProfileMudPointBalanceView(balance); + return { + mudPointBalance, + legacyWalletBalance: mudPointBalance.totalPoints, + mudPointBalanceStatus: 'ready' as const, + mudPointBalanceError: '', + }; +} + export function createProfileWalletStore( api: ProfileWalletApi, ): UseBoundStore> { @@ -119,13 +133,7 @@ export function createProfileWalletStore( snapshot.operationSequence, ); settledRefreshVersion = snapshot.invalidationVersion; - const mudPointBalance = resolveProfileMudPointBalanceView(balance); - set({ - mudPointBalance, - legacyWalletBalance: mudPointBalance.totalPoints, - mudPointBalanceStatus: 'ready', - mudPointBalanceError: '', - }); + set(readyWalletBalanceState(balance)); return true; }, onWalletBalanceMayHaveChanged: () => { @@ -160,15 +168,7 @@ export function createProfileWalletStore( } settledRefreshVersion = requestedVersion; - const mudPointBalance = resolveProfileMudPointBalanceView( - center.mudPointBalance, - ); - set({ - mudPointBalance, - legacyWalletBalance: mudPointBalance.totalPoints, - mudPointBalanceStatus: 'ready', - mudPointBalanceError: '', - }); + set(readyWalletBalanceState(center.mudPointBalance)); } catch { if (generation !== requestGeneration) { return;