| 1 | import 'package:cake_wallet/generated/i18n.dart'; |
| 2 | import 'package:cake_wallet/routes.dart'; |
| 3 | import 'package:cake_wallet/src/screens/base_page.dart'; |
| 4 | import 'package:cake_wallet/src/screens/settings/widgets/settings_cell_with_arrow.dart'; |
| 5 | import 'package:cake_wallet/src/widgets/cake_image_widget.dart'; |
| 6 | import 'package:cake_wallet/src/widgets/section_divider.dart'; |
| 7 | import 'package:cake_wallet/src/widgets/standard_list.dart'; |
| 8 | import 'package:cake_wallet/view_model/set_up_2fa_viewmodel.dart'; |
| 9 | import 'package:flutter/material.dart'; |
| 10 | import 'package:url_launcher/url_launcher.dart'; |
| 11 | |
| 12 | class Setup2FAPage extends BasePage { |
| 13 | Setup2FAPage({required this.setup2FAViewModel}); |
| 14 | |
| 15 | final Setup2FAViewModel setup2FAViewModel; |
| 16 | |
| 17 | @override |
| 18 | String get title => 'Cake 2FA'; |
| 19 | |
| 20 | @override |
| 21 | Widget body(BuildContext context) { |
| 22 | final cake2FAGuideTitle = 'Cake 2FA Guide'; |
| 23 | final cake2FAGuideUri = |
| 24 | Uri.parse('https://docs.cakewallet.com/features/advanced/authentication/'); |
| 25 | return Column( |
| 26 | crossAxisAlignment: CrossAxisAlignment.center, |
| 27 | children: [ |
| 28 | Expanded( |
| 29 | flex: 2, |
| 30 | child: ConstrainedBox( |
| 31 | constraints: BoxConstraints(maxHeight: MediaQuery.of(context).size.height * 0.3), |
| 32 | child: AspectRatio( |
| 33 | aspectRatio: 0.764, |
| 34 | child: CakeImageWidget(imageUrl: 'assets/images/2fa.png'), |
| 35 | ), |
| 36 | ), |
| 37 | ), |
| 38 | const SizedBox(height: 24), |
| 39 | Expanded( |
| 40 | flex: 2, |
| 41 | child: Padding( |
| 42 | padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16), |
| 43 | child: Text( |
| 44 | S.current.setup_2fa_text, |
| 45 | textAlign: TextAlign.center, |
| 46 | style: Theme.of(context).textTheme.bodyMedium?.copyWith( |
| 47 | height: 1.571, |
| 48 | color: Theme.of(context).colorScheme.onSurfaceVariant, |
| 49 | ), |
| 50 | ), |
| 51 | ), |
| 52 | ), |
| 53 | Expanded( |
| 54 | child: Column( |
| 55 | children: [ |
| 56 | SettingsCellWithArrow( |
| 57 | title: S.current.setup_totp_recommended, |
| 58 | handler: (_) { |
| 59 | setup2FAViewModel.generateSecretKey(); |
| 60 | return Navigator.of(context).pushReplacementNamed(Routes.setup_2faQRPage); |
| 61 | }, |
| 62 | ), |
| 63 | HorizontalSectionDivider(margin: EdgeInsets.symmetric(horizontal: 24)), |
| 64 | SettingsCellWithArrow( |
| 65 | title: cake2FAGuideTitle, handler: (_) => _launchUrl(cake2FAGuideUri)), |
| 66 | HorizontalSectionDivider(margin: EdgeInsets.symmetric(horizontal: 24)), |
| 67 | ], |
| 68 | ), |
| 69 | ), |
| 70 | ], |
| 71 | ); |
| 72 | } |
| 73 | |
| 74 | static void _launchUrl(Uri url) async { |
| 75 | try { |
| 76 | await launchUrl(url, mode: LaunchMode.externalApplication); |
| 77 | } catch (e) {} |
| 78 | } |
| 79 | } |