CWA-69 | added focusNode to address_text_field, got recipient name in the openalias, added focusNode listener in the send_page
Oleksandr Sobol committed
Feb 20, 2020 at 22:50 UTC
91091a8d19c3ac7a4dfb21a87c19ec3d68c3f8e4
3 files changed
+58
-15
lib/src/domain/common/openalias.dart
+22
-9
@@ -1,15 +1,17 @@
1
import 'package:basic_utils/basic_utils.dart';
2
3
String formatDomainName(String name) {
4
- if (!name.contains(".")) {
5
- return "";
4
+ String formattedName = name;
5
+
6
+ if (name.contains(".")) {
7
+ formattedName = name.replaceAll("@", ".");
8
}
9
8
- return name.replaceAll("@", ".");
10
+ return formattedName;
11
}
12
11
-Future<String> fetchXmrAddress(String name) async {
12
- String xmrAddress = "";
13
+Future<Map<String, String>> fetchXmrAddressAndRecipientName(String name) async {
14
+ final map = {"recipient_address" : name, "recipient_name" : name};
15
16
await DnsUtils.lookupRecord(name, RRecordType.TXT, dnssec: true).then((txtRecord) {
17
if (txtRecord != null) {
@@ -20,14 +22,25 @@ Future<String> fetchXmrAddress(String name) async {
22
23
if (record.contains("oa1:xmr") && record.contains("recipient_address")) {
24
record = record.replaceAll('\"', "");
23
- xmrAddress = record.split(" ").where((item) => (item.contains("recipient_address")))
24
- .toString().replaceAll("recipient_address=", "").replaceAll("\;", "")
25
- .replaceAll("(", "").replaceAll(")", "");
25
+
26
+ final dataList = record.split(";");
27
+
28
+ map["recipient_address"] = dataList.where((item) => (item.contains("recipient_address")))
29
+ .toString().replaceAll("oa1:xmr recipient_address=", "")
30
+ .replaceAll("(", "").replaceAll(")", "").trim();
31
+
32
+ final recipientName = dataList.where((item) => (item.contains("recipient_name"))).toString();
33
+
34
+ if (recipientName.isNotEmpty) {
35
+ map["recipient_name"] = recipientName.replaceAll("recipient_name=", "")
36
+ .replaceAll("(", "").replaceAll(")", "").trim();
37
+ }
38
+
39
break;
40
}
41
}
42
}
43
});
44
32
- return xmrAddress;
45
+ return map;
46
}
\ No newline at end of file
lib/src/screens/send/send_page.dart
+33
-6
@@ -49,10 +49,42 @@ class SendFormState extends State<SendForm> {
49
final _cryptoAmountController = TextEditingController();
50
final _fiatAmountController = TextEditingController();
51
52
+ final _focusNode = FocusNode();
53
+
54
bool _effectsInstalled = false;
55
56
final _formKey = GlobalKey<FormState>();
57
58
+ @override
59
+ void initState() {
60
+ _focusNode.addListener(() async {
61
+ if (_addressController.text.isNotEmpty) {
62
+ await fetchXmrAddressAndRecipientName(formatDomainName(_addressController.text)).then((map) async {
63
+
64
+ if (_addressController.text != map["recipient_address"]) {
65
+ _addressController.text = map["recipient_address"];
66
+
67
+ await showDialog<void>(
68
+ context: context,
69
+ builder: (BuildContext context) {
70
+ return AlertDialog(
71
+ title: Text("XMR Recipient Detected"),
72
+ content: Text("You will be sending funds to\n${map["recipient_name"]}"),
73
+ actions: <Widget>[
74
+ FlatButton(
75
+ child: Text(S.of(context).ok),
76
+ onPressed: () => Navigator.of(context).pop())
77
+ ],
78
+ );
79
+ });
80
+ }
81
+ });
82
+ }
83
+ });
84
+
85
+ super.initState();
86
+ }
87
+
88
@override
89
Widget build(BuildContext context) {
90
final settingsStore = Provider.of<SettingsStore>(context);
@@ -151,6 +183,7 @@ class SendFormState extends State<SendForm> {
183
AddressTextField(
184
controller: _addressController,
185
placeholder: S.of(context).send_monero_address,
186
+ focusNode: _focusNode,
187
onURIScanned: (uri) {
188
var address = '';
189
var amount = '';
@@ -359,12 +392,6 @@ class SendFormState extends State<SendForm> {
392
// Hack. Don't ask me.
393
FocusScope.of(context).requestFocus(FocusNode());
394
362
- final domainName = formatDomainName(_addressController.text);
363
-
364
- if (domainName != "") {
365
- await fetchXmrAddress(domainName).then((address) => _addressController.text = address);
366
- }
367
-
395
if (_formKey.currentState.validate()) {
396
await showDialog<void>(
397
context: context,
lib/src/widgets/address_text_field.dart
+3
@@ -18,6 +18,7 @@ class AddressTextField extends StatelessWidget {
18
AddressTextFieldOption.addressBook
19
],
20
this.onURIScanned,
21
+ this.focusNode,
22
this.validator});
23
24
static const prefixIconWidth = 34.0;
@@ -30,6 +31,7 @@ class AddressTextField extends StatelessWidget {
31
final Function(Uri) onURIScanned;
32
final List<AddressTextFieldOption> options;
33
final FormFieldValidator<String> validator;
34
+ FocusNode focusNode;
35
36
@override
37
Widget build(BuildContext context) {
@@ -37,6 +39,7 @@ class AddressTextField extends StatelessWidget {
39
onFieldSubmitted: (_) => FocusScope.of(context).unfocus(),
40
enabled: isActive,
41
controller: controller,
42
+ focusNode: focusNode,
43
decoration: InputDecoration(
44
suffixIcon: SizedBox(
45
width: prefixIconWidth * options.length +