mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-31 16:09:49 +00:00
CAKE-192 | created parse_address_from_domain.dart; applied parseAddressFromDomain() to send_page.dart and exchange_page.dart; deleted unstoppable_domain_address_alert.dart
This commit is contained in:
parent
2cecec9257
commit
bb219e4da2
7 changed files with 77 additions and 129 deletions
|
@ -1,7 +1,7 @@
|
|||
import 'dart:ui';
|
||||
import 'package:cake_wallet/entities/sync_status.dart';
|
||||
import 'package:cake_wallet/entities/wallet_type.dart';
|
||||
import 'package:cake_wallet/src/screens/send/widgets/unstoppable_domain_address_alert.dart';
|
||||
import 'package:cake_wallet/src/screens/send/parse_address_from_domain.dart';
|
||||
import 'package:cake_wallet/src/widgets/standard_checkbox.dart';
|
||||
import 'package:dotted_border/dotted_border.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
|
@ -226,10 +226,10 @@ class ExchangePage extends BasePage {
|
|||
onPushPasteButton: (context) async {
|
||||
final domain =
|
||||
exchangeViewModel.depositAddress;
|
||||
final ticker =
|
||||
exchangeViewModel.depositCurrency.title;
|
||||
final ticker = exchangeViewModel
|
||||
.depositCurrency.title.toLowerCase();
|
||||
exchangeViewModel.depositAddress =
|
||||
await applyUnstoppableDomainAddress(
|
||||
await parseAddressFromDomain(
|
||||
context, domain, ticker);
|
||||
},
|
||||
),
|
||||
|
@ -281,10 +281,10 @@ class ExchangePage extends BasePage {
|
|||
onPushPasteButton: (context) async {
|
||||
final domain =
|
||||
exchangeViewModel.receiveAddress;
|
||||
final ticker =
|
||||
exchangeViewModel.receiveCurrency.title;
|
||||
final ticker = exchangeViewModel
|
||||
.receiveCurrency.title.toLowerCase();
|
||||
exchangeViewModel.receiveAddress =
|
||||
await applyUnstoppableDomainAddress(
|
||||
await parseAddressFromDomain(
|
||||
context, domain, ticker);
|
||||
},
|
||||
)),
|
||||
|
@ -512,14 +512,14 @@ class ExchangePage extends BasePage {
|
|||
exchangeViewModel.isFixedRateMode = false;
|
||||
|
||||
var domain = template.depositAddress;
|
||||
var ticker = template.depositCurrency;
|
||||
var ticker = template.depositCurrency.toLowerCase();
|
||||
exchangeViewModel.depositAddress =
|
||||
await applyUnstoppableDomainAddress(context, domain, ticker);
|
||||
await parseAddressFromDomain(context, domain, ticker);
|
||||
|
||||
domain = template.receiveAddress;
|
||||
ticker = template.receiveCurrency;
|
||||
ticker = template.receiveCurrency.toLowerCase();
|
||||
exchangeViewModel.receiveAddress =
|
||||
await applyUnstoppableDomainAddress(context, domain, ticker);
|
||||
await parseAddressFromDomain(context, domain, ticker);
|
||||
}
|
||||
|
||||
void _setReactions(
|
||||
|
@ -689,9 +689,9 @@ class ExchangePage extends BasePage {
|
|||
if (!_depositAddressFocus.hasFocus &&
|
||||
depositAddressController.text.isNotEmpty) {
|
||||
final domain = depositAddressController.text;
|
||||
final ticker = exchangeViewModel.depositCurrency.title;
|
||||
final ticker = exchangeViewModel.depositCurrency.title.toLowerCase();
|
||||
exchangeViewModel.depositAddress =
|
||||
await applyUnstoppableDomainAddress(context, domain, ticker);
|
||||
await parseAddressFromDomain(context, domain, ticker);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -699,9 +699,9 @@ class ExchangePage extends BasePage {
|
|||
if (!_receiveAddressFocus.hasFocus &&
|
||||
receiveAddressController.text.isNotEmpty) {
|
||||
final domain = receiveAddressController.text;
|
||||
final ticker = exchangeViewModel.receiveCurrency.title;
|
||||
final ticker = exchangeViewModel.receiveCurrency.title.toLowerCase();
|
||||
exchangeViewModel.receiveAddress =
|
||||
await applyUnstoppableDomainAddress(context, domain, ticker);
|
||||
await parseAddressFromDomain(context, domain, ticker);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -775,27 +775,4 @@ class ExchangePage extends BasePage {
|
|||
key.currentState.addressController.text = null;
|
||||
}
|
||||
}
|
||||
|
||||
Future<String> applyUnstoppableDomainAddress(BuildContext context,
|
||||
String domain, String ticker) async {
|
||||
const topLevelDomain = 'crypto';
|
||||
|
||||
if (domain.contains('.')) {
|
||||
final name = domain.split('.').last;
|
||||
if (name == topLevelDomain) {
|
||||
try {
|
||||
final address =
|
||||
await exchangeViewModel.getUnstoppableDomainAddress(domain, ticker);
|
||||
if ((address != null)&&address.isNotEmpty) {
|
||||
unstoppableDomainAddressAlert(context, domain);
|
||||
return address;
|
||||
}
|
||||
} catch (e) {
|
||||
print(e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return domain;
|
||||
}
|
||||
}
|
||||
|
|
53
lib/src/screens/send/parse_address_from_domain.dart
Normal file
53
lib/src/screens/send/parse_address_from_domain.dart
Normal file
|
@ -0,0 +1,53 @@
|
|||
import 'package:cake_wallet/entities/openalias_record.dart';
|
||||
import 'package:cake_wallet/entities/unstoppable_domain_address.dart';
|
||||
import 'package:cake_wallet/src/widgets/alert_with_one_action.dart';
|
||||
import 'package:cake_wallet/utils/show_pop_up.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:cake_wallet/generated/i18n.dart';
|
||||
|
||||
const topLevelDomain = 'crypto';
|
||||
|
||||
Future<String> parseAddressFromDomain(
|
||||
BuildContext context, String domain, String ticker) async {
|
||||
try {
|
||||
final name = domain.split('.').last;
|
||||
|
||||
if (name.contains(topLevelDomain)) {
|
||||
final address = await fetchUnstoppableDomainAddress(domain, ticker);
|
||||
if (address.isNotEmpty) {
|
||||
showAddressAlert(
|
||||
context,
|
||||
S.of(context).address_detected,
|
||||
S.of(context).address_from_domain(domain));
|
||||
return address;
|
||||
}
|
||||
} else if (name.isNotEmpty) {
|
||||
final record = await OpenaliasRecord.fetchAddressAndName(
|
||||
OpenaliasRecord.formatDomainName(domain));
|
||||
if (record.name != null && record.name != domain) {
|
||||
showAddressAlert(
|
||||
context,
|
||||
S.of(context).openalias_alert_title,
|
||||
S.of(context).openalias_alert_content(domain));
|
||||
return record.address;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
print(e.toString());
|
||||
}
|
||||
|
||||
return domain;
|
||||
}
|
||||
|
||||
void showAddressAlert(BuildContext context, String title, String content) async {
|
||||
await showPopUp<void>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
|
||||
return AlertWithOneAction(
|
||||
alertTitle: title,
|
||||
alertContent: content,
|
||||
buttonText: S.of(context).ok,
|
||||
buttonAction: () => Navigator.of(context).pop());
|
||||
});
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
import 'dart:ui';
|
||||
import 'package:cake_wallet/entities/transaction_priority.dart';
|
||||
import 'package:cake_wallet/src/screens/send/widgets/unstoppable_domain_address_alert.dart';
|
||||
import 'package:cake_wallet/src/screens/send/parse_address_from_domain.dart';
|
||||
import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart';
|
||||
import 'package:cake_wallet/src/widgets/keyboard_done_button.dart';
|
||||
import 'package:cake_wallet/src/widgets/picker.dart';
|
||||
|
@ -736,26 +736,6 @@ class SendPage extends BasePage {
|
|||
_effectsInstalled = true;
|
||||
}
|
||||
|
||||
Future<void> getOpenaliasRecord(BuildContext context) async {
|
||||
final record =
|
||||
await sendViewModel.decodeOpenaliasRecord(_addressController.text);
|
||||
|
||||
if (record != null) {
|
||||
_addressController.text = record.address;
|
||||
|
||||
await showPopUp<void>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertWithOneAction(
|
||||
alertTitle: S.of(context).openalias_alert_title,
|
||||
alertContent:
|
||||
S.of(context).openalias_alert_content(record.name),
|
||||
buttonText: S.of(context).ok,
|
||||
buttonAction: () => Navigator.of(context).pop());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _setTransactionPriority(BuildContext context) async {
|
||||
final items = priorityForWalletType(sendViewModel.walletType);
|
||||
final selectedItem = items.indexOf(sendViewModel.transactionPriority);
|
||||
|
@ -774,35 +754,10 @@ class SendPage extends BasePage {
|
|||
context: context);
|
||||
}
|
||||
|
||||
Future<void> getUnstoppableDomainAddress(BuildContext context) async {
|
||||
try {
|
||||
final address = await sendViewModel
|
||||
.getUnstoppableDomainAddress(
|
||||
_addressController.text);
|
||||
|
||||
if ((address != null)&&address.isNotEmpty) {
|
||||
unstoppableDomainAddressAlert(
|
||||
context, _addressController.text);
|
||||
_addressController.text = address;
|
||||
}
|
||||
} catch (e) {
|
||||
print(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
void applyOpenaliasOrUnstoppableDomains(BuildContext context) async {
|
||||
const topLevelDomain = 'crypto';
|
||||
final address = _addressController.text;
|
||||
|
||||
if (address.contains('.')) {
|
||||
final name = address.split('.').last;
|
||||
if (name.isNotEmpty) {
|
||||
if (name == topLevelDomain) {
|
||||
await getUnstoppableDomainAddress(context);
|
||||
} else {
|
||||
await getOpenaliasRecord(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
final domain = _addressController.text;
|
||||
final ticker = sendViewModel.currency.title.toLowerCase();
|
||||
_addressController.text =
|
||||
await parseAddressFromDomain(context, domain, ticker);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
import 'package:cake_wallet/src/widgets/alert_with_one_action.dart';
|
||||
import 'package:cake_wallet/utils/show_pop_up.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:cake_wallet/generated/i18n.dart';
|
||||
|
||||
void unstoppableDomainAddressAlert(BuildContext context, String domain) async {
|
||||
await showPopUp<void>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
|
||||
return AlertWithOneAction(
|
||||
alertTitle: S.of(context).address_detected,
|
||||
alertContent: S.of(context).address_from_domain(domain),
|
||||
buttonText: S.of(context).ok,
|
||||
buttonAction: () => Navigator.of(context).pop());
|
||||
});
|
||||
}
|
|
@ -4,7 +4,6 @@ import 'package:cake_wallet/bitcoin/bitcoin_wallet.dart';
|
|||
import 'package:cake_wallet/core/wallet_base.dart';
|
||||
import 'package:cake_wallet/entities/crypto_currency.dart';
|
||||
import 'package:cake_wallet/entities/sync_status.dart';
|
||||
import 'package:cake_wallet/entities/unstoppable_domain_address.dart';
|
||||
import 'package:cake_wallet/entities/wallet_type.dart';
|
||||
import 'package:cake_wallet/exchange/exchange_provider.dart';
|
||||
import 'package:cake_wallet/exchange/limits.dart';
|
||||
|
@ -423,8 +422,4 @@ abstract class ExchangeViewModelBase with Store {
|
|||
}*/
|
||||
isReceiveAmountEditable = false;
|
||||
}
|
||||
|
||||
Future<String> getUnstoppableDomainAddress(String domain, String ticker) async {
|
||||
return await fetchUnstoppableDomainAddress(domain, ticker.toLowerCase());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +1,14 @@
|
|||
import 'package:cake_wallet/bitcoin/bitcoin_amount_format.dart';
|
||||
import 'package:cake_wallet/bitcoin/bitcoin_transaction_priority.dart';
|
||||
import 'package:cake_wallet/bitcoin/electrum_wallet.dart';
|
||||
import 'package:cake_wallet/entities/balance_display_mode.dart';
|
||||
import 'package:cake_wallet/entities/calculate_fiat_amount_raw.dart';
|
||||
import 'package:cake_wallet/entities/transaction_description.dart';
|
||||
import 'package:cake_wallet/entities/transaction_priority.dart';
|
||||
import 'package:cake_wallet/entities/unstoppable_domain_address.dart';
|
||||
import 'package:cake_wallet/monero/monero_amount_format.dart';
|
||||
import 'package:cake_wallet/view_model/settings/settings_view_model.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
import 'package:cake_wallet/entities/openalias_record.dart';
|
||||
import 'package:cake_wallet/entities/template.dart';
|
||||
import 'package:cake_wallet/store/templates/send_template_store.dart';
|
||||
import 'package:cake_wallet/core/template_validator.dart';
|
||||
|
@ -21,7 +18,6 @@ import 'package:cake_wallet/core/pending_transaction.dart';
|
|||
import 'package:cake_wallet/core/validator.dart';
|
||||
import 'package:cake_wallet/core/wallet_base.dart';
|
||||
import 'package:cake_wallet/core/execution_state.dart';
|
||||
import 'package:cake_wallet/bitcoin/bitcoin_wallet.dart';
|
||||
import 'package:cake_wallet/bitcoin/bitcoin_transaction_credentials.dart';
|
||||
import 'package:cake_wallet/monero/monero_wallet.dart';
|
||||
import 'package:cake_wallet/monero/monero_transaction_creation_credentials.dart';
|
||||
|
@ -265,17 +261,6 @@ abstract class SendViewModelBase with Store {
|
|||
void setTransactionPriority(TransactionPriority priority) =>
|
||||
_settingsStore.priority[_wallet.type] = priority;
|
||||
|
||||
Future<OpenaliasRecord> decodeOpenaliasRecord(String name) async {
|
||||
final record = await OpenaliasRecord.fetchAddressAndName(
|
||||
OpenaliasRecord.formatDomainName(name));
|
||||
|
||||
return record.name != name ? record : null;
|
||||
}
|
||||
|
||||
Future<String> getUnstoppableDomainAddress(String domain) async {
|
||||
return await fetchUnstoppableDomainAddress(domain, currency.title.toLowerCase());
|
||||
}
|
||||
|
||||
@action
|
||||
void _updateFiatAmount() {
|
||||
try {
|
||||
|
|
|
@ -482,9 +482,9 @@
|
|||
"buy_with" : "一起购买",
|
||||
"moonpay_alert_text" : "金额的价值必须大于或等于 ${minAmount} ${fiatCurrency}",
|
||||
|
||||
"address_detected" : "檢測到地址",
|
||||
"address_from_domain" : "您有以下地址 unstoppable domain ${domain}",
|
||||
|
||||
"outdated_electrum_wallet_receive_warning": "如果这个钱包有一个 12 字的种子并且是在 Cake 中创建的,不要将比特币存入这个钱包。 任何转移到此钱包的 BTC 都可能丢失。 创建一个新的 24 字钱包(点击右上角的菜单,选择钱包,选择创建新钱包,然后选择比特币)并立即将您的 BTC 移到那里。 Cake 的新(24 字)BTC 钱包是安全的",
|
||||
"do_not_show_me": "不再提示"
|
||||
"do_not_show_me": "不再提示",
|
||||
|
||||
"address_detected" : "檢測到地址",
|
||||
"address_from_domain" : "您有以下地址 unstoppable domain ${domain}"
|
||||
}
|
Loading…
Reference in a new issue