mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-03 17:40:43 +00:00
Add initial integration with Moonpay SDK
This commit is contained in:
parent
cef3029f6f
commit
63b0896db9
6 changed files with 79 additions and 0 deletions
12
assets/index.html
Normal file
12
assets/index.html
Normal file
|
@ -0,0 +1,12 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
</head>
|
||||
<body>
|
||||
<script src="index.js"></script>
|
||||
<script src="https://static.moonpay.com/web-sdk/v1/moonpay-web-sdk.min.js"></script>
|
||||
</body>
|
||||
</html>
|
|
@ -28,6 +28,7 @@ import 'package:cake_wallet/src/screens/dashboard/desktop_widgets/desktop_wallet
|
|||
import 'package:cake_wallet/src/screens/dashboard/edit_token_page.dart';
|
||||
import 'package:cake_wallet/src/screens/dashboard/home_settings_page.dart';
|
||||
import 'package:cake_wallet/src/screens/dashboard/widgets/transactions_page.dart';
|
||||
import 'package:cake_wallet/src/screens/exchange/moonpay_exchange_web_view.dart';
|
||||
import 'package:cake_wallet/src/screens/nano/nano_change_rep_page.dart';
|
||||
import 'package:cake_wallet/src/screens/nano_accounts/nano_account_edit_or_create_page.dart';
|
||||
import 'package:cake_wallet/src/screens/nano_accounts/nano_account_list_page.dart';
|
||||
|
@ -784,6 +785,8 @@ Future<void> setup({
|
|||
|
||||
getIt.registerFactoryParam<WebViewPage, String, Uri>((title, uri) => WebViewPage(title, uri));
|
||||
|
||||
getIt.registerFactory<MoonpayExchangeWebView>(() => MoonpayExchangeWebView());
|
||||
|
||||
getIt.registerFactory<PayfuraBuyProvider>(() => PayfuraBuyProvider(
|
||||
settingsStore: getIt.get<AppStore>().settingsStore,
|
||||
wallet: getIt.get<AppStore>().wallet!,
|
||||
|
|
|
@ -12,6 +12,7 @@ import 'package:cake_wallet/src/screens/buy/buy_webview_page.dart';
|
|||
import 'package:cake_wallet/src/screens/buy/webview_page.dart';
|
||||
import 'package:cake_wallet/src/screens/dashboard/edit_token_page.dart';
|
||||
import 'package:cake_wallet/src/screens/dashboard/home_settings_page.dart';
|
||||
import 'package:cake_wallet/src/screens/exchange/moonpay_exchange_web_view.dart';
|
||||
import 'package:cake_wallet/src/screens/nano/nano_change_rep_page.dart';
|
||||
import 'package:cake_wallet/src/screens/nano_accounts/nano_account_edit_or_create_page.dart';
|
||||
import 'package:cake_wallet/src/screens/nodes/pow_node_create_or_edit_page.dart';
|
||||
|
@ -519,6 +520,9 @@ Route<dynamic> createRoute(RouteSettings settings) {
|
|||
return CupertinoPageRoute<void>(
|
||||
builder: (_) => getIt.get<WebViewPage>(param1: title, param2: url));
|
||||
|
||||
case Routes.moonpayExchangeWebView:
|
||||
return CupertinoPageRoute<void>(builder: (_) => getIt.get<MoonpayExchangeWebView>());
|
||||
|
||||
case Routes.advancedPrivacySettings:
|
||||
final type = settings.arguments as WalletType;
|
||||
|
||||
|
|
|
@ -78,6 +78,7 @@ class Routes {
|
|||
static const ioniaMoreOptionsPage = '/ionia_more_options_page';
|
||||
static const ioniaCustomRedeemPage = '/ionia_custom_redeem_page';
|
||||
static const webViewPage = '/web_view_page';
|
||||
static const moonpayExchangeWebView = '/moonpay_exchange_web_view';
|
||||
static const connectionSync = '/connection_sync_page';
|
||||
static const securityBackupPage = '/security_and_backup_page';
|
||||
static const privacyPage = '/privacy_page';
|
||||
|
|
58
lib/src/screens/exchange/moonpay_exchange_web_view.dart
Normal file
58
lib/src/screens/exchange/moonpay_exchange_web_view.dart
Normal file
|
@ -0,0 +1,58 @@
|
|||
import 'package:cake_wallet/generated/i18n.dart';
|
||||
import 'package:cake_wallet/src/screens/base_page.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
||||
import 'package:cake_wallet/.secrets.g.dart' as secrets;
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
|
||||
class MoonpayExchangeWebView extends BasePage {
|
||||
@override
|
||||
String get title => "Swap";
|
||||
|
||||
@override
|
||||
Widget body(BuildContext context) {
|
||||
return InAppWebView(
|
||||
initialOptions: InAppWebViewGroupOptions(
|
||||
crossPlatform: InAppWebViewOptions(transparentBackground: true),
|
||||
),
|
||||
initialFile: "assets/index.html",
|
||||
onLoadStop: (controller, uri) {
|
||||
final String functionBody = """
|
||||
const moonPay = window.MoonPayWebSdk.init;
|
||||
|
||||
const moonPaySdk = moonPay({
|
||||
flow: 'buy',
|
||||
environment: 'production',
|
||||
variant: 'newTab',
|
||||
params: {
|
||||
apiKey: '${secrets.moonPayApiKey}',
|
||||
theme: 'dark',
|
||||
baseCurrencyCode: 'usd',
|
||||
baseCurrencyAmount: '100',
|
||||
defaultCurrencyCode: 'eth'
|
||||
},
|
||||
debug: $kDebugMode
|
||||
});
|
||||
|
||||
moonPaySdk.show();
|
||||
""";
|
||||
controller.callAsyncJavaScript(functionBody: functionBody);
|
||||
},
|
||||
androidOnPermissionRequest: (_, __, List<String> resources) async {
|
||||
bool permissionGranted = await Permission.camera.status == PermissionStatus.granted;
|
||||
if (!permissionGranted) {
|
||||
final permissionStatus = await Permission.camera.request();
|
||||
permissionGranted = await permissionStatus.isGranted;
|
||||
}
|
||||
|
||||
return PermissionRequestResponse(
|
||||
resources: resources,
|
||||
action: permissionGranted
|
||||
? PermissionRequestResponseAction.GRANT
|
||||
: PermissionRequestResponseAction.DENY,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
|
@ -135,6 +135,7 @@ flutter:
|
|||
- assets/text/
|
||||
- assets/faq/
|
||||
- assets/animation/
|
||||
- assets/index.html
|
||||
|
||||
fonts:
|
||||
- family: Lato
|
||||
|
|
Loading…
Reference in a new issue