2022-03-15 09:11:53 +00:00
|
|
|
import 'package:cake_wallet/entities/openalias_record.dart';
|
|
|
|
import 'package:cake_wallet/entities/yat_record.dart';
|
|
|
|
|
2024-01-27 02:34:38 +00:00
|
|
|
enum ParseFrom {
|
|
|
|
unstoppableDomains,
|
|
|
|
openAlias,
|
|
|
|
yatRecord,
|
|
|
|
fio,
|
|
|
|
notParsed,
|
|
|
|
twitter,
|
|
|
|
ens,
|
|
|
|
contact,
|
|
|
|
mastodon,
|
2024-05-06 19:16:25 +00:00
|
|
|
nostr,
|
|
|
|
thorChain
|
2024-01-27 02:34:38 +00:00
|
|
|
}
|
2021-07-07 14:31:16 +00:00
|
|
|
|
|
|
|
class ParsedAddress {
|
2021-07-16 10:28:46 +00:00
|
|
|
ParsedAddress({
|
2022-10-12 17:09:57 +00:00
|
|
|
required this.addresses,
|
2021-07-16 10:28:46 +00:00
|
|
|
this.name = '',
|
2022-01-18 07:46:13 +00:00
|
|
|
this.description = '',
|
2024-03-01 19:38:48 +00:00
|
|
|
this.profileImageUrl = '',
|
|
|
|
this.profileName = '',
|
2022-01-18 07:46:13 +00:00
|
|
|
this.parseFrom = ParseFrom.notParsed,
|
|
|
|
});
|
2024-01-27 02:34:38 +00:00
|
|
|
|
2022-03-15 09:11:53 +00:00
|
|
|
factory ParsedAddress.fetchEmojiAddress({
|
2024-01-27 02:34:38 +00:00
|
|
|
List<YatRecord>? addresses,
|
2022-10-12 17:09:57 +00:00
|
|
|
required String name,
|
2024-03-01 19:38:48 +00:00
|
|
|
}) {
|
|
|
|
if (addresses?.isEmpty ?? true) {
|
|
|
|
return ParsedAddress(addresses: [name], parseFrom: ParseFrom.yatRecord);
|
|
|
|
}
|
|
|
|
return ParsedAddress(
|
|
|
|
addresses: addresses!.map((e) => e.address).toList(),
|
|
|
|
name: name,
|
|
|
|
parseFrom: ParseFrom.yatRecord,
|
|
|
|
);
|
2022-03-15 09:11:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
factory ParsedAddress.fetchUnstoppableDomainAddress({
|
2024-01-27 02:34:38 +00:00
|
|
|
String? address,
|
2022-10-12 17:09:57 +00:00
|
|
|
required String name,
|
2024-03-01 19:38:48 +00:00
|
|
|
}) {
|
|
|
|
if (address?.isEmpty ?? true) {
|
|
|
|
return ParsedAddress(addresses: [name]);
|
|
|
|
}
|
|
|
|
return ParsedAddress(
|
|
|
|
addresses: [address!],
|
|
|
|
name: name,
|
|
|
|
parseFrom: ParseFrom.unstoppableDomains,
|
|
|
|
);
|
2022-03-15 09:11:53 +00:00
|
|
|
}
|
|
|
|
|
2023-08-01 12:00:00 +00:00
|
|
|
factory ParsedAddress.fetchOpenAliasAddress(
|
|
|
|
{required OpenaliasRecord record, required String name}) {
|
|
|
|
if (record.address.isEmpty) {
|
|
|
|
return ParsedAddress(addresses: [name]);
|
|
|
|
}
|
|
|
|
return ParsedAddress(
|
|
|
|
addresses: [record.address],
|
|
|
|
name: record.name,
|
|
|
|
description: record.description,
|
|
|
|
parseFrom: ParseFrom.openAlias,
|
|
|
|
);
|
2022-03-15 09:11:53 +00:00
|
|
|
}
|
2022-06-13 11:41:46 +00:00
|
|
|
|
2024-03-01 19:38:48 +00:00
|
|
|
factory ParsedAddress.fetchFioAddress({required String address, required String name}) {
|
2022-06-13 11:41:46 +00:00
|
|
|
return ParsedAddress(
|
|
|
|
addresses: [address],
|
|
|
|
name: name,
|
|
|
|
parseFrom: ParseFrom.fio,
|
|
|
|
);
|
|
|
|
}
|
2022-10-12 17:09:57 +00:00
|
|
|
|
2024-03-01 19:38:48 +00:00
|
|
|
factory ParsedAddress.fetchTwitterAddress(
|
|
|
|
{required String address,
|
|
|
|
required String name,
|
|
|
|
required String profileImageUrl,
|
|
|
|
required String profileName,
|
|
|
|
String? description}) {
|
2023-01-24 18:24:46 +00:00
|
|
|
return ParsedAddress(
|
|
|
|
addresses: [address],
|
|
|
|
name: name,
|
2024-03-01 19:38:48 +00:00
|
|
|
description: description ?? '',
|
|
|
|
profileImageUrl: profileImageUrl,
|
|
|
|
profileName: profileName,
|
2023-01-24 18:24:46 +00:00
|
|
|
parseFrom: ParseFrom.twitter,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-03-01 19:38:48 +00:00
|
|
|
factory ParsedAddress.fetchMastodonAddress(
|
|
|
|
{required String address,
|
|
|
|
required String name,
|
|
|
|
required String profileImageUrl,
|
|
|
|
required String profileName}) {
|
2023-10-05 12:18:35 +00:00
|
|
|
return ParsedAddress(
|
|
|
|
addresses: [address],
|
|
|
|
name: name,
|
2024-03-01 19:38:48 +00:00
|
|
|
parseFrom: ParseFrom.mastodon,
|
|
|
|
profileImageUrl: profileImageUrl,
|
|
|
|
profileName: profileName,
|
2023-10-05 12:18:35 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-03-01 19:38:48 +00:00
|
|
|
factory ParsedAddress.fetchContactAddress({required String address, required String name}) {
|
2023-08-01 12:00:00 +00:00
|
|
|
return ParsedAddress(
|
|
|
|
addresses: [address],
|
|
|
|
name: name,
|
|
|
|
parseFrom: ParseFrom.contact,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-09-21 14:16:27 +00:00
|
|
|
factory ParsedAddress.fetchEnsAddress({required String address, required String name}) {
|
|
|
|
return ParsedAddress(
|
|
|
|
addresses: [address],
|
|
|
|
name: name,
|
|
|
|
parseFrom: ParseFrom.ens,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-03-04 17:32:10 +00:00
|
|
|
factory ParsedAddress.nostrAddress(
|
|
|
|
{required String address,
|
|
|
|
required String name,
|
|
|
|
required String profileImageUrl,
|
|
|
|
required String profileName}) {
|
2024-01-27 02:34:38 +00:00
|
|
|
return ParsedAddress(
|
|
|
|
addresses: [address],
|
|
|
|
name: name,
|
|
|
|
parseFrom: ParseFrom.nostr,
|
2024-03-04 17:32:10 +00:00
|
|
|
profileImageUrl: profileImageUrl,
|
|
|
|
profileName: profileName,
|
2024-01-27 02:34:38 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-05-06 19:16:25 +00:00
|
|
|
factory ParsedAddress.thorChainAddress({required String address, required String name}) {
|
|
|
|
return ParsedAddress(
|
|
|
|
addresses: [address],
|
|
|
|
name: name,
|
|
|
|
parseFrom: ParseFrom.thorChain,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-10-12 17:09:57 +00:00
|
|
|
final List<String> addresses;
|
|
|
|
final String name;
|
|
|
|
final String description;
|
2024-03-01 19:38:48 +00:00
|
|
|
final String profileImageUrl;
|
|
|
|
final String profileName;
|
2022-10-12 17:09:57 +00:00
|
|
|
final ParseFrom parseFrom;
|
2022-01-18 07:46:13 +00:00
|
|
|
}
|