lib/core/address_validator.dart - updated zano address regex

lib/src/screens/dashboard/edit_token_page.dart - using AddressValidator().call
This commit is contained in:
leo 2024-10-27 06:04:46 +00:00
parent cda4a38b59
commit 3caca5c913
2 changed files with 7 additions and 7 deletions

View file

@ -7,18 +7,18 @@ import 'package:cw_core/erc20_token.dart';
import 'package:cw_zano/zano_utils.dart';
class AddressValidator extends TextValidator {
AddressValidator({required CryptoCurrency type, bool skipZanoAddressValidation = false})
AddressValidator({required CryptoCurrency type})
: super(
errorMessage: S.current.error_text_address,
useAdditionalValidation: type == CryptoCurrency.btc
? (String txt) => validateAddress(address: txt, network: BitcoinNetwork.mainnet)
: type == CryptoCurrency.zano && !skipZanoAddressValidation
: type == CryptoCurrency.zano
? ZanoUtils.validateAddress
: null,
pattern: getPattern(type, skipZanoAddressValidation),
pattern: getPattern(type),
length: getLength(type));
static String getPattern(CryptoCurrency type, bool skipZanoAddressValidation) {
static String getPattern(CryptoCurrency type) {
if (type is Erc20Token) {
return '0x[0-9a-zA-Z]';
}
@ -127,7 +127,7 @@ class AddressValidator extends TextValidator {
case CryptoCurrency.btcln:
return '^(lnbc|LNBC)([0-9]{1,}[a-zA-Z0-9]+)';
case CryptoCurrency.zano:
return skipZanoAddressValidation ? '[0-9a-zA-Z]' : r'$.^'; // always false, we use additional validation then
return '([1-9A-HJ-NP-Za-km-z]{90,200})|(@[\w\d-.]+)';
default:
return '[0-9a-zA-Z]';
}
@ -308,7 +308,7 @@ class AddressValidator extends TextValidator {
case CryptoCurrency.trx:
return '(T|t)[1-9A-HJ-NP-Za-km-z]{33}';
case CryptoCurrency.zano:
return '[0-9a-zA-Z]{1,100}';
return '([1-9A-HJ-NP-Za-km-z]{90,200})|(@[\w\d-.]+)';
default:
if (type.tag == CryptoCurrency.eth.title) {
return '0x[0-9a-zA-Z]{42}';

View file

@ -267,7 +267,7 @@ class _EditTokenPageBodyState extends State<EditTokenPageBody> {
placeholder: S.of(context).token_contract_address,
options: [AddressTextFieldOption.paste],
buttonColor: Theme.of(context).hintColor,
validator: widget.homeSettingsViewModel.walletType == WalletType.zano ? null : AddressValidator(type: widget.homeSettingsViewModel.nativeToken),
validator: widget.homeSettingsViewModel.walletType == WalletType.zano ? null : AddressValidator(type: widget.homeSettingsViewModel.nativeToken).call,
onPushPasteButton: (_) {
_pasteText();
},