mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-11-21 10:24:15 +01:00
CWA-173 | created OpenaliasRecord class, renamed fetchXmrAddressAndRecipientName method on fetchAddressAndName, used forEach instead of for loop in this method, checked entered xmr address in the send store
This commit is contained in:
@@ -1,50 +0,0 @@
|
||||
import 'package:basic_utils/basic_utils.dart';
|
||||
|
||||
String formatDomainName(String name) {
|
||||
String formattedName = name;
|
||||
|
||||
if (name.contains(".")) {
|
||||
formattedName = name.replaceAll("@", ".");
|
||||
}
|
||||
|
||||
return formattedName;
|
||||
}
|
||||
|
||||
Future<Map<String, String>> fetchXmrAddressAndRecipientName(String name) async {
|
||||
final map = {"recipient_address" : name, "recipient_name" : name};
|
||||
|
||||
try {
|
||||
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('\"', "");
|
||||
|
||||
final dataList = record.split(";");
|
||||
|
||||
map["recipient_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();
|
||||
|
||||
if (recipientName.isNotEmpty) {
|
||||
map["recipient_name"] = recipientName.replaceAll("recipient_name=", "");
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
print("${e.toString()}");
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
import 'package:basic_utils/basic_utils.dart';
|
||||
|
||||
class OpenaliasRecord {
|
||||
|
||||
OpenaliasRecord({this.name});
|
||||
|
||||
String name;
|
||||
String address;
|
||||
|
||||
String get recordName => name;
|
||||
String get recordAddress => address;
|
||||
|
||||
String formatDomainName() {
|
||||
String formattedName = name;
|
||||
|
||||
if (name.contains("@")) {
|
||||
formattedName = name.replaceAll("@", ".");
|
||||
}
|
||||
|
||||
return formattedName;
|
||||
}
|
||||
|
||||
Future<void> fetchAddressAndName(String name) async {
|
||||
this.name = name;
|
||||
address = name;
|
||||
|
||||
try {
|
||||
final txtRecord = await DnsUtils.lookupRecord(name, RRecordType.TXT, dnssec: true);
|
||||
|
||||
if (txtRecord != null) {
|
||||
|
||||
for (RRecord element in txtRecord) {
|
||||
String record = element.data;
|
||||
|
||||
if (record.contains("oa1:xmr") && record.contains("recipient_address")) {
|
||||
record = record.replaceAll('\"', "");
|
||||
|
||||
final dataList = record.split(";");
|
||||
|
||||
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();
|
||||
|
||||
if (recipientName.isNotEmpty) {
|
||||
this.name = recipientName.replaceAll("recipient_name=", "");
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
print("${e.toString()}");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user