refactor OpenCommand logic
MODIFY
WalletWasabi.Fluent/ViewModels/AddWallet/AddWalletPageViewModel.cs
WalletWasabi.Fluent/ViewModels/AddWallet/AddWalletPageViewModel.cs
@@ -9,6 +9,7 @@ using WalletWasabi.Fluent.Helpers;
using WalletWasabi.Fluent.Models;
using WalletWasabi.Fluent.ViewModels.Dialogs.Base;
using WalletWasabi.Fluent.ViewModels.NavBar;
+using WalletWasabi.Fluent.ViewModels.Navigation;
using WalletWasabi.Helpers;
using WalletWasabi.Logging;
@@ -38,13 +39,6 @@ public partial class AddWalletPageViewModel : DialogViewModelBase<Unit>
ImportWalletCommand = ReactiveCommand.CreateFromTask(async () => await OnImportWalletAsync());
RecoverWalletCommand = ReactiveCommand.Create(OnRecoverWallet);
-
- OpenCommand = ReactiveCommand.Create(async () =>
- {
- MainViewModel.Instance.IsOobeBackgroundVisible = true;
- await NavigateDialogAsync(this, NavigationTarget.DialogScreen);
- MainViewModel.Instance.IsOobeBackgroundVisible = false;
- });
}
public ICommand CreateWalletCommand { get; }
@@ -100,6 +94,13 @@ public partial class AddWalletPageViewModel : DialogViewModelBase<Unit>
Navigate().To(new WalletNamePageViewModel(WalletCreationOption.RecoverWallet));
}
+ protected override async Task OnOpen(NavigationMode defaultNavigationMode)
+ {
+ MainViewModel.Instance.IsOobeBackgroundVisible = true;
+ await NavigateDialogAsync(this, NavigationTarget.DialogScreen);
+ MainViewModel.Instance.IsOobeBackgroundVisible = false;
+ }
+
private async Task ImportWalletAsync()
{
try

MODIFY
WalletWasabi.Fluent/ViewModels/AddWallet/AddedWalletPageViewModel.cs
WalletWasabi.Fluent/ViewModels/AddWallet/AddedWalletPageViewModel.cs
@@ -34,15 +34,8 @@ public partial class AddedWalletPageViewModel : RoutableViewModel
{
Navigate().Clear();
- var navBar = NavigationManager.Get<NavBarViewModel>();
-
- var wallet = navBar?.Wallets.FirstOrDefault(x => x.WalletName == WalletName);
-
- if (wallet is { } && navBar is { })
- {
- navBar.SelectedItem = wallet;
- wallet.OpenCommand.Execute(default);
- }
+ var wallet = UiServices.WalletManager.Wallets.FirstOrDefault(x => x.WalletName == WalletName);
+ wallet?.OpenCommand.Execute(default);
}
protected override void OnNavigatedTo(bool isInHistory, CompositeDisposable disposables)

MODIFY
WalletWasabi.Fluent/ViewModels/AddWallet/HardwareWallet/ConnectHardwareWalletViewModel.cs
WalletWasabi.Fluent/ViewModels/AddWallet/HardwareWallet/ConnectHardwareWalletViewModel.cs
@@ -79,11 +79,8 @@ public partial class ConnectHardwareWalletViewModel : RoutableViewModel
private void OnNavigateToExistingWalletLogin()
{
- var navBar = NavigationManager.Get<NavBarViewModel>();
-
- if (ExistingWallet is { } && navBar is { })
+ if (ExistingWallet is { } && ExistingWallet.OpenCommand.CanExecute(default))
{
- navBar.SelectedItem = ExistingWallet;
Navigate().Clear();
ExistingWallet.OpenCommand.Execute(default);
}

MODIFY
WalletWasabi.Fluent/ViewModels/NavBar/NavBarItemViewModel.cs
WalletWasabi.Fluent/ViewModels/NavBar/NavBarItemViewModel.cs
+using System.Threading.Tasks;
using ReactiveUI;
using System.Windows.Input;
using WalletWasabi.Fluent.ViewModels.Navigation;
@@ -19,8 +20,16 @@ public abstract class NavBarItemViewModel : RoutableViewModel
{
SelectionMode = NavBarItemSelectionMode.Selected;
- OpenCommand = ReactiveCommand.Create(
- () => OnOpen(defaultNavigationMode));
+ OpenCommand = ReactiveCommand.CreateFromTask(async () =>
+ {
+ if (IsSelected)
+ {
+ return;
+ }
+
+ IsSelected = true;
+ await OnOpen(defaultNavigationMode);
+ });
}
public NavBarItemSelectionMode SelectionMode { get; protected init; }
@@ -44,9 +53,9 @@ public abstract class NavBarItemViewModel : RoutableViewModel
}
}
- public ICommand OpenCommand { get; protected set; }
+ public ICommand OpenCommand { get; }
- private void OnOpen(NavigationMode defaultNavigationMode)
+ protected virtual Task OnOpen(NavigationMode defaultNavigationMode)
{
if (SelectionMode == NavBarItemSelectionMode.Toggle)
{
@@ -56,6 +65,8 @@ public abstract class NavBarItemViewModel : RoutableViewModel
{
Navigate().To(this, defaultNavigationMode);
}
+
+ return Task.CompletedTask;
}
public virtual void Toggle()

MODIFY
WalletWasabi.Fluent/ViewModels/Wallets/ClosedWalletViewModel.cs
WalletWasabi.Fluent/ViewModels/Wallets/ClosedWalletViewModel.cs
using System.Reactive.Disposables;
-using ReactiveUI;
+using System.Threading.Tasks;
using WalletWasabi.Fluent.ViewModels.Login;
using WalletWasabi.Fluent.ViewModels.Navigation;
using WalletWasabi.Wallets;
@@ -11,7 +11,6 @@ public class ClosedWalletViewModel : WalletViewModelBase
protected ClosedWalletViewModel(Wallet wallet)
: base(wallet)
{
- OpenCommand = ReactiveCommand.Create(OnOpen);
}
public LoadingViewModel? Loading { get; private set; }
@@ -26,7 +25,7 @@ public class ClosedWalletViewModel : WalletViewModelBase
IsLoading = true;
}
- private void OnOpen()
+ protected override async Task OnOpen(NavigationMode defaultNavigationMode)
{
if (!Wallet.IsLoggedIn)
{
@@ -34,7 +33,7 @@ public class ClosedWalletViewModel : WalletViewModelBase
}
else
{
- Navigate().To(this, NavigationMode.Clear);
+ await base.OnOpen(defaultNavigationMode);
}
}

MODIFY
WalletWasabi.Fluent/ViewModels/Wallets/WalletViewModelBase.cs
WalletWasabi.Fluent/ViewModels/Wallets/WalletViewModelBase.cs
@@ -24,8 +24,6 @@ public abstract partial class WalletViewModelBase : NavBarItemViewModel, ICompar
_title = WalletName;
WalletState = wallet.State;
- OpenCommand = ReactiveCommand.Create(() => Navigate().To(this, NavigationMode.Clear));
-
SetIcon();
this.WhenAnyValue(x => x.IsCoinJoining)

refactor OpenCommand logic