2024-08-13 12:15:31 +00:00
|
|
|
import 'dart:convert';
|
|
|
|
|
2024-12-09 18:23:59 +00:00
|
|
|
import 'package:cw_core/utils/print_verbose.dart';
|
2024-08-13 12:15:31 +00:00
|
|
|
import 'package:http/http.dart' as http;
|
2021-04-20 17:49:53 +00:00
|
|
|
|
|
|
|
Future<String> fetchUnstoppableDomainAddress(String domain, String ticker) async {
|
2021-07-07 13:50:55 +00:00
|
|
|
var address = '';
|
2021-04-20 17:49:53 +00:00
|
|
|
|
|
|
|
try {
|
2024-08-13 12:15:31 +00:00
|
|
|
final uri = Uri.parse("https://api.unstoppabledomains.com/profile/public/${Uri.encodeQueryComponent(domain)}?fields=records");
|
|
|
|
final jsonString = await http.read(uri);
|
|
|
|
final jsonParsed = json.decode(jsonString) as Map<String, dynamic>;
|
|
|
|
if (jsonParsed["records"] == null) {
|
|
|
|
throw Exception(".records response from $uri is empty");
|
|
|
|
};
|
|
|
|
final records = jsonParsed["records"] as Map<String, dynamic>;
|
|
|
|
final key = "crypto.${ticker.toUpperCase()}.address";
|
|
|
|
if (records[key] == null) {
|
|
|
|
throw Exception(".records.${key} response from $uri is empty");
|
2023-04-14 04:39:08 +00:00
|
|
|
}
|
2024-08-13 12:15:31 +00:00
|
|
|
|
|
|
|
return records[key] as String? ?? '';
|
2021-04-20 17:49:53 +00:00
|
|
|
} catch (e) {
|
2024-12-09 18:23:59 +00:00
|
|
|
printV('Unstoppable domain error: ${e.toString()}');
|
2021-04-20 17:49:53 +00:00
|
|
|
address = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
return address;
|
|
|
|
}
|