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

This commit is contained in:
Oleksandr Sobol
2020-02-19 22:14:39 +02:00
parent fb10f17622
commit df9418c799
5 changed files with 48 additions and 4 deletions
+33
View File
@@ -0,0 +1,33 @@
import 'package:basic_utils/basic_utils.dart';
String formatDomainName(String name) {
if (!name.contains(".")) {
return "";
}
return name.replaceAll("@", ".");
}
Future<String> fetchXmrAddress(String name) async {
String xmrAddress = "";
await DnsUtils.lookupRecord(name, RRecordType.TXT, dnssec: true).then((txtRecord) {
if (txtRecord != null) {
String record;
for (int i = 0; i < txtRecord.length; i++) {
record = txtRecord[i].data;
if (record.contains("oa1:xmr") && record.contains("recipient_address")) {
record = record.replaceAll('\"', "");
xmrAddress = record.split(" ").where((item) => (item.contains("recipient_address")))
.toString().replaceAll("recipient_address=", "").replaceAll("\;", "")
.replaceAll("(", "").replaceAll(")", "");
break;
}
}
}
});
return xmrAddress;
}
+7
View File
@@ -22,6 +22,7 @@ import 'package:cake_wallet/src/domain/common/calculate_estimated_fee.dart';
import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/src/domain/common/sync_status.dart';
import 'package:cake_wallet/src/stores/sync/sync_store.dart';
import 'package:cake_wallet/src/domain/common/openalias.dart';
class SendPage extends BasePage {
@override
@@ -358,6 +359,12 @@ class SendFormState extends State<SendForm> {
// Hack. Don't ask me.
FocusScope.of(context).requestFocus(FocusNode());
final domainName = formatDomainName(_addressController.text);
if (domainName != "") {
await fetchXmrAddress(domainName).then((address) => _addressController.text = address);
}
if (_formKey.currentState.validate()) {
await showDialog<void>(
context: context,