Refactor AddWallet commands execute to methods
MODIFY
WalletWasabi.Fluent/ViewModels/AddWallet/AddWalletPageViewModel.cs
WalletWasabi.Fluent/ViewModels/AddWallet/AddWalletPageViewModel.cs
@@ -63,30 +63,30 @@ namespace WalletWasabi.Fluent.ViewModels.AddWallet
.Select(x => !string.IsNullOrWhiteSpace(x))
.Subscribe(x => OptionsEnabled = x && !Validations.Any);
- RecoverWalletCommand = ReactiveCommand.Create(() => RecoverWallet(walletManagerViewModel));
+ RecoverWalletCommand = ReactiveCommand.Create(() => RecoverWalletExecute(walletManagerViewModel));
- ImportWalletCommand = ReactiveCommand.CreateFromTask(async () => await ImportWallet(walletManager));
+ ImportWalletCommand = ReactiveCommand.CreateFromTask(async () => await ImportWalletExecute(walletManager));
- ConnectHardwareWalletCommand = ReactiveCommand.Create(() => ConnectHardwareWallet(walletManagerViewModel));
+ ConnectHardwareWalletCommand = ReactiveCommand.Create(() => ConnectHardwareWalletExecute(walletManagerViewModel));
- CreateWalletCommand = ReactiveCommand.CreateFromTask(async () => await CreateWallet(walletManager, store, network));
+ CreateWalletCommand = ReactiveCommand.CreateFromTask(async () => await CreateWalletExecute(walletManager, store, network));
this.ValidateProperty(x => x.WalletName, errors => ValidateWalletName(errors, walletManager, WalletName));
EnableAutoBusyOn(CreateWalletCommand);
}
- private void RecoverWallet(WalletManagerViewModel walletManagerViewModel)
+ private void RecoverWalletExecute(WalletManagerViewModel walletManagerViewModel)
{
Navigate().To(new RecoverWalletViewModel(WalletName, walletManagerViewModel));
}
- private void ConnectHardwareWallet(WalletManagerViewModel walletManagerViewModel)
+ private void ConnectHardwareWalletExecute(WalletManagerViewModel walletManagerViewModel)
{
Navigate().To(new ConnectHardwareWalletViewModel(WalletName, walletManagerViewModel));
}
- private async Task ImportWallet(WalletManager walletManager)
+ private async Task ImportWalletExecute(WalletManager walletManager)
{
try
{
@@ -110,7 +110,7 @@ namespace WalletWasabi.Fluent.ViewModels.AddWallet
}
}
- private async Task CreateWallet(WalletManager walletManager, BitcoinStore store, Network network)
+ private async Task CreateWalletExecute(WalletManager walletManager, BitcoinStore store, Network network)
{
var dialogResult = await NavigateDialog(
new CreatePasswordDialogViewModel("Type the password of the wallet and click Continue."));

MODIFY
WalletWasabi.Fluent/ViewModels/AddWallet/AddedWalletPageViewModel.cs
WalletWasabi.Fluent/ViewModels/AddWallet/AddedWalletPageViewModel.cs
@@ -18,8 +18,10 @@ namespace WalletWasabi.Fluent.ViewModels.AddWallet
IsHardwareWallet = keyManager.IsHardwareWallet;
WalletName = keyManager.WalletName;
- NextCommand = ReactiveCommand.Create(
- () =>
+ NextCommand = ReactiveCommand.Create(() => NextExecute(walletManager, keyManager));
+ }
+
+ private void NextExecute(WalletManager walletManager, KeyManager keyManager)
{
walletManager.AddWallet(keyManager);
@@ -34,7 +36,6 @@ namespace WalletWasabi.Fluent.ViewModels.AddWallet
navBar.SelectedItem = wallet;
wallet.OpenCommand.Execute(default);
}
- });
}
public string? WalletIcon { get; }

MODIFY
WalletWasabi.Fluent/ViewModels/AddWallet/Create/ConfirmRecoveryWordsViewModel.cs
WalletWasabi.Fluent/ViewModels/AddWallet/Create/ConfirmRecoveryWordsViewModel.cs
@@ -32,7 +32,7 @@ namespace WalletWasabi.Fluent.ViewModels.AddWallet.Create
.Select(_ => confirmationWordsSourceList.Items.All(x => x.IsConfirmed));
NextCommand = ReactiveCommand.Create(
- () => Navigate().To(new AddedWalletPageViewModel(walletManager, keyManager)),
+ () => NextExecute(keyManager, walletManager),
nextCommandCanExecute);
if (_isSkipEnable)
@@ -40,7 +40,7 @@ namespace WalletWasabi.Fluent.ViewModels.AddWallet.Create
SkipCommand = ReactiveCommand.Create(() => NextCommand.Execute(null));
}
- CancelCommand = ReactiveCommand.Create(() => Navigate().Clear());
+ CancelCommand = ReactiveCommand.Create(CancelExecute);
confirmationWordsSourceList
.Connect()
@@ -54,6 +54,16 @@ namespace WalletWasabi.Fluent.ViewModels.AddWallet.Create
confirmationWordsSourceList.AddRange(mnemonicWords.OrderBy(_ => new Random().NextDouble()).Take(4));
}
+ private void NextExecute(KeyManager keyManager, WalletManager walletManager)
+ {
+ Navigate().To(new AddedWalletPageViewModel(walletManager, keyManager));
+ }
+
+ private void CancelExecute()
+ {
+ Navigate().Clear();
+ }
+
public ReadOnlyObservableCollection<RecoveryWordViewModel> ConfirmationWords => _confirmationWords;
}
}

MODIFY
WalletWasabi.Fluent/ViewModels/AddWallet/Create/RecoveryWordsViewModel.cs
WalletWasabi.Fluent/ViewModels/AddWallet/Create/RecoveryWordsViewModel.cs
@@ -22,10 +22,19 @@ namespace WalletWasabi.Fluent.ViewModels.AddWallet.Create
MnemonicWords.Add(new RecoveryWordViewModel(i + 1, mnemonic.Words[i]));
}
- NextCommand = ReactiveCommand.Create(
- () => Navigate().To(new ConfirmRecoveryWordsViewModel(MnemonicWords, keyManager, walletManager)));
+ NextCommand = ReactiveCommand.Create(() => NextExecute(keyManager, walletManager));
- CancelCommand = ReactiveCommand.Create(() => Navigate().Clear());
+ CancelCommand = ReactiveCommand.Create(CancelExecute);
+ }
+
+ private void NextExecute(KeyManager keyManager, WalletManager walletManager)
+ {
+ Navigate().To(new ConfirmRecoveryWordsViewModel(MnemonicWords, keyManager, walletManager));
+ }
+
+ private void CancelExecute()
+ {
+ Navigate().Clear();
}
public List<RecoveryWordViewModel> MnemonicWords { get; set; }

MODIFY
WalletWasabi.Fluent/ViewModels/AddWallet/HardwareWallet/ConnectHardwareWalletViewModel.cs
WalletWasabi.Fluent/ViewModels/AddWallet/HardwareWallet/ConnectHardwareWalletViewModel.cs
@@ -36,7 +36,19 @@ namespace WalletWasabi.Fluent.ViewModels.AddWallet.HardwareWallet
AbandonedTasks = new AbandonedTasks();
CancelCts = new CancellationTokenSource();
- NextCommand = ReactiveCommand.Create(() =>
+ NextCommand = ReactiveCommand.Create(NextExecute);
+
+ OpenBrowserCommand = ReactiveCommand.CreateFromTask(async () =>
+ await IoHelpers.OpenBrowserAsync("https://docs.wasabiwallet.io/using-wasabi/ColdWasabi.html#using-hardware-wallet-step-by-step"));
+
+ NavigateToExistingWalletLoginCommand = ReactiveCommand.Create(NavigateToExistingWalletLoginExecute);
+
+ this.WhenAnyValue(x => x.Message)
+ .ObserveOn(RxApp.MainThreadScheduler)
+ .Subscribe(message => ConfirmationRequired = !string.IsNullOrEmpty(message));
+ }
+
+ private void NextExecute()
{
if (DetectedDevice is { } device)
{
@@ -45,12 +57,9 @@ namespace WalletWasabi.Fluent.ViewModels.AddWallet.HardwareWallet
}
StartDetection();
- });
-
- OpenBrowserCommand = ReactiveCommand.CreateFromTask(async () =>
- await IoHelpers.OpenBrowserAsync("https://docs.wasabiwallet.io/using-wasabi/ColdWasabi.html#using-hardware-wallet-step-by-step"));
+ }
- NavigateToExistingWalletLoginCommand = ReactiveCommand.Create(() =>
+ private void NavigateToExistingWalletLoginExecute()
{
var navBar = NavigationManager.Get<NavBarViewModel>();
@@ -60,11 +69,6 @@ namespace WalletWasabi.Fluent.ViewModels.AddWallet.HardwareWallet
Navigate().Clear();
ExistingWallet.OpenCommand.Execute(default);
}
- });
-
- this.WhenAnyValue(x => x.Message)
- .ObserveOn(RxApp.MainThreadScheduler)
- .Subscribe(message => ConfirmationRequired = !string.IsNullOrEmpty(message));
}
private HwiEnumerateEntry? DetectedDevice { get; set; }

MODIFY
WalletWasabi.Fluent/ViewModels/AddWallet/HardwareWallet/DetectedHardwareWalletViewModel.cs
WalletWasabi.Fluent/ViewModels/AddWallet/HardwareWallet/DetectedHardwareWalletViewModel.cs
using System;
using System.Reactive.Disposables;
using System.Threading;
+using System.Threading.Tasks;
using System.Windows.Input;
using ReactiveUI;
using WalletWasabi.Extensions;
@@ -31,12 +32,20 @@ namespace WalletWasabi.Fluent.ViewModels.AddWallet.HardwareWallet
TypeName = device.Model.FriendlyName();
- NextCommand = ReactiveCommand.CreateFromTask(async () =>
+ NextCommand = ReactiveCommand.CreateFromTask(async () => await NextExecute(walletManager, device));
+
+ NoCommand = ReactiveCommand.Create(NoExecute);
+
+ EnableAutoBusyOn(NextCommand);
+ }
+
+ private async Task NextExecute(WalletManager walletManager, HwiEnumerateEntry device)
{
try
{
var walletFilePath = WalletManager.WalletDirectories.GetWalletFilePaths(WalletName).walletFilePath;
- var km = await HardwareWalletOperationHelpers.GenerateWalletAsync(device, walletFilePath, WalletManager.Network, CancelCts.Token);
+ var km = await HardwareWalletOperationHelpers.GenerateWalletAsync(device, walletFilePath, WalletManager.Network,
+ CancelCts.Token);
km.SetIcon(Type);
Navigate().To(new AddedWalletPageViewModel(walletManager, km));
@@ -47,11 +56,11 @@ namespace WalletWasabi.Fluent.ViewModels.AddWallet.HardwareWallet
await ShowErrorAsync(Title, ex.ToUserFriendlyString(), "Error occured during adding your wallet.");
Navigate().Back();
}
- });
-
- NoCommand = ReactiveCommand.Create(() => Navigate().Back());
+ }
- EnableAutoBusyOn(NextCommand);
+ private void NoExecute()
+ {
+ Navigate().Back();
}
public CancellationTokenSource CancelCts { get; }

MODIFY
WalletWasabi.Fluent/ViewModels/AddWallet/RecoverWalletViewModel.cs
WalletWasabi.Fluent/ViewModels/AddWallet/RecoverWalletViewModel.cs
@@ -48,7 +48,7 @@ namespace WalletWasabi.Fluent.ViewModels.AddWallet
.Select(currentMnemonics => currentMnemonics is { } && !Validations.Any);
NextCommand = ReactiveCommand.CreateFromTask(
- async () => await OnNext(walletManager, network, walletName),
+ async () => await NextExecute(walletManager, network, walletName),
FinishCommandCanExecute);
AdvancedOptionsInteraction = new Interaction<(KeyPath, int), (KeyPath?, int?)>();
@@ -57,26 +57,12 @@ namespace WalletWasabi.Fluent.ViewModels.AddWallet
interaction.SetOutput(
(await new AdvancedRecoveryOptionsViewModel(interaction.Input).ShowDialogAsync()).Result));
- AdvancedRecoveryOptionsDialogCommand = ReactiveCommand.CreateFromTask(
- async () =>
- {
- var (accountKeyPathIn, minGapLimitIn) = await AdvancedOptionsInteraction
- .Handle((AccountKeyPath, MinGapLimit)).ToTask();
-
- if (accountKeyPathIn is { } && minGapLimitIn is { })
- {
- AccountKeyPath = accountKeyPathIn;
- MinGapLimit = (int)minGapLimitIn;
- }
- });
+ AdvancedRecoveryOptionsDialogCommand = ReactiveCommand.CreateFromTask(async () => await AdvancedRecoveryOptionsDialogExecute());
EnableAutoBusyOn(NextCommand);
}
- private async Task OnNext(
- WalletManager walletManager,
- Network network,
- string? walletName)
+ private async Task NextExecute(WalletManager walletManager, Network network, string? walletName)
{
var dialogResult = await NavigateDialog(
new CreatePasswordDialogViewModel(
@@ -121,6 +107,18 @@ namespace WalletWasabi.Fluent.ViewModels.AddWallet
}
}
+ private async Task AdvancedRecoveryOptionsDialogExecute()
+ {
+ var (accountKeyPathIn, minGapLimitIn) = await AdvancedOptionsInteraction
+ .Handle((AccountKeyPath, MinGapLimit)).ToTask();
+
+ if (accountKeyPathIn is { } && minGapLimitIn is { })
+ {
+ AccountKeyPath = accountKeyPathIn;
+ MinGapLimit = (int) minGapLimitIn;
+ }
+ }
+
public IObservable<bool> FinishCommandCanExecute { get; }
public ICommand AdvancedRecoveryOptionsDialogCommand { get; }

MODIFY
WalletWasabi.Fluent/ViewModels/AddWallet/TermsAndConditionsViewModel.cs
WalletWasabi.Fluent/ViewModels/AddWallet/TermsAndConditionsViewModel.cs
@@ -12,15 +12,24 @@ namespace WalletWasabi.Fluent.ViewModels.AddWallet
public TermsAndConditionsViewModel(string legalDocument)
{
- ViewTermsCommand = ReactiveCommand.Create(
- () => Navigate().To(new LegalDocumentsViewModel(legalDocument)));
+ ViewTermsCommand = ReactiveCommand.Create(() => ViewTermsExecute(legalDocument));
NextCommand = ReactiveCommand.Create(
- () => Close(DialogResultKind.Normal, true),
+ NextExecute,
this.WhenAnyValue(x => x.IsAgreed)
.ObserveOn(RxApp.MainThreadScheduler));
}
+ private void ViewTermsExecute(string legalDocument)
+ {
+ Navigate().To(new LegalDocumentsViewModel(legalDocument));
+ }
+
+ private void NextExecute()
+ {
+ Close(DialogResultKind.Normal, true);
+ }
+
public ICommand ViewTermsCommand { get; }
}
}

Refactor AddWallet commands execute to methods