2024-08-13 12:15:31 +00:00
|
|
|
import 'dart:convert';
|
|
|
|
|
2021-04-20 17:49:53 +00:00
|
|
|
import 'package:flutter/services.dart';
|
2024-08-13 12:15:31 +00:00
|
|
|
import 'package:http/http.dart' as http;
|
2021-04-20 17:49:53 +00:00
|
|
|
|
2021-07-07 13:50:55 +00:00
|
|
|
const channel = MethodChannel('com.cake_wallet/native_utils');
|
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) {
|
|
|
|
print('Unstoppable domain error: ${e.toString()}');
|
|
|
|
address = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
return address;
|
|
|
|
}
|