Select sub address or standard address instead of both. (#346)
* Use the sub address first then the std
Keith Simon committed
May 16, 2022 at 20:51 UTC
6762207bb8ba49193cc85643729d08d716d2f6e1
2 files changed
+18
-11
lib/core/yat_service.dart
+16
-9
@@ -9,35 +9,42 @@ class YatService {
9
static String get apiUrl =>
10
YatService.isDevMode ? YatService.apiDevUrl : YatService.apiReleaseUrl;
11
static const apiReleaseUrl = "https://a.y.at";
12
- static const apiDevUrl = 'https://yat.fyi';
12
+ static const apiDevUrl = 'https://a.yat.fyi';
13
14
static String lookupEmojiUrl(String emojiId) =>
15
"$apiUrl/emoji_id/$emojiId/payment";
16
17
+ static const String MONERO_SUB_ADDRESS = '0x1002';
18
+ static const String MONERO_STD_ADDRESS = '0x1001';
19
static const tags = {
18
- 'XMR': '0x1001,0x1002',
20
+ 'XMR': "$MONERO_STD_ADDRESS,$MONERO_SUB_ADDRESS",
21
'BTC': '0x1003',
20
- 'LTC': '0x3fff'
22
+ 'LTC': '0x1019'
23
};
24
25
Future<List<YatRecord>> fetchYatAddress(String emojiId, String ticker) async {
26
final formattedTicker = ticker.toUpperCase();
27
final formattedEmojiId = emojiId.replaceAll(' ', '');
28
+ final tag = tags[formattedTicker];
29
final uri = Uri.parse(lookupEmojiUrl(formattedEmojiId)).replace(
30
queryParameters: <String, dynamic>{
28
- "tags": tags[formattedTicker]
31
+ "tags": tag
32
});
30
-
33
final yatRecords = <YatRecord>[];
34
35
try {
36
final response = await get(uri);
37
final resBody = json.decode(response.body) as Map<String, dynamic>;
36
-
38
final results = resBody["result"] as Map<dynamic, dynamic>;
38
- results.forEach((dynamic key, dynamic value) {
39
- yatRecords.add(YatRecord.fromJson(value as Map<String, dynamic>));
40
- });
39
+ // Favour a subaddress over a standard address.
40
+ final yatRecord = (
41
+ results[MONERO_SUB_ADDRESS] ??
42
+ results[MONERO_STD_ADDRESS] ??
43
+ results[tag]) as Map<String, dynamic>;
44
+
45
+ if (yatRecord != null) {
46
+ yatRecords.add(YatRecord.fromJson(yatRecord));
47
+ }
48
49
return yatRecords;
50
} catch (_) {
lib/store/yat/yat_store.dart
+2
-2
@@ -29,7 +29,7 @@ class YatLink {
29
static const startFlowUrl = ''; // 'https://www.y03btrk.com/4RQSJ/6JHXF/';
30
static const isDevMode = true;
31
static const tags = <String, List<String>>{"XMR" : ['0x1001', '0x1002'],
32
- "BTC" : ['0x1003'], "LTC" : ['0x3fff']};
32
+ "BTC" : ['0x1003'], "LTC" : ['0x1019']};
33
34
static String get apiUrl => YatLink.isDevMode
35
? YatLink.apiDevUrl
@@ -281,4 +281,4 @@ abstract class YatStoreBase with Store {
281
//return base64.encode(addressJsonBytes);
282
return '';
283
}
284
-}
\ No newline at end of file
284
+}