mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-17 17:57:40 +00:00
fix start issues
This commit is contained in:
parent
99dc1aef42
commit
3e5035bd66
1 changed files with 22 additions and 20 deletions
|
@ -12,7 +12,6 @@ import 'dart:convert';
|
||||||
|
|
||||||
import 'package:decimal/decimal.dart';
|
import 'package:decimal/decimal.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:http/http.dart' as http;
|
|
||||||
import 'package:stackwallet/exceptions/exchange/exchange_exception.dart';
|
import 'package:stackwallet/exceptions/exchange/exchange_exception.dart';
|
||||||
import 'package:stackwallet/exceptions/exchange/pair_unavailable_exception.dart';
|
import 'package:stackwallet/exceptions/exchange/pair_unavailable_exception.dart';
|
||||||
import 'package:stackwallet/exceptions/exchange/unsupported_currency_exception.dart';
|
import 'package:stackwallet/exceptions/exchange/unsupported_currency_exception.dart';
|
||||||
|
@ -26,9 +25,11 @@ import 'package:stackwallet/models/exchange/response_objects/fixed_rate_market.d
|
||||||
import 'package:stackwallet/models/exchange/response_objects/range.dart';
|
import 'package:stackwallet/models/exchange/response_objects/range.dart';
|
||||||
import 'package:stackwallet/models/isar/exchange_cache/currency.dart';
|
import 'package:stackwallet/models/isar/exchange_cache/currency.dart';
|
||||||
import 'package:stackwallet/models/isar/exchange_cache/pair.dart';
|
import 'package:stackwallet/models/isar/exchange_cache/pair.dart';
|
||||||
|
import 'package:stackwallet/networking/http.dart';
|
||||||
import 'package:stackwallet/services/exchange/change_now/change_now_exchange.dart';
|
import 'package:stackwallet/services/exchange/change_now/change_now_exchange.dart';
|
||||||
import 'package:stackwallet/services/exchange/exchange_response.dart';
|
import 'package:stackwallet/services/exchange/exchange_response.dart';
|
||||||
import 'package:stackwallet/utilities/logger.dart';
|
import 'package:stackwallet/utilities/logger.dart';
|
||||||
|
import 'package:stackwallet/utilities/prefs.dart';
|
||||||
import 'package:tuple/tuple.dart';
|
import 'package:tuple/tuple.dart';
|
||||||
|
|
||||||
class ChangeNowAPI {
|
class ChangeNowAPI {
|
||||||
|
@ -41,9 +42,6 @@ class ChangeNowAPI {
|
||||||
static final ChangeNowAPI _instance = ChangeNowAPI._();
|
static final ChangeNowAPI _instance = ChangeNowAPI._();
|
||||||
static ChangeNowAPI get instance => _instance;
|
static ChangeNowAPI get instance => _instance;
|
||||||
|
|
||||||
/// set this to override using standard http client. Useful for testing
|
|
||||||
http.Client? client;
|
|
||||||
|
|
||||||
Uri _buildUri(String path, Map<String, dynamic>? params) {
|
Uri _buildUri(String path, Map<String, dynamic>? params) {
|
||||||
return Uri.https(authority, apiVersion + path, params);
|
return Uri.https(authority, apiVersion + path, params);
|
||||||
}
|
}
|
||||||
|
@ -53,21 +51,22 @@ class ChangeNowAPI {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<dynamic> _makeGetRequest(Uri uri) async {
|
Future<dynamic> _makeGetRequest(Uri uri) async {
|
||||||
final client = this.client ?? http.Client();
|
|
||||||
try {
|
try {
|
||||||
final response = await client.get(
|
final response = await HTTP.get(
|
||||||
uri,
|
url: uri,
|
||||||
headers: {'Content-Type': 'application/json'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
|
routeOverTor: Prefs.instance.useTor,
|
||||||
);
|
);
|
||||||
|
String? data;
|
||||||
try {
|
try {
|
||||||
final parsed = jsonDecode(response.body);
|
data = await response.transform(utf8.decoder).join();
|
||||||
|
final parsed = jsonDecode(data);
|
||||||
|
|
||||||
return parsed;
|
return parsed;
|
||||||
} on FormatException catch (e) {
|
} on FormatException catch (e) {
|
||||||
return {
|
return {
|
||||||
"error": "Dart format exception",
|
"error": "Dart format exception",
|
||||||
"message": response.body,
|
"message": data,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
|
@ -78,17 +77,18 @@ class ChangeNowAPI {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<dynamic> _makeGetRequestV2(Uri uri, String apiKey) async {
|
Future<dynamic> _makeGetRequestV2(Uri uri, String apiKey) async {
|
||||||
final client = this.client ?? http.Client();
|
|
||||||
try {
|
try {
|
||||||
final response = await client.get(
|
final response = await HTTP.get(
|
||||||
uri,
|
url: uri,
|
||||||
headers: {
|
headers: {
|
||||||
// 'Content-Type': 'application/json',
|
// 'Content-Type': 'application/json',
|
||||||
'x-changenow-api-key': apiKey,
|
'x-changenow-api-key': apiKey,
|
||||||
},
|
},
|
||||||
|
routeOverTor: Prefs.instance.useTor,
|
||||||
);
|
);
|
||||||
|
|
||||||
final parsed = jsonDecode(response.body);
|
final data = await response.transform(utf8.decoder).join();
|
||||||
|
final parsed = jsonDecode(data);
|
||||||
|
|
||||||
return parsed;
|
return parsed;
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
|
@ -102,21 +102,23 @@ class ChangeNowAPI {
|
||||||
Uri uri,
|
Uri uri,
|
||||||
Map<String, String> body,
|
Map<String, String> body,
|
||||||
) async {
|
) async {
|
||||||
final client = this.client ?? http.Client();
|
|
||||||
try {
|
try {
|
||||||
final response = await client.post(
|
final response = await HTTP.post(
|
||||||
uri,
|
url: uri,
|
||||||
headers: {'Content-Type': 'application/json'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
body: jsonEncode(body),
|
body: jsonEncode(body),
|
||||||
|
routeOverTor: Prefs.instance.useTor,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
String? data;
|
||||||
try {
|
try {
|
||||||
final parsed = jsonDecode(response.body);
|
data = await response.transform(utf8.decoder).join();
|
||||||
|
final parsed = jsonDecode(data);
|
||||||
|
|
||||||
return parsed;
|
return parsed;
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
Logging.instance.log("ChangeNOW api failed to parse: ${response.body}",
|
Logging.instance
|
||||||
level: LogLevel.Error);
|
.log("ChangeNOW api failed to parse: $data", level: LogLevel.Error);
|
||||||
rethrow;
|
rethrow;
|
||||||
}
|
}
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
|
|
Loading…
Reference in a new issue