feat: add optional parameter to customize address extraction pattern

This commit is contained in:
Konstantin Ullrich 2025-06-13 15:14:50 +02:00
parent e5d0194f11
commit 3af22422a8
No known key found for this signature in database
GPG key ID: 6B3199AD9B3D23B8
2 changed files with 5 additions and 3 deletions

View file

@ -284,7 +284,7 @@ class AddressValidator extends TextValidator {
static String get silentPaymentAddressPattern => SilentPaymentAddress.regex.pattern;
static String get mWebAddressPattern => MwebAddress.regex.pattern;
static String? getAddressFromStringPattern(CryptoCurrency type) {
static String? getAddressFromStringPattern(CryptoCurrency type, [bool requireJustAddress = true]) {
String? pattern = null;
switch (type) {
@ -336,7 +336,9 @@ class AddressValidator extends TextValidator {
}
if (pattern != null) {
return "$BEFORE_REGEX($pattern)$AFTER_REGEX";
if (requireJustAddress)
return "$BEFORE_REGEX($pattern)$AFTER_REGEX";
return "($pattern)";
}
return null;

View file

@ -166,7 +166,7 @@ class AddressResolver {
];
static String? extractAddressByType({required String raw, required CryptoCurrency type}) {
final addressPattern = AddressValidator.getAddressFromStringPattern(type);
final addressPattern = AddressValidator.getAddressFromStringPattern(type, false);
if (addressPattern == null) {
throw Exception('Unexpected token: $type for getAddressFromStringPattern');