fix start issues

This commit is contained in:
julian 2023-08-07 11:52:36 -06:00
parent 99dc1aef42
commit 3e5035bd66

View file

@ -12,7 +12,6 @@ import 'dart:convert';
import 'package:decimal/decimal.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/pair_unavailable_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/isar/exchange_cache/currency.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/exchange_response.dart';
import 'package:stackwallet/utilities/logger.dart';
import 'package:stackwallet/utilities/prefs.dart';
import 'package:tuple/tuple.dart';
class ChangeNowAPI {
@ -41,9 +42,6 @@ class ChangeNowAPI {
static final ChangeNowAPI _instance = ChangeNowAPI._();
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) {
return Uri.https(authority, apiVersion + path, params);
}
@ -53,21 +51,22 @@ class ChangeNowAPI {
}
Future<dynamic> _makeGetRequest(Uri uri) async {
final client = this.client ?? http.Client();
try {
final response = await client.get(
uri,
final response = await HTTP.get(
url: uri,
headers: {'Content-Type': 'application/json'},
routeOverTor: Prefs.instance.useTor,
);
String? data;
try {
final parsed = jsonDecode(response.body);
data = await response.transform(utf8.decoder).join();
final parsed = jsonDecode(data);
return parsed;
} on FormatException catch (e) {
return {
"error": "Dart format exception",
"message": response.body,
"message": data,
};
}
} catch (e, s) {
@ -78,17 +77,18 @@ class ChangeNowAPI {
}
Future<dynamic> _makeGetRequestV2(Uri uri, String apiKey) async {
final client = this.client ?? http.Client();
try {
final response = await client.get(
uri,
final response = await HTTP.get(
url: uri,
headers: {
// 'Content-Type': 'application/json',
'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;
} catch (e, s) {
@ -102,21 +102,23 @@ class ChangeNowAPI {
Uri uri,
Map<String, String> body,
) async {
final client = this.client ?? http.Client();
try {
final response = await client.post(
uri,
final response = await HTTP.post(
url: uri,
headers: {'Content-Type': 'application/json'},
body: jsonEncode(body),
routeOverTor: Prefs.instance.useTor,
);
String? data;
try {
final parsed = jsonDecode(response.body);
data = await response.transform(utf8.decoder).join();
final parsed = jsonDecode(data);
return parsed;
} catch (_) {
Logging.instance.log("ChangeNOW api failed to parse: ${response.body}",
level: LogLevel.Error);
Logging.instance
.log("ChangeNOW api failed to parse: $data", level: LogLevel.Error);
rethrow;
}
} catch (e, s) {