feat(ui): wallet name field in creation wizard

The last wizard step (password) now shows an optional name field.
The name becomes the filename: <name>.wallet.json in the wallets
directory. Invalid filename characters are replaced with '_'.

If left empty, the existing auto-name logic applies (default.wallet.json,
wallet-2.wallet.json, …). If the chosen name already exists the wizard
shows an error instead of overwriting.

The name field is visually separated from the encryption section by a
distinct background panel and a horizontal divider.
This commit is contained in:
2026-06-15 15:05:49 +02:00
parent 3054a9baaa
commit 14ae39c5aa
3 changed files with 71 additions and 15 deletions
+3
View File
@@ -98,6 +98,9 @@ public sealed class Loc
["wiz.words.placeholder"] = ["Mnemonica BIP39 (12 o 24 parole separate da spazi)", "BIP39 mnemonic (12 or 24 words separated by spaces)", "Mnemónico BIP39 (12 o 24 palabras separadas por espacios)", "Mnémonique BIP39 (12 ou 24 mots séparés par des espaces)", "Mnemônico BIP39 (12 ou 24 palavras separadas por espaços)", "BIP39-Mnemonic (12 oder 24 durch Leerzeichen getrennte Wörter)"],
["wiz.passphrase.title"] = ["Passphrase opzionale", "Optional passphrase", "Frase de contraseña opcional", "Phrase de passe optionnelle", "Frase-senha opcional", "Optionale Passphrase"],
["wiz.passphrase.placeholder"] = ["Lascia vuoto per non usarla", "Leave empty to skip", "Deja vacío para omitir", "Laisser vide pour ignorer", "Deixe vazio para ignorar", "Leer lassen zum Überspringen"],
["wiz.name.label"] = ["Nome wallet (opzionale)", "Wallet name (optional)", "Nombre del wallet (opcional)", "Nom du wallet (optionnel)", "Nome da carteira (opcional)", "Wallet-Name (optional)"],
["wiz.name.placeholder"] = ["es. risparmio, trading… (lascia vuoto per nome automatico)", "e.g. savings, trading… (leave blank for auto name)", "p.ej. ahorro, trading… (deja en blanco para nombre automático)", "ex. épargne, trading… (laisser vide pour nom automatique)", "ex. poupança, trading… (deixe em branco para nome automático)", "z.B. Sparen, Trading… (leer lassen für automatischen Namen)"],
["msg.wallet.exists"] = ["Esiste già un wallet con questo nome. Scegli un nome diverso.", "A wallet with this name already exists. Choose a different name.", "Ya existe un wallet con este nombre. Elige un nombre diferente.", "Un wallet avec ce nom existe déjà. Choisissez un nom différent.", "Já existe uma carteira com este nome. Escolha um nome diferente.", "Ein Wallet mit diesem Namen existiert bereits. Wähle einen anderen Namen."],
["wiz.password.title"] = ["Password del file wallet", "Wallet file password", "Contraseña del archivo wallet", "Mot de passe du fichier wallet", "Senha do arquivo da carteira", "Wallet-Dateipasswort"],
["wiz.password.placeholder"] = ["Consigliata (vuoto = file in chiaro su disco)", "Recommended (empty = plaintext file on disk)", "Recomendada (vacío = archivo en texto claro en disco)", "Recommandé (vide = fichier en texte clair sur disque)", "Recomendada (vazio = arquivo em texto simples no disco)", "Empfohlen (leer = Klartextdatei auf Disk)"],
["wiz.password.create"] = ["Crea il wallet", "Create wallet", "Crear wallet", "Créer le wallet", "Criar carteira", "Wallet erstellen"],
@@ -1,6 +1,7 @@
using System;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using PalladiumWallet.App.Localization;
@@ -97,6 +98,9 @@ public partial class MainWindowViewModel
[ObservableProperty]
private string passphraseInput = "";
[ObservableProperty]
private string walletNameInput = "";
[ObservableProperty]
private string passwordInput = "";
@@ -399,9 +403,12 @@ public partial class MainWindowViewModel
}
}
var path = AppPaths.DefaultWalletPath(Net);
for (var n = 2; WalletStore.Exists(path); n++)
path = Path.Combine(AppPaths.WalletsDir(Net), $"wallet-{n}.wallet.json");
var path = WalletPathFromName(WalletNameInput);
if (WalletStore.Exists(path))
{
StatusMessage = Loc.Tr("msg.wallet.exists");
return;
}
WalletStore.Save(doc, path, password);
var newLock = WalletLock.TryAcquire(path);
if (newLock is null) { StatusMessage = Loc.Tr("msg.wallet.locked"); return; }
@@ -413,6 +420,31 @@ public partial class MainWindowViewModel
}
}
/// <summary>
/// Costruisce il percorso file dal nome inserito dall'utente.
/// Se il nome è vuoto genera un nome automatico (default, wallet-2, …).
/// Rimuove i caratteri non validi per il filesystem.
/// </summary>
private string WalletPathFromName(string name)
{
var clean = string.IsNullOrWhiteSpace(name)
? ""
: string.Concat(name.Trim()
.Select(c => Path.GetInvalidFileNameChars().Contains(c) ? '_' : c))
.Trim('.');
if (string.IsNullOrEmpty(clean))
{
// Nessun nome → nome automatico
var def = AppPaths.DefaultWalletPath(Net);
for (var n = 2; WalletStore.Exists(def); n++)
def = Path.Combine(AppPaths.WalletsDir(Net), $"wallet-{n}.wallet.json");
return def;
}
return Path.Combine(AppPaths.WalletsDir(Net), $"{clean}.wallet.json");
}
[RelayCommand]
private void OpenExisting()
{
@@ -499,7 +531,7 @@ public partial class MainWindowViewModel
_account = account;
_walletPath = path;
_password = password;
MnemonicInput = ConfirmMnemonicInput = PassphraseInput = PasswordInput = ConfirmPasswordInput = "";
MnemonicInput = ConfirmMnemonicInput = PassphraseInput = PasswordInput = ConfirmPasswordInput = WalletNameInput = "";
ImportXkeyInput = ImportWifInput = ImportXkeyDetectedKind = "";
SetupStep = StepStart;
+32 -11
View File
@@ -254,18 +254,39 @@
</StackPanel>
</StackPanel>
<!-- Passo finale: password del file (cifratura, stile Electrum) -->
<StackPanel IsVisible="{Binding IsStepPassword}" Spacing="12">
<!-- Passo finale: nome + password del file (cifratura, stile Electrum) -->
<StackPanel IsVisible="{Binding IsStepPassword}" Spacing="16">
<TextBlock Text="{Binding Loc[wiz.password.title]}" FontSize="18" FontWeight="Bold"/>
<TextBox PlaceholderText="{Binding Loc[wiz.password.placeholder]}"
PasswordChar="●" Text="{Binding PasswordInput}"/>
<TextBox PlaceholderText="{Binding Loc[wiz.password.confirm]}"
PasswordChar="●" Text="{Binding ConfirmPasswordInput}"/>
<CheckBox Content="{Binding Loc[wiz.password.encrypt]}"
IsChecked="{Binding EncryptWallet}"/>
<TextBlock Text="{Binding Loc[wiz.password.encrypt.hint]}"
Foreground="Gray" FontSize="12" TextWrapping="Wrap"
IsVisible="{Binding !EncryptWallet}"/>
<!-- Sezione nome: bordo distinto dal gruppo password -->
<Border BorderBrush="{DynamicResource SystemAccentColor}"
BorderThickness="0,0,0,0"
Background="{DynamicResource SystemControlBackgroundAltHighBrush}"
CornerRadius="6" Padding="12,10">
<StackPanel Spacing="6">
<TextBlock Text="{Binding Loc[wiz.name.label]}"
FontWeight="SemiBold" FontSize="13"/>
<TextBox PlaceholderText="{Binding Loc[wiz.name.placeholder]}"
Text="{Binding WalletNameInput}"/>
</StackPanel>
</Border>
<!-- Separatore visivo -->
<Separator Margin="0,0"/>
<!-- Sezione cifratura -->
<StackPanel Spacing="8">
<TextBox PlaceholderText="{Binding Loc[wiz.password.placeholder]}"
PasswordChar="●" Text="{Binding PasswordInput}"/>
<TextBox PlaceholderText="{Binding Loc[wiz.password.confirm]}"
PasswordChar="●" Text="{Binding ConfirmPasswordInput}"/>
<CheckBox Content="{Binding Loc[wiz.password.encrypt]}"
IsChecked="{Binding EncryptWallet}"/>
<TextBlock Text="{Binding Loc[wiz.password.encrypt.hint]}"
Foreground="Gray" FontSize="12" TextWrapping="Wrap"
IsVisible="{Binding !EncryptWallet}"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Spacing="10">
<Button Content="{Binding Loc[wiz.back]}" Command="{Binding WizardBackCommand}"/>
<Button Content="{Binding Loc[wiz.password.create]}" Classes="accent"