Add navigation support to new view models
MODIFY
WalletWasabi.Fluent/ViewModels/AddWallet/ConfirmRecoveryWordsViewModel.cs
WalletWasabi.Fluent/ViewModels/AddWallet/ConfirmRecoveryWordsViewModel.cs
@@ -13,15 +13,14 @@ using WalletWasabi.Wallets;
namespace WalletWasabi.Fluent.ViewModels.AddWallet
{
- public class ConfirmRecoveryWordsViewModel : ViewModelBase, IRoutableViewModel
+ public class ConfirmRecoveryWordsViewModel : RoutableViewModel
{
private readonly ReadOnlyObservableCollection<RecoveryWordViewModel> _confirmationWords;
private readonly SourceList<RecoveryWordViewModel> _confirmationWordsSourceList;
- public ConfirmRecoveryWordsViewModel(IScreen screen, List<RecoveryWordViewModel> mnemonicWords, KeyManager keyManager, WalletManager walletManager)
+ public ConfirmRecoveryWordsViewModel(NavigationStateViewModel navigationState, List<RecoveryWordViewModel> mnemonicWords, KeyManager keyManager, WalletManager walletManager)
+ : base(navigationState, NavigationTarget.Dialog)
{
- HostScreen = screen;
-
_confirmationWordsSourceList = new SourceList<RecoveryWordViewModel>();
var finishCommandCanExecute =
@@ -35,7 +34,7 @@ namespace WalletWasabi.Fluent.ViewModels.AddWallet
() =>
{
walletManager.AddWallet(keyManager);
- screen.Router.NavigationStack.Clear();
+ navigationState.DialogScreen?.Invoke().Router.NavigationStack.Clear();
},
finishCommandCanExecute);

MODIFY
WalletWasabi.Fluent/ViewModels/AddWallet/RecoveryWordsViewModel.cs
WalletWasabi.Fluent/ViewModels/AddWallet/RecoveryWordsViewModel.cs
@@ -10,11 +10,11 @@ namespace WalletWasabi.Fluent.ViewModels.AddWallet
public class RecoveryWordsViewModel : RoutableViewModel
{
public RecoveryWordsViewModel(
- IScreen screen,
+ NavigationStateViewModel navigationState,
KeyManager keyManager,
Mnemonic mnemonic,
WalletManager walletManager)
- : base(screen)
+ : base(navigationState, NavigationTarget.Dialog)
{
MnemonicWords = new List<RecoveryWordViewModel>();
@@ -24,8 +24,8 @@ namespace WalletWasabi.Fluent.ViewModels.AddWallet
}
ContinueCommand = ReactiveCommand.Create(
- () => screen.Router.Navigate.Execute(
- new ConfirmRecoveryWordsViewModel(HostScreen, MnemonicWords, keyManager, walletManager)));
+ () => navigationState.DialogScreen?.Invoke().Router.Navigate.Execute(
+ new ConfirmRecoveryWordsViewModel(navigationState, MnemonicWords, keyManager, walletManager)));
}
public ICommand ContinueCommand { get; }

MODIFY
WalletWasabi.Fluent/ViewModels/AddWalletPageViewModel.cs
WalletWasabi.Fluent/ViewModels/AddWalletPageViewModel.cs
@@ -30,7 +30,7 @@ namespace WalletWasabi.Fluent.ViewModels
.Select(x => !string.IsNullOrWhiteSpace(x))
.Subscribe(x => OptionsEnabled = x);
- RecoverWalletCommand = ReactiveCommand.Create(() => screen.Router.Navigate.Execute(new RecoveryPageViewModel(screen)));
+ RecoverWalletCommand = ReactiveCommand.Create(() => navigationState.DialogScreen?.Invoke().Router.Navigate.Execute(new RecoveryPageViewModel(navigationState)));
CreateWalletCommand = ReactiveCommand.CreateFromTask(
async () =>
@@ -49,8 +49,8 @@ namespace WalletWasabi.Fluent.ViewModels
return walletGenerator.GenerateWallet(WalletName, password);
});
- await screen.Router.Navigate.Execute(
- new RecoveryWordsViewModel(screen, km, mnemonic, walletManager));
+ await navigationState.DialogScreen?.Invoke().Router.Navigate.Execute(
+ new RecoveryWordsViewModel(navigationState, km, mnemonic, walletManager));
}
});

MODIFY
WalletWasabi.Fluent/ViewModels/NavBarItemViewModel.cs
WalletWasabi.Fluent/ViewModels/NavBarItemViewModel.cs
@@ -5,18 +5,12 @@ namespace WalletWasabi.Fluent.ViewModels
{
public abstract class NavBarItemViewModel : RoutableViewModel
{
- private NavigationStateViewModel _navigationState;
- private NavigationTarget _navigationTarget;
private bool _isSelected;
private bool _isExpanded;
private string? _title;
- protected NavBarItemViewModel(NavigationStateViewModel navigationState, NavigationTarget navigationTarget) : base(navigationState)
+ protected NavBarItemViewModel(NavigationStateViewModel navigationState, NavigationTarget navigationTarget) : base(navigationState, navigationTarget)
{
- _navigationState = navigationState;
-
- _navigationTarget = navigationTarget;
-
OpenCommand = ReactiveCommand.Create(() => Navigate());
}
@@ -24,10 +18,6 @@ namespace WalletWasabi.Fluent.ViewModels
public abstract string IconName { get; }
- public string UrlPathSegment { get; } = Guid.NewGuid().ToString().Substring(0, 5);
-
- public IScreen HostScreen => _navigationState.HomeScreen?.Invoke();
-
public bool IsExpanded
{
get => _isExpanded;
@@ -55,33 +45,5 @@ namespace WalletWasabi.Fluent.ViewModels
}
public ICommand OpenCommand { get; }
-
- public void Navigate()
- {
- switch (_navigationTarget)
- {
- case NavigationTarget.Default:
- case NavigationTarget.Home:
- _navigationState.HomeScreen?.Invoke().Router.Navigate.Execute(this);
- break;
- case NavigationTarget.Dialog:
- _navigationState.DialogScreen?.Invoke().Router.Navigate.Execute(this);
- break;
- }
- }
-
- public void NavigateAndReset()
- {
- switch (_navigationTarget)
- {
- case NavigationTarget.Default:
- case NavigationTarget.Home:
- _navigationState.HomeScreen?.Invoke().Router.NavigateAndReset.Execute(this);
- break;
- case NavigationTarget.Dialog:
- _navigationState.DialogScreen?.Invoke().Router.NavigateAndReset.Execute(this);
- break;
- }
- }
}
}
\ No newline at end of file

MODIFY
WalletWasabi.Fluent/ViewModels/RecoverWalletPageViewModel.cs
WalletWasabi.Fluent/ViewModels/RecoverWalletPageViewModel.cs
@@ -17,7 +17,7 @@ namespace WalletWasabi.Fluent.ViewModels
private IEnumerable<string>? _suggestions;
private string? _selectedTag;
- public RecoveryPageViewModel(IScreen screen) : base(screen)
+ public RecoveryPageViewModel(NavigationStateViewModel navigationState) : base(navigationState, NavigationTarget.Dialog)
{
Suggestions = new Mnemonic(Wordlist.English, WordCount.Twelve).WordList.GetWords();

MODIFY
WalletWasabi.Fluent/ViewModels/RoutableViewModel.cs
WalletWasabi.Fluent/ViewModels/RoutableViewModel.cs
@@ -6,13 +6,57 @@ namespace WalletWasabi.Fluent.ViewModels
{
public abstract class RoutableViewModel : ViewModelBase, IRoutableViewModel
{
- protected RoutableViewModel(IScreen screen)
+ private NavigationStateViewModel _navigationState;
+ private NavigationTarget _navigationTarget;
+
+ protected RoutableViewModel(NavigationStateViewModel navigationState, NavigationTarget navigationTarget)
{
- HostScreen = screen;
+ _navigationState = navigationState;
+ _navigationTarget = navigationTarget;
}
public string UrlPathSegment { get; } = Guid.NewGuid().ToString().Substring(0, 5);
- public IScreen HostScreen { get; }
+ public IScreen HostScreen
+ {
+ get
+ {
+ return _navigationTarget switch
+ {
+ NavigationTarget.Dialog => _navigationState.DialogScreen?.Invoke(),
+ _ => _navigationState.HomeScreen?.Invoke(),
+ };
+ }
+ }
+
+ public void Navigate()
+ {
+ switch (_navigationTarget)
+ {
+ case NavigationTarget.Default:
+ case NavigationTarget.Home:
+ _navigationState.HomeScreen?.Invoke().Router.Navigate.Execute(this);
+ break;
+
+ case NavigationTarget.Dialog:
+ _navigationState.DialogScreen?.Invoke().Router.Navigate.Execute(this);
+ break;
+ }
+ }
+
+ public void NavigateAndReset()
+ {
+ switch (_navigationTarget)
+ {
+ case NavigationTarget.Default:
+ case NavigationTarget.Home:
+ _navigationState.HomeScreen?.Invoke().Router.NavigateAndReset.Execute(this);
+ break;
+
+ case NavigationTarget.Dialog:
+ _navigationState.DialogScreen?.Invoke().Router.NavigateAndReset.Execute(this);
+ break;
+ }
+ }
}
}
\ No newline at end of file

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

Add navigation support to new view models