cake_wallet/lib/entities/parsed_address.dart

77 lines
2.1 KiB
Dart
Raw Normal View History

import 'package:cake_wallet/entities/openalias_record.dart';
import 'package:cake_wallet/entities/yat_record.dart';
2023-01-24 18:24:46 +00:00
enum ParseFrom { unstoppableDomains, openAlias, yatRecord, fio, notParsed, twitter }
class ParsedAddress {
ParsedAddress({
2022-10-12 17:09:57 +00:00
required this.addresses,
this.name = '',
2022-01-18 07:46:13 +00:00
this.description = '',
this.parseFrom = ParseFrom.notParsed,
});
factory ParsedAddress.fetchEmojiAddress({
2022-10-12 17:09:57 +00:00
List<YatRecord>? addresses,
required String name,
}){
if (addresses?.isEmpty ?? true) {
return ParsedAddress(
addresses: [name], parseFrom: ParseFrom.yatRecord);
2022-10-12 17:09:57 +00:00
}
return ParsedAddress(
2022-10-12 17:09:57 +00:00
addresses: addresses!.map((e) => e.address).toList(),
name: name,
parseFrom: ParseFrom.yatRecord,
);
}
factory ParsedAddress.fetchUnstoppableDomainAddress({
2022-10-12 17:09:57 +00:00
String? address,
required String name,
}){
2022-10-12 17:09:57 +00:00
if (address?.isEmpty ?? true) {
return ParsedAddress(addresses: [name]);
}
return ParsedAddress(
2022-10-12 17:09:57 +00:00
addresses: [address!],
name: name,
parseFrom: ParseFrom.unstoppableDomains,
);
}
2022-10-12 17:09:57 +00:00
factory ParsedAddress.fetchOpenAliasAddress({OpenaliasRecord? record, required String name}){
final formattedName = OpenaliasRecord.formatDomainName(name);
if (record == null || record.address.contains(formattedName)) {
return ParsedAddress(addresses: [name]);
}
return ParsedAddress(
addresses: [record.address],
name: record.name,
description: record.description,
parseFrom: ParseFrom.openAlias,
);
}
2022-10-12 17:09:57 +00:00
factory ParsedAddress.fetchFioAddress({required String address, required String name}){
return ParsedAddress(
addresses: [address],
name: name,
parseFrom: ParseFrom.fio,
);
}
2022-10-12 17:09:57 +00:00
2023-01-24 18:24:46 +00:00
factory ParsedAddress.fetchTwitterAddress({required String address, required String name}){
return ParsedAddress(
addresses: [address],
name: name,
parseFrom: ParseFrom.twitter,
);
}
2022-10-12 17:09:57 +00:00
final List<String> addresses;
final String name;
final String description;
final ParseFrom parseFrom;
2022-01-18 07:46:13 +00:00
}