CAKE-192 | created parse_address_from_domain.dart; applied parseAddressFromDomain() to send_page.dart and exchange_page.dart; deleted unstoppable_domain_address_alert.dart

OleksandrSobol committed Jun 22, 2021 at 11:29 UTC bb219e4da27b9cbf5bcd6198be6e1e653b5fc9ac
7 files changed +77 -129
lib/src/screens/exchange/exchange_page.dart
+15 -38
@@ -1,7 +1,7 @@
1 import 'dart:ui';
2 import 'package:cake_wallet/entities/sync_status.dart';
3 import 'package:cake_wallet/entities/wallet_type.dart';
4 -import 'package:cake_wallet/src/screens/send/widgets/unstoppable_domain_address_alert.dart';
4 +import 'package:cake_wallet/src/screens/send/parse_address_from_domain.dart';
5 import 'package:cake_wallet/src/widgets/standard_checkbox.dart';
6 import 'package:dotted_border/dotted_border.dart';
7 import 'package:flutter/cupertino.dart';
@@ -226,10 +226,10 @@ class ExchangePage extends BasePage {
226 onPushPasteButton: (context) async {
227 final domain =
228 exchangeViewModel.depositAddress;
229 - final ticker =
230 - exchangeViewModel.depositCurrency.title;
229 + final ticker = exchangeViewModel
230 + .depositCurrency.title.toLowerCase();
231 exchangeViewModel.depositAddress =
232 - await applyUnstoppableDomainAddress(
232 + await parseAddressFromDomain(
233 context, domain, ticker);
234 },
235 ),
@@ -281,10 +281,10 @@ class ExchangePage extends BasePage {
281 onPushPasteButton: (context) async {
282 final domain =
283 exchangeViewModel.receiveAddress;
284 - final ticker =
285 - exchangeViewModel.receiveCurrency.title;
284 + final ticker = exchangeViewModel
285 + .receiveCurrency.title.toLowerCase();
286 exchangeViewModel.receiveAddress =
287 - await applyUnstoppableDomainAddress(
287 + await parseAddressFromDomain(
288 context, domain, ticker);
289 },
290 )),
@@ -512,14 +512,14 @@ class ExchangePage extends BasePage {
512 exchangeViewModel.isFixedRateMode = false;
513
514 var domain = template.depositAddress;
515 - var ticker = template.depositCurrency;
515 + var ticker = template.depositCurrency.toLowerCase();
516 exchangeViewModel.depositAddress =
517 - await applyUnstoppableDomainAddress(context, domain, ticker);
517 + await parseAddressFromDomain(context, domain, ticker);
518
519 domain = template.receiveAddress;
520 - ticker = template.receiveCurrency;
520 + ticker = template.receiveCurrency.toLowerCase();
521 exchangeViewModel.receiveAddress =
522 - await applyUnstoppableDomainAddress(context, domain, ticker);
522 + await parseAddressFromDomain(context, domain, ticker);
523 }
524
525 void _setReactions(
@@ -689,9 +689,9 @@ class ExchangePage extends BasePage {
689 if (!_depositAddressFocus.hasFocus &&
690 depositAddressController.text.isNotEmpty) {
691 final domain = depositAddressController.text;
692 - final ticker = exchangeViewModel.depositCurrency.title;
692 + final ticker = exchangeViewModel.depositCurrency.title.toLowerCase();
693 exchangeViewModel.depositAddress =
694 - await applyUnstoppableDomainAddress(context, domain, ticker);
694 + await parseAddressFromDomain(context, domain, ticker);
695 }
696 });
697
@@ -699,9 +699,9 @@ class ExchangePage extends BasePage {
699 if (!_receiveAddressFocus.hasFocus &&
700 receiveAddressController.text.isNotEmpty) {
701 final domain = receiveAddressController.text;
702 - final ticker = exchangeViewModel.receiveCurrency.title;
702 + final ticker = exchangeViewModel.receiveCurrency.title.toLowerCase();
703 exchangeViewModel.receiveAddress =
704 - await applyUnstoppableDomainAddress(context, domain, ticker);
704 + await parseAddressFromDomain(context, domain, ticker);
705 }
706 });
707
@@ -775,27 +775,4 @@ class ExchangePage extends BasePage {
775 key.currentState.addressController.text = null;
776 }
777 }
778 -
779 - Future<String> applyUnstoppableDomainAddress(BuildContext context,
780 - String domain, String ticker) async {
781 - const topLevelDomain = 'crypto';
782 -
783 - if (domain.contains('.')) {
784 - final name = domain.split('.').last;
785 - if (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 - }
797 - }
798 -
799 - return domain;
800 - }
778 }
lib/src/screens/send/parse_address_from_domain.dart new
+53
@@ -0,0 +1,53 @@
1 +import 'package:cake_wallet/entities/openalias_record.dart';
2 +import 'package:cake_wallet/entities/unstoppable_domain_address.dart';
3 +import 'package:cake_wallet/src/widgets/alert_with_one_action.dart';
4 +import 'package:cake_wallet/utils/show_pop_up.dart';
5 +import 'package:flutter/material.dart';
6 +import 'package:cake_wallet/generated/i18n.dart';
7 +
8 +const topLevelDomain = 'crypto';
9 +
10 +Future<String> parseAddressFromDomain(
11 + BuildContext context, String domain, String ticker) async {
12 + try {
13 + final name = domain.split('.').last;
14 +
15 + if (name.contains(topLevelDomain)) {
16 + final address = await fetchUnstoppableDomainAddress(domain, ticker);
17 + if (address.isNotEmpty) {
18 + showAddressAlert(
19 + context,
20 + S.of(context).address_detected,
21 + S.of(context).address_from_domain(domain));
22 + return address;
23 + }
24 + } else if (name.isNotEmpty) {
25 + final record = await OpenaliasRecord.fetchAddressAndName(
26 + OpenaliasRecord.formatDomainName(domain));
27 + if (record.name != null && record.name != domain) {
28 + showAddressAlert(
29 + context,
30 + S.of(context).openalias_alert_title,
31 + S.of(context).openalias_alert_content(domain));
32 + return record.address;
33 + }
34 + }
35 + } catch (e) {
36 + print(e.toString());
37 + }
38 +
39 + return domain;
40 +}
41 +
42 +void showAddressAlert(BuildContext context, String title, String content) async {
43 + await showPopUp<void>(
44 + context: context,
45 + builder: (BuildContext context) {
46 +
47 + return AlertWithOneAction(
48 + alertTitle: title,
49 + alertContent: content,
50 + buttonText: S.of(context).ok,
51 + buttonAction: () => Navigator.of(context).pop());
52 + });
53 +}
\ No newline at end of file
lib/src/screens/send/send_page.dart
+5 -50
@@ -1,6 +1,6 @@
1 import 'dart:ui';
2 import 'package:cake_wallet/entities/transaction_priority.dart';
3 -import 'package:cake_wallet/src/screens/send/widgets/unstoppable_domain_address_alert.dart';
3 +import 'package:cake_wallet/src/screens/send/parse_address_from_domain.dart';
4 import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart';
5 import 'package:cake_wallet/src/widgets/keyboard_done_button.dart';
6 import 'package:cake_wallet/src/widgets/picker.dart';
@@ -736,26 +736,6 @@ class SendPage extends BasePage {
736 _effectsInstalled = true;
737 }
738
739 - Future<void> getOpenaliasRecord(BuildContext context) async {
740 - final record =
741 - await sendViewModel.decodeOpenaliasRecord(_addressController.text);
742 -
743 - if (record != null) {
744 - _addressController.text = record.address;
745 -
746 - await showPopUp<void>(
747 - context: context,
748 - builder: (BuildContext context) {
749 - return AlertWithOneAction(
750 - alertTitle: S.of(context).openalias_alert_title,
751 - alertContent:
752 - S.of(context).openalias_alert_content(record.name),
753 - buttonText: S.of(context).ok,
754 - buttonAction: () => Navigator.of(context).pop());
755 - });
756 - }
757 - }
758 -
739 Future<void> _setTransactionPriority(BuildContext context) async {
740 final items = priorityForWalletType(sendViewModel.walletType);
741 final selectedItem = items.indexOf(sendViewModel.transactionPriority);
@@ -774,35 +754,10 @@ class SendPage extends BasePage {
754 context: context);
755 }
756
777 - Future<void> getUnstoppableDomainAddress(BuildContext context) async {
778 - try {
779 - final address = await sendViewModel
780 - .getUnstoppableDomainAddress(
781 - _addressController.text);
782 -
783 - if ((address != null)&&address.isNotEmpty) {
784 - unstoppableDomainAddressAlert(
785 - context, _addressController.text);
786 - _addressController.text = address;
787 - }
788 - } catch (e) {
789 - print(e.toString());
790 - }
791 - }
792 -
757 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 getUnstoppableDomainAddress(context);
802 - } else {
803 - await getOpenaliasRecord(context);
804 - }
805 - }
806 - }
758 + final domain = _addressController.text;
759 + final ticker = sendViewModel.currency.title.toLowerCase();
760 + _addressController.text =
761 + await parseAddressFromDomain(context, domain, ticker);
762 }
763 }
lib/src/screens/send/widgets/unstoppable_domain_address_alert.dart deleted
-17
@@ -1,17 +0,0 @@
1 -import 'package:cake_wallet/src/widgets/alert_with_one_action.dart';
2 -import 'package:cake_wallet/utils/show_pop_up.dart';
3 -import 'package:flutter/material.dart';
4 -import 'package:cake_wallet/generated/i18n.dart';
5 -
6 -void unstoppableDomainAddressAlert(BuildContext context, String domain) async {
7 - await showPopUp<void>(
8 - context: context,
9 - builder: (BuildContext context) {
10 -
11 - return AlertWithOneAction(
12 - alertTitle: S.of(context).address_detected,
13 - alertContent: S.of(context).address_from_domain(domain),
14 - buttonText: S.of(context).ok,
15 - buttonAction: () => Navigator.of(context).pop());
16 - });
17 -}
\ No newline at end of file
lib/view_model/exchange/exchange_view_model.dart
-5
@@ -4,7 +4,6 @@ import 'package:cake_wallet/bitcoin/bitcoin_wallet.dart';
4 import 'package:cake_wallet/core/wallet_base.dart';
5 import 'package:cake_wallet/entities/crypto_currency.dart';
6 import 'package:cake_wallet/entities/sync_status.dart';
7 -import 'package:cake_wallet/entities/unstoppable_domain_address.dart';
7 import 'package:cake_wallet/entities/wallet_type.dart';
8 import 'package:cake_wallet/exchange/exchange_provider.dart';
9 import 'package:cake_wallet/exchange/limits.dart';
@@ -423,8 +422,4 @@ abstract class ExchangeViewModelBase with Store {
422 }*/
423 isReceiveAmountEditable = false;
424 }
426 -
427 - Future<String> getUnstoppableDomainAddress(String domain, String ticker) async {
428 - return await fetchUnstoppableDomainAddress(domain, ticker.toLowerCase());
429 - }
425 }
lib/view_model/send/send_view_model.dart
-15
@@ -1,17 +1,14 @@
1 import 'package:cake_wallet/bitcoin/bitcoin_amount_format.dart';
2 import 'package:cake_wallet/bitcoin/bitcoin_transaction_priority.dart';
3 import 'package:cake_wallet/bitcoin/electrum_wallet.dart';
4 -import 'package:cake_wallet/entities/balance_display_mode.dart';
4 import 'package:cake_wallet/entities/calculate_fiat_amount_raw.dart';
5 import 'package:cake_wallet/entities/transaction_description.dart';
6 import 'package:cake_wallet/entities/transaction_priority.dart';
8 -import 'package:cake_wallet/entities/unstoppable_domain_address.dart';
7 import 'package:cake_wallet/monero/monero_amount_format.dart';
8 import 'package:cake_wallet/view_model/settings/settings_view_model.dart';
9 import 'package:hive/hive.dart';
10 import 'package:intl/intl.dart';
11 import 'package:mobx/mobx.dart';
14 -import 'package:cake_wallet/entities/openalias_record.dart';
12 import 'package:cake_wallet/entities/template.dart';
13 import 'package:cake_wallet/store/templates/send_template_store.dart';
14 import 'package:cake_wallet/core/template_validator.dart';
@@ -21,7 +18,6 @@ import 'package:cake_wallet/core/pending_transaction.dart';
18 import 'package:cake_wallet/core/validator.dart';
19 import 'package:cake_wallet/core/wallet_base.dart';
20 import 'package:cake_wallet/core/execution_state.dart';
24 -import 'package:cake_wallet/bitcoin/bitcoin_wallet.dart';
21 import 'package:cake_wallet/bitcoin/bitcoin_transaction_credentials.dart';
22 import 'package:cake_wallet/monero/monero_wallet.dart';
23 import 'package:cake_wallet/monero/monero_transaction_creation_credentials.dart';
@@ -265,17 +261,6 @@ abstract class SendViewModelBase with Store {
261 void setTransactionPriority(TransactionPriority priority) =>
262 _settingsStore.priority[_wallet.type] = priority;
263
268 - Future<OpenaliasRecord> decodeOpenaliasRecord(String name) async {
269 - final record = await OpenaliasRecord.fetchAddressAndName(
270 - OpenaliasRecord.formatDomainName(name));
271 -
272 - return record.name != name ? record : null;
273 - }
274 -
275 - Future<String> getUnstoppableDomainAddress(String domain) async {
276 - return await fetchUnstoppableDomainAddress(domain, currency.title.toLowerCase());
277 - }
278 -
264 @action
265 void _updateFiatAmount() {
266 try {
res/values/strings_zh.arb
+4 -4
@@ -482,9 +482,9 @@
482 "buy_with" : "一起购买",
483 "moonpay_alert_text" : "金额的价值必须大于或等于 ${minAmount} ${fiatCurrency}",
484
485 - "address_detected" : "檢測到地址",
486 - "address_from_domain" : "您有以下地址 unstoppable domain ${domain}",
487 -
485 "outdated_electrum_wallet_receive_warning": "如果这个钱包有一个 12 字的种子并且是在 Cake 中创建的,不要将比特币存入这个钱包。 任何转移到此钱包的 BTC 都可能丢失。 创建一个新的 24 字钱包(点击右上角的菜单,选择钱包,选择创建新钱包,然后选择比特币)并立即将您的 BTC 移到那里。 Cake 的新(24 字)BTC 钱包是安全的",
489 - "do_not_show_me": "不再提示"
486 + "do_not_show_me": "不再提示",
487 +
488 + "address_detected" : "檢測到地址",
489 + "address_from_domain" : "您有以下地址 unstoppable domain ${domain}"
490 }
\ No newline at end of file