mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-06-28 20:39:51 +00:00
unstoppable domains fix (#1600)
This commit is contained in:
parent
0491ad9ee2
commit
2949299821
7 changed files with 16 additions and 123 deletions
|
@ -1,5 +1,7 @@
|
|||
import 'package:cake_wallet/utils/device_info.dart';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
const channel = MethodChannel('com.cake_wallet/native_utils');
|
||||
|
||||
|
@ -7,18 +9,19 @@ Future<String> fetchUnstoppableDomainAddress(String domain, String ticker) async
|
|||
var address = '';
|
||||
|
||||
try {
|
||||
if (DeviceInfo.instance.isMobile) {
|
||||
address = await channel.invokeMethod<String>(
|
||||
'getUnstoppableDomainAddress',
|
||||
<String, String> {
|
||||
'domain' : domain,
|
||||
'ticker' : ticker
|
||||
}
|
||||
) ?? '';
|
||||
} else {
|
||||
// TODO: Integrate with Unstoppable domains resolution API
|
||||
return address;
|
||||
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");
|
||||
}
|
||||
|
||||
return records[key] as String? ?? '';
|
||||
} catch (e) {
|
||||
print('Unstoppable domain error: ${e.toString()}');
|
||||
address = '';
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue