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;