Validate the WalletName property.
MODIFY
WalletWasabi.Fluent/ViewModels/AddWalletPageViewModel.cs
WalletWasabi.Fluent/ViewModels/AddWalletPageViewModel.cs
using ReactiveUI;
using System;
+using System.IO;
using System.Windows.Input;
using System.Reactive.Linq;
using System.Reactive.Threading.Tasks;
@@ -10,6 +11,8 @@ using NBitcoin;
using WalletWasabi.Fluent.ViewModels.Dialogs;
using WalletWasabi.Fluent.ViewModels.AddWallet;
using System.Threading.Tasks;
+using WalletWasabi.Gui.Validation;
+using WalletWasabi.Models;
namespace WalletWasabi.Fluent.ViewModels
{
@@ -38,7 +41,9 @@ namespace WalletWasabi.Fluent.ViewModels
var (km, mnemonic) = await Task.Run(
() =>
{
- var walletGenerator = new WalletGenerator(walletManager.WalletDirectories.WalletsDir,network)
+ var walletGenerator = new WalletGenerator(
+ walletManager.WalletDirectories.WalletsDir,
+ network)
{
TipHeight = store.SmartHeaderChain.TipHeight
};
@@ -53,6 +58,34 @@ namespace WalletWasabi.Fluent.ViewModels
PasswordInteraction = new Interaction<string, string?>();
PasswordInteraction.RegisterHandler(
async interaction => interaction.SetOutput(await new EnterPasswordViewModel().ShowDialogAsync()));
+
+ this.ValidateProperty(x => x.WalletName, errors => ValidateWalletName(errors, walletManager, WalletName));
+ }
+
+ private void ValidateWalletName(IValidationErrors errors, WalletManager walletManager, string walletName)
+ {
+ string walletFilePath = Path.Combine(walletManager.WalletDirectories.WalletsDir, $"{walletName}.json");
+
+ if (string.IsNullOrEmpty(walletName))
+ {
+ return;
+ }
+
+ if (File.Exists(walletFilePath))
+ {
+ errors.Add(ErrorSeverity.Error, $"A wallet named {WalletName} already exists. Please try a different name.");
+ }
+
+ if (string.IsNullOrWhiteSpace(walletName))
+ {
+ errors.Add(ErrorSeverity.Error, "Wallet name is not valid.");
+ return;
+ }
+
+ if (!WalletGenerator.ValidateWalletName(walletName))
+ {
+ errors.Add(ErrorSeverity.Error, $"{walletName} is not a valid Wallet name. Please try a different name.");
+ }
}
public override string IconName => "add_circle_regular";

Validate the WalletName property.