From 65e767b774e1884deffcf8842afaba1964a946bd Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 23 Feb 2026 20:05:34 +0000 Subject: [PATCH] fix: refresh balance and transactions in WalletModel.connect() on wallet switch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a new wallet is connected, clear stale balance and transaction data from the previous wallet immediately so the view does not display outdated information while fresh data is being fetched. Closes: https://github.com/damus-io/damus/issues/3644 Changelog-Fixed: Wallet view now immediately clears stale data when switching wallets Signed-off-by: Daniel D’Aquino Co-authored-by: Daniel D’Aquino Tested-by: Daniel D’Aquino --- damus/Features/Wallet/Models/WalletModel.swift | 4 ++++ damus/Features/Wallet/Views/WalletView.swift | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/damus/Features/Wallet/Models/WalletModel.swift b/damus/Features/Wallet/Models/WalletModel.swift index 23f72ea4..4111705e 100644 --- a/damus/Features/Wallet/Models/WalletModel.swift +++ b/damus/Features/Wallet/Models/WalletModel.swift @@ -87,6 +87,10 @@ class WalletModel: ObservableObject { notify(.attached_wallet(nwc)) self.connect_state = .existing(nwc) self.previous_state = .existing(nwc) + // Reset cached wallet information so the view does not show stale + // data from a previously connected wallet while fresh data is loading. + self.balance = nil + self.transactions = nil } /// Handles an NWC response event and updates the model. diff --git a/damus/Features/Wallet/Views/WalletView.swift b/damus/Features/Wallet/Views/WalletView.swift index ae052567..e154d0c0 100644 --- a/damus/Features/Wallet/Views/WalletView.swift +++ b/damus/Features/Wallet/Views/WalletView.swift @@ -106,6 +106,11 @@ struct WalletView: View { .task { await self.refreshWalletInformation() } + .onReceive(handle_notify(.attached_wallet)) { _ in + Task { + await self.refreshWalletInformation() + } + } .refreshable { await self.refreshWalletInformation() }