From de2074e6ebeac18b2a6208190e11ce60a82472ad Mon Sep 17 00:00:00 2001 From: M Date: Tue, 23 Mar 2021 20:09:35 +0200 Subject: [PATCH] Changed way to get order id. --- lib/src/screens/wyre/wyre_page.dart | 38 ++++++++++++++++------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/lib/src/screens/wyre/wyre_page.dart b/lib/src/screens/wyre/wyre_page.dart index e30d2a209..c95ba601f 100644 --- a/lib/src/screens/wyre/wyre_page.dart +++ b/lib/src/screens/wyre/wyre_page.dart @@ -1,3 +1,4 @@ +import 'dart:async'; import 'dart:io'; import 'package:cake_wallet/generated/i18n.dart'; import 'package:cake_wallet/palette.dart'; @@ -43,6 +44,7 @@ class WyrePageBodyState extends State { String orderId; WebViewController _webViewController; GlobalKey _webViewkey; + Timer _timer; @override void initState() { @@ -51,6 +53,24 @@ class WyrePageBodyState extends State { widget.ordersStore.orderId = ''; if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView(); + + _timer = Timer.periodic(Duration(milliseconds: 200), (_) async { + if (_webViewController == null) { + return; + } + + final url = await _webViewController.currentUrl(); + + if (url.contains('completed')) { + final urlParts = url.split('/'); + orderId = urlParts.last; + widget.ordersStore.orderId = orderId; + + if (orderId.isNotEmpty) { + await widget.wyreViewModel.saveOrder(orderId); + } + } + }); } @override @@ -60,22 +80,6 @@ class WyrePageBodyState extends State { 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; - widget.ordersStore.orderId = orderId; - - if (orderId.isNotEmpty) { - await widget.wyreViewModel.saveOrder(orderId); - } - } - - return NavigationDecision.navigate; - }); + setState(() => _webViewController = controller)); } }