implement generate wallet validation.
MODIFY
WalletWasabi.Gui/Controls/ModalDialog.xaml
WalletWasabi.Gui/Controls/ModalDialog.xaml
xmlns:cont="clr-namespace:AvalonStudio.Controls;assembly=AvalonStudio.Shell.Extensibility">
<Grid Background="#EF2D2D2D" IsVisible="{Binding IsVisible, FallbackValue=False}">
<Grid Height="500" Background="{DynamicResource ThemeAccentBrush}" Margin="10 0">
- <DockPanel LastChildFill="True" Margin="4 0">
-
+ <DockPanel LastChildFill="True" Margin="350 0">
<StackPanel Orientation="Horizontal" Gap="20" HorizontalAlignment="Right" DockPanel.Dock="Bottom" Margin="8 0 8 8" TextBlock.FontSize="20">
<Button Command="{Binding CancelCommand}" IsVisible="{Binding CancelButtonVisible}" Content="Cancel" Width="160" Height="50" />
<Button Content="OK" Command="{Binding OKCommand}" IsVisible="{Binding OKButtonVisible}" Width="160" Height="50" />

MODIFY
WalletWasabi.Gui/Styles/Styles.xaml
WalletWasabi.Gui/Styles/Styles.xaml
<Style.Resources>
<SolidColorBrush x:Key="ThemeAccentBrush">#007ACC</SolidColorBrush>
<SolidColorBrush x:Key="HyperLinkForeground">#00A2E8</SolidColorBrush>
+ <SolidColorBrush x:Key="ErrorMessageForeground">#F25022</SolidColorBrush>
<sys:Double x:Key="FontSizeSmall">12</sys:Double>
<sys:Double x:Key="FontSizeNormal">14</sys:Double>
<Setter Property="TextBlock.Foreground" Value="{DynamicResource HyperLinkForeground}" />
</Style>
+ <Style Selector=".errorMessage">
+ <Setter Property="TextBlock.Foreground" Value="{DynamicResource ErrorMessageForeground}" />
+ </Style>
+
<Style Selector="Button.activeHyperLink">
<Setter Property="TextBlock.Foreground" Value="{DynamicResource HyperLinkForeground}" />
<Setter Property="Cursor" Value="Hand" />

MODIFY
WalletWasabi.Gui/Tabs/WalletManager/GenerateWalletView.xaml
WalletWasabi.Gui/Tabs/WalletManager/GenerateWalletView.xaml
<Button Content="Generate" Command="{Binding GenerateCommand}" DockPanel.Dock="Right" />
<Grid></Grid>
</DockPanel>
+ <TextBlock Text="{Binding ValidationMessage}" Classes="errorMessage" />
</StackPanel>
</UserControl>

MODIFY
WalletWasabi.Gui/Tabs/WalletManager/GenerateWalletViewModel.cs
WalletWasabi.Gui/Tabs/WalletManager/GenerateWalletViewModel.cs
@@ -5,6 +5,7 @@ using ReactiveUI;
using System;
using System.Collections.ObjectModel;
using System.IO;
+using WalletWasabi.Gui.Dialogs;
using WalletWasabi.Gui.ViewModels;
using WalletWasabi.KeyManagement;
using WalletWasabi.Logging;
@@ -17,10 +18,11 @@ namespace WalletWasabi.Gui.Tabs.WalletManager
private string _passwordConfirmation;
private string _walletName;
private bool _termsAccepted;
+ private string _validationMessage;
public GenerateWalletViewModel() : base("Generate Wallet")
{
- GenerateCommand = ReactiveCommand.Create(() =>
+ GenerateCommand = ReactiveCommand.Create(async () =>
{
string walletFilePath = Path.Combine(Global.WalletsDir, $"{WalletName}.json");
@@ -31,14 +33,17 @@ namespace WalletWasabi.Gui.Tabs.WalletManager
else if (string.IsNullOrWhiteSpace(WalletName))
{
// Invalid wallet name.
+ ValidationMessage = $"The name {WalletName} is not valid.";
}
else if (File.Exists(walletFilePath))
{
// Wallet with the same name already exists.
+ ValidationMessage = $"The name {WalletName} is already taken.";
}
else if (Password != PasswordConfirmation)
{
// Password does not match the password confirmation.
+ ValidationMessage = $"The passwords do not match.";
}
else
{
@@ -80,6 +85,12 @@ namespace WalletWasabi.Gui.Tabs.WalletManager
set { this.RaiseAndSetIfChanged(ref _termsAccepted, value); }
}
+ public string ValidationMessage
+ {
+ get { return _validationMessage; }
+ set { this.RaiseAndSetIfChanged(ref _validationMessage, value); }
+ }
+
public ReactiveCommand GenerateCommand { get; }
public void OnTermsClicked()
@@ -89,5 +100,29 @@ namespace WalletWasabi.Gui.Tabs.WalletManager
public void OnPrivacyClicked()
{
}
+
+ public override void OnCategorySelected()
+ {
+ base.OnCategorySelected();
+
+ Password = null;
+ PasswordConfirmation = null;
+ WalletName = GetNextWalletName();
+ TermsAccepted = false;
+ ValidationMessage = null;
+ }
+
+ private static string GetNextWalletName()
+ {
+ for (int i = 0; i < int.MaxValue; i++)
+ {
+ if (!File.Exists(Path.Combine(Global.WalletsDir, $"Wallet{i}.json")))
+ {
+ return $"Wallet{i}";
+ }
+ }
+
+ throw new NotSupportedException("This is impossible.");
+ }
}
}

MODIFY
WalletWasabi.Gui/Tabs/WalletManager/WalletManagerViewModel.cs
WalletWasabi.Gui/Tabs/WalletManager/WalletManagerViewModel.cs
using System.Collections.ObjectModel;
using System.Linq;
using WalletWasabi.Gui.ViewModels;
+using System;
namespace WalletWasabi.Gui.Tabs.WalletManager
{
@@ -14,10 +15,16 @@ namespace WalletWasabi.Gui.Tabs.WalletManager
{
Categories = new ObservableCollection<CategoryViewModel>
{
- new GenerateWalletViewModel()
+ new GenerateWalletViewModel(),
+ new RecoverWalletViewModel()
};
SelectedCategory = Categories.FirstOrDefault();
+
+ this.WhenAnyValue(x => x.SelectedCategory).Subscribe(category =>
+ {
+ category?.OnCategorySelected();
+ });
}
public ObservableCollection<CategoryViewModel> Categories

implement generate wallet validation.