CAKE-192 | added verification of open alias and unstoppable domains in exchange_page.dart and send_page.dart

OleksandrSobol committed Jun 15, 2021 at 22:43 UTC 7ddbc6b8f420cea82b10291b7408ffdfaf617fdc
4 files changed +39 -19
lib/src/screens/exchange/exchange_page.dart
+15 -8
@@ -778,15 +778,22 @@ class ExchangePage extends BasePage {
778
779 Future<String> applyUnstoppableDomainAddress(BuildContext context,
780 String domain, String ticker) async {
781 - try {
782 - final address =
783 - await exchangeViewModel.getUnstoppableDomainAddress(domain, ticker);
784 - if ((address != null)&&address.isNotEmpty) {
785 - unstoppableDomainAddressAlert(context, domain);
786 - return address;
781 + const topLevelDomain = 'crypto';
782 +
783 + if (domain.contains('.')) {
784 + final name = domain.split('.').last;
785 + if (name.isNotEmpty && (name == topLevelDomain)) {
786 + try {
787 + final address =
788 + await exchangeViewModel.getUnstoppableDomainAddress(domain, ticker);
789 + if ((address != null)&&address.isNotEmpty) {
790 + unstoppableDomainAddressAlert(context, domain);
791 + return address;
792 + }
793 + } catch (e) {
794 + print(e.toString());
795 + }
796 }
788 - } catch (e) {
789 - print(e.toString());
797 }
798
799 return domain;
lib/src/screens/send/send_page.dart
+22 -9
@@ -38,10 +38,9 @@ class SendPage extends BasePage {
38 _cryptoAmountFocus = FocusNode(),
39 _fiatAmountFocus = FocusNode(),
40 _addressFocusNode = FocusNode() {
41 - _addressFocusNode.addListener(() async {
41 + _addressFocusNode.addListener(() {
42 if (!_addressFocusNode.hasFocus && _addressController.text.isNotEmpty) {
43 - await getOpenaliasRecord(_addressFocusNode.context);
44 - await applyUnstoppableDomainAddress(_addressFocusNode.context);
43 + applyOpenaliasOrUnstoppableDomains(_addressFocusNode.context);
44 }
45 });
46 }
@@ -174,9 +173,8 @@ class SendPage extends BasePage {
173 .headline
174 .decorationColor),
175 validator: sendViewModel.addressValidator,
177 - onPushPasteButton: (context) async {
178 - await getOpenaliasRecord(context);
179 - await applyUnstoppableDomainAddress(context);
176 + onPushPasteButton: (context) {
177 + applyOpenaliasOrUnstoppableDomains(context);
178 },
179 ),
180 Observer(
@@ -518,13 +516,12 @@ class SendPage extends BasePage {
516 to: template.name,
517 amount: template.amount,
518 from: template.cryptoCurrency,
521 - onTap: () async {
519 + onTap: () {
520 _addressController.text =
521 template.address;
522 _cryptoAmountController.text =
523 template.amount;
526 - await getOpenaliasRecord(context);
527 - await applyUnstoppableDomainAddress(context);
524 + applyOpenaliasOrUnstoppableDomains(context);
525 },
526 onRemove: () {
527 showPopUp<void>(
@@ -792,4 +789,20 @@ class SendPage extends BasePage {
789 print(e.toString());
790 }
791 }
792 +
793 + void applyOpenaliasOrUnstoppableDomains(BuildContext context) async {
794 + const topLevelDomain = 'crypto';
795 + final address = _addressController.text;
796 +
797 + if (address.contains('.')) {
798 + final name = address.split('.').last;
799 + if (name.isNotEmpty) {
800 + if (name == topLevelDomain) {
801 + await applyUnstoppableDomainAddress(context);
802 + } else {
803 + await getOpenaliasRecord(context);
804 + }
805 + }
806 + }
807 + }
808 }
res/values/strings_de.arb
+1 -1
@@ -480,7 +480,7 @@
480 "moonpay_alert_text" : "Der Wert des Betrags muss größer oder gleich sein ${minAmount} ${fiatCurrency}",
481
482 "outdated_electrum_wallet_receive_warning": "Wenn diese Brieftasche einen 12-Wort-Seed hat und in Cake erstellt wurde, zahlen Sie KEINE Bitcoins in diese Brieftasche ein. Alle auf diese Wallet übertragenen BTC können verloren gehen. Erstellen Sie eine neue 24-Wort-Wallet (tippen Sie auf das Menü oben rechts, wählen Sie Wallets, wählen Sie Create New Wallet und dann Bitcoin) und verschieben Sie Ihre BTC SOFORT dorthin. Neue (24 Wörter) BTC-Wallets von Cake sind sicher",
483 - "do_not_show_me": "Zeig mir das nicht noch einmal"
483 + "do_not_show_me": "Zeig mir das nicht noch einmal",
484 "outdated_electrum_wallet_description" : "Neue Bitcoin-Geldbörsen, die in Cake erstellt wurden, haben jetzt einen Startwert von 24 Wörtern. Es ist obligatorisch, dass Sie eine neue Bitcoin-Brieftasche erstellen, Ihr gesamtes Geld in die neue 24-Wörter-Brieftasche überweisen und keine Brieftaschen mit einem 12-Wörter-Startwert mehr verwenden. Bitte tun Sie dies sofort, um Ihr Geld zu sichern.",
485 "understand" : "Ich verstehe",
486
res/values/strings_en.arb
+1 -1
@@ -483,7 +483,7 @@
483 "moonpay_alert_text" : "Value of the amount must be more or equal to ${minAmount} ${fiatCurrency}",
484
485 "outdated_electrum_wallet_receive_warning": "If this wallet has a 12-word seed and was created in Cake, DO NOT deposit Bitcoin into this wallet. Any BTC transferred to this wallet may be lost. Create a new 24-word wallet (tap the menu at the top right, select Wallets, choose Create New Wallet, then select Bitcoin) and IMMEDIATELY move your BTC there. New (24-word) BTC wallets from Cake are secure",
486 - "do_not_show_me": "Do not show me this again"
486 + "do_not_show_me": "Do not show me this again",
487
488 "address_detected" : "Address detected",
489 "address_from_domain" : "You got address from unstoppable domain ${domain}"