refactor: streamline validators by updating patterns and adjusting syntax for consistency (#2685)
Konstantin Ullrich committed
Nov 26, 2025 at 20:02 UTC
4a0a336ebb05e7f87b9d3940eeaa16682bb819ff
1 file changed
+21
-28
lib/core/amount_validator.dart
+21
-28
@@ -52,45 +52,38 @@ class AmountValidator extends TextValidator {
52
class SymbolsAmountValidator extends TextValidator {
53
SymbolsAmountValidator({required bool isAutovalidate})
54
: super(
55
- errorMessage: S.current.error_text_amount,
56
- pattern: _pattern(),
57
- isAutovalidate: isAutovalidate,
58
- minLength: 0,
59
- maxLength: 0);
55
+ errorMessage: S.current.error_text_amount,
56
+ pattern: _pattern(),
57
+ isAutovalidate: isAutovalidate,
58
+ minLength: 0,
59
+ maxLength: 0,
60
+ );
61
62
static String _pattern() => '^([0-9]+([.\,][0-9]+)?|[.\,][0-9]+)\$';
63
}
64
65
class DecimalAmountValidator extends TextValidator {
65
- DecimalAmountValidator({required Currency currency, required bool isAutovalidate })
66
+ DecimalAmountValidator({required Currency currency, required bool isAutovalidate})
67
: super(
67
- errorMessage: S.current.decimal_places_error,
68
- pattern: _pattern(currency),
69
- isAutovalidate: isAutovalidate,
70
- minLength: 0,
71
- maxLength: 0);
72
-
73
- static String _pattern(Currency currency) {
74
- switch (currency) {
75
- case CryptoCurrency.xmr:
76
- return '^([0-9]+([.\,][0-9]{1,12})?|[.\,][0-9]{1,12})\$';
77
- case CryptoCurrency.btc:
78
- return '^([0-9]+([.\,][0-9]{1,8})?|[.\,][0-9]{1,8})\$';
79
- case CryptoCurrency.zano:
80
- return '^([0-9]+([.\,][0-9]{1,12})?|[.\,][0-9]{1,18})\$';
81
- default:
82
- return '^([0-9]+([.\,][0-9]{1,12})?|[.\,][0-9]{1,12})\$';
83
- }
84
- }
68
+ errorMessage: S.current.decimal_places_error,
69
+ pattern: _pattern(currency),
70
+ isAutovalidate: isAutovalidate,
71
+ minLength: 0,
72
+ maxLength: 0,
73
+ );
74
+
75
+ static String _pattern(Currency currency) =>
76
+ '^([0-9]+([.\,][0-9]{1,${currency.decimals})?|[.\,][0-9]{1,${currency.decimals}})\$';
77
}
78
79
class AllAmountValidator extends TextValidator {
80
AllAmountValidator()
81
: super(
90
- errorMessage: S.current.error_text_amount,
91
- pattern: S.current.all,
92
- minLength: 0,
93
- maxLength: 0);
82
+ errorMessage: S.current.error_text_amount,
83
+ pattern: S.current.all,
84
+ minLength: 0,
85
+ maxLength: 0,
86
+ );
87
}
88
89
class AmountMinValidator extends Validator<String> {