mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-09 12:29:31 +00:00
CAKE-279 | saved orderId in the orders store; added saveOrder() method to the dashboard_view_model.dart
This commit is contained in:
parent
e787a764c0
commit
d752692c3f
5 changed files with 33 additions and 18 deletions
|
@ -530,7 +530,7 @@ Future setup(
|
|||
OrderDetailsPage(getIt.get<OrderDetailsViewModel>(param1: order)));
|
||||
|
||||
getIt.registerFactoryParam<WebViewPage, String, void>((String url, _) =>
|
||||
WebViewPage(url: url));
|
||||
WebViewPage(ordersStore: getIt.get<OrdersStore>(), url: url));
|
||||
|
||||
getIt.registerFactory(() => SupportViewModel());
|
||||
|
||||
|
|
|
@ -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/generated/i18n.dart';
|
||||
import 'package:cake_wallet/routes.dart';
|
||||
|
@ -132,6 +133,12 @@ class DashboardPage extends BasePage {
|
|||
if (url.isNotEmpty) {
|
||||
await Navigator.of(context)
|
||||
.pushNamed(Routes.webView, arguments: url);
|
||||
|
||||
final orderId = walletViewModel.ordersStore.orderId;
|
||||
|
||||
if (orderId.isNotEmpty) {
|
||||
await walletViewModel.saveOrder(orderId);
|
||||
}
|
||||
}
|
||||
}),
|
||||
],
|
||||
|
|
|
@ -1,24 +1,28 @@
|
|||
import 'dart:io';
|
||||
import 'package:cake_wallet/generated/i18n.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:webview_flutter/webview_flutter.dart';
|
||||
|
||||
class WebViewPage extends BasePage {
|
||||
WebViewPage({@required this.url});
|
||||
WebViewPage({@required this.ordersStore, @required this.url});
|
||||
|
||||
final OrdersStore ordersStore;
|
||||
final String url;
|
||||
|
||||
@override
|
||||
String get title => S.current.buy;
|
||||
|
||||
@override
|
||||
Widget body(BuildContext context) => WebViewPageBody(url: url);
|
||||
Widget body(BuildContext context) =>
|
||||
WebViewPageBody(ordersStore: ordersStore,url: url);
|
||||
}
|
||||
|
||||
class WebViewPageBody extends StatefulWidget {
|
||||
WebViewPageBody({this.url});
|
||||
WebViewPageBody({this.ordersStore, this.url});
|
||||
|
||||
final OrdersStore ordersStore;
|
||||
final String url;
|
||||
|
||||
@override
|
||||
|
@ -34,6 +38,7 @@ class WebViewPageBodyState extends State<WebViewPageBody> {
|
|||
void initState() {
|
||||
super.initState();
|
||||
_webViewkey = GlobalKey();
|
||||
widget.ordersStore.orderId = '';
|
||||
|
||||
if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView();
|
||||
}
|
||||
|
@ -53,7 +58,7 @@ class WebViewPageBodyState extends State<WebViewPageBody> {
|
|||
currentUrl.contains('completed')) {
|
||||
final urlParts = currentUrl.split('/');
|
||||
orderId = urlParts.last;
|
||||
print(orderId);
|
||||
widget.ordersStore.orderId = orderId;
|
||||
}
|
||||
|
||||
return NavigationDecision.navigate;
|
||||
|
|
|
@ -13,6 +13,8 @@ abstract class OrdersStoreBase with Store {
|
|||
OrdersStoreBase({this.ordersSource, this.settingsStore}) {
|
||||
orders = <OrderListItem>[];
|
||||
|
||||
orderId = '';
|
||||
|
||||
_onOrdersChanged =
|
||||
ordersSource.watch().listen((_) async => await updateOrderList());
|
||||
|
||||
|
@ -29,6 +31,9 @@ abstract class OrdersStoreBase with Store {
|
|||
@observable
|
||||
Order order;
|
||||
|
||||
@observable
|
||||
String orderId;
|
||||
|
||||
@action
|
||||
void setOrder(Order order) => this.order = order;
|
||||
|
||||
|
|
|
@ -330,15 +330,13 @@ abstract class DashboardViewModelBase with Store {
|
|||
final timestamp = DateTime.now().millisecondsSinceEpoch.toString();
|
||||
final url = 'https://api.testwyre.com/v3/orders/reserve' + '?timestamp=' +
|
||||
timestamp;
|
||||
final apiKey = secrets.wyre_api_key;
|
||||
final secretKey = secrets.wyre_secret_key;
|
||||
final accountId = secrets.wyre_account_id;
|
||||
final apiKey = secrets.wyreApiKey;
|
||||
final secretKey = secrets.wyreSecretKey;
|
||||
final accountId = secrets.wyreAccountId;
|
||||
final body = {
|
||||
//'destCurrency' : walletTypeToCryptoCurrency(type).title,
|
||||
//'dest' : walletTypeToString(type).toLowerCase() + ':' + address,
|
||||
'referrerAccountId' : accountId,
|
||||
//'redirectUrl' : 'http://google.com'
|
||||
//'redirectUrl' : 'cakewallet://wyre-trade-success'
|
||||
//'lockFields' : ['destCurrency', 'dest']
|
||||
};
|
||||
|
||||
|
@ -355,16 +353,16 @@ abstract class DashboardViewModelBase with Store {
|
|||
final responseJSON = json.decode(response.body) as Map<String, dynamic>;
|
||||
final urlFromResponse = responseJSON['url'] as String;
|
||||
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 {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue