CAKE-284 | added static function defineUrlForCalculatingAmount() to changenow_exchange_provider.dart; fixed FAQ in the support_view_model.dart
OleksandrSobol committed
Mar 1, 2021 at 20:16 UTC
6245dfe88588336bda16015578a8366267c9780c
3 files changed
+42
-44
lib/exchange/changenow/changenow_exchange_provider.dart
+36
-41
@@ -158,30 +158,17 @@ class ChangeNowExchangeProvider extends ExchangeProvider {
158
? DateTime.parse(expiredAtRaw).toLocal()
159
: null;
160
161
- if (expiredAt != null) {
162
- return Trade(
163
- id: id,
164
- from: from,
165
- to: to,
166
- provider: description,
167
- inputAddress: inputAddress,
168
- amount: expectedSendAmount,
169
- state: state,
170
- extraId: extraId,
171
- expiredAt: expiredAt,
172
- outputTransaction: outputTransaction);
173
- } else {
174
- return Trade(
175
- id: id,
176
- from: from,
177
- to: to,
178
- provider: description,
179
- inputAddress: inputAddress,
180
- amount: expectedSendAmount,
181
- state: state,
182
- extraId: extraId,
183
- outputTransaction: outputTransaction);
184
- }
161
+ return Trade(
162
+ id: id,
163
+ from: from,
164
+ to: to,
165
+ provider: description,
166
+ inputAddress: inputAddress,
167
+ amount: expectedSendAmount,
168
+ state: state,
169
+ extraId: extraId,
170
+ expiredAt: expiredAt,
171
+ outputTransaction: outputTransaction);
172
}
173
174
@override
@@ -215,23 +202,7 @@ class ChangeNowExchangeProvider extends ExchangeProvider {
202
203
return estimatedAmount;
204
} else {
218
- final url = isFixedRateMode
219
- ? apiUri +
220
- _exchangeAmountUriSufix +
221
- _fixedRateUriSufix +
222
- amount.toString() +
223
- '/' +
224
- from.toString() +
225
- '_' +
226
- to.toString() +
227
- '?api_key=' + apiKey
228
- : apiUri +
229
- _exchangeAmountUriSufix +
230
- amount.toString() +
231
- '/' +
232
- from.toString() +
233
- '_' +
234
- to.toString();
205
+ final url = defineUrlForCalculatingAmount(from, to, amount, isFixedRateMode);
206
final response = await get(url);
207
final responseJSON = json.decode(response.body) as Map<String, dynamic>;
208
final estimatedAmount = responseJSON['estimatedAmount'] as double;
@@ -239,4 +210,28 @@ class ChangeNowExchangeProvider extends ExchangeProvider {
210
return estimatedAmount;
211
}
212
}
213
+
214
+ static String defineUrlForCalculatingAmount(
215
+ CryptoCurrency from,
216
+ CryptoCurrency to,
217
+ double amount,
218
+ bool isFixedRateMode) {
219
+ return isFixedRateMode
220
+ ? apiUri +
221
+ _exchangeAmountUriSufix +
222
+ _fixedRateUriSufix +
223
+ amount.toString() +
224
+ '/' +
225
+ from.toString() +
226
+ '_' +
227
+ to.toString() +
228
+ '?api_key=' + apiKey
229
+ : apiUri +
230
+ _exchangeAmountUriSufix +
231
+ amount.toString() +
232
+ '/' +
233
+ from.toString() +
234
+ '_' +
235
+ to.toString();
236
+ }
237
}
lib/view_model/settings/settings_view_model.dart
-1
@@ -20,7 +20,6 @@ import 'package:cake_wallet/entities/node.dart';
20
import 'package:cake_wallet/entities/monero_transaction_priority.dart';
21
import 'package:cake_wallet/entities/action_list_display_mode.dart';
22
import 'package:cake_wallet/view_model/settings/version_list_item.dart';
23
-import 'package:cake_wallet/view_model/settings/link_list_item.dart';
23
import 'package:cake_wallet/view_model/settings/picker_list_item.dart';
24
import 'package:cake_wallet/view_model/settings/regular_list_item.dart';
25
import 'package:cake_wallet/view_model/settings/settings_list_item.dart';
lib/view_model/support_view_model.dart
+6
-2
@@ -6,6 +6,7 @@ import 'package:cake_wallet/view_model/settings/settings_list_item.dart';
6
import 'package:flutter/cupertino.dart';
7
import 'package:flutter/material.dart';
8
import 'package:mobx/mobx.dart';
9
+import 'package:url_launcher/url_launcher.dart';
10
11
part 'support_view_model.g.dart';
12
@@ -16,8 +17,9 @@ abstract class SupportViewModelBase with Store {
17
items = [
18
RegularListItem(
19
title: S.current.faq,
19
- handler: (BuildContext context) =>
20
- Navigator.pushNamed(context, Routes.faq),
20
+ handler: (BuildContext context) async {
21
+ if (await canLaunch(url)) await launch(url);
22
+ },
23
),
24
LinkListItem(
25
title: 'Email',
@@ -40,5 +42,7 @@ abstract class SupportViewModelBase with Store {
42
link: 'mailto:support@changenow.io')
43
];
44
}
45
+ static const url = 'https://cakewallet.com/guide/';
46
+
47
List<SettingsListItem> items;
48
}
\ No newline at end of file