From dd51b5a6091ce89e233fc99aace9745666ad461a Mon Sep 17 00:00:00 2001 From: OmarHatem Date: Wed, 17 Dec 2025 03:13:10 +0200 Subject: [PATCH] Add script to check fiat api and see which currencies are not working --- .gitignore | 3 +- tool/fiat_api_check.dart | 183 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 185 insertions(+), 1 deletion(-) create mode 100644 tool/fiat_api_check.dart diff --git a/.gitignore b/.gitignore index 10bd0b7a8..cbe622744 100644 --- a/.gitignore +++ b/.gitignore @@ -213,4 +213,5 @@ flatpak-build/ **/linux/flutter/generated_plugin_registrant.h **/linux/flutter/generated_plugins.cmake -scripts/torch_dart/ \ No newline at end of file +scripts/torch_dart/ +fiat-check-output.txt \ No newline at end of file diff --git a/tool/fiat_api_check.dart b/tool/fiat_api_check.dart new file mode 100644 index 000000000..e6f53636a --- /dev/null +++ b/tool/fiat_api_check.dart @@ -0,0 +1,183 @@ +import 'dart:async'; +import 'dart:convert'; +import 'dart:io'; +import 'package:http/http.dart' as http; +import 'package:cake_wallet/.secrets.g.dart' as secrets; + +// 1. Configuration +const _fiatApiClearNetAuthority = 'fiat-api.cakewallet.com'; +const _fiatApiPath = '/v2/rates'; +const _apiKey = secrets.fiatApiKey; + +// 2. Define Lists +const List cryptoCurrencies = [ + 'btc', + 'ltc', + 'xmr', + 'bch', + 'doge', + 'eth', + 'pol', + 'sol', + 'xno', + 'trx', + 'dcr', + 'zano', + 'wow', + 'arb', + 'usdt', + 'pepe', + 'zec', + 'bnb', + 'xrp', + 'ada', + 'avax', + 'shib', + 'ton', + 'dot', + 'link', + 'uni', + 'near', + 'atom', + 'xlm', + 'stx', + 'kas', + 'dai', +]; + +const List fiatCurrencies = [ + 'usd', + 'eur', + 'aud', + 'gbp', + 'jpy', + 'cad', + 'chf', + 'cny', + 'inr', + 'brl', + 'zar', + 'mxn', + 'krw', + 'hkd', + 'sgd', + 'nzd', + 'sek', + 'try' +]; + +void main() { + // --- A. Setup the Output File --- + final logFile = File('fiat-check-output.txt'); + // Write a header to start fresh (overwrite old file) + logFile.writeAsStringSync('--- Starting Verified Price Check at ${DateTime.now()} ---\n'); + + // --- B. Run App in a Zone to Capture Prints --- + runZoned( + () async { + print('--- Starting Verified Price Check ---'); + + final Map> workingPairs = {}; + final Map> failedPairs = {}; + final client = http.Client(); + + try { + for (final crypto in cryptoCurrencies) { + workingPairs[crypto] = []; + failedPairs[crypto] = []; + + for (final fiat in fiatCurrencies) { + // Clean ticker logic + String cleanCrypto = crypto.split(".").first; + + final Map queryParams = { + 'interval_count': '1', + 'base': cleanCrypto, + 'quote': fiat, + }; + + final uri = Uri.https(_fiatApiClearNetAuthority, _fiatApiPath, queryParams); + bool isSuccess = false; + String logPrefix = "❌"; + String logMessage = ""; + + try { + final response = await client.get(uri, headers: {"x-api-key": _apiKey}); + + if (response.statusCode == 200) { + final data = jsonDecode(response.body) as Map; + final Map results = data['results'] as Map? ?? {}; + final Map errors = data['errors'] as Map? ?? {}; + + if (results.isNotEmpty && errors.isEmpty) { + isSuccess = true; + logPrefix = "✅"; + final price = results.values.first; + logMessage = "${cleanCrypto.toUpperCase()}/${fiat.toUpperCase()} = $price"; + } else { + isSuccess = false; + logPrefix = "❌"; + logMessage = + "${cleanCrypto.toUpperCase()}/${fiat.toUpperCase()} returned empty results or error."; + } + } else { + logMessage = + "${cleanCrypto.toUpperCase()}/${fiat.toUpperCase()} HTTP ${response.statusCode}"; + } + } catch (e) { + logMessage = "${cleanCrypto.toUpperCase()}/${fiat.toUpperCase()} Error: $e"; + } + + // Print immediate status (Captured by Zone) + print('$logPrefix $logMessage'); + + // Aggregate + if (isSuccess) { + workingPairs[crypto]!.add(fiat); + } else { + failedPairs[crypto]!.add(fiat); + } + + // 50ms delay to prevent rate limiting + await Future.delayed(Duration(milliseconds: 50)); + } + } + } finally { + client.close(); + } + + // --- FINAL SUMMARY --- + print('\n\n=== SUMMARY ===\n'); + + // Print Successful + workingPairs.forEach((crypto, fiats) { + if (fiats.isNotEmpty) { + print('✅ ${crypto.toUpperCase()}: ${fiats.join(", ")}'); + } + }); + + print('\n--------------------------------------------------\n'); + + // Print Failed + failedPairs.forEach((crypto, fiats) { + if (fiats.isNotEmpty) { + print('❌ ${crypto.toUpperCase()}: ${fiats.join(", ")}'); + } + }); + + print('\n=== DONE ==='); + }, + + // --- C. The Interceptor --- + zoneSpecification: ZoneSpecification( + print: (self, parent, zone, line) { + // 1. Print to Standard Console + parent.print(zone, line); + + // 2. Append to Text File + // We use Sync to ensure data isn't lost if the script crashes + logFile.writeAsStringSync('$line\n', mode: FileMode.append); + }, + ), + ); +}