mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-17 05:41:29 +02:00
CW-924-Don't-prompt-to-save-to-address-book-on-standard-Bitcoin-Litecoin-Bitcoin-Cash-addresses (#2043)
* don't prompt regular btc ltc bch address * minor fix
This commit is contained in:
@@ -281,6 +281,9 @@ class AddressValidator extends TextValidator {
|
||||
}
|
||||
}
|
||||
|
||||
static String get silentPaymentAddressPattern => SilentPaymentAddress.regex.pattern;
|
||||
static String get mWebAddressPattern => MwebAddress.regex.pattern;
|
||||
|
||||
static String? getAddressFromStringPattern(CryptoCurrency type) {
|
||||
String? pattern = null;
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:cake_wallet/bitcoin/bitcoin.dart';
|
||||
import 'package:cake_wallet/core/address_validator.dart';
|
||||
import 'package:cake_wallet/core/auth_service.dart';
|
||||
import 'package:cake_wallet/entities/contact_record.dart';
|
||||
import 'package:cake_wallet/core/execution_state.dart';
|
||||
@@ -544,6 +545,10 @@ class SendPage extends BasePage {
|
||||
);
|
||||
|
||||
newContactAddress = newContactAddress ?? sendViewModel.newContactAddress();
|
||||
if (newContactAddress?.address != null && isRegularElectrumAddress(newContactAddress!.address)) {
|
||||
newContactAddress = null;
|
||||
}
|
||||
|
||||
if (sendViewModel.coinTypeToSpendFrom != UnspentCoinType.any) newContactAddress = null;
|
||||
|
||||
if (newContactAddress != null && sendViewModel.showAddressBookPopup) {
|
||||
@@ -664,4 +669,35 @@ class SendPage extends BasePage {
|
||||
),
|
||||
context: context);
|
||||
}
|
||||
|
||||
bool isRegularElectrumAddress(String address) {
|
||||
final supportedTypes = [CryptoCurrency.btc, CryptoCurrency.ltc, CryptoCurrency.bch];
|
||||
final excludedPatterns = [
|
||||
RegExp(AddressValidator.silentPaymentAddressPattern),
|
||||
RegExp(AddressValidator.mWebAddressPattern)
|
||||
];
|
||||
|
||||
final trimmed = address.trim();
|
||||
|
||||
bool isValid = false;
|
||||
for (var type in supportedTypes) {
|
||||
final addressPattern = AddressValidator.getAddressFromStringPattern(type);
|
||||
if (addressPattern != null) {
|
||||
final regex = RegExp('^$addressPattern\$');
|
||||
if (regex.hasMatch(trimmed)) {
|
||||
isValid = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (var pattern in excludedPatterns) {
|
||||
if (pattern.hasMatch(trimmed)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return isValid;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user