mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-23 12:09:43 +00:00
cfaa89d165
* CW-425 Display Contact Name in the send view * CW-425 Ignore false positives on OpenAlias
84 lines
2.2 KiB
Dart
84 lines
2.2 KiB
Dart
import 'package:cake_wallet/entities/openalias_record.dart';
|
|
import 'package:cake_wallet/entities/yat_record.dart';
|
|
|
|
enum ParseFrom { unstoppableDomains, openAlias, yatRecord, fio, notParsed, twitter, contact }
|
|
|
|
class ParsedAddress {
|
|
ParsedAddress({
|
|
required this.addresses,
|
|
this.name = '',
|
|
this.description = '',
|
|
this.parseFrom = ParseFrom.notParsed,
|
|
});
|
|
|
|
factory ParsedAddress.fetchEmojiAddress({
|
|
List<YatRecord>? addresses,
|
|
required String name,
|
|
}){
|
|
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,
|
|
);
|
|
}
|
|
|
|
factory ParsedAddress.fetchUnstoppableDomainAddress({
|
|
String? address,
|
|
required String name,
|
|
}){
|
|
if (address?.isEmpty ?? true) {
|
|
return ParsedAddress(addresses: [name]);
|
|
}
|
|
return ParsedAddress(
|
|
addresses: [address!],
|
|
name: name,
|
|
parseFrom: ParseFrom.unstoppableDomains,
|
|
);
|
|
}
|
|
|
|
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,
|
|
);
|
|
}
|
|
|
|
factory ParsedAddress.fetchFioAddress({required String address, required String name}){
|
|
return ParsedAddress(
|
|
addresses: [address],
|
|
name: name,
|
|
parseFrom: ParseFrom.fio,
|
|
);
|
|
}
|
|
|
|
factory ParsedAddress.fetchTwitterAddress({required String address, required String name}){
|
|
return ParsedAddress(
|
|
addresses: [address],
|
|
name: name,
|
|
parseFrom: ParseFrom.twitter,
|
|
);
|
|
}
|
|
|
|
factory ParsedAddress.fetchContactAddress({required String address, required String name}){
|
|
return ParsedAddress(
|
|
addresses: [address],
|
|
name: name,
|
|
parseFrom: ParseFrom.contact,
|
|
);
|
|
}
|
|
|
|
final List<String> addresses;
|
|
final String name;
|
|
final String description;
|
|
final ParseFrom parseFrom;
|
|
}
|