interaction pattern for password
MODIFY
WalletWasabi.Fluent/AddWallet/Common/EnterPasswordView.axaml
WalletWasabi.Fluent/AddWallet/Common/EnterPasswordView.axaml
<UserControl.KeyBindings>
<KeyBinding Gesture="Enter" Command="{Binding ContinueCommand}" />
</UserControl.KeyBindings>
- <DockPanel>
+ <DockPanel Margin="0 0 0 20">
<DockPanel DockPanel.Dock="Bottom">
<Button DockPanel.Dock="Left" Content="Cancel" Command="{Binding CancelCommand}" Classes="invisible"

MODIFY
WalletWasabi.Fluent/AddWallet/Common/EnterPasswordViewModel.cs
WalletWasabi.Fluent/AddWallet/Common/EnterPasswordViewModel.cs
@@ -4,6 +4,8 @@ using System.Reactive.Linq;
using System.Windows.Input;
using WalletWasabi.Blockchain.Keys;
using WalletWasabi.Fluent.AddWallet.CreateWallet;
+using WalletWasabi.Fluent.ViewModels;
+using WalletWasabi.Fluent.ViewModels.Dialogs;
using WalletWasabi.Gui;
using WalletWasabi.Gui.Validation;
using WalletWasabi.Gui.ViewModels;
@@ -12,14 +14,15 @@ using WalletWasabi.Userfacing;
namespace WalletWasabi.Fluent.AddWallet.Common
{
- public class EnterPasswordViewModel : ViewModelBase, IRoutableViewModel
+ public class EnterPasswordViewModel : DialogViewModelBase<string>
{
+ private IScreen _screen;
private string _password;
private string _confirmPassword;
public EnterPasswordViewModel(IScreen screen, Global global, string walletName)
{
- HostScreen = screen;
+ _screen = screen;
this.ValidateProperty(x => x.Password, ValidatePassword);
this.ValidateProperty(x => x.ConfirmPassword, ValidateConfirmPassword);
@@ -37,15 +40,8 @@ namespace WalletWasabi.Fluent.AddWallet.Common
})
.ObserveOn(RxApp.MainThreadScheduler);
- ContinueCommand = ReactiveCommand.Create(
- () =>
- {
- var walletGenerator = new WalletGenerator(global.WalletManager.WalletDirectories.WalletsDir, global.Network);
- walletGenerator.TipHeight = global.BitcoinStore.SmartHeaderChain.TipHeight;
- var (km, mnemonic) = walletGenerator.GenerateWallet(walletName, Password);
- screen.Router.Navigate.Execute(new RecoveryWordsViewModel(screen, km, mnemonic, global));
- },
- continueCommandCanExecute);
+ ContinueCommand = ReactiveCommand.Create(() => Close(Password), continueCommandCanExecute);
+ CancelCommand = ReactiveCommand.Create(() => Close(null!));
}
public string Password
@@ -63,8 +59,10 @@ namespace WalletWasabi.Fluent.AddWallet.Common
public ICommand ContinueCommand { get; }
public ICommand CancelCommand { get; }
- public string? UrlPathSegment => throw new NotImplementedException();
- public IScreen HostScreen { get; }
+ protected override void OnDialogClosed()
+ {
+ _screen.Router.NavigateAndReset.Execute(new AddWalletPageViewModel(_screen));
+ }
private void ValidateConfirmPassword(IValidationErrors errors)
{

MODIFY
WalletWasabi.Fluent/ViewModels/AddWalletPageViewModel.cs
WalletWasabi.Fluent/ViewModels/AddWalletPageViewModel.cs
@@ -5,6 +5,9 @@ using System.Windows.Input;
using System.Reactive.Linq;
using WalletWasabi.Fluent.AddWallet.Common;
using WalletWasabi.Gui;
+using System.Reactive.Threading.Tasks;
+using WalletWasabi.Blockchain.Keys;
+using WalletWasabi.Fluent.AddWallet.CreateWallet;
namespace WalletWasabi.Fluent.ViewModels
{
@@ -23,11 +26,27 @@ namespace WalletWasabi.Fluent.ViewModels
RecoverWalletCommand = ReactiveCommand.Create(() => screen.Router.Navigate.Execute(new RecoveryPageViewModel(screen)));
- CreateWalletCommand = ReactiveCommand.Create(() =>
- {
+
var global = Locator.Current.GetService<Global>();
- screen.Router.Navigate.Execute(new EnterPasswordViewModel(screen, global, WalletName));
+ CreateWalletCommand = ReactiveCommand.CreateFromTask(async () =>
+ {
+ var result = await PasswordInteraction.Handle("").ToTask();
+
+ if (result is { } password)
+ {
+ var walletGenerator = new WalletGenerator(global.WalletManager.WalletDirectories.WalletsDir, global.Network);
+ walletGenerator.TipHeight = global.BitcoinStore.SmartHeaderChain.TipHeight;
+ var (km, mnemonic) = walletGenerator.GenerateWallet(WalletName, password);
+ await screen.Router.Navigate.Execute(new RecoveryWordsViewModel(screen, km, mnemonic, global));
+ }
+ });
+ PasswordInteraction = new Interaction<string, string>();
+ PasswordInteraction.RegisterHandler(
+ async interaction =>
+ {
+ var result = await new EnterPasswordViewModel(screen, global, WalletName).ShowDialogAsync(MainViewModel.Instance);
+ interaction.SetOutput(result);
});
}
@@ -45,6 +64,8 @@ namespace WalletWasabi.Fluent.ViewModels
set => this.RaiseAndSetIfChanged(ref _optionsEnabled, value);
}
+ public Interaction<string, string> PasswordInteraction { get; }
+
public ICommand CreateWalletCommand { get; }
public ICommand RecoverWalletCommand { get; }
}

interaction pattern for password