Fix token account switcher not refreshing menu with new account data#799
Fix token account switcher not refreshing menu with new account data#799Zeko369 wants to merge 1 commit intosteipete:mainfrom
Conversation
When switching token accounts via the menu, the usage card did not update because (1) `store.refresh()` was silently dropped by the global `isRefreshing` guard when an existing refresh was in-flight, and (2) the open menu was never repopulated after the async fetch completed. Replace `store.refresh()` with `store.refreshProvider(display.provider)` which targets only the relevant provider and is not blocked by the global refresh gate. Add `refreshOpenMenuIfStillVisible` after the fetch completes so the menu updates in-place, matching the pattern used by the Codex account switcher. Fixes steipete#798 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3a24f18f0e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| Task { @MainActor in | ||
| await ProviderInteractionContext.$current.withValue(.userInitiated) { | ||
| await self.store.refresh() | ||
| await self.store.refreshProvider(display.provider) |
There was a problem hiding this comment.
Avoid concurrent provider refreshes on account switch
Calling refreshProvider(display.provider) here can race with the menu-open refresh that is already running (menuWillOpen -> scheduleOpenMenuRefresh -> refreshStore), because UsageStore.refreshProvider has no per-provider in-flight guard and applies results unconditionally (refreshingProviders.insert is bookkeeping only, then snapshot writes happen on completion). In that overlap, the earlier refresh (started with the previous token account) can finish after the new selection and overwrite the newer snapshot, so the menu may revert to stale account data even though the switcher shows the new account.
Useful? React with 👍 / 👎.
|
Thanks @Zeko369 — I landed this on main in 1164cb8 with changelog credit and a regression test. The final patch keeps your provider-scoped refresh idea, adapted to current main: token account selections now call Verified:
|
Summary
store.refresh()with targetedstore.refreshProvider(display.provider)in the token account switcher'sonSelecthandler — avoids being silently dropped by the globalisRefreshingguard when a menu-open refresh is already in-flightrefreshOpenMenuIfStillVisibleafter the async fetch completes so the open menu updates in-place (matching the Codex account switcher pattern)Fixes #798
Test plan
🤖 Generated with Claude Code