diff --git a/lib/entities/wyre_service.dart b/lib/entities/wyre_service.dart index 1007e5a71..c3cef07c8 100644 --- a/lib/entities/wyre_service.dart +++ b/lib/entities/wyre_service.dart @@ -68,7 +68,7 @@ class WyreService { } Future findOrderById(String id) async { - final orderUrl = baseApiUrl + _ordersSuffix + id; + final orderUrl = baseApiUrl + _ordersSuffix + '/$id'; final orderResponse = await get(orderUrl); if (orderResponse.statusCode != 200) { diff --git a/lib/src/screens/wyre/wyre_page.dart b/lib/src/screens/wyre/wyre_page.dart index c95ba601f..1ba49da64 100644 --- a/lib/src/screens/wyre/wyre_page.dart +++ b/lib/src/screens/wyre/wyre_page.dart @@ -9,7 +9,8 @@ import 'package:flutter/material.dart'; import 'package:webview_flutter/webview_flutter.dart'; class WyrePage extends BasePage { - WyrePage(this.wyreViewModel, {@required this.ordersStore, @required this.url}); + WyrePage(this.wyreViewModel, + {@required this.ordersStore, @required this.url}); final OrdersStore ordersStore; final String url; @@ -26,7 +27,7 @@ class WyrePage extends BasePage { @override Widget body(BuildContext context) => - WyrePageBody(wyreViewModel, ordersStore: ordersStore,url: url); + WyrePageBody(wyreViewModel, ordersStore: ordersStore, url: url); } class WyrePageBody extends StatefulWidget { @@ -45,30 +46,41 @@ class WyrePageBodyState extends State { WebViewController _webViewController; GlobalKey _webViewkey; Timer _timer; + bool _isSaving; @override void initState() { super.initState(); _webViewkey = GlobalKey(); + _isSaving = false; widget.ordersStore.orderId = ''; if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView(); - _timer = Timer.periodic(Duration(milliseconds: 200), (_) async { - if (_webViewController == null) { - return; - } + _timer?.cancel(); + _timer = Timer.periodic(Duration(seconds: 1), (timer) async { - 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); + try { + if (_webViewController == null || _isSaving) { + return; } + + final url = await _webViewController.currentUrl(); + + if (url.contains('completed')) { + final urlParts = url.split('/'); + orderId = urlParts.last; + widget.ordersStore.orderId = orderId; + + if (orderId.isNotEmpty) { + _isSaving = true; + await widget.wyreViewModel.saveOrder(orderId); + timer.cancel(); + } + } + } catch (e) { + _isSaving = false; + print(e); } }); }