From 6762207bb8ba49193cc85643729d08d716d2f6e1 Mon Sep 17 00:00:00 2001 From: Keith Simon <41575888+Krakaw@users.noreply.github.com> Date: Mon, 16 May 2022 20:51:32 +0200 Subject: [PATCH] Select sub address or standard address instead of both. (#346) * Use the sub address first then the std --- lib/core/yat_service.dart | 25 ++++++++++++++++--------- lib/store/yat/yat_store.dart | 4 ++-- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/lib/core/yat_service.dart b/lib/core/yat_service.dart index 0383d4ba5..92e81e5ef 100644 --- a/lib/core/yat_service.dart +++ b/lib/core/yat_service.dart @@ -9,35 +9,42 @@ class YatService { static String get apiUrl => YatService.isDevMode ? YatService.apiDevUrl : YatService.apiReleaseUrl; static const apiReleaseUrl = "https://a.y.at"; - static const apiDevUrl = 'https://yat.fyi'; + static const apiDevUrl = 'https://a.yat.fyi'; static String lookupEmojiUrl(String emojiId) => "$apiUrl/emoji_id/$emojiId/payment"; + static const String MONERO_SUB_ADDRESS = '0x1002'; + static const String MONERO_STD_ADDRESS = '0x1001'; static const tags = { - 'XMR': '0x1001,0x1002', + 'XMR': "$MONERO_STD_ADDRESS,$MONERO_SUB_ADDRESS", 'BTC': '0x1003', - 'LTC': '0x3fff' + 'LTC': '0x1019' }; Future> fetchYatAddress(String emojiId, String ticker) async { final formattedTicker = ticker.toUpperCase(); final formattedEmojiId = emojiId.replaceAll(' ', ''); + final tag = tags[formattedTicker]; final uri = Uri.parse(lookupEmojiUrl(formattedEmojiId)).replace( queryParameters: { - "tags": tags[formattedTicker] + "tags": tag }); - final yatRecords = []; try { final response = await get(uri); final resBody = json.decode(response.body) as Map; - final results = resBody["result"] as Map; - results.forEach((dynamic key, dynamic value) { - yatRecords.add(YatRecord.fromJson(value as Map)); - }); + // Favour a subaddress over a standard address. + final yatRecord = ( + results[MONERO_SUB_ADDRESS] ?? + results[MONERO_STD_ADDRESS] ?? + results[tag]) as Map; + + if (yatRecord != null) { + yatRecords.add(YatRecord.fromJson(yatRecord)); + } return yatRecords; } catch (_) { diff --git a/lib/store/yat/yat_store.dart b/lib/store/yat/yat_store.dart index 8cb13c735..8876f5af7 100644 --- a/lib/store/yat/yat_store.dart +++ b/lib/store/yat/yat_store.dart @@ -29,7 +29,7 @@ class YatLink { static const startFlowUrl = ''; // 'https://www.y03btrk.com/4RQSJ/6JHXF/'; static const isDevMode = true; static const tags = >{"XMR" : ['0x1001', '0x1002'], - "BTC" : ['0x1003'], "LTC" : ['0x3fff']}; + "BTC" : ['0x1003'], "LTC" : ['0x1019']}; static String get apiUrl => YatLink.isDevMode ? YatLink.apiDevUrl @@ -281,4 +281,4 @@ abstract class YatStoreBase with Store { //return base64.encode(addressJsonBytes); return ''; } -} \ No newline at end of file +}