diff --git a/lib/entities/openalias_record.dart b/lib/entities/openalias_record.dart index cb659d533..073f5dbe9 100644 --- a/lib/entities/openalias_record.dart +++ b/lib/entities/openalias_record.dart @@ -1,7 +1,8 @@ import 'package:basic_utils/basic_utils.dart'; +import 'package:cw_core/wallet_type.dart'; +import 'package:flutter/material.dart'; class OpenaliasRecord { - OpenaliasRecord({this.address, this.name}); final String name; @@ -17,30 +18,43 @@ class OpenaliasRecord { return formattedName; } - static Future fetchAddressAndName(String formattedName) async { + static Future fetchAddressAndName({ + @required String formattedName, + @required String ticker, + }) async { String address = formattedName; String name = formattedName; if (formattedName.contains(".")) { try { - final txtRecord = await DnsUtils.lookupRecord(formattedName, RRecordType.TXT, dnssec: true); + final txtRecord = await DnsUtils.lookupRecord( + formattedName, 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")) { + if (record.contains("oa1:$ticker") && + 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(); + address = dataList + .where((item) => (item.contains("recipient_address"))) + .toString() + .replaceAll("oa1:$ticker 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) { name = recipientName.replaceAll("recipient_name=", ""); @@ -57,6 +71,4 @@ class OpenaliasRecord { return OpenaliasRecord(address: address, name: name); } - } - diff --git a/lib/entities/parse_address_from_domain.dart b/lib/entities/parse_address_from_domain.dart index 851251df6..13fa6a0ed 100644 --- a/lib/entities/parse_address_from_domain.dart +++ b/lib/entities/parse_address_from_domain.dart @@ -2,18 +2,20 @@ import 'package:cake_wallet/entities/openalias_record.dart'; import 'package:cake_wallet/entities/parsed_address.dart'; import 'package:cake_wallet/entities/unstoppable_domain_address.dart'; import 'package:cake_wallet/store/yat/yat_store.dart'; +import 'package:cw_core/wallet_type.dart'; const unstoppableDomains = [ - 'crypto', - 'zil', - 'x', - 'coin', - 'wallet', - 'bitcoin', - '888', - 'nft', - 'dao', - 'blockchain']; + 'crypto', + 'zil', + 'x', + 'coin', + 'wallet', + 'bitcoin', + '888', + 'nft', + 'dao', + 'blockchain' +]; Future parseAddressFromDomain( String domain, String ticker) async { @@ -28,22 +30,18 @@ Future parseAddressFromDomain( if (addresses?.isEmpty ?? true) { return ParsedAddress( - addresses: [domain], - parseFrom: ParseFrom.yatRecord); + addresses: [domain], parseFrom: ParseFrom.yatRecord); } return ParsedAddress( - addresses: addresses, - name: domain, - parseFrom: ParseFrom.yatRecord); + addresses: addresses, name: domain, parseFrom: ParseFrom.yatRecord); } catch (e) { return ParsedAddress(addresses: [domain]); } } if (unstoppableDomains.any((domain) => name.contains(domain))) { - final address = - await fetchUnstoppableDomainAddress(domain, ticker); + final address = await fetchUnstoppableDomainAddress(domain, ticker); if (address?.isEmpty ?? true) { return ParsedAddress(addresses: [domain]); @@ -55,7 +53,8 @@ Future parseAddressFromDomain( parseFrom: ParseFrom.unstoppableDomains); } - final record = await OpenaliasRecord.fetchAddressAndName(formattedName); + final record = await OpenaliasRecord.fetchAddressAndName( + formattedName: formattedName, ticker: ticker); if (record == null || record.address.contains(formattedName)) { return ParsedAddress(addresses: [domain]); @@ -70,4 +69,4 @@ Future parseAddressFromDomain( } return ParsedAddress(addresses: [domain]); -} \ No newline at end of file +}