2020-06-20 07:10:00 +00:00
|
|
|
import 'package:cake_wallet/core/validator.dart';
|
|
|
|
import 'package:cake_wallet/generated/i18n.dart';
|
2020-09-21 11:50:26 +00:00
|
|
|
import 'package:cake_wallet/entities/wallet_type.dart';
|
2020-06-20 07:10:00 +00:00
|
|
|
|
|
|
|
class AmountValidator extends TextValidator {
|
2020-07-31 15:29:21 +00:00
|
|
|
AmountValidator({WalletType type, bool isAutovalidate = false})
|
2020-06-20 07:10:00 +00:00
|
|
|
: super(
|
|
|
|
errorMessage: S.current.error_text_amount,
|
|
|
|
pattern: _pattern(type),
|
2020-07-31 15:29:21 +00:00
|
|
|
isAutovalidate: isAutovalidate,
|
2020-06-20 07:10:00 +00:00
|
|
|
minLength: 0,
|
|
|
|
maxLength: 0);
|
|
|
|
|
|
|
|
static String _pattern(WalletType type) {
|
|
|
|
switch (type) {
|
|
|
|
case WalletType.monero:
|
2020-08-25 16:32:40 +00:00
|
|
|
return '^([0-9]+([.\,][0-9]{0,12})?|[.\,][0-9]{1,12})\$';
|
2020-06-20 07:10:00 +00:00
|
|
|
case WalletType.bitcoin:
|
|
|
|
// FIXME: Incorrect pattern for bitcoin
|
2020-08-25 16:32:40 +00:00
|
|
|
return '^([0-9]+([.\,][0-9]{0,12})?|[.\,][0-9]{1,12})\$';
|
2020-06-20 07:10:00 +00:00
|
|
|
default:
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-10-09 07:41:29 +00:00
|
|
|
|
|
|
|
class AllAmountValidator extends TextValidator {
|
|
|
|
AllAmountValidator() : super(
|
|
|
|
errorMessage: S.current.error_text_amount,
|
|
|
|
pattern: S.current.all,
|
|
|
|
minLength: 0,
|
|
|
|
maxLength: 0);
|
|
|
|
}
|