From fcb1c891f6f845f49661dce5ed5a012de3386ff4 Mon Sep 17 00:00:00 2001 From: M Date: Mon, 7 Jun 2021 17:01:21 +0300 Subject: [PATCH] Changed web client for moonpay. --- lib/src/screens/buy/pre_order_page.dart | 38 ++++++++++++++++--------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/lib/src/screens/buy/pre_order_page.dart b/lib/src/screens/buy/pre_order_page.dart index cf6cca586..54eeebb6f 100644 --- a/lib/src/screens/buy/pre_order_page.dart +++ b/lib/src/screens/buy/pre_order_page.dart @@ -20,6 +20,7 @@ import 'package:cake_wallet/generated/i18n.dart'; import 'package:cake_wallet/src/widgets/base_text_form_field.dart'; import 'package:cake_wallet/src/widgets/trail_button.dart'; import 'package:mobx/mobx.dart'; +import 'package:url_launcher/url_launcher.dart'; class PreOrderPage extends BasePage { PreOrderPage({@required this.buyViewModel}) @@ -221,20 +222,7 @@ class PreOrderPage extends BasePage { EdgeInsets.only(left: 24, right: 24, bottom: 24), bottomSection: Observer(builder: (_) { return LoadingPrimaryButton( - onPressed: buyViewModel.isRunning - ? null - : () async { - buyViewModel.isRunning = true; - final url = - await buyViewModel.fetchUrl(); - if (url.isNotEmpty) { - await Navigator.of(context) - .pushNamed(Routes.buyWebView, - arguments: [url, buyViewModel]); - buyViewModel.reset(); - } - buyViewModel.isRunning = false; - }, + onPressed: () => onPresentProvider(context: context), text: buyViewModel.selectedProvider == null ? S.of(context).buy : S.of(context).buy_with + @@ -275,4 +263,26 @@ class PreOrderPage extends BasePage { ? buyViewModel.isDisabled = false : buyViewModel.isDisabled = true; } + + Future onPresentProvider({BuildContext context}) async { + if (buyViewModel.isRunning) { + return; + } + + buyViewModel.isRunning = true; + final url = await buyViewModel.fetchUrl(); + + if (url.isNotEmpty) { + if (buyViewModel.selectedProvider is MoonPayBuyProvider) { + if (await canLaunch(url)) await launch(url); + } else { + await Navigator.of(context) + .pushNamed(Routes.buyWebView, + arguments: [url, buyViewModel]); + } + } + + buyViewModel.reset(); + buyViewModel.isRunning = false; + } } \ No newline at end of file