From f205312bb9efb950a48b15306a6d524fa08ce0ba Mon Sep 17 00:00:00 2001 From: sneurlax Date: Sat, 21 Jan 2023 00:19:56 -0600 Subject: [PATCH] TODOs --- lib/services/buy/simplex/simplex_api.dart | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/lib/services/buy/simplex/simplex_api.dart b/lib/services/buy/simplex/simplex_api.dart index 9ac74042f..7b9459015 100644 --- a/lib/services/buy/simplex/simplex_api.dart +++ b/lib/services/buy/simplex/simplex_api.dart @@ -1,3 +1,5 @@ +// TODO use _buildUri + import 'dart:async'; import 'dart:convert'; @@ -28,11 +30,6 @@ class SimplexAPI { } Future>> getSupportedCryptos() async { - // official docs reference eg - // curl --request GET \ - // --url https://sandbox.test-simplexcc.com/v2/supported_crypto_currencies \ - // --header 'accept: application/json' - try { Map headers = { 'Content-Type': 'application/x-www-form-urlencoded', @@ -40,13 +37,11 @@ class SimplexAPI { Uri url = Uri.parse('http://localhost/api.php?ROUTE=supported_cryptos'); var res = await http.post(url, headers: headers); - if (res.statusCode != 200) { throw Exception( 'getAvailableCurrencies exception: statusCode= ${res.statusCode}'); } - - final jsonArray = jsonDecode(res.body); + final jsonArray = jsonDecode(res.body); // TODO handle if invalid json return await compute(_parseSupportedCryptos, jsonArray); } catch (e, s) { @@ -67,6 +62,7 @@ class SimplexAPI { List fiats = []; for (final crypto in jsonArray as List) { + // TODO validate jsonArray cryptos.add(Crypto.fromJson({ 'ticker': "${crypto['ticker_symbol']}", 'name': crypto['name'], @@ -97,13 +93,11 @@ class SimplexAPI { Uri url = Uri.parse('http://localhost/api.php?ROUTE=supported_fiats'); var res = await http.post(url, headers: headers); - if (res.statusCode != 200) { throw Exception( 'getAvailableCurrencies exception: statusCode= ${res.statusCode}'); } - - final jsonArray = jsonDecode(res.body); + final jsonArray = jsonDecode(res.body); // TODO validate json return await compute(_parseSupportedFiats, jsonArray); } catch (e, s) { @@ -124,6 +118,7 @@ class SimplexAPI { List fiats = []; for (final fiat in jsonArray as List) { + // TODO validate list fiats.add(Fiat.fromJson({ 'ticker': "${fiat['ticker_symbol']}", 'name': "${fiat['ticker_symbol']}",