2021-07-07 13:50:55 +00:00
|
|
|
import 'package:cake_wallet/entities/openalias_record.dart';
|
2021-07-07 14:31:16 +00:00
|
|
|
import 'package:cake_wallet/entities/parsed_address.dart';
|
2021-07-07 13:50:55 +00:00
|
|
|
import 'package:cake_wallet/entities/unstoppable_domain_address.dart';
|
2021-10-01 15:13:10 +00:00
|
|
|
import 'package:cake_wallet/store/yat/yat_store.dart';
|
2021-07-07 13:50:55 +00:00
|
|
|
|
2021-08-16 09:42:16 +00:00
|
|
|
const unstoppableDomains = [
|
|
|
|
'crypto',
|
|
|
|
'zil',
|
|
|
|
'x',
|
|
|
|
'coin',
|
|
|
|
'wallet',
|
|
|
|
'bitcoin',
|
|
|
|
'888',
|
|
|
|
'nft',
|
|
|
|
'dao',
|
|
|
|
'blockchain'];
|
2021-07-07 13:50:55 +00:00
|
|
|
|
2021-07-07 14:31:16 +00:00
|
|
|
Future<ParsedAddress> parseAddressFromDomain(
|
|
|
|
String domain, String ticker) async {
|
2021-07-07 13:50:55 +00:00
|
|
|
try {
|
2021-07-16 10:28:46 +00:00
|
|
|
final formattedName = OpenaliasRecord.formatDomainName(domain);
|
|
|
|
final domainParts = formattedName.split('.');
|
2021-07-07 13:50:55 +00:00
|
|
|
final name = domainParts.last;
|
|
|
|
|
|
|
|
if (domainParts.length <= 1 || domainParts.first.isEmpty || name.isEmpty) {
|
2021-08-27 17:46:24 +00:00
|
|
|
try {
|
2021-09-20 14:56:27 +00:00
|
|
|
final addresses = await fetchYatAddress(domain, ticker);
|
2021-08-27 17:46:24 +00:00
|
|
|
|
2021-09-20 14:56:27 +00:00
|
|
|
if (addresses?.isEmpty ?? true) {
|
|
|
|
return ParsedAddress(
|
|
|
|
addresses: [domain],
|
|
|
|
parseFrom: ParseFrom.yatRecord);
|
2021-08-27 17:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ParsedAddress(
|
2021-09-20 14:56:27 +00:00
|
|
|
addresses: addresses,
|
2021-08-27 17:46:24 +00:00
|
|
|
name: domain,
|
|
|
|
parseFrom: ParseFrom.yatRecord);
|
|
|
|
} catch (e) {
|
2021-09-20 14:56:27 +00:00
|
|
|
return ParsedAddress(addresses: [domain]);
|
2021-08-27 17:46:24 +00:00
|
|
|
}
|
2021-07-07 13:50:55 +00:00
|
|
|
}
|
|
|
|
|
2021-08-16 09:42:16 +00:00
|
|
|
if (unstoppableDomains.any((domain) => name.contains(domain))) {
|
2021-07-16 10:28:46 +00:00
|
|
|
final address =
|
2021-07-16 10:44:12 +00:00
|
|
|
await fetchUnstoppableDomainAddress(domain, ticker);
|
2021-07-07 13:50:55 +00:00
|
|
|
|
|
|
|
if (address?.isEmpty ?? true) {
|
2021-09-20 14:56:27 +00:00
|
|
|
return ParsedAddress(addresses: [domain]);
|
2021-07-07 13:50:55 +00:00
|
|
|
}
|
|
|
|
|
2021-07-16 10:28:46 +00:00
|
|
|
return ParsedAddress(
|
2021-09-20 14:56:27 +00:00
|
|
|
addresses: [address],
|
2021-07-16 10:44:12 +00:00
|
|
|
name: domain,
|
2021-07-16 10:28:46 +00:00
|
|
|
parseFrom: ParseFrom.unstoppableDomains);
|
2021-07-07 13:50:55 +00:00
|
|
|
}
|
|
|
|
|
2021-07-16 10:28:46 +00:00
|
|
|
final record = await OpenaliasRecord.fetchAddressAndName(formattedName);
|
2021-07-07 13:50:55 +00:00
|
|
|
|
2021-07-16 10:28:46 +00:00
|
|
|
if (record == null || record.address.contains(formattedName)) {
|
2021-09-20 14:56:27 +00:00
|
|
|
return ParsedAddress(addresses: [domain]);
|
2021-07-07 13:50:55 +00:00
|
|
|
}
|
|
|
|
|
2021-07-16 10:28:46 +00:00
|
|
|
return ParsedAddress(
|
2021-09-20 14:56:27 +00:00
|
|
|
addresses: [record.address],
|
2021-07-16 10:28:46 +00:00
|
|
|
name: record.name,
|
|
|
|
parseFrom: ParseFrom.openAlias);
|
2021-07-07 13:50:55 +00:00
|
|
|
} catch (e) {
|
|
|
|
print(e.toString());
|
|
|
|
}
|
|
|
|
|
2021-09-20 14:56:27 +00:00
|
|
|
return ParsedAddress(addresses: [domain]);
|
2021-07-07 13:50:55 +00:00
|
|
|
}
|