fix: refresh balance and transactions in WalletModel.connect() on wallet switch

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 <daniel@daquino.me>
Co-authored-by: Daniel D’Aquino <daniel@daquino.me>
Tested-by: Daniel D’Aquino <daniel@daquino.me>
This commit is contained in:
copilot-swe-agent[bot]
2026-02-23 20:05:34 +00:00
committed by Daniel D’Aquino
parent af9956de8a
commit 65e767b774
2 changed files with 9 additions and 0 deletions

View File

@@ -87,6 +87,10 @@ class WalletModel: ObservableObject {
notify(.attached_wallet(nwc)) notify(.attached_wallet(nwc))
self.connect_state = .existing(nwc) self.connect_state = .existing(nwc)
self.previous_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. /// Handles an NWC response event and updates the model.

View File

@@ -106,6 +106,11 @@ struct WalletView: View {
.task { .task {
await self.refreshWalletInformation() await self.refreshWalletInformation()
} }
.onReceive(handle_notify(.attached_wallet)) { _ in
Task {
await self.refreshWalletInformation()
}
}
.refreshable { .refreshable {
await self.refreshWalletInformation() await self.refreshWalletInformation()
} }