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

View file

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

View file

@ -2,7 +2,6 @@ import 'dart:async';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.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/change_now/exchange_transaction.dart';
import 'package:stackwallet/models/exchange/incomplete_exchange.dart'; import 'package:stackwallet/models/exchange/incomplete_exchange.dart';
import 'package:stackwallet/pages/exchange_view/exchange_step_views/step_4_view.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/pages/exchange_view/sub_widgets/step_row.dart';
import 'package:stackwallet/providers/exchange/change_now_provider.dart'; import 'package:stackwallet/providers/exchange/change_now_provider.dart';
import 'package:stackwallet/providers/global/trades_service_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/services/notifications_api.dart';
import 'package:stackwallet/utilities/assets.dart'; import 'package:stackwallet/utilities/assets.dart';
import 'package:stackwallet/utilities/clipboard_interface.dart'; import 'package:stackwallet/utilities/clipboard_interface.dart';
@ -243,7 +243,7 @@ class _Step3ViewState extends ConsumerState<Step3View> {
), ),
); );
ChangeNowResponse<ExchangeTransaction> ExchangeResponse<ExchangeTransaction>
response; response;
if (model.rateType == if (model.rateType ==
ExchangeRateType.estimated) { 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/global/notifications_provider.dart';
import 'package:stackwallet/providers/ui/home_view_index_provider.dart'; import 'package:stackwallet/providers/ui/home_view_index_provider.dart';
import 'package:stackwallet/providers/ui/unread_notifications_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/assets.dart';
import 'package:stackwallet/utilities/constants.dart'; import 'package:stackwallet/utilities/constants.dart';
import 'package:stackwallet/utilities/text_styles.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/ui/unread_notifications_provider.dart';
import 'package:stackwallet/providers/wallet/public_private_balance_state_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/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/firo/firo_wallet.dart';
import 'package:stackwallet/services/coins/manager.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/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/events/global/wallet_sync_status_changed_event.dart';
import 'package:stackwallet/services/event_bus/global_event_bus.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/assets.dart';
import 'package:stackwallet/utilities/constants.dart'; import 'package:stackwallet/utilities/constants.dart';
import 'package:stackwallet/utilities/enums/backup_frequency_type.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: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:http/http.dart' as http;
import 'package:stackwallet/external_api_keys.dart'; 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/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/cn_exchange_estimate.dart';
import 'package:stackwallet/models/exchange/change_now/estimated_exchange_amount.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.dart';
import 'package:stackwallet/models/exchange/change_now/exchange_transaction_status.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/change_now/fixed_rate_market.dart';
import 'package:stackwallet/models/exchange/response_objects/currency.dart'; import 'package:stackwallet/models/exchange/response_objects/currency.dart';
import 'package:stackwallet/services/exchange/exchange_response.dart';
import 'package:stackwallet/utilities/logger.dart'; import 'package:stackwallet/utilities/logger.dart';
class ChangeNow { class ChangeNowAPI {
static const String scheme = "https"; static const String scheme = "https";
static const String authority = "api.changenow.io"; static const String authority = "api.changenow.io";
static const String apiVersion = "/v1"; static const String apiVersion = "/v1";
static const String apiVersionV2 = "/v2"; static const String apiVersionV2 = "/v2";
ChangeNow._(); ChangeNowAPI._();
static final ChangeNow _instance = ChangeNow._(); static final ChangeNowAPI _instance = ChangeNowAPI._();
static ChangeNow get instance => _instance; static ChangeNowAPI get instance => _instance;
/// set this to override using standard http client. Useful for testing /// set this to override using standard http client. Useful for testing
http.Client? client; http.Client? client;
@ -100,7 +100,7 @@ class ChangeNow {
/// ///
/// Set [active] to true to return only active currencies. /// Set [active] to true to return only active currencies.
/// Set [fixedRate] to true to return only currencies available on a fixed-rate flow. /// 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? fixedRate,
bool? active, bool? active,
}) async { }) async {
@ -129,26 +129,26 @@ class ChangeNow {
} catch (e, s) { } catch (e, s) {
Logging.instance.log("getAvailableCurrencies exception: $e\n$s", Logging.instance.log("getAvailableCurrencies exception: $e\n$s",
level: LogLevel.Error); level: LogLevel.Error);
return ChangeNowResponse( return ExchangeResponse(
exception: ChangeNowException( exception: ExchangeException(
"Error: $jsonArray", "Error: $jsonArray",
ChangeNowExceptionType.serializeResponseError, ExchangeExceptionType.serializeResponseError,
), ),
); );
} }
} catch (e, s) { } catch (e, s) {
Logging.instance.log("getAvailableCurrencies exception: $e\n$s", Logging.instance.log("getAvailableCurrencies exception: $e\n$s",
level: LogLevel.Error); level: LogLevel.Error);
return ChangeNowResponse( return ExchangeResponse(
exception: ChangeNowException( exception: ExchangeException(
e.toString(), e.toString(),
ChangeNowExceptionType.generic, ExchangeExceptionType.generic,
), ),
); );
} }
} }
ChangeNowResponse<List<Currency>> _parseAvailableCurrenciesJson( ExchangeResponse<List<Currency>> _parseAvailableCurrenciesJson(
List<dynamic> jsonArray) { List<dynamic> jsonArray) {
try { try {
List<Currency> currencies = []; List<Currency> currencies = [];
@ -158,13 +158,13 @@ class ChangeNow {
currencies currencies
.add(Currency.fromJson(Map<String, dynamic>.from(json as Map))); .add(Currency.fromJson(Map<String, dynamic>.from(json as Map)));
} catch (_) { } catch (_) {
return ChangeNowResponse( return ExchangeResponse(
exception: ChangeNowException("Failed to serialize $json", exception: ExchangeException("Failed to serialize $json",
ChangeNowExceptionType.serializeResponseError)); ExchangeExceptionType.serializeResponseError));
} }
} }
return ChangeNowResponse(value: currencies); return ExchangeResponse(value: currencies);
} catch (_) { } catch (_) {
rethrow; rethrow;
} }
@ -175,7 +175,7 @@ class ChangeNow {
/// ///
/// Required [ticker] to fetch paired currencies for. /// Required [ticker] to fetch paired currencies for.
/// Set [fixedRate] to true to return only currencies available on a fixed-rate flow. /// 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, required String ticker,
bool? fixedRate, bool? fixedRate,
}) async { }) async {
@ -199,10 +199,10 @@ class ChangeNow {
currencies currencies
.add(Currency.fromJson(Map<String, dynamic>.from(json as Map))); .add(Currency.fromJson(Map<String, dynamic>.from(json as Map)));
} catch (_) { } catch (_) {
return ChangeNowResponse( return ExchangeResponse(
exception: ChangeNowException( exception: ExchangeException(
"Failed to serialize $json", "Failed to serialize $json",
ChangeNowExceptionType.serializeResponseError, ExchangeExceptionType.serializeResponseError,
), ),
); );
} }
@ -210,18 +210,18 @@ class ChangeNow {
} catch (e, s) { } catch (e, s) {
Logging.instance.log("getPairedCurrencies exception: $e\n$s", Logging.instance.log("getPairedCurrencies exception: $e\n$s",
level: LogLevel.Error); level: LogLevel.Error);
return ChangeNowResponse( return ExchangeResponse(
exception: ChangeNowException("Error: $jsonArray", exception: ExchangeException("Error: $jsonArray",
ChangeNowExceptionType.serializeResponseError)); ExchangeExceptionType.serializeResponseError));
} }
return ChangeNowResponse(value: currencies); return ExchangeResponse(value: currencies);
} catch (e, s) { } catch (e, s) {
Logging.instance Logging.instance
.log("getPairedCurrencies exception: $e\n$s", level: LogLevel.Error); .log("getPairedCurrencies exception: $e\n$s", level: LogLevel.Error);
return ChangeNowResponse( return ExchangeResponse(
exception: ChangeNowException( exception: ExchangeException(
e.toString(), e.toString(),
ChangeNowExceptionType.generic, ExchangeExceptionType.generic,
), ),
); );
} }
@ -230,7 +230,7 @@ class ChangeNow {
/// The API endpoint returns minimal payment amount required to make /// The API endpoint returns minimal payment amount required to make
/// an exchange of [fromTicker] to [toTicker]. /// an exchange of [fromTicker] to [toTicker].
/// If you try to exchange less, the transaction will most likely fail. /// 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 fromTicker,
required String toTicker, required String toTicker,
String? apiKey, String? apiKey,
@ -245,22 +245,22 @@ class ChangeNow {
try { try {
final value = Decimal.parse(json["minAmount"].toString()); final value = Decimal.parse(json["minAmount"].toString());
return ChangeNowResponse(value: value); return ExchangeResponse(value: value);
} catch (_) { } catch (_) {
return ChangeNowResponse( return ExchangeResponse(
exception: ChangeNowException( exception: ExchangeException(
"Failed to serialize $json", "Failed to serialize $json",
ChangeNowExceptionType.serializeResponseError, ExchangeExceptionType.serializeResponseError,
), ),
); );
} }
} catch (e, s) { } catch (e, s) {
Logging.instance.log("getMinimalExchangeAmount exception: $e\n$s", Logging.instance.log("getMinimalExchangeAmount exception: $e\n$s",
level: LogLevel.Error); level: LogLevel.Error);
return ChangeNowResponse( return ExchangeResponse(
exception: ChangeNowException( exception: ExchangeException(
e.toString(), e.toString(),
ChangeNowExceptionType.generic, ExchangeExceptionType.generic,
), ),
); );
} }
@ -268,8 +268,7 @@ class ChangeNow {
/// Get estimated amount of [toTicker] cryptocurrency to receive /// Get estimated amount of [toTicker] cryptocurrency to receive
/// for [fromAmount] of [fromTicker] /// for [fromAmount] of [fromTicker]
Future<ChangeNowResponse<EstimatedExchangeAmount>> Future<ExchangeResponse<EstimatedExchangeAmount>> getEstimatedExchangeAmount({
getEstimatedExchangeAmount({
required String fromTicker, required String fromTicker,
required String toTicker, required String toTicker,
required Decimal fromAmount, required Decimal fromAmount,
@ -289,22 +288,22 @@ class ChangeNow {
try { try {
final value = EstimatedExchangeAmount.fromJson( final value = EstimatedExchangeAmount.fromJson(
Map<String, dynamic>.from(json as Map)); Map<String, dynamic>.from(json as Map));
return ChangeNowResponse(value: value); return ExchangeResponse(value: value);
} catch (_) { } catch (_) {
return ChangeNowResponse( return ExchangeResponse(
exception: ChangeNowException( exception: ExchangeException(
"Failed to serialize $json", "Failed to serialize $json",
ChangeNowExceptionType.serializeResponseError, ExchangeExceptionType.serializeResponseError,
), ),
); );
} }
} catch (e, s) { } catch (e, s) {
Logging.instance.log("getEstimatedExchangeAmount exception: $e\n$s", Logging.instance.log("getEstimatedExchangeAmount exception: $e\n$s",
level: LogLevel.Error); level: LogLevel.Error);
return ChangeNowResponse( return ExchangeResponse(
exception: ChangeNowException( exception: ExchangeException(
e.toString(), e.toString(),
ChangeNowExceptionType.generic, ExchangeExceptionType.generic,
), ),
); );
} }
@ -313,7 +312,7 @@ class ChangeNow {
// old v1 version // old v1 version
/// This API endpoint returns fixed-rate estimated exchange amount of /// This API endpoint returns fixed-rate estimated exchange amount of
/// [toTicker] cryptocurrency to receive for [fromAmount] of [fromTicker] /// [toTicker] cryptocurrency to receive for [fromAmount] of [fromTicker]
// Future<ChangeNowResponse<EstimatedExchangeAmount>> // Future<ExchangeResponse<EstimatedExchangeAmount>>
// getEstimatedFixedRateExchangeAmount({ // getEstimatedFixedRateExchangeAmount({
// required String fromTicker, // required String fromTicker,
// required String toTicker, // required String toTicker,
@ -342,12 +341,12 @@ class ChangeNow {
// try { // try {
// final value = EstimatedExchangeAmount.fromJson( // final value = EstimatedExchangeAmount.fromJson(
// Map<String, dynamic>.from(json as Map)); // Map<String, dynamic>.from(json as Map));
// return ChangeNowResponse(value: value); // return ExchangeResponse(value: value);
// } catch (_) { // } catch (_) {
// return ChangeNowResponse( // return ExchangeResponse(
// exception: ChangeNowException( // exception: ExchangeException(
// "Failed to serialize $json", // "Failed to serialize $json",
// ChangeNowExceptionType.serializeResponseError, // ExchangeExceptionType.serializeResponseError,
// ), // ),
// ); // );
// } // }
@ -355,10 +354,10 @@ class ChangeNow {
// Logging.instance.log( // Logging.instance.log(
// "getEstimatedFixedRateExchangeAmount exception: $e\n$s", // "getEstimatedFixedRateExchangeAmount exception: $e\n$s",
// level: LogLevel.Error); // level: LogLevel.Error);
// return ChangeNowResponse( // return ExchangeResponse(
// exception: ChangeNowException( // exception: ExchangeException(
// e.toString(), // e.toString(),
// ChangeNowExceptionType.generic, // ExchangeExceptionType.generic,
// ), // ),
// ); // );
// } // }
@ -366,7 +365,7 @@ class ChangeNow {
/// Get estimated amount of [toTicker] cryptocurrency to receive /// Get estimated amount of [toTicker] cryptocurrency to receive
/// for [fromAmount] of [fromTicker] /// for [fromAmount] of [fromTicker]
Future<ChangeNowResponse<CNExchangeEstimate>> getEstimatedExchangeAmountV2({ Future<ExchangeResponse<CNExchangeEstimate>> getEstimatedExchangeAmountV2({
required String fromTicker, required String fromTicker,
required String toTicker, required String toTicker,
required CNEstimateType fromOrTo, required CNEstimateType fromOrTo,
@ -413,22 +412,22 @@ class ChangeNow {
try { try {
final value = final value =
CNExchangeEstimate.fromJson(Map<String, dynamic>.from(json as Map)); CNExchangeEstimate.fromJson(Map<String, dynamic>.from(json as Map));
return ChangeNowResponse(value: value); return ExchangeResponse(value: value);
} catch (_) { } catch (_) {
return ChangeNowResponse( return ExchangeResponse(
exception: ChangeNowException( exception: ExchangeException(
"Failed to serialize $json", "Failed to serialize $json",
ChangeNowExceptionType.serializeResponseError, ExchangeExceptionType.serializeResponseError,
), ),
); );
} }
} catch (e, s) { } catch (e, s) {
Logging.instance.log("getEstimatedExchangeAmountV2 exception: $e\n$s", Logging.instance.log("getEstimatedExchangeAmountV2 exception: $e\n$s",
level: LogLevel.Error); level: LogLevel.Error);
return ChangeNowResponse( return ExchangeResponse(
exception: ChangeNowException( exception: ExchangeException(
e.toString(), e.toString(),
ChangeNowExceptionType.generic, ExchangeExceptionType.generic,
), ),
); );
} }
@ -438,8 +437,7 @@ class ChangeNow {
/// fixed-rate flow. Some currencies get enabled or disabled from time to /// 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 /// time and the market info gets updates, so make sure to refresh the list
/// occasionally. One time per minute is sufficient. /// occasionally. One time per minute is sufficient.
Future<ChangeNowResponse<List<FixedRateMarket>>> Future<ExchangeResponse<List<FixedRateMarket>>> getAvailableFixedRateMarkets({
getAvailableFixedRateMarkets({
String? apiKey, String? apiKey,
}) async { }) async {
final uri = _buildUri( final uri = _buildUri(
@ -456,26 +454,26 @@ class ChangeNow {
} catch (e, s) { } catch (e, s) {
Logging.instance.log("getAvailableFixedRateMarkets exception: $e\n$s", Logging.instance.log("getAvailableFixedRateMarkets exception: $e\n$s",
level: LogLevel.Error); level: LogLevel.Error);
return ChangeNowResponse( return ExchangeResponse(
exception: ChangeNowException( exception: ExchangeException(
"Error: $jsonArray", "Error: $jsonArray",
ChangeNowExceptionType.serializeResponseError, ExchangeExceptionType.serializeResponseError,
), ),
); );
} }
} catch (e, s) { } catch (e, s) {
Logging.instance.log("getAvailableFixedRateMarkets exception: $e\n$s", Logging.instance.log("getAvailableFixedRateMarkets exception: $e\n$s",
level: LogLevel.Error); level: LogLevel.Error);
return ChangeNowResponse( return ExchangeResponse(
exception: ChangeNowException( exception: ExchangeException(
e.toString(), e.toString(),
ChangeNowExceptionType.generic, ExchangeExceptionType.generic,
), ),
); );
} }
} }
ChangeNowResponse<List<FixedRateMarket>> _parseFixedRateMarketsJson( ExchangeResponse<List<FixedRateMarket>> _parseFixedRateMarketsJson(
List<dynamic> jsonArray) { List<dynamic> jsonArray) {
try { try {
List<FixedRateMarket> markets = []; List<FixedRateMarket> markets = [];
@ -484,12 +482,12 @@ class ChangeNow {
markets.add( markets.add(
FixedRateMarket.fromJson(Map<String, dynamic>.from(json as Map))); FixedRateMarket.fromJson(Map<String, dynamic>.from(json as Map)));
} catch (_) { } catch (_) {
return ChangeNowResponse( return ExchangeResponse(
exception: ChangeNowException("Failed to serialize $json", exception: ExchangeException("Failed to serialize $json",
ChangeNowExceptionType.serializeResponseError)); ExchangeExceptionType.serializeResponseError));
} }
} }
return ChangeNowResponse(value: markets); return ExchangeResponse(value: markets);
} catch (_) { } catch (_) {
rethrow; rethrow;
} }
@ -497,7 +495,7 @@ class ChangeNow {
/// The API endpoint creates a transaction, generates an address for /// The API endpoint creates a transaction, generates an address for
/// sending funds and returns transaction attributes. /// sending funds and returns transaction attributes.
Future<ChangeNowResponse<ExchangeTransaction>> Future<ExchangeResponse<ExchangeTransaction>>
createStandardExchangeTransaction({ createStandardExchangeTransaction({
required String fromTicker, required String fromTicker,
required String toTicker, required String toTicker,
@ -535,12 +533,12 @@ class ChangeNow {
try { try {
final value = ExchangeTransaction.fromJson( final value = ExchangeTransaction.fromJson(
Map<String, dynamic>.from(json as Map)); Map<String, dynamic>.from(json as Map));
return ChangeNowResponse(value: value); return ExchangeResponse(value: value);
} catch (_) { } catch (_) {
return ChangeNowResponse( return ExchangeResponse(
exception: ChangeNowException( exception: ExchangeException(
"Failed to serialize $json", "Failed to serialize $json",
ChangeNowExceptionType.serializeResponseError, ExchangeExceptionType.serializeResponseError,
), ),
); );
} }
@ -548,10 +546,10 @@ class ChangeNow {
Logging.instance.log( Logging.instance.log(
"createStandardExchangeTransaction exception: $e\n$s", "createStandardExchangeTransaction exception: $e\n$s",
level: LogLevel.Error); level: LogLevel.Error);
return ChangeNowResponse( return ExchangeResponse(
exception: ChangeNowException( exception: ExchangeException(
e.toString(), e.toString(),
ChangeNowExceptionType.generic, ExchangeExceptionType.generic,
), ),
); );
} }
@ -559,7 +557,7 @@ class ChangeNow {
/// The API endpoint creates a transaction, generates an address for /// The API endpoint creates a transaction, generates an address for
/// sending funds and returns transaction attributes. /// sending funds and returns transaction attributes.
Future<ChangeNowResponse<ExchangeTransaction>> Future<ExchangeResponse<ExchangeTransaction>>
createFixedRateExchangeTransaction({ createFixedRateExchangeTransaction({
required String fromTicker, required String fromTicker,
required String toTicker, required String toTicker,
@ -600,12 +598,12 @@ class ChangeNow {
try { try {
final value = ExchangeTransaction.fromJson( final value = ExchangeTransaction.fromJson(
Map<String, dynamic>.from(json as Map)); Map<String, dynamic>.from(json as Map));
return ChangeNowResponse(value: value); return ExchangeResponse(value: value);
} catch (_) { } catch (_) {
return ChangeNowResponse( return ExchangeResponse(
exception: ChangeNowException( exception: ExchangeException(
"Failed to serialize $json", "Failed to serialize $json",
ChangeNowExceptionType.serializeResponseError, ExchangeExceptionType.serializeResponseError,
), ),
); );
} }
@ -613,16 +611,16 @@ class ChangeNow {
Logging.instance.log( Logging.instance.log(
"createFixedRateExchangeTransaction exception: $e\n$s", "createFixedRateExchangeTransaction exception: $e\n$s",
level: LogLevel.Error); level: LogLevel.Error);
return ChangeNowResponse( return ExchangeResponse(
exception: ChangeNowException( exception: ExchangeException(
e.toString(), e.toString(),
ChangeNowExceptionType.generic, ExchangeExceptionType.generic,
), ),
); );
} }
} }
Future<ChangeNowResponse<ExchangeTransactionStatus>> getTransactionStatus({ Future<ExchangeResponse<ExchangeTransactionStatus>> getTransactionStatus({
required String id, required String id,
String? apiKey, String? apiKey,
}) async { }) async {
@ -636,28 +634,28 @@ class ChangeNow {
try { try {
final value = ExchangeTransactionStatus.fromJson( final value = ExchangeTransactionStatus.fromJson(
Map<String, dynamic>.from(json as Map)); Map<String, dynamic>.from(json as Map));
return ChangeNowResponse(value: value); return ExchangeResponse(value: value);
} catch (_) { } catch (_) {
return ChangeNowResponse( return ExchangeResponse(
exception: ChangeNowException( exception: ExchangeException(
"Failed to serialize $json", "Failed to serialize $json",
ChangeNowExceptionType.serializeResponseError, ExchangeExceptionType.serializeResponseError,
), ),
); );
} }
} catch (e, s) { } catch (e, s) {
Logging.instance Logging.instance
.log("getTransactionStatus exception: $e\n$s", level: LogLevel.Error); .log("getTransactionStatus exception: $e\n$s", level: LogLevel.Error);
return ChangeNowResponse( return ExchangeResponse(
exception: ChangeNowException( exception: ExchangeException(
e.toString(), e.toString(),
ChangeNowExceptionType.generic, ExchangeExceptionType.generic,
), ),
); );
} }
} }
Future<ChangeNowResponse<List<AvailableFloatingRatePair>>> Future<ExchangeResponse<List<AvailableFloatingRatePair>>>
getAvailableFloatingRatePairs({ getAvailableFloatingRatePairs({
bool includePartners = false, bool includePartners = false,
}) async { }) async {
@ -675,26 +673,26 @@ class ChangeNow {
} catch (e, s) { } catch (e, s) {
Logging.instance.log("getAvailableFloatingRatePairs exception: $e\n$s", Logging.instance.log("getAvailableFloatingRatePairs exception: $e\n$s",
level: LogLevel.Error); level: LogLevel.Error);
return ChangeNowResponse( return ExchangeResponse(
exception: ChangeNowException( exception: ExchangeException(
"Error: $jsonArray", "Error: $jsonArray",
ChangeNowExceptionType.serializeResponseError, ExchangeExceptionType.serializeResponseError,
), ),
); );
} }
} catch (e, s) { } catch (e, s) {
Logging.instance.log("getAvailableFloatingRatePairs exception: $e\n$s", Logging.instance.log("getAvailableFloatingRatePairs exception: $e\n$s",
level: LogLevel.Error); level: LogLevel.Error);
return ChangeNowResponse( return ExchangeResponse(
exception: ChangeNowException( exception: ExchangeException(
e.toString(), e.toString(),
ChangeNowExceptionType.generic, ExchangeExceptionType.generic,
), ),
); );
} }
} }
ChangeNowResponse<List<AvailableFloatingRatePair>> ExchangeResponse<List<AvailableFloatingRatePair>>
_parseAvailableFloatingRatePairsJson(List<dynamic> jsonArray) { _parseAvailableFloatingRatePairsJson(List<dynamic> jsonArray) {
try { try {
List<AvailableFloatingRatePair> pairs = []; List<AvailableFloatingRatePair> pairs = [];
@ -704,12 +702,12 @@ class ChangeNow {
pairs.add(AvailableFloatingRatePair( pairs.add(AvailableFloatingRatePair(
fromTicker: stringPair[0], toTicker: stringPair[1])); fromTicker: stringPair[0], toTicker: stringPair[1]));
} catch (_) { } catch (_) {
return ChangeNowResponse( return ExchangeResponse(
exception: ChangeNowException("Failed to serialize $json", exception: ExchangeException("Failed to serialize $json",
ChangeNowExceptionType.serializeResponseError)); ExchangeExceptionType.serializeResponseError));
} }
} }
return ChangeNowResponse(value: pairs); return ExchangeResponse(value: pairs);
} catch (_) { } catch (_) {
rethrow; 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/hive/db.dart';
import 'package:stackwallet/models/exchange/change_now/exchange_transaction_status.dart'; import 'package:stackwallet/models/exchange/change_now/exchange_transaction_status.dart';
import 'package:stackwallet/models/notification_model.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/node_service.dart';
import 'package:stackwallet/services/notifications_api.dart'; import 'package:stackwallet/services/notifications_api.dart';
import 'package:stackwallet/services/trade_service.dart'; import 'package:stackwallet/services/trade_service.dart';
@ -17,7 +17,7 @@ class NotificationsService extends ChangeNotifier {
late NodeService nodeService; late NodeService nodeService;
late TradesService tradesService; late TradesService tradesService;
late Prefs prefs; late Prefs prefs;
late ChangeNow changeNow; late ChangeNowAPI changeNow;
NotificationsService._(); NotificationsService._();
static final NotificationsService _instance = NotificationsService._(); static final NotificationsService _instance = NotificationsService._();
@ -27,7 +27,7 @@ class NotificationsService extends ChangeNotifier {
required NodeService nodeService, required NodeService nodeService,
required TradesService tradesService, required TradesService tradesService,
required Prefs prefs, required Prefs prefs,
required ChangeNow changeNow, required ChangeNowAPI changeNow,
}) async { }) async {
this.nodeService = nodeService; this.nodeService = nodeService;
this.tradesService = tradesService; this.tradesService = tradesService;

View file

@ -2,15 +2,15 @@ import 'package:decimal/decimal.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/annotations.dart'; import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.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/change_now/estimated_exchange_amount.dart';
import 'package:stackwallet/models/exchange/estimated_rate_exchange_form_state.dart'; import 'package:stackwallet/models/exchange/estimated_rate_exchange_form_state.dart';
import 'package:stackwallet/models/exchange/response_objects/currency.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'; import 'estimated_rate_exchange_form_state_test.mocks.dart';
@GenerateMocks([ChangeNow]) @GenerateMocks([ChangeNowAPI])
void main() { void main() {
final currencyA = Currency( final currencyA = Currency(
ticker: "btc", ticker: "btc",
@ -98,7 +98,7 @@ void main() {
state.cnTesting = cn; state.cnTesting = cn;
when(cn.getMinimalExchangeAmount(fromTicker: "btc", toTicker: "xmr")) 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.updateFrom(currencyA, true);
await state.updateTo(currencyB, true); await state.updateTo(currencyB, true);
@ -125,7 +125,7 @@ void main() {
state.cnTesting = cn; state.cnTesting = cn;
when(cn.getMinimalExchangeAmount(fromTicker: "btc", toTicker: "xmr")) when(cn.getMinimalExchangeAmount(fromTicker: "btc", toTicker: "xmr"))
.thenAnswer((_) async => ChangeNowResponse()); .thenAnswer((_) async => ExchangeResponse());
await state.updateFrom(currencyA, true); await state.updateFrom(currencyA, true);
await state.updateTo(currencyB, true); await state.updateTo(currencyB, true);
@ -152,7 +152,7 @@ void main() {
state.cnTesting = cn; state.cnTesting = cn;
when(cn.getMinimalExchangeAmount(fromTicker: "btc", toTicker: "xmr")) 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.updateFrom(currencyA, true);
await state.setFromAmountAndCalculateToAmount(Decimal.parse("10.10"), true); await state.setFromAmountAndCalculateToAmount(Decimal.parse("10.10"), true);
@ -180,12 +180,12 @@ void main() {
state.cnTesting = cn; state.cnTesting = cn;
when(cn.getMinimalExchangeAmount(fromTicker: "btc", toTicker: "xmr")) when(cn.getMinimalExchangeAmount(fromTicker: "btc", toTicker: "xmr"))
.thenAnswer((_) async => ChangeNowResponse(value: Decimal.fromInt(42))); .thenAnswer((_) async => ExchangeResponse(value: Decimal.fromInt(42)));
when(cn.getEstimatedExchangeAmount( when(cn.getEstimatedExchangeAmount(
fromTicker: "btc", fromTicker: "btc",
toTicker: "xmr", toTicker: "xmr",
fromAmount: Decimal.parse("110.10"))) fromAmount: Decimal.parse("110.10")))
.thenAnswer((_) async => ChangeNowResponse( .thenAnswer((_) async => ExchangeResponse(
value: EstimatedExchangeAmount( value: EstimatedExchangeAmount(
transactionSpeedForecast: '10-60', transactionSpeedForecast: '10-60',
rateId: 'some rate id', 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:mockito/mockito.dart' as _i1;
import 'package:stackwallet/models/exchange/change_now/available_floating_rate_pair.dart' import 'package:stackwallet/models/exchange/change_now/available_floating_rate_pair.dart'
as _i13; 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' import 'package:stackwallet/models/exchange/change_now/cn_exchange_estimate.dart'
as _i9; as _i9;
import 'package:stackwallet/models/exchange/change_now/estimated_exchange_amount.dart' 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; as _i10;
import 'package:stackwallet/models/exchange/response_objects/currency.dart' import 'package:stackwallet/models/exchange/response_objects/currency.dart'
as _i6; 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: type=lint
// ignore_for_file: avoid_redundant_argument_values // 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 // ignore_for_file: camel_case_types
class _FakeChangeNowResponse_0<T> extends _i1.Fake class _FakeChangeNowResponse_0<T> extends _i1.Fake
implements _i2.ChangeNowResponse<T> {} implements _i2.ExchangeResponse<T> {}
/// A class which mocks [ChangeNow]. /// A class which mocks [ChangeNow].
/// ///
/// See the documentation for Mockito's code generation for more information. /// 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() { MockChangeNow() {
_i1.throwOnMissingStub(this); _i1.throwOnMissingStub(this);
} }
@ -51,25 +51,25 @@ class MockChangeNow extends _i1.Mock implements _i3.ChangeNow {
super.noSuchMethod(Invocation.setter(#client, _client), super.noSuchMethod(Invocation.setter(#client, _client),
returnValueForMissingStub: null); returnValueForMissingStub: null);
@override @override
_i5.Future<_i2.ChangeNowResponse<List<_i6.Currency>>> getAvailableCurrencies( _i5.Future<_i2.ExchangeResponse<List<_i6.Currency>>> getAvailableCurrencies(
{bool? fixedRate, bool? active}) => {bool? fixedRate, bool? active}) =>
(super.noSuchMethod( (super.noSuchMethod(
Invocation.method(#getAvailableCurrencies, [], Invocation.method(#getAvailableCurrencies, [],
{#fixedRate: fixedRate, #active: active}), {#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 _FakeChangeNowResponse_0<List<_i6.Currency>>())) as _i5
.Future<_i2.ChangeNowResponse<List<_i6.Currency>>>); .Future<_i2.ExchangeResponse<List<_i6.Currency>>>);
@override @override
_i5.Future<_i2.ChangeNowResponse<List<_i6.Currency>>> getPairedCurrencies( _i5.Future<_i2.ExchangeResponse<List<_i6.Currency>>> getPairedCurrencies(
{String? ticker, bool? fixedRate}) => {String? ticker, bool? fixedRate}) =>
(super.noSuchMethod( (super.noSuchMethod(
Invocation.method(#getPairedCurrencies, [], Invocation.method(#getPairedCurrencies, [],
{#ticker: ticker, #fixedRate: fixedRate}), {#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 _FakeChangeNowResponse_0<List<_i6.Currency>>())) as _i5
.Future<_i2.ChangeNowResponse<List<_i6.Currency>>>); .Future<_i2.ExchangeResponse<List<_i6.Currency>>>);
@override @override
_i5.Future<_i2.ChangeNowResponse<_i7.Decimal>> getMinimalExchangeAmount( _i5.Future<_i2.ExchangeResponse<_i7.Decimal>> getMinimalExchangeAmount(
{String? fromTicker, String? toTicker, String? apiKey}) => {String? fromTicker, String? toTicker, String? apiKey}) =>
(super.noSuchMethod( (super.noSuchMethod(
Invocation.method(#getMinimalExchangeAmount, [], { Invocation.method(#getMinimalExchangeAmount, [], {
@ -77,11 +77,11 @@ class MockChangeNow extends _i1.Mock implements _i3.ChangeNow {
#toTicker: toTicker, #toTicker: toTicker,
#apiKey: apiKey #apiKey: apiKey
}), }),
returnValue: Future<_i2.ChangeNowResponse<_i7.Decimal>>.value( returnValue: Future<_i2.ExchangeResponse<_i7.Decimal>>.value(
_FakeChangeNowResponse_0<_i7.Decimal>())) _FakeChangeNowResponse_0<_i7.Decimal>()))
as _i5.Future<_i2.ChangeNowResponse<_i7.Decimal>>); as _i5.Future<_i2.ExchangeResponse<_i7.Decimal>>);
@override @override
_i5.Future<_i2.ChangeNowResponse<_i8.EstimatedExchangeAmount>> _i5.Future<_i2.ExchangeResponse<_i8.EstimatedExchangeAmount>>
getEstimatedExchangeAmount( getEstimatedExchangeAmount(
{String? fromTicker, {String? fromTicker,
String? toTicker, String? toTicker,
@ -95,13 +95,12 @@ class MockChangeNow extends _i1.Mock implements _i3.ChangeNow {
#apiKey: apiKey #apiKey: apiKey
}), }),
returnValue: Future< returnValue: Future<
_i2.ChangeNowResponse< _i2.ExchangeResponse<
_i8.EstimatedExchangeAmount>>.value( _i8.EstimatedExchangeAmount>>.value(
_FakeChangeNowResponse_0<_i8.EstimatedExchangeAmount>())) _FakeChangeNowResponse_0<_i8.EstimatedExchangeAmount>()))
as _i5 as _i5.Future<_i2.ExchangeResponse<_i8.EstimatedExchangeAmount>>);
.Future<_i2.ChangeNowResponse<_i8.EstimatedExchangeAmount>>);
@override @override
_i5.Future<_i2.ChangeNowResponse<_i9.CNExchangeEstimate>> _i5.Future<_i2.ExchangeResponse<_i9.CNExchangeEstimate>>
getEstimatedExchangeAmountV2( getEstimatedExchangeAmountV2(
{String? fromTicker, {String? fromTicker,
String? toTicker, String? toTicker,
@ -123,20 +122,20 @@ class MockChangeNow extends _i1.Mock implements _i3.ChangeNow {
#apiKey: apiKey #apiKey: apiKey
}), }),
returnValue: Future< returnValue: Future<
_i2.ChangeNowResponse<_i9.CNExchangeEstimate>>.value( _i2.ExchangeResponse<_i9.CNExchangeEstimate>>.value(
_FakeChangeNowResponse_0<_i9.CNExchangeEstimate>())) _FakeChangeNowResponse_0<_i9.CNExchangeEstimate>()))
as _i5.Future<_i2.ChangeNowResponse<_i9.CNExchangeEstimate>>); as _i5.Future<_i2.ExchangeResponse<_i9.CNExchangeEstimate>>);
@override @override
_i5.Future<_i2.ChangeNowResponse<List<_i10.FixedRateMarket>>> _i5.Future<_i2.ExchangeResponse<List<_i10.FixedRateMarket>>>
getAvailableFixedRateMarkets({String? apiKey}) => (super.noSuchMethod( getAvailableFixedRateMarkets({String? apiKey}) => (super.noSuchMethod(
Invocation.method( Invocation.method(
#getAvailableFixedRateMarkets, [], {#apiKey: apiKey}), #getAvailableFixedRateMarkets, [], {#apiKey: apiKey}),
returnValue: returnValue:
Future<_i2.ChangeNowResponse<List<_i10.FixedRateMarket>>>.value( Future<_i2.ExchangeResponse<List<_i10.FixedRateMarket>>>.value(
_FakeChangeNowResponse_0<List<_i10.FixedRateMarket>>())) as _i5 _FakeChangeNowResponse_0<List<_i10.FixedRateMarket>>()))
.Future<_i2.ChangeNowResponse<List<_i10.FixedRateMarket>>>); as _i5.Future<_i2.ExchangeResponse<List<_i10.FixedRateMarket>>>);
@override @override
_i5.Future<_i2.ChangeNowResponse<_i11.ExchangeTransaction>> _i5.Future<_i2.ExchangeResponse<_i11.ExchangeTransaction>>
createStandardExchangeTransaction( createStandardExchangeTransaction(
{String? fromTicker, {String? fromTicker,
String? toTicker, String? toTicker,
@ -149,24 +148,24 @@ class MockChangeNow extends _i1.Mock implements _i3.ChangeNow {
String? refundExtraId = r'', String? refundExtraId = r'',
String? apiKey}) => String? apiKey}) =>
(super.noSuchMethod( (super.noSuchMethod(
Invocation.method(#createStandardExchangeTransaction, [], { Invocation.method(#createStandardExchangeTransaction, [], {
#fromTicker: fromTicker, #fromTicker: fromTicker,
#toTicker: toTicker, #toTicker: toTicker,
#receivingAddress: receivingAddress, #receivingAddress: receivingAddress,
#amount: amount, #amount: amount,
#extraId: extraId, #extraId: extraId,
#userId: userId, #userId: userId,
#contactEmail: contactEmail, #contactEmail: contactEmail,
#refundAddress: refundAddress, #refundAddress: refundAddress,
#refundExtraId: refundExtraId, #refundExtraId: refundExtraId,
#apiKey: apiKey #apiKey: apiKey
}), }),
returnValue: Future< returnValue: Future<
_i2.ChangeNowResponse<_i11.ExchangeTransaction>>.value( _i2.ExchangeResponse<_i11.ExchangeTransaction>>.value(
_FakeChangeNowResponse_0<_i11.ExchangeTransaction>())) as _i5 _FakeChangeNowResponse_0<_i11.ExchangeTransaction>()))
.Future<_i2.ChangeNowResponse<_i11.ExchangeTransaction>>); as _i5.Future<_i2.ExchangeResponse<_i11.ExchangeTransaction>>);
@override @override
_i5.Future<_i2.ChangeNowResponse<_i11.ExchangeTransaction>> _i5.Future<_i2.ExchangeResponse<_i11.ExchangeTransaction>>
createFixedRateExchangeTransaction( createFixedRateExchangeTransaction(
{String? fromTicker, {String? fromTicker,
String? toTicker, String? toTicker,
@ -180,40 +179,40 @@ class MockChangeNow extends _i1.Mock implements _i3.ChangeNow {
String? refundExtraId = r'', String? refundExtraId = r'',
String? apiKey}) => String? apiKey}) =>
(super.noSuchMethod( (super.noSuchMethod(
Invocation.method(#createFixedRateExchangeTransaction, [], { Invocation.method(#createFixedRateExchangeTransaction, [], {
#fromTicker: fromTicker, #fromTicker: fromTicker,
#toTicker: toTicker, #toTicker: toTicker,
#receivingAddress: receivingAddress, #receivingAddress: receivingAddress,
#amount: amount, #amount: amount,
#rateId: rateId, #rateId: rateId,
#extraId: extraId, #extraId: extraId,
#userId: userId, #userId: userId,
#contactEmail: contactEmail, #contactEmail: contactEmail,
#refundAddress: refundAddress, #refundAddress: refundAddress,
#refundExtraId: refundExtraId, #refundExtraId: refundExtraId,
#apiKey: apiKey #apiKey: apiKey
}), }),
returnValue: Future< returnValue: Future<
_i2.ChangeNowResponse<_i11.ExchangeTransaction>>.value( _i2.ExchangeResponse<_i11.ExchangeTransaction>>.value(
_FakeChangeNowResponse_0<_i11.ExchangeTransaction>())) as _i5 _FakeChangeNowResponse_0<_i11.ExchangeTransaction>()))
.Future<_i2.ChangeNowResponse<_i11.ExchangeTransaction>>); as _i5.Future<_i2.ExchangeResponse<_i11.ExchangeTransaction>>);
@override @override
_i5.Future<_i2.ChangeNowResponse<_i12.ExchangeTransactionStatus>> _i5.Future<_i2.ExchangeResponse<_i12.ExchangeTransactionStatus>>
getTransactionStatus({String? id, String? apiKey}) => (super.noSuchMethod( getTransactionStatus({String? id, String? apiKey}) => (super.noSuchMethod(
Invocation.method( Invocation.method(
#getTransactionStatus, [], {#id: id, #apiKey: apiKey}), #getTransactionStatus, [], {#id: id, #apiKey: apiKey}),
returnValue: returnValue:
Future<_i2.ChangeNowResponse<_i12.ExchangeTransactionStatus>>.value( Future<_i2.ExchangeResponse<_i12.ExchangeTransactionStatus>>.value(
_FakeChangeNowResponse_0<_i12.ExchangeTransactionStatus>())) as _i5 _FakeChangeNowResponse_0<_i12.ExchangeTransactionStatus>())) as _i5
.Future<_i2.ChangeNowResponse<_i12.ExchangeTransactionStatus>>); .Future<_i2.ExchangeResponse<_i12.ExchangeTransactionStatus>>);
@override @override
_i5.Future<_i2.ChangeNowResponse<List<_i13.AvailableFloatingRatePair>>> _i5.Future<_i2.ExchangeResponse<List<_i13.AvailableFloatingRatePair>>>
getAvailableFloatingRatePairs({bool? includePartners = false}) => (super getAvailableFloatingRatePairs({bool? includePartners = false}) => (super
.noSuchMethod( .noSuchMethod(
Invocation.method(#getAvailableFloatingRatePairs, [], Invocation.method(#getAvailableFloatingRatePairs, [],
{#includePartners: includePartners}), {#includePartners: includePartners}),
returnValue: returnValue:
Future<_i2.ChangeNowResponse<List<_i13.AvailableFloatingRatePair>>>.value( Future<_i2.ExchangeResponse<List<_i13.AvailableFloatingRatePair>>>.value(
_FakeChangeNowResponse_0<List<_i13.AvailableFloatingRatePair>>())) as _i5 _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: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_notes_service.dart';
import 'package:stackwallet/services/trade_service.dart'; import 'package:stackwallet/services/trade_service.dart';
import 'package:stackwallet/utilities/prefs.dart'; import 'package:stackwallet/utilities/prefs.dart';
@GenerateMocks([Prefs, TradesService, TradeNotesService, ChangeNow]) @GenerateMocks([Prefs, TradesService, TradeNotesService, ChangeNowAPI])
void main() { void main() {
// testWidgets("ExchangeView builds correctly with no trade history", // testWidgets("ExchangeView builds correctly with no trade history",
// (widgetTester) async { // (widgetTester) async {

View file

@ -10,8 +10,6 @@ import 'package:http/http.dart' as _i13;
import 'package:mockito/mockito.dart' as _i1; import 'package:mockito/mockito.dart' as _i1;
import 'package:stackwallet/models/exchange/change_now/available_floating_rate_pair.dart' import 'package:stackwallet/models/exchange/change_now/available_floating_rate_pair.dart'
as _i20; 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' import 'package:stackwallet/models/exchange/change_now/cn_exchange_estimate.dart'
as _i17; as _i17;
import 'package:stackwallet/models/exchange/change_now/estimated_exchange_amount.dart' 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; as _i14;
import 'package:stackwallet/pages/exchange_view/sub_widgets/exchange_rate_sheet.dart' import 'package:stackwallet/pages/exchange_view/sub_widgets/exchange_rate_sheet.dart'
as _i5; 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_notes_service.dart' as _i11;
import 'package:stackwallet/services/trade_service.dart' as _i9; import 'package:stackwallet/services/trade_service.dart' as _i9;
import 'package:stackwallet/utilities/enums/backup_frequency_type.dart' as _i6; 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 // ignore_for_file: camel_case_types
class _FakeChangeNowResponse_0<T> extends _i1.Fake class _FakeChangeNowResponse_0<T> extends _i1.Fake
implements _i2.ChangeNowResponse<T> {} implements _i2.ExchangeResponse<T> {}
/// A class which mocks [Prefs]. /// A class which mocks [Prefs].
/// ///
@ -351,7 +351,7 @@ class MockTradeNotesService extends _i1.Mock implements _i11.TradeNotesService {
/// A class which mocks [ChangeNow]. /// A class which mocks [ChangeNow].
/// ///
/// See the documentation for Mockito's code generation for more information. /// 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() { MockChangeNow() {
_i1.throwOnMissingStub(this); _i1.throwOnMissingStub(this);
} }
@ -361,25 +361,25 @@ class MockChangeNow extends _i1.Mock implements _i12.ChangeNow {
super.noSuchMethod(Invocation.setter(#client, _client), super.noSuchMethod(Invocation.setter(#client, _client),
returnValueForMissingStub: null); returnValueForMissingStub: null);
@override @override
_i7.Future<_i2.ChangeNowResponse<List<_i14.Currency>>> getAvailableCurrencies( _i7.Future<_i2.ExchangeResponse<List<_i14.Currency>>> getAvailableCurrencies(
{bool? fixedRate, bool? active}) => {bool? fixedRate, bool? active}) =>
(super.noSuchMethod( (super.noSuchMethod(
Invocation.method(#getAvailableCurrencies, [], Invocation.method(#getAvailableCurrencies, [],
{#fixedRate: fixedRate, #active: active}), {#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 _FakeChangeNowResponse_0<List<_i14.Currency>>())) as _i7
.Future<_i2.ChangeNowResponse<List<_i14.Currency>>>); .Future<_i2.ExchangeResponse<List<_i14.Currency>>>);
@override @override
_i7.Future<_i2.ChangeNowResponse<List<_i14.Currency>>> getPairedCurrencies( _i7.Future<_i2.ExchangeResponse<List<_i14.Currency>>> getPairedCurrencies(
{String? ticker, bool? fixedRate}) => {String? ticker, bool? fixedRate}) =>
(super.noSuchMethod( (super.noSuchMethod(
Invocation.method(#getPairedCurrencies, [], Invocation.method(#getPairedCurrencies, [],
{#ticker: ticker, #fixedRate: fixedRate}), {#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 _FakeChangeNowResponse_0<List<_i14.Currency>>())) as _i7
.Future<_i2.ChangeNowResponse<List<_i14.Currency>>>); .Future<_i2.ExchangeResponse<List<_i14.Currency>>>);
@override @override
_i7.Future<_i2.ChangeNowResponse<_i15.Decimal>> getMinimalExchangeAmount( _i7.Future<_i2.ExchangeResponse<_i15.Decimal>> getMinimalExchangeAmount(
{String? fromTicker, String? toTicker, String? apiKey}) => {String? fromTicker, String? toTicker, String? apiKey}) =>
(super.noSuchMethod( (super.noSuchMethod(
Invocation.method(#getMinimalExchangeAmount, [], { Invocation.method(#getMinimalExchangeAmount, [], {
@ -387,11 +387,11 @@ class MockChangeNow extends _i1.Mock implements _i12.ChangeNow {
#toTicker: toTicker, #toTicker: toTicker,
#apiKey: apiKey #apiKey: apiKey
}), }),
returnValue: Future<_i2.ChangeNowResponse<_i15.Decimal>>.value( returnValue: Future<_i2.ExchangeResponse<_i15.Decimal>>.value(
_FakeChangeNowResponse_0<_i15.Decimal>())) _FakeChangeNowResponse_0<_i15.Decimal>()))
as _i7.Future<_i2.ChangeNowResponse<_i15.Decimal>>); as _i7.Future<_i2.ExchangeResponse<_i15.Decimal>>);
@override @override
_i7.Future<_i2.ChangeNowResponse<_i16.EstimatedExchangeAmount>> _i7.Future<_i2.ExchangeResponse<_i16.EstimatedExchangeAmount>>
getEstimatedExchangeAmount( getEstimatedExchangeAmount(
{String? fromTicker, {String? fromTicker,
String? toTicker, String? toTicker,
@ -405,13 +405,13 @@ class MockChangeNow extends _i1.Mock implements _i12.ChangeNow {
#apiKey: apiKey #apiKey: apiKey
}), }),
returnValue: Future< returnValue: Future<
_i2.ChangeNowResponse< _i2.ExchangeResponse<
_i16.EstimatedExchangeAmount>>.value( _i16.EstimatedExchangeAmount>>.value(
_FakeChangeNowResponse_0<_i16.EstimatedExchangeAmount>())) _FakeChangeNowResponse_0<_i16.EstimatedExchangeAmount>()))
as _i7 as _i7
.Future<_i2.ChangeNowResponse<_i16.EstimatedExchangeAmount>>); .Future<_i2.ExchangeResponse<_i16.EstimatedExchangeAmount>>);
@override @override
_i7.Future<_i2.ChangeNowResponse<_i17.CNExchangeEstimate>> _i7.Future<_i2.ExchangeResponse<_i17.CNExchangeEstimate>>
getEstimatedExchangeAmountV2( getEstimatedExchangeAmountV2(
{String? fromTicker, {String? fromTicker,
String? toTicker, String? toTicker,
@ -433,20 +433,20 @@ class MockChangeNow extends _i1.Mock implements _i12.ChangeNow {
#apiKey: apiKey #apiKey: apiKey
}), }),
returnValue: Future< returnValue: Future<
_i2.ChangeNowResponse<_i17.CNExchangeEstimate>>.value( _i2.ExchangeResponse<_i17.CNExchangeEstimate>>.value(
_FakeChangeNowResponse_0<_i17.CNExchangeEstimate>())) _FakeChangeNowResponse_0<_i17.CNExchangeEstimate>()))
as _i7.Future<_i2.ChangeNowResponse<_i17.CNExchangeEstimate>>); as _i7.Future<_i2.ExchangeResponse<_i17.CNExchangeEstimate>>);
@override @override
_i7.Future<_i2.ChangeNowResponse<List<_i18.FixedRateMarket>>> _i7.Future<_i2.ExchangeResponse<List<_i18.FixedRateMarket>>>
getAvailableFixedRateMarkets({String? apiKey}) => (super.noSuchMethod( getAvailableFixedRateMarkets({String? apiKey}) => (super.noSuchMethod(
Invocation.method( Invocation.method(
#getAvailableFixedRateMarkets, [], {#apiKey: apiKey}), #getAvailableFixedRateMarkets, [], {#apiKey: apiKey}),
returnValue: returnValue:
Future<_i2.ChangeNowResponse<List<_i18.FixedRateMarket>>>.value( Future<_i2.ExchangeResponse<List<_i18.FixedRateMarket>>>.value(
_FakeChangeNowResponse_0<List<_i18.FixedRateMarket>>())) as _i7 _FakeChangeNowResponse_0<List<_i18.FixedRateMarket>>()))
.Future<_i2.ChangeNowResponse<List<_i18.FixedRateMarket>>>); as _i7.Future<_i2.ExchangeResponse<List<_i18.FixedRateMarket>>>);
@override @override
_i7.Future<_i2.ChangeNowResponse<_i10.ExchangeTransaction>> _i7.Future<_i2.ExchangeResponse<_i10.ExchangeTransaction>>
createStandardExchangeTransaction( createStandardExchangeTransaction(
{String? fromTicker, {String? fromTicker,
String? toTicker, String? toTicker,
@ -459,24 +459,24 @@ class MockChangeNow extends _i1.Mock implements _i12.ChangeNow {
String? refundExtraId = r'', String? refundExtraId = r'',
String? apiKey}) => String? apiKey}) =>
(super.noSuchMethod( (super.noSuchMethod(
Invocation.method(#createStandardExchangeTransaction, [], { Invocation.method(#createStandardExchangeTransaction, [], {
#fromTicker: fromTicker, #fromTicker: fromTicker,
#toTicker: toTicker, #toTicker: toTicker,
#receivingAddress: receivingAddress, #receivingAddress: receivingAddress,
#amount: amount, #amount: amount,
#extraId: extraId, #extraId: extraId,
#userId: userId, #userId: userId,
#contactEmail: contactEmail, #contactEmail: contactEmail,
#refundAddress: refundAddress, #refundAddress: refundAddress,
#refundExtraId: refundExtraId, #refundExtraId: refundExtraId,
#apiKey: apiKey #apiKey: apiKey
}), }),
returnValue: Future< returnValue: Future<
_i2.ChangeNowResponse<_i10.ExchangeTransaction>>.value( _i2.ExchangeResponse<_i10.ExchangeTransaction>>.value(
_FakeChangeNowResponse_0<_i10.ExchangeTransaction>())) as _i7 _FakeChangeNowResponse_0<_i10.ExchangeTransaction>()))
.Future<_i2.ChangeNowResponse<_i10.ExchangeTransaction>>); as _i7.Future<_i2.ExchangeResponse<_i10.ExchangeTransaction>>);
@override @override
_i7.Future<_i2.ChangeNowResponse<_i10.ExchangeTransaction>> _i7.Future<_i2.ExchangeResponse<_i10.ExchangeTransaction>>
createFixedRateExchangeTransaction( createFixedRateExchangeTransaction(
{String? fromTicker, {String? fromTicker,
String? toTicker, String? toTicker,
@ -490,40 +490,40 @@ class MockChangeNow extends _i1.Mock implements _i12.ChangeNow {
String? refundExtraId = r'', String? refundExtraId = r'',
String? apiKey}) => String? apiKey}) =>
(super.noSuchMethod( (super.noSuchMethod(
Invocation.method(#createFixedRateExchangeTransaction, [], { Invocation.method(#createFixedRateExchangeTransaction, [], {
#fromTicker: fromTicker, #fromTicker: fromTicker,
#toTicker: toTicker, #toTicker: toTicker,
#receivingAddress: receivingAddress, #receivingAddress: receivingAddress,
#amount: amount, #amount: amount,
#rateId: rateId, #rateId: rateId,
#extraId: extraId, #extraId: extraId,
#userId: userId, #userId: userId,
#contactEmail: contactEmail, #contactEmail: contactEmail,
#refundAddress: refundAddress, #refundAddress: refundAddress,
#refundExtraId: refundExtraId, #refundExtraId: refundExtraId,
#apiKey: apiKey #apiKey: apiKey
}), }),
returnValue: Future< returnValue: Future<
_i2.ChangeNowResponse<_i10.ExchangeTransaction>>.value( _i2.ExchangeResponse<_i10.ExchangeTransaction>>.value(
_FakeChangeNowResponse_0<_i10.ExchangeTransaction>())) as _i7 _FakeChangeNowResponse_0<_i10.ExchangeTransaction>()))
.Future<_i2.ChangeNowResponse<_i10.ExchangeTransaction>>); as _i7.Future<_i2.ExchangeResponse<_i10.ExchangeTransaction>>);
@override @override
_i7.Future<_i2.ChangeNowResponse<_i19.ExchangeTransactionStatus>> _i7.Future<_i2.ExchangeResponse<_i19.ExchangeTransactionStatus>>
getTransactionStatus({String? id, String? apiKey}) => (super.noSuchMethod( getTransactionStatus({String? id, String? apiKey}) => (super.noSuchMethod(
Invocation.method( Invocation.method(
#getTransactionStatus, [], {#id: id, #apiKey: apiKey}), #getTransactionStatus, [], {#id: id, #apiKey: apiKey}),
returnValue: returnValue:
Future<_i2.ChangeNowResponse<_i19.ExchangeTransactionStatus>>.value( Future<_i2.ExchangeResponse<_i19.ExchangeTransactionStatus>>.value(
_FakeChangeNowResponse_0<_i19.ExchangeTransactionStatus>())) as _i7 _FakeChangeNowResponse_0<_i19.ExchangeTransactionStatus>())) as _i7
.Future<_i2.ChangeNowResponse<_i19.ExchangeTransactionStatus>>); .Future<_i2.ExchangeResponse<_i19.ExchangeTransactionStatus>>);
@override @override
_i7.Future<_i2.ChangeNowResponse<List<_i20.AvailableFloatingRatePair>>> _i7.Future<_i2.ExchangeResponse<List<_i20.AvailableFloatingRatePair>>>
getAvailableFloatingRatePairs({bool? includePartners = false}) => (super getAvailableFloatingRatePairs({bool? includePartners = false}) => (super
.noSuchMethod( .noSuchMethod(
Invocation.method(#getAvailableFloatingRatePairs, [], Invocation.method(#getAvailableFloatingRatePairs, [],
{#includePartners: includePartners}), {#includePartners: includePartners}),
returnValue: returnValue:
Future<_i2.ChangeNowResponse<List<_i20.AvailableFloatingRatePair>>>.value( Future<_i2.ExchangeResponse<List<_i20.AvailableFloatingRatePair>>>.value(
_FakeChangeNowResponse_0<List<_i20.AvailableFloatingRatePair>>())) as _i7 _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/annotations.dart';
import 'package:mockito/mockito.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/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/estimated_exchange_amount.dart';
import 'package:stackwallet/models/exchange/change_now/exchange_transaction.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/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_sample_data.dart';
import 'change_now_test.mocks.dart'; import 'change_now_test.mocks.dart';
@ -20,7 +20,7 @@ void main() {
group("getAvailableCurrencies", () { group("getAvailableCurrencies", () {
test("getAvailableCurrencies succeeds without options", () async { test("getAvailableCurrencies succeeds without options", () async {
final client = MockClient(); final client = MockClient();
ChangeNow.instance.client = client; ChangeNowAPI.instance.client = client;
when(client.get( when(client.get(
Uri.parse("https://api.ChangeNow.io/v1/currencies"), Uri.parse("https://api.ChangeNow.io/v1/currencies"),
@ -28,7 +28,7 @@ void main() {
)).thenAnswer((realInvocation) async => )).thenAnswer((realInvocation) async =>
Response(jsonEncode(availableCurrenciesJSON), 200)); Response(jsonEncode(availableCurrenciesJSON), 200));
final result = await ChangeNow.instance.getAvailableCurrencies(); final result = await ChangeNowAPI.instance.getAvailableCurrencies();
expect(result.exception, null); expect(result.exception, null);
expect(result.value == null, false); expect(result.value == null, false);
@ -37,7 +37,7 @@ void main() {
test("getAvailableCurrencies succeeds with active option", () async { test("getAvailableCurrencies succeeds with active option", () async {
final client = MockClient(); final client = MockClient();
ChangeNow.instance.client = client; ChangeNowAPI.instance.client = client;
when(client.get( when(client.get(
Uri.parse("https://api.ChangeNow.io/v1/currencies?active=true"), Uri.parse("https://api.ChangeNow.io/v1/currencies?active=true"),
@ -46,7 +46,7 @@ void main() {
Response(jsonEncode(availableCurrenciesJSONActive), 200)); Response(jsonEncode(availableCurrenciesJSONActive), 200));
final result = final result =
await ChangeNow.instance.getAvailableCurrencies(active: true); await ChangeNowAPI.instance.getAvailableCurrencies(active: true);
expect(result.exception, null); expect(result.exception, null);
expect(result.value == null, false); expect(result.value == null, false);
@ -55,7 +55,7 @@ void main() {
test("getAvailableCurrencies succeeds with fixedRate option", () async { test("getAvailableCurrencies succeeds with fixedRate option", () async {
final client = MockClient(); final client = MockClient();
ChangeNow.instance.client = client; ChangeNowAPI.instance.client = client;
when(client.get( when(client.get(
Uri.parse("https://api.ChangeNow.io/v1/currencies?fixedRate=true"), Uri.parse("https://api.ChangeNow.io/v1/currencies?fixedRate=true"),
@ -64,7 +64,7 @@ void main() {
Response(jsonEncode(availableCurrenciesJSONFixedRate), 200)); Response(jsonEncode(availableCurrenciesJSONFixedRate), 200));
final result = final result =
await ChangeNow.instance.getAvailableCurrencies(fixedRate: true); await ChangeNowAPI.instance.getAvailableCurrencies(fixedRate: true);
expect(result.exception, null); expect(result.exception, null);
expect(result.value == null, false); expect(result.value == null, false);
@ -74,7 +74,7 @@ void main() {
test("getAvailableCurrencies succeeds with fixedRate and active options", test("getAvailableCurrencies succeeds with fixedRate and active options",
() async { () async {
final client = MockClient(); final client = MockClient();
ChangeNow.instance.client = client; ChangeNowAPI.instance.client = client;
when(client.get( when(client.get(
Uri.parse( Uri.parse(
@ -83,7 +83,7 @@ void main() {
)).thenAnswer((realInvocation) async => )).thenAnswer((realInvocation) async =>
Response(jsonEncode(availableCurrenciesJSONActiveFixedRate), 200)); Response(jsonEncode(availableCurrenciesJSONActiveFixedRate), 200));
final result = await ChangeNow.instance final result = await ChangeNowAPI.instance
.getAvailableCurrencies(active: true, fixedRate: true); .getAvailableCurrencies(active: true, fixedRate: true);
expect(result.exception, null); expect(result.exception, null);
@ -95,7 +95,7 @@ void main() {
"getAvailableCurrencies fails with ChangeNowExceptionType.serializeResponseError", "getAvailableCurrencies fails with ChangeNowExceptionType.serializeResponseError",
() async { () async {
final client = MockClient(); final client = MockClient();
ChangeNow.instance.client = client; ChangeNowAPI.instance.client = client;
when(client.get( when(client.get(
Uri.parse("https://api.ChangeNow.io/v1/currencies"), Uri.parse("https://api.ChangeNow.io/v1/currencies"),
@ -103,25 +103,25 @@ void main() {
)).thenAnswer((realInvocation) async => )).thenAnswer((realInvocation) async =>
Response('{"some unexpected": "but valid json data"}', 200)); Response('{"some unexpected": "but valid json data"}', 200));
final result = await ChangeNow.instance.getAvailableCurrencies(); final result = await ChangeNowAPI.instance.getAvailableCurrencies();
expect(result.exception!.type, expect(
ChangeNowExceptionType.serializeResponseError); result.exception!.type, ExchangeExceptionType.serializeResponseError);
expect(result.value == null, true); expect(result.value == null, true);
}); });
test("getAvailableCurrencies fails for any other reason", () async { test("getAvailableCurrencies fails for any other reason", () async {
final client = MockClient(); final client = MockClient();
ChangeNow.instance.client = client; ChangeNowAPI.instance.client = client;
when(client.get( when(client.get(
Uri.parse("https://api.ChangeNow.io/v1/currencies"), Uri.parse("https://api.ChangeNow.io/v1/currencies"),
headers: {'Content-Type': 'application/json'}, headers: {'Content-Type': 'application/json'},
)).thenAnswer((realInvocation) async => Response("", 400)); )).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); expect(result.value == null, true);
}); });
}); });
@ -129,7 +129,7 @@ void main() {
group("getPairedCurrencies", () { group("getPairedCurrencies", () {
test("getPairedCurrencies succeeds without fixedRate option", () async { test("getPairedCurrencies succeeds without fixedRate option", () async {
final client = MockClient(); final client = MockClient();
ChangeNow.instance.client = client; ChangeNowAPI.instance.client = client;
when(client.get( when(client.get(
Uri.parse("https://api.ChangeNow.io/v1/currencies-to/XMR"), Uri.parse("https://api.ChangeNow.io/v1/currencies-to/XMR"),
@ -138,7 +138,7 @@ void main() {
Response(jsonEncode(getPairedCurrenciesJSON), 200)); Response(jsonEncode(getPairedCurrenciesJSON), 200));
final result = final result =
await ChangeNow.instance.getPairedCurrencies(ticker: "XMR"); await ChangeNowAPI.instance.getPairedCurrencies(ticker: "XMR");
expect(result.exception, null); expect(result.exception, null);
expect(result.value == null, false); expect(result.value == null, false);
@ -147,7 +147,7 @@ void main() {
test("getPairedCurrencies succeeds with fixedRate option", () async { test("getPairedCurrencies succeeds with fixedRate option", () async {
final client = MockClient(); final client = MockClient();
ChangeNow.instance.client = client; ChangeNowAPI.instance.client = client;
when(client.get( when(client.get(
Uri.parse( Uri.parse(
@ -156,7 +156,7 @@ void main() {
)).thenAnswer((realInvocation) async => )).thenAnswer((realInvocation) async =>
Response(jsonEncode(getPairedCurrenciesJSONFixedRate), 200)); Response(jsonEncode(getPairedCurrenciesJSONFixedRate), 200));
final result = await ChangeNow.instance final result = await ChangeNowAPI.instance
.getPairedCurrencies(ticker: "XMR", fixedRate: true); .getPairedCurrencies(ticker: "XMR", fixedRate: true);
expect(result.exception, null); expect(result.exception, null);
@ -168,7 +168,7 @@ void main() {
"getPairedCurrencies fails with ChangeNowExceptionType.serializeResponseError A", "getPairedCurrencies fails with ChangeNowExceptionType.serializeResponseError A",
() async { () async {
final client = MockClient(); final client = MockClient();
ChangeNow.instance.client = client; ChangeNowAPI.instance.client = client;
when(client.get( when(client.get(
Uri.parse("https://api.ChangeNow.io/v1/currencies-to/XMR"), Uri.parse("https://api.ChangeNow.io/v1/currencies-to/XMR"),
@ -177,26 +177,26 @@ void main() {
Response('[{"some unexpected": "but valid json data"}]', 200)); Response('[{"some unexpected": "but valid json data"}]', 200));
final result = final result =
await ChangeNow.instance.getPairedCurrencies(ticker: "XMR"); await ChangeNowAPI.instance.getPairedCurrencies(ticker: "XMR");
expect(result.exception!.type, expect(
ChangeNowExceptionType.serializeResponseError); result.exception!.type, ExchangeExceptionType.serializeResponseError);
expect(result.value == null, true); expect(result.value == null, true);
}); });
test("getPairedCurrencies fails for any other reason", () async { test("getPairedCurrencies fails for any other reason", () async {
final client = MockClient(); final client = MockClient();
ChangeNow.instance.client = client; ChangeNowAPI.instance.client = client;
when(client.get( when(client.get(
Uri.parse("https://api.ChangeNow.io/v1/currencies"), Uri.parse("https://api.ChangeNow.io/v1/currencies"),
headers: {'Content-Type': 'application/json'}, headers: {'Content-Type': 'application/json'},
)).thenAnswer((realInvocation) async => Response("", 400)); )).thenAnswer((realInvocation) async => Response("", 400));
final result = await ChangeNow.instance final result = await ChangeNowAPI.instance
.getPairedCurrencies(ticker: "XMR", fixedRate: true); .getPairedCurrencies(ticker: "XMR", fixedRate: true);
expect(result.exception!.type, ChangeNowExceptionType.generic); expect(result.exception!.type, ExchangeExceptionType.generic);
expect(result.value == null, true); expect(result.value == null, true);
}); });
}); });
@ -204,7 +204,7 @@ void main() {
group("getMinimalExchangeAmount", () { group("getMinimalExchangeAmount", () {
test("getMinimalExchangeAmount succeeds", () async { test("getMinimalExchangeAmount succeeds", () async {
final client = MockClient(); final client = MockClient();
ChangeNow.instance.client = client; ChangeNowAPI.instance.client = client;
when(client.get( when(client.get(
Uri.parse( Uri.parse(
@ -213,7 +213,7 @@ void main() {
)).thenAnswer( )).thenAnswer(
(realInvocation) async => Response('{"minAmount": 42}', 200)); (realInvocation) async => Response('{"minAmount": 42}', 200));
final result = await ChangeNow.instance.getMinimalExchangeAmount( final result = await ChangeNowAPI.instance.getMinimalExchangeAmount(
fromTicker: "xmr", fromTicker: "xmr",
toTicker: "btc", toTicker: "btc",
apiKey: "testAPIKEY", apiKey: "testAPIKEY",
@ -228,7 +228,7 @@ void main() {
"getMinimalExchangeAmount fails with ChangeNowExceptionType.serializeResponseError", "getMinimalExchangeAmount fails with ChangeNowExceptionType.serializeResponseError",
() async { () async {
final client = MockClient(); final client = MockClient();
ChangeNow.instance.client = client; ChangeNowAPI.instance.client = client;
when(client.get( when(client.get(
Uri.parse( Uri.parse(
@ -236,20 +236,20 @@ void main() {
headers: {'Content-Type': 'application/json'}, headers: {'Content-Type': 'application/json'},
)).thenAnswer((realInvocation) async => Response('{"error": 42}', 200)); )).thenAnswer((realInvocation) async => Response('{"error": 42}', 200));
final result = await ChangeNow.instance.getMinimalExchangeAmount( final result = await ChangeNowAPI.instance.getMinimalExchangeAmount(
fromTicker: "xmr", fromTicker: "xmr",
toTicker: "btc", toTicker: "btc",
apiKey: "testAPIKEY", apiKey: "testAPIKEY",
); );
expect(result.exception!.type, expect(
ChangeNowExceptionType.serializeResponseError); result.exception!.type, ExchangeExceptionType.serializeResponseError);
expect(result.value == null, true); expect(result.value == null, true);
}); });
test("getMinimalExchangeAmount fails for any other reason", () async { test("getMinimalExchangeAmount fails for any other reason", () async {
final client = MockClient(); final client = MockClient();
ChangeNow.instance.client = client; ChangeNowAPI.instance.client = client;
when(client.get( when(client.get(
Uri.parse( Uri.parse(
@ -257,13 +257,13 @@ void main() {
headers: {'Content-Type': 'application/json'}, headers: {'Content-Type': 'application/json'},
)).thenAnswer((realInvocation) async => Response('', 400)); )).thenAnswer((realInvocation) async => Response('', 400));
final result = await ChangeNow.instance.getMinimalExchangeAmount( final result = await ChangeNowAPI.instance.getMinimalExchangeAmount(
fromTicker: "xmr", fromTicker: "xmr",
toTicker: "btc", toTicker: "btc",
apiKey: "testAPIKEY", apiKey: "testAPIKEY",
); );
expect(result.exception!.type, ChangeNowExceptionType.generic); expect(result.exception!.type, ExchangeExceptionType.generic);
expect(result.value == null, true); expect(result.value == null, true);
}); });
}); });
@ -271,7 +271,7 @@ void main() {
group("getEstimatedExchangeAmount", () { group("getEstimatedExchangeAmount", () {
test("getEstimatedExchangeAmount succeeds", () async { test("getEstimatedExchangeAmount succeeds", () async {
final client = MockClient(); final client = MockClient();
ChangeNow.instance.client = client; ChangeNowAPI.instance.client = client;
when(client.get( when(client.get(
Uri.parse( Uri.parse(
@ -281,7 +281,7 @@ void main() {
'{"estimatedAmount": 58.4142873, "transactionSpeedForecast": "10-60", "warningMessage": null}', '{"estimatedAmount": 58.4142873, "transactionSpeedForecast": "10-60", "warningMessage": null}',
200)); 200));
final result = await ChangeNow.instance.getEstimatedExchangeAmount( final result = await ChangeNowAPI.instance.getEstimatedExchangeAmount(
fromTicker: "xmr", fromTicker: "xmr",
toTicker: "btc", toTicker: "btc",
fromAmount: Decimal.fromInt(42), fromAmount: Decimal.fromInt(42),
@ -297,7 +297,7 @@ void main() {
"getEstimatedExchangeAmount fails with ChangeNowExceptionType.serializeResponseError", "getEstimatedExchangeAmount fails with ChangeNowExceptionType.serializeResponseError",
() async { () async {
final client = MockClient(); final client = MockClient();
ChangeNow.instance.client = client; ChangeNowAPI.instance.client = client;
when(client.get( when(client.get(
Uri.parse( Uri.parse(
@ -305,21 +305,21 @@ void main() {
headers: {'Content-Type': 'application/json'}, headers: {'Content-Type': 'application/json'},
)).thenAnswer((realInvocation) async => Response('{"error": 42}', 200)); )).thenAnswer((realInvocation) async => Response('{"error": 42}', 200));
final result = await ChangeNow.instance.getEstimatedExchangeAmount( final result = await ChangeNowAPI.instance.getEstimatedExchangeAmount(
fromTicker: "xmr", fromTicker: "xmr",
toTicker: "btc", toTicker: "btc",
fromAmount: Decimal.fromInt(42), fromAmount: Decimal.fromInt(42),
apiKey: "testAPIKEY", apiKey: "testAPIKEY",
); );
expect(result.exception!.type, expect(
ChangeNowExceptionType.serializeResponseError); result.exception!.type, ExchangeExceptionType.serializeResponseError);
expect(result.value == null, true); expect(result.value == null, true);
}); });
test("getEstimatedExchangeAmount fails for any other reason", () async { test("getEstimatedExchangeAmount fails for any other reason", () async {
final client = MockClient(); final client = MockClient();
ChangeNow.instance.client = client; ChangeNowAPI.instance.client = client;
when(client.get( when(client.get(
Uri.parse( Uri.parse(
@ -327,14 +327,14 @@ void main() {
headers: {'Content-Type': 'application/json'}, headers: {'Content-Type': 'application/json'},
)).thenAnswer((realInvocation) async => Response('', 400)); )).thenAnswer((realInvocation) async => Response('', 400));
final result = await ChangeNow.instance.getEstimatedExchangeAmount( final result = await ChangeNowAPI.instance.getEstimatedExchangeAmount(
fromTicker: "xmr", fromTicker: "xmr",
toTicker: "btc", toTicker: "btc",
fromAmount: Decimal.fromInt(42), fromAmount: Decimal.fromInt(42),
apiKey: "testAPIKEY", apiKey: "testAPIKEY",
); );
expect(result.exception!.type, ChangeNowExceptionType.generic); expect(result.exception!.type, ExchangeExceptionType.generic);
expect(result.value == null, true); expect(result.value == null, true);
}); });
}); });
@ -417,7 +417,7 @@ void main() {
group("getAvailableFixedRateMarkets", () { group("getAvailableFixedRateMarkets", () {
test("getAvailableFixedRateMarkets succeeds", () async { test("getAvailableFixedRateMarkets succeeds", () async {
final client = MockClient(); final client = MockClient();
ChangeNow.instance.client = client; ChangeNowAPI.instance.client = client;
when(client.get( when(client.get(
Uri.parse( Uri.parse(
@ -426,7 +426,7 @@ void main() {
)).thenAnswer((realInvocation) async => )).thenAnswer((realInvocation) async =>
Response(jsonEncode(fixedRateMarketsJSON), 200)); Response(jsonEncode(fixedRateMarketsJSON), 200));
final result = await ChangeNow.instance.getAvailableFixedRateMarkets( final result = await ChangeNowAPI.instance.getAvailableFixedRateMarkets(
apiKey: "testAPIKEY", apiKey: "testAPIKEY",
); );
@ -439,7 +439,7 @@ void main() {
"getAvailableFixedRateMarkets fails with ChangeNowExceptionType.serializeResponseError", "getAvailableFixedRateMarkets fails with ChangeNowExceptionType.serializeResponseError",
() async { () async {
final client = MockClient(); final client = MockClient();
ChangeNow.instance.client = client; ChangeNowAPI.instance.client = client;
when(client.get( when(client.get(
Uri.parse( Uri.parse(
@ -447,18 +447,18 @@ void main() {
headers: {'Content-Type': 'application/json'}, headers: {'Content-Type': 'application/json'},
)).thenAnswer((realInvocation) async => Response('{"error": 42}', 200)); )).thenAnswer((realInvocation) async => Response('{"error": 42}', 200));
final result = await ChangeNow.instance.getAvailableFixedRateMarkets( final result = await ChangeNowAPI.instance.getAvailableFixedRateMarkets(
apiKey: "testAPIKEY", apiKey: "testAPIKEY",
); );
expect(result.exception!.type, expect(
ChangeNowExceptionType.serializeResponseError); result.exception!.type, ExchangeExceptionType.serializeResponseError);
expect(result.value == null, true); expect(result.value == null, true);
}); });
test("getAvailableFixedRateMarkets fails for any other reason", () async { test("getAvailableFixedRateMarkets fails for any other reason", () async {
final client = MockClient(); final client = MockClient();
ChangeNow.instance.client = client; ChangeNowAPI.instance.client = client;
when(client.get( when(client.get(
Uri.parse( Uri.parse(
@ -466,11 +466,11 @@ void main() {
headers: {'Content-Type': 'application/json'}, headers: {'Content-Type': 'application/json'},
)).thenAnswer((realInvocation) async => Response('', 400)); )).thenAnswer((realInvocation) async => Response('', 400));
final result = await ChangeNow.instance.getAvailableFixedRateMarkets( final result = await ChangeNowAPI.instance.getAvailableFixedRateMarkets(
apiKey: "testAPIKEY", apiKey: "testAPIKEY",
); );
expect(result.exception!.type, ChangeNowExceptionType.generic); expect(result.exception!.type, ExchangeExceptionType.generic);
expect(result.value == null, true); expect(result.value == null, true);
}); });
}); });
@ -478,7 +478,7 @@ void main() {
group("createStandardExchangeTransaction", () { group("createStandardExchangeTransaction", () {
test("createStandardExchangeTransaction succeeds", () async { test("createStandardExchangeTransaction succeeds", () async {
final client = MockClient(); final client = MockClient();
ChangeNow.instance.client = client; ChangeNowAPI.instance.client = client;
when(client.post( when(client.post(
Uri.parse("https://api.ChangeNow.io/v1/transactions/testAPIKEY"), Uri.parse("https://api.ChangeNow.io/v1/transactions/testAPIKEY"),
@ -489,7 +489,8 @@ void main() {
)).thenAnswer((realInvocation) async => )).thenAnswer((realInvocation) async =>
Response(jsonEncode(createStandardTransactionResponse), 200)); Response(jsonEncode(createStandardTransactionResponse), 200));
final result = await ChangeNow.instance.createStandardExchangeTransaction( final result =
await ChangeNowAPI.instance.createStandardExchangeTransaction(
fromTicker: "xmr", fromTicker: "xmr",
toTicker: "btc", toTicker: "btc",
receivingAddress: "bc1qu58svs9983e2vuyqh7gq7ratf8k5qehz5k0cn5", receivingAddress: "bc1qu58svs9983e2vuyqh7gq7ratf8k5qehz5k0cn5",
@ -508,7 +509,7 @@ void main() {
"createStandardExchangeTransaction fails with ChangeNowExceptionType.serializeResponseError", "createStandardExchangeTransaction fails with ChangeNowExceptionType.serializeResponseError",
() async { () async {
final client = MockClient(); final client = MockClient();
ChangeNow.instance.client = client; ChangeNowAPI.instance.client = client;
when(client.post( when(client.post(
Uri.parse("https://api.ChangeNow.io/v1/transactions/testAPIKEY"), Uri.parse("https://api.ChangeNow.io/v1/transactions/testAPIKEY"),
@ -518,7 +519,8 @@ void main() {
encoding: null, encoding: null,
)).thenAnswer((realInvocation) async => Response('{"error": 42}', 200)); )).thenAnswer((realInvocation) async => Response('{"error": 42}', 200));
final result = await ChangeNow.instance.createStandardExchangeTransaction( final result =
await ChangeNowAPI.instance.createStandardExchangeTransaction(
fromTicker: "xmr", fromTicker: "xmr",
toTicker: "btc", toTicker: "btc",
receivingAddress: "bc1qu58svs9983e2vuyqh7gq7ratf8k5qehz5k0cn5", receivingAddress: "bc1qu58svs9983e2vuyqh7gq7ratf8k5qehz5k0cn5",
@ -528,15 +530,15 @@ void main() {
apiKey: "testAPIKEY", apiKey: "testAPIKEY",
); );
expect(result.exception!.type, expect(
ChangeNowExceptionType.serializeResponseError); result.exception!.type, ExchangeExceptionType.serializeResponseError);
expect(result.value == null, true); expect(result.value == null, true);
}); });
test("createStandardExchangeTransaction fails for any other reason", test("createStandardExchangeTransaction fails for any other reason",
() async { () async {
final client = MockClient(); final client = MockClient();
ChangeNow.instance.client = client; ChangeNowAPI.instance.client = client;
when(client.post( when(client.post(
Uri.parse("https://api.ChangeNow.io/v1/transactions/testAPIKEY"), Uri.parse("https://api.ChangeNow.io/v1/transactions/testAPIKEY"),
@ -546,7 +548,8 @@ void main() {
encoding: null, encoding: null,
)).thenAnswer((realInvocation) async => Response('', 400)); )).thenAnswer((realInvocation) async => Response('', 400));
final result = await ChangeNow.instance.createStandardExchangeTransaction( final result =
await ChangeNowAPI.instance.createStandardExchangeTransaction(
fromTicker: "xmr", fromTicker: "xmr",
toTicker: "btc", toTicker: "btc",
receivingAddress: "bc1qu58svs9983e2vuyqh7gq7ratf8k5qehz5k0cn5", receivingAddress: "bc1qu58svs9983e2vuyqh7gq7ratf8k5qehz5k0cn5",
@ -556,7 +559,7 @@ void main() {
apiKey: "testAPIKEY", apiKey: "testAPIKEY",
); );
expect(result.exception!.type, ChangeNowExceptionType.generic); expect(result.exception!.type, ExchangeExceptionType.generic);
expect(result.value == null, true); expect(result.value == null, true);
}); });
}); });
@ -564,7 +567,7 @@ void main() {
group("createFixedRateExchangeTransaction", () { group("createFixedRateExchangeTransaction", () {
test("createFixedRateExchangeTransaction succeeds", () async { test("createFixedRateExchangeTransaction succeeds", () async {
final client = MockClient(); final client = MockClient();
ChangeNow.instance.client = client; ChangeNowAPI.instance.client = client;
when(client.post( when(client.post(
Uri.parse( Uri.parse(
@ -578,7 +581,7 @@ void main() {
200)); 200));
final result = final result =
await ChangeNow.instance.createFixedRateExchangeTransaction( await ChangeNowAPI.instance.createFixedRateExchangeTransaction(
fromTicker: "btc", fromTicker: "btc",
toTicker: "eth", toTicker: "eth",
receivingAddress: "0x57f31ad4b64095347F87eDB1675566DAfF5EC886", receivingAddress: "0x57f31ad4b64095347F87eDB1675566DAfF5EC886",
@ -597,7 +600,7 @@ void main() {
"createFixedRateExchangeTransaction fails with ChangeNowExceptionType.serializeResponseError", "createFixedRateExchangeTransaction fails with ChangeNowExceptionType.serializeResponseError",
() async { () async {
final client = MockClient(); final client = MockClient();
ChangeNow.instance.client = client; ChangeNowAPI.instance.client = client;
when(client.post( when(client.post(
Uri.parse( Uri.parse(
@ -610,7 +613,7 @@ void main() {
Response('{"id": "a5c73e2603f40d","amount": 62.9737711}', 200)); Response('{"id": "a5c73e2603f40d","amount": 62.9737711}', 200));
final result = final result =
await ChangeNow.instance.createFixedRateExchangeTransaction( await ChangeNowAPI.instance.createFixedRateExchangeTransaction(
fromTicker: "btc", fromTicker: "btc",
toTicker: "eth", toTicker: "eth",
receivingAddress: "0x57f31ad4b64095347F87eDB1675566DAfF5EC886", receivingAddress: "0x57f31ad4b64095347F87eDB1675566DAfF5EC886",
@ -620,15 +623,15 @@ void main() {
rateId: '', rateId: '',
); );
expect(result.exception!.type, expect(
ChangeNowExceptionType.serializeResponseError); result.exception!.type, ExchangeExceptionType.serializeResponseError);
expect(result.value == null, true); expect(result.value == null, true);
}); });
test("createFixedRateExchangeTransaction fails for any other reason", test("createFixedRateExchangeTransaction fails for any other reason",
() async { () async {
final client = MockClient(); final client = MockClient();
ChangeNow.instance.client = client; ChangeNowAPI.instance.client = client;
when(client.post( when(client.post(
Uri.parse( Uri.parse(
@ -640,7 +643,7 @@ void main() {
)).thenAnswer((realInvocation) async => Response('', 400)); )).thenAnswer((realInvocation) async => Response('', 400));
final result = final result =
await ChangeNow.instance.createFixedRateExchangeTransaction( await ChangeNowAPI.instance.createFixedRateExchangeTransaction(
fromTicker: "xmr", fromTicker: "xmr",
toTicker: "btc", toTicker: "btc",
receivingAddress: "bc1qu58svs9983e2vuyqh7gq7ratf8k5qehz5k0cn5", receivingAddress: "bc1qu58svs9983e2vuyqh7gq7ratf8k5qehz5k0cn5",
@ -651,7 +654,7 @@ void main() {
rateId: '', rateId: '',
); );
expect(result.exception!.type, ChangeNowExceptionType.generic); expect(result.exception!.type, ExchangeExceptionType.generic);
expect(result.value == null, true); expect(result.value == null, true);
}); });
}); });
@ -659,7 +662,7 @@ void main() {
group("getTransactionStatus", () { group("getTransactionStatus", () {
test("getTransactionStatus succeeds", () async { test("getTransactionStatus succeeds", () async {
final client = MockClient(); final client = MockClient();
ChangeNow.instance.client = client; ChangeNowAPI.instance.client = client;
when(client.get( when(client.get(
Uri.parse( 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}', '{"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)); 200));
final result = await ChangeNow.instance.getTransactionStatus( final result = await ChangeNowAPI.instance.getTransactionStatus(
id: "47F87eDB1675566DAfF5EC886", id: "47F87eDB1675566DAfF5EC886",
apiKey: "testAPIKEY", apiKey: "testAPIKEY",
); );
@ -683,7 +686,7 @@ void main() {
"getTransactionStatus fails with ChangeNowExceptionType.serializeResponseError", "getTransactionStatus fails with ChangeNowExceptionType.serializeResponseError",
() async { () async {
final client = MockClient(); final client = MockClient();
ChangeNow.instance.client = client; ChangeNowAPI.instance.client = client;
when(client.get( when(client.get(
Uri.parse( Uri.parse(
@ -691,19 +694,19 @@ void main() {
headers: {'Content-Type': 'application/json'}, headers: {'Content-Type': 'application/json'},
)).thenAnswer((realInvocation) async => Response('{"error": 42}', 200)); )).thenAnswer((realInvocation) async => Response('{"error": 42}', 200));
final result = await ChangeNow.instance.getTransactionStatus( final result = await ChangeNowAPI.instance.getTransactionStatus(
id: "47F87eDB1675566DAfF5EC886", id: "47F87eDB1675566DAfF5EC886",
apiKey: "testAPIKEY", apiKey: "testAPIKEY",
); );
expect(result.exception!.type, expect(
ChangeNowExceptionType.serializeResponseError); result.exception!.type, ExchangeExceptionType.serializeResponseError);
expect(result.value == null, true); expect(result.value == null, true);
}); });
test("getTransactionStatus fails for any other reason", () async { test("getTransactionStatus fails for any other reason", () async {
final client = MockClient(); final client = MockClient();
ChangeNow.instance.client = client; ChangeNowAPI.instance.client = client;
when(client.get( when(client.get(
Uri.parse( Uri.parse(
@ -711,12 +714,12 @@ void main() {
headers: {'Content-Type': 'application/json'}, headers: {'Content-Type': 'application/json'},
)).thenAnswer((realInvocation) async => Response('', 400)); )).thenAnswer((realInvocation) async => Response('', 400));
final result = await ChangeNow.instance.getTransactionStatus( final result = await ChangeNowAPI.instance.getTransactionStatus(
id: "47F87eDB1675566DAfF5EC886", id: "47F87eDB1675566DAfF5EC886",
apiKey: "testAPIKEY", apiKey: "testAPIKEY",
); );
expect(result.exception!.type, ChangeNowExceptionType.generic); expect(result.exception!.type, ExchangeExceptionType.generic);
expect(result.value == null, true); expect(result.value == null, true);
}); });
}); });
@ -724,7 +727,7 @@ void main() {
group("getAvailableFloatingRatePairs", () { group("getAvailableFloatingRatePairs", () {
test("getAvailableFloatingRatePairs succeeds", () async { test("getAvailableFloatingRatePairs succeeds", () async {
final client = MockClient(); final client = MockClient();
ChangeNow.instance.client = client; ChangeNowAPI.instance.client = client;
when(client.get( when(client.get(
Uri.parse( Uri.parse(
@ -733,7 +736,8 @@ void main() {
)).thenAnswer((realInvocation) async => )).thenAnswer((realInvocation) async =>
Response('["btc_xmr","btc_firo","btc_doge","eth_ltc"]', 200)); 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.exception, null);
expect(result.value == null, false); expect(result.value == null, false);
@ -744,7 +748,7 @@ void main() {
"getAvailableFloatingRatePairs fails with ChangeNowExceptionType.serializeResponseError", "getAvailableFloatingRatePairs fails with ChangeNowExceptionType.serializeResponseError",
() async { () async {
final client = MockClient(); final client = MockClient();
ChangeNow.instance.client = client; ChangeNowAPI.instance.client = client;
when(client.get( when(client.get(
Uri.parse( Uri.parse(
@ -752,16 +756,17 @@ void main() {
headers: {'Content-Type': 'application/json'}, headers: {'Content-Type': 'application/json'},
)).thenAnswer((realInvocation) async => Response('{"error": 42}', 200)); )).thenAnswer((realInvocation) async => Response('{"error": 42}', 200));
final result = await ChangeNow.instance.getAvailableFloatingRatePairs(); final result =
await ChangeNowAPI.instance.getAvailableFloatingRatePairs();
expect(result.exception!.type, expect(
ChangeNowExceptionType.serializeResponseError); result.exception!.type, ExchangeExceptionType.serializeResponseError);
expect(result.value == null, true); expect(result.value == null, true);
}); });
test("getAvailableFloatingRatePairs fails for any other reason", () async { test("getAvailableFloatingRatePairs fails for any other reason", () async {
final client = MockClient(); final client = MockClient();
ChangeNow.instance.client = client; ChangeNowAPI.instance.client = client;
when(client.get( when(client.get(
Uri.parse( Uri.parse(
@ -769,9 +774,10 @@ void main() {
headers: {'Content-Type': 'application/json'}, headers: {'Content-Type': 'application/json'},
)).thenAnswer((realInvocation) async => Response('', 400)); )).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); expect(result.value == null, true);
}); });
}); });