mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-03 17:40:43 +00:00
moonpay fixes, swap moonpay and normal exchange
This commit is contained in:
parent
0dd121a56d
commit
cba3fc65ce
2 changed files with 47 additions and 12 deletions
|
@ -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/generated/i18n.dart';
|
||||||
|
import 'package:cake_wallet/routes.dart';
|
||||||
import 'package:cake_wallet/src/screens/base_page.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/material.dart';
|
||||||
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
||||||
|
import 'package:fluttertoast/fluttertoast.dart';
|
||||||
import 'package:permission_handler/permission_handler.dart';
|
import 'package:permission_handler/permission_handler.dart';
|
||||||
|
|
||||||
class WebViewPage extends BasePage {
|
class WebViewPage extends BasePage {
|
||||||
|
@ -36,9 +40,40 @@ class WebViewPageBodyState extends State<WebViewPageBody> {
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return InAppWebView(
|
return InAppWebView(
|
||||||
initialOptions: InAppWebViewGroupOptions(
|
initialOptions: InAppWebViewGroupOptions(
|
||||||
crossPlatform: InAppWebViewOptions(transparentBackground: true),
|
crossPlatform: InAppWebViewOptions(
|
||||||
|
transparentBackground: true,
|
||||||
|
javaScriptEnabled: true,
|
||||||
|
cacheEnabled: true,
|
||||||
|
resourceCustomSchemes: ["cakewallet"],
|
||||||
|
useShouldOverrideUrlLoading: true,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
initialUrlRequest: URLRequest(url: widget.uri),
|
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<AppStore>().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 {
|
androidOnPermissionRequest: (_, __, resources) async {
|
||||||
bool permissionGranted = await Permission.camera.status == PermissionStatus.granted;
|
bool permissionGranted = await Permission.camera.status == PermissionStatus.granted;
|
||||||
if (!permissionGranted) {
|
if (!permissionGranted) {
|
||||||
|
|
|
@ -34,16 +34,6 @@ class ExchangeOptionsPage extends BasePage {
|
||||||
constraints: BoxConstraints(maxWidth: 330),
|
constraints: BoxConstraints(maxWidth: 330),
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
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<MoonPayExchangeProvider>().launchProvider(context),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Padding(
|
Padding(
|
||||||
padding: EdgeInsets.only(top: 24),
|
padding: EdgeInsets.only(top: 24),
|
||||||
child: OptionTile(
|
child: OptionTile(
|
||||||
|
@ -54,6 +44,16 @@ class ExchangeOptionsPage extends BasePage {
|
||||||
await Navigator.of(context).pushReplacementNamed(Routes.exchange),
|
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<MoonPayExchangeProvider>().launchProvider(context),
|
||||||
|
),
|
||||||
|
),
|
||||||
Spacer(),
|
Spacer(),
|
||||||
Padding(
|
Padding(
|
||||||
padding: EdgeInsets.fromLTRB(24, 24, 24, 32),
|
padding: EdgeInsets.fromLTRB(24, 24, 24, 32),
|
||||||
|
|
Loading…
Reference in a new issue