CAKE-279 | saved orderId in the orders store; added saveOrder() method to the dashboard_view_model.dart

This commit is contained in:
OleksandrSobol 2021-03-17 20:21:26 +02:00
parent e787a764c0
commit d752692c3f
5 changed files with 33 additions and 18 deletions

View file

@ -530,7 +530,7 @@ Future setup(
OrderDetailsPage(getIt.get<OrderDetailsViewModel>(param1: order))); OrderDetailsPage(getIt.get<OrderDetailsViewModel>(param1: order)));
getIt.registerFactoryParam<WebViewPage, String, void>((String url, _) => getIt.registerFactoryParam<WebViewPage, String, void>((String url, _) =>
WebViewPage(url: url)); WebViewPage(ordersStore: getIt.get<OrdersStore>(), url: url));
getIt.registerFactory(() => SupportViewModel()); getIt.registerFactory(() => SupportViewModel());

View file

@ -1,3 +1,4 @@
import 'package:cake_wallet/entities/find_order_by_id.dart';
import 'package:cake_wallet/entities/wallet_type.dart'; import 'package:cake_wallet/entities/wallet_type.dart';
import 'package:cake_wallet/generated/i18n.dart'; import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/routes.dart'; import 'package:cake_wallet/routes.dart';
@ -132,6 +133,12 @@ class DashboardPage extends BasePage {
if (url.isNotEmpty) { if (url.isNotEmpty) {
await Navigator.of(context) await Navigator.of(context)
.pushNamed(Routes.webView, arguments: url); .pushNamed(Routes.webView, arguments: url);
final orderId = walletViewModel.ordersStore.orderId;
if (orderId.isNotEmpty) {
await walletViewModel.saveOrder(orderId);
}
} }
}), }),
], ],

View file

@ -1,24 +1,28 @@
import 'dart:io'; import 'dart:io';
import 'package:cake_wallet/generated/i18n.dart'; import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/src/screens/base_page.dart'; import 'package:cake_wallet/src/screens/base_page.dart';
import 'package:cake_wallet/store/dashboard/orders_store.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart'; import 'package:webview_flutter/webview_flutter.dart';
class WebViewPage extends BasePage { class WebViewPage extends BasePage {
WebViewPage({@required this.url}); WebViewPage({@required this.ordersStore, @required this.url});
final OrdersStore ordersStore;
final String url; final String url;
@override @override
String get title => S.current.buy; String get title => S.current.buy;
@override @override
Widget body(BuildContext context) => WebViewPageBody(url: url); Widget body(BuildContext context) =>
WebViewPageBody(ordersStore: ordersStore,url: url);
} }
class WebViewPageBody extends StatefulWidget { class WebViewPageBody extends StatefulWidget {
WebViewPageBody({this.url}); WebViewPageBody({this.ordersStore, this.url});
final OrdersStore ordersStore;
final String url; final String url;
@override @override
@ -34,6 +38,7 @@ class WebViewPageBodyState extends State<WebViewPageBody> {
void initState() { void initState() {
super.initState(); super.initState();
_webViewkey = GlobalKey(); _webViewkey = GlobalKey();
widget.ordersStore.orderId = '';
if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView(); if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView();
} }
@ -53,7 +58,7 @@ class WebViewPageBodyState extends State<WebViewPageBody> {
currentUrl.contains('completed')) { currentUrl.contains('completed')) {
final urlParts = currentUrl.split('/'); final urlParts = currentUrl.split('/');
orderId = urlParts.last; orderId = urlParts.last;
print(orderId); widget.ordersStore.orderId = orderId;
} }
return NavigationDecision.navigate; return NavigationDecision.navigate;

View file

@ -13,6 +13,8 @@ abstract class OrdersStoreBase with Store {
OrdersStoreBase({this.ordersSource, this.settingsStore}) { OrdersStoreBase({this.ordersSource, this.settingsStore}) {
orders = <OrderListItem>[]; orders = <OrderListItem>[];
orderId = '';
_onOrdersChanged = _onOrdersChanged =
ordersSource.watch().listen((_) async => await updateOrderList()); ordersSource.watch().listen((_) async => await updateOrderList());
@ -29,6 +31,9 @@ abstract class OrdersStoreBase with Store {
@observable @observable
Order order; Order order;
@observable
String orderId;
@action @action
void setOrder(Order order) => this.order = order; void setOrder(Order order) => this.order = order;

View file

@ -330,15 +330,13 @@ abstract class DashboardViewModelBase with Store {
final timestamp = DateTime.now().millisecondsSinceEpoch.toString(); final timestamp = DateTime.now().millisecondsSinceEpoch.toString();
final url = 'https://api.testwyre.com/v3/orders/reserve' + '?timestamp=' + final url = 'https://api.testwyre.com/v3/orders/reserve' + '?timestamp=' +
timestamp; timestamp;
final apiKey = secrets.wyre_api_key; final apiKey = secrets.wyreApiKey;
final secretKey = secrets.wyre_secret_key; final secretKey = secrets.wyreSecretKey;
final accountId = secrets.wyre_account_id; final accountId = secrets.wyreAccountId;
final body = { final body = {
//'destCurrency' : walletTypeToCryptoCurrency(type).title, //'destCurrency' : walletTypeToCryptoCurrency(type).title,
//'dest' : walletTypeToString(type).toLowerCase() + ':' + address, //'dest' : walletTypeToString(type).toLowerCase() + ':' + address,
'referrerAccountId' : accountId, 'referrerAccountId' : accountId,
//'redirectUrl' : 'http://google.com'
//'redirectUrl' : 'cakewallet://wyre-trade-success'
//'lockFields' : ['destCurrency', 'dest'] //'lockFields' : ['destCurrency', 'dest']
}; };
@ -355,16 +353,16 @@ abstract class DashboardViewModelBase with Store {
final responseJSON = json.decode(response.body) as Map<String, dynamic>; final responseJSON = json.decode(response.body) as Map<String, dynamic>;
final urlFromResponse = responseJSON['url'] as String; final urlFromResponse = responseJSON['url'] as String;
return urlFromResponse; return urlFromResponse;
//if (await canLaunch(urlFromResponse)) await launch(urlFromResponse);
/*final orderId = '';
final order = await findOrderById(orderId);
order.receiveAddress = address;
order.walletId = wallet.id;
await ordersSource.add(order);
ordersStore.setOrder(order);*/
} else { } else {
return ''; return '';
} }
} }
Future<void> saveOrder(String orderId) async {
final order = await findOrderById(orderId);
order.receiveAddress = address;
order.walletId = wallet.id;
await ordersSource.add(order);
ordersStore.setOrder(order);
}
} }