From 6245dfe88588336bda16015578a8366267c9780c Mon Sep 17 00:00:00 2001 From: OleksandrSobol Date: Mon, 1 Mar 2021 20:16:28 +0200 Subject: [PATCH] CAKE-284 | added static function defineUrlForCalculatingAmount() to changenow_exchange_provider.dart; fixed FAQ in the support_view_model.dart --- .../changenow_exchange_provider.dart | 77 +++++++++---------- .../settings/settings_view_model.dart | 1 - lib/view_model/support_view_model.dart | 8 +- 3 files changed, 42 insertions(+), 44 deletions(-) diff --git a/lib/exchange/changenow/changenow_exchange_provider.dart b/lib/exchange/changenow/changenow_exchange_provider.dart index 02e6d9f7c..01b6f1b96 100644 --- a/lib/exchange/changenow/changenow_exchange_provider.dart +++ b/lib/exchange/changenow/changenow_exchange_provider.dart @@ -158,30 +158,17 @@ class ChangeNowExchangeProvider extends ExchangeProvider { ? DateTime.parse(expiredAtRaw).toLocal() : null; - if (expiredAt != null) { - return Trade( - id: id, - from: from, - to: to, - provider: description, - inputAddress: inputAddress, - amount: expectedSendAmount, - state: state, - extraId: extraId, - expiredAt: expiredAt, - outputTransaction: outputTransaction); - } else { - return Trade( - id: id, - from: from, - to: to, - provider: description, - inputAddress: inputAddress, - amount: expectedSendAmount, - state: state, - extraId: extraId, - outputTransaction: outputTransaction); - } + return Trade( + id: id, + from: from, + to: to, + provider: description, + inputAddress: inputAddress, + amount: expectedSendAmount, + state: state, + extraId: extraId, + expiredAt: expiredAt, + outputTransaction: outputTransaction); } @override @@ -215,23 +202,7 @@ class ChangeNowExchangeProvider extends ExchangeProvider { return estimatedAmount; } else { - final url = isFixedRateMode - ? apiUri + - _exchangeAmountUriSufix + - _fixedRateUriSufix + - amount.toString() + - '/' + - from.toString() + - '_' + - to.toString() + - '?api_key=' + apiKey - : apiUri + - _exchangeAmountUriSufix + - amount.toString() + - '/' + - from.toString() + - '_' + - to.toString(); + final url = defineUrlForCalculatingAmount(from, to, amount, isFixedRateMode); final response = await get(url); final responseJSON = json.decode(response.body) as Map; final estimatedAmount = responseJSON['estimatedAmount'] as double; @@ -239,4 +210,28 @@ class ChangeNowExchangeProvider extends ExchangeProvider { return estimatedAmount; } } + + static String defineUrlForCalculatingAmount( + CryptoCurrency from, + CryptoCurrency to, + double amount, + bool isFixedRateMode) { + return isFixedRateMode + ? apiUri + + _exchangeAmountUriSufix + + _fixedRateUriSufix + + amount.toString() + + '/' + + from.toString() + + '_' + + to.toString() + + '?api_key=' + apiKey + : apiUri + + _exchangeAmountUriSufix + + amount.toString() + + '/' + + from.toString() + + '_' + + to.toString(); + } } diff --git a/lib/view_model/settings/settings_view_model.dart b/lib/view_model/settings/settings_view_model.dart index 19214006c..c0dcf27bd 100644 --- a/lib/view_model/settings/settings_view_model.dart +++ b/lib/view_model/settings/settings_view_model.dart @@ -20,7 +20,6 @@ import 'package:cake_wallet/entities/node.dart'; import 'package:cake_wallet/entities/monero_transaction_priority.dart'; import 'package:cake_wallet/entities/action_list_display_mode.dart'; import 'package:cake_wallet/view_model/settings/version_list_item.dart'; -import 'package:cake_wallet/view_model/settings/link_list_item.dart'; import 'package:cake_wallet/view_model/settings/picker_list_item.dart'; import 'package:cake_wallet/view_model/settings/regular_list_item.dart'; import 'package:cake_wallet/view_model/settings/settings_list_item.dart'; diff --git a/lib/view_model/support_view_model.dart b/lib/view_model/support_view_model.dart index 4e5633b50..f5661745c 100644 --- a/lib/view_model/support_view_model.dart +++ b/lib/view_model/support_view_model.dart @@ -6,6 +6,7 @@ import 'package:cake_wallet/view_model/settings/settings_list_item.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:mobx/mobx.dart'; +import 'package:url_launcher/url_launcher.dart'; part 'support_view_model.g.dart'; @@ -16,8 +17,9 @@ abstract class SupportViewModelBase with Store { items = [ RegularListItem( title: S.current.faq, - handler: (BuildContext context) => - Navigator.pushNamed(context, Routes.faq), + handler: (BuildContext context) async { + if (await canLaunch(url)) await launch(url); + }, ), LinkListItem( title: 'Email', @@ -40,5 +42,7 @@ abstract class SupportViewModelBase with Store { link: 'mailto:support@changenow.io') ]; } + static const url = 'https://cakewallet.com/guide/'; + List items; } \ No newline at end of file