Added and refactored RoutableViewModel navigation helper methods
MODIFY
WalletWasabi.Fluent/ViewModels/AddWallet/ConfirmRecoveryWordsViewModel.cs
WalletWasabi.Fluent/ViewModels/AddWallet/ConfirmRecoveryWordsViewModel.cs
@@ -33,11 +33,11 @@ namespace WalletWasabi.Fluent.ViewModels.AddWallet
() =>
{
walletManager.AddWallet(keyManager);
- navigationState.DialogScreen?.Invoke().Router.NavigationStack.Clear();
+ ClearNavigation(NavigationTarget.DialogScreen);
},
finishCommandCanExecute);
- CancelCommand = ReactiveCommand.Create(() => navigationState.DialogScreen?.Invoke().Router.NavigationStack.Clear());
+ CancelCommand = ReactiveCommand.Create(() => ClearNavigation(NavigationTarget.DialogScreen));
_confirmationWordsSourceList
.Connect()

MODIFY
WalletWasabi.Fluent/ViewModels/AddWallet/RecoverWalletViewModel.cs
WalletWasabi.Fluent/ViewModels/AddWallet/RecoverWalletViewModel.cs
@@ -83,7 +83,7 @@ namespace WalletWasabi.Fluent.ViewModels.AddWallet
NavigationTarget.DialogScreen,
"Type the password of the wallet to be able to recover and click Continue.");
- navigationState.DialogScreen().Router.Navigate.Execute(enterPassword);
+ NavigateTo(enterPassword, NavigationTarget.DialogScreen);
var password = await enterPassword.GetDialogResultAsync();
@@ -99,7 +99,7 @@ namespace WalletWasabi.Fluent.ViewModels.AddWallet
keyManager.SetNetwork(network);
walletManager.AddWallet(keyManager);
- navigationState.DialogScreen.Invoke().Router.NavigationStack.Clear();
+ ClearNavigation(NavigationTarget.DialogScreen);
}
catch (Exception ex)
{

MODIFY
WalletWasabi.Fluent/ViewModels/AddWallet/RecoveryWordsViewModel.cs
WalletWasabi.Fluent/ViewModels/AddWallet/RecoveryWordsViewModel.cs
@@ -24,10 +24,9 @@ namespace WalletWasabi.Fluent.ViewModels.AddWallet
}
NextCommand = ReactiveCommand.Create(
- () => navigationState.DialogScreen?.Invoke().Router.Navigate.Execute(
- new ConfirmRecoveryWordsViewModel(navigationState, MnemonicWords, keyManager, walletManager)));
+ () => NavigateTo(new ConfirmRecoveryWordsViewModel(navigationState, MnemonicWords, keyManager, walletManager), NavigationTarget.DialogScreen));
- CancelCommand = ReactiveCommand.Create(() => navigationState.DialogScreen?.Invoke().Router.NavigationStack.Clear());
+ CancelCommand = ReactiveCommand.Create(() => ClearNavigation(NavigationTarget.DialogScreen));
}
public ICommand NextCommand { get; }

MODIFY
WalletWasabi.Fluent/ViewModels/AddWalletPageViewModel.cs
WalletWasabi.Fluent/ViewModels/AddWalletPageViewModel.cs
@@ -32,8 +32,7 @@ namespace WalletWasabi.Fluent.ViewModels
RecoverWalletCommand = ReactiveCommand.CreateFromTask(async () =>
{
- await navigationState.DialogScreen.Invoke().Router.Navigate.Execute(
- new RecoverWalletViewModel(navigationState, WalletName, network, walletManager));
+ NavigateTo(new RecoverWalletViewModel(navigationState, WalletName, network, walletManager), NavigationTarget.DialogScreen);
});
CreateWalletCommand = ReactiveCommand.CreateFromTask(
@@ -44,7 +43,7 @@ namespace WalletWasabi.Fluent.ViewModels
NavigationTarget.DialogScreen,
"Type the password of the wallet and click Continue.");
- navigationState.DialogScreen.Invoke().Router.Navigate.Execute(enterPassword);
+ NavigateTo(enterPassword, NavigationTarget.DialogScreen);
var result = await enterPassword.GetDialogResultAsync();
@@ -62,8 +61,7 @@ namespace WalletWasabi.Fluent.ViewModels
return walletGenerator.GenerateWallet(WalletName, password);
});
- await navigationState.DialogScreen?.Invoke().Router.NavigateAndReset.Execute(
- new RecoveryWordsViewModel(navigationState, km, mnemonic, walletManager));
+ NavigateTo(new RecoveryWordsViewModel(navigationState, km, mnemonic, walletManager), NavigationTarget.DialogScreen, true);
}
else
{

MODIFY
WalletWasabi.Fluent/ViewModels/Dialogs/TestDialogViewModel.cs
WalletWasabi.Fluent/ViewModels/Dialogs/TestDialogViewModel.cs
@@ -34,7 +34,7 @@ namespace WalletWasabi.Fluent.ViewModels.Dialogs
protected override void OnDialogClosed()
{
// TODO: Disable when using Dialog inside DialogScreenViewModel / Settings
- // _navigationState.HomeScreen?.Invoke().Router.NavigateAndReset.Execute(new SettingsPageViewModel(_navigationState));
+ //NavigateTo(new SettingsPageViewModel(NavigationState), NavigationTarget.HomeScreen, true);
}
public void Close()

MODIFY
WalletWasabi.Fluent/ViewModels/NavBar/NavBarItemViewModel.cs
WalletWasabi.Fluent/ViewModels/NavBar/NavBarItemViewModel.cs
@@ -12,7 +12,7 @@ namespace WalletWasabi.Fluent.ViewModels.NavBar
protected NavBarItemViewModel(NavigationStateViewModel navigationState, NavigationTarget navigationTarget) : base(navigationState, navigationTarget)
{
_title = "";
- OpenCommand = ReactiveCommand.Create(() => Navigate());
+ OpenCommand = ReactiveCommand.Create(() => NavigateToSelf());
}
public NavBarItemViewModel? Parent { get; set; }

MODIFY
WalletWasabi.Fluent/ViewModels/NavBar/NavBarViewModel.cs
WalletWasabi.Fluent/ViewModels/NavBar/NavBarViewModel.cs
@@ -61,7 +61,7 @@ namespace WalletWasabi.Fluent.ViewModels.NavBar
if (!_isNavigating)
{
_isNavigating = true;
- x.NavigateAndReset();
+ x.NavigateToSelfAndReset();
CollapseOnClickAction?.Invoke();
_isNavigating = false;

MODIFY
WalletWasabi.Fluent/ViewModels/RoutableViewModel.cs
WalletWasabi.Fluent/ViewModels/RoutableViewModel.cs
using System;
+using System.Threading.Tasks;
using System.Windows.Input;
using ReactiveUI;
+using WalletWasabi.Fluent.ViewModels.Dialogs;
using WalletWasabi.Gui.ViewModels;
namespace WalletWasabi.Fluent.ViewModels
@@ -11,7 +13,7 @@ namespace WalletWasabi.Fluent.ViewModels
{
NavigationState = navigationState;
- NigationTarget = navigationTarget;
+ NavigationTarget = navigationTarget;
BackCommand = ReactiveCommand.Create(() => GoBack());
@@ -20,7 +22,7 @@ namespace WalletWasabi.Fluent.ViewModels
public string UrlPathSegment { get; } = Guid.NewGuid().ToString().Substring(0, 5);
- public IScreen HostScreen => NigationTarget switch
+ public IScreen HostScreen => NavigationTarget switch
{
NavigationTarget.DialogScreen => NavigationState.DialogScreen.Invoke(),
_ => NavigationState.HomeScreen.Invoke(),
@@ -28,45 +30,62 @@ namespace WalletWasabi.Fluent.ViewModels
public NavigationStateViewModel NavigationState { get; }
- public NavigationTarget NigationTarget { get; }
+ public NavigationTarget NavigationTarget { get; }
- public void Navigate()
+ public ICommand BackCommand { get; protected set; }
+
+ public ICommand CancelCommand { get; protected set; }
+
+ public void NavigateTo(RoutableViewModel viewModel, NavigationTarget navigationTarget, bool resetNavigation = false)
{
- switch (NigationTarget)
+ switch (navigationTarget)
{
case NavigationTarget.Default:
case NavigationTarget.HomeScreen:
+ {
+ if (resetNavigation)
+ {
+ NavigationState.HomeScreen.Invoke().Router.NavigateAndReset.Execute(this);
+ }
+ else
+ {
NavigationState.HomeScreen.Invoke().Router.Navigate.Execute(this);
+ }
+ }
break;
case NavigationTarget.DialogScreen:
+ {
+ if (resetNavigation)
+ {
+ NavigationState.DialogScreen.Invoke().Router.NavigateAndReset.Execute(this);
+ }
+ else
+ {
NavigationState.DialogScreen.Invoke().Router.Navigate.Execute(this);
- break;
}
}
+ break;
- public void NavigateAndReset()
- {
- switch (NigationTarget)
+ case NavigationTarget.DialogHost:
+ if (viewModel is DialogViewModelBase dialog && NavigationState.DialogHost?.Invoke() is IDialogHost dialogHost)
{
- case NavigationTarget.Default:
- case NavigationTarget.HomeScreen:
- NavigationState.HomeScreen.Invoke().Router.NavigateAndReset.Execute(this);
+ dialogHost.CurrentDialog = dialog;
+ }
break;
- case NavigationTarget.DialogScreen:
- NavigationState.DialogScreen.Invoke().Router.NavigateAndReset.Execute(this);
+ default:
break;
}
}
- public ICommand BackCommand { get; protected set; }
+ public void NavigateToSelf() => NavigateTo(this, NavigationTarget, false);
- public ICommand CancelCommand { get; protected set; }
+ public void NavigateToSelfAndReset() => NavigateTo(this, NavigationTarget, true);
- public void GoBack()
+ public void GoBack(NavigationTarget navigationTarget)
{
- switch (NigationTarget)
+ switch (navigationTarget)
{
case NavigationTarget.Default:
case NavigationTarget.HomeScreen:
@@ -79,9 +98,11 @@ namespace WalletWasabi.Fluent.ViewModels
}
}
- public void ClearNavigation()
+ public void GoBack() => GoBack(NavigationTarget);
+
+ public void ClearNavigation(NavigationTarget navigationTarget)
{
- switch (NigationTarget)
+ switch (navigationTarget)
{
case NavigationTarget.Default:
case NavigationTarget.HomeScreen:
@@ -93,5 +114,7 @@ namespace WalletWasabi.Fluent.ViewModels
break;
}
}
+
+ public void ClearNavigation() => ClearNavigation(NavigationTarget);
}
}
\ No newline at end of file

MODIFY
WalletWasabi.Fluent/ViewModels/SettingsPageViewModel.cs
WalletWasabi.Fluent/ViewModels/SettingsPageViewModel.cs
@@ -18,11 +18,11 @@ namespace WalletWasabi.Fluent.ViewModels
BackCommand = ReactiveCommand.Create(() => ClearNavigation());
- NextCommand = ReactiveCommand.Create(() => navigationState.HomeScreen?.Invoke().Router.Navigate.Execute(new SettingsPageViewModel(navigationState)));
+ NextCommand = ReactiveCommand.Create(() => NavigateTo(new SettingsPageViewModel(navigationState), NavigationTarget.HomeScreen));
OpenDialogCommand = ReactiveCommand.CreateFromTask(async () => await ConfirmSetting.Handle("Please confirm the setting:").ToTask());
- OpenDialogScreenCommand = ReactiveCommand.Create(() => navigationState.DialogScreen?.Invoke().Router.Navigate.Execute(new SettingsPageViewModel(navigationState)));
+ OpenDialogScreenCommand = ReactiveCommand.Create(() => NavigateTo(new SettingsPageViewModel(navigationState), NavigationTarget.DialogScreen));
ConfirmSetting = new Interaction<string, bool>();

Added and refactored RoutableViewModel navigation helper methods