| 1 | import 'dart:io'; |
| 2 | |
| 3 | import 'package:cake_wallet/generated/i18n.dart'; |
| 4 | import 'package:cake_wallet/new-ui/widgets/apps_widget.dart'; |
| 5 | import 'package:cake_wallet/routes.dart'; |
| 6 | import 'package:cake_wallet/src/widgets/alert_with_one_action.dart'; |
| 7 | import 'package:cake_wallet/src/widgets/cake_image_widget.dart'; |
| 8 | import 'package:cake_wallet/src/widgets/dashboard_card_widget.dart'; |
| 9 | import 'package:cake_wallet/utils/feature_flag.dart'; |
| 10 | import 'package:cake_wallet/utils/show_pop_up.dart'; |
| 11 | import 'package:cake_wallet/view_model/dashboard/cake_features_view_model.dart'; |
| 12 | import 'package:cake_wallet/view_model/dashboard/dashboard_view_model.dart'; |
| 13 | import 'package:cw_core/utils/print_verbose.dart'; |
| 14 | import 'package:cw_core/wallet_type.dart'; |
| 15 | import 'package:flutter/material.dart'; |
| 16 | import 'package:flutter_mobx/flutter_mobx.dart'; |
| 17 | import 'package:url_launcher/url_launcher.dart'; |
| 18 | import 'package:cake_wallet/src/widgets/gradient_background.dart'; |
| 19 | |
| 20 | class CakeFeaturesPage extends StatelessWidget { |
| 21 | CakeFeaturesPage({required this.dashboardViewModel, required this.cakeFeaturesViewModel}); |
| 22 | |
| 23 | final DashboardViewModel dashboardViewModel; |
| 24 | final CakeFeaturesViewModel cakeFeaturesViewModel; |
| 25 | |
| 26 | @override |
| 27 | Widget build(BuildContext context) { |
| 28 | return GradientBackground( |
| 29 | scaffold: SafeArea( |
| 30 | child: Column( |
| 31 | crossAxisAlignment: CrossAxisAlignment.start, |
| 32 | children: [ |
| 33 | _buildHeader(context), |
| 34 | Expanded( |
| 35 | child: LayoutBuilder( |
| 36 | builder: (context, constraints) { |
| 37 | return SingleChildScrollView( |
| 38 | child: ConstrainedBox( |
| 39 | constraints: BoxConstraints(minHeight: constraints.maxHeight), |
| 40 | child: IntrinsicHeight( |
| 41 | child: !FeatureFlag.hasNewUi ? _buildOldUi(context) : _buildNewUi(context), |
| 42 | ), |
| 43 | ), |
| 44 | ); |
| 45 | }, |
| 46 | ), |
| 47 | ), |
| 48 | ], |
| 49 | ), |
| 50 | ), |
| 51 | ); |
| 52 | } |
| 53 | |
| 54 | Widget _buildHeader(BuildContext context) { |
| 55 | if (!FeatureFlag.hasNewUi) { |
| 56 | return Padding( |
| 57 | padding: const EdgeInsets.only(left: 24, top: 16, bottom: 16), |
| 58 | child: Text( |
| 59 | S.of(context).apps, |
| 60 | style: Theme.of(context).textTheme.headlineLarge?.copyWith( |
| 61 | fontWeight: FontWeight.w500, |
| 62 | color: Theme.of(context).colorScheme.onSurface, |
| 63 | ), |
| 64 | ), |
| 65 | ); |
| 66 | } |
| 67 | |
| 68 | return Align( |
| 69 | alignment: Alignment.center, |
| 70 | child: Padding( |
| 71 | padding: const EdgeInsets.only(top: 24, bottom: 24), |
| 72 | child: Text( |
| 73 | S.of(context).apps, |
| 74 | style: Theme.of(context).textTheme.titleLarge?.copyWith( |
| 75 | fontSize: 18.0, |
| 76 | fontWeight: FontWeight.w600, |
| 77 | color: Theme.of(context).colorScheme.onSurface, |
| 78 | ), |
| 79 | ), |
| 80 | ), |
| 81 | ); |
| 82 | } |
| 83 | |
| 84 | Widget _buildOldUi(BuildContext context) { |
| 85 | return Column( |
| 86 | children: [ |
| 87 | const SizedBox(height: 2), |
| 88 | DashBoardRoundedCardWidget( |
| 89 | shadowBlur: dashboardViewModel.getShadowBlur(), |
| 90 | shadowSpread: dashboardViewModel.getShadowSpread(), |
| 91 | onTap: () => _onCakePayTap(context), |
| 92 | title: 'Cake Pay', |
| 93 | subTitle: S.of(context).cake_pay_subtitle, |
| 94 | image: Image.asset('assets/images/cakepay.png', height: 74, width: 70, fit: BoxFit.cover), |
| 95 | ), |
| 96 | Observer(builder: (_) { |
| 97 | if (dashboardViewModel.type == WalletType.ethereum) { |
| 98 | return DashBoardRoundedCardWidget( |
| 99 | shadowBlur: dashboardViewModel.getShadowBlur(), |
| 100 | shadowSpread: dashboardViewModel.getShadowSpread(), |
| 101 | onTap: () => Navigator.of(context).pushNamed(Routes.dEuroSavings), |
| 102 | title: S.of(context).deuro_savings, |
| 103 | subTitle: S.of(context).deuro_savings_subtitle, |
| 104 | image: Image.asset('assets/images/deuro_icon.png', |
| 105 | height: 80, width: 80, fit: BoxFit.cover), |
| 106 | ); |
| 107 | } |
| 108 | return const SizedBox(); |
| 109 | }), |
| 110 | DashBoardRoundedCardWidget( |
| 111 | shadowBlur: dashboardViewModel.getShadowBlur(), |
| 112 | shadowSpread: dashboardViewModel.getShadowSpread(), |
| 113 | onTap: () => _launchUrl("cake.nano-gpt.com"), |
| 114 | title: "NanoGPT", |
| 115 | subTitle: S.of(context).nanogpt_subtitle, |
| 116 | image: Image.asset('assets/images/nanogpt.png', height: 80, width: 80, fit: BoxFit.cover), |
| 117 | ), |
| 118 | const Spacer(), |
| 119 | const SizedBox(height: 125), |
| 120 | ], |
| 121 | ); |
| 122 | } |
| 123 | |
| 124 | Widget _buildNewUi(BuildContext context) { |
| 125 | return Column( |
| 126 | crossAxisAlignment: CrossAxisAlignment.start, |
| 127 | children: [ |
| 128 | Align( |
| 129 | alignment: Alignment.centerLeft, |
| 130 | child: Padding( |
| 131 | padding: const EdgeInsets.only(left: 24, bottom: 8), |
| 132 | child: CakeImageWidget( |
| 133 | imageUrl: "assets/new-ui/by-cakelabs.svg", |
| 134 | height: 20, |
| 135 | color: Theme.of(context).colorScheme.onSurfaceVariant), |
| 136 | ), |
| 137 | ), |
| 138 | AppsWidget( |
| 139 | isWide: true, |
| 140 | isCake: true, |
| 141 | onTap: () => _onCakePayTap(context), |
| 142 | title: 'Cake Pay', |
| 143 | subTitle: S.of(context).cake_pay_subtitle, |
| 144 | image: 'assets/images/cakepay.png', |
| 145 | ), |
| 146 | AppsWidget( |
| 147 | isWide: true, |
| 148 | isLink: true, |
| 149 | isCake: true, |
| 150 | onTap: () => _launchUrl("cupcakewallet.com"), |
| 151 | title: "Cupcake", |
| 152 | subTitle: "Turn your old phone into your new hardware wallet with our new app", |
| 153 | image: 'assets/images/cupcake.png', |
| 154 | ), |
| 155 | AppsWidget( |
| 156 | isWide: true, |
| 157 | isLink: true, |
| 158 | isCake: true, |
| 159 | onTap: () => _launchUrl("radar.chat"), |
| 160 | title: "Radar", |
| 161 | subTitle: "Your messages. Your Bitcoin. Together, at last", |
| 162 | image: 'assets/images/radar.png', |
| 163 | ), |
| 164 | const SizedBox(height: 12), |
| 165 | Padding( |
| 166 | padding: const EdgeInsets.only(left: 24, top: 16, bottom: 8), |
| 167 | child: Text( |
| 168 | "Featured Apps", |
| 169 | style: Theme.of(context).textTheme.headlineMedium?.copyWith( |
| 170 | fontWeight: FontWeight.w500, |
| 171 | color: Theme.of(context).colorScheme.onSurface, |
| 172 | ), |
| 173 | ), |
| 174 | ), |
| 175 | AppsWidget( |
| 176 | isWide: true, |
| 177 | isLink: true, |
| 178 | onTap: () => _launchUrl("cake.nano-gpt.com"), |
| 179 | title: "NanoGPT", |
| 180 | subTitle: S.of(context).nanogpt_subtitle, |
| 181 | image: 'assets/images/nanogpt.png', |
| 182 | ), |
| 183 | Observer(builder: (_) { |
| 184 | if (dashboardViewModel.type == WalletType.ethereum) { |
| 185 | return AppsWidget( |
| 186 | isWide: true, |
| 187 | onTap: () => Navigator.of(context).pushNamed(Routes.dEuroSavings), |
| 188 | title: S.of(context).deuro_savings, |
| 189 | subTitle: S.of(context).deuro_savings_subtitle, |
| 190 | image: 'assets/images/deuro_icon.png', |
| 191 | ); |
| 192 | } |
| 193 | return const SizedBox(); |
| 194 | }), |
| 195 | const Spacer(), |
| 196 | const SizedBox(height: 125), |
| 197 | ], |
| 198 | ); |
| 199 | } |
| 200 | |
| 201 | void _onCakePayTap(BuildContext context) { |
| 202 | if (Platform.isMacOS) { |
| 203 | _launchUrl("buy.cakepay.com"); |
| 204 | } else { |
| 205 | _navigatorToGiftCardsPage(context); |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | void _launchUrl(String url) { |
| 210 | try { |
| 211 | launchUrl(Uri.https(url), mode: LaunchMode.externalApplication); |
| 212 | } catch (e) { |
| 213 | printV(e); |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | void _navigatorToGiftCardsPage(BuildContext context) { |
| 218 | if (dashboardViewModel.type == WalletType.haven) { |
| 219 | showPopUp<void>( |
| 220 | context: context, |
| 221 | builder: (BuildContext context) { |
| 222 | return AlertWithOneAction( |
| 223 | alertTitle: S.of(context).error, |
| 224 | alertContent: S.of(context).gift_cards_unavailable, |
| 225 | buttonText: S.of(context).ok, |
| 226 | buttonAction: () => Navigator.of(context).pop()); |
| 227 | }); |
| 228 | } else { |
| 229 | Navigator.pushNamed(context, Routes.cakePayCardsPage); |
| 230 | } |
| 231 | } |
| 232 | } |