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-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-07-16 10:28:46 +00:00
|
|
|
return ParsedAddress(address: domain);
|
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-07-16 10:28:46 +00:00
|
|
|
return ParsedAddress(address: domain);
|
2021-07-07 13:50:55 +00:00
|
|
|
}
|
|
|
|
|
2021-07-16 10:28:46 +00:00
|
|
|
return ParsedAddress(
|
|
|
|
address: 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)) {
|
|
|
|
return ParsedAddress(address: domain);
|
2021-07-07 13:50:55 +00:00
|
|
|
}
|
|
|
|
|
2021-07-16 10:28:46 +00:00
|
|
|
return ParsedAddress(
|
|
|
|
address: record.address,
|
|
|
|
name: record.name,
|
|
|
|
parseFrom: ParseFrom.openAlias);
|
2021-07-07 13:50:55 +00:00
|
|
|
} catch (e) {
|
|
|
|
print(e.toString());
|
|
|
|
}
|
|
|
|
|
2021-07-16 10:28:46 +00:00
|
|
|
return ParsedAddress(address: domain);
|
2021-07-07 13:50:55 +00:00
|
|
|
}
|