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:
committed by
Daniel D’Aquino
parent
af9956de8a
commit
65e767b774
@@ -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.
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user