2021-08-20 13:26:00 +00:00
|
|
|
import 'dart:convert';
|
|
|
|
import 'package:cake_wallet/yat/yat_exception.dart';
|
|
|
|
import 'package:http/http.dart';
|
|
|
|
|
2021-08-27 19:56:21 +00:00
|
|
|
Future<String> fetchYatAddress(String emojiId, String ticker) async {
|
2021-08-27 17:46:24 +00:00
|
|
|
const _requestURL = 'https://a.y.at/emoji_id/';
|
2021-08-27 19:56:21 +00:00
|
|
|
|
2021-08-31 15:47:00 +00:00
|
|
|
final url = _requestURL + emojiId + '/' + ticker.toUpperCase();
|
2021-08-27 17:46:24 +00:00
|
|
|
final response = await get(url);
|
2021-08-20 13:26:00 +00:00
|
|
|
|
|
|
|
if (response.statusCode != 200) {
|
|
|
|
throw YatException(text: response.body.toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
final responseJSON = json.decode(response.body) as Map<String, dynamic>;
|
2021-08-27 19:56:21 +00:00
|
|
|
final result = responseJSON['result'] as List<dynamic>;
|
|
|
|
|
2021-09-16 10:21:54 +00:00
|
|
|
if (result?.isEmpty ?? true) {
|
2021-08-27 19:56:21 +00:00
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2021-08-31 15:47:00 +00:00
|
|
|
final yatAddress = result.first['data'] as String;
|
|
|
|
return yatAddress;
|
2021-08-20 13:26:00 +00:00
|
|
|
}
|