diff --git a/lib/src/domain/common/openalias_record.dart b/lib/src/domain/common/openalias_record.dart index dffc8487a..cb659d533 100644 --- a/lib/src/domain/common/openalias_record.dart +++ b/lib/src/domain/common/openalias_record.dart @@ -2,15 +2,12 @@ import 'package:basic_utils/basic_utils.dart'; class OpenaliasRecord { - OpenaliasRecord({this.name}); + OpenaliasRecord({this.address, this.name}); - String name; - String address; + final String name; + final String address; - String get recordName => name; - String get recordAddress => address; - - String formatDomainName() { + static String formatDomainName(String name) { String formattedName = name; if (name.contains("@")) { @@ -20,41 +17,45 @@ class OpenaliasRecord { return formattedName; } - Future fetchAddressAndName(String name) async { - this.name = name; - address = name; + static Future fetchAddressAndName(String formattedName) async { + String address = formattedName; + String name = formattedName; - try { - final txtRecord = await DnsUtils.lookupRecord(name, RRecordType.TXT, dnssec: true); + if (formattedName.contains(".")) { + try { + final txtRecord = await DnsUtils.lookupRecord(formattedName, RRecordType.TXT, dnssec: true); - if (txtRecord != null) { + if (txtRecord != null) { - for (RRecord element in txtRecord) { - String record = element.data; + for (RRecord element in txtRecord) { + String record = element.data; - if (record.contains("oa1:xmr") && record.contains("recipient_address")) { - record = record.replaceAll('\"', ""); + if (record.contains("oa1:xmr") && record.contains("recipient_address")) { + record = record.replaceAll('\"', ""); - final dataList = record.split(";"); + final dataList = record.split(";"); - address = dataList.where((item) => (item.contains("recipient_address"))) - .toString().replaceAll("oa1:xmr recipient_address=", "") - .replaceAll("(", "").replaceAll(")", "").trim(); + address = dataList.where((item) => (item.contains("recipient_address"))) + .toString().replaceAll("oa1:xmr recipient_address=", "") + .replaceAll("(", "").replaceAll(")", "").trim(); - final recipientName = dataList.where((item) => (item.contains("recipient_name"))).toString() - .replaceAll("(", "").replaceAll(")", "").trim(); + final recipientName = dataList.where((item) => (item.contains("recipient_name"))).toString() + .replaceAll("(", "").replaceAll(")", "").trim(); - if (recipientName.isNotEmpty) { - this.name = recipientName.replaceAll("recipient_name=", ""); + if (recipientName.isNotEmpty) { + name = recipientName.replaceAll("recipient_name=", ""); + } + + break; } - - break; } } + } catch (e) { + print("${e.toString()}"); } - } catch (e) { - print("${e.toString()}"); } + + return OpenaliasRecord(address: address, name: name); } } diff --git a/lib/src/screens/send/send_page.dart b/lib/src/screens/send/send_page.dart index a77498648..07394e97d 100644 --- a/lib/src/screens/send/send_page.dart +++ b/lib/src/screens/send/send_page.dart @@ -65,7 +65,7 @@ class SendFormState extends State { super.initState(); } - void getOpenaliasRecord(BuildContext context) async { + Future getOpenaliasRecord(BuildContext context) async { final sendStore = Provider.of(context); final isOpenalias = await sendStore.isOpenaliasRecord(_addressController.text); diff --git a/lib/src/stores/send/send_store.dart b/lib/src/stores/send/send_store.dart index 5f6bd415a..5f0df3541 100644 --- a/lib/src/stores/send/send_store.dart +++ b/lib/src/stores/send/send_store.dart @@ -56,7 +56,6 @@ abstract class SendStoreBase with Store { NumberFormat _cryptoNumberFormat; NumberFormat _fiatNumberFormat; String _lastRecipientAddress; - OpenaliasRecord _openaliasRecord; @action Future createTransaction( @@ -159,11 +158,11 @@ abstract class SendStoreBase with Store { } Future isOpenaliasRecord(String name) async { - _openaliasRecord = OpenaliasRecord(name: name); - await _openaliasRecord.fetchAddressAndName(_openaliasRecord.formatDomainName()); + final _openaliasRecord = await OpenaliasRecord + .fetchAddressAndName(OpenaliasRecord.formatDomainName(name)); - recordAddress = _openaliasRecord.recordAddress; - recordName = _openaliasRecord.recordName; + recordAddress = _openaliasRecord.address; + recordName = _openaliasRecord.name; return recordAddress != name; }