Skip to content

refactor(ui): centralize wallet selection to prevent stale sync panel cache #657

@lklimek

Description

@lklimek

Context

PR #642 introduced a platform_sync_info cache on WalletsBalancesScreen to avoid DB reads every frame for the sync status panel. The cache is refreshed in select_hd_wallet() and two display_task_result() handlers.

Problem

Several code paths assign self.selected_wallet directly without going through select_hd_wallet(), which means platform_sync_info is not refreshed:

  • update_selected_wallet_for_network() (lines 288, 309) — fallback wallet selection after network switch
  • Wallet removal handler (line 716) — selecting next wallet after removing current
  • refresh_on_arrival() (line 2239) — auto-selecting first wallet when none selected

This can leave stale sync status data displayed for the wrong wallet.

Proposed Solution

Create a centralized set_selected_hd_wallet(&mut self, wallet: Option<Arc<RwLock<Wallet>>>) helper that:

  1. Sets self.selected_wallet
  2. Clears self.selected_account
  3. Persists the wallet hash
  4. Refreshes platform_sync_info cache

Replace all direct assignments to self.selected_wallet with calls to this helper.

References

🤖 Filed by Claudius the Magnificent AI Agent

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions