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

OleksandrSobol committed Aug 31, 2021 at 18:47 UTC e787c96734100c63ef766c92dbdcdf2ae6a0e371
1 file changed +4 -24
lib/yat/yat_record.dart
+4 -24
@@ -4,15 +4,8 @@ import 'package:http/http.dart';
4
5 Future<String> fetchYatAddress(String emojiId, String ticker) async {
6 const _requestURL = 'https://a.y.at/emoji_id/';
7 - const classValue = '0x10';
8 - const tagValues = {'xmr' : ['01', '02'], 'btc' : ['03'], 'eth' : ['04']};
9 - final tagValue = tagValues[ticker];
7
11 - if (tagValue == null) {
12 - return '';
13 - }
14 -
15 - final url = _requestURL + emojiId;
8 + final url = _requestURL + emojiId + '/' + ticker.toUpperCase();
9 final response = await get(url);
10
11 if (response.statusCode != 200) {
@@ -22,23 +15,10 @@ Future<String> fetchYatAddress(String emojiId, String ticker) async {
15 final responseJSON = json.decode(response.body) as Map<String, dynamic>;
16 final result = responseJSON['result'] as List<dynamic>;
17
25 - if (result == null) {
18 + if (result == null || result.isEmpty) {
19 return '';
20 }
21
29 - for (var value in tagValue) {
30 - for (int i = 0; i < result.length; i++) {
31 - final record = result[i] as Map<String, dynamic>;
32 - final tag = record['tag'] as String;
33 - if (tag?.contains(classValue + value) ?? false) {
34 - final yatAddress = record['data'] as String;
35 - return yatAddress;
36 - }
37 - }
38 - }
39 -
40 - return '';
41 -
42 - //final yatAddress = responseJSON['result'][2]['data'] as String;
43 - //return yatAddress;
22 + final yatAddress = result.first['data'] as String;
23 + return yatAddress;
24 }
\ No newline at end of file