2022-03-15 09:11:53 +00:00
|
|
|
import 'package:cake_wallet/entities/openalias_record.dart';
|
|
|
|
import 'package:cake_wallet/entities/yat_record.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
2022-06-13 11:41:46 +00:00
|
|
|
enum ParseFrom { unstoppableDomains, openAlias, yatRecord, fio, notParsed }
|
2021-07-07 14:31:16 +00:00
|
|
|
|
|
|
|
class ParsedAddress {
|
2021-07-16 10:28:46 +00:00
|
|
|
ParsedAddress({
|
2021-09-20 14:56:27 +00:00
|
|
|
this.addresses,
|
2021-07-16 10:28:46 +00:00
|
|
|
this.name = '',
|
2022-01-18 07:46:13 +00:00
|
|
|
this.description = '',
|
|
|
|
this.parseFrom = ParseFrom.notParsed,
|
|
|
|
});
|
2021-07-07 14:31:16 +00:00
|
|
|
|
2021-09-20 14:56:27 +00:00
|
|
|
final List<String> addresses;
|
2021-07-16 10:28:46 +00:00
|
|
|
final String name;
|
2022-01-18 07:46:13 +00:00
|
|
|
final String description;
|
2021-07-07 14:31:16 +00:00
|
|
|
final ParseFrom parseFrom;
|
2022-03-15 09:11:53 +00:00
|
|
|
|
|
|
|
factory ParsedAddress.fetchEmojiAddress({
|
|
|
|
@required 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({
|
|
|
|
@required 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}){
|
|
|
|
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-06-13 11:41:46 +00:00
|
|
|
|
|
|
|
factory ParsedAddress.fetchFioAddress({@required String address, @required String name}){
|
|
|
|
|
|
|
|
return ParsedAddress(
|
|
|
|
addresses: [address],
|
|
|
|
name: name,
|
|
|
|
parseFrom: ParseFrom.fio,
|
|
|
|
);
|
|
|
|
}
|
2022-01-18 07:46:13 +00:00
|
|
|
}
|