subscribe to events on event manager rather than individual wallets.
MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/ClosedWalletViewModel.cs
WalletWasabi.Gui/Controls/WalletExplorer/ClosedWalletViewModel.cs
@@ -47,8 +47,6 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
walletExplorer.RemoveWallet(this);
- Dispose();
-
walletExplorer.OpenClosedWallet(this);
});
}

MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/WalletExplorerViewModel.cs
WalletWasabi.Gui/Controls/WalletExplorer/WalletExplorerViewModel.cs
+using System;
using AvalonStudio.Extensibility;
using AvalonStudio.MVVM;
using AvalonStudio.Shell;
@@ -7,6 +8,7 @@ using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Composition;
using System.Linq;
+using System.Reactive.Linq;
using WalletWasabi.Gui.ViewModels;
using WalletWasabi.Wallets;
@@ -20,6 +22,7 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
{
private ObservableCollection<WalletViewModelBase> _wallets;
private ViewModelBase _selectedItem;
+ private Dictionary<Wallet, WalletViewModelBase> _walletDictionary;
public override Location DefaultLocation => Location.Right;
@@ -29,7 +32,21 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
_wallets = new ObservableCollection<WalletViewModelBase>();
+ _walletDictionary = new Dictionary<Wallet, WalletViewModelBase>();
+
WalletManager = Locator.Current.GetService<Global>().WalletManager;
+
+ Observable.FromEventPattern<WalletState>(WalletManager, nameof(WalletManager.WalletStateChanged))
+ .ObserveOn(RxApp.MainThreadScheduler)
+ .Subscribe(x =>
+ {
+ var wallet = x.Sender as Wallet;
+
+ if (wallet is { } && _walletDictionary.ContainsKey(wallet))
+ {
+ _walletDictionary[wallet].WalletState = x.EventArgs;
+ }
+ });
}
private WalletManager WalletManager { get; }
@@ -46,6 +63,12 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
set => this.RaiseAndSetIfChanged(ref _selectedItem, value);
}
+ private void InsertWallet(WalletViewModelBase walletVM)
+ {
+ Wallets.InsertSorted(walletVM);
+ _walletDictionary.Add(walletVM.Wallet, walletVM);
+ }
+
internal WalletViewModelBase OpenWallet(Wallet wallet)
{
if (wallet.Coins.Any())
@@ -80,23 +103,24 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
var walletViewModel = new WalletViewModel(wallet);
- Wallets.InsertSorted(walletViewModel);
+ InsertWallet(walletViewModel);
walletViewModel.OpenWallet(receiveDominant);
return walletViewModel;
}
- internal void RemoveWallet(WalletViewModelBase wallet)
+ internal void RemoveWallet(WalletViewModelBase walletVM)
{
- Wallets.Remove(wallet);
+ Wallets.Remove(walletVM);
+ _walletDictionary.Remove(walletVM.Wallet);
}
private void LoadWallets()
{
foreach (var wallet in WalletManager.GetKeyManagers())
{
- Wallets.InsertSorted(new ClosedWalletViewModel(WalletManager.GetWalletByName(wallet.WalletName)));
+ InsertWallet(new ClosedWalletViewModel(WalletManager.GetWalletByName(wallet.WalletName)));
}
}

MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/WalletViewModelBase.cs
WalletWasabi.Gui/Controls/WalletExplorer/WalletViewModelBase.cs
@@ -9,14 +9,12 @@ using WalletWasabi.Wallets;
namespace WalletWasabi.Gui.Controls.WalletExplorer
{
- public class WalletViewModelBase : ViewModelBase, IComparable<WalletViewModelBase>, IDisposable
+ public class WalletViewModelBase : ViewModelBase, IComparable<WalletViewModelBase>
{
private bool _isExpanded;
private bool _isBusy;
private string _title;
private WalletState _walletState;
- private CompositeDisposable _disposables;
- private volatile bool _disposedValue = false;
public WalletViewModelBase(Wallet wallet)
{
@@ -25,13 +23,6 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
Wallet = wallet;
Title = WalletName;
- _disposables = new CompositeDisposable();
-
- Observable.FromEventPattern<WalletState>(wallet, nameof(wallet.StateChanged))
- .ObserveOn(RxApp.MainThreadScheduler)
- .Subscribe(x => WalletState = x.EventArgs)
- .DisposeWith(_disposables);
-
WalletState = wallet.State;
this.WhenAnyValue(x => x.WalletState)
@@ -93,26 +84,5 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
return Title.CompareTo(other.Title);
}
-
- #region IDisposable Support
- protected virtual void Dispose(bool disposing)
- {
- if (!_disposedValue)
- {
- if (disposing)
- {
- _disposables?.Dispose();
- }
-
- _disposables = null;
- _disposedValue = true;
- }
- }
-
- public void Dispose()
- {
- Dispose(true);
- }
- #endregion IDisposable Support
}
}

subscribe to events on event manager rather than individual wallets.