use _buildUri to get supported cryptos

This commit is contained in:
sneurlax 2023-01-25 10:52:41 -06:00
parent c68e739ffe
commit 61748b4b2f

View file

@ -17,8 +17,9 @@ import 'package:stackwallet/utilities/prefs.dart';
import 'package:url_launcher/url_launcher.dart'; import 'package:url_launcher/url_launcher.dart';
class SimplexAPI { class SimplexAPI {
static const String scheme = "https";
static const String authority = "sandbox-api.stackwallet.com"; static const String authority = "sandbox-api.stackwallet.com";
// static const String authority = "localhost";
static const String scheme = authority == "localhost" ? "http" : "https";
final _prefs = Prefs.instance; final _prefs = Prefs.instance;
@ -30,6 +31,9 @@ class SimplexAPI {
http.Client? client; http.Client? client;
Uri _buildUri(String path, Map<String, String>? params) { Uri _buildUri(String path, Map<String, String>? params) {
if (scheme == "http") {
return Uri.http(authority, path, params);
}
return Uri.https(authority, path, params); return Uri.https(authority, path, params);
} }
@ -38,8 +42,10 @@ class SimplexAPI {
Map<String, String> headers = { Map<String, String> headers = {
'Content-Type': 'application/x-www-form-urlencoded', 'Content-Type': 'application/x-www-form-urlencoded',
}; };
Uri url = Uri.parse( Map<String, String> data = {
'https://simplex-sandbox.stackwallet.com/api.php?ROUTE=supported_cryptos'); 'ROUTE': 'supported_cryptos',
};
Uri url = _buildUri('api.php', data);
var res = await http.post(url, headers: headers); var res = await http.post(url, headers: headers);
if (res.statusCode != 200) { if (res.statusCode != 200) {
@ -48,7 +54,7 @@ class SimplexAPI {
} }
final jsonArray = jsonDecode(res.body); // TODO handle if invalid json final jsonArray = jsonDecode(res.body); // TODO handle if invalid json
return await compute(_parseSupportedCryptos, jsonArray); return _parseSupportedCryptos(jsonArray);
} catch (e, s) { } catch (e, s) {
Logging.instance.log("getAvailableCurrencies exception: $e\n$s", Logging.instance.log("getAvailableCurrencies exception: $e\n$s",
level: LogLevel.Error); level: LogLevel.Error);