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
Serhii committed
Mar 4, 2025 at 03:58 UTC
dcd978eb38f370fce975d23517d73aa4728df0f3
2 files changed
+39
lib/core/address_validator.dart
+3
@@ -281,6 +281,9 @@ class AddressValidator extends TextValidator {
281
}
282
}
283
284
+ static String get silentPaymentAddressPattern => SilentPaymentAddress.regex.pattern;
285
+ static String get mWebAddressPattern => MwebAddress.regex.pattern;
286
+
287
static String? getAddressFromStringPattern(CryptoCurrency type) {
288
String? pattern = null;
289
lib/src/screens/send/send_page.dart
+36
@@ -1,4 +1,5 @@
1
import 'package:cake_wallet/bitcoin/bitcoin.dart';
2
+import 'package:cake_wallet/core/address_validator.dart';
3
import 'package:cake_wallet/core/auth_service.dart';
4
import 'package:cake_wallet/entities/contact_record.dart';
5
import 'package:cake_wallet/core/execution_state.dart';
@@ -544,6 +545,10 @@ class SendPage extends BasePage {
545
);
546
547
newContactAddress = newContactAddress ?? sendViewModel.newContactAddress();
548
+ if (newContactAddress?.address != null && isRegularElectrumAddress(newContactAddress!.address)) {
549
+ newContactAddress = null;
550
+ }
551
+
552
if (sendViewModel.coinTypeToSpendFrom != UnspentCoinType.any) newContactAddress = null;
553
554
if (newContactAddress != null && sendViewModel.showAddressBookPopup) {
@@ -664,4 +669,35 @@ class SendPage extends BasePage {
669
),
670
context: context);
671
}
672
+
673
+ bool isRegularElectrumAddress(String address) {
674
+ final supportedTypes = [CryptoCurrency.btc, CryptoCurrency.ltc, CryptoCurrency.bch];
675
+ final excludedPatterns = [
676
+ RegExp(AddressValidator.silentPaymentAddressPattern),
677
+ RegExp(AddressValidator.mWebAddressPattern)
678
+ ];
679
+
680
+ final trimmed = address.trim();
681
+
682
+ bool isValid = false;
683
+ for (var type in supportedTypes) {
684
+ final addressPattern = AddressValidator.getAddressFromStringPattern(type);
685
+ if (addressPattern != null) {
686
+ final regex = RegExp('^$addressPattern\$');
687
+ if (regex.hasMatch(trimmed)) {
688
+ isValid = true;
689
+ break;
690
+ }
691
+ }
692
+ }
693
+
694
+ for (var pattern in excludedPatterns) {
695
+ if (pattern.hasMatch(trimmed)) {
696
+ return false;
697
+ }
698
+ }
699
+
700
+ return isValid;
701
+ }
702
+
703
}