2022-03-15 09:11:53 +00:00
|
|
|
import 'package:cake_wallet/core/yat_service.dart';
|
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';
|
2022-03-15 09:11:53 +00:00
|
|
|
import 'package:cake_wallet/entities/emoji_string_extension.dart';
|
2022-06-28 15:46:32 +00:00
|
|
|
import 'package:cw_core/wallet_type.dart';
|
2022-03-15 09:11:53 +00:00
|
|
|
import 'package:flutter/foundation.dart';
|
2022-06-13 11:41:46 +00:00
|
|
|
import 'package:cake_wallet/entities/fio_address_provider.dart';
|
2022-03-15 09:11:53 +00:00
|
|
|
|
|
|
|
class AddressResolver {
|
|
|
|
|
2022-10-12 17:09:57 +00:00
|
|
|
AddressResolver({required this.yatService, required this.walletType});
|
2022-03-15 09:11:53 +00:00
|
|
|
|
|
|
|
final YatService yatService;
|
2022-06-28 15:46:32 +00:00
|
|
|
final WalletType walletType;
|
2022-03-15 09:11:53 +00:00
|
|
|
|
|
|
|
static const unstoppableDomains = [
|
2022-01-14 13:18:03 +00:00
|
|
|
'crypto',
|
|
|
|
'zil',
|
|
|
|
'x',
|
|
|
|
'coin',
|
|
|
|
'wallet',
|
|
|
|
'bitcoin',
|
|
|
|
'888',
|
|
|
|
'nft',
|
|
|
|
'dao',
|
|
|
|
'blockchain'
|
|
|
|
];
|
2021-07-07 13:50:55 +00:00
|
|
|
|
2022-03-15 09:11:53 +00:00
|
|
|
Future<ParsedAddress> resolve(String text, String ticker) async {
|
|
|
|
try {
|
2022-06-13 11:41:46 +00:00
|
|
|
if (text.contains('@') && !text.contains('.')) {
|
|
|
|
final bool isFioRegistered = await FioAddressProvider.checkAvail(text);
|
|
|
|
if (isFioRegistered) {
|
|
|
|
final address = await FioAddressProvider.getPubAddress(text, ticker);
|
|
|
|
return ParsedAddress.fetchFioAddress(address: address, name: text);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2022-03-15 09:11:53 +00:00
|
|
|
if (text.hasOnlyEmojis) {
|
2022-06-28 15:46:32 +00:00
|
|
|
if (walletType != WalletType.haven) {
|
|
|
|
final addresses = await yatService.fetchYatAddress(text, ticker);
|
|
|
|
return ParsedAddress.fetchEmojiAddress(addresses: addresses, name: text);
|
|
|
|
}
|
2021-08-27 17:46:24 +00:00
|
|
|
}
|
2022-03-15 09:11:53 +00:00
|
|
|
final formattedName = OpenaliasRecord.formatDomainName(text);
|
|
|
|
final domainParts = formattedName.split('.');
|
|
|
|
final name = domainParts.last;
|
2021-07-07 13:50:55 +00:00
|
|
|
|
2022-03-15 09:11:53 +00:00
|
|
|
if (domainParts.length <= 1 || domainParts.first.isEmpty || name.isEmpty) {
|
|
|
|
return ParsedAddress(addresses: [text]);
|
2021-07-07 13:50:55 +00:00
|
|
|
}
|
|
|
|
|
2022-03-15 09:11:53 +00:00
|
|
|
if (unstoppableDomains.any((domain) => name.contains(domain))) {
|
|
|
|
final address = await fetchUnstoppableDomainAddress(text, ticker);
|
|
|
|
return ParsedAddress.fetchUnstoppableDomainAddress(address: address, name: text);
|
|
|
|
}
|
2021-07-07 13:50:55 +00:00
|
|
|
|
2022-03-15 09:11:53 +00:00
|
|
|
final record = await OpenaliasRecord.fetchAddressAndName(
|
|
|
|
formattedName: formattedName, ticker: ticker);
|
|
|
|
return ParsedAddress.fetchOpenAliasAddress(record: record, name: text);
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
print(e.toString());
|
2021-07-07 13:50:55 +00:00
|
|
|
}
|
|
|
|
|
2022-03-15 09:11:53 +00:00
|
|
|
return ParsedAddress(addresses: [text]);
|
2021-07-07 13:50:55 +00:00
|
|
|
}
|
2022-01-14 13:18:03 +00:00
|
|
|
}
|