Fixes for wyre.

This commit is contained in:
M 2021-03-24 11:50:51 +02:00
parent a9566b2748
commit c1b52ebede
2 changed files with 28 additions and 16 deletions

View file

@ -68,7 +68,7 @@ class WyreService {
}
Future<Order> findOrderById(String id) async {
final orderUrl = baseApiUrl + _ordersSuffix + id;
final orderUrl = baseApiUrl + _ordersSuffix + '/$id';
final orderResponse = await get(orderUrl);
if (orderResponse.statusCode != 200) {

View file

@ -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<WyrePageBody> {
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);
}
});
}