CAKE-356 | fixed yat_record.dart (request with tag)

This commit is contained in:
OleksandrSobol 2021-08-31 18:47:00 +03:00
parent 6defc6384e
commit e787c96734

View file

@ -4,15 +4,8 @@ import 'package:http/http.dart';
Future<String> fetchYatAddress(String emojiId, String ticker) async {
const _requestURL = 'https://a.y.at/emoji_id/';
const classValue = '0x10';
const tagValues = {'xmr' : ['01', '02'], 'btc' : ['03'], 'eth' : ['04']};
final tagValue = tagValues[ticker];
if (tagValue == null) {
return '';
}
final url = _requestURL + emojiId;
final url = _requestURL + emojiId + '/' + ticker.toUpperCase();
final response = await get(url);
if (response.statusCode != 200) {
@ -22,23 +15,10 @@ Future<String> fetchYatAddress(String emojiId, String ticker) async {
final responseJSON = json.decode(response.body) as Map<String, dynamic>;
final result = responseJSON['result'] as List<dynamic>;
if (result == null) {
if (result == null || result.isEmpty) {
return '';
}
for (var value in tagValue) {
for (int i = 0; i < result.length; i++) {
final record = result[i] as Map<String, dynamic>;
final tag = record['tag'] as String;
if (tag?.contains(classValue + value) ?? false) {
final yatAddress = record['data'] as String;
final yatAddress = result.first['data'] as String;
return yatAddress;
}
}
}
return '';
//final yatAddress = responseJSON['result'][2]['data'] as String;
//return yatAddress;
}