From cba3fc65cead91b409aa40553270615477ad5b4c Mon Sep 17 00:00:00 2001 From: fosse Date: Mon, 13 Nov 2023 11:22:19 -0500 Subject: [PATCH] moonpay fixes, swap moonpay and normal exchange --- lib/src/screens/buy/webview_page.dart | 39 ++++++++++++++++++- .../exchange/exchange_options_page.dart | 20 +++++----- 2 files changed, 47 insertions(+), 12 deletions(-) diff --git a/lib/src/screens/buy/webview_page.dart b/lib/src/screens/buy/webview_page.dart index 205b87c47..6a8acc998 100644 --- a/lib/src/screens/buy/webview_page.dart +++ b/lib/src/screens/buy/webview_page.dart @@ -1,8 +1,12 @@ -import 'package:cake_wallet/buy/onramper/onramper_buy_provider.dart'; +import 'package:cake_wallet/di.dart'; import 'package:cake_wallet/generated/i18n.dart'; +import 'package:cake_wallet/routes.dart'; import 'package:cake_wallet/src/screens/base_page.dart'; +import 'package:cake_wallet/store/app_store.dart'; +import 'package:cw_core/wallet_type.dart'; import 'package:flutter/material.dart'; import 'package:flutter_inappwebview/flutter_inappwebview.dart'; +import 'package:fluttertoast/fluttertoast.dart'; import 'package:permission_handler/permission_handler.dart'; class WebViewPage extends BasePage { @@ -36,9 +40,40 @@ class WebViewPageBodyState extends State { Widget build(BuildContext context) { return InAppWebView( initialOptions: InAppWebViewGroupOptions( - crossPlatform: InAppWebViewOptions(transparentBackground: true), + crossPlatform: InAppWebViewOptions( + transparentBackground: true, + javaScriptEnabled: true, + cacheEnabled: true, + resourceCustomSchemes: ["cakewallet"], + useShouldOverrideUrlLoading: true, + ), ), initialUrlRequest: URLRequest(url: widget.uri), + onLoadResource: (controller, resource) async {}, + shouldOverrideUrlLoading: (controller, navigationAction) async { + return NavigationActionPolicy.ALLOW; + }, + onLoadResourceCustomScheme: (controller, uri) async { + final url = await controller.getUrl(); + if (url.toString().startsWith("cakewallet://wc")) { + if (getIt.get().wallet!.type != WalletType.ethereum) { + Fluttertoast.showToast( + msg: S.current.switchToETHWallet, + toastLength: Toast.LENGTH_LONG, + gravity: ToastGravity.SNACKBAR, + backgroundColor: Colors.black, + textColor: Colors.white, + fontSize: 16.0, + ); + return; + } + // required because fully loading the custom url scheme will result in an error page: + await controller.stopLoading(); + // navigate to the wallet connect screen: + Navigator.of(context).pushNamed(Routes.walletConnectConnectionsListing, arguments: url); + return null; + } + }, androidOnPermissionRequest: (_, __, resources) async { bool permissionGranted = await Permission.camera.status == PermissionStatus.granted; if (!permissionGranted) { diff --git a/lib/src/screens/exchange/exchange_options_page.dart b/lib/src/screens/exchange/exchange_options_page.dart index f694bf0c2..e70b3e947 100644 --- a/lib/src/screens/exchange/exchange_options_page.dart +++ b/lib/src/screens/exchange/exchange_options_page.dart @@ -34,16 +34,6 @@ class ExchangeOptionsPage extends BasePage { constraints: BoxConstraints(maxWidth: 330), child: Column( children: [ - Padding( - padding: EdgeInsets.only(top: 24), - child: OptionTile( - image: iconMoonPay, - title: "MoonPay Swaps", - description: S.of(context).moonpay_exchange_description, - onPressed: () async => - await getIt.get().launchProvider(context), - ), - ), Padding( padding: EdgeInsets.only(top: 24), child: OptionTile( @@ -54,6 +44,16 @@ class ExchangeOptionsPage extends BasePage { await Navigator.of(context).pushReplacementNamed(Routes.exchange), ), ), + Padding( + padding: EdgeInsets.only(top: 24), + child: OptionTile( + image: iconMoonPay, + title: "MoonPay Swaps", + description: S.of(context).moonpay_exchange_description, + onPressed: () async => + await getIt.get().launchProvider(context), + ), + ), Spacer(), Padding( padding: EdgeInsets.fromLTRB(24, 24, 24, 32),