Cleanup WalletManagerViewModel
MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/WalletViewModelBase.cs
WalletWasabi.Gui/Controls/WalletExplorer/WalletViewModelBase.cs
@@ -27,12 +27,11 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
Wallet = wallet;
Title = WalletName;
- WalletState = wallet.State;
-
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)
.Subscribe(x =>

MODIFY
WalletWasabi.Gui/Tabs/WalletManager/GenerateWallets/GenerateWalletSuccessViewModel.cs
WalletWasabi.Gui/Tabs/WalletManager/GenerateWallets/GenerateWalletSuccessViewModel.cs
@@ -26,7 +26,7 @@ namespace WalletWasabi.Gui.Tabs.WalletManager.GenerateWallets
{
var wallet = global.WalletManager.AddWallet(keyManager);
NotificationHelpers.Success("Wallet was generated.");
- owner.SelectTestPassword();
+ owner.SelectTestPassword(wallet.WalletName);
});
ConfirmCommand.ThrownExceptions

MODIFY
WalletWasabi.Gui/Tabs/WalletManager/LoadWallets/LoadWalletViewModel.cs
WalletWasabi.Gui/Tabs/WalletManager/LoadWallets/LoadWalletViewModel.cs
@@ -30,7 +30,6 @@ namespace WalletWasabi.Gui.Tabs.WalletManager.LoadWallets
private string _password;
private WalletViewModelBase _selectedWallet;
private bool _isWalletSelected;
- private bool _isWalletOpened;
private bool _canLoadWallet;
private bool _canTestPassword;
private bool _isBusy;
@@ -56,9 +55,6 @@ namespace WalletWasabi.Gui.Tabs.WalletManager.LoadWallets
this.WhenAnyValue(x => x.SelectedWallet)
.Subscribe(_ => TrySetWalletStates());
- this.WhenAnyValue(x => x.IsWalletOpened)
- .Subscribe(_ => TrySetWalletStates());
-
this.WhenAnyValue(x => x.IsBusy)
.Subscribe(_ => TrySetWalletStates());
@@ -66,10 +62,7 @@ namespace WalletWasabi.Gui.Tabs.WalletManager.LoadWallets
.ObserveOn(RxApp.MainThreadScheduler)
.Select(x => x.EventArgs)
.Where(x => x is { } && (!IsPasswordRequired || !x.KeyManager.IsWatchOnly))
- .Subscribe(wallet =>
- {
- RootList.Add(new WalletViewModelBase(wallet));
- });
+ .Subscribe(wallet => RootList.Add(new WalletViewModelBase(wallet)));
RootList.AddRange(Global.WalletManager.GetWallets().Where(x => !IsPasswordRequired || !x.KeyManager.IsWatchOnly).Select(x => new WalletViewModelBase(x)));
@@ -116,12 +109,6 @@ namespace WalletWasabi.Gui.Tabs.WalletManager.LoadWallets
set => this.RaiseAndSetIfChanged(ref _isWalletSelected, value);
}
- public bool IsWalletOpened
- {
- get => _isWalletOpened;
- set => this.RaiseAndSetIfChanged(ref _isWalletOpened, value);
- }
-
public string LoadButtonText
{
get => _loadButtonText;
@@ -172,11 +159,6 @@ namespace WalletWasabi.Gui.Tabs.WalletManager.LoadWallets
Password = "";
TrySetWalletStates();
-
- if (!CanLoadWallet && Wallets.Count > 0)
- {
- NotificationHelpers.Warning("There is already an open wallet. Restart the application in order to open a different one.");
- }
}
public KeyManager LoadKeyManager()
@@ -221,7 +203,7 @@ namespace WalletWasabi.Gui.Tabs.WalletManager.LoadWallets
{
if (keyManager.PasswordVerified == false)
{
- Owner.SelectTestPassword();
+ Owner.SelectTestPassword(walletName);
return null;
}
}
@@ -295,21 +277,7 @@ namespace WalletWasabi.Gui.Tabs.WalletManager.LoadWallets
IsWalletSelected = SelectedWallet != null;
CanTestPassword = IsWalletSelected;
-
- if (Global.WalletManager.AnyWallet())
- {
- IsWalletOpened = true;
- CanLoadWallet = false;
- }
- else
- {
- IsWalletOpened = false;
-
- // If not busy loading.
- // And wallet is selected.
- // And no wallet is opened.
- CanLoadWallet = !IsBusy && IsWalletSelected;
- }
+ CanLoadWallet = SelectedWallet is { } ? (!SelectedWallet.IsBusy && SelectedWallet.WalletState <= WalletState.Initialized) : false;
SetLoadButtonText();
return true;

MODIFY
WalletWasabi.Gui/Tabs/WalletManager/WalletManagerViewModel.cs
WalletWasabi.Gui/Tabs/WalletManager/WalletManagerViewModel.cs
@@ -5,6 +5,7 @@ using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Composition;
using System.Linq;
+using System.Reactive.Disposables;
using System.Threading;
using System.Threading.Tasks;
using WalletWasabi.Gui.Tabs.WalletManager.GenerateWallets;
@@ -24,29 +25,10 @@ namespace WalletWasabi.Gui.Tabs.WalletManager
private ObservableCollection<CategoryViewModel> _categories;
private CategoryViewModel _selectedCategory;
private ViewModelBase _currentView;
- private LoadWalletViewModel LoadWalletViewModelDesktop { get; }
+ private LoadWalletViewModel LoadWalletViewModelDesktop { get; set; }
public WalletManagerViewModel() : base("Wallet Manager")
{
- LoadWalletViewModelDesktop = new LoadWalletViewModel(this, LoadWalletType.Desktop);
-
- Categories = new ObservableCollection<CategoryViewModel>
- {
- new GenerateWalletViewModel(this),
- new RecoverWalletViewModel(this),
- LoadWalletViewModelDesktop,
- new LoadWalletViewModel(this, LoadWalletType.Password),
- new ConnectHardwareWalletViewModel(this)
- };
-
- SelectedCategory = Categories.FirstOrDefault();
-
- this.WhenAnyValue(x => x.SelectedCategory).Subscribe(category =>
- {
- category?.OnCategorySelected();
-
- CurrentView = category;
- });
}
public ObservableCollection<CategoryViewModel> Categories
@@ -76,9 +58,11 @@ namespace WalletWasabi.Gui.Tabs.WalletManager
SelectedCategory = Categories.First(x => x is LoadWalletViewModel model && model.LoadWalletType == LoadWalletType.Desktop);
}
- public void SelectTestPassword()
+ public void SelectTestPassword(string walletNameToSelect)
{
- SelectedCategory = Categories.First(x => x is LoadWalletViewModel model && model.LoadWalletType == LoadWalletType.Password);
+ LoadWalletViewModel pwTest = Categories.OfType<LoadWalletViewModel>().First(x => x.LoadWalletType == LoadWalletType.Password);
+ pwTest.SelectedWallet = pwTest.Wallets.FirstOrDefault(x => x.WalletName == walletNameToSelect);
+ SelectedCategory = pwTest;
}
public ViewModelBase CurrentView
@@ -87,6 +71,31 @@ namespace WalletWasabi.Gui.Tabs.WalletManager
set => this.RaiseAndSetIfChanged(ref _currentView, value);
}
+ public override void OnOpen(CompositeDisposable disposables)
+ {
+ base.OnOpen(disposables);
+
+ LoadWalletViewModelDesktop = new LoadWalletViewModel(this, LoadWalletType.Desktop);
+
+ Categories = new ObservableCollection<CategoryViewModel>
+ {
+ new GenerateWalletViewModel(this),
+ new RecoverWalletViewModel(this),
+ LoadWalletViewModelDesktop,
+ new LoadWalletViewModel(this, LoadWalletType.Password),
+ new ConnectHardwareWalletViewModel(this)
+ };
+
+ SelectedCategory = Categories.FirstOrDefault();
+
+ this.WhenAnyValue(x => x.SelectedCategory).Subscribe(category =>
+ {
+ category?.OnCategorySelected();
+
+ CurrentView = category;
+ });
+ }
+
public override bool OnClose()
{
foreach (var tab in Categories.OfType<IDisposable>())

Cleanup WalletManagerViewModel