refactor changenow api

This commit is contained in:
julian 2022-10-02 14:53:53 -06:00
parent cdcda481bf
commit 9af457d1c6
16 changed files with 447 additions and 387 deletions

View file

@ -1,24 +0,0 @@
enum ChangeNowExceptionType { generic, serializeResponseError }
class ChangeNowException implements Exception {
String errorMessage;
ChangeNowExceptionType type;
ChangeNowException(this.errorMessage, this.type);
@override
String toString() {
return errorMessage;
}
}
class ChangeNowResponse<T> {
late final T? value;
late final ChangeNowException? exception;
ChangeNowResponse({this.value, this.exception});
@override
String toString() {
return "{ error: $exception, value: $value }";
}
}

View file

@ -2,12 +2,12 @@ import 'package:decimal/decimal.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:stackwallet/models/exchange/response_objects/currency.dart';
import 'package:stackwallet/services/change_now/change_now.dart';
import 'package:stackwallet/services/exchange/change_now/change_now_api.dart';
import 'package:stackwallet/utilities/logger.dart';
class EstimatedRateExchangeFormState extends ChangeNotifier {
/// used in testing to inject mock
ChangeNow? cnTesting;
ChangeNowAPI? cnTesting;
Decimal? _fromAmount;
Decimal? _toAmount;
@ -195,7 +195,7 @@ class EstimatedRateExchangeFormState extends ChangeNotifier {
required Currency to,
}) async {
final response =
await (cnTesting ?? ChangeNow.instance).getEstimatedExchangeAmount(
await (cnTesting ?? ChangeNowAPI.instance).getEstimatedExchangeAmount(
fromTicker: from.ticker,
toTicker: to.ticker,
fromAmount: fromAmount,
@ -234,7 +234,7 @@ class EstimatedRateExchangeFormState extends ChangeNotifier {
required Currency from,
required Currency to,
}) async {
final response = await (cnTesting ?? ChangeNow.instance)
final response = await (cnTesting ?? ChangeNowAPI.instance)
.getMinimalExchangeAmount(fromTicker: from.ticker, toTicker: to.ticker);
if (response.value != null) {

View file

@ -2,7 +2,7 @@ import 'package:decimal/decimal.dart';
import 'package:flutter/cupertino.dart';
import 'package:stackwallet/models/exchange/change_now/cn_exchange_estimate.dart';
import 'package:stackwallet/models/exchange/change_now/fixed_rate_market.dart';
import 'package:stackwallet/services/change_now/change_now.dart';
import 'package:stackwallet/services/exchange/change_now/change_now_api.dart';
import 'package:stackwallet/utilities/logger.dart';
class FixedRateExchangeFormState extends ChangeNotifier {
@ -153,7 +153,8 @@ class FixedRateExchangeFormState extends ChangeNotifier {
}
if (amount != null && market != null && amount > Decimal.zero) {
final response = await ChangeNow.instance.getEstimatedExchangeAmountV2(
final response =
await ChangeNowAPI.instance.getEstimatedExchangeAmountV2(
fromTicker: market!.from,
toTicker: market!.to,
fromOrTo: direction,

View file

@ -2,7 +2,6 @@ import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:stackwallet/models/exchange/change_now/change_now_response.dart';
import 'package:stackwallet/models/exchange/change_now/exchange_transaction.dart';
import 'package:stackwallet/models/exchange/incomplete_exchange.dart';
import 'package:stackwallet/pages/exchange_view/exchange_step_views/step_4_view.dart';
@ -10,6 +9,7 @@ import 'package:stackwallet/pages/exchange_view/sub_widgets/exchange_rate_sheet.
import 'package:stackwallet/pages/exchange_view/sub_widgets/step_row.dart';
import 'package:stackwallet/providers/exchange/change_now_provider.dart';
import 'package:stackwallet/providers/global/trades_service_provider.dart';
import 'package:stackwallet/services/exchange/exchange_response.dart';
import 'package:stackwallet/services/notifications_api.dart';
import 'package:stackwallet/utilities/assets.dart';
import 'package:stackwallet/utilities/clipboard_interface.dart';
@ -243,7 +243,7 @@ class _Step3ViewState extends ConsumerState<Step3View> {
),
);
ChangeNowResponse<ExchangeTransaction>
ExchangeResponse<ExchangeTransaction>
response;
if (model.rateType ==
ExchangeRateType.estimated) {

View file

@ -13,7 +13,7 @@ import 'package:stackwallet/pages/wallets_view/wallets_view.dart';
import 'package:stackwallet/providers/global/notifications_provider.dart';
import 'package:stackwallet/providers/ui/home_view_index_provider.dart';
import 'package:stackwallet/providers/ui/unread_notifications_provider.dart';
import 'package:stackwallet/services/change_now/change_now_loading_service.dart';
import 'package:stackwallet/services/exchange/change_now/change_now_loading_service.dart';
import 'package:stackwallet/utilities/assets.dart';
import 'package:stackwallet/utilities/constants.dart';
import 'package:stackwallet/utilities/text_styles.dart';

View file

@ -26,12 +26,12 @@ import 'package:stackwallet/providers/ui/transaction_filter_provider.dart';
import 'package:stackwallet/providers/ui/unread_notifications_provider.dart';
import 'package:stackwallet/providers/wallet/public_private_balance_state_provider.dart';
import 'package:stackwallet/providers/wallet/wallet_balance_toggle_state_provider.dart';
import 'package:stackwallet/services/change_now/change_now_loading_service.dart';
import 'package:stackwallet/services/coins/firo/firo_wallet.dart';
import 'package:stackwallet/services/coins/manager.dart';
import 'package:stackwallet/services/event_bus/events/global/node_connection_status_changed_event.dart';
import 'package:stackwallet/services/event_bus/events/global/wallet_sync_status_changed_event.dart';
import 'package:stackwallet/services/event_bus/global_event_bus.dart';
import 'package:stackwallet/services/exchange/change_now/change_now_loading_service.dart';
import 'package:stackwallet/utilities/assets.dart';
import 'package:stackwallet/utilities/constants.dart';
import 'package:stackwallet/utilities/enums/backup_frequency_type.dart';

View file

@ -1,4 +1,5 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:stackwallet/services/change_now/change_now.dart';
import 'package:stackwallet/services/exchange/change_now/change_now_api.dart';
final changeNowProvider = Provider<ChangeNow>((ref) => ChangeNow.instance);
final changeNowProvider =
Provider<ChangeNowAPI>((ref) => ChangeNowAPI.instance);

View file

@ -5,24 +5,24 @@ import 'package:flutter/foundation.dart';
import 'package:http/http.dart' as http;
import 'package:stackwallet/external_api_keys.dart';
import 'package:stackwallet/models/exchange/change_now/available_floating_rate_pair.dart';
import 'package:stackwallet/models/exchange/change_now/change_now_response.dart';
import 'package:stackwallet/models/exchange/change_now/cn_exchange_estimate.dart';
import 'package:stackwallet/models/exchange/change_now/estimated_exchange_amount.dart';
import 'package:stackwallet/models/exchange/change_now/exchange_transaction.dart';
import 'package:stackwallet/models/exchange/change_now/exchange_transaction_status.dart';
import 'package:stackwallet/models/exchange/change_now/fixed_rate_market.dart';
import 'package:stackwallet/models/exchange/response_objects/currency.dart';
import 'package:stackwallet/services/exchange/exchange_response.dart';
import 'package:stackwallet/utilities/logger.dart';
class ChangeNow {
class ChangeNowAPI {
static const String scheme = "https";
static const String authority = "api.changenow.io";
static const String apiVersion = "/v1";
static const String apiVersionV2 = "/v2";
ChangeNow._();
static final ChangeNow _instance = ChangeNow._();
static ChangeNow get instance => _instance;
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;
@ -100,7 +100,7 @@ class ChangeNow {
///
/// Set [active] to true to return only active currencies.
/// Set [fixedRate] to true to return only currencies available on a fixed-rate flow.
Future<ChangeNowResponse<List<Currency>>> getAvailableCurrencies({
Future<ExchangeResponse<List<Currency>>> getAvailableCurrencies({
bool? fixedRate,
bool? active,
}) async {
@ -129,26 +129,26 @@ class ChangeNow {
} catch (e, s) {
Logging.instance.log("getAvailableCurrencies exception: $e\n$s",
level: LogLevel.Error);
return ChangeNowResponse(
exception: ChangeNowException(
return ExchangeResponse(
exception: ExchangeException(
"Error: $jsonArray",
ChangeNowExceptionType.serializeResponseError,
ExchangeExceptionType.serializeResponseError,
),
);
}
} catch (e, s) {
Logging.instance.log("getAvailableCurrencies exception: $e\n$s",
level: LogLevel.Error);
return ChangeNowResponse(
exception: ChangeNowException(
return ExchangeResponse(
exception: ExchangeException(
e.toString(),
ChangeNowExceptionType.generic,
ExchangeExceptionType.generic,
),
);
}
}
ChangeNowResponse<List<Currency>> _parseAvailableCurrenciesJson(
ExchangeResponse<List<Currency>> _parseAvailableCurrenciesJson(
List<dynamic> jsonArray) {
try {
List<Currency> currencies = [];
@ -158,13 +158,13 @@ class ChangeNow {
currencies
.add(Currency.fromJson(Map<String, dynamic>.from(json as Map)));
} catch (_) {
return ChangeNowResponse(
exception: ChangeNowException("Failed to serialize $json",
ChangeNowExceptionType.serializeResponseError));
return ExchangeResponse(
exception: ExchangeException("Failed to serialize $json",
ExchangeExceptionType.serializeResponseError));
}
}
return ChangeNowResponse(value: currencies);
return ExchangeResponse(value: currencies);
} catch (_) {
rethrow;
}
@ -175,7 +175,7 @@ class ChangeNow {
///
/// Required [ticker] to fetch paired currencies for.
/// Set [fixedRate] to true to return only currencies available on a fixed-rate flow.
Future<ChangeNowResponse<List<Currency>>> getPairedCurrencies({
Future<ExchangeResponse<List<Currency>>> getPairedCurrencies({
required String ticker,
bool? fixedRate,
}) async {
@ -199,10 +199,10 @@ class ChangeNow {
currencies
.add(Currency.fromJson(Map<String, dynamic>.from(json as Map)));
} catch (_) {
return ChangeNowResponse(
exception: ChangeNowException(
return ExchangeResponse(
exception: ExchangeException(
"Failed to serialize $json",
ChangeNowExceptionType.serializeResponseError,
ExchangeExceptionType.serializeResponseError,
),
);
}
@ -210,18 +210,18 @@ class ChangeNow {
} catch (e, s) {
Logging.instance.log("getPairedCurrencies exception: $e\n$s",
level: LogLevel.Error);
return ChangeNowResponse(
exception: ChangeNowException("Error: $jsonArray",
ChangeNowExceptionType.serializeResponseError));
return ExchangeResponse(
exception: ExchangeException("Error: $jsonArray",
ExchangeExceptionType.serializeResponseError));
}
return ChangeNowResponse(value: currencies);
return ExchangeResponse(value: currencies);
} catch (e, s) {
Logging.instance
.log("getPairedCurrencies exception: $e\n$s", level: LogLevel.Error);
return ChangeNowResponse(
exception: ChangeNowException(
return ExchangeResponse(
exception: ExchangeException(
e.toString(),
ChangeNowExceptionType.generic,
ExchangeExceptionType.generic,
),
);
}
@ -230,7 +230,7 @@ class ChangeNow {
/// The API endpoint returns minimal payment amount required to make
/// an exchange of [fromTicker] to [toTicker].
/// If you try to exchange less, the transaction will most likely fail.
Future<ChangeNowResponse<Decimal>> getMinimalExchangeAmount({
Future<ExchangeResponse<Decimal>> getMinimalExchangeAmount({
required String fromTicker,
required String toTicker,
String? apiKey,
@ -245,22 +245,22 @@ class ChangeNow {
try {
final value = Decimal.parse(json["minAmount"].toString());
return ChangeNowResponse(value: value);
return ExchangeResponse(value: value);
} catch (_) {
return ChangeNowResponse(
exception: ChangeNowException(
return ExchangeResponse(
exception: ExchangeException(
"Failed to serialize $json",
ChangeNowExceptionType.serializeResponseError,
ExchangeExceptionType.serializeResponseError,
),
);
}
} catch (e, s) {
Logging.instance.log("getMinimalExchangeAmount exception: $e\n$s",
level: LogLevel.Error);
return ChangeNowResponse(
exception: ChangeNowException(
return ExchangeResponse(
exception: ExchangeException(
e.toString(),
ChangeNowExceptionType.generic,
ExchangeExceptionType.generic,
),
);
}
@ -268,8 +268,7 @@ class ChangeNow {
/// Get estimated amount of [toTicker] cryptocurrency to receive
/// for [fromAmount] of [fromTicker]
Future<ChangeNowResponse<EstimatedExchangeAmount>>
getEstimatedExchangeAmount({
Future<ExchangeResponse<EstimatedExchangeAmount>> getEstimatedExchangeAmount({
required String fromTicker,
required String toTicker,
required Decimal fromAmount,
@ -289,22 +288,22 @@ class ChangeNow {
try {
final value = EstimatedExchangeAmount.fromJson(
Map<String, dynamic>.from(json as Map));
return ChangeNowResponse(value: value);
return ExchangeResponse(value: value);
} catch (_) {
return ChangeNowResponse(
exception: ChangeNowException(
return ExchangeResponse(
exception: ExchangeException(
"Failed to serialize $json",
ChangeNowExceptionType.serializeResponseError,
ExchangeExceptionType.serializeResponseError,
),
);
}
} catch (e, s) {
Logging.instance.log("getEstimatedExchangeAmount exception: $e\n$s",
level: LogLevel.Error);
return ChangeNowResponse(
exception: ChangeNowException(
return ExchangeResponse(
exception: ExchangeException(
e.toString(),
ChangeNowExceptionType.generic,
ExchangeExceptionType.generic,
),
);
}
@ -313,7 +312,7 @@ class ChangeNow {
// old v1 version
/// This API endpoint returns fixed-rate estimated exchange amount of
/// [toTicker] cryptocurrency to receive for [fromAmount] of [fromTicker]
// Future<ChangeNowResponse<EstimatedExchangeAmount>>
// Future<ExchangeResponse<EstimatedExchangeAmount>>
// getEstimatedFixedRateExchangeAmount({
// required String fromTicker,
// required String toTicker,
@ -342,12 +341,12 @@ class ChangeNow {
// try {
// final value = EstimatedExchangeAmount.fromJson(
// Map<String, dynamic>.from(json as Map));
// return ChangeNowResponse(value: value);
// return ExchangeResponse(value: value);
// } catch (_) {
// return ChangeNowResponse(
// exception: ChangeNowException(
// return ExchangeResponse(
// exception: ExchangeException(
// "Failed to serialize $json",
// ChangeNowExceptionType.serializeResponseError,
// ExchangeExceptionType.serializeResponseError,
// ),
// );
// }
@ -355,10 +354,10 @@ class ChangeNow {
// Logging.instance.log(
// "getEstimatedFixedRateExchangeAmount exception: $e\n$s",
// level: LogLevel.Error);
// return ChangeNowResponse(
// exception: ChangeNowException(
// return ExchangeResponse(
// exception: ExchangeException(
// e.toString(),
// ChangeNowExceptionType.generic,
// ExchangeExceptionType.generic,
// ),
// );
// }
@ -366,7 +365,7 @@ class ChangeNow {
/// Get estimated amount of [toTicker] cryptocurrency to receive
/// for [fromAmount] of [fromTicker]
Future<ChangeNowResponse<CNExchangeEstimate>> getEstimatedExchangeAmountV2({
Future<ExchangeResponse<CNExchangeEstimate>> getEstimatedExchangeAmountV2({
required String fromTicker,
required String toTicker,
required CNEstimateType fromOrTo,
@ -413,22 +412,22 @@ class ChangeNow {
try {
final value =
CNExchangeEstimate.fromJson(Map<String, dynamic>.from(json as Map));
return ChangeNowResponse(value: value);
return ExchangeResponse(value: value);
} catch (_) {
return ChangeNowResponse(
exception: ChangeNowException(
return ExchangeResponse(
exception: ExchangeException(
"Failed to serialize $json",
ChangeNowExceptionType.serializeResponseError,
ExchangeExceptionType.serializeResponseError,
),
);
}
} catch (e, s) {
Logging.instance.log("getEstimatedExchangeAmountV2 exception: $e\n$s",
level: LogLevel.Error);
return ChangeNowResponse(
exception: ChangeNowException(
return ExchangeResponse(
exception: ExchangeException(
e.toString(),
ChangeNowExceptionType.generic,
ExchangeExceptionType.generic,
),
);
}
@ -438,8 +437,7 @@ class ChangeNow {
/// fixed-rate flow. Some currencies get enabled or disabled from time to
/// time and the market info gets updates, so make sure to refresh the list
/// occasionally. One time per minute is sufficient.
Future<ChangeNowResponse<List<FixedRateMarket>>>
getAvailableFixedRateMarkets({
Future<ExchangeResponse<List<FixedRateMarket>>> getAvailableFixedRateMarkets({
String? apiKey,
}) async {
final uri = _buildUri(
@ -456,26 +454,26 @@ class ChangeNow {
} catch (e, s) {
Logging.instance.log("getAvailableFixedRateMarkets exception: $e\n$s",
level: LogLevel.Error);
return ChangeNowResponse(
exception: ChangeNowException(
return ExchangeResponse(
exception: ExchangeException(
"Error: $jsonArray",
ChangeNowExceptionType.serializeResponseError,
ExchangeExceptionType.serializeResponseError,
),
);
}
} catch (e, s) {
Logging.instance.log("getAvailableFixedRateMarkets exception: $e\n$s",
level: LogLevel.Error);
return ChangeNowResponse(
exception: ChangeNowException(
return ExchangeResponse(
exception: ExchangeException(
e.toString(),
ChangeNowExceptionType.generic,
ExchangeExceptionType.generic,
),
);
}
}
ChangeNowResponse<List<FixedRateMarket>> _parseFixedRateMarketsJson(
ExchangeResponse<List<FixedRateMarket>> _parseFixedRateMarketsJson(
List<dynamic> jsonArray) {
try {
List<FixedRateMarket> markets = [];
@ -484,12 +482,12 @@ class ChangeNow {
markets.add(
FixedRateMarket.fromJson(Map<String, dynamic>.from(json as Map)));
} catch (_) {
return ChangeNowResponse(
exception: ChangeNowException("Failed to serialize $json",
ChangeNowExceptionType.serializeResponseError));
return ExchangeResponse(
exception: ExchangeException("Failed to serialize $json",
ExchangeExceptionType.serializeResponseError));
}
}
return ChangeNowResponse(value: markets);
return ExchangeResponse(value: markets);
} catch (_) {
rethrow;
}
@ -497,7 +495,7 @@ class ChangeNow {
/// The API endpoint creates a transaction, generates an address for
/// sending funds and returns transaction attributes.
Future<ChangeNowResponse<ExchangeTransaction>>
Future<ExchangeResponse<ExchangeTransaction>>
createStandardExchangeTransaction({
required String fromTicker,
required String toTicker,
@ -535,12 +533,12 @@ class ChangeNow {
try {
final value = ExchangeTransaction.fromJson(
Map<String, dynamic>.from(json as Map));
return ChangeNowResponse(value: value);
return ExchangeResponse(value: value);
} catch (_) {
return ChangeNowResponse(
exception: ChangeNowException(
return ExchangeResponse(
exception: ExchangeException(
"Failed to serialize $json",
ChangeNowExceptionType.serializeResponseError,
ExchangeExceptionType.serializeResponseError,
),
);
}
@ -548,10 +546,10 @@ class ChangeNow {
Logging.instance.log(
"createStandardExchangeTransaction exception: $e\n$s",
level: LogLevel.Error);
return ChangeNowResponse(
exception: ChangeNowException(
return ExchangeResponse(
exception: ExchangeException(
e.toString(),
ChangeNowExceptionType.generic,
ExchangeExceptionType.generic,
),
);
}
@ -559,7 +557,7 @@ class ChangeNow {
/// The API endpoint creates a transaction, generates an address for
/// sending funds and returns transaction attributes.
Future<ChangeNowResponse<ExchangeTransaction>>
Future<ExchangeResponse<ExchangeTransaction>>
createFixedRateExchangeTransaction({
required String fromTicker,
required String toTicker,
@ -600,12 +598,12 @@ class ChangeNow {
try {
final value = ExchangeTransaction.fromJson(
Map<String, dynamic>.from(json as Map));
return ChangeNowResponse(value: value);
return ExchangeResponse(value: value);
} catch (_) {
return ChangeNowResponse(
exception: ChangeNowException(
return ExchangeResponse(
exception: ExchangeException(
"Failed to serialize $json",
ChangeNowExceptionType.serializeResponseError,
ExchangeExceptionType.serializeResponseError,
),
);
}
@ -613,16 +611,16 @@ class ChangeNow {
Logging.instance.log(
"createFixedRateExchangeTransaction exception: $e\n$s",
level: LogLevel.Error);
return ChangeNowResponse(
exception: ChangeNowException(
return ExchangeResponse(
exception: ExchangeException(
e.toString(),
ChangeNowExceptionType.generic,
ExchangeExceptionType.generic,
),
);
}
}
Future<ChangeNowResponse<ExchangeTransactionStatus>> getTransactionStatus({
Future<ExchangeResponse<ExchangeTransactionStatus>> getTransactionStatus({
required String id,
String? apiKey,
}) async {
@ -636,28 +634,28 @@ class ChangeNow {
try {
final value = ExchangeTransactionStatus.fromJson(
Map<String, dynamic>.from(json as Map));
return ChangeNowResponse(value: value);
return ExchangeResponse(value: value);
} catch (_) {
return ChangeNowResponse(
exception: ChangeNowException(
return ExchangeResponse(
exception: ExchangeException(
"Failed to serialize $json",
ChangeNowExceptionType.serializeResponseError,
ExchangeExceptionType.serializeResponseError,
),
);
}
} catch (e, s) {
Logging.instance
.log("getTransactionStatus exception: $e\n$s", level: LogLevel.Error);
return ChangeNowResponse(
exception: ChangeNowException(
return ExchangeResponse(
exception: ExchangeException(
e.toString(),
ChangeNowExceptionType.generic,
ExchangeExceptionType.generic,
),
);
}
}
Future<ChangeNowResponse<List<AvailableFloatingRatePair>>>
Future<ExchangeResponse<List<AvailableFloatingRatePair>>>
getAvailableFloatingRatePairs({
bool includePartners = false,
}) async {
@ -675,26 +673,26 @@ class ChangeNow {
} catch (e, s) {
Logging.instance.log("getAvailableFloatingRatePairs exception: $e\n$s",
level: LogLevel.Error);
return ChangeNowResponse(
exception: ChangeNowException(
return ExchangeResponse(
exception: ExchangeException(
"Error: $jsonArray",
ChangeNowExceptionType.serializeResponseError,
ExchangeExceptionType.serializeResponseError,
),
);
}
} catch (e, s) {
Logging.instance.log("getAvailableFloatingRatePairs exception: $e\n$s",
level: LogLevel.Error);
return ChangeNowResponse(
exception: ChangeNowException(
return ExchangeResponse(
exception: ExchangeException(
e.toString(),
ChangeNowExceptionType.generic,
ExchangeExceptionType.generic,
),
);
}
}
ChangeNowResponse<List<AvailableFloatingRatePair>>
ExchangeResponse<List<AvailableFloatingRatePair>>
_parseAvailableFloatingRatePairsJson(List<dynamic> jsonArray) {
try {
List<AvailableFloatingRatePair> pairs = [];
@ -704,12 +702,12 @@ class ChangeNow {
pairs.add(AvailableFloatingRatePair(
fromTicker: stringPair[0], toTicker: stringPair[1]));
} catch (_) {
return ChangeNowResponse(
exception: ChangeNowException("Failed to serialize $json",
ChangeNowExceptionType.serializeResponseError));
return ExchangeResponse(
exception: ExchangeException("Failed to serialize $json",
ExchangeExceptionType.serializeResponseError));
}
}
return ChangeNowResponse(value: pairs);
return ExchangeResponse(value: pairs);
} catch (_) {
rethrow;
}

View file

@ -0,0 +1,79 @@
import 'package:decimal/decimal.dart';
import 'package:stackwallet/models/exchange/response_objects/currency.dart';
import 'package:stackwallet/models/exchange/response_objects/pair.dart';
import 'package:stackwallet/models/exchange/response_objects/range.dart';
import 'package:stackwallet/models/exchange/response_objects/trade.dart';
import 'package:stackwallet/services/exchange/exchange.dart';
import 'package:stackwallet/services/exchange/exchange_response.dart';
class ChangeNowExchange extends Exchange {
@override
Future<ExchangeResponse<Trade>> createTrade({
required String from,
required String to,
required bool fixedRate,
required Decimal amount,
required String addressTo,
required String addressRefund,
required String refundExtraId,
}) async {
// TODO: implement createTrade
throw UnimplementedError();
}
@override
Future<ExchangeResponse<List<Currency>>> getAllCurrencies(
bool fixedRate,
) async {
// TODO: implement getAllCurrencies
throw UnimplementedError();
}
@override
Future<ExchangeResponse<List<Pair>>> getAllPairs(bool fixedRate) async {
// TODO: implement getAllPairs
throw UnimplementedError();
}
@override
Future<ExchangeResponse<Decimal>> getEstimate(
String from,
String to,
Decimal amount,
bool fixedRate,
) async {
// TODO: implement getEstimate
throw UnimplementedError();
}
@override
Future<ExchangeResponse<Range>> getMinMaxExchangeAmounts(
String from,
String to,
bool fixedRate,
) async {
// TODO: implement getMinMaxExchangeAmounts
throw UnimplementedError();
}
@override
Future<ExchangeResponse<List<Pair>>> getPairsFor(
String currency,
bool fixedRate,
) async {
// TODO: implement getPairsFor
throw UnimplementedError();
}
@override
Future<ExchangeResponse<Trade>> getTrade(String tradeId) async {
// TODO: implement getTrade
throw UnimplementedError();
}
@override
Future<ExchangeResponse<List<Trade>>> getTrades() async {
// TODO: implement getTrades
throw UnimplementedError();
}
}

View file

@ -5,7 +5,7 @@ import 'package:stackwallet/electrumx_rpc/electrumx.dart';
import 'package:stackwallet/hive/db.dart';
import 'package:stackwallet/models/exchange/change_now/exchange_transaction_status.dart';
import 'package:stackwallet/models/notification_model.dart';
import 'package:stackwallet/services/change_now/change_now.dart';
import 'package:stackwallet/services/exchange/change_now/change_now_api.dart';
import 'package:stackwallet/services/node_service.dart';
import 'package:stackwallet/services/notifications_api.dart';
import 'package:stackwallet/services/trade_service.dart';
@ -17,7 +17,7 @@ class NotificationsService extends ChangeNotifier {
late NodeService nodeService;
late TradesService tradesService;
late Prefs prefs;
late ChangeNow changeNow;
late ChangeNowAPI changeNow;
NotificationsService._();
static final NotificationsService _instance = NotificationsService._();
@ -27,7 +27,7 @@ class NotificationsService extends ChangeNotifier {
required NodeService nodeService,
required TradesService tradesService,
required Prefs prefs,
required ChangeNow changeNow,
required ChangeNowAPI changeNow,
}) async {
this.nodeService = nodeService;
this.tradesService = tradesService;

View file

@ -2,15 +2,15 @@ import 'package:decimal/decimal.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'package:stackwallet/models/exchange/change_now/change_now_response.dart';
import 'package:stackwallet/models/exchange/change_now/estimated_exchange_amount.dart';
import 'package:stackwallet/models/exchange/estimated_rate_exchange_form_state.dart';
import 'package:stackwallet/models/exchange/response_objects/currency.dart';
import 'package:stackwallet/services/change_now/change_now.dart';
import 'package:stackwallet/services/exchange/change_now/change_now_api.dart';
import 'package:stackwallet/services/exchange/exchange_response.dart';
import 'estimated_rate_exchange_form_state_test.mocks.dart';
@GenerateMocks([ChangeNow])
@GenerateMocks([ChangeNowAPI])
void main() {
final currencyA = Currency(
ticker: "btc",
@ -98,7 +98,7 @@ void main() {
state.cnTesting = cn;
when(cn.getMinimalExchangeAmount(fromTicker: "btc", toTicker: "xmr"))
.thenAnswer((_) async => ChangeNowResponse(value: Decimal.fromInt(42)));
.thenAnswer((_) async => ExchangeResponse(value: Decimal.fromInt(42)));
await state.updateFrom(currencyA, true);
await state.updateTo(currencyB, true);
@ -125,7 +125,7 @@ void main() {
state.cnTesting = cn;
when(cn.getMinimalExchangeAmount(fromTicker: "btc", toTicker: "xmr"))
.thenAnswer((_) async => ChangeNowResponse());
.thenAnswer((_) async => ExchangeResponse());
await state.updateFrom(currencyA, true);
await state.updateTo(currencyB, true);
@ -152,7 +152,7 @@ void main() {
state.cnTesting = cn;
when(cn.getMinimalExchangeAmount(fromTicker: "btc", toTicker: "xmr"))
.thenAnswer((_) async => ChangeNowResponse(value: Decimal.fromInt(42)));
.thenAnswer((_) async => ExchangeResponse(value: Decimal.fromInt(42)));
await state.updateFrom(currencyA, true);
await state.setFromAmountAndCalculateToAmount(Decimal.parse("10.10"), true);
@ -180,12 +180,12 @@ void main() {
state.cnTesting = cn;
when(cn.getMinimalExchangeAmount(fromTicker: "btc", toTicker: "xmr"))
.thenAnswer((_) async => ChangeNowResponse(value: Decimal.fromInt(42)));
.thenAnswer((_) async => ExchangeResponse(value: Decimal.fromInt(42)));
when(cn.getEstimatedExchangeAmount(
fromTicker: "btc",
toTicker: "xmr",
fromAmount: Decimal.parse("110.10")))
.thenAnswer((_) async => ChangeNowResponse(
.thenAnswer((_) async => ExchangeResponse(
value: EstimatedExchangeAmount(
transactionSpeedForecast: '10-60',
rateId: 'some rate id',

View file

@ -9,8 +9,6 @@ import 'package:http/http.dart' as _i4;
import 'package:mockito/mockito.dart' as _i1;
import 'package:stackwallet/models/exchange/change_now/available_floating_rate_pair.dart'
as _i13;
import 'package:stackwallet/models/exchange/change_now/change_now_response.dart'
as _i2;
import 'package:stackwallet/models/exchange/change_now/cn_exchange_estimate.dart'
as _i9;
import 'package:stackwallet/models/exchange/change_now/estimated_exchange_amount.dart'
@ -23,7 +21,9 @@ import 'package:stackwallet/models/exchange/change_now/fixed_rate_market.dart'
as _i10;
import 'package:stackwallet/models/exchange/response_objects/currency.dart'
as _i6;
import 'package:stackwallet/services/change_now/change_now.dart' as _i3;
import 'package:stackwallet/services/exchange/change_now/change_now_api.dart'
as _i3;
import 'package:stackwallet/services/exchange/exchange_response.dart' as _i2;
// ignore_for_file: type=lint
// ignore_for_file: avoid_redundant_argument_values
@ -36,12 +36,12 @@ import 'package:stackwallet/services/change_now/change_now.dart' as _i3;
// ignore_for_file: camel_case_types
class _FakeChangeNowResponse_0<T> extends _i1.Fake
implements _i2.ChangeNowResponse<T> {}
implements _i2.ExchangeResponse<T> {}
/// A class which mocks [ChangeNow].
///
/// See the documentation for Mockito's code generation for more information.
class MockChangeNow extends _i1.Mock implements _i3.ChangeNow {
class MockChangeNow extends _i1.Mock implements _i3.ChangeNowAPI {
MockChangeNow() {
_i1.throwOnMissingStub(this);
}
@ -51,25 +51,25 @@ class MockChangeNow extends _i1.Mock implements _i3.ChangeNow {
super.noSuchMethod(Invocation.setter(#client, _client),
returnValueForMissingStub: null);
@override
_i5.Future<_i2.ChangeNowResponse<List<_i6.Currency>>> getAvailableCurrencies(
_i5.Future<_i2.ExchangeResponse<List<_i6.Currency>>> getAvailableCurrencies(
{bool? fixedRate, bool? active}) =>
(super.noSuchMethod(
Invocation.method(#getAvailableCurrencies, [],
{#fixedRate: fixedRate, #active: active}),
returnValue: Future<_i2.ChangeNowResponse<List<_i6.Currency>>>.value(
returnValue: Future<_i2.ExchangeResponse<List<_i6.Currency>>>.value(
_FakeChangeNowResponse_0<List<_i6.Currency>>())) as _i5
.Future<_i2.ChangeNowResponse<List<_i6.Currency>>>);
.Future<_i2.ExchangeResponse<List<_i6.Currency>>>);
@override
_i5.Future<_i2.ChangeNowResponse<List<_i6.Currency>>> getPairedCurrencies(
_i5.Future<_i2.ExchangeResponse<List<_i6.Currency>>> getPairedCurrencies(
{String? ticker, bool? fixedRate}) =>
(super.noSuchMethod(
Invocation.method(#getPairedCurrencies, [],
{#ticker: ticker, #fixedRate: fixedRate}),
returnValue: Future<_i2.ChangeNowResponse<List<_i6.Currency>>>.value(
returnValue: Future<_i2.ExchangeResponse<List<_i6.Currency>>>.value(
_FakeChangeNowResponse_0<List<_i6.Currency>>())) as _i5
.Future<_i2.ChangeNowResponse<List<_i6.Currency>>>);
.Future<_i2.ExchangeResponse<List<_i6.Currency>>>);
@override
_i5.Future<_i2.ChangeNowResponse<_i7.Decimal>> getMinimalExchangeAmount(
_i5.Future<_i2.ExchangeResponse<_i7.Decimal>> getMinimalExchangeAmount(
{String? fromTicker, String? toTicker, String? apiKey}) =>
(super.noSuchMethod(
Invocation.method(#getMinimalExchangeAmount, [], {
@ -77,11 +77,11 @@ class MockChangeNow extends _i1.Mock implements _i3.ChangeNow {
#toTicker: toTicker,
#apiKey: apiKey
}),
returnValue: Future<_i2.ChangeNowResponse<_i7.Decimal>>.value(
returnValue: Future<_i2.ExchangeResponse<_i7.Decimal>>.value(
_FakeChangeNowResponse_0<_i7.Decimal>()))
as _i5.Future<_i2.ChangeNowResponse<_i7.Decimal>>);
as _i5.Future<_i2.ExchangeResponse<_i7.Decimal>>);
@override
_i5.Future<_i2.ChangeNowResponse<_i8.EstimatedExchangeAmount>>
_i5.Future<_i2.ExchangeResponse<_i8.EstimatedExchangeAmount>>
getEstimatedExchangeAmount(
{String? fromTicker,
String? toTicker,
@ -95,13 +95,12 @@ class MockChangeNow extends _i1.Mock implements _i3.ChangeNow {
#apiKey: apiKey
}),
returnValue: Future<
_i2.ChangeNowResponse<
_i2.ExchangeResponse<
_i8.EstimatedExchangeAmount>>.value(
_FakeChangeNowResponse_0<_i8.EstimatedExchangeAmount>()))
as _i5
.Future<_i2.ChangeNowResponse<_i8.EstimatedExchangeAmount>>);
as _i5.Future<_i2.ExchangeResponse<_i8.EstimatedExchangeAmount>>);
@override
_i5.Future<_i2.ChangeNowResponse<_i9.CNExchangeEstimate>>
_i5.Future<_i2.ExchangeResponse<_i9.CNExchangeEstimate>>
getEstimatedExchangeAmountV2(
{String? fromTicker,
String? toTicker,
@ -123,20 +122,20 @@ class MockChangeNow extends _i1.Mock implements _i3.ChangeNow {
#apiKey: apiKey
}),
returnValue: Future<
_i2.ChangeNowResponse<_i9.CNExchangeEstimate>>.value(
_i2.ExchangeResponse<_i9.CNExchangeEstimate>>.value(
_FakeChangeNowResponse_0<_i9.CNExchangeEstimate>()))
as _i5.Future<_i2.ChangeNowResponse<_i9.CNExchangeEstimate>>);
as _i5.Future<_i2.ExchangeResponse<_i9.CNExchangeEstimate>>);
@override
_i5.Future<_i2.ChangeNowResponse<List<_i10.FixedRateMarket>>>
_i5.Future<_i2.ExchangeResponse<List<_i10.FixedRateMarket>>>
getAvailableFixedRateMarkets({String? apiKey}) => (super.noSuchMethod(
Invocation.method(
#getAvailableFixedRateMarkets, [], {#apiKey: apiKey}),
returnValue:
Future<_i2.ChangeNowResponse<List<_i10.FixedRateMarket>>>.value(
_FakeChangeNowResponse_0<List<_i10.FixedRateMarket>>())) as _i5
.Future<_i2.ChangeNowResponse<List<_i10.FixedRateMarket>>>);
Invocation.method(
#getAvailableFixedRateMarkets, [], {#apiKey: apiKey}),
returnValue:
Future<_i2.ExchangeResponse<List<_i10.FixedRateMarket>>>.value(
_FakeChangeNowResponse_0<List<_i10.FixedRateMarket>>()))
as _i5.Future<_i2.ExchangeResponse<List<_i10.FixedRateMarket>>>);
@override
_i5.Future<_i2.ChangeNowResponse<_i11.ExchangeTransaction>>
_i5.Future<_i2.ExchangeResponse<_i11.ExchangeTransaction>>
createStandardExchangeTransaction(
{String? fromTicker,
String? toTicker,
@ -149,24 +148,24 @@ class MockChangeNow extends _i1.Mock implements _i3.ChangeNow {
String? refundExtraId = r'',
String? apiKey}) =>
(super.noSuchMethod(
Invocation.method(#createStandardExchangeTransaction, [], {
#fromTicker: fromTicker,
#toTicker: toTicker,
#receivingAddress: receivingAddress,
#amount: amount,
#extraId: extraId,
#userId: userId,
#contactEmail: contactEmail,
#refundAddress: refundAddress,
#refundExtraId: refundExtraId,
#apiKey: apiKey
}),
returnValue: Future<
_i2.ChangeNowResponse<_i11.ExchangeTransaction>>.value(
_FakeChangeNowResponse_0<_i11.ExchangeTransaction>())) as _i5
.Future<_i2.ChangeNowResponse<_i11.ExchangeTransaction>>);
Invocation.method(#createStandardExchangeTransaction, [], {
#fromTicker: fromTicker,
#toTicker: toTicker,
#receivingAddress: receivingAddress,
#amount: amount,
#extraId: extraId,
#userId: userId,
#contactEmail: contactEmail,
#refundAddress: refundAddress,
#refundExtraId: refundExtraId,
#apiKey: apiKey
}),
returnValue: Future<
_i2.ExchangeResponse<_i11.ExchangeTransaction>>.value(
_FakeChangeNowResponse_0<_i11.ExchangeTransaction>()))
as _i5.Future<_i2.ExchangeResponse<_i11.ExchangeTransaction>>);
@override
_i5.Future<_i2.ChangeNowResponse<_i11.ExchangeTransaction>>
_i5.Future<_i2.ExchangeResponse<_i11.ExchangeTransaction>>
createFixedRateExchangeTransaction(
{String? fromTicker,
String? toTicker,
@ -180,40 +179,40 @@ class MockChangeNow extends _i1.Mock implements _i3.ChangeNow {
String? refundExtraId = r'',
String? apiKey}) =>
(super.noSuchMethod(
Invocation.method(#createFixedRateExchangeTransaction, [], {
#fromTicker: fromTicker,
#toTicker: toTicker,
#receivingAddress: receivingAddress,
#amount: amount,
#rateId: rateId,
#extraId: extraId,
#userId: userId,
#contactEmail: contactEmail,
#refundAddress: refundAddress,
#refundExtraId: refundExtraId,
#apiKey: apiKey
}),
returnValue: Future<
_i2.ChangeNowResponse<_i11.ExchangeTransaction>>.value(
_FakeChangeNowResponse_0<_i11.ExchangeTransaction>())) as _i5
.Future<_i2.ChangeNowResponse<_i11.ExchangeTransaction>>);
Invocation.method(#createFixedRateExchangeTransaction, [], {
#fromTicker: fromTicker,
#toTicker: toTicker,
#receivingAddress: receivingAddress,
#amount: amount,
#rateId: rateId,
#extraId: extraId,
#userId: userId,
#contactEmail: contactEmail,
#refundAddress: refundAddress,
#refundExtraId: refundExtraId,
#apiKey: apiKey
}),
returnValue: Future<
_i2.ExchangeResponse<_i11.ExchangeTransaction>>.value(
_FakeChangeNowResponse_0<_i11.ExchangeTransaction>()))
as _i5.Future<_i2.ExchangeResponse<_i11.ExchangeTransaction>>);
@override
_i5.Future<_i2.ChangeNowResponse<_i12.ExchangeTransactionStatus>>
_i5.Future<_i2.ExchangeResponse<_i12.ExchangeTransactionStatus>>
getTransactionStatus({String? id, String? apiKey}) => (super.noSuchMethod(
Invocation.method(
#getTransactionStatus, [], {#id: id, #apiKey: apiKey}),
returnValue:
Future<_i2.ChangeNowResponse<_i12.ExchangeTransactionStatus>>.value(
Future<_i2.ExchangeResponse<_i12.ExchangeTransactionStatus>>.value(
_FakeChangeNowResponse_0<_i12.ExchangeTransactionStatus>())) as _i5
.Future<_i2.ChangeNowResponse<_i12.ExchangeTransactionStatus>>);
.Future<_i2.ExchangeResponse<_i12.ExchangeTransactionStatus>>);
@override
_i5.Future<_i2.ChangeNowResponse<List<_i13.AvailableFloatingRatePair>>>
_i5.Future<_i2.ExchangeResponse<List<_i13.AvailableFloatingRatePair>>>
getAvailableFloatingRatePairs({bool? includePartners = false}) => (super
.noSuchMethod(
Invocation.method(#getAvailableFloatingRatePairs, [],
{#includePartners: includePartners}),
returnValue:
Future<_i2.ChangeNowResponse<List<_i13.AvailableFloatingRatePair>>>.value(
Future<_i2.ExchangeResponse<List<_i13.AvailableFloatingRatePair>>>.value(
_FakeChangeNowResponse_0<List<_i13.AvailableFloatingRatePair>>())) as _i5
.Future<_i2.ChangeNowResponse<List<_i13.AvailableFloatingRatePair>>>);
.Future<_i2.ExchangeResponse<List<_i13.AvailableFloatingRatePair>>>);
}

View file

@ -1,10 +1,10 @@
import 'package:mockito/annotations.dart';
import 'package:stackwallet/services/change_now/change_now.dart';
import 'package:stackwallet/services/exchange/change_now/change_now_api.dart';
import 'package:stackwallet/services/trade_notes_service.dart';
import 'package:stackwallet/services/trade_service.dart';
import 'package:stackwallet/utilities/prefs.dart';
@GenerateMocks([Prefs, TradesService, TradeNotesService, ChangeNow])
@GenerateMocks([Prefs, TradesService, TradeNotesService, ChangeNowAPI])
void main() {
// testWidgets("ExchangeView builds correctly with no trade history",
// (widgetTester) async {

View file

@ -10,8 +10,6 @@ import 'package:http/http.dart' as _i13;
import 'package:mockito/mockito.dart' as _i1;
import 'package:stackwallet/models/exchange/change_now/available_floating_rate_pair.dart'
as _i20;
import 'package:stackwallet/models/exchange/change_now/change_now_response.dart'
as _i2;
import 'package:stackwallet/models/exchange/change_now/cn_exchange_estimate.dart'
as _i17;
import 'package:stackwallet/models/exchange/change_now/estimated_exchange_amount.dart'
@ -26,7 +24,9 @@ import 'package:stackwallet/models/exchange/response_objects/currency.dart'
as _i14;
import 'package:stackwallet/pages/exchange_view/sub_widgets/exchange_rate_sheet.dart'
as _i5;
import 'package:stackwallet/services/change_now/change_now.dart' as _i12;
import 'package:stackwallet/services/exchange/change_now/change_now_api.dart'
as _i12;
import 'package:stackwallet/services/exchange/exchange_response.dart' as _i2;
import 'package:stackwallet/services/trade_notes_service.dart' as _i11;
import 'package:stackwallet/services/trade_service.dart' as _i9;
import 'package:stackwallet/utilities/enums/backup_frequency_type.dart' as _i6;
@ -44,7 +44,7 @@ import 'package:stackwallet/utilities/prefs.dart' as _i3;
// ignore_for_file: camel_case_types
class _FakeChangeNowResponse_0<T> extends _i1.Fake
implements _i2.ChangeNowResponse<T> {}
implements _i2.ExchangeResponse<T> {}
/// A class which mocks [Prefs].
///
@ -351,7 +351,7 @@ class MockTradeNotesService extends _i1.Mock implements _i11.TradeNotesService {
/// A class which mocks [ChangeNow].
///
/// See the documentation for Mockito's code generation for more information.
class MockChangeNow extends _i1.Mock implements _i12.ChangeNow {
class MockChangeNow extends _i1.Mock implements _i12.ChangeNowAPI {
MockChangeNow() {
_i1.throwOnMissingStub(this);
}
@ -361,25 +361,25 @@ class MockChangeNow extends _i1.Mock implements _i12.ChangeNow {
super.noSuchMethod(Invocation.setter(#client, _client),
returnValueForMissingStub: null);
@override
_i7.Future<_i2.ChangeNowResponse<List<_i14.Currency>>> getAvailableCurrencies(
_i7.Future<_i2.ExchangeResponse<List<_i14.Currency>>> getAvailableCurrencies(
{bool? fixedRate, bool? active}) =>
(super.noSuchMethod(
Invocation.method(#getAvailableCurrencies, [],
{#fixedRate: fixedRate, #active: active}),
returnValue: Future<_i2.ChangeNowResponse<List<_i14.Currency>>>.value(
returnValue: Future<_i2.ExchangeResponse<List<_i14.Currency>>>.value(
_FakeChangeNowResponse_0<List<_i14.Currency>>())) as _i7
.Future<_i2.ChangeNowResponse<List<_i14.Currency>>>);
.Future<_i2.ExchangeResponse<List<_i14.Currency>>>);
@override
_i7.Future<_i2.ChangeNowResponse<List<_i14.Currency>>> getPairedCurrencies(
_i7.Future<_i2.ExchangeResponse<List<_i14.Currency>>> getPairedCurrencies(
{String? ticker, bool? fixedRate}) =>
(super.noSuchMethod(
Invocation.method(#getPairedCurrencies, [],
{#ticker: ticker, #fixedRate: fixedRate}),
returnValue: Future<_i2.ChangeNowResponse<List<_i14.Currency>>>.value(
returnValue: Future<_i2.ExchangeResponse<List<_i14.Currency>>>.value(
_FakeChangeNowResponse_0<List<_i14.Currency>>())) as _i7
.Future<_i2.ChangeNowResponse<List<_i14.Currency>>>);
.Future<_i2.ExchangeResponse<List<_i14.Currency>>>);
@override
_i7.Future<_i2.ChangeNowResponse<_i15.Decimal>> getMinimalExchangeAmount(
_i7.Future<_i2.ExchangeResponse<_i15.Decimal>> getMinimalExchangeAmount(
{String? fromTicker, String? toTicker, String? apiKey}) =>
(super.noSuchMethod(
Invocation.method(#getMinimalExchangeAmount, [], {
@ -387,11 +387,11 @@ class MockChangeNow extends _i1.Mock implements _i12.ChangeNow {
#toTicker: toTicker,
#apiKey: apiKey
}),
returnValue: Future<_i2.ChangeNowResponse<_i15.Decimal>>.value(
returnValue: Future<_i2.ExchangeResponse<_i15.Decimal>>.value(
_FakeChangeNowResponse_0<_i15.Decimal>()))
as _i7.Future<_i2.ChangeNowResponse<_i15.Decimal>>);
as _i7.Future<_i2.ExchangeResponse<_i15.Decimal>>);
@override
_i7.Future<_i2.ChangeNowResponse<_i16.EstimatedExchangeAmount>>
_i7.Future<_i2.ExchangeResponse<_i16.EstimatedExchangeAmount>>
getEstimatedExchangeAmount(
{String? fromTicker,
String? toTicker,
@ -405,13 +405,13 @@ class MockChangeNow extends _i1.Mock implements _i12.ChangeNow {
#apiKey: apiKey
}),
returnValue: Future<
_i2.ChangeNowResponse<
_i2.ExchangeResponse<
_i16.EstimatedExchangeAmount>>.value(
_FakeChangeNowResponse_0<_i16.EstimatedExchangeAmount>()))
as _i7
.Future<_i2.ChangeNowResponse<_i16.EstimatedExchangeAmount>>);
.Future<_i2.ExchangeResponse<_i16.EstimatedExchangeAmount>>);
@override
_i7.Future<_i2.ChangeNowResponse<_i17.CNExchangeEstimate>>
_i7.Future<_i2.ExchangeResponse<_i17.CNExchangeEstimate>>
getEstimatedExchangeAmountV2(
{String? fromTicker,
String? toTicker,
@ -433,20 +433,20 @@ class MockChangeNow extends _i1.Mock implements _i12.ChangeNow {
#apiKey: apiKey
}),
returnValue: Future<
_i2.ChangeNowResponse<_i17.CNExchangeEstimate>>.value(
_i2.ExchangeResponse<_i17.CNExchangeEstimate>>.value(
_FakeChangeNowResponse_0<_i17.CNExchangeEstimate>()))
as _i7.Future<_i2.ChangeNowResponse<_i17.CNExchangeEstimate>>);
as _i7.Future<_i2.ExchangeResponse<_i17.CNExchangeEstimate>>);
@override
_i7.Future<_i2.ChangeNowResponse<List<_i18.FixedRateMarket>>>
_i7.Future<_i2.ExchangeResponse<List<_i18.FixedRateMarket>>>
getAvailableFixedRateMarkets({String? apiKey}) => (super.noSuchMethod(
Invocation.method(
#getAvailableFixedRateMarkets, [], {#apiKey: apiKey}),
returnValue:
Future<_i2.ChangeNowResponse<List<_i18.FixedRateMarket>>>.value(
_FakeChangeNowResponse_0<List<_i18.FixedRateMarket>>())) as _i7
.Future<_i2.ChangeNowResponse<List<_i18.FixedRateMarket>>>);
Invocation.method(
#getAvailableFixedRateMarkets, [], {#apiKey: apiKey}),
returnValue:
Future<_i2.ExchangeResponse<List<_i18.FixedRateMarket>>>.value(
_FakeChangeNowResponse_0<List<_i18.FixedRateMarket>>()))
as _i7.Future<_i2.ExchangeResponse<List<_i18.FixedRateMarket>>>);
@override
_i7.Future<_i2.ChangeNowResponse<_i10.ExchangeTransaction>>
_i7.Future<_i2.ExchangeResponse<_i10.ExchangeTransaction>>
createStandardExchangeTransaction(
{String? fromTicker,
String? toTicker,
@ -459,24 +459,24 @@ class MockChangeNow extends _i1.Mock implements _i12.ChangeNow {
String? refundExtraId = r'',
String? apiKey}) =>
(super.noSuchMethod(
Invocation.method(#createStandardExchangeTransaction, [], {
#fromTicker: fromTicker,
#toTicker: toTicker,
#receivingAddress: receivingAddress,
#amount: amount,
#extraId: extraId,
#userId: userId,
#contactEmail: contactEmail,
#refundAddress: refundAddress,
#refundExtraId: refundExtraId,
#apiKey: apiKey
}),
returnValue: Future<
_i2.ChangeNowResponse<_i10.ExchangeTransaction>>.value(
_FakeChangeNowResponse_0<_i10.ExchangeTransaction>())) as _i7
.Future<_i2.ChangeNowResponse<_i10.ExchangeTransaction>>);
Invocation.method(#createStandardExchangeTransaction, [], {
#fromTicker: fromTicker,
#toTicker: toTicker,
#receivingAddress: receivingAddress,
#amount: amount,
#extraId: extraId,
#userId: userId,
#contactEmail: contactEmail,
#refundAddress: refundAddress,
#refundExtraId: refundExtraId,
#apiKey: apiKey
}),
returnValue: Future<
_i2.ExchangeResponse<_i10.ExchangeTransaction>>.value(
_FakeChangeNowResponse_0<_i10.ExchangeTransaction>()))
as _i7.Future<_i2.ExchangeResponse<_i10.ExchangeTransaction>>);
@override
_i7.Future<_i2.ChangeNowResponse<_i10.ExchangeTransaction>>
_i7.Future<_i2.ExchangeResponse<_i10.ExchangeTransaction>>
createFixedRateExchangeTransaction(
{String? fromTicker,
String? toTicker,
@ -490,40 +490,40 @@ class MockChangeNow extends _i1.Mock implements _i12.ChangeNow {
String? refundExtraId = r'',
String? apiKey}) =>
(super.noSuchMethod(
Invocation.method(#createFixedRateExchangeTransaction, [], {
#fromTicker: fromTicker,
#toTicker: toTicker,
#receivingAddress: receivingAddress,
#amount: amount,
#rateId: rateId,
#extraId: extraId,
#userId: userId,
#contactEmail: contactEmail,
#refundAddress: refundAddress,
#refundExtraId: refundExtraId,
#apiKey: apiKey
}),
returnValue: Future<
_i2.ChangeNowResponse<_i10.ExchangeTransaction>>.value(
_FakeChangeNowResponse_0<_i10.ExchangeTransaction>())) as _i7
.Future<_i2.ChangeNowResponse<_i10.ExchangeTransaction>>);
Invocation.method(#createFixedRateExchangeTransaction, [], {
#fromTicker: fromTicker,
#toTicker: toTicker,
#receivingAddress: receivingAddress,
#amount: amount,
#rateId: rateId,
#extraId: extraId,
#userId: userId,
#contactEmail: contactEmail,
#refundAddress: refundAddress,
#refundExtraId: refundExtraId,
#apiKey: apiKey
}),
returnValue: Future<
_i2.ExchangeResponse<_i10.ExchangeTransaction>>.value(
_FakeChangeNowResponse_0<_i10.ExchangeTransaction>()))
as _i7.Future<_i2.ExchangeResponse<_i10.ExchangeTransaction>>);
@override
_i7.Future<_i2.ChangeNowResponse<_i19.ExchangeTransactionStatus>>
_i7.Future<_i2.ExchangeResponse<_i19.ExchangeTransactionStatus>>
getTransactionStatus({String? id, String? apiKey}) => (super.noSuchMethod(
Invocation.method(
#getTransactionStatus, [], {#id: id, #apiKey: apiKey}),
returnValue:
Future<_i2.ChangeNowResponse<_i19.ExchangeTransactionStatus>>.value(
Future<_i2.ExchangeResponse<_i19.ExchangeTransactionStatus>>.value(
_FakeChangeNowResponse_0<_i19.ExchangeTransactionStatus>())) as _i7
.Future<_i2.ChangeNowResponse<_i19.ExchangeTransactionStatus>>);
.Future<_i2.ExchangeResponse<_i19.ExchangeTransactionStatus>>);
@override
_i7.Future<_i2.ChangeNowResponse<List<_i20.AvailableFloatingRatePair>>>
_i7.Future<_i2.ExchangeResponse<List<_i20.AvailableFloatingRatePair>>>
getAvailableFloatingRatePairs({bool? includePartners = false}) => (super
.noSuchMethod(
Invocation.method(#getAvailableFloatingRatePairs, [],
{#includePartners: includePartners}),
returnValue:
Future<_i2.ChangeNowResponse<List<_i20.AvailableFloatingRatePair>>>.value(
Future<_i2.ExchangeResponse<List<_i20.AvailableFloatingRatePair>>>.value(
_FakeChangeNowResponse_0<List<_i20.AvailableFloatingRatePair>>())) as _i7
.Future<_i2.ChangeNowResponse<List<_i20.AvailableFloatingRatePair>>>);
.Future<_i2.ExchangeResponse<List<_i20.AvailableFloatingRatePair>>>);
}

View file

@ -6,11 +6,11 @@ import 'package:http/http.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'package:stackwallet/models/exchange/change_now/available_floating_rate_pair.dart';
import 'package:stackwallet/models/exchange/change_now/change_now_response.dart';
import 'package:stackwallet/models/exchange/change_now/estimated_exchange_amount.dart';
import 'package:stackwallet/models/exchange/change_now/exchange_transaction.dart';
import 'package:stackwallet/models/exchange/change_now/exchange_transaction_status.dart';
import 'package:stackwallet/services/change_now/change_now.dart';
import 'package:stackwallet/services/exchange/change_now/change_now_api.dart';
import 'package:stackwallet/services/exchange/exchange_response.dart';
import 'change_now_sample_data.dart';
import 'change_now_test.mocks.dart';
@ -20,7 +20,7 @@ void main() {
group("getAvailableCurrencies", () {
test("getAvailableCurrencies succeeds without options", () async {
final client = MockClient();
ChangeNow.instance.client = client;
ChangeNowAPI.instance.client = client;
when(client.get(
Uri.parse("https://api.ChangeNow.io/v1/currencies"),
@ -28,7 +28,7 @@ void main() {
)).thenAnswer((realInvocation) async =>
Response(jsonEncode(availableCurrenciesJSON), 200));
final result = await ChangeNow.instance.getAvailableCurrencies();
final result = await ChangeNowAPI.instance.getAvailableCurrencies();
expect(result.exception, null);
expect(result.value == null, false);
@ -37,7 +37,7 @@ void main() {
test("getAvailableCurrencies succeeds with active option", () async {
final client = MockClient();
ChangeNow.instance.client = client;
ChangeNowAPI.instance.client = client;
when(client.get(
Uri.parse("https://api.ChangeNow.io/v1/currencies?active=true"),
@ -46,7 +46,7 @@ void main() {
Response(jsonEncode(availableCurrenciesJSONActive), 200));
final result =
await ChangeNow.instance.getAvailableCurrencies(active: true);
await ChangeNowAPI.instance.getAvailableCurrencies(active: true);
expect(result.exception, null);
expect(result.value == null, false);
@ -55,7 +55,7 @@ void main() {
test("getAvailableCurrencies succeeds with fixedRate option", () async {
final client = MockClient();
ChangeNow.instance.client = client;
ChangeNowAPI.instance.client = client;
when(client.get(
Uri.parse("https://api.ChangeNow.io/v1/currencies?fixedRate=true"),
@ -64,7 +64,7 @@ void main() {
Response(jsonEncode(availableCurrenciesJSONFixedRate), 200));
final result =
await ChangeNow.instance.getAvailableCurrencies(fixedRate: true);
await ChangeNowAPI.instance.getAvailableCurrencies(fixedRate: true);
expect(result.exception, null);
expect(result.value == null, false);
@ -74,7 +74,7 @@ void main() {
test("getAvailableCurrencies succeeds with fixedRate and active options",
() async {
final client = MockClient();
ChangeNow.instance.client = client;
ChangeNowAPI.instance.client = client;
when(client.get(
Uri.parse(
@ -83,7 +83,7 @@ void main() {
)).thenAnswer((realInvocation) async =>
Response(jsonEncode(availableCurrenciesJSONActiveFixedRate), 200));
final result = await ChangeNow.instance
final result = await ChangeNowAPI.instance
.getAvailableCurrencies(active: true, fixedRate: true);
expect(result.exception, null);
@ -95,7 +95,7 @@ void main() {
"getAvailableCurrencies fails with ChangeNowExceptionType.serializeResponseError",
() async {
final client = MockClient();
ChangeNow.instance.client = client;
ChangeNowAPI.instance.client = client;
when(client.get(
Uri.parse("https://api.ChangeNow.io/v1/currencies"),
@ -103,25 +103,25 @@ void main() {
)).thenAnswer((realInvocation) async =>
Response('{"some unexpected": "but valid json data"}', 200));
final result = await ChangeNow.instance.getAvailableCurrencies();
final result = await ChangeNowAPI.instance.getAvailableCurrencies();
expect(result.exception!.type,
ChangeNowExceptionType.serializeResponseError);
expect(
result.exception!.type, ExchangeExceptionType.serializeResponseError);
expect(result.value == null, true);
});
test("getAvailableCurrencies fails for any other reason", () async {
final client = MockClient();
ChangeNow.instance.client = client;
ChangeNowAPI.instance.client = client;
when(client.get(
Uri.parse("https://api.ChangeNow.io/v1/currencies"),
headers: {'Content-Type': 'application/json'},
)).thenAnswer((realInvocation) async => Response("", 400));
final result = await ChangeNow.instance.getAvailableCurrencies();
final result = await ChangeNowAPI.instance.getAvailableCurrencies();
expect(result.exception!.type, ChangeNowExceptionType.generic);
expect(result.exception!.type, ExchangeExceptionType.generic);
expect(result.value == null, true);
});
});
@ -129,7 +129,7 @@ void main() {
group("getPairedCurrencies", () {
test("getPairedCurrencies succeeds without fixedRate option", () async {
final client = MockClient();
ChangeNow.instance.client = client;
ChangeNowAPI.instance.client = client;
when(client.get(
Uri.parse("https://api.ChangeNow.io/v1/currencies-to/XMR"),
@ -138,7 +138,7 @@ void main() {
Response(jsonEncode(getPairedCurrenciesJSON), 200));
final result =
await ChangeNow.instance.getPairedCurrencies(ticker: "XMR");
await ChangeNowAPI.instance.getPairedCurrencies(ticker: "XMR");
expect(result.exception, null);
expect(result.value == null, false);
@ -147,7 +147,7 @@ void main() {
test("getPairedCurrencies succeeds with fixedRate option", () async {
final client = MockClient();
ChangeNow.instance.client = client;
ChangeNowAPI.instance.client = client;
when(client.get(
Uri.parse(
@ -156,7 +156,7 @@ void main() {
)).thenAnswer((realInvocation) async =>
Response(jsonEncode(getPairedCurrenciesJSONFixedRate), 200));
final result = await ChangeNow.instance
final result = await ChangeNowAPI.instance
.getPairedCurrencies(ticker: "XMR", fixedRate: true);
expect(result.exception, null);
@ -168,7 +168,7 @@ void main() {
"getPairedCurrencies fails with ChangeNowExceptionType.serializeResponseError A",
() async {
final client = MockClient();
ChangeNow.instance.client = client;
ChangeNowAPI.instance.client = client;
when(client.get(
Uri.parse("https://api.ChangeNow.io/v1/currencies-to/XMR"),
@ -177,26 +177,26 @@ void main() {
Response('[{"some unexpected": "but valid json data"}]', 200));
final result =
await ChangeNow.instance.getPairedCurrencies(ticker: "XMR");
await ChangeNowAPI.instance.getPairedCurrencies(ticker: "XMR");
expect(result.exception!.type,
ChangeNowExceptionType.serializeResponseError);
expect(
result.exception!.type, ExchangeExceptionType.serializeResponseError);
expect(result.value == null, true);
});
test("getPairedCurrencies fails for any other reason", () async {
final client = MockClient();
ChangeNow.instance.client = client;
ChangeNowAPI.instance.client = client;
when(client.get(
Uri.parse("https://api.ChangeNow.io/v1/currencies"),
headers: {'Content-Type': 'application/json'},
)).thenAnswer((realInvocation) async => Response("", 400));
final result = await ChangeNow.instance
final result = await ChangeNowAPI.instance
.getPairedCurrencies(ticker: "XMR", fixedRate: true);
expect(result.exception!.type, ChangeNowExceptionType.generic);
expect(result.exception!.type, ExchangeExceptionType.generic);
expect(result.value == null, true);
});
});
@ -204,7 +204,7 @@ void main() {
group("getMinimalExchangeAmount", () {
test("getMinimalExchangeAmount succeeds", () async {
final client = MockClient();
ChangeNow.instance.client = client;
ChangeNowAPI.instance.client = client;
when(client.get(
Uri.parse(
@ -213,7 +213,7 @@ void main() {
)).thenAnswer(
(realInvocation) async => Response('{"minAmount": 42}', 200));
final result = await ChangeNow.instance.getMinimalExchangeAmount(
final result = await ChangeNowAPI.instance.getMinimalExchangeAmount(
fromTicker: "xmr",
toTicker: "btc",
apiKey: "testAPIKEY",
@ -228,7 +228,7 @@ void main() {
"getMinimalExchangeAmount fails with ChangeNowExceptionType.serializeResponseError",
() async {
final client = MockClient();
ChangeNow.instance.client = client;
ChangeNowAPI.instance.client = client;
when(client.get(
Uri.parse(
@ -236,20 +236,20 @@ void main() {
headers: {'Content-Type': 'application/json'},
)).thenAnswer((realInvocation) async => Response('{"error": 42}', 200));
final result = await ChangeNow.instance.getMinimalExchangeAmount(
final result = await ChangeNowAPI.instance.getMinimalExchangeAmount(
fromTicker: "xmr",
toTicker: "btc",
apiKey: "testAPIKEY",
);
expect(result.exception!.type,
ChangeNowExceptionType.serializeResponseError);
expect(
result.exception!.type, ExchangeExceptionType.serializeResponseError);
expect(result.value == null, true);
});
test("getMinimalExchangeAmount fails for any other reason", () async {
final client = MockClient();
ChangeNow.instance.client = client;
ChangeNowAPI.instance.client = client;
when(client.get(
Uri.parse(
@ -257,13 +257,13 @@ void main() {
headers: {'Content-Type': 'application/json'},
)).thenAnswer((realInvocation) async => Response('', 400));
final result = await ChangeNow.instance.getMinimalExchangeAmount(
final result = await ChangeNowAPI.instance.getMinimalExchangeAmount(
fromTicker: "xmr",
toTicker: "btc",
apiKey: "testAPIKEY",
);
expect(result.exception!.type, ChangeNowExceptionType.generic);
expect(result.exception!.type, ExchangeExceptionType.generic);
expect(result.value == null, true);
});
});
@ -271,7 +271,7 @@ void main() {
group("getEstimatedExchangeAmount", () {
test("getEstimatedExchangeAmount succeeds", () async {
final client = MockClient();
ChangeNow.instance.client = client;
ChangeNowAPI.instance.client = client;
when(client.get(
Uri.parse(
@ -281,7 +281,7 @@ void main() {
'{"estimatedAmount": 58.4142873, "transactionSpeedForecast": "10-60", "warningMessage": null}',
200));
final result = await ChangeNow.instance.getEstimatedExchangeAmount(
final result = await ChangeNowAPI.instance.getEstimatedExchangeAmount(
fromTicker: "xmr",
toTicker: "btc",
fromAmount: Decimal.fromInt(42),
@ -297,7 +297,7 @@ void main() {
"getEstimatedExchangeAmount fails with ChangeNowExceptionType.serializeResponseError",
() async {
final client = MockClient();
ChangeNow.instance.client = client;
ChangeNowAPI.instance.client = client;
when(client.get(
Uri.parse(
@ -305,21 +305,21 @@ void main() {
headers: {'Content-Type': 'application/json'},
)).thenAnswer((realInvocation) async => Response('{"error": 42}', 200));
final result = await ChangeNow.instance.getEstimatedExchangeAmount(
final result = await ChangeNowAPI.instance.getEstimatedExchangeAmount(
fromTicker: "xmr",
toTicker: "btc",
fromAmount: Decimal.fromInt(42),
apiKey: "testAPIKEY",
);
expect(result.exception!.type,
ChangeNowExceptionType.serializeResponseError);
expect(
result.exception!.type, ExchangeExceptionType.serializeResponseError);
expect(result.value == null, true);
});
test("getEstimatedExchangeAmount fails for any other reason", () async {
final client = MockClient();
ChangeNow.instance.client = client;
ChangeNowAPI.instance.client = client;
when(client.get(
Uri.parse(
@ -327,14 +327,14 @@ void main() {
headers: {'Content-Type': 'application/json'},
)).thenAnswer((realInvocation) async => Response('', 400));
final result = await ChangeNow.instance.getEstimatedExchangeAmount(
final result = await ChangeNowAPI.instance.getEstimatedExchangeAmount(
fromTicker: "xmr",
toTicker: "btc",
fromAmount: Decimal.fromInt(42),
apiKey: "testAPIKEY",
);
expect(result.exception!.type, ChangeNowExceptionType.generic);
expect(result.exception!.type, ExchangeExceptionType.generic);
expect(result.value == null, true);
});
});
@ -417,7 +417,7 @@ void main() {
group("getAvailableFixedRateMarkets", () {
test("getAvailableFixedRateMarkets succeeds", () async {
final client = MockClient();
ChangeNow.instance.client = client;
ChangeNowAPI.instance.client = client;
when(client.get(
Uri.parse(
@ -426,7 +426,7 @@ void main() {
)).thenAnswer((realInvocation) async =>
Response(jsonEncode(fixedRateMarketsJSON), 200));
final result = await ChangeNow.instance.getAvailableFixedRateMarkets(
final result = await ChangeNowAPI.instance.getAvailableFixedRateMarkets(
apiKey: "testAPIKEY",
);
@ -439,7 +439,7 @@ void main() {
"getAvailableFixedRateMarkets fails with ChangeNowExceptionType.serializeResponseError",
() async {
final client = MockClient();
ChangeNow.instance.client = client;
ChangeNowAPI.instance.client = client;
when(client.get(
Uri.parse(
@ -447,18 +447,18 @@ void main() {
headers: {'Content-Type': 'application/json'},
)).thenAnswer((realInvocation) async => Response('{"error": 42}', 200));
final result = await ChangeNow.instance.getAvailableFixedRateMarkets(
final result = await ChangeNowAPI.instance.getAvailableFixedRateMarkets(
apiKey: "testAPIKEY",
);
expect(result.exception!.type,
ChangeNowExceptionType.serializeResponseError);
expect(
result.exception!.type, ExchangeExceptionType.serializeResponseError);
expect(result.value == null, true);
});
test("getAvailableFixedRateMarkets fails for any other reason", () async {
final client = MockClient();
ChangeNow.instance.client = client;
ChangeNowAPI.instance.client = client;
when(client.get(
Uri.parse(
@ -466,11 +466,11 @@ void main() {
headers: {'Content-Type': 'application/json'},
)).thenAnswer((realInvocation) async => Response('', 400));
final result = await ChangeNow.instance.getAvailableFixedRateMarkets(
final result = await ChangeNowAPI.instance.getAvailableFixedRateMarkets(
apiKey: "testAPIKEY",
);
expect(result.exception!.type, ChangeNowExceptionType.generic);
expect(result.exception!.type, ExchangeExceptionType.generic);
expect(result.value == null, true);
});
});
@ -478,7 +478,7 @@ void main() {
group("createStandardExchangeTransaction", () {
test("createStandardExchangeTransaction succeeds", () async {
final client = MockClient();
ChangeNow.instance.client = client;
ChangeNowAPI.instance.client = client;
when(client.post(
Uri.parse("https://api.ChangeNow.io/v1/transactions/testAPIKEY"),
@ -489,7 +489,8 @@ void main() {
)).thenAnswer((realInvocation) async =>
Response(jsonEncode(createStandardTransactionResponse), 200));
final result = await ChangeNow.instance.createStandardExchangeTransaction(
final result =
await ChangeNowAPI.instance.createStandardExchangeTransaction(
fromTicker: "xmr",
toTicker: "btc",
receivingAddress: "bc1qu58svs9983e2vuyqh7gq7ratf8k5qehz5k0cn5",
@ -508,7 +509,7 @@ void main() {
"createStandardExchangeTransaction fails with ChangeNowExceptionType.serializeResponseError",
() async {
final client = MockClient();
ChangeNow.instance.client = client;
ChangeNowAPI.instance.client = client;
when(client.post(
Uri.parse("https://api.ChangeNow.io/v1/transactions/testAPIKEY"),
@ -518,7 +519,8 @@ void main() {
encoding: null,
)).thenAnswer((realInvocation) async => Response('{"error": 42}', 200));
final result = await ChangeNow.instance.createStandardExchangeTransaction(
final result =
await ChangeNowAPI.instance.createStandardExchangeTransaction(
fromTicker: "xmr",
toTicker: "btc",
receivingAddress: "bc1qu58svs9983e2vuyqh7gq7ratf8k5qehz5k0cn5",
@ -528,15 +530,15 @@ void main() {
apiKey: "testAPIKEY",
);
expect(result.exception!.type,
ChangeNowExceptionType.serializeResponseError);
expect(
result.exception!.type, ExchangeExceptionType.serializeResponseError);
expect(result.value == null, true);
});
test("createStandardExchangeTransaction fails for any other reason",
() async {
final client = MockClient();
ChangeNow.instance.client = client;
ChangeNowAPI.instance.client = client;
when(client.post(
Uri.parse("https://api.ChangeNow.io/v1/transactions/testAPIKEY"),
@ -546,7 +548,8 @@ void main() {
encoding: null,
)).thenAnswer((realInvocation) async => Response('', 400));
final result = await ChangeNow.instance.createStandardExchangeTransaction(
final result =
await ChangeNowAPI.instance.createStandardExchangeTransaction(
fromTicker: "xmr",
toTicker: "btc",
receivingAddress: "bc1qu58svs9983e2vuyqh7gq7ratf8k5qehz5k0cn5",
@ -556,7 +559,7 @@ void main() {
apiKey: "testAPIKEY",
);
expect(result.exception!.type, ChangeNowExceptionType.generic);
expect(result.exception!.type, ExchangeExceptionType.generic);
expect(result.value == null, true);
});
});
@ -564,7 +567,7 @@ void main() {
group("createFixedRateExchangeTransaction", () {
test("createFixedRateExchangeTransaction succeeds", () async {
final client = MockClient();
ChangeNow.instance.client = client;
ChangeNowAPI.instance.client = client;
when(client.post(
Uri.parse(
@ -578,7 +581,7 @@ void main() {
200));
final result =
await ChangeNow.instance.createFixedRateExchangeTransaction(
await ChangeNowAPI.instance.createFixedRateExchangeTransaction(
fromTicker: "btc",
toTicker: "eth",
receivingAddress: "0x57f31ad4b64095347F87eDB1675566DAfF5EC886",
@ -597,7 +600,7 @@ void main() {
"createFixedRateExchangeTransaction fails with ChangeNowExceptionType.serializeResponseError",
() async {
final client = MockClient();
ChangeNow.instance.client = client;
ChangeNowAPI.instance.client = client;
when(client.post(
Uri.parse(
@ -610,7 +613,7 @@ void main() {
Response('{"id": "a5c73e2603f40d","amount": 62.9737711}', 200));
final result =
await ChangeNow.instance.createFixedRateExchangeTransaction(
await ChangeNowAPI.instance.createFixedRateExchangeTransaction(
fromTicker: "btc",
toTicker: "eth",
receivingAddress: "0x57f31ad4b64095347F87eDB1675566DAfF5EC886",
@ -620,15 +623,15 @@ void main() {
rateId: '',
);
expect(result.exception!.type,
ChangeNowExceptionType.serializeResponseError);
expect(
result.exception!.type, ExchangeExceptionType.serializeResponseError);
expect(result.value == null, true);
});
test("createFixedRateExchangeTransaction fails for any other reason",
() async {
final client = MockClient();
ChangeNow.instance.client = client;
ChangeNowAPI.instance.client = client;
when(client.post(
Uri.parse(
@ -640,7 +643,7 @@ void main() {
)).thenAnswer((realInvocation) async => Response('', 400));
final result =
await ChangeNow.instance.createFixedRateExchangeTransaction(
await ChangeNowAPI.instance.createFixedRateExchangeTransaction(
fromTicker: "xmr",
toTicker: "btc",
receivingAddress: "bc1qu58svs9983e2vuyqh7gq7ratf8k5qehz5k0cn5",
@ -651,7 +654,7 @@ void main() {
rateId: '',
);
expect(result.exception!.type, ChangeNowExceptionType.generic);
expect(result.exception!.type, ExchangeExceptionType.generic);
expect(result.value == null, true);
});
});
@ -659,7 +662,7 @@ void main() {
group("getTransactionStatus", () {
test("getTransactionStatus succeeds", () async {
final client = MockClient();
ChangeNow.instance.client = client;
ChangeNowAPI.instance.client = client;
when(client.get(
Uri.parse(
@ -669,7 +672,7 @@ void main() {
'{"status": "waiting", "payinAddress": "32Ge2ci26rj1sRGw2NjiQa9L7Xvxtgzhrj", "payoutAddress": "0x57f31ad4b64095347F87eDB1675566DAfF5EC886", "fromCurrency": "btc", "toCurrency": "eth", "id": "50727663e5d9a4", "updatedAt": "2019-08-22T14:47:49.943Z", "expectedSendAmount": 1, "expectedReceiveAmount": 52.31667, "createdAt": "2019-08-22T14:47:49.943Z", "isPartner": false}',
200));
final result = await ChangeNow.instance.getTransactionStatus(
final result = await ChangeNowAPI.instance.getTransactionStatus(
id: "47F87eDB1675566DAfF5EC886",
apiKey: "testAPIKEY",
);
@ -683,7 +686,7 @@ void main() {
"getTransactionStatus fails with ChangeNowExceptionType.serializeResponseError",
() async {
final client = MockClient();
ChangeNow.instance.client = client;
ChangeNowAPI.instance.client = client;
when(client.get(
Uri.parse(
@ -691,19 +694,19 @@ void main() {
headers: {'Content-Type': 'application/json'},
)).thenAnswer((realInvocation) async => Response('{"error": 42}', 200));
final result = await ChangeNow.instance.getTransactionStatus(
final result = await ChangeNowAPI.instance.getTransactionStatus(
id: "47F87eDB1675566DAfF5EC886",
apiKey: "testAPIKEY",
);
expect(result.exception!.type,
ChangeNowExceptionType.serializeResponseError);
expect(
result.exception!.type, ExchangeExceptionType.serializeResponseError);
expect(result.value == null, true);
});
test("getTransactionStatus fails for any other reason", () async {
final client = MockClient();
ChangeNow.instance.client = client;
ChangeNowAPI.instance.client = client;
when(client.get(
Uri.parse(
@ -711,12 +714,12 @@ void main() {
headers: {'Content-Type': 'application/json'},
)).thenAnswer((realInvocation) async => Response('', 400));
final result = await ChangeNow.instance.getTransactionStatus(
final result = await ChangeNowAPI.instance.getTransactionStatus(
id: "47F87eDB1675566DAfF5EC886",
apiKey: "testAPIKEY",
);
expect(result.exception!.type, ChangeNowExceptionType.generic);
expect(result.exception!.type, ExchangeExceptionType.generic);
expect(result.value == null, true);
});
});
@ -724,7 +727,7 @@ void main() {
group("getAvailableFloatingRatePairs", () {
test("getAvailableFloatingRatePairs succeeds", () async {
final client = MockClient();
ChangeNow.instance.client = client;
ChangeNowAPI.instance.client = client;
when(client.get(
Uri.parse(
@ -733,7 +736,8 @@ void main() {
)).thenAnswer((realInvocation) async =>
Response('["btc_xmr","btc_firo","btc_doge","eth_ltc"]', 200));
final result = await ChangeNow.instance.getAvailableFloatingRatePairs();
final result =
await ChangeNowAPI.instance.getAvailableFloatingRatePairs();
expect(result.exception, null);
expect(result.value == null, false);
@ -744,7 +748,7 @@ void main() {
"getAvailableFloatingRatePairs fails with ChangeNowExceptionType.serializeResponseError",
() async {
final client = MockClient();
ChangeNow.instance.client = client;
ChangeNowAPI.instance.client = client;
when(client.get(
Uri.parse(
@ -752,16 +756,17 @@ void main() {
headers: {'Content-Type': 'application/json'},
)).thenAnswer((realInvocation) async => Response('{"error": 42}', 200));
final result = await ChangeNow.instance.getAvailableFloatingRatePairs();
final result =
await ChangeNowAPI.instance.getAvailableFloatingRatePairs();
expect(result.exception!.type,
ChangeNowExceptionType.serializeResponseError);
expect(
result.exception!.type, ExchangeExceptionType.serializeResponseError);
expect(result.value == null, true);
});
test("getAvailableFloatingRatePairs fails for any other reason", () async {
final client = MockClient();
ChangeNow.instance.client = client;
ChangeNowAPI.instance.client = client;
when(client.get(
Uri.parse(
@ -769,9 +774,10 @@ void main() {
headers: {'Content-Type': 'application/json'},
)).thenAnswer((realInvocation) async => Response('', 400));
final result = await ChangeNow.instance.getAvailableFloatingRatePairs();
final result =
await ChangeNowAPI.instance.getAvailableFloatingRatePairs();
expect(result.exception!.type, ChangeNowExceptionType.generic);
expect(result.exception!.type, ExchangeExceptionType.generic);
expect(result.value == null, true);
});
});