From 4a0a336ebb05e7f87b9d3940eeaa16682bb819ff Mon Sep 17 00:00:00 2001 From: Konstantin Ullrich Date: Wed, 26 Nov 2025 20:02:54 +0100 Subject: [PATCH] refactor: streamline validators by updating patterns and adjusting syntax for consistency (#2685) --- lib/core/amount_validator.dart | 47 +++++++++++++++------------------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/lib/core/amount_validator.dart b/lib/core/amount_validator.dart index f85df483f..20008e357 100644 --- a/lib/core/amount_validator.dart +++ b/lib/core/amount_validator.dart @@ -52,45 +52,38 @@ class AmountValidator extends TextValidator { class SymbolsAmountValidator extends TextValidator { SymbolsAmountValidator({required bool isAutovalidate}) : super( - errorMessage: S.current.error_text_amount, - pattern: _pattern(), - isAutovalidate: isAutovalidate, - minLength: 0, - maxLength: 0); + errorMessage: S.current.error_text_amount, + pattern: _pattern(), + isAutovalidate: isAutovalidate, + minLength: 0, + maxLength: 0, + ); static String _pattern() => '^([0-9]+([.\,][0-9]+)?|[.\,][0-9]+)\$'; } class DecimalAmountValidator extends TextValidator { - DecimalAmountValidator({required Currency currency, required bool isAutovalidate }) + DecimalAmountValidator({required Currency currency, required bool isAutovalidate}) : super( - errorMessage: S.current.decimal_places_error, - pattern: _pattern(currency), - isAutovalidate: isAutovalidate, - minLength: 0, - maxLength: 0); + errorMessage: S.current.decimal_places_error, + pattern: _pattern(currency), + isAutovalidate: isAutovalidate, + minLength: 0, + maxLength: 0, + ); - static String _pattern(Currency currency) { - switch (currency) { - case CryptoCurrency.xmr: - return '^([0-9]+([.\,][0-9]{1,12})?|[.\,][0-9]{1,12})\$'; - case CryptoCurrency.btc: - return '^([0-9]+([.\,][0-9]{1,8})?|[.\,][0-9]{1,8})\$'; - case CryptoCurrency.zano: - return '^([0-9]+([.\,][0-9]{1,12})?|[.\,][0-9]{1,18})\$'; - default: - return '^([0-9]+([.\,][0-9]{1,12})?|[.\,][0-9]{1,12})\$'; - } - } + static String _pattern(Currency currency) => + '^([0-9]+([.\,][0-9]{1,${currency.decimals})?|[.\,][0-9]{1,${currency.decimals}})\$'; } class AllAmountValidator extends TextValidator { AllAmountValidator() : super( - errorMessage: S.current.error_text_amount, - pattern: S.current.all, - minLength: 0, - maxLength: 0); + errorMessage: S.current.error_text_amount, + pattern: S.current.all, + minLength: 0, + maxLength: 0, + ); } class AmountMinValidator extends Validator {