Add script to check fiat api and see which currencies are not working
OmarHatem committed
Dec 17, 2025 at 03:13 UTC
dd51b5a6091ce89e233fc99aace9745666ad461a
2 files changed
+185
-1
.gitignore
+2
-1
@@ -213,4 +213,5 @@ flatpak-build/
213
**/linux/flutter/generated_plugin_registrant.h
214
**/linux/flutter/generated_plugins.cmake
215
216
-scripts/torch_dart/
\ No newline at end of file
216
+scripts/torch_dart/
217
+fiat-check-output.txt
\ No newline at end of file
tool/fiat_api_check.dart
new
+183
@@ -0,0 +1,183 @@
1
+import 'dart:async';
2
+import 'dart:convert';
3
+import 'dart:io';
4
+import 'package:http/http.dart' as http;
5
+import 'package:cake_wallet/.secrets.g.dart' as secrets;
6
+
7
+// 1. Configuration
8
+const _fiatApiClearNetAuthority = 'fiat-api.cakewallet.com';
9
+const _fiatApiPath = '/v2/rates';
10
+const _apiKey = secrets.fiatApiKey;
11
+
12
+// 2. Define Lists
13
+const List<String> cryptoCurrencies = [
14
+ 'btc',
15
+ 'ltc',
16
+ 'xmr',
17
+ 'bch',
18
+ 'doge',
19
+ 'eth',
20
+ 'pol',
21
+ 'sol',
22
+ 'xno',
23
+ 'trx',
24
+ 'dcr',
25
+ 'zano',
26
+ 'wow',
27
+ 'arb',
28
+ 'usdt',
29
+ 'pepe',
30
+ 'zec',
31
+ 'bnb',
32
+ 'xrp',
33
+ 'ada',
34
+ 'avax',
35
+ 'shib',
36
+ 'ton',
37
+ 'dot',
38
+ 'link',
39
+ 'uni',
40
+ 'near',
41
+ 'atom',
42
+ 'xlm',
43
+ 'stx',
44
+ 'kas',
45
+ 'dai',
46
+];
47
+
48
+const List<String> fiatCurrencies = [
49
+ 'usd',
50
+ 'eur',
51
+ 'aud',
52
+ 'gbp',
53
+ 'jpy',
54
+ 'cad',
55
+ 'chf',
56
+ 'cny',
57
+ 'inr',
58
+ 'brl',
59
+ 'zar',
60
+ 'mxn',
61
+ 'krw',
62
+ 'hkd',
63
+ 'sgd',
64
+ 'nzd',
65
+ 'sek',
66
+ 'try'
67
+];
68
+
69
+void main() {
70
+ // --- A. Setup the Output File ---
71
+ final logFile = File('fiat-check-output.txt');
72
+ // Write a header to start fresh (overwrite old file)
73
+ logFile.writeAsStringSync('--- Starting Verified Price Check at ${DateTime.now()} ---\n');
74
+
75
+ // --- B. Run App in a Zone to Capture Prints ---
76
+ runZoned(
77
+ () async {
78
+ print('--- Starting Verified Price Check ---');
79
+
80
+ final Map<String, List<String>> workingPairs = {};
81
+ final Map<String, List<String>> failedPairs = {};
82
+ final client = http.Client();
83
+
84
+ try {
85
+ for (final crypto in cryptoCurrencies) {
86
+ workingPairs[crypto] = [];
87
+ failedPairs[crypto] = [];
88
+
89
+ for (final fiat in fiatCurrencies) {
90
+ // Clean ticker logic
91
+ String cleanCrypto = crypto.split(".").first;
92
+
93
+ final Map<String, String> queryParams = {
94
+ 'interval_count': '1',
95
+ 'base': cleanCrypto,
96
+ 'quote': fiat,
97
+ };
98
+
99
+ final uri = Uri.https(_fiatApiClearNetAuthority, _fiatApiPath, queryParams);
100
+ bool isSuccess = false;
101
+ String logPrefix = "❌";
102
+ String logMessage = "";
103
+
104
+ try {
105
+ final response = await client.get(uri, headers: {"x-api-key": _apiKey});
106
+
107
+ if (response.statusCode == 200) {
108
+ final data = jsonDecode(response.body) as Map<String, dynamic>;
109
+ final Map<String, dynamic> results = data['results'] as Map<String, dynamic>? ?? {};
110
+ final Map<String, dynamic> errors = data['errors'] as Map<String, dynamic>? ?? {};
111
+
112
+ if (results.isNotEmpty && errors.isEmpty) {
113
+ isSuccess = true;
114
+ logPrefix = "✅";
115
+ final price = results.values.first;
116
+ logMessage = "${cleanCrypto.toUpperCase()}/${fiat.toUpperCase()} = $price";
117
+ } else {
118
+ isSuccess = false;
119
+ logPrefix = "❌";
120
+ logMessage =
121
+ "${cleanCrypto.toUpperCase()}/${fiat.toUpperCase()} returned empty results or error.";
122
+ }
123
+ } else {
124
+ logMessage =
125
+ "${cleanCrypto.toUpperCase()}/${fiat.toUpperCase()} HTTP ${response.statusCode}";
126
+ }
127
+ } catch (e) {
128
+ logMessage = "${cleanCrypto.toUpperCase()}/${fiat.toUpperCase()} Error: $e";
129
+ }
130
+
131
+ // Print immediate status (Captured by Zone)
132
+ print('$logPrefix $logMessage');
133
+
134
+ // Aggregate
135
+ if (isSuccess) {
136
+ workingPairs[crypto]!.add(fiat);
137
+ } else {
138
+ failedPairs[crypto]!.add(fiat);
139
+ }
140
+
141
+ // 50ms delay to prevent rate limiting
142
+ await Future.delayed(Duration(milliseconds: 50));
143
+ }
144
+ }
145
+ } finally {
146
+ client.close();
147
+ }
148
+
149
+ // --- FINAL SUMMARY ---
150
+ print('\n\n=== SUMMARY ===\n');
151
+
152
+ // Print Successful
153
+ workingPairs.forEach((crypto, fiats) {
154
+ if (fiats.isNotEmpty) {
155
+ print('✅ ${crypto.toUpperCase()}: ${fiats.join(", ")}');
156
+ }
157
+ });
158
+
159
+ print('\n--------------------------------------------------\n');
160
+
161
+ // Print Failed
162
+ failedPairs.forEach((crypto, fiats) {
163
+ if (fiats.isNotEmpty) {
164
+ print('❌ ${crypto.toUpperCase()}: ${fiats.join(", ")}');
165
+ }
166
+ });
167
+
168
+ print('\n=== DONE ===');
169
+ },
170
+
171
+ // --- C. The Interceptor ---
172
+ zoneSpecification: ZoneSpecification(
173
+ print: (self, parent, zone, line) {
174
+ // 1. Print to Standard Console
175
+ parent.print(zone, line);
176
+
177
+ // 2. Append to Text File
178
+ // We use Sync to ensure data isn't lost if the script crashes
179
+ logFile.writeAsStringSync('$line\n', mode: FileMode.append);
180
+ },
181
+ ),
182
+ );
183
+}