Refactor command execute actions to method
MODIFY
WalletWasabi.Fluent/ViewModels/AddWallet/AddWalletPageViewModel.cs
WalletWasabi.Fluent/ViewModels/AddWallet/AddWalletPageViewModel.cs
@@ -9,6 +9,7 @@ using WalletWasabi.Wallets;
using WalletWasabi.Stores;
using WalletWasabi.Fluent.ViewModels.Dialogs;
using System.Threading.Tasks;
+using NBitcoin;
using WalletWasabi.Fluent.Helpers;
using WalletWasabi.Fluent.ViewModels.AddWallet.Create;
using WalletWasabi.Fluent.ViewModels.AddWallet.HardwareWallet;
@@ -62,10 +63,30 @@ namespace WalletWasabi.Fluent.ViewModels.AddWallet
.Select(x => !string.IsNullOrWhiteSpace(x))
.Subscribe(x => OptionsEnabled = x && !Validations.Any);
- RecoverWalletCommand = ReactiveCommand.Create(
- () => Navigate().To(new RecoverWalletViewModel(WalletName, walletManagerViewModel)));
+ RecoverWalletCommand = ReactiveCommand.Create(() => RecoverWallet(walletManagerViewModel));
- ImportWalletCommand = ReactiveCommand.CreateFromTask(async () =>
+ ImportWalletCommand = ReactiveCommand.CreateFromTask(async () => await ImportWallet(walletManager));
+
+ ConnectHardwareWalletCommand = ReactiveCommand.Create(() => ConnectHardwareWallet(walletManagerViewModel));
+
+ CreateWalletCommand = ReactiveCommand.CreateFromTask(async () => await CreateWallet(walletManager, store, network));
+
+ this.ValidateProperty(x => x.WalletName, errors => ValidateWalletName(errors, walletManager, WalletName));
+
+ EnableAutoBusyOn(CreateWalletCommand);
+ }
+
+ private void RecoverWallet(WalletManagerViewModel walletManagerViewModel)
+ {
+ Navigate().To(new RecoverWalletViewModel(WalletName, walletManagerViewModel));
+ }
+
+ private void ConnectHardwareWallet(WalletManagerViewModel walletManagerViewModel)
+ {
+ Navigate().To(new ConnectHardwareWalletViewModel(WalletName, walletManagerViewModel));
+ }
+
+ private async Task ImportWallet(WalletManager walletManager)
{
try
{
@@ -84,14 +105,12 @@ namespace WalletWasabi.Fluent.ViewModels.AddWallet
catch (Exception ex)
{
Logger.LogError(ex);
- await ShowErrorAsync(Title, ex.ToUserFriendlyString(), "The wallet file was not valid or compatible with Wasabi.");
+ await ShowErrorAsync(Title, ex.ToUserFriendlyString(),
+ "The wallet file was not valid or compatible with Wasabi.");
+ }
}
- });
-
- ConnectHardwareWalletCommand = ReactiveCommand.Create(() => Navigate().To(new ConnectHardwareWalletViewModel(WalletName, walletManagerViewModel)));
- CreateWalletCommand = ReactiveCommand.CreateFromTask(
- async () =>
+ private async Task CreateWallet(WalletManager walletManager, BitcoinStore store, Network network)
{
var dialogResult = await NavigateDialog(
new CreatePasswordDialogViewModel("Type the password of the wallet and click Continue."));
@@ -112,11 +131,6 @@ namespace WalletWasabi.Fluent.ViewModels.AddWallet
Navigate().To(new RecoveryWordsViewModel(km, mnemonic, walletManager));
}
- });
-
- this.ValidateProperty(x => x.WalletName, errors => ValidateWalletName(errors, walletManager, WalletName));
-
- EnableAutoBusyOn(CreateWalletCommand);
}
protected override void OnNavigatedTo(bool isInHistory, CompositeDisposable disposables)

Refactor command execute actions to method