mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-18 05:51:34 +02: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:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user