mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-11 05:04:35 +00:00
use _buildUri to get supported cryptos
This commit is contained in:
parent
c68e739ffe
commit
61748b4b2f
1 changed files with 10 additions and 4 deletions
|
@ -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);
|
||||||
|
|
Loading…
Reference in a new issue