Skip to content

Commit 48315e1

Browse files
committed
trim wallet name before validation
1 parent 36ba974 commit 48315e1

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

lib/blocs/wallets_repository.dart

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,23 @@ class WalletsRepository {
9999
getWallets().ignore();
100100
return null;
101101
}
102+
103+
final trimmedName = name.trim();
104+
105+
// Check if the trimmed name is empty (prevents space-only names)
106+
if (trimmedName.isEmpty) {
107+
return LocaleKeys.walletCreationNameLengthError.tr();
108+
}
109+
110+
// Check if trimmed name exceeds length limit
111+
if (trimmedName.length > 40) {
112+
return LocaleKeys.walletCreationNameLengthError.tr();
113+
}
102114

115+
// Check for duplicates using the exact input name (not trimmed)
116+
// This preserves backward compatibility with existing wallets that might have spaces
103117
if (_cachedWallets!.firstWhereOrNull((w) => w.name == name) != null) {
104118
return LocaleKeys.walletCreationExistNameError.tr();
105-
} else if (name.isEmpty || name.length > 40) {
106-
return LocaleKeys.walletCreationNameLengthError.tr();
107119
}
108120

109121
return null;

lib/views/wallets_manager/widgets/wallet_creation.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ class _WalletCreationState extends State<WalletCreation> {
186186

187187
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
188188
widget.onCreate(
189-
name: _nameController.text,
189+
name: _nameController.text.trim(),
190190
password: _passwordController.text,
191191
walletType: _isHdMode ? WalletType.hdwallet : WalletType.iguana,
192192
);

lib/views/wallets_manager/widgets/wallet_simple_import.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class _WalletImportWrapperState extends State<WalletSimpleImport> {
9797
_step == WalletSimpleImportSteps.nameAndSeed
9898
? LocaleKeys.walletImportTitle.tr()
9999
: LocaleKeys.walletImportCreatePasswordTitle.tr(
100-
args: [_nameController.text],
100+
args: [_nameController.text.trim()],
101101
),
102102
style: Theme.of(
103103
context,
@@ -325,7 +325,7 @@ class _WalletImportWrapperState extends State<WalletSimpleImport> {
325325

326326
WidgetsBinding.instance.addPostFrameCallback((_) {
327327
widget.onImport(
328-
name: _nameController.text,
328+
name: _nameController.text.trim(),
329329
password: _passwordController.text,
330330
walletConfig: config,
331331
);

0 commit comments

Comments
 (0)