diff --git a/lib/di.dart b/lib/di.dart index 6a3ea37d9..c10b8de5f 100644 --- a/lib/di.dart +++ b/lib/di.dart @@ -4,6 +4,7 @@ import 'package:cake_wallet/entities/wake_lock.dart'; import 'package:cake_wallet/ionia/ionia_anypay.dart'; import 'package:cake_wallet/ionia/ionia_gift_card.dart'; import 'package:cake_wallet/ionia/ionia_tip.dart'; +import 'package:cake_wallet/src/screens/buy/onramper_page.dart'; import 'package:cake_wallet/src/screens/ionia/cards/ionia_custom_redeem_page.dart'; import 'package:cake_wallet/src/screens/ionia/cards/ionia_gift_card_detail_page.dart'; import 'package:cake_wallet/src/screens/ionia/cards/ionia_more_options_page.dart'; @@ -482,6 +483,10 @@ Future setup( getIt.registerFactory( () => NodeCreateOrEditPage(getIt.get())); + getIt.registerFactory(() => OnRamperPage( + settingsStore: getIt.get().settingsStore, + wallet: getIt.get().wallet!)); + getIt.registerFactory(() => ExchangeViewModel( getIt.get().wallet!, _tradesSource, diff --git a/lib/router.dart b/lib/router.dart index 45459a08e..b255ce8b9 100644 --- a/lib/router.dart +++ b/lib/router.dart @@ -3,6 +3,7 @@ import 'package:cake_wallet/buy/order.dart'; import 'package:cake_wallet/src/screens/backup/backup_page.dart'; import 'package:cake_wallet/src/screens/backup/edit_backup_password_page.dart'; import 'package:cake_wallet/src/screens/buy/buy_webview_page.dart'; +import 'package:cake_wallet/src/screens/buy/onramper_page.dart'; import 'package:cake_wallet/src/screens/buy/pre_order_page.dart'; import 'package:cake_wallet/src/screens/ionia/cards/ionia_account_cards_page.dart'; import 'package:cake_wallet/src/screens/ionia/cards/ionia_account_page.dart'; @@ -471,6 +472,9 @@ Route createRoute(RouteSettings settings) { param1: paymentInfo, param2: commitedInfo)); + case Routes.onramperPage: + return CupertinoPageRoute(builder: (_) => getIt.get()); + default: return MaterialPageRoute( builder: (_) => Scaffold( diff --git a/lib/routes.dart b/lib/routes.dart index 7431d71df..3a781ac3a 100644 --- a/lib/routes.dart +++ b/lib/routes.dart @@ -76,4 +76,5 @@ class Routes { static const ioniaPaymentStatusPage = '/ionia_payment_status_page'; static const ioniaMoreOptionsPage = '/ionia_more_options_page'; static const ioniaCustomRedeemPage = '/ionia_custom_redeem_page'; + static const onramperPage = '/onramper'; } diff --git a/lib/src/screens/buy/onramper_page.dart b/lib/src/screens/buy/onramper_page.dart new file mode 100644 index 000000000..1ba0dc869 --- /dev/null +++ b/lib/src/screens/buy/onramper_page.dart @@ -0,0 +1,82 @@ +import 'dart:io'; +import 'package:cake_wallet/generated/i18n.dart'; +import 'package:cake_wallet/src/screens/base_page.dart'; +import 'package:cake_wallet/store/settings_store.dart'; +import 'package:cw_core/wallet_base.dart'; +import 'package:flutter/material.dart'; +import 'package:webview_flutter/webview_flutter.dart'; +import 'package:cake_wallet/.secrets.g.dart' as secrets; + +class OnRamperPage extends BasePage { + OnRamperPage({ + required this.settingsStore, + required this.wallet}); + + final SettingsStore settingsStore; + final WalletBase wallet; + + @override + String get title => S.current.buy; + + @override + Widget body(BuildContext context) { + final darkMode = Theme.of(context).brightness == Brightness.dark; + return OnRamperPageBody( + settingsStore: settingsStore, + wallet: wallet, + darkMode: darkMode, + backgroundColor: darkMode + ? backgroundDarkColor + : backgroundLightColor, + supportSell: false); + } +} + +class OnRamperPageBody extends StatefulWidget { + OnRamperPageBody({ + required this.settingsStore, + required this.wallet, + required this.darkMode, + required this.supportSell, + required this.backgroundColor}); + + static const baseUrl = 'widget.onramper.com'; + final SettingsStore settingsStore; + final WalletBase wallet; + final Color backgroundColor; + final bool darkMode; + final bool supportSell; + + Uri get uri + => Uri.https( + baseUrl, + '', + { + 'apiKey': secrets.onramperApiKey, + 'defaultCrypto': wallet.currency.title, + 'defaultFiat': settingsStore.fiatCurrency.title, + 'wallets': '${wallet.currency.title}:${wallet.walletAddresses.address}', + 'darkMode': darkMode.toString(), + 'supportSell': supportSell.toString()}); + + @override + OnRamperPageBodyState createState() => OnRamperPageBodyState(); +} + +class OnRamperPageBodyState extends State { + OnRamperPageBodyState(); + + @override + void initState() { + super.initState(); + if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView(); + } + + @override + Widget build(BuildContext context) { + return WebView( + initialUrl: widget.uri.toString(), + backgroundColor: widget.backgroundColor, + javascriptMode: JavascriptMode.unrestricted); + } +} diff --git a/lib/src/screens/dashboard/dashboard_page.dart b/lib/src/screens/dashboard/dashboard_page.dart index c893a7df8..f3d5a21fb 100644 --- a/lib/src/screens/dashboard/dashboard_page.dart +++ b/lib/src/screens/dashboard/dashboard_page.dart @@ -271,10 +271,10 @@ class DashboardPage extends BasePage { switch (walletType) { case WalletType.bitcoin: - Navigator.of(context).pushNamed(Routes.preOrder); + Navigator.of(context).pushNamed(Routes.onramperPage); break; case WalletType.litecoin: - Navigator.of(context).pushNamed(Routes.preOrder); + Navigator.of(context).pushNamed(Routes.onramperPage); break; default: await showPopUp( diff --git a/tool/utils/secret_key.dart b/tool/utils/secret_key.dart index 9bf360017..4502bca74 100644 --- a/tool/utils/secret_key.dart +++ b/tool/utils/secret_key.dart @@ -25,7 +25,8 @@ class SecretKey { SecretKey('moonPaySecretKey', () => ''), SecretKey('sideShiftAffiliateId', () => ''), SecretKey('sideShiftApiKey', () => ''), - SecretKey('simpleSwapApiKey', () => '') + SecretKey('simpleSwapApiKey', () => ''), + SecretKey('onramperApiKey', () => ''), ]; final String name;