mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-12-23 03:49:22 +00:00
refactor ChangeNow for easier testability
This commit is contained in:
parent
0cebce6706
commit
71826d4da3
13 changed files with 321 additions and 271 deletions
|
@ -31,6 +31,7 @@ import 'package:stackwallet/pages/pinpad_views/lock_screen_view.dart';
|
||||||
import 'package:stackwallet/pages/settings_views/global_settings_view/stack_backup_views/restore_from_encrypted_string_view.dart';
|
import 'package:stackwallet/pages/settings_views/global_settings_view/stack_backup_views/restore_from_encrypted_string_view.dart';
|
||||||
import 'package:stackwallet/providers/exchange/available_currencies_state_provider.dart';
|
import 'package:stackwallet/providers/exchange/available_currencies_state_provider.dart';
|
||||||
import 'package:stackwallet/providers/exchange/available_floating_rate_pairs_state_provider.dart';
|
import 'package:stackwallet/providers/exchange/available_floating_rate_pairs_state_provider.dart';
|
||||||
|
import 'package:stackwallet/providers/exchange/change_now_provider.dart';
|
||||||
import 'package:stackwallet/providers/exchange/changenow_initial_load_status.dart';
|
import 'package:stackwallet/providers/exchange/changenow_initial_load_status.dart';
|
||||||
import 'package:stackwallet/providers/exchange/exchange_form_provider.dart';
|
import 'package:stackwallet/providers/exchange/exchange_form_provider.dart';
|
||||||
import 'package:stackwallet/providers/exchange/fixed_rate_exchange_form_provider.dart';
|
import 'package:stackwallet/providers/exchange/fixed_rate_exchange_form_provider.dart';
|
||||||
|
@ -41,7 +42,6 @@ import 'package:stackwallet/providers/global/base_currencies_provider.dart';
|
||||||
import 'package:stackwallet/providers/global/trades_service_provider.dart';
|
import 'package:stackwallet/providers/global/trades_service_provider.dart';
|
||||||
import 'package:stackwallet/providers/providers.dart';
|
import 'package:stackwallet/providers/providers.dart';
|
||||||
import 'package:stackwallet/route_generator.dart';
|
import 'package:stackwallet/route_generator.dart';
|
||||||
import 'package:stackwallet/services/change_now/change_now.dart';
|
|
||||||
import 'package:stackwallet/services/debug_service.dart';
|
import 'package:stackwallet/services/debug_service.dart';
|
||||||
import 'package:stackwallet/services/locale_service.dart';
|
import 'package:stackwallet/services/locale_service.dart';
|
||||||
import 'package:stackwallet/services/node_service.dart';
|
import 'package:stackwallet/services/node_service.dart';
|
||||||
|
@ -79,7 +79,7 @@ void main() async {
|
||||||
await DebugService.instance.init(isar);
|
await DebugService.instance.init(isar);
|
||||||
|
|
||||||
// clear out all info logs on startup. No need to await and block
|
// clear out all info logs on startup. No need to await and block
|
||||||
DebugService.instance.purgeInfoLogs();
|
unawaited(DebugService.instance.purgeInfoLogs());
|
||||||
|
|
||||||
// Registering Transaction Model Adapters
|
// Registering Transaction Model Adapters
|
||||||
Hive.registerAdapter(TransactionDataAdapter());
|
Hive.registerAdapter(TransactionDataAdapter());
|
||||||
|
@ -193,13 +193,14 @@ class _MaterialAppWithThemeState extends ConsumerState<MaterialAppWithTheme>
|
||||||
NotificationApi.prefs = _prefs;
|
NotificationApi.prefs = _prefs;
|
||||||
NotificationApi.notificationsService = _notificationsService;
|
NotificationApi.notificationsService = _notificationsService;
|
||||||
|
|
||||||
ref.read(baseCurrenciesProvider).update();
|
unawaited(ref.read(baseCurrenciesProvider).update());
|
||||||
|
|
||||||
await _nodeService.updateDefaults();
|
await _nodeService.updateDefaults();
|
||||||
await _notificationsService.init(
|
await _notificationsService.init(
|
||||||
nodeService: _nodeService,
|
nodeService: _nodeService,
|
||||||
tradesService: _tradesService,
|
tradesService: _tradesService,
|
||||||
prefs: _prefs,
|
prefs: _prefs,
|
||||||
|
changeNow: ref.read(changeNowProvider),
|
||||||
);
|
);
|
||||||
await _prefs.init();
|
await _prefs.init();
|
||||||
ref.read(priceAnd24hChangeNotifierProvider).start(true);
|
ref.read(priceAnd24hChangeNotifierProvider).start(true);
|
||||||
|
@ -216,7 +217,7 @@ class _MaterialAppWithThemeState extends ConsumerState<MaterialAppWithTheme>
|
||||||
.startPeriodicBackupTimer(duration: const Duration(minutes: 10));
|
.startPeriodicBackupTimer(duration: const Duration(minutes: 10));
|
||||||
break;
|
break;
|
||||||
case BackupFrequencyType.everyAppStart:
|
case BackupFrequencyType.everyAppStart:
|
||||||
ref.read(autoSWBServiceProvider).doBackup();
|
unawaited(ref.read(autoSWBServiceProvider).doBackup());
|
||||||
break;
|
break;
|
||||||
case BackupFrequencyType.afterClosingAWallet:
|
case BackupFrequencyType.afterClosingAWallet:
|
||||||
// ignore this case here
|
// ignore this case here
|
||||||
|
@ -236,8 +237,9 @@ class _MaterialAppWithThemeState extends ConsumerState<MaterialAppWithTheme>
|
||||||
.isNotEmpty) {
|
.isNotEmpty) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final response = await ChangeNow.getAvailableCurrencies();
|
final response = await ref.read(changeNowProvider).getAvailableCurrencies();
|
||||||
final response2 = await ChangeNow.getAvailableFloatingRatePairs();
|
final response2 =
|
||||||
|
await ref.read(changeNowProvider).getAvailableFloatingRatePairs();
|
||||||
if (response.value != null) {
|
if (response.value != null) {
|
||||||
ref.read(availableChangeNowCurrenciesStateProvider.state).state =
|
ref.read(availableChangeNowCurrenciesStateProvider.state).state =
|
||||||
response.value!;
|
response.value!;
|
||||||
|
@ -248,13 +250,13 @@ class _MaterialAppWithThemeState extends ConsumerState<MaterialAppWithTheme>
|
||||||
if (response.value!.length > 1) {
|
if (response.value!.length > 1) {
|
||||||
if (ref.read(estimatedRateExchangeFormProvider).from == null) {
|
if (ref.read(estimatedRateExchangeFormProvider).from == null) {
|
||||||
if (response.value!.where((e) => e.ticker == "btc").isNotEmpty) {
|
if (response.value!.where((e) => e.ticker == "btc").isNotEmpty) {
|
||||||
ref.read(estimatedRateExchangeFormProvider).updateFrom(
|
await ref.read(estimatedRateExchangeFormProvider).updateFrom(
|
||||||
response.value!.firstWhere((e) => e.ticker == "btc"), false);
|
response.value!.firstWhere((e) => e.ticker == "btc"), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ref.read(estimatedRateExchangeFormProvider).to == null) {
|
if (ref.read(estimatedRateExchangeFormProvider).to == null) {
|
||||||
if (response.value!.where((e) => e.ticker == "doge").isNotEmpty) {
|
if (response.value!.where((e) => e.ticker == "doge").isNotEmpty) {
|
||||||
ref.read(estimatedRateExchangeFormProvider).updateTo(
|
await ref.read(estimatedRateExchangeFormProvider).updateTo(
|
||||||
response.value!.firstWhere((e) => e.ticker == "doge"), false);
|
response.value!.firstWhere((e) => e.ticker == "doge"), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -288,7 +290,8 @@ class _MaterialAppWithThemeState extends ConsumerState<MaterialAppWithTheme>
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final response3 = await ChangeNow.getAvailableFixedRateMarkets();
|
final response3 =
|
||||||
|
await ref.read(changeNowProvider).getAvailableFixedRateMarkets();
|
||||||
if (response3.value != null) {
|
if (response3.value != null) {
|
||||||
ref.read(fixedRateMarketPairsStateProvider.state).state =
|
ref.read(fixedRateMarketPairsStateProvider.state).state =
|
||||||
response3.value!;
|
response3.value!;
|
||||||
|
@ -297,7 +300,7 @@ class _MaterialAppWithThemeState extends ConsumerState<MaterialAppWithTheme>
|
||||||
final matchingMarkets =
|
final matchingMarkets =
|
||||||
response3.value!.where((e) => e.to == "doge" && e.from == "btc");
|
response3.value!.where((e) => e.to == "doge" && e.from == "btc");
|
||||||
if (matchingMarkets.isNotEmpty) {
|
if (matchingMarkets.isNotEmpty) {
|
||||||
ref
|
await ref
|
||||||
.read(fixedRateExchangeFormProvider)
|
.read(fixedRateExchangeFormProvider)
|
||||||
.updateMarket(matchingMarkets.first, true);
|
.updateMarket(matchingMarkets.first, true);
|
||||||
}
|
}
|
||||||
|
@ -443,7 +446,7 @@ class _MaterialAppWithThemeState extends ConsumerState<MaterialAppWithTheme>
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
Navigator.push(
|
unawaited(Navigator.push(
|
||||||
navigatorKey.currentContext!,
|
navigatorKey.currentContext!,
|
||||||
RouteGenerator.getRoute(
|
RouteGenerator.getRoute(
|
||||||
shouldUseMaterialRoute: RouteGenerator.useMaterialPageRoute,
|
shouldUseMaterialRoute: RouteGenerator.useMaterialPageRoute,
|
||||||
|
@ -458,7 +461,7 @@ class _MaterialAppWithThemeState extends ConsumerState<MaterialAppWithTheme>
|
||||||
),
|
),
|
||||||
settings: const RouteSettings(name: "/swbrestorelockscreen"),
|
settings: const RouteSettings(name: "/swbrestorelockscreen"),
|
||||||
),
|
),
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -270,7 +270,7 @@ class ExchangeFormState extends ChangeNotifier {
|
||||||
required Currency from,
|
required Currency from,
|
||||||
required Currency to,
|
required Currency to,
|
||||||
}) async {
|
}) async {
|
||||||
final response = await ChangeNow.getEstimatedExchangeAmount(
|
final response = await ChangeNow.instance.getEstimatedExchangeAmount(
|
||||||
fromTicker: from.ticker, toTicker: to.ticker, fromAmount: fromAmount);
|
fromTicker: from.ticker, toTicker: to.ticker, fromAmount: fromAmount);
|
||||||
|
|
||||||
if (response.value != null) {
|
if (response.value != null) {
|
||||||
|
@ -286,8 +286,8 @@ class ExchangeFormState extends ChangeNotifier {
|
||||||
required Currency from,
|
required Currency from,
|
||||||
required Currency to,
|
required Currency to,
|
||||||
}) async {
|
}) async {
|
||||||
final response = await ChangeNow.getMinimalExchangeAmount(
|
final response = await ChangeNow.instance
|
||||||
fromTicker: from.ticker, toTicker: to.ticker);
|
.getMinimalExchangeAmount(fromTicker: from.ticker, toTicker: to.ticker);
|
||||||
|
|
||||||
if (response.value != null) {
|
if (response.value != null) {
|
||||||
return response.value!;
|
return response.value!;
|
||||||
|
|
|
@ -2,11 +2,11 @@ import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:stackwallet/providers/exchange/available_currencies_state_provider.dart';
|
import 'package:stackwallet/providers/exchange/available_currencies_state_provider.dart';
|
||||||
import 'package:stackwallet/providers/exchange/available_floating_rate_pairs_state_provider.dart';
|
import 'package:stackwallet/providers/exchange/available_floating_rate_pairs_state_provider.dart';
|
||||||
|
import 'package:stackwallet/providers/exchange/change_now_provider.dart';
|
||||||
import 'package:stackwallet/providers/exchange/changenow_initial_load_status.dart';
|
import 'package:stackwallet/providers/exchange/changenow_initial_load_status.dart';
|
||||||
import 'package:stackwallet/providers/exchange/exchange_form_provider.dart';
|
import 'package:stackwallet/providers/exchange/exchange_form_provider.dart';
|
||||||
import 'package:stackwallet/providers/exchange/fixed_rate_exchange_form_provider.dart';
|
import 'package:stackwallet/providers/exchange/fixed_rate_exchange_form_provider.dart';
|
||||||
import 'package:stackwallet/providers/exchange/fixed_rate_market_pairs_provider.dart';
|
import 'package:stackwallet/providers/exchange/fixed_rate_market_pairs_provider.dart';
|
||||||
import 'package:stackwallet/services/change_now/change_now.dart';
|
|
||||||
import 'package:stackwallet/utilities/cfcolors.dart';
|
import 'package:stackwallet/utilities/cfcolors.dart';
|
||||||
import 'package:stackwallet/utilities/logger.dart';
|
import 'package:stackwallet/utilities/logger.dart';
|
||||||
import 'package:stackwallet/utilities/text_styles.dart';
|
import 'package:stackwallet/utilities/text_styles.dart';
|
||||||
|
@ -38,7 +38,8 @@ class _ExchangeLoadingOverlayViewState
|
||||||
ref.read(changeNowFixedInitialLoadStatusStateProvider.state).state =
|
ref.read(changeNowFixedInitialLoadStatusStateProvider.state).state =
|
||||||
ChangeNowLoadStatus.loading;
|
ChangeNowLoadStatus.loading;
|
||||||
|
|
||||||
final response3 = await ChangeNow.getAvailableFixedRateMarkets();
|
final response3 =
|
||||||
|
await ref.read(changeNowProvider).getAvailableFixedRateMarkets();
|
||||||
if (response3.value != null) {
|
if (response3.value != null) {
|
||||||
ref.read(fixedRateMarketPairsStateProvider.state).state =
|
ref.read(fixedRateMarketPairsStateProvider.state).state =
|
||||||
response3.value!;
|
response3.value!;
|
||||||
|
@ -47,7 +48,7 @@ class _ExchangeLoadingOverlayViewState
|
||||||
final matchingMarkets =
|
final matchingMarkets =
|
||||||
response3.value!.where((e) => e.to == "doge" && e.from == "btc");
|
response3.value!.where((e) => e.to == "doge" && e.from == "btc");
|
||||||
if (matchingMarkets.isNotEmpty) {
|
if (matchingMarkets.isNotEmpty) {
|
||||||
ref
|
await ref
|
||||||
.read(fixedRateExchangeFormProvider)
|
.read(fixedRateExchangeFormProvider)
|
||||||
.updateMarket(matchingMarkets.first, true);
|
.updateMarket(matchingMarkets.first, true);
|
||||||
}
|
}
|
||||||
|
@ -78,8 +79,9 @@ class _ExchangeLoadingOverlayViewState
|
||||||
ref.read(changeNowEstimatedInitialLoadStatusStateProvider.state).state =
|
ref.read(changeNowEstimatedInitialLoadStatusStateProvider.state).state =
|
||||||
ChangeNowLoadStatus.loading;
|
ChangeNowLoadStatus.loading;
|
||||||
|
|
||||||
final response = await ChangeNow.getAvailableCurrencies();
|
final response = await ref.read(changeNowProvider).getAvailableCurrencies();
|
||||||
final response2 = await ChangeNow.getAvailableFloatingRatePairs();
|
final response2 =
|
||||||
|
await ref.read(changeNowProvider).getAvailableFloatingRatePairs();
|
||||||
if (response.value != null) {
|
if (response.value != null) {
|
||||||
ref.read(availableChangeNowCurrenciesStateProvider.state).state =
|
ref.read(availableChangeNowCurrenciesStateProvider.state).state =
|
||||||
response.value!;
|
response.value!;
|
||||||
|
@ -90,13 +92,13 @@ class _ExchangeLoadingOverlayViewState
|
||||||
if (response.value!.length > 1) {
|
if (response.value!.length > 1) {
|
||||||
if (ref.read(estimatedRateExchangeFormProvider).from == null) {
|
if (ref.read(estimatedRateExchangeFormProvider).from == null) {
|
||||||
if (response.value!.where((e) => e.ticker == "btc").isNotEmpty) {
|
if (response.value!.where((e) => e.ticker == "btc").isNotEmpty) {
|
||||||
ref.read(estimatedRateExchangeFormProvider).updateFrom(
|
await ref.read(estimatedRateExchangeFormProvider).updateFrom(
|
||||||
response.value!.firstWhere((e) => e.ticker == "btc"), false);
|
response.value!.firstWhere((e) => e.ticker == "btc"), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ref.read(estimatedRateExchangeFormProvider).to == null) {
|
if (ref.read(estimatedRateExchangeFormProvider).to == null) {
|
||||||
if (response.value!.where((e) => e.ticker == "doge").isNotEmpty) {
|
if (response.value!.where((e) => e.ticker == "doge").isNotEmpty) {
|
||||||
ref.read(estimatedRateExchangeFormProvider).updateTo(
|
await ref.read(estimatedRateExchangeFormProvider).updateTo(
|
||||||
response.value!.firstWhere((e) => e.ticker == "doge"), false);
|
response.value!.firstWhere((e) => e.ticker == "doge"), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
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/change_now_response.dart';
|
||||||
|
@ -6,8 +8,8 @@ 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';
|
||||||
import 'package:stackwallet/pages/exchange_view/sub_widgets/exchange_rate_sheet.dart';
|
import 'package:stackwallet/pages/exchange_view/sub_widgets/exchange_rate_sheet.dart';
|
||||||
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/global/trades_service_provider.dart';
|
import 'package:stackwallet/providers/global/trades_service_provider.dart';
|
||||||
import 'package:stackwallet/services/change_now/change_now.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/cfcolors.dart';
|
import 'package:stackwallet/utilities/cfcolors.dart';
|
||||||
|
@ -219,35 +221,39 @@ class _Step3ViewState extends ConsumerState<Step3View> {
|
||||||
response;
|
response;
|
||||||
if (model.rateType ==
|
if (model.rateType ==
|
||||||
ExchangeRateType.estimated) {
|
ExchangeRateType.estimated) {
|
||||||
response = await ChangeNow
|
response = await ref
|
||||||
|
.read(changeNowProvider)
|
||||||
.createStandardExchangeTransaction(
|
.createStandardExchangeTransaction(
|
||||||
fromTicker: model.sendTicker,
|
fromTicker: model.sendTicker,
|
||||||
toTicker: model.receiveTicker,
|
toTicker: model.receiveTicker,
|
||||||
receivingAddress: model.recipientAddress!,
|
receivingAddress:
|
||||||
amount: model.sendAmount,
|
model.recipientAddress!,
|
||||||
refundAddress: model.refundAddress!,
|
amount: model.sendAmount,
|
||||||
);
|
refundAddress: model.refundAddress!,
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
response = await ChangeNow
|
response = await ref
|
||||||
|
.read(changeNowProvider)
|
||||||
.createFixedRateExchangeTransaction(
|
.createFixedRateExchangeTransaction(
|
||||||
fromTicker: model.sendTicker,
|
fromTicker: model.sendTicker,
|
||||||
toTicker: model.receiveTicker,
|
toTicker: model.receiveTicker,
|
||||||
receivingAddress: model.recipientAddress!,
|
receivingAddress:
|
||||||
amount: model.sendAmount,
|
model.recipientAddress!,
|
||||||
refundAddress: model.refundAddress!,
|
amount: model.sendAmount,
|
||||||
rateId: model.rateId!,
|
refundAddress: model.refundAddress!,
|
||||||
);
|
rateId: model.rateId!,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response.value == null) {
|
if (response.value == null) {
|
||||||
showDialog<void>(
|
unawaited(showDialog<void>(
|
||||||
context: context,
|
context: context,
|
||||||
barrierDismissible: true,
|
barrierDismissible: true,
|
||||||
builder: (_) => StackDialog(
|
builder: (_) => StackDialog(
|
||||||
title: "Failed to create trade",
|
title: "Failed to create trade",
|
||||||
message: response.exception?.toString(),
|
message: response.exception?.toString(),
|
||||||
),
|
),
|
||||||
);
|
));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -257,8 +263,9 @@ class _Step3ViewState extends ConsumerState<Step3View> {
|
||||||
shouldNotifyListeners: true,
|
shouldNotifyListeners: true,
|
||||||
);
|
);
|
||||||
|
|
||||||
final statusResponse =
|
final statusResponse = await ref
|
||||||
await ChangeNow.getTransactionStatus(
|
.read(changeNowProvider)
|
||||||
|
.getTransactionStatus(
|
||||||
id: response.value!.id);
|
id: response.value!.id);
|
||||||
|
|
||||||
debugPrint("WTF: $statusResponse");
|
debugPrint("WTF: $statusResponse");
|
||||||
|
@ -278,7 +285,7 @@ class _Step3ViewState extends ConsumerState<Step3View> {
|
||||||
status += " for deposit";
|
status += " for deposit";
|
||||||
}
|
}
|
||||||
|
|
||||||
NotificationApi.showNotification(
|
unawaited(NotificationApi.showNotification(
|
||||||
changeNowId: model.trade!.id,
|
changeNowId: model.trade!.id,
|
||||||
title: status,
|
title: status,
|
||||||
body: "Trade ID ${model.trade!.id}",
|
body: "Trade ID ${model.trade!.id}",
|
||||||
|
@ -287,13 +294,13 @@ class _Step3ViewState extends ConsumerState<Step3View> {
|
||||||
date: model.trade!.date,
|
date: model.trade!.date,
|
||||||
shouldWatchForUpdates: true,
|
shouldWatchForUpdates: true,
|
||||||
coinName: "coinName",
|
coinName: "coinName",
|
||||||
);
|
));
|
||||||
|
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
Navigator.of(context).pushNamed(
|
unawaited(Navigator.of(context).pushNamed(
|
||||||
Step4View.routeName,
|
Step4View.routeName,
|
||||||
arguments: model,
|
arguments: model,
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
style: Theme.of(context)
|
style: Theme.of(context)
|
||||||
|
|
|
@ -13,10 +13,10 @@ import 'package:stackwallet/pages/exchange_view/send_from_view.dart';
|
||||||
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/pages/home_view/home_view.dart';
|
import 'package:stackwallet/pages/home_view/home_view.dart';
|
||||||
import 'package:stackwallet/pages/send_view/sub_widgets/building_transaction_dialog.dart';
|
import 'package:stackwallet/pages/send_view/sub_widgets/building_transaction_dialog.dart';
|
||||||
|
import 'package:stackwallet/providers/exchange/change_now_provider.dart';
|
||||||
import 'package:stackwallet/providers/exchange/exchange_send_from_wallet_id_provider.dart';
|
import 'package:stackwallet/providers/exchange/exchange_send_from_wallet_id_provider.dart';
|
||||||
import 'package:stackwallet/providers/providers.dart';
|
import 'package:stackwallet/providers/providers.dart';
|
||||||
import 'package:stackwallet/route_generator.dart';
|
import 'package:stackwallet/route_generator.dart';
|
||||||
import 'package:stackwallet/services/change_now/change_now.dart';
|
|
||||||
import 'package:stackwallet/utilities/assets.dart';
|
import 'package:stackwallet/utilities/assets.dart';
|
||||||
import 'package:stackwallet/utilities/cfcolors.dart';
|
import 'package:stackwallet/utilities/cfcolors.dart';
|
||||||
import 'package:stackwallet/utilities/clipboard_interface.dart';
|
import 'package:stackwallet/utilities/clipboard_interface.dart';
|
||||||
|
@ -69,8 +69,9 @@ class _Step4ViewState extends ConsumerState<Step4View> {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _updateStatus() async {
|
Future<void> _updateStatus() async {
|
||||||
final statusResponse =
|
final statusResponse = await ref
|
||||||
await ChangeNow.getTransactionStatus(id: model.trade!.id);
|
.read(changeNowProvider)
|
||||||
|
.getTransactionStatus(id: model.trade!.id);
|
||||||
String status = "Waiting";
|
String status = "Waiting";
|
||||||
if (statusResponse.value != null) {
|
if (statusResponse.value != null) {
|
||||||
_status = statusResponse.value!.status;
|
_status = statusResponse.value!.status;
|
||||||
|
@ -214,11 +215,11 @@ class _Step4ViewState extends ConsumerState<Step4View> {
|
||||||
final data = ClipboardData(
|
final data = ClipboardData(
|
||||||
text: model.sendAmount.toString());
|
text: model.sendAmount.toString());
|
||||||
await clipboard.setData(data);
|
await clipboard.setData(data);
|
||||||
showFloatingFlushBar(
|
unawaited(showFloatingFlushBar(
|
||||||
type: FlushBarType.info,
|
type: FlushBarType.info,
|
||||||
message: "Copied to clipboard",
|
message: "Copied to clipboard",
|
||||||
context: context,
|
context: context,
|
||||||
);
|
));
|
||||||
},
|
},
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
|
@ -271,11 +272,11 @@ class _Step4ViewState extends ConsumerState<Step4View> {
|
||||||
final data = ClipboardData(
|
final data = ClipboardData(
|
||||||
text: model.trade!.payinAddress);
|
text: model.trade!.payinAddress);
|
||||||
await clipboard.setData(data);
|
await clipboard.setData(data);
|
||||||
showFloatingFlushBar(
|
unawaited(showFloatingFlushBar(
|
||||||
type: FlushBarType.info,
|
type: FlushBarType.info,
|
||||||
message: "Copied to clipboard",
|
message: "Copied to clipboard",
|
||||||
context: context,
|
context: context,
|
||||||
);
|
));
|
||||||
},
|
},
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
|
@ -331,11 +332,11 @@ class _Step4ViewState extends ConsumerState<Step4View> {
|
||||||
final data =
|
final data =
|
||||||
ClipboardData(text: model.trade!.id);
|
ClipboardData(text: model.trade!.id);
|
||||||
await clipboard.setData(data);
|
await clipboard.setData(data);
|
||||||
showFloatingFlushBar(
|
unawaited(showFloatingFlushBar(
|
||||||
type: FlushBarType.info,
|
type: FlushBarType.info,
|
||||||
message: "Copied to clipboard",
|
message: "Copied to clipboard",
|
||||||
context: context,
|
context: context,
|
||||||
);
|
));
|
||||||
},
|
},
|
||||||
child: SvgPicture.asset(
|
child: SvgPicture.asset(
|
||||||
Assets.svg.copy,
|
Assets.svg.copy,
|
||||||
|
@ -487,7 +488,7 @@ class _Step4ViewState extends ConsumerState<Step4View> {
|
||||||
try {
|
try {
|
||||||
bool wasCancelled = false;
|
bool wasCancelled = false;
|
||||||
|
|
||||||
showDialog<dynamic>(
|
unawaited(showDialog<dynamic>(
|
||||||
context: context,
|
context: context,
|
||||||
useSafeArea: false,
|
useSafeArea: false,
|
||||||
barrierDismissible: false,
|
barrierDismissible: false,
|
||||||
|
@ -500,7 +501,7 @@ class _Step4ViewState extends ConsumerState<Step4View> {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
));
|
||||||
|
|
||||||
final txData =
|
final txData =
|
||||||
await manager.prepareSend(
|
await manager.prepareSend(
|
||||||
|
@ -524,7 +525,8 @@ class _Step4ViewState extends ConsumerState<Step4View> {
|
||||||
txData["address"] = address;
|
txData["address"] = address;
|
||||||
|
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
Navigator.of(context).push(
|
unawaited(
|
||||||
|
Navigator.of(context).push(
|
||||||
RouteGenerator.getRoute(
|
RouteGenerator.getRoute(
|
||||||
shouldUseMaterialRoute:
|
shouldUseMaterialRoute:
|
||||||
RouteGenerator
|
RouteGenerator
|
||||||
|
@ -543,7 +545,7 @@ class _Step4ViewState extends ConsumerState<Step4View> {
|
||||||
.routeName,
|
.routeName,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -551,7 +553,7 @@ class _Step4ViewState extends ConsumerState<Step4View> {
|
||||||
// pop building dialog
|
// pop building dialog
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
|
|
||||||
showDialog<dynamic>(
|
unawaited(showDialog<dynamic>(
|
||||||
context: context,
|
context: context,
|
||||||
useSafeArea: false,
|
useSafeArea: false,
|
||||||
barrierDismissible: true,
|
barrierDismissible: true,
|
||||||
|
@ -584,7 +586,7 @@ class _Step4ViewState extends ConsumerState<Step4View> {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
));
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:decimal/decimal.dart';
|
import 'package:decimal/decimal.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
@ -16,6 +18,7 @@ import 'package:stackwallet/pages/exchange_view/sub_widgets/exchange_rate_sheet.
|
||||||
import 'package:stackwallet/pages/exchange_view/trade_details_view.dart';
|
import 'package:stackwallet/pages/exchange_view/trade_details_view.dart';
|
||||||
import 'package:stackwallet/providers/exchange/available_currencies_state_provider.dart';
|
import 'package:stackwallet/providers/exchange/available_currencies_state_provider.dart';
|
||||||
import 'package:stackwallet/providers/exchange/available_floating_rate_pairs_state_provider.dart';
|
import 'package:stackwallet/providers/exchange/available_floating_rate_pairs_state_provider.dart';
|
||||||
|
import 'package:stackwallet/providers/exchange/change_now_provider.dart';
|
||||||
import 'package:stackwallet/providers/exchange/changenow_initial_load_status.dart';
|
import 'package:stackwallet/providers/exchange/changenow_initial_load_status.dart';
|
||||||
import 'package:stackwallet/providers/exchange/exchange_form_provider.dart';
|
import 'package:stackwallet/providers/exchange/exchange_form_provider.dart';
|
||||||
import 'package:stackwallet/providers/exchange/exchange_send_from_wallet_id_provider.dart';
|
import 'package:stackwallet/providers/exchange/exchange_send_from_wallet_id_provider.dart';
|
||||||
|
@ -24,7 +27,6 @@ import 'package:stackwallet/providers/exchange/fixed_rate_market_pairs_provider.
|
||||||
import 'package:stackwallet/providers/exchange/trade_sent_from_stack_lookup_provider.dart';
|
import 'package:stackwallet/providers/exchange/trade_sent_from_stack_lookup_provider.dart';
|
||||||
import 'package:stackwallet/providers/global/trades_service_provider.dart';
|
import 'package:stackwallet/providers/global/trades_service_provider.dart';
|
||||||
import 'package:stackwallet/providers/providers.dart';
|
import 'package:stackwallet/providers/providers.dart';
|
||||||
import 'package:stackwallet/services/change_now/change_now.dart';
|
|
||||||
import 'package:stackwallet/utilities/assets.dart';
|
import 'package:stackwallet/utilities/assets.dart';
|
||||||
import 'package:stackwallet/utilities/cfcolors.dart';
|
import 'package:stackwallet/utilities/cfcolors.dart';
|
||||||
import 'package:stackwallet/utilities/constants.dart';
|
import 'package:stackwallet/utilities/constants.dart';
|
||||||
|
@ -407,14 +409,14 @@ class _ExchangeViewState extends ConsumerState<ExchangeView> {
|
||||||
.read(fixedRateExchangeFormProvider)
|
.read(fixedRateExchangeFormProvider)
|
||||||
.updateMarket(market, true);
|
.updateMarket(market, true);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
showDialog<dynamic>(
|
unawaited(showDialog<dynamic>(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (_) => const StackDialog(
|
builder: (_) => const StackDialog(
|
||||||
title: "Fixed rate market error",
|
title: "Fixed rate market error",
|
||||||
message:
|
message:
|
||||||
"Could not find the specified fixed rate trade pair",
|
"Could not find the specified fixed rate trade pair",
|
||||||
),
|
),
|
||||||
);
|
));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -716,14 +718,14 @@ class _ExchangeViewState extends ConsumerState<ExchangeView> {
|
||||||
.read(fixedRateExchangeFormProvider)
|
.read(fixedRateExchangeFormProvider)
|
||||||
.updateMarket(market, true);
|
.updateMarket(market, true);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
showDialog<dynamic>(
|
unawaited(showDialog<dynamic>(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (_) => const StackDialog(
|
builder: (_) => const StackDialog(
|
||||||
title: "Fixed rate market error",
|
title: "Fixed rate market error",
|
||||||
message:
|
message:
|
||||||
"Could not find the specified fixed rate trade pair",
|
"Could not find the specified fixed rate trade pair",
|
||||||
),
|
),
|
||||||
);
|
));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -924,12 +926,12 @@ class _ExchangeViewState extends ConsumerState<ExchangeView> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
showFloatingFlushBar(
|
unawaited(showFloatingFlushBar(
|
||||||
type: FlushBarType.warning,
|
type: FlushBarType.warning,
|
||||||
message:
|
message:
|
||||||
"Estimated rate trade pair \"$fromTicker-$toTicker\" unavailable. Reverting to last estimated rate pair.",
|
"Estimated rate trade pair \"$fromTicker-$toTicker\" unavailable. Reverting to last estimated rate pair.",
|
||||||
context: context,
|
context: context,
|
||||||
);
|
));
|
||||||
break;
|
break;
|
||||||
case ExchangeRateType.fixed:
|
case ExchangeRateType.fixed:
|
||||||
final fromTicker = ref
|
final fromTicker = ref
|
||||||
|
@ -970,12 +972,12 @@ class _ExchangeViewState extends ConsumerState<ExchangeView> {
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
showFloatingFlushBar(
|
unawaited(showFloatingFlushBar(
|
||||||
type: FlushBarType.warning,
|
type: FlushBarType.warning,
|
||||||
message:
|
message:
|
||||||
"Fixed rate trade pair \"$fromTicker-$toTicker\" unavailable. Reverting to last fixed rate pair.",
|
"Fixed rate trade pair \"$fromTicker-$toTicker\" unavailable. Reverting to last fixed rate pair.",
|
||||||
context: context,
|
context: context,
|
||||||
);
|
));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -1047,7 +1049,7 @@ class _ExchangeViewState extends ConsumerState<ExchangeView> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isAvailable) {
|
if (!isAvailable) {
|
||||||
showDialog<dynamic>(
|
unawaited(showDialog<dynamic>(
|
||||||
context: context,
|
context: context,
|
||||||
barrierDismissible: true,
|
barrierDismissible: true,
|
||||||
builder: (_) => StackDialog(
|
builder: (_) => StackDialog(
|
||||||
|
@ -1056,7 +1058,7 @@ class _ExchangeViewState extends ConsumerState<ExchangeView> {
|
||||||
message:
|
message:
|
||||||
"The $fromTicker - $toTicker market is currently disabled for estimated/floating rate trades",
|
"The $fromTicker - $toTicker market is currently disabled for estimated/floating rate trades",
|
||||||
),
|
),
|
||||||
);
|
));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1068,15 +1070,16 @@ class _ExchangeViewState extends ConsumerState<ExchangeView> {
|
||||||
.read(prefsChangeNotifierProvider)
|
.read(prefsChangeNotifierProvider)
|
||||||
.exchangeRateType;
|
.exchangeRateType;
|
||||||
|
|
||||||
final response = await ChangeNow
|
final response = await ref
|
||||||
|
.read(changeNowProvider)
|
||||||
.getEstimatedExchangeAmount(
|
.getEstimatedExchangeAmount(
|
||||||
fromTicker: fromTicker,
|
fromTicker: fromTicker,
|
||||||
toTicker: toTicker,
|
toTicker: toTicker,
|
||||||
fromAmount: sendAmount,
|
fromAmount: sendAmount,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (response.value == null) {
|
if (response.value == null) {
|
||||||
showDialog<dynamic>(
|
unawaited(showDialog<dynamic>(
|
||||||
context: context,
|
context: context,
|
||||||
barrierDismissible: true,
|
barrierDismissible: true,
|
||||||
builder: (_) => StackDialog(
|
builder: (_) => StackDialog(
|
||||||
|
@ -1084,7 +1087,7 @@ class _ExchangeViewState extends ConsumerState<ExchangeView> {
|
||||||
"Failed to update trade estimate",
|
"Failed to update trade estimate",
|
||||||
message: response.exception?.toString(),
|
message: response.exception?.toString(),
|
||||||
),
|
),
|
||||||
);
|
));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1108,10 +1111,10 @@ class _ExchangeViewState extends ConsumerState<ExchangeView> {
|
||||||
exchangeSendFromWalletIdStateProvider
|
exchangeSendFromWalletIdStateProvider
|
||||||
.state)
|
.state)
|
||||||
.state = null;
|
.state = null;
|
||||||
Navigator.of(context).pushNamed(
|
unawaited(Navigator.of(context).pushNamed(
|
||||||
Step1View.routeName,
|
Step1View.routeName,
|
||||||
arguments: model,
|
arguments: model,
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
final fromTicker = ref
|
final fromTicker = ref
|
||||||
|
@ -1133,18 +1136,19 @@ class _ExchangeViewState extends ConsumerState<ExchangeView> {
|
||||||
.read(prefsChangeNotifierProvider)
|
.read(prefsChangeNotifierProvider)
|
||||||
.exchangeRateType;
|
.exchangeRateType;
|
||||||
|
|
||||||
final response = await ChangeNow
|
final response = await ref
|
||||||
|
.read(changeNowProvider)
|
||||||
.getEstimatedFixedRateExchangeAmount(
|
.getEstimatedFixedRateExchangeAmount(
|
||||||
fromTicker: fromTicker,
|
fromTicker: fromTicker,
|
||||||
toTicker: toTicker,
|
toTicker: toTicker,
|
||||||
fromAmount: sendAmount,
|
fromAmount: sendAmount,
|
||||||
useRateId: true,
|
useRateId: true,
|
||||||
);
|
);
|
||||||
|
|
||||||
bool? shouldCancel;
|
bool? shouldCancel;
|
||||||
|
|
||||||
if (response.value == null) {
|
if (response.value == null) {
|
||||||
showDialog<dynamic>(
|
unawaited(showDialog<dynamic>(
|
||||||
context: context,
|
context: context,
|
||||||
barrierDismissible: true,
|
barrierDismissible: true,
|
||||||
builder: (_) => StackDialog(
|
builder: (_) => StackDialog(
|
||||||
|
@ -1152,7 +1156,7 @@ class _ExchangeViewState extends ConsumerState<ExchangeView> {
|
||||||
"Failed to update trade estimate",
|
"Failed to update trade estimate",
|
||||||
message: response.exception?.toString(),
|
message: response.exception?.toString(),
|
||||||
),
|
),
|
||||||
);
|
));
|
||||||
return;
|
return;
|
||||||
} else if (response.value!.warningMessage !=
|
} else if (response.value!.warningMessage !=
|
||||||
null &&
|
null &&
|
||||||
|
@ -1234,10 +1238,10 @@ class _ExchangeViewState extends ConsumerState<ExchangeView> {
|
||||||
exchangeSendFromWalletIdStateProvider
|
exchangeSendFromWalletIdStateProvider
|
||||||
.state)
|
.state)
|
||||||
.state = null;
|
.state = null;
|
||||||
Navigator.of(context).pushNamed(
|
unawaited(Navigator.of(context).pushNamed(
|
||||||
Step1View.routeName,
|
Step1View.routeName,
|
||||||
arguments: model,
|
arguments: model,
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1341,18 +1345,18 @@ class _ExchangeViewState extends ConsumerState<ExchangeView> {
|
||||||
final tx = txData.getAllTransactions()[txid];
|
final tx = txData.getAllTransactions()[txid];
|
||||||
|
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
Navigator.of(context).pushNamed(
|
unawaited(Navigator.of(context).pushNamed(
|
||||||
TradeDetailsView.routeName,
|
TradeDetailsView.routeName,
|
||||||
arguments: Tuple4(tradeId, tx,
|
arguments: Tuple4(tradeId, tx,
|
||||||
walletIds.first, manager.walletName),
|
walletIds.first, manager.walletName),
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Navigator.of(context).pushNamed(
|
unawaited(Navigator.of(context).pushNamed(
|
||||||
TradeDetailsView.routeName,
|
TradeDetailsView.routeName,
|
||||||
arguments: Tuple4(
|
arguments: Tuple4(
|
||||||
tradeId, null, walletIds?.first, null),
|
tradeId, null, walletIds?.first, null),
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
@ -1454,7 +1458,7 @@ class RateInfo extends ConsumerWidget {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
showModalBottomSheet<dynamic>(
|
unawaited(showModalBottomSheet<dynamic>(
|
||||||
backgroundColor: Colors.transparent,
|
backgroundColor: Colors.transparent,
|
||||||
context: context,
|
context: context,
|
||||||
shape: const RoundedRectangleBorder(
|
shape: const RoundedRectangleBorder(
|
||||||
|
@ -1467,7 +1471,7 @@ class RateInfo extends ConsumerWidget {
|
||||||
if (value is ExchangeRateType && value != type) {
|
if (value is ExchangeRateType && value != type) {
|
||||||
onChanged(value);
|
onChanged(value);
|
||||||
}
|
}
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
: null,
|
: null,
|
||||||
style: Theme.of(context).textButtonTheme.style?.copyWith(
|
style: Theme.of(context).textButtonTheme.style?.copyWith(
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:decimal/decimal.dart';
|
import 'package:decimal/decimal.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
@ -16,13 +18,12 @@ 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/available_currencies_state_provider.dart';
|
import 'package:stackwallet/providers/exchange/available_currencies_state_provider.dart';
|
||||||
import 'package:stackwallet/providers/exchange/available_floating_rate_pairs_state_provider.dart';
|
import 'package:stackwallet/providers/exchange/available_floating_rate_pairs_state_provider.dart';
|
||||||
import 'package:stackwallet/providers/exchange/changenow_initial_load_status.dart';
|
import 'package:stackwallet/providers/exchange/change_now_provider.dart';
|
||||||
import 'package:stackwallet/providers/exchange/exchange_form_provider.dart';
|
import 'package:stackwallet/providers/exchange/exchange_form_provider.dart';
|
||||||
import 'package:stackwallet/providers/exchange/exchange_send_from_wallet_id_provider.dart';
|
import 'package:stackwallet/providers/exchange/exchange_send_from_wallet_id_provider.dart';
|
||||||
import 'package:stackwallet/providers/exchange/fixed_rate_exchange_form_provider.dart';
|
import 'package:stackwallet/providers/exchange/fixed_rate_exchange_form_provider.dart';
|
||||||
import 'package:stackwallet/providers/exchange/fixed_rate_market_pairs_provider.dart';
|
import 'package:stackwallet/providers/exchange/fixed_rate_market_pairs_provider.dart';
|
||||||
import 'package:stackwallet/providers/providers.dart';
|
import 'package:stackwallet/providers/providers.dart';
|
||||||
import 'package:stackwallet/services/change_now/change_now.dart';
|
|
||||||
import 'package:stackwallet/utilities/assets.dart';
|
import 'package:stackwallet/utilities/assets.dart';
|
||||||
import 'package:stackwallet/utilities/cfcolors.dart';
|
import 'package:stackwallet/utilities/cfcolors.dart';
|
||||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||||
|
@ -477,14 +478,14 @@ class _WalletInitiatedExchangeViewState
|
||||||
fixedRateExchangeFormProvider)
|
fixedRateExchangeFormProvider)
|
||||||
.updateMarket(market, true);
|
.updateMarket(market, true);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
showDialog<dynamic>(
|
unawaited(showDialog<dynamic>(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (_) => const StackDialog(
|
builder: (_) => const StackDialog(
|
||||||
title: "Fixed rate market error",
|
title: "Fixed rate market error",
|
||||||
message:
|
message:
|
||||||
"Could not find the specified fixed rate trade pair",
|
"Could not find the specified fixed rate trade pair",
|
||||||
),
|
),
|
||||||
);
|
));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -832,14 +833,14 @@ class _WalletInitiatedExchangeViewState
|
||||||
fixedRateExchangeFormProvider)
|
fixedRateExchangeFormProvider)
|
||||||
.updateMarket(market, true);
|
.updateMarket(market, true);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
showDialog<dynamic>(
|
unawaited(showDialog<dynamic>(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (_) => const StackDialog(
|
builder: (_) => const StackDialog(
|
||||||
title: "Fixed rate market error",
|
title: "Fixed rate market error",
|
||||||
message:
|
message:
|
||||||
"Could not find the specified fixed rate trade pair",
|
"Could not find the specified fixed rate trade pair",
|
||||||
),
|
),
|
||||||
);
|
));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -1064,12 +1065,12 @@ class _WalletInitiatedExchangeViewState
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
showFloatingFlushBar(
|
unawaited(showFloatingFlushBar(
|
||||||
type: FlushBarType.warning,
|
type: FlushBarType.warning,
|
||||||
message:
|
message:
|
||||||
"Estimated rate trade pair \"$fromTicker-$toTicker\" unavailable. Reverting to last estimated rate pair.",
|
"Estimated rate trade pair \"$fromTicker-$toTicker\" unavailable. Reverting to last estimated rate pair.",
|
||||||
context: context,
|
context: context,
|
||||||
);
|
));
|
||||||
break;
|
break;
|
||||||
case ExchangeRateType.fixed:
|
case ExchangeRateType.fixed:
|
||||||
final fromTicker = ref
|
final fromTicker = ref
|
||||||
|
@ -1111,12 +1112,12 @@ class _WalletInitiatedExchangeViewState
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
showFloatingFlushBar(
|
unawaited(showFloatingFlushBar(
|
||||||
type: FlushBarType.warning,
|
type: FlushBarType.warning,
|
||||||
message:
|
message:
|
||||||
"Fixed rate trade pair \"$fromTicker-$toTicker\" unavailable. Reverting to last fixed rate pair.",
|
"Fixed rate trade pair \"$fromTicker-$toTicker\" unavailable. Reverting to last fixed rate pair.",
|
||||||
context: context,
|
context: context,
|
||||||
);
|
));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -1196,14 +1197,14 @@ class _WalletInitiatedExchangeViewState
|
||||||
if (availableBalance <
|
if (availableBalance <
|
||||||
sendAmount +
|
sendAmount +
|
||||||
Format.satoshisToAmount(fee)) {
|
Format.satoshisToAmount(fee)) {
|
||||||
showDialog<void>(
|
unawaited(showDialog<void>(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (_) => StackOkDialog(
|
builder: (_) => StackOkDialog(
|
||||||
title: "Insufficient balance",
|
title: "Insufficient balance",
|
||||||
message:
|
message:
|
||||||
"Current ${coin.prettyName} wallet does not have enough ${coin.ticker} for this trade",
|
"Current ${coin.prettyName} wallet does not have enough ${coin.ticker} for this trade",
|
||||||
),
|
),
|
||||||
);
|
));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1237,7 +1238,7 @@ class _WalletInitiatedExchangeViewState
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isAvailable) {
|
if (!isAvailable) {
|
||||||
showDialog<dynamic>(
|
unawaited(showDialog<dynamic>(
|
||||||
context: context,
|
context: context,
|
||||||
barrierDismissible: true,
|
barrierDismissible: true,
|
||||||
builder: (_) => StackDialog(
|
builder: (_) => StackDialog(
|
||||||
|
@ -1246,7 +1247,7 @@ class _WalletInitiatedExchangeViewState
|
||||||
message:
|
message:
|
||||||
"The $fromTicker - $toTicker market is currently disabled for estimated/floating rate trades",
|
"The $fromTicker - $toTicker market is currently disabled for estimated/floating rate trades",
|
||||||
),
|
),
|
||||||
);
|
));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1254,15 +1255,16 @@ class _WalletInitiatedExchangeViewState
|
||||||
.read(prefsChangeNotifierProvider)
|
.read(prefsChangeNotifierProvider)
|
||||||
.exchangeRateType;
|
.exchangeRateType;
|
||||||
|
|
||||||
final response = await ChangeNow
|
final response = await ref
|
||||||
|
.read(changeNowProvider)
|
||||||
.getEstimatedExchangeAmount(
|
.getEstimatedExchangeAmount(
|
||||||
fromTicker: fromTicker,
|
fromTicker: fromTicker,
|
||||||
toTicker: toTicker,
|
toTicker: toTicker,
|
||||||
fromAmount: sendAmount,
|
fromAmount: sendAmount,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (response.value == null) {
|
if (response.value == null) {
|
||||||
showDialog<dynamic>(
|
unawaited(showDialog<dynamic>(
|
||||||
context: context,
|
context: context,
|
||||||
barrierDismissible: true,
|
barrierDismissible: true,
|
||||||
builder: (_) => StackDialog(
|
builder: (_) => StackDialog(
|
||||||
|
@ -1271,7 +1273,7 @@ class _WalletInitiatedExchangeViewState
|
||||||
message:
|
message:
|
||||||
response.exception?.toString(),
|
response.exception?.toString(),
|
||||||
),
|
),
|
||||||
);
|
));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1295,10 +1297,10 @@ class _WalletInitiatedExchangeViewState
|
||||||
exchangeSendFromWalletIdStateProvider
|
exchangeSendFromWalletIdStateProvider
|
||||||
.state)
|
.state)
|
||||||
.state = Tuple2(walletId, coin);
|
.state = Tuple2(walletId, coin);
|
||||||
Navigator.of(context).pushNamed(
|
unawaited(Navigator.of(context).pushNamed(
|
||||||
Step2View.routeName,
|
Step2View.routeName,
|
||||||
arguments: model,
|
arguments: model,
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
final fromTicker = ref
|
final fromTicker = ref
|
||||||
|
@ -1320,18 +1322,19 @@ class _WalletInitiatedExchangeViewState
|
||||||
.read(prefsChangeNotifierProvider)
|
.read(prefsChangeNotifierProvider)
|
||||||
.exchangeRateType;
|
.exchangeRateType;
|
||||||
|
|
||||||
final response = await ChangeNow
|
final response = await ref
|
||||||
|
.read(changeNowProvider)
|
||||||
.getEstimatedFixedRateExchangeAmount(
|
.getEstimatedFixedRateExchangeAmount(
|
||||||
fromTicker: fromTicker,
|
fromTicker: fromTicker,
|
||||||
toTicker: toTicker,
|
toTicker: toTicker,
|
||||||
fromAmount: sendAmount,
|
fromAmount: sendAmount,
|
||||||
useRateId: true,
|
useRateId: true,
|
||||||
);
|
);
|
||||||
|
|
||||||
bool? shouldCancel;
|
bool? shouldCancel;
|
||||||
|
|
||||||
if (response.value == null) {
|
if (response.value == null) {
|
||||||
showDialog<dynamic>(
|
unawaited(showDialog<dynamic>(
|
||||||
context: context,
|
context: context,
|
||||||
barrierDismissible: true,
|
barrierDismissible: true,
|
||||||
builder: (_) => StackDialog(
|
builder: (_) => StackDialog(
|
||||||
|
@ -1340,7 +1343,7 @@ class _WalletInitiatedExchangeViewState
|
||||||
message:
|
message:
|
||||||
response.exception?.toString(),
|
response.exception?.toString(),
|
||||||
),
|
),
|
||||||
);
|
));
|
||||||
return;
|
return;
|
||||||
} else if (response.value!.warningMessage !=
|
} else if (response.value!.warningMessage !=
|
||||||
null &&
|
null &&
|
||||||
|
@ -1422,10 +1425,10 @@ class _WalletInitiatedExchangeViewState
|
||||||
exchangeSendFromWalletIdStateProvider
|
exchangeSendFromWalletIdStateProvider
|
||||||
.state)
|
.state)
|
||||||
.state = Tuple2(walletId, coin);
|
.state = Tuple2(walletId, coin);
|
||||||
Navigator.of(context).pushNamed(
|
unawaited(Navigator.of(context).pushNamed(
|
||||||
Step2View.routeName,
|
Step2View.routeName,
|
||||||
arguments: model,
|
arguments: model,
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,15 @@
|
||||||
|
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/pages/exchange_view/exchange_view.dart';
|
import 'package:stackwallet/pages/exchange_view/exchange_view.dart';
|
||||||
import 'package:stackwallet/providers/exchange/available_currencies_state_provider.dart';
|
import 'package:stackwallet/providers/exchange/available_currencies_state_provider.dart';
|
||||||
import 'package:stackwallet/providers/exchange/available_floating_rate_pairs_state_provider.dart';
|
import 'package:stackwallet/providers/exchange/available_floating_rate_pairs_state_provider.dart';
|
||||||
|
import 'package:stackwallet/providers/exchange/change_now_provider.dart';
|
||||||
import 'package:stackwallet/providers/exchange/exchange_form_provider.dart';
|
import 'package:stackwallet/providers/exchange/exchange_form_provider.dart';
|
||||||
import 'package:stackwallet/providers/exchange/fixed_rate_exchange_form_provider.dart';
|
import 'package:stackwallet/providers/exchange/fixed_rate_exchange_form_provider.dart';
|
||||||
import 'package:stackwallet/providers/exchange/fixed_rate_market_pairs_provider.dart';
|
import 'package:stackwallet/providers/exchange/fixed_rate_market_pairs_provider.dart';
|
||||||
import 'package:stackwallet/providers/providers.dart';
|
import 'package:stackwallet/providers/providers.dart';
|
||||||
import 'package:stackwallet/services/change_now/change_now.dart';
|
|
||||||
import 'package:stackwallet/utilities/cfcolors.dart';
|
import 'package:stackwallet/utilities/cfcolors.dart';
|
||||||
import 'package:stackwallet/utilities/logger.dart';
|
import 'package:stackwallet/utilities/logger.dart';
|
||||||
import 'package:stackwallet/utilities/text_styles.dart';
|
import 'package:stackwallet/utilities/text_styles.dart';
|
||||||
|
@ -41,8 +43,9 @@ class _HomeViewButtonBarState extends ConsumerState<HomeViewButtonBar> {
|
||||||
BuildContext context,
|
BuildContext context,
|
||||||
WidgetRef ref,
|
WidgetRef ref,
|
||||||
) async {
|
) async {
|
||||||
final response = await ChangeNow.getAvailableCurrencies();
|
final response = await ref.read(changeNowProvider).getAvailableCurrencies();
|
||||||
final response2 = await ChangeNow.getAvailableFloatingRatePairs();
|
final response2 =
|
||||||
|
await ref.read(changeNowProvider).getAvailableFloatingRatePairs();
|
||||||
if (response.value != null && response2.value != null) {
|
if (response.value != null && response2.value != null) {
|
||||||
ref.read(availableChangeNowCurrenciesStateProvider.state).state =
|
ref.read(availableChangeNowCurrenciesStateProvider.state).state =
|
||||||
response.value!;
|
response.value!;
|
||||||
|
@ -52,13 +55,13 @@ class _HomeViewButtonBarState extends ConsumerState<HomeViewButtonBar> {
|
||||||
if (response.value!.length > 1) {
|
if (response.value!.length > 1) {
|
||||||
if (ref.read(estimatedRateExchangeFormProvider).from == null) {
|
if (ref.read(estimatedRateExchangeFormProvider).from == null) {
|
||||||
if (response.value!.where((e) => e.ticker == "btc").isNotEmpty) {
|
if (response.value!.where((e) => e.ticker == "btc").isNotEmpty) {
|
||||||
ref.read(estimatedRateExchangeFormProvider).updateFrom(
|
await ref.read(estimatedRateExchangeFormProvider).updateFrom(
|
||||||
response.value!.firstWhere((e) => e.ticker == "btc"), true);
|
response.value!.firstWhere((e) => e.ticker == "btc"), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ref.read(estimatedRateExchangeFormProvider).to == null) {
|
if (ref.read(estimatedRateExchangeFormProvider).to == null) {
|
||||||
if (response.value!.where((e) => e.ticker == "doge").isNotEmpty) {
|
if (response.value!.where((e) => e.ticker == "doge").isNotEmpty) {
|
||||||
ref.read(estimatedRateExchangeFormProvider).updateTo(
|
await ref.read(estimatedRateExchangeFormProvider).updateTo(
|
||||||
response.value!.firstWhere((e) => e.ticker == "doge"), true);
|
response.value!.firstWhere((e) => e.ticker == "doge"), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,15 +73,15 @@ class _HomeViewButtonBarState extends ConsumerState<HomeViewButtonBar> {
|
||||||
Logging.instance.log(
|
Logging.instance.log(
|
||||||
"Failed to load changeNOW floating rate market data: \n${response.exception?.errorMessage}\n${response2.exception?.toString()}",
|
"Failed to load changeNOW floating rate market data: \n${response.exception?.errorMessage}\n${response2.exception?.toString()}",
|
||||||
level: LogLevel.Error);
|
level: LogLevel.Error);
|
||||||
showDialog<dynamic>(
|
unawaited(showDialog<dynamic>(
|
||||||
context: context,
|
context: context,
|
||||||
barrierDismissible: true,
|
barrierDismissible: true,
|
||||||
builder: (_) => StackDialog(
|
builder: (_) => StackDialog(
|
||||||
title: "Failed to fetch available currencies",
|
title: "Failed to fetch available currencies",
|
||||||
message:
|
message:
|
||||||
"${response.exception?.toString()}\n\n${response2.exception?.toString()}",
|
"${response.exception?.toString()}\n\n${response2.exception?.toString()}",
|
||||||
),
|
),
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,7 +89,8 @@ class _HomeViewButtonBarState extends ConsumerState<HomeViewButtonBar> {
|
||||||
BuildContext context,
|
BuildContext context,
|
||||||
WidgetRef ref,
|
WidgetRef ref,
|
||||||
) async {
|
) async {
|
||||||
final response3 = await ChangeNow.getAvailableFixedRateMarkets();
|
final response3 =
|
||||||
|
await ref.read(changeNowProvider).getAvailableFixedRateMarkets();
|
||||||
|
|
||||||
if (response3.value != null) {
|
if (response3.value != null) {
|
||||||
ref.read(fixedRateMarketPairsStateProvider.state).state =
|
ref.read(fixedRateMarketPairsStateProvider.state).state =
|
||||||
|
@ -97,7 +101,7 @@ class _HomeViewButtonBarState extends ConsumerState<HomeViewButtonBar> {
|
||||||
response3.value!.where((e) => e.to == "doge" && e.from == "btc");
|
response3.value!.where((e) => e.to == "doge" && e.from == "btc");
|
||||||
|
|
||||||
if (matchingMarkets.isNotEmpty) {
|
if (matchingMarkets.isNotEmpty) {
|
||||||
ref
|
await ref
|
||||||
.read(fixedRateExchangeFormProvider)
|
.read(fixedRateExchangeFormProvider)
|
||||||
.updateMarket(matchingMarkets.first, true);
|
.updateMarket(matchingMarkets.first, true);
|
||||||
}
|
}
|
||||||
|
@ -108,14 +112,14 @@ class _HomeViewButtonBarState extends ConsumerState<HomeViewButtonBar> {
|
||||||
Logging.instance.log(
|
Logging.instance.log(
|
||||||
"Failed to load changeNOW fixed rate markets: ${response3.exception?.errorMessage}",
|
"Failed to load changeNOW fixed rate markets: ${response3.exception?.errorMessage}",
|
||||||
level: LogLevel.Error);
|
level: LogLevel.Error);
|
||||||
showDialog<dynamic>(
|
unawaited(showDialog<dynamic>(
|
||||||
context: context,
|
context: context,
|
||||||
barrierDismissible: true,
|
barrierDismissible: true,
|
||||||
builder: (_) => StackDialog(
|
builder: (_) => StackDialog(
|
||||||
title: "ChangeNOW API call failed",
|
title: "ChangeNOW API call failed",
|
||||||
message: "${response3.exception?.toString()}",
|
message: "${response3.exception?.toString()}",
|
||||||
),
|
),
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
4
lib/providers/exchange/change_now_provider.dart
Normal file
4
lib/providers/exchange/change_now_provider.dart
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
|
import 'package:stackwallet/services/change_now/change_now.dart';
|
||||||
|
|
||||||
|
final changeNowProvider = Provider<ChangeNow>((ref) => ChangeNow.instance);
|
|
@ -13,20 +13,24 @@ import 'package:stackwallet/models/exchange/change_now/exchange_transaction_stat
|
||||||
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/utilities/logger.dart';
|
import 'package:stackwallet/utilities/logger.dart';
|
||||||
|
|
||||||
abstract class ChangeNow {
|
class ChangeNow {
|
||||||
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";
|
||||||
|
|
||||||
/// set this to override using standard http client. Useful for testing
|
ChangeNow._();
|
||||||
static http.Client? client;
|
static final ChangeNow _instance = ChangeNow._();
|
||||||
|
static ChangeNow get instance => _instance;
|
||||||
|
|
||||||
static Uri _buildUri(String path, Map<String, dynamic>? params) {
|
/// set this to override using standard http client. Useful for testing
|
||||||
|
http.Client? client;
|
||||||
|
|
||||||
|
Uri _buildUri(String path, Map<String, dynamic>? params) {
|
||||||
return Uri.https(authority, apiVersion + path, params);
|
return Uri.https(authority, apiVersion + path, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<dynamic> _makeGetRequest(Uri uri) async {
|
Future<dynamic> _makeGetRequest(Uri uri) async {
|
||||||
final client = ChangeNow.client ?? http.Client();
|
final client = this.client ?? http.Client();
|
||||||
try {
|
try {
|
||||||
final response = await client.get(
|
final response = await client.get(
|
||||||
uri,
|
uri,
|
||||||
|
@ -43,11 +47,11 @@ abstract class ChangeNow {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<dynamic> _makePostRequest(
|
Future<dynamic> _makePostRequest(
|
||||||
Uri uri,
|
Uri uri,
|
||||||
Map<String, String> body,
|
Map<String, String> body,
|
||||||
) async {
|
) async {
|
||||||
final client = ChangeNow.client ?? http.Client();
|
final client = this.client ?? http.Client();
|
||||||
try {
|
try {
|
||||||
final response = await client.post(
|
final response = await client.post(
|
||||||
uri,
|
uri,
|
||||||
|
@ -69,7 +73,7 @@ abstract 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.
|
||||||
static Future<ChangeNowResponse<List<Currency>>> getAvailableCurrencies({
|
Future<ChangeNowResponse<List<Currency>>> getAvailableCurrencies({
|
||||||
bool? fixedRate,
|
bool? fixedRate,
|
||||||
bool? active,
|
bool? active,
|
||||||
}) async {
|
}) async {
|
||||||
|
@ -117,7 +121,7 @@ abstract class ChangeNow {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static ChangeNowResponse<List<Currency>> _parseAvailableCurrenciesJson(
|
ChangeNowResponse<List<Currency>> _parseAvailableCurrenciesJson(
|
||||||
List<dynamic> jsonArray) {
|
List<dynamic> jsonArray) {
|
||||||
try {
|
try {
|
||||||
List<Currency> currencies = [];
|
List<Currency> currencies = [];
|
||||||
|
@ -144,7 +148,7 @@ abstract 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.
|
||||||
static Future<ChangeNowResponse<List<Currency>>> getPairedCurrencies({
|
Future<ChangeNowResponse<List<Currency>>> getPairedCurrencies({
|
||||||
required String ticker,
|
required String ticker,
|
||||||
bool? fixedRate,
|
bool? fixedRate,
|
||||||
}) async {
|
}) async {
|
||||||
|
@ -199,7 +203,7 @@ abstract 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.
|
||||||
static Future<ChangeNowResponse<Decimal>> getMinimalExchangeAmount({
|
Future<ChangeNowResponse<Decimal>> getMinimalExchangeAmount({
|
||||||
required String fromTicker,
|
required String fromTicker,
|
||||||
required String toTicker,
|
required String toTicker,
|
||||||
String? apiKey,
|
String? apiKey,
|
||||||
|
@ -237,7 +241,7 @@ abstract 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]
|
||||||
static Future<ChangeNowResponse<EstimatedExchangeAmount>>
|
Future<ChangeNowResponse<EstimatedExchangeAmount>>
|
||||||
getEstimatedExchangeAmount({
|
getEstimatedExchangeAmount({
|
||||||
required String fromTicker,
|
required String fromTicker,
|
||||||
required String toTicker,
|
required String toTicker,
|
||||||
|
@ -281,7 +285,7 @@ abstract class ChangeNow {
|
||||||
|
|
||||||
/// 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]
|
||||||
static Future<ChangeNowResponse<EstimatedExchangeAmount>>
|
Future<ChangeNowResponse<EstimatedExchangeAmount>>
|
||||||
getEstimatedFixedRateExchangeAmount({
|
getEstimatedFixedRateExchangeAmount({
|
||||||
required String fromTicker,
|
required String fromTicker,
|
||||||
required String toTicker,
|
required String toTicker,
|
||||||
|
@ -336,7 +340,7 @@ abstract 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.
|
||||||
static Future<ChangeNowResponse<List<FixedRateMarket>>>
|
Future<ChangeNowResponse<List<FixedRateMarket>>>
|
||||||
getAvailableFixedRateMarkets({
|
getAvailableFixedRateMarkets({
|
||||||
String? apiKey,
|
String? apiKey,
|
||||||
}) async {
|
}) async {
|
||||||
|
@ -373,7 +377,7 @@ abstract class ChangeNow {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static ChangeNowResponse<List<FixedRateMarket>> _parseFixedRateMarketsJson(
|
ChangeNowResponse<List<FixedRateMarket>> _parseFixedRateMarketsJson(
|
||||||
List<dynamic> jsonArray) {
|
List<dynamic> jsonArray) {
|
||||||
try {
|
try {
|
||||||
List<FixedRateMarket> markets = [];
|
List<FixedRateMarket> markets = [];
|
||||||
|
@ -395,7 +399,7 @@ abstract 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.
|
||||||
static Future<ChangeNowResponse<ExchangeTransaction>>
|
Future<ChangeNowResponse<ExchangeTransaction>>
|
||||||
createStandardExchangeTransaction({
|
createStandardExchangeTransaction({
|
||||||
required String fromTicker,
|
required String fromTicker,
|
||||||
required String toTicker,
|
required String toTicker,
|
||||||
|
@ -457,7 +461,7 @@ abstract 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.
|
||||||
static Future<ChangeNowResponse<ExchangeTransaction>>
|
Future<ChangeNowResponse<ExchangeTransaction>>
|
||||||
createFixedRateExchangeTransaction({
|
createFixedRateExchangeTransaction({
|
||||||
required String fromTicker,
|
required String fromTicker,
|
||||||
required String toTicker,
|
required String toTicker,
|
||||||
|
@ -520,8 +524,7 @@ abstract class ChangeNow {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<ChangeNowResponse<ExchangeTransactionStatus>>
|
Future<ChangeNowResponse<ExchangeTransactionStatus>> getTransactionStatus({
|
||||||
getTransactionStatus({
|
|
||||||
required String id,
|
required String id,
|
||||||
String? apiKey,
|
String? apiKey,
|
||||||
}) async {
|
}) async {
|
||||||
|
@ -556,7 +559,7 @@ abstract class ChangeNow {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<ChangeNowResponse<List<AvailableFloatingRatePair>>>
|
Future<ChangeNowResponse<List<AvailableFloatingRatePair>>>
|
||||||
getAvailableFloatingRatePairs({
|
getAvailableFloatingRatePairs({
|
||||||
bool includePartners = false,
|
bool includePartners = false,
|
||||||
}) async {
|
}) async {
|
||||||
|
@ -593,7 +596,7 @@ abstract class ChangeNow {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static ChangeNowResponse<List<AvailableFloatingRatePair>>
|
ChangeNowResponse<List<AvailableFloatingRatePair>>
|
||||||
_parseAvailableFloatingRatePairsJson(List<dynamic> jsonArray) {
|
_parseAvailableFloatingRatePairsJson(List<dynamic> jsonArray) {
|
||||||
try {
|
try {
|
||||||
List<AvailableFloatingRatePair> pairs = [];
|
List<AvailableFloatingRatePair> pairs = [];
|
||||||
|
|
|
@ -17,6 +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;
|
||||||
|
|
||||||
NotificationsService._();
|
NotificationsService._();
|
||||||
static final NotificationsService _instance = NotificationsService._();
|
static final NotificationsService _instance = NotificationsService._();
|
||||||
|
@ -26,10 +27,12 @@ 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,
|
||||||
}) async {
|
}) async {
|
||||||
this.nodeService = nodeService;
|
this.nodeService = nodeService;
|
||||||
this.tradesService = tradesService;
|
this.tradesService = tradesService;
|
||||||
this.prefs = prefs;
|
this.prefs = prefs;
|
||||||
|
this.changeNow = changeNow;
|
||||||
}
|
}
|
||||||
|
|
||||||
// watched transactions
|
// watched transactions
|
||||||
|
@ -177,7 +180,7 @@ class NotificationsService extends ChangeNotifier {
|
||||||
for (final notification in _watchedChangeNowTradeNotifications) {
|
for (final notification in _watchedChangeNowTradeNotifications) {
|
||||||
final id = notification.changeNowId!;
|
final id = notification.changeNowId!;
|
||||||
|
|
||||||
final result = await ChangeNow.getTransactionStatus(id: id);
|
final result = await changeNow.getTransactionStatus(id: id);
|
||||||
|
|
||||||
ChangeNowTransactionStatus? status = result.value?.status;
|
ChangeNowTransactionStatus? status = result.value?.status;
|
||||||
|
|
||||||
|
|
|
@ -20,15 +20,15 @@ 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.client = client;
|
ChangeNow.instance.client = client;
|
||||||
|
|
||||||
when(client.get(
|
when(client.get(
|
||||||
Uri.parse("https://api.changenow.io/v1/currencies"),
|
Uri.parse("https://api.ChangeNow.instance.io/v1/currencies"),
|
||||||
headers: {'Content-Type': 'application/json'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
)).thenAnswer((realInvocation) async =>
|
)).thenAnswer((realInvocation) async =>
|
||||||
Response(jsonEncode(availableCurrenciesJSON), 200));
|
Response(jsonEncode(availableCurrenciesJSON), 200));
|
||||||
|
|
||||||
final result = await ChangeNow.getAvailableCurrencies();
|
final result = await ChangeNow.instance.getAvailableCurrencies();
|
||||||
|
|
||||||
expect(result.exception, null);
|
expect(result.exception, null);
|
||||||
expect(result.value == null, false);
|
expect(result.value == null, false);
|
||||||
|
@ -37,15 +37,17 @@ void main() {
|
||||||
|
|
||||||
test("getAvailableCurrencies succeeds with active option", () async {
|
test("getAvailableCurrencies succeeds with active option", () async {
|
||||||
final client = MockClient();
|
final client = MockClient();
|
||||||
ChangeNow.client = client;
|
ChangeNow.instance.client = client;
|
||||||
|
|
||||||
when(client.get(
|
when(client.get(
|
||||||
Uri.parse("https://api.changenow.io/v1/currencies?active=true"),
|
Uri.parse(
|
||||||
|
"https://api.ChangeNow.instance.io/v1/currencies?active=true"),
|
||||||
headers: {'Content-Type': 'application/json'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
)).thenAnswer((realInvocation) async =>
|
)).thenAnswer((realInvocation) async =>
|
||||||
Response(jsonEncode(availableCurrenciesJSONActive), 200));
|
Response(jsonEncode(availableCurrenciesJSONActive), 200));
|
||||||
|
|
||||||
final result = await ChangeNow.getAvailableCurrencies(active: true);
|
final result =
|
||||||
|
await ChangeNow.instance.getAvailableCurrencies(active: true);
|
||||||
|
|
||||||
expect(result.exception, null);
|
expect(result.exception, null);
|
||||||
expect(result.value == null, false);
|
expect(result.value == null, false);
|
||||||
|
@ -54,15 +56,17 @@ void main() {
|
||||||
|
|
||||||
test("getAvailableCurrencies succeeds with fixedRate option", () async {
|
test("getAvailableCurrencies succeeds with fixedRate option", () async {
|
||||||
final client = MockClient();
|
final client = MockClient();
|
||||||
ChangeNow.client = client;
|
ChangeNow.instance.client = client;
|
||||||
|
|
||||||
when(client.get(
|
when(client.get(
|
||||||
Uri.parse("https://api.changenow.io/v1/currencies?fixedRate=true"),
|
Uri.parse(
|
||||||
|
"https://api.ChangeNow.instance.io/v1/currencies?fixedRate=true"),
|
||||||
headers: {'Content-Type': 'application/json'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
)).thenAnswer((realInvocation) async =>
|
)).thenAnswer((realInvocation) async =>
|
||||||
Response(jsonEncode(availableCurrenciesJSONFixedRate), 200));
|
Response(jsonEncode(availableCurrenciesJSONFixedRate), 200));
|
||||||
|
|
||||||
final result = await ChangeNow.getAvailableCurrencies(fixedRate: true);
|
final result =
|
||||||
|
await ChangeNow.instance.getAvailableCurrencies(fixedRate: true);
|
||||||
|
|
||||||
expect(result.exception, null);
|
expect(result.exception, null);
|
||||||
expect(result.value == null, false);
|
expect(result.value == null, false);
|
||||||
|
@ -72,17 +76,17 @@ 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.client = client;
|
ChangeNow.instance.client = client;
|
||||||
|
|
||||||
when(client.get(
|
when(client.get(
|
||||||
Uri.parse(
|
Uri.parse(
|
||||||
"https://api.changenow.io/v1/currencies?fixedRate=true&active=true"),
|
"https://api.ChangeNow.instance.io/v1/currencies?fixedRate=true&active=true"),
|
||||||
headers: {'Content-Type': 'application/json'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
)).thenAnswer((realInvocation) async =>
|
)).thenAnswer((realInvocation) async =>
|
||||||
Response(jsonEncode(availableCurrenciesJSONActiveFixedRate), 200));
|
Response(jsonEncode(availableCurrenciesJSONActiveFixedRate), 200));
|
||||||
|
|
||||||
final result =
|
final result = await ChangeNow.instance
|
||||||
await ChangeNow.getAvailableCurrencies(active: true, fixedRate: true);
|
.getAvailableCurrencies(active: true, fixedRate: true);
|
||||||
|
|
||||||
expect(result.exception, null);
|
expect(result.exception, null);
|
||||||
expect(result.value == null, false);
|
expect(result.value == null, false);
|
||||||
|
@ -93,15 +97,15 @@ void main() {
|
||||||
"getAvailableCurrencies fails with ChangeNowExceptionType.serializeResponseError",
|
"getAvailableCurrencies fails with ChangeNowExceptionType.serializeResponseError",
|
||||||
() async {
|
() async {
|
||||||
final client = MockClient();
|
final client = MockClient();
|
||||||
ChangeNow.client = client;
|
ChangeNow.instance.client = client;
|
||||||
|
|
||||||
when(client.get(
|
when(client.get(
|
||||||
Uri.parse("https://api.changenow.io/v1/currencies"),
|
Uri.parse("https://api.ChangeNow.instance.io/v1/currencies"),
|
||||||
headers: {'Content-Type': 'application/json'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
)).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.getAvailableCurrencies();
|
final result = await ChangeNow.instance.getAvailableCurrencies();
|
||||||
|
|
||||||
expect(result.exception!.type,
|
expect(result.exception!.type,
|
||||||
ChangeNowExceptionType.serializeResponseError);
|
ChangeNowExceptionType.serializeResponseError);
|
||||||
|
@ -110,14 +114,14 @@ void main() {
|
||||||
|
|
||||||
test("getAvailableCurrencies fails for any other reason", () async {
|
test("getAvailableCurrencies fails for any other reason", () async {
|
||||||
final client = MockClient();
|
final client = MockClient();
|
||||||
ChangeNow.client = client;
|
ChangeNow.instance.client = client;
|
||||||
|
|
||||||
when(client.get(
|
when(client.get(
|
||||||
Uri.parse("https://api.changenow.io/v1/currencies"),
|
Uri.parse("https://api.ChangeNow.instance.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.getAvailableCurrencies();
|
final result = await ChangeNow.instance.getAvailableCurrencies();
|
||||||
|
|
||||||
expect(result.exception!.type, ChangeNowExceptionType.generic);
|
expect(result.exception!.type, ChangeNowExceptionType.generic);
|
||||||
expect(result.value == null, true);
|
expect(result.value == null, true);
|
||||||
|
@ -127,15 +131,16 @@ 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.client = client;
|
ChangeNow.instance.client = client;
|
||||||
|
|
||||||
when(client.get(
|
when(client.get(
|
||||||
Uri.parse("https://api.changenow.io/v1/currencies-to/XMR"),
|
Uri.parse("https://api.ChangeNow.instance.io/v1/currencies-to/XMR"),
|
||||||
headers: {'Content-Type': 'application/json'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
)).thenAnswer((realInvocation) async =>
|
)).thenAnswer((realInvocation) async =>
|
||||||
Response(jsonEncode(getPairedCurrenciesJSON), 200));
|
Response(jsonEncode(getPairedCurrenciesJSON), 200));
|
||||||
|
|
||||||
final result = await ChangeNow.getPairedCurrencies(ticker: "XMR");
|
final result =
|
||||||
|
await ChangeNow.instance.getPairedCurrencies(ticker: "XMR");
|
||||||
|
|
||||||
expect(result.exception, null);
|
expect(result.exception, null);
|
||||||
expect(result.value == null, false);
|
expect(result.value == null, false);
|
||||||
|
@ -144,17 +149,17 @@ void main() {
|
||||||
|
|
||||||
test("getPairedCurrencies succeeds with fixedRate option", () async {
|
test("getPairedCurrencies succeeds with fixedRate option", () async {
|
||||||
final client = MockClient();
|
final client = MockClient();
|
||||||
ChangeNow.client = client;
|
ChangeNow.instance.client = client;
|
||||||
|
|
||||||
when(client.get(
|
when(client.get(
|
||||||
Uri.parse(
|
Uri.parse(
|
||||||
"https://api.changenow.io/v1/currencies-to/XMR?fixedRate=true"),
|
"https://api.ChangeNow.instance.io/v1/currencies-to/XMR?fixedRate=true"),
|
||||||
headers: {'Content-Type': 'application/json'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
)).thenAnswer((realInvocation) async =>
|
)).thenAnswer((realInvocation) async =>
|
||||||
Response(jsonEncode(getPairedCurrenciesJSONFixedRate), 200));
|
Response(jsonEncode(getPairedCurrenciesJSONFixedRate), 200));
|
||||||
|
|
||||||
final result =
|
final result = await ChangeNow.instance
|
||||||
await ChangeNow.getPairedCurrencies(ticker: "XMR", fixedRate: true);
|
.getPairedCurrencies(ticker: "XMR", fixedRate: true);
|
||||||
|
|
||||||
expect(result.exception, null);
|
expect(result.exception, null);
|
||||||
expect(result.value == null, false);
|
expect(result.value == null, false);
|
||||||
|
@ -165,15 +170,16 @@ void main() {
|
||||||
"getPairedCurrencies fails with ChangeNowExceptionType.serializeResponseError A",
|
"getPairedCurrencies fails with ChangeNowExceptionType.serializeResponseError A",
|
||||||
() async {
|
() async {
|
||||||
final client = MockClient();
|
final client = MockClient();
|
||||||
ChangeNow.client = client;
|
ChangeNow.instance.client = client;
|
||||||
|
|
||||||
when(client.get(
|
when(client.get(
|
||||||
Uri.parse("https://api.changenow.io/v1/currencies-to/XMR"),
|
Uri.parse("https://api.ChangeNow.instance.io/v1/currencies-to/XMR"),
|
||||||
headers: {'Content-Type': 'application/json'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
)).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.getPairedCurrencies(ticker: "XMR");
|
final result =
|
||||||
|
await ChangeNow.instance.getPairedCurrencies(ticker: "XMR");
|
||||||
|
|
||||||
expect(result.exception!.type,
|
expect(result.exception!.type,
|
||||||
ChangeNowExceptionType.serializeResponseError);
|
ChangeNowExceptionType.serializeResponseError);
|
||||||
|
@ -182,15 +188,15 @@ void main() {
|
||||||
|
|
||||||
test("getPairedCurrencies fails for any other reason", () async {
|
test("getPairedCurrencies fails for any other reason", () async {
|
||||||
final client = MockClient();
|
final client = MockClient();
|
||||||
ChangeNow.client = client;
|
ChangeNow.instance.client = client;
|
||||||
|
|
||||||
when(client.get(
|
when(client.get(
|
||||||
Uri.parse("https://api.changenow.io/v1/currencies"),
|
Uri.parse("https://api.ChangeNow.instance.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 =
|
final result = await ChangeNow.instance
|
||||||
await ChangeNow.getPairedCurrencies(ticker: "XMR", fixedRate: true);
|
.getPairedCurrencies(ticker: "XMR", fixedRate: true);
|
||||||
|
|
||||||
expect(result.exception!.type, ChangeNowExceptionType.generic);
|
expect(result.exception!.type, ChangeNowExceptionType.generic);
|
||||||
expect(result.value == null, true);
|
expect(result.value == null, true);
|
||||||
|
@ -200,16 +206,16 @@ void main() {
|
||||||
group("getMinimalExchangeAmount", () {
|
group("getMinimalExchangeAmount", () {
|
||||||
test("getMinimalExchangeAmount succeeds", () async {
|
test("getMinimalExchangeAmount succeeds", () async {
|
||||||
final client = MockClient();
|
final client = MockClient();
|
||||||
ChangeNow.client = client;
|
ChangeNow.instance.client = client;
|
||||||
|
|
||||||
when(client.get(
|
when(client.get(
|
||||||
Uri.parse(
|
Uri.parse(
|
||||||
"https://api.changenow.io/v1/min-amount/xmr_btc?api_key=testAPIKEY"),
|
"https://api.ChangeNow.instance.io/v1/min-amount/xmr_btc?api_key=testAPIKEY"),
|
||||||
headers: {'Content-Type': 'application/json'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
)).thenAnswer(
|
)).thenAnswer(
|
||||||
(realInvocation) async => Response('{"minAmount": 42}', 200));
|
(realInvocation) async => Response('{"minAmount": 42}', 200));
|
||||||
|
|
||||||
final result = await ChangeNow.getMinimalExchangeAmount(
|
final result = await ChangeNow.instance.getMinimalExchangeAmount(
|
||||||
fromTicker: "xmr",
|
fromTicker: "xmr",
|
||||||
toTicker: "btc",
|
toTicker: "btc",
|
||||||
apiKey: "testAPIKEY",
|
apiKey: "testAPIKEY",
|
||||||
|
@ -224,15 +230,15 @@ void main() {
|
||||||
"getMinimalExchangeAmount fails with ChangeNowExceptionType.serializeResponseError",
|
"getMinimalExchangeAmount fails with ChangeNowExceptionType.serializeResponseError",
|
||||||
() async {
|
() async {
|
||||||
final client = MockClient();
|
final client = MockClient();
|
||||||
ChangeNow.client = client;
|
ChangeNow.instance.client = client;
|
||||||
|
|
||||||
when(client.get(
|
when(client.get(
|
||||||
Uri.parse(
|
Uri.parse(
|
||||||
"https://api.changenow.io/v1/min-amount/xmr_btc?api_key=testAPIKEY"),
|
"https://api.ChangeNow.instance.io/v1/min-amount/xmr_btc?api_key=testAPIKEY"),
|
||||||
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.getMinimalExchangeAmount(
|
final result = await ChangeNow.instance.getMinimalExchangeAmount(
|
||||||
fromTicker: "xmr",
|
fromTicker: "xmr",
|
||||||
toTicker: "btc",
|
toTicker: "btc",
|
||||||
apiKey: "testAPIKEY",
|
apiKey: "testAPIKEY",
|
||||||
|
@ -245,15 +251,15 @@ void main() {
|
||||||
|
|
||||||
test("getMinimalExchangeAmount fails for any other reason", () async {
|
test("getMinimalExchangeAmount fails for any other reason", () async {
|
||||||
final client = MockClient();
|
final client = MockClient();
|
||||||
ChangeNow.client = client;
|
ChangeNow.instance.client = client;
|
||||||
|
|
||||||
when(client.get(
|
when(client.get(
|
||||||
Uri.parse(
|
Uri.parse(
|
||||||
"https://api.changenow.io/v1/min-amount/xmr_btc?api_key=testAPIKEY"),
|
"https://api.ChangeNow.instance.io/v1/min-amount/xmr_btc?api_key=testAPIKEY"),
|
||||||
headers: {'Content-Type': 'application/json'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
)).thenAnswer((realInvocation) async => Response('', 400));
|
)).thenAnswer((realInvocation) async => Response('', 400));
|
||||||
|
|
||||||
final result = await ChangeNow.getMinimalExchangeAmount(
|
final result = await ChangeNow.instance.getMinimalExchangeAmount(
|
||||||
fromTicker: "xmr",
|
fromTicker: "xmr",
|
||||||
toTicker: "btc",
|
toTicker: "btc",
|
||||||
apiKey: "testAPIKEY",
|
apiKey: "testAPIKEY",
|
||||||
|
@ -267,17 +273,17 @@ void main() {
|
||||||
group("getEstimatedExchangeAmount", () {
|
group("getEstimatedExchangeAmount", () {
|
||||||
test("getEstimatedExchangeAmount succeeds", () async {
|
test("getEstimatedExchangeAmount succeeds", () async {
|
||||||
final client = MockClient();
|
final client = MockClient();
|
||||||
ChangeNow.client = client;
|
ChangeNow.instance.client = client;
|
||||||
|
|
||||||
when(client.get(
|
when(client.get(
|
||||||
Uri.parse(
|
Uri.parse(
|
||||||
"https://api.changenow.io/v1/exchange-amount/42/xmr_btc?api_key=testAPIKEY"),
|
"https://api.ChangeNow.instance.io/v1/exchange-amount/42/xmr_btc?api_key=testAPIKEY"),
|
||||||
headers: {'Content-Type': 'application/json'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
)).thenAnswer((realInvocation) async => Response(
|
)).thenAnswer((realInvocation) async => Response(
|
||||||
'{"estimatedAmount": 58.4142873, "transactionSpeedForecast": "10-60", "warningMessage": null}',
|
'{"estimatedAmount": 58.4142873, "transactionSpeedForecast": "10-60", "warningMessage": null}',
|
||||||
200));
|
200));
|
||||||
|
|
||||||
final result = await ChangeNow.getEstimatedExchangeAmount(
|
final result = await ChangeNow.instance.getEstimatedExchangeAmount(
|
||||||
fromTicker: "xmr",
|
fromTicker: "xmr",
|
||||||
toTicker: "btc",
|
toTicker: "btc",
|
||||||
fromAmount: Decimal.fromInt(42),
|
fromAmount: Decimal.fromInt(42),
|
||||||
|
@ -293,15 +299,15 @@ void main() {
|
||||||
"getEstimatedExchangeAmount fails with ChangeNowExceptionType.serializeResponseError",
|
"getEstimatedExchangeAmount fails with ChangeNowExceptionType.serializeResponseError",
|
||||||
() async {
|
() async {
|
||||||
final client = MockClient();
|
final client = MockClient();
|
||||||
ChangeNow.client = client;
|
ChangeNow.instance.client = client;
|
||||||
|
|
||||||
when(client.get(
|
when(client.get(
|
||||||
Uri.parse(
|
Uri.parse(
|
||||||
"https://api.changenow.io/v1/exchange-amount/42/xmr_btc?api_key=testAPIKEY"),
|
"https://api.ChangeNow.instance.io/v1/exchange-amount/42/xmr_btc?api_key=testAPIKEY"),
|
||||||
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.getEstimatedExchangeAmount(
|
final result = await ChangeNow.instance.getEstimatedExchangeAmount(
|
||||||
fromTicker: "xmr",
|
fromTicker: "xmr",
|
||||||
toTicker: "btc",
|
toTicker: "btc",
|
||||||
fromAmount: Decimal.fromInt(42),
|
fromAmount: Decimal.fromInt(42),
|
||||||
|
@ -315,15 +321,15 @@ void main() {
|
||||||
|
|
||||||
test("getEstimatedExchangeAmount fails for any other reason", () async {
|
test("getEstimatedExchangeAmount fails for any other reason", () async {
|
||||||
final client = MockClient();
|
final client = MockClient();
|
||||||
ChangeNow.client = client;
|
ChangeNow.instance.client = client;
|
||||||
|
|
||||||
when(client.get(
|
when(client.get(
|
||||||
Uri.parse(
|
Uri.parse(
|
||||||
"https://api.changenow.io/v1/exchange-amount/42/xmr_btc?api_key=testAPIKEY"),
|
"https://api.ChangeNow.instance.io/v1/exchange-amount/42/xmr_btc?api_key=testAPIKEY"),
|
||||||
headers: {'Content-Type': 'application/json'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
)).thenAnswer((realInvocation) async => Response('', 400));
|
)).thenAnswer((realInvocation) async => Response('', 400));
|
||||||
|
|
||||||
final result = await ChangeNow.getEstimatedExchangeAmount(
|
final result = await ChangeNow.instance.getEstimatedExchangeAmount(
|
||||||
fromTicker: "xmr",
|
fromTicker: "xmr",
|
||||||
toTicker: "btc",
|
toTicker: "btc",
|
||||||
fromAmount: Decimal.fromInt(42),
|
fromAmount: Decimal.fromInt(42),
|
||||||
|
@ -338,16 +344,17 @@ void main() {
|
||||||
group("getEstimatedFixedRateExchangeAmount", () {
|
group("getEstimatedFixedRateExchangeAmount", () {
|
||||||
test("getEstimatedFixedRateExchangeAmount succeeds", () async {
|
test("getEstimatedFixedRateExchangeAmount succeeds", () async {
|
||||||
final client = MockClient();
|
final client = MockClient();
|
||||||
ChangeNow.client = client;
|
ChangeNow.instance.client = client;
|
||||||
|
|
||||||
when(client.get(
|
when(client.get(
|
||||||
Uri.parse(
|
Uri.parse(
|
||||||
"https://api.changenow.io/v1/exchange-amount/fixed-rate/10/xmr_btc?api_key=testAPIKEY&useRateId=true"),
|
"https://api.ChangeNow.instance.io/v1/exchange-amount/fixed-rate/10/xmr_btc?api_key=testAPIKEY&useRateId=true"),
|
||||||
headers: {'Content-Type': 'application/json'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
)).thenAnswer((realInvocation) async =>
|
)).thenAnswer((realInvocation) async =>
|
||||||
Response(jsonEncode(estFixedRateExchangeAmountJSON), 200));
|
Response(jsonEncode(estFixedRateExchangeAmountJSON), 200));
|
||||||
|
|
||||||
final result = await ChangeNow.getEstimatedFixedRateExchangeAmount(
|
final result =
|
||||||
|
await ChangeNow.instance.getEstimatedFixedRateExchangeAmount(
|
||||||
fromTicker: "xmr",
|
fromTicker: "xmr",
|
||||||
toTicker: "btc",
|
toTicker: "btc",
|
||||||
fromAmount: Decimal.fromInt(10),
|
fromAmount: Decimal.fromInt(10),
|
||||||
|
@ -364,15 +371,16 @@ void main() {
|
||||||
"getEstimatedFixedRateExchangeAmount fails with ChangeNowExceptionType.serializeResponseError",
|
"getEstimatedFixedRateExchangeAmount fails with ChangeNowExceptionType.serializeResponseError",
|
||||||
() async {
|
() async {
|
||||||
final client = MockClient();
|
final client = MockClient();
|
||||||
ChangeNow.client = client;
|
ChangeNow.instance.client = client;
|
||||||
|
|
||||||
when(client.get(
|
when(client.get(
|
||||||
Uri.parse(
|
Uri.parse(
|
||||||
"https://api.changenow.io/v1/exchange-amount/fixed-rate/10/xmr_btc?api_key=testAPIKEY&useRateId=true"),
|
"https://api.ChangeNow.instance.io/v1/exchange-amount/fixed-rate/10/xmr_btc?api_key=testAPIKEY&useRateId=true"),
|
||||||
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.getEstimatedFixedRateExchangeAmount(
|
final result =
|
||||||
|
await ChangeNow.instance.getEstimatedFixedRateExchangeAmount(
|
||||||
fromTicker: "xmr",
|
fromTicker: "xmr",
|
||||||
toTicker: "btc",
|
toTicker: "btc",
|
||||||
fromAmount: Decimal.fromInt(10),
|
fromAmount: Decimal.fromInt(10),
|
||||||
|
@ -387,15 +395,16 @@ void main() {
|
||||||
test("getEstimatedFixedRateExchangeAmount fails for any other reason",
|
test("getEstimatedFixedRateExchangeAmount fails for any other reason",
|
||||||
() async {
|
() async {
|
||||||
final client = MockClient();
|
final client = MockClient();
|
||||||
ChangeNow.client = client;
|
ChangeNow.instance.client = client;
|
||||||
|
|
||||||
when(client.get(
|
when(client.get(
|
||||||
Uri.parse(
|
Uri.parse(
|
||||||
"https://api.changenow.io/v1/exchange-amount/fixed-rate/10/xmr_btc?api_key=testAPIKEY&useRateId=true"),
|
"https://api.ChangeNow.instance.io/v1/exchange-amount/fixed-rate/10/xmr_btc?api_key=testAPIKEY&useRateId=true"),
|
||||||
headers: {'Content-Type': 'application/json'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
)).thenAnswer((realInvocation) async => Response('', 400));
|
)).thenAnswer((realInvocation) async => Response('', 400));
|
||||||
|
|
||||||
final result = await ChangeNow.getEstimatedFixedRateExchangeAmount(
|
final result =
|
||||||
|
await ChangeNow.instance.getEstimatedFixedRateExchangeAmount(
|
||||||
fromTicker: "xmr",
|
fromTicker: "xmr",
|
||||||
toTicker: "btc",
|
toTicker: "btc",
|
||||||
fromAmount: Decimal.fromInt(10),
|
fromAmount: Decimal.fromInt(10),
|
||||||
|
@ -410,16 +419,16 @@ void main() {
|
||||||
group("getAvailableFixedRateMarkets", () {
|
group("getAvailableFixedRateMarkets", () {
|
||||||
test("getAvailableFixedRateMarkets succeeds", () async {
|
test("getAvailableFixedRateMarkets succeeds", () async {
|
||||||
final client = MockClient();
|
final client = MockClient();
|
||||||
ChangeNow.client = client;
|
ChangeNow.instance.client = client;
|
||||||
|
|
||||||
when(client.get(
|
when(client.get(
|
||||||
Uri.parse(
|
Uri.parse(
|
||||||
"https://api.changenow.io/v1/market-info/fixed-rate/testAPIKEY"),
|
"https://api.ChangeNow.instance.io/v1/market-info/fixed-rate/testAPIKEY"),
|
||||||
headers: {'Content-Type': 'application/json'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
)).thenAnswer((realInvocation) async =>
|
)).thenAnswer((realInvocation) async =>
|
||||||
Response(jsonEncode(fixedRateMarketsJSON), 200));
|
Response(jsonEncode(fixedRateMarketsJSON), 200));
|
||||||
|
|
||||||
final result = await ChangeNow.getAvailableFixedRateMarkets(
|
final result = await ChangeNow.instance.getAvailableFixedRateMarkets(
|
||||||
apiKey: "testAPIKEY",
|
apiKey: "testAPIKEY",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -432,15 +441,15 @@ void main() {
|
||||||
"getAvailableFixedRateMarkets fails with ChangeNowExceptionType.serializeResponseError",
|
"getAvailableFixedRateMarkets fails with ChangeNowExceptionType.serializeResponseError",
|
||||||
() async {
|
() async {
|
||||||
final client = MockClient();
|
final client = MockClient();
|
||||||
ChangeNow.client = client;
|
ChangeNow.instance.client = client;
|
||||||
|
|
||||||
when(client.get(
|
when(client.get(
|
||||||
Uri.parse(
|
Uri.parse(
|
||||||
"https://api.changenow.io/v1/market-info/fixed-rate/testAPIKEY"),
|
"https://api.ChangeNow.instance.io/v1/market-info/fixed-rate/testAPIKEY"),
|
||||||
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.getAvailableFixedRateMarkets(
|
final result = await ChangeNow.instance.getAvailableFixedRateMarkets(
|
||||||
apiKey: "testAPIKEY",
|
apiKey: "testAPIKEY",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -451,15 +460,15 @@ void main() {
|
||||||
|
|
||||||
test("getAvailableFixedRateMarkets fails for any other reason", () async {
|
test("getAvailableFixedRateMarkets fails for any other reason", () async {
|
||||||
final client = MockClient();
|
final client = MockClient();
|
||||||
ChangeNow.client = client;
|
ChangeNow.instance.client = client;
|
||||||
|
|
||||||
when(client.get(
|
when(client.get(
|
||||||
Uri.parse(
|
Uri.parse(
|
||||||
"https://api.changenow.io/v1/market-info/fixed-rate/testAPIKEY"),
|
"https://api.ChangeNow.instance.io/v1/market-info/fixed-rate/testAPIKEY"),
|
||||||
headers: {'Content-Type': 'application/json'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
)).thenAnswer((realInvocation) async => Response('', 400));
|
)).thenAnswer((realInvocation) async => Response('', 400));
|
||||||
|
|
||||||
final result = await ChangeNow.getAvailableFixedRateMarkets(
|
final result = await ChangeNow.instance.getAvailableFixedRateMarkets(
|
||||||
apiKey: "testAPIKEY",
|
apiKey: "testAPIKEY",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -471,10 +480,11 @@ void main() {
|
||||||
group("createStandardExchangeTransaction", () {
|
group("createStandardExchangeTransaction", () {
|
||||||
test("createStandardExchangeTransaction succeeds", () async {
|
test("createStandardExchangeTransaction succeeds", () async {
|
||||||
final client = MockClient();
|
final client = MockClient();
|
||||||
ChangeNow.client = client;
|
ChangeNow.instance.client = client;
|
||||||
|
|
||||||
when(client.post(
|
when(client.post(
|
||||||
Uri.parse("https://api.changenow.io/v1/transactions/testAPIKEY"),
|
Uri.parse(
|
||||||
|
"https://api.ChangeNow.instance.io/v1/transactions/testAPIKEY"),
|
||||||
headers: {'Content-Type': 'application/json'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
body:
|
body:
|
||||||
'{"from":"xmr","to":"btc","address":"bc1qu58svs9983e2vuyqh7gq7ratf8k5qehz5k0cn5","amount":"0.3","flow":"standard","extraId":"","userId":"","contactEmail":"","refundAddress":"888tNkZrPN6JsEgekjMnABU4TBzc2Dt29EPAvkRxbANsAnjyPbb3iQ1YBRk1UXcdRsiKc9dhwMVgN5S9cQUiyoogDavup3H","refundExtraId":""}',
|
'{"from":"xmr","to":"btc","address":"bc1qu58svs9983e2vuyqh7gq7ratf8k5qehz5k0cn5","amount":"0.3","flow":"standard","extraId":"","userId":"","contactEmail":"","refundAddress":"888tNkZrPN6JsEgekjMnABU4TBzc2Dt29EPAvkRxbANsAnjyPbb3iQ1YBRk1UXcdRsiKc9dhwMVgN5S9cQUiyoogDavup3H","refundExtraId":""}',
|
||||||
|
@ -482,7 +492,7 @@ void main() {
|
||||||
)).thenAnswer((realInvocation) async =>
|
)).thenAnswer((realInvocation) async =>
|
||||||
Response(jsonEncode(createStandardTransactionResponse), 200));
|
Response(jsonEncode(createStandardTransactionResponse), 200));
|
||||||
|
|
||||||
final result = await ChangeNow.createStandardExchangeTransaction(
|
final result = await ChangeNow.instance.createStandardExchangeTransaction(
|
||||||
fromTicker: "xmr",
|
fromTicker: "xmr",
|
||||||
toTicker: "btc",
|
toTicker: "btc",
|
||||||
receivingAddress: "bc1qu58svs9983e2vuyqh7gq7ratf8k5qehz5k0cn5",
|
receivingAddress: "bc1qu58svs9983e2vuyqh7gq7ratf8k5qehz5k0cn5",
|
||||||
|
@ -501,17 +511,18 @@ void main() {
|
||||||
"createStandardExchangeTransaction fails with ChangeNowExceptionType.serializeResponseError",
|
"createStandardExchangeTransaction fails with ChangeNowExceptionType.serializeResponseError",
|
||||||
() async {
|
() async {
|
||||||
final client = MockClient();
|
final client = MockClient();
|
||||||
ChangeNow.client = client;
|
ChangeNow.instance.client = client;
|
||||||
|
|
||||||
when(client.post(
|
when(client.post(
|
||||||
Uri.parse("https://api.changenow.io/v1/transactions/testAPIKEY"),
|
Uri.parse(
|
||||||
|
"https://api.ChangeNow.instance.io/v1/transactions/testAPIKEY"),
|
||||||
headers: {'Content-Type': 'application/json'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
body:
|
body:
|
||||||
'{"from":"xmr","to":"btc","address":"bc1qu58svs9983e2vuyqh7gq7ratf8k5qehz5k0cn5","amount":"0.3","flow":"standard","extraId":"","userId":"","contactEmail":"","refundAddress":"888tNkZrPN6JsEgekjMnABU4TBzc2Dt29EPAvkRxbANsAnjyPbb3iQ1YBRk1UXcdRsiKc9dhwMVgN5S9cQUiyoogDavup3H","refundExtraId":""}',
|
'{"from":"xmr","to":"btc","address":"bc1qu58svs9983e2vuyqh7gq7ratf8k5qehz5k0cn5","amount":"0.3","flow":"standard","extraId":"","userId":"","contactEmail":"","refundAddress":"888tNkZrPN6JsEgekjMnABU4TBzc2Dt29EPAvkRxbANsAnjyPbb3iQ1YBRk1UXcdRsiKc9dhwMVgN5S9cQUiyoogDavup3H","refundExtraId":""}',
|
||||||
encoding: null,
|
encoding: null,
|
||||||
)).thenAnswer((realInvocation) async => Response('{"error": 42}', 200));
|
)).thenAnswer((realInvocation) async => Response('{"error": 42}', 200));
|
||||||
|
|
||||||
final result = await ChangeNow.createStandardExchangeTransaction(
|
final result = await ChangeNow.instance.createStandardExchangeTransaction(
|
||||||
fromTicker: "xmr",
|
fromTicker: "xmr",
|
||||||
toTicker: "btc",
|
toTicker: "btc",
|
||||||
receivingAddress: "bc1qu58svs9983e2vuyqh7gq7ratf8k5qehz5k0cn5",
|
receivingAddress: "bc1qu58svs9983e2vuyqh7gq7ratf8k5qehz5k0cn5",
|
||||||
|
@ -529,17 +540,18 @@ void main() {
|
||||||
test("createStandardExchangeTransaction fails for any other reason",
|
test("createStandardExchangeTransaction fails for any other reason",
|
||||||
() async {
|
() async {
|
||||||
final client = MockClient();
|
final client = MockClient();
|
||||||
ChangeNow.client = client;
|
ChangeNow.instance.client = client;
|
||||||
|
|
||||||
when(client.post(
|
when(client.post(
|
||||||
Uri.parse("https://api.changenow.io/v1/transactions/testAPIKEY"),
|
Uri.parse(
|
||||||
|
"https://api.ChangeNow.instance.io/v1/transactions/testAPIKEY"),
|
||||||
headers: {'Content-Type': 'application/json'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
body:
|
body:
|
||||||
'{"from":"xmr","to":"btc","address":"bc1qu58svs9983e2vuyqh7gq7ratf8k5qehz5k0cn5","amount":"0.3","flow":"standard","extraId":"","userId":"","contactEmail":"","refundAddress":"888tNkZrPN6JsEgekjMnABU4TBzc2Dt29EPAvkRxbANsAnjyPbb3iQ1YBRk1UXcdRsiKc9dhwMVgN5S9cQUiyoogDavup3H","refundExtraId":""}',
|
'{"from":"xmr","to":"btc","address":"bc1qu58svs9983e2vuyqh7gq7ratf8k5qehz5k0cn5","amount":"0.3","flow":"standard","extraId":"","userId":"","contactEmail":"","refundAddress":"888tNkZrPN6JsEgekjMnABU4TBzc2Dt29EPAvkRxbANsAnjyPbb3iQ1YBRk1UXcdRsiKc9dhwMVgN5S9cQUiyoogDavup3H","refundExtraId":""}',
|
||||||
encoding: null,
|
encoding: null,
|
||||||
)).thenAnswer((realInvocation) async => Response('', 400));
|
)).thenAnswer((realInvocation) async => Response('', 400));
|
||||||
|
|
||||||
final result = await ChangeNow.createStandardExchangeTransaction(
|
final result = await ChangeNow.instance.createStandardExchangeTransaction(
|
||||||
fromTicker: "xmr",
|
fromTicker: "xmr",
|
||||||
toTicker: "btc",
|
toTicker: "btc",
|
||||||
receivingAddress: "bc1qu58svs9983e2vuyqh7gq7ratf8k5qehz5k0cn5",
|
receivingAddress: "bc1qu58svs9983e2vuyqh7gq7ratf8k5qehz5k0cn5",
|
||||||
|
@ -557,11 +569,11 @@ void main() {
|
||||||
group("createFixedRateExchangeTransaction", () {
|
group("createFixedRateExchangeTransaction", () {
|
||||||
test("createFixedRateExchangeTransaction succeeds", () async {
|
test("createFixedRateExchangeTransaction succeeds", () async {
|
||||||
final client = MockClient();
|
final client = MockClient();
|
||||||
ChangeNow.client = client;
|
ChangeNow.instance.client = client;
|
||||||
|
|
||||||
when(client.post(
|
when(client.post(
|
||||||
Uri.parse(
|
Uri.parse(
|
||||||
"https://api.changenow.io/v1/transactions/fixed-rate/testAPIKEY"),
|
"https://api.ChangeNow.instance.io/v1/transactions/fixed-rate/testAPIKEY"),
|
||||||
headers: {'Content-Type': 'application/json'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
body:
|
body:
|
||||||
'{"from":"btc","to":"eth","address":"0x57f31ad4b64095347F87eDB1675566DAfF5EC886","amount":"0.3","flow":"fixed-rate","extraId":"","userId":"","contactEmail":"","refundAddress":"","refundExtraId":"","rateId":""}',
|
'{"from":"btc","to":"eth","address":"0x57f31ad4b64095347F87eDB1675566DAfF5EC886","amount":"0.3","flow":"fixed-rate","extraId":"","userId":"","contactEmail":"","refundAddress":"","refundExtraId":"","rateId":""}',
|
||||||
|
@ -570,7 +582,8 @@ void main() {
|
||||||
'{"payinAddress": "33eFX2jfeWbXMSmRe9ewUUTrmSVSxZi5cj", "payoutAddress": "0x57f31ad4b64095347F87eDB1675566DAfF5EC886","payoutExtraId": "", "fromCurrency": "btc", "toCurrency": "eth", "refundAddress": "","refundExtraId": "","validUntil": "2019-09-09T14:01:04.921Z","id": "a5c73e2603f40d","amount": 62.9737711}',
|
'{"payinAddress": "33eFX2jfeWbXMSmRe9ewUUTrmSVSxZi5cj", "payoutAddress": "0x57f31ad4b64095347F87eDB1675566DAfF5EC886","payoutExtraId": "", "fromCurrency": "btc", "toCurrency": "eth", "refundAddress": "","refundExtraId": "","validUntil": "2019-09-09T14:01:04.921Z","id": "a5c73e2603f40d","amount": 62.9737711}',
|
||||||
200));
|
200));
|
||||||
|
|
||||||
final result = await ChangeNow.createFixedRateExchangeTransaction(
|
final result =
|
||||||
|
await ChangeNow.instance.createFixedRateExchangeTransaction(
|
||||||
fromTicker: "btc",
|
fromTicker: "btc",
|
||||||
toTicker: "eth",
|
toTicker: "eth",
|
||||||
receivingAddress: "0x57f31ad4b64095347F87eDB1675566DAfF5EC886",
|
receivingAddress: "0x57f31ad4b64095347F87eDB1675566DAfF5EC886",
|
||||||
|
@ -589,11 +602,11 @@ void main() {
|
||||||
"createFixedRateExchangeTransaction fails with ChangeNowExceptionType.serializeResponseError",
|
"createFixedRateExchangeTransaction fails with ChangeNowExceptionType.serializeResponseError",
|
||||||
() async {
|
() async {
|
||||||
final client = MockClient();
|
final client = MockClient();
|
||||||
ChangeNow.client = client;
|
ChangeNow.instance.client = client;
|
||||||
|
|
||||||
when(client.post(
|
when(client.post(
|
||||||
Uri.parse(
|
Uri.parse(
|
||||||
"https://api.changenow.io/v1/transactions/fixed-rate/testAPIKEY"),
|
"https://api.ChangeNow.instance.io/v1/transactions/fixed-rate/testAPIKEY"),
|
||||||
headers: {'Content-Type': 'application/json'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
body:
|
body:
|
||||||
'{"from":"btc","to":"eth","address":"0x57f31ad4b64095347F87eDB1675566DAfF5EC886","amount":"0.3","flow":"fixed-rate","extraId":"","userId":"","contactEmail":"","refundAddress":"","refundExtraId":"","rateId":""}',
|
'{"from":"btc","to":"eth","address":"0x57f31ad4b64095347F87eDB1675566DAfF5EC886","amount":"0.3","flow":"fixed-rate","extraId":"","userId":"","contactEmail":"","refundAddress":"","refundExtraId":"","rateId":""}',
|
||||||
|
@ -601,7 +614,8 @@ void main() {
|
||||||
)).thenAnswer((realInvocation) async =>
|
)).thenAnswer((realInvocation) async =>
|
||||||
Response('{"id": "a5c73e2603f40d","amount": 62.9737711}', 200));
|
Response('{"id": "a5c73e2603f40d","amount": 62.9737711}', 200));
|
||||||
|
|
||||||
final result = await ChangeNow.createFixedRateExchangeTransaction(
|
final result =
|
||||||
|
await ChangeNow.instance.createFixedRateExchangeTransaction(
|
||||||
fromTicker: "btc",
|
fromTicker: "btc",
|
||||||
toTicker: "eth",
|
toTicker: "eth",
|
||||||
receivingAddress: "0x57f31ad4b64095347F87eDB1675566DAfF5EC886",
|
receivingAddress: "0x57f31ad4b64095347F87eDB1675566DAfF5EC886",
|
||||||
|
@ -619,18 +633,19 @@ void main() {
|
||||||
test("createFixedRateExchangeTransaction fails for any other reason",
|
test("createFixedRateExchangeTransaction fails for any other reason",
|
||||||
() async {
|
() async {
|
||||||
final client = MockClient();
|
final client = MockClient();
|
||||||
ChangeNow.client = client;
|
ChangeNow.instance.client = client;
|
||||||
|
|
||||||
when(client.post(
|
when(client.post(
|
||||||
Uri.parse(
|
Uri.parse(
|
||||||
"https://api.changenow.io/v1/transactions/fixed-rate/testAPIKEY"),
|
"https://api.ChangeNow.instance.io/v1/transactions/fixed-rate/testAPIKEY"),
|
||||||
headers: {'Content-Type': 'application/json'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
body:
|
body:
|
||||||
'{"from": "btc","to": "eth","address": "0x57f31ad4b64095347F87eDB1675566DAfF5EC886", "amount": "1.12345","extraId": "", "userId": "","contactEmail": "","refundAddress": "", "refundExtraId": "", "rateId": "" }',
|
'{"from": "btc","to": "eth","address": "0x57f31ad4b64095347F87eDB1675566DAfF5EC886", "amount": "1.12345","extraId": "", "userId": "","contactEmail": "","refundAddress": "", "refundExtraId": "", "rateId": "" }',
|
||||||
encoding: null,
|
encoding: null,
|
||||||
)).thenAnswer((realInvocation) async => Response('', 400));
|
)).thenAnswer((realInvocation) async => Response('', 400));
|
||||||
|
|
||||||
final result = await ChangeNow.createFixedRateExchangeTransaction(
|
final result =
|
||||||
|
await ChangeNow.instance.createFixedRateExchangeTransaction(
|
||||||
fromTicker: "xmr",
|
fromTicker: "xmr",
|
||||||
toTicker: "btc",
|
toTicker: "btc",
|
||||||
receivingAddress: "bc1qu58svs9983e2vuyqh7gq7ratf8k5qehz5k0cn5",
|
receivingAddress: "bc1qu58svs9983e2vuyqh7gq7ratf8k5qehz5k0cn5",
|
||||||
|
@ -649,17 +664,17 @@ void main() {
|
||||||
group("getTransactionStatus", () {
|
group("getTransactionStatus", () {
|
||||||
test("getTransactionStatus succeeds", () async {
|
test("getTransactionStatus succeeds", () async {
|
||||||
final client = MockClient();
|
final client = MockClient();
|
||||||
ChangeNow.client = client;
|
ChangeNow.instance.client = client;
|
||||||
|
|
||||||
when(client.get(
|
when(client.get(
|
||||||
Uri.parse(
|
Uri.parse(
|
||||||
"https://api.changenow.io/v1/transactions/47F87eDB1675566DAfF5EC886/testAPIKEY"),
|
"https://api.ChangeNow.instance.io/v1/transactions/47F87eDB1675566DAfF5EC886/testAPIKEY"),
|
||||||
headers: {'Content-Type': 'application/json'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
)).thenAnswer((realInvocation) async => Response(
|
)).thenAnswer((realInvocation) async => Response(
|
||||||
'{"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.getTransactionStatus(
|
final result = await ChangeNow.instance.getTransactionStatus(
|
||||||
id: "47F87eDB1675566DAfF5EC886",
|
id: "47F87eDB1675566DAfF5EC886",
|
||||||
apiKey: "testAPIKEY",
|
apiKey: "testAPIKEY",
|
||||||
);
|
);
|
||||||
|
@ -673,15 +688,15 @@ void main() {
|
||||||
"getTransactionStatus fails with ChangeNowExceptionType.serializeResponseError",
|
"getTransactionStatus fails with ChangeNowExceptionType.serializeResponseError",
|
||||||
() async {
|
() async {
|
||||||
final client = MockClient();
|
final client = MockClient();
|
||||||
ChangeNow.client = client;
|
ChangeNow.instance.client = client;
|
||||||
|
|
||||||
when(client.get(
|
when(client.get(
|
||||||
Uri.parse(
|
Uri.parse(
|
||||||
"https://api.changenow.io/v1/transactions/47F87eDB1675566DAfF5EC886/testAPIKEY"),
|
"https://api.ChangeNow.instance.io/v1/transactions/47F87eDB1675566DAfF5EC886/testAPIKEY"),
|
||||||
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.getTransactionStatus(
|
final result = await ChangeNow.instance.getTransactionStatus(
|
||||||
id: "47F87eDB1675566DAfF5EC886",
|
id: "47F87eDB1675566DAfF5EC886",
|
||||||
apiKey: "testAPIKEY",
|
apiKey: "testAPIKEY",
|
||||||
);
|
);
|
||||||
|
@ -693,15 +708,15 @@ void main() {
|
||||||
|
|
||||||
test("getTransactionStatus fails for any other reason", () async {
|
test("getTransactionStatus fails for any other reason", () async {
|
||||||
final client = MockClient();
|
final client = MockClient();
|
||||||
ChangeNow.client = client;
|
ChangeNow.instance.client = client;
|
||||||
|
|
||||||
when(client.get(
|
when(client.get(
|
||||||
Uri.parse(
|
Uri.parse(
|
||||||
"https://api.changenow.io/v1/transactions/47F87eDB1675566DAfF5EC886/testAPIKEY"),
|
"https://api.ChangeNow.instance.io/v1/transactions/47F87eDB1675566DAfF5EC886/testAPIKEY"),
|
||||||
headers: {'Content-Type': 'application/json'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
)).thenAnswer((realInvocation) async => Response('', 400));
|
)).thenAnswer((realInvocation) async => Response('', 400));
|
||||||
|
|
||||||
final result = await ChangeNow.getTransactionStatus(
|
final result = await ChangeNow.instance.getTransactionStatus(
|
||||||
id: "47F87eDB1675566DAfF5EC886",
|
id: "47F87eDB1675566DAfF5EC886",
|
||||||
apiKey: "testAPIKEY",
|
apiKey: "testAPIKEY",
|
||||||
);
|
);
|
||||||
|
@ -714,16 +729,16 @@ void main() {
|
||||||
group("getAvailableFloatingRatePairs", () {
|
group("getAvailableFloatingRatePairs", () {
|
||||||
test("getAvailableFloatingRatePairs succeeds", () async {
|
test("getAvailableFloatingRatePairs succeeds", () async {
|
||||||
final client = MockClient();
|
final client = MockClient();
|
||||||
ChangeNow.client = client;
|
ChangeNow.instance.client = client;
|
||||||
|
|
||||||
when(client.get(
|
when(client.get(
|
||||||
Uri.parse(
|
Uri.parse(
|
||||||
"https://api.changenow.io/v1/market-info/available-pairs?includePartners=false"),
|
"https://api.ChangeNow.instance.io/v1/market-info/available-pairs?includePartners=false"),
|
||||||
headers: {'Content-Type': 'application/json'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
)).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.getAvailableFloatingRatePairs();
|
final result = await ChangeNow.instance.getAvailableFloatingRatePairs();
|
||||||
|
|
||||||
expect(result.exception, null);
|
expect(result.exception, null);
|
||||||
expect(result.value == null, false);
|
expect(result.value == null, false);
|
||||||
|
@ -734,15 +749,15 @@ void main() {
|
||||||
"getAvailableFloatingRatePairs fails with ChangeNowExceptionType.serializeResponseError",
|
"getAvailableFloatingRatePairs fails with ChangeNowExceptionType.serializeResponseError",
|
||||||
() async {
|
() async {
|
||||||
final client = MockClient();
|
final client = MockClient();
|
||||||
ChangeNow.client = client;
|
ChangeNow.instance.client = client;
|
||||||
|
|
||||||
when(client.get(
|
when(client.get(
|
||||||
Uri.parse(
|
Uri.parse(
|
||||||
"https://api.changenow.io/v1/market-info/available-pairs?includePartners=false"),
|
"https://api.ChangeNow.instance.io/v1/market-info/available-pairs?includePartners=false"),
|
||||||
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.getAvailableFloatingRatePairs();
|
final result = await ChangeNow.instance.getAvailableFloatingRatePairs();
|
||||||
|
|
||||||
expect(result.exception!.type,
|
expect(result.exception!.type,
|
||||||
ChangeNowExceptionType.serializeResponseError);
|
ChangeNowExceptionType.serializeResponseError);
|
||||||
|
@ -751,15 +766,15 @@ void main() {
|
||||||
|
|
||||||
test("getAvailableFloatingRatePairs fails for any other reason", () async {
|
test("getAvailableFloatingRatePairs fails for any other reason", () async {
|
||||||
final client = MockClient();
|
final client = MockClient();
|
||||||
ChangeNow.client = client;
|
ChangeNow.instance.client = client;
|
||||||
|
|
||||||
when(client.get(
|
when(client.get(
|
||||||
Uri.parse(
|
Uri.parse(
|
||||||
"https://api.changenow.io/v1/market-info/available-pairs?includePartners=false"),
|
"https://api.ChangeNow.instance.io/v1/market-info/available-pairs?includePartners=false"),
|
||||||
headers: {'Content-Type': 'application/json'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
)).thenAnswer((realInvocation) async => Response('', 400));
|
)).thenAnswer((realInvocation) async => Response('', 400));
|
||||||
|
|
||||||
final result = await ChangeNow.getAvailableFloatingRatePairs();
|
final result = await ChangeNow.instance.getAvailableFloatingRatePairs();
|
||||||
|
|
||||||
expect(result.exception!.type, ChangeNowExceptionType.generic);
|
expect(result.exception!.type, ChangeNowExceptionType.generic);
|
||||||
expect(result.value == null, true);
|
expect(result.value == null, true);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// Mocks generated by Mockito 5.2.0 from annotations
|
// Mocks generated by Mockito 5.2.0 from annotations
|
||||||
// in stackwallet/test/services/change_now_test.dart.
|
// in stackwallet/test/services/change_now/change_now_test.dart.
|
||||||
// Do not manually edit this file.
|
// Do not manually edit this file.
|
||||||
|
|
||||||
import 'dart:async' as _i5;
|
import 'dart:async' as _i5;
|
||||||
|
|
Loading…
Reference in a new issue