2023-05-26 21:21:16 +00:00
|
|
|
/*
|
|
|
|
* This file is part of Stack Wallet.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2023 Cypher Stack
|
|
|
|
* All Rights Reserved.
|
|
|
|
* The code is distributed under GPLv3 license, see LICENSE file for details.
|
|
|
|
* Generated by Cypher Stack on 2023-05-26
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2022-10-02 19:37:11 +00:00
|
|
|
import 'dart:convert';
|
|
|
|
|
|
|
|
import 'package:decimal/decimal.dart';
|
|
|
|
import 'package:flutter/foundation.dart';
|
2023-02-04 17:15:42 +00:00
|
|
|
import 'package:stackwallet/exceptions/exchange/exchange_exception.dart';
|
2022-10-02 19:37:11 +00:00
|
|
|
import 'package:stackwallet/external_api_keys.dart';
|
2022-10-03 16:30:50 +00:00
|
|
|
import 'package:stackwallet/models/exchange/response_objects/fixed_rate_market.dart';
|
2022-10-02 19:37:11 +00:00
|
|
|
import 'package:stackwallet/models/exchange/response_objects/range.dart';
|
|
|
|
import 'package:stackwallet/models/exchange/response_objects/trade.dart';
|
|
|
|
import 'package:stackwallet/models/exchange/simpleswap/sp_currency.dart';
|
2023-02-05 20:32:39 +00:00
|
|
|
import 'package:stackwallet/models/isar/exchange_cache/pair.dart';
|
2023-09-11 20:20:40 +00:00
|
|
|
import 'package:stackwallet/networking/http.dart';
|
2022-10-02 19:37:11 +00:00
|
|
|
import 'package:stackwallet/services/exchange/exchange_response.dart';
|
2022-10-03 00:54:35 +00:00
|
|
|
import 'package:stackwallet/services/exchange/simpleswap/simpleswap_exchange.dart';
|
2023-09-11 20:20:40 +00:00
|
|
|
import 'package:stackwallet/services/tor_service.dart';
|
2022-10-02 19:37:11 +00:00
|
|
|
import 'package:stackwallet/utilities/logger.dart';
|
2023-09-11 20:20:40 +00:00
|
|
|
import 'package:stackwallet/utilities/prefs.dart';
|
2022-10-02 19:37:11 +00:00
|
|
|
import 'package:tuple/tuple.dart';
|
|
|
|
import 'package:uuid/uuid.dart';
|
|
|
|
|
|
|
|
class SimpleSwapAPI {
|
|
|
|
static const String scheme = "https";
|
|
|
|
static const String authority = "api.simpleswap.io";
|
|
|
|
|
|
|
|
SimpleSwapAPI._();
|
|
|
|
static final SimpleSwapAPI _instance = SimpleSwapAPI._();
|
|
|
|
static SimpleSwapAPI get instance => _instance;
|
|
|
|
|
2023-09-11 20:20:40 +00:00
|
|
|
HTTP client = HTTP();
|
2022-10-02 19:37:11 +00:00
|
|
|
|
|
|
|
Uri _buildUri(String path, Map<String, String>? params) {
|
|
|
|
return Uri.https(authority, path, params);
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<dynamic> _makeGetRequest(Uri uri) async {
|
2022-10-14 18:21:00 +00:00
|
|
|
int code = -1;
|
2022-10-02 19:37:11 +00:00
|
|
|
try {
|
|
|
|
final response = await client.get(
|
2023-09-11 20:20:40 +00:00
|
|
|
url: uri,
|
|
|
|
proxyInfo:
|
|
|
|
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
|
2022-10-02 19:37:11 +00:00
|
|
|
);
|
|
|
|
|
2023-09-11 20:20:40 +00:00
|
|
|
code = response.code;
|
2022-10-14 18:21:00 +00:00
|
|
|
|
2022-10-02 19:37:11 +00:00
|
|
|
final parsed = jsonDecode(response.body);
|
|
|
|
|
|
|
|
return parsed;
|
|
|
|
} catch (e, s) {
|
2022-10-14 18:21:00 +00:00
|
|
|
Logging.instance.log(
|
|
|
|
"_makeRequest($uri) HTTP:$code threw: $e\n$s",
|
|
|
|
level: LogLevel.Error,
|
|
|
|
);
|
2022-10-02 19:37:11 +00:00
|
|
|
rethrow;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<dynamic> _makePostRequest(
|
|
|
|
Uri uri,
|
|
|
|
Map<String, dynamic> body,
|
|
|
|
) async {
|
|
|
|
try {
|
|
|
|
final response = await client.post(
|
2023-09-11 20:20:40 +00:00
|
|
|
url: uri,
|
2022-10-02 19:37:11 +00:00
|
|
|
headers: {'Content-Type': 'application/json'},
|
|
|
|
body: jsonEncode(body),
|
2023-09-11 20:20:40 +00:00
|
|
|
proxyInfo:
|
|
|
|
Prefs.instance.useTor ? TorService.sharedInstance.proxyInfo : null,
|
2022-10-02 19:37:11 +00:00
|
|
|
);
|
|
|
|
|
2023-09-11 20:20:40 +00:00
|
|
|
if (response.code == 200) {
|
2022-10-02 19:37:11 +00:00
|
|
|
final parsed = jsonDecode(response.body);
|
|
|
|
return parsed;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw Exception("response: ${response.body}");
|
|
|
|
} catch (e, s) {
|
|
|
|
Logging.instance
|
|
|
|
.log("_makeRequest($uri) threw: $e\n$s", level: LogLevel.Error);
|
|
|
|
rethrow;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<ExchangeResponse<Trade>> createNewExchange({
|
|
|
|
required bool isFixedRate,
|
|
|
|
required String currencyFrom,
|
|
|
|
required String currencyTo,
|
|
|
|
required String addressTo,
|
|
|
|
required String userRefundAddress,
|
|
|
|
required String userRefundExtraId,
|
|
|
|
required String amount,
|
|
|
|
String? extraIdTo,
|
|
|
|
String? apiKey,
|
|
|
|
}) async {
|
2022-10-02 20:02:10 +00:00
|
|
|
Map<String, dynamic> body = {
|
|
|
|
"fixed": isFixedRate,
|
2022-10-02 19:37:11 +00:00
|
|
|
"currency_from": currencyFrom,
|
|
|
|
"currency_to": currencyTo,
|
|
|
|
"addressTo": addressTo,
|
|
|
|
"userRefundAddress": userRefundAddress,
|
|
|
|
"userRefundExtraId": userRefundExtraId,
|
2022-10-02 20:02:10 +00:00
|
|
|
"amount": double.parse(amount),
|
2022-10-03 00:54:35 +00:00
|
|
|
"extraIdTo": extraIdTo,
|
2022-10-02 19:37:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
final uri =
|
|
|
|
_buildUri("/create_exchange", {"api_key": apiKey ?? kSimpleSwapApiKey});
|
|
|
|
|
|
|
|
try {
|
|
|
|
final jsonObject = await _makePostRequest(uri, body);
|
|
|
|
|
|
|
|
final json = Map<String, dynamic>.from(jsonObject as Map);
|
|
|
|
final trade = Trade(
|
|
|
|
uuid: const Uuid().v1(),
|
|
|
|
tradeId: json["id"] as String,
|
|
|
|
rateType: json["type"] as String,
|
|
|
|
direction: "direct",
|
|
|
|
timestamp: DateTime.parse(json["timestamp"] as String),
|
|
|
|
updatedAt: DateTime.parse(json["updated_at"] as String),
|
2022-10-02 20:46:50 +00:00
|
|
|
payInCurrency: json["currency_from"] as String,
|
|
|
|
payInAmount: json["amount_from"] as String,
|
|
|
|
payInAddress: json["address_from"] as String,
|
|
|
|
payInNetwork: "",
|
2022-10-04 22:10:50 +00:00
|
|
|
payInExtraId: json["extra_id_from"] as String? ?? "",
|
|
|
|
payInTxid: json["tx_from"] as String? ?? "",
|
2022-10-02 20:46:50 +00:00
|
|
|
payOutCurrency: json["currency_to"] as String,
|
|
|
|
payOutAmount: json["amount_to"] as String,
|
|
|
|
payOutAddress: json["address_to"] as String,
|
|
|
|
payOutNetwork: "",
|
|
|
|
payOutExtraId: json["extra_id_to"] as String? ?? "",
|
2022-10-04 22:10:50 +00:00
|
|
|
payOutTxid: json["tx_to"] as String? ?? "",
|
2022-10-02 19:37:11 +00:00
|
|
|
refundAddress: json["user_refund_address"] as String,
|
|
|
|
refundExtraId: json["user_refund_extra_id"] as String,
|
|
|
|
status: json["status"] as String,
|
2022-10-03 00:54:35 +00:00
|
|
|
exchangeName: SimpleSwapExchange.exchangeName,
|
2022-10-02 19:37:11 +00:00
|
|
|
);
|
|
|
|
return ExchangeResponse(value: trade, exception: null);
|
|
|
|
} catch (e, s) {
|
|
|
|
Logging.instance.log("getAvailableCurrencies exception: $e\n$s",
|
|
|
|
level: LogLevel.Error);
|
|
|
|
return ExchangeResponse(
|
|
|
|
exception: ExchangeException(
|
|
|
|
e.toString(),
|
|
|
|
ExchangeExceptionType.generic,
|
|
|
|
),
|
|
|
|
value: null,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<ExchangeResponse<List<SPCurrency>>> getAllCurrencies({
|
|
|
|
String? apiKey,
|
|
|
|
required bool fixedRate,
|
|
|
|
}) async {
|
|
|
|
final uri = _buildUri(
|
|
|
|
"/get_all_currencies", {"api_key": apiKey ?? kSimpleSwapApiKey});
|
|
|
|
|
|
|
|
try {
|
|
|
|
final jsonArray = await _makeGetRequest(uri);
|
|
|
|
|
|
|
|
return await compute(_parseAvailableCurrenciesJson, jsonArray as List);
|
|
|
|
} catch (e, s) {
|
|
|
|
Logging.instance.log("getAvailableCurrencies exception: $e\n$s",
|
|
|
|
level: LogLevel.Error);
|
|
|
|
return ExchangeResponse(
|
|
|
|
exception: ExchangeException(
|
|
|
|
e.toString(),
|
|
|
|
ExchangeExceptionType.generic,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ExchangeResponse<List<SPCurrency>> _parseAvailableCurrenciesJson(
|
|
|
|
List<dynamic> jsonArray) {
|
|
|
|
try {
|
|
|
|
List<SPCurrency> currencies = [];
|
|
|
|
|
|
|
|
for (final json in jsonArray) {
|
|
|
|
try {
|
|
|
|
currencies
|
|
|
|
.add(SPCurrency.fromJson(Map<String, dynamic>.from(json as Map)));
|
|
|
|
} catch (_) {
|
|
|
|
return ExchangeResponse(
|
|
|
|
exception: ExchangeException("Failed to serialize $json",
|
|
|
|
ExchangeExceptionType.serializeResponseError));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ExchangeResponse(value: currencies);
|
|
|
|
} catch (e, s) {
|
|
|
|
Logging.instance.log("_parseAvailableCurrenciesJson exception: $e\n$s",
|
|
|
|
level: LogLevel.Error);
|
|
|
|
return ExchangeResponse(
|
|
|
|
exception: ExchangeException(
|
|
|
|
e.toString(),
|
|
|
|
ExchangeExceptionType.generic,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<ExchangeResponse<SPCurrency>> getCurrency({
|
|
|
|
required String symbol,
|
|
|
|
String? apiKey,
|
|
|
|
}) async {
|
|
|
|
final uri = _buildUri(
|
|
|
|
"/get_currency",
|
|
|
|
{
|
|
|
|
"api_key": apiKey ?? kSimpleSwapApiKey,
|
|
|
|
"symbol": symbol,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
try {
|
|
|
|
final jsonObject = await _makeGetRequest(uri);
|
|
|
|
|
|
|
|
return ExchangeResponse(
|
|
|
|
value: SPCurrency.fromJson(
|
|
|
|
Map<String, dynamic>.from(jsonObject as Map)));
|
|
|
|
} catch (e, s) {
|
|
|
|
Logging.instance
|
|
|
|
.log("getCurrency exception: $e\n$s", level: LogLevel.Error);
|
|
|
|
return ExchangeResponse(
|
|
|
|
exception: ExchangeException(
|
|
|
|
e.toString(),
|
|
|
|
ExchangeExceptionType.generic,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// returns a map where the key currency symbol is a valid pair with any of
|
|
|
|
/// the symbols in its value list
|
|
|
|
Future<ExchangeResponse<List<Pair>>> getAllPairs({
|
|
|
|
required bool isFixedRate,
|
|
|
|
String? apiKey,
|
|
|
|
}) async {
|
|
|
|
final uri = _buildUri(
|
|
|
|
"/get_all_pairs",
|
|
|
|
{
|
|
|
|
"api_key": apiKey ?? kSimpleSwapApiKey,
|
|
|
|
"fixed": isFixedRate.toString(),
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
try {
|
|
|
|
final jsonObject = await _makeGetRequest(uri);
|
|
|
|
final result = await compute(
|
|
|
|
_parseAvailablePairsJson,
|
|
|
|
Tuple2(jsonObject as Map, isFixedRate),
|
|
|
|
);
|
|
|
|
return result;
|
|
|
|
} catch (e, s) {
|
|
|
|
Logging.instance
|
|
|
|
.log("getAllPairs exception: $e\n$s", level: LogLevel.Error);
|
|
|
|
return ExchangeResponse(
|
|
|
|
exception: ExchangeException(
|
|
|
|
e.toString(),
|
|
|
|
ExchangeExceptionType.generic,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ExchangeResponse<List<Pair>> _parseAvailablePairsJson(
|
|
|
|
Tuple2<Map<dynamic, dynamic>, bool> args,
|
|
|
|
) {
|
|
|
|
try {
|
|
|
|
List<Pair> pairs = [];
|
|
|
|
|
|
|
|
for (final entry in args.item1.entries) {
|
|
|
|
try {
|
|
|
|
final from = entry.key as String;
|
|
|
|
for (final to in entry.value as List) {
|
|
|
|
pairs.add(
|
|
|
|
Pair(
|
2023-02-05 20:32:39 +00:00
|
|
|
exchangeName: SimpleSwapExchange.exchangeName,
|
2022-10-02 19:37:11 +00:00
|
|
|
from: from,
|
|
|
|
to: to as String,
|
2023-02-06 14:43:16 +00:00
|
|
|
rateType: SupportedRateType.estimated,
|
2022-10-02 19:37:11 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} catch (_) {
|
|
|
|
return ExchangeResponse(
|
|
|
|
exception: ExchangeException("Failed to serialize $json",
|
|
|
|
ExchangeExceptionType.serializeResponseError));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ExchangeResponse(value: pairs);
|
|
|
|
} catch (e, s) {
|
|
|
|
Logging.instance.log("_parseAvailableCurrenciesJson exception: $e\n$s",
|
|
|
|
level: LogLevel.Error);
|
|
|
|
return ExchangeResponse(
|
|
|
|
exception: ExchangeException(
|
|
|
|
e.toString(),
|
|
|
|
ExchangeExceptionType.generic,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// returns the estimated amount as a string
|
|
|
|
Future<ExchangeResponse<String>> getEstimated({
|
|
|
|
required bool isFixedRate,
|
|
|
|
required String currencyFrom,
|
|
|
|
required String currencyTo,
|
|
|
|
required String amount,
|
|
|
|
String? apiKey,
|
|
|
|
}) async {
|
|
|
|
final uri = _buildUri(
|
|
|
|
"/get_estimated",
|
|
|
|
{
|
|
|
|
"api_key": apiKey ?? kSimpleSwapApiKey,
|
|
|
|
"fixed": isFixedRate.toString(),
|
|
|
|
"currency_from": currencyFrom,
|
|
|
|
"currency_to": currencyTo,
|
|
|
|
"amount": amount,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
try {
|
|
|
|
final jsonObject = await _makeGetRequest(uri);
|
|
|
|
|
|
|
|
return ExchangeResponse(value: jsonObject as String);
|
|
|
|
} catch (e, s) {
|
|
|
|
Logging.instance
|
|
|
|
.log("getEstimated exception: $e\n$s", level: LogLevel.Error);
|
|
|
|
return ExchangeResponse(
|
|
|
|
exception: ExchangeException(
|
|
|
|
e.toString(),
|
|
|
|
ExchangeExceptionType.generic,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// returns the exchange for the given id
|
|
|
|
Future<ExchangeResponse<Trade>> getExchange({
|
|
|
|
required String exchangeId,
|
|
|
|
String? apiKey,
|
2022-10-02 21:48:43 +00:00
|
|
|
Trade? oldTrade,
|
2022-10-02 19:37:11 +00:00
|
|
|
}) async {
|
|
|
|
final uri = _buildUri(
|
|
|
|
"/get_exchange",
|
|
|
|
{
|
|
|
|
"api_key": apiKey ?? kSimpleSwapApiKey,
|
|
|
|
"id": exchangeId,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
try {
|
|
|
|
final jsonObject = await _makeGetRequest(uri);
|
|
|
|
|
|
|
|
final json = Map<String, dynamic>.from(jsonObject as Map);
|
2022-10-02 20:02:10 +00:00
|
|
|
final ts = DateTime.parse(json["timestamp"] as String);
|
2022-10-02 19:37:11 +00:00
|
|
|
final trade = Trade(
|
2022-10-02 21:48:43 +00:00
|
|
|
uuid: oldTrade?.uuid ?? const Uuid().v1(),
|
2022-10-02 19:37:11 +00:00
|
|
|
tradeId: json["id"] as String,
|
|
|
|
rateType: json["type"] as String,
|
|
|
|
direction: "direct",
|
2022-10-02 20:02:10 +00:00
|
|
|
timestamp: ts,
|
|
|
|
updatedAt: DateTime.tryParse(json["updated_at"] as String? ?? "") ?? ts,
|
2022-10-02 20:46:50 +00:00
|
|
|
payInCurrency: json["currency_from"] as String,
|
|
|
|
payInAmount: json["amount_from"] as String,
|
|
|
|
payInAddress: json["address_from"] as String,
|
|
|
|
payInNetwork: "",
|
2022-10-04 22:10:50 +00:00
|
|
|
payInExtraId: json["extra_id_from"] as String? ?? "",
|
|
|
|
payInTxid: json["tx_from"] as String? ?? "",
|
2022-10-02 20:46:50 +00:00
|
|
|
payOutCurrency: json["currency_to"] as String,
|
|
|
|
payOutAmount: json["amount_to"] as String,
|
|
|
|
payOutAddress: json["address_to"] as String,
|
|
|
|
payOutNetwork: "",
|
|
|
|
payOutExtraId: json["extra_id_to"] as String? ?? "",
|
2022-10-04 22:10:50 +00:00
|
|
|
payOutTxid: json["tx_to"] as String? ?? "",
|
2022-10-02 19:37:11 +00:00
|
|
|
refundAddress: json["user_refund_address"] as String,
|
|
|
|
refundExtraId: json["user_refund_extra_id"] as String,
|
|
|
|
status: json["status"] as String,
|
2022-10-03 00:54:35 +00:00
|
|
|
exchangeName: SimpleSwapExchange.exchangeName,
|
2022-10-02 19:37:11 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
return ExchangeResponse(value: trade);
|
|
|
|
} catch (e, s) {
|
|
|
|
Logging.instance
|
|
|
|
.log("getExchange exception: $e\n$s", level: LogLevel.Error);
|
|
|
|
return ExchangeResponse(
|
|
|
|
exception: ExchangeException(
|
|
|
|
e.toString(),
|
|
|
|
ExchangeExceptionType.generic,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// returns the minimal exchange amount
|
|
|
|
Future<ExchangeResponse<Range>> getRange({
|
|
|
|
required bool isFixedRate,
|
|
|
|
required String currencyFrom,
|
|
|
|
required String currencyTo,
|
|
|
|
String? apiKey,
|
|
|
|
}) async {
|
|
|
|
final uri = _buildUri(
|
|
|
|
"/get_ranges",
|
|
|
|
{
|
|
|
|
"api_key": apiKey ?? kSimpleSwapApiKey,
|
|
|
|
"fixed": isFixedRate.toString(),
|
|
|
|
"currency_from": currencyFrom,
|
|
|
|
"currency_to": currencyTo,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
try {
|
|
|
|
final jsonObject = await _makeGetRequest(uri);
|
|
|
|
|
|
|
|
final json = Map<String, dynamic>.from(jsonObject as Map);
|
|
|
|
return ExchangeResponse(
|
|
|
|
value: Range(
|
|
|
|
max: Decimal.tryParse(json["max"] as String? ?? ""),
|
|
|
|
min: Decimal.tryParse(json["min"] as String? ?? ""),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
} catch (e, s) {
|
|
|
|
Logging.instance.log("getRange exception: $e\n$s", level: LogLevel.Error);
|
|
|
|
return ExchangeResponse(
|
|
|
|
exception: ExchangeException(
|
|
|
|
e.toString(),
|
|
|
|
ExchangeExceptionType.generic,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2022-10-03 16:30:50 +00:00
|
|
|
|
|
|
|
Future<ExchangeResponse<List<FixedRateMarket>>> getFixedRateMarketInfo({
|
|
|
|
String? apiKey,
|
|
|
|
}) async {
|
|
|
|
final uri = _buildUri(
|
|
|
|
"/get_market_info",
|
|
|
|
null,
|
|
|
|
// {
|
|
|
|
// "api_key": apiKey ?? kSimpleSwapApiKey,
|
|
|
|
// "fixed": isFixedRate.toString(),
|
|
|
|
// "currency_from": currencyFrom,
|
|
|
|
// "currency_to": currencyTo,
|
|
|
|
// },
|
|
|
|
);
|
|
|
|
|
|
|
|
try {
|
|
|
|
final jsonArray = await _makeGetRequest(uri);
|
|
|
|
|
|
|
|
try {
|
|
|
|
final result = await compute(
|
|
|
|
_parseFixedRateMarketsJson,
|
|
|
|
jsonArray as List,
|
|
|
|
);
|
|
|
|
return result;
|
|
|
|
} catch (e, s) {
|
|
|
|
Logging.instance.log("getAvailableFixedRateMarkets exception: $e\n$s",
|
|
|
|
level: LogLevel.Error);
|
|
|
|
return ExchangeResponse(
|
|
|
|
exception: ExchangeException(
|
|
|
|
"Error: $jsonArray",
|
|
|
|
ExchangeExceptionType.serializeResponseError,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} catch (e, s) {
|
|
|
|
Logging.instance.log("getAvailableFixedRateMarkets exception: $e\n$s",
|
|
|
|
level: LogLevel.Error);
|
|
|
|
return ExchangeResponse(
|
|
|
|
exception: ExchangeException(
|
|
|
|
e.toString(),
|
|
|
|
ExchangeExceptionType.generic,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ExchangeResponse<List<FixedRateMarket>> _parseFixedRateMarketsJson(
|
|
|
|
List<dynamic> jsonArray) {
|
|
|
|
try {
|
|
|
|
final List<FixedRateMarket> markets = [];
|
|
|
|
for (final json in jsonArray) {
|
|
|
|
try {
|
|
|
|
final map = Map<String, dynamic>.from(json as Map);
|
|
|
|
markets.add(FixedRateMarket(
|
|
|
|
from: map["currency_from"] as String,
|
|
|
|
to: map["currency_to"] as String,
|
|
|
|
min: Decimal.parse(map["min"] as String),
|
|
|
|
max: Decimal.parse(map["max"] as String),
|
|
|
|
rate: Decimal.parse(map["rate"] as String),
|
|
|
|
minerFee: null,
|
|
|
|
));
|
|
|
|
} catch (_) {
|
|
|
|
return ExchangeResponse(
|
|
|
|
exception: ExchangeException("Failed to serialize $json",
|
|
|
|
ExchangeExceptionType.serializeResponseError));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ExchangeResponse(value: markets);
|
|
|
|
} catch (_) {
|
|
|
|
rethrow;
|
|
|
|
}
|
|
|
|
}
|
2022-10-02 19:37:11 +00:00
|
|
|
}
|