CAKE-192 | added name property to parsed_address.dart; fixed parse_address_from_domain.dart

This commit is contained in:
OleksandrSobol 2021-07-16 13:28:46 +03:00
parent bac491c44f
commit 008936435b
4 changed files with 27 additions and 16 deletions

View file

@ -7,34 +7,41 @@ const topLevelDomain = 'crypto';
Future<ParsedAddress> parseAddressFromDomain(
String domain, String ticker) async {
try {
final domainParts = domain.split('.');
final formattedName = OpenaliasRecord.formatDomainName(domain);
final domainParts = formattedName.split('.');
final name = domainParts.last;
if (domainParts.length <= 1 || domainParts.first.isEmpty || name.isEmpty) {
return ParsedAddress(domain, ParseFrom.notParsed);
return ParsedAddress(address: domain);
}
if (name.contains(topLevelDomain)) {
final address = await fetchUnstoppableDomainAddress(domain, ticker);
final address =
await fetchUnstoppableDomainAddress(formattedName, ticker);
if (address?.isEmpty ?? true) {
return ParsedAddress(domain, ParseFrom.notParsed);
return ParsedAddress(address: domain);
}
return ParsedAddress(address, ParseFrom.unstoppableDomains);
return ParsedAddress(
address: address,
name: formattedName,
parseFrom: ParseFrom.unstoppableDomains);
}
final record = await OpenaliasRecord.fetchAddressAndName(
OpenaliasRecord.formatDomainName(domain));
final record = await OpenaliasRecord.fetchAddressAndName(formattedName);
if (record == null || record.address.contains(domain)) {
return ParsedAddress(domain, ParseFrom.notParsed);
if (record == null || record.address.contains(formattedName)) {
return ParsedAddress(address: domain);
}
return ParsedAddress(record.address, ParseFrom.openAlias);
return ParsedAddress(
address: record.address,
name: record.name,
parseFrom: ParseFrom.openAlias);
} catch (e) {
print(e.toString());
}
return ParsedAddress(domain, ParseFrom.notParsed);
return ParsedAddress(address: domain);
}

View file

@ -1,8 +1,12 @@
enum ParseFrom {unstoppableDomains, openAlias, notParsed}
class ParsedAddress {
ParsedAddress(this.address, this.parseFrom);
ParsedAddress({
this.address = '',
this.name = '',
this.parseFrom = ParseFrom.notParsed});
final String address;
final String name;
final ParseFrom parseFrom;
}

View file

@ -787,13 +787,13 @@ class ExchangePage extends BasePage {
showAddressAlert(
context,
S.of(context).address_detected,
S.of(context).address_from_domain(domain));
S.of(context).address_from_domain(parsedAddress.name));
break;
case ParseFrom.openAlias:
showAddressAlert(
context,
S.of(context).openalias_alert_title,
S.of(context).openalias_alert_content(domain));
S.of(context).openalias_alert_content(parsedAddress.name));
break;
case ParseFrom.notParsed:
break;

View file

@ -767,13 +767,13 @@ class SendPage extends BasePage {
showAddressAlert(
context,
S.of(context).address_detected,
S.of(context).address_from_domain(domain));
S.of(context).address_from_domain(parsedAddress.name));
break;
case ParseFrom.openAlias:
showAddressAlert(
context,
S.of(context).openalias_alert_title,
S.of(context).openalias_alert_content(domain));
S.of(context).openalias_alert_content(parsedAddress.name));
break;
case ParseFrom.notParsed:
break;