2021-03-17 10:32:22 +00:00
|
|
|
import 'dart:io';
|
|
|
|
import 'package:cake_wallet/generated/i18n.dart';
|
2021-03-18 18:36:58 +00:00
|
|
|
import 'package:cake_wallet/palette.dart';
|
2021-03-17 10:32:22 +00:00
|
|
|
import 'package:cake_wallet/src/screens/base_page.dart';
|
2021-03-17 18:21:26 +00:00
|
|
|
import 'package:cake_wallet/store/dashboard/orders_store.dart';
|
2021-03-17 10:32:22 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:webview_flutter/webview_flutter.dart';
|
|
|
|
|
2021-03-18 18:36:58 +00:00
|
|
|
class WyrePage extends BasePage {
|
|
|
|
WyrePage({@required this.ordersStore, @required this.url});
|
2021-03-17 10:32:22 +00:00
|
|
|
|
2021-03-17 18:21:26 +00:00
|
|
|
final OrdersStore ordersStore;
|
2021-03-17 10:32:22 +00:00
|
|
|
final String url;
|
|
|
|
|
|
|
|
@override
|
|
|
|
String get title => S.current.buy;
|
|
|
|
|
2021-03-18 18:36:58 +00:00
|
|
|
@override
|
|
|
|
Color get backgroundDarkColor => Colors.white;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Color get titleColor => Palette.darkBlueCraiola;
|
|
|
|
|
2021-03-17 10:32:22 +00:00
|
|
|
@override
|
2021-03-17 18:21:26 +00:00
|
|
|
Widget body(BuildContext context) =>
|
2021-03-18 18:36:58 +00:00
|
|
|
WyrePageBody(ordersStore: ordersStore,url: url);
|
2021-03-17 10:32:22 +00:00
|
|
|
}
|
|
|
|
|
2021-03-18 18:36:58 +00:00
|
|
|
class WyrePageBody extends StatefulWidget {
|
|
|
|
WyrePageBody({this.ordersStore, this.url});
|
2021-03-17 10:32:22 +00:00
|
|
|
|
2021-03-17 18:21:26 +00:00
|
|
|
final OrdersStore ordersStore;
|
2021-03-17 10:32:22 +00:00
|
|
|
final String url;
|
|
|
|
|
|
|
|
@override
|
2021-03-18 18:36:58 +00:00
|
|
|
WyrePageBodyState createState() => WyrePageBodyState();
|
2021-03-17 10:32:22 +00:00
|
|
|
}
|
|
|
|
|
2021-03-18 18:36:58 +00:00
|
|
|
class WyrePageBodyState extends State<WyrePageBody> {
|
2021-03-17 14:14:48 +00:00
|
|
|
String orderId;
|
|
|
|
WebViewController _webViewController;
|
|
|
|
GlobalKey _webViewkey;
|
2021-03-17 10:32:22 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
2021-03-17 14:14:48 +00:00
|
|
|
_webViewkey = GlobalKey();
|
2021-03-17 18:21:26 +00:00
|
|
|
widget.ordersStore.orderId = '';
|
2021-03-17 14:14:48 +00:00
|
|
|
|
2021-03-17 10:32:22 +00:00
|
|
|
if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return WebView(
|
2021-03-17 14:14:48 +00:00
|
|
|
key: _webViewkey,
|
|
|
|
initialUrl: widget.url,
|
|
|
|
javascriptMode: JavascriptMode.unrestricted,
|
|
|
|
onWebViewCreated: (WebViewController controller) =>
|
|
|
|
setState(() => _webViewController = controller),
|
|
|
|
navigationDelegate: (req) async {
|
|
|
|
final currentUrl = await _webViewController?.currentUrl() ?? '';
|
|
|
|
|
|
|
|
if (currentUrl.contains('processing') ||
|
|
|
|
currentUrl.contains('completed')) {
|
|
|
|
final urlParts = currentUrl.split('/');
|
|
|
|
orderId = urlParts.last;
|
2021-03-17 18:21:26 +00:00
|
|
|
widget.ordersStore.orderId = orderId;
|
2021-03-17 14:14:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NavigationDecision.navigate;
|
|
|
|
});
|
2021-03-17 10:32:22 +00:00
|
|
|
}
|
2021-03-17 14:14:48 +00:00
|
|
|
}
|