Skip to content

Commit

Permalink
lib/core/address_validator.dart - updated zano address regex
Browse files Browse the repository at this point in the history
lib/src/screens/dashboard/edit_token_page.dart - using AddressValidator().call
  • Loading branch information
LeoBlackCat committed Oct 27, 2024
1 parent cda4a38 commit 3caca5c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions lib/core/address_validator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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]';
}
Expand Down Expand Up @@ -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]';
}
Expand Down Expand Up @@ -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}';
Expand Down
2 changes: 1 addition & 1 deletion lib/src/screens/dashboard/edit_token_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
},
Expand Down

0 comments on commit 3caca5c

Please sign in to comment.