| 1 | import 'dart:io'; |
| 2 | |
| 3 | import 'package:cake_wallet/di.dart'; |
| 4 | import 'package:cake_wallet/entities/preferences_key.dart'; |
| 5 | import 'package:cake_wallet/new-ui/pages/home_page.dart'; |
| 6 | import 'package:cake_wallet/new-ui/widgets/changelog_modal.dart'; |
| 7 | import 'package:cake_wallet/src/screens/contact/contact_list_page.dart'; |
| 8 | import 'package:cake_wallet/src/screens/dashboard/pages/cake_features_page.dart'; |
| 9 | import 'package:cake_wallet/src/screens/dashboard/widgets/new_main_navbar_widget.dart'; |
| 10 | import 'package:cake_wallet/src/screens/wallet_connect/services/bottom_sheet_service.dart'; |
| 11 | import 'package:cake_wallet/src/screens/wallet_connect/widgets/bottom_sheet/bottom_sheet_listener_widget.dart'; |
| 12 | import 'package:cake_wallet/src/screens/wallet_list/wallet_list_page.dart'; |
| 13 | import 'package:cake_wallet/src/widgets/vulnerable_seeds_popup.dart'; |
| 14 | import 'package:cake_wallet/utils/show_pop_up.dart'; |
| 15 | import 'package:cake_wallet/utils/version_comparator.dart'; |
| 16 | import 'package:flutter/material.dart'; |
| 17 | import 'package:mobx/mobx.dart'; |
| 18 | import 'package:modal_bottom_sheet/modal_bottom_sheet.dart'; |
| 19 | import 'package:shared_preferences/shared_preferences.dart'; |
| 20 | import '../view_model/dashboard/dashboard_view_model.dart'; |
| 21 | |
| 22 | class NewDashboard extends StatefulWidget { |
| 23 | NewDashboard({ |
| 24 | super.key, |
| 25 | required this.dashboardViewModel, |
| 26 | required this.bottomSheetService, |
| 27 | }); |
| 28 | |
| 29 | final DashboardViewModel dashboardViewModel; |
| 30 | final BottomSheetService bottomSheetService; |
| 31 | |
| 32 | final List<Widget> dashboardPageWidgets = [ |
| 33 | getIt.get<NewHomePage>(), |
| 34 | getIt.get<WalletListPage>(), |
| 35 | getIt.get<ContactListPage>(), |
| 36 | getIt.get<CakeFeaturesPage>(), |
| 37 | Placeholder(), |
| 38 | ]; |
| 39 | |
| 40 | @override |
| 41 | State<NewDashboard> createState() => _NewDashboardState(); |
| 42 | } |
| 43 | |
| 44 | class _NewDashboardState extends State<NewDashboard> { |
| 45 | int _selectedPage = 0; |
| 46 | |
| 47 | @override |
| 48 | void initState() { |
| 49 | super.initState(); |
| 50 | reaction((_) => widget.dashboardViewModel.appStore.wallet, (_) { |
| 51 | setState(() { |
| 52 | _selectedPage = 0; |
| 53 | }); |
| 54 | }); |
| 55 | |
| 56 | Future.delayed(Duration(milliseconds: 300)).then((_) => _showChangelog(context)); |
| 57 | _showVulnerableSeedsPopup(context); |
| 58 | } |
| 59 | |
| 60 | @override |
| 61 | Widget build(BuildContext context) { |
| 62 | return BottomSheetListener( |
| 63 | bottomSheetService: widget.bottomSheetService, |
| 64 | child: CupertinoScaffold( |
| 65 | body: Material( |
| 66 | child: Stack( |
| 67 | alignment: Alignment.bottomCenter, |
| 68 | children: [ |
| 69 | // widget.dashboardPageWidgets[_selectedPage], |
| 70 | IndexedStack( |
| 71 | index: _selectedPage, |
| 72 | children: widget.dashboardPageWidgets, |
| 73 | ), |
| 74 | IgnorePointer( |
| 75 | child: Container( |
| 76 | height: 150, |
| 77 | decoration: BoxDecoration( |
| 78 | gradient: LinearGradient( |
| 79 | begin: Alignment.topCenter, |
| 80 | end: Alignment.bottomCenter, |
| 81 | colors: <Color>[ |
| 82 | Theme.of(context).colorScheme.surfaceDim.withAlpha(5), |
| 83 | Theme.of(context).colorScheme.surfaceDim.withAlpha(50), |
| 84 | Theme.of(context).colorScheme.surfaceDim.withAlpha(100), |
| 85 | Theme.of(context).colorScheme.surfaceDim.withAlpha(150), |
| 86 | Theme.of(context).colorScheme.surfaceDim.withAlpha(200), |
| 87 | Theme.of(context).colorScheme.surfaceDim.withAlpha(200), |
| 88 | ], |
| 89 | ), |
| 90 | ), |
| 91 | ), |
| 92 | ), |
| 93 | // Invisible pointer-absorbing strip behind the nav bar: it must not |
| 94 | // be reachable by screen-reader traversal either. |
| 95 | ExcludeSemantics( |
| 96 | child: SafeArea( |
| 97 | bottom: !(Platform.isIOS), |
| 98 | child: SizedBox( |
| 99 | width: double.infinity, |
| 100 | height: NewMainNavBar.barHeight + NewMainNavBar.barBottomPadding, |
| 101 | child: AbsorbPointer( |
| 102 | absorbing: true, |
| 103 | child: Container(color: Colors.transparent), |
| 104 | ), |
| 105 | ), |
| 106 | ), |
| 107 | ), |
| 108 | NewMainNavBar( |
| 109 | dashboardViewModel: widget.dashboardViewModel, |
| 110 | selectedIndex: _selectedPage, |
| 111 | onItemTap: (index) { |
| 112 | setState(() { |
| 113 | _selectedPage = index; |
| 114 | }); |
| 115 | }, |
| 116 | ) |
| 117 | ], |
| 118 | ), |
| 119 | ), |
| 120 | ), |
| 121 | ); |
| 122 | } |
| 123 | |
| 124 | void _showChangelog(BuildContext context) async { |
| 125 | final sharedPrefs = await SharedPreferences.getInstance(); |
| 126 | final currentAppVersion = VersionComparator.getExtendedVersionNumber( |
| 127 | widget.dashboardViewModel.settingsStore.appVersion); |
| 128 | final lastSeenAppVersion = sharedPrefs.getInt(PreferencesKey.lastSeenAppVersion); |
| 129 | final isNewInstall = sharedPrefs.getBool(PreferencesKey.isNewInstall) ?? true; |
| 130 | |
| 131 | if (currentAppVersion != lastSeenAppVersion && !isNewInstall) { |
| 132 | Future<void>.delayed( |
| 133 | Duration(seconds: 1), |
| 134 | () { |
| 135 | if (context.mounted) { |
| 136 | showModalBottomSheet( |
| 137 | isScrollControlled: true, |
| 138 | context: context, |
| 139 | builder: (context) { |
| 140 | return ChangelogModal( |
| 141 | version: widget.dashboardViewModel.settingsStore.appVersion, |
| 142 | ); |
| 143 | }); |
| 144 | } |
| 145 | }, |
| 146 | ); |
| 147 | |
| 148 | sharedPrefs.setInt(PreferencesKey.lastSeenAppVersion, currentAppVersion); |
| 149 | } else if (isNewInstall) { |
| 150 | sharedPrefs.setInt(PreferencesKey.lastSeenAppVersion, currentAppVersion); |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | void _showVulnerableSeedsPopup(BuildContext context) async { |
| 155 | final List<String> affectedWalletNames = await widget.dashboardViewModel.checkAffectedWallets(); |
| 156 | |
| 157 | if (affectedWalletNames.isNotEmpty) { |
| 158 | Future<void>.delayed( |
| 159 | Duration(seconds: 1), |
| 160 | () { |
| 161 | if (context.mounted) { |
| 162 | showPopUp<void>( |
| 163 | context: context, |
| 164 | builder: (BuildContext context) { |
| 165 | return VulnerableSeedsPopup(affectedWalletNames); |
| 166 | }, |
| 167 | ); |
| 168 | } |
| 169 | }, |
| 170 | ); |
| 171 | } |
| 172 | } |
| 173 | } |