CWA-69 | created formatDomainName() and fetchXmrAddress() in the openalias.dart. Added openalias to send page

Oleksandr Sobol committed Feb 19, 2020 at 22:14 UTC df9418c7999a817eb9c551fb081e35fd8970fd11
5 files changed +48 -4
lib/src/domain/common/openalias.dart new
+33
@@ -0,0 +1,33 @@
1 +import 'package:basic_utils/basic_utils.dart';
2 +
3 +String formatDomainName(String name) {
4 + if (!name.contains(".")) {
5 + return "";
6 + }
7 +
8 + return name.replaceAll("@", ".");
9 +}
10 +
11 +Future<String> fetchXmrAddress(String name) async {
12 + String xmrAddress = "";
13 +
14 + await DnsUtils.lookupRecord(name, RRecordType.TXT, dnssec: true).then((txtRecord) {
15 + if (txtRecord != null) {
16 + String record;
17 +
18 + for (int i = 0; i < txtRecord.length; i++) {
19 + record = txtRecord[i].data;
20 +
21 + if (record.contains("oa1:xmr") && record.contains("recipient_address")) {
22 + record = record.replaceAll('\"', "");
23 + xmrAddress = record.split(" ").where((item) => (item.contains("recipient_address")))
24 + .toString().replaceAll("recipient_address=", "").replaceAll("\;", "")
25 + .replaceAll("(", "").replaceAll(")", "");
26 + break;
27 + }
28 + }
29 + }
30 + });
31 +
32 + return xmrAddress;
33 +}
\ No newline at end of file
lib/src/screens/send/send_page.dart
+7
@@ -22,6 +22,7 @@ import 'package:cake_wallet/src/domain/common/calculate_estimated_fee.dart';
22 import 'package:cake_wallet/generated/i18n.dart';
23 import 'package:cake_wallet/src/domain/common/sync_status.dart';
24 import 'package:cake_wallet/src/stores/sync/sync_store.dart';
25 +import 'package:cake_wallet/src/domain/common/openalias.dart';
26
27 class SendPage extends BasePage {
28 @override
@@ -358,6 +359,12 @@ class SendFormState extends State<SendForm> {
359 // Hack. Don't ask me.
360 FocusScope.of(context).requestFocus(FocusNode());
361
362 + final domainName = formatDomainName(_addressController.text);
363 +
364 + if (domainName != "") {
365 + await fetchXmrAddress(domainName).then((address) => _addressController.text = address);
366 + }
367 +
368 if (_formKey.currentState.validate()) {
369 await showDialog<void>(
370 context: context,
pubspec.lock
+7
@@ -43,6 +43,13 @@ packages:
43 url: "https://pub.dartlang.org"
44 source: hosted
45 version: "1.0.0"
46 + basic_utils:
47 + dependency: "direct main"
48 + description:
49 + name: basic_utils
50 + url: "https://pub.dartlang.org"
51 + source: hosted
52 + version: "1.9.3"
53 boolean_selector:
54 dependency: transitive
55 description:
pubspec.yaml
+1
@@ -53,6 +53,7 @@ dependencies:
53 cupertino_icons: ^0.1.2
54 encrypt: ^4.0.0
55 password: ^1.0.0
56 + basic_utils: ^1.0.8
57
58 dev_dependencies:
59 flutter_test:
res/values/strings_ko.arb
-4
@@ -342,9 +342,5 @@
342 "incorrect_seed" : "입력하신 텍스트가 유효하지 않습니다.",
343
344 "biometric_auth_reason" : "지문을 스캔하여 인증",
345 -<<<<<<< HEAD
346 -=======
347 -
348 ->>>>>>> 4848485be8cbc34cbec847abbb76dabd075841ae
345 "version" : "버전 ${currentVersion}"
346 }
\ No newline at end of file