import 'dart:io'; import 'package:hash_wallet/di.dart'; import 'package:hash_wallet/entities/preferences_key.dart'; import 'package:hash_wallet/new-ui/pages/home_page.dart'; import 'package:hash_wallet/new-ui/widgets/changelog_modal.dart'; import 'package:hash_wallet/src/screens/contact/contact_list_page.dart'; import 'package:hash_wallet/src/screens/dashboard/pages/cake_features_page.dart'; import 'package:hash_wallet/src/screens/dashboard/widgets/new_main_navbar_widget.dart'; import 'package:hash_wallet/src/screens/wallet_connect/services/bottom_sheet_service.dart'; import 'package:hash_wallet/src/screens/wallet_connect/widgets/bottom_sheet/bottom_sheet_listener_widget.dart'; import 'package:hash_wallet/src/screens/wallet_list/wallet_list_page.dart'; import 'package:hash_wallet/src/widgets/vulnerable_seeds_popup.dart'; import 'package:hash_wallet/utils/show_pop_up.dart'; import 'package:hash_wallet/utils/version_comparator.dart'; import 'package:flutter/material.dart'; import 'package:mobx/mobx.dart'; import 'package:modal_bottom_sheet/modal_bottom_sheet.dart'; import 'package:shared_preferences/shared_preferences.dart'; import '../view_model/dashboard/dashboard_view_model.dart'; class NewDashboard extends StatefulWidget { NewDashboard({ super.key, required this.dashboardViewModel, required this.bottomSheetService, }); final DashboardViewModel dashboardViewModel; final BottomSheetService bottomSheetService; final List dashboardPageWidgets = [ getIt.get(), getIt.get(), getIt.get(), getIt.get(), Placeholder(), ]; @override State createState() => _NewDashboardState(); } class _NewDashboardState extends State { int _selectedPage = 0; @override void initState() { super.initState(); reaction((_) => widget.dashboardViewModel.appStore.wallet, (_) { setState(() { _selectedPage = 0; }); }); // Hash Bags: changelog modal disabled. The Cake-supplied changelog // text (assets/new-ui/changelog/text) describes Cake's release history // including v6.1.0 entries that aren't ours, and the 'View more info' // button linked to blog.cakewallet.com. Re-enable once we have our // own changelog content + versioning under our control. // Future.delayed(Duration(milliseconds: 300)).then((_) => _showChangelog(context)); _showVulnerableSeedsPopup(context); } @override Widget build(BuildContext context) { return BottomSheetListener( bottomSheetService: widget.bottomSheetService, child: CupertinoScaffold( body: Material( child: Stack( alignment: Alignment.bottomCenter, children: [ // widget.dashboardPageWidgets[_selectedPage], IndexedStack( index: _selectedPage, children: widget.dashboardPageWidgets, ), IgnorePointer( child: Container( height: 150, decoration: BoxDecoration( gradient: LinearGradient( begin: Alignment.topCenter, end: Alignment.bottomCenter, colors: [ Theme.of(context).colorScheme.surfaceDim.withAlpha(5), Theme.of(context).colorScheme.surfaceDim.withAlpha(50), Theme.of(context).colorScheme.surfaceDim.withAlpha(100), Theme.of(context).colorScheme.surfaceDim.withAlpha(150), Theme.of(context).colorScheme.surfaceDim.withAlpha(200), Theme.of(context).colorScheme.surfaceDim.withAlpha(200), ], ), ), ), ), SafeArea( bottom: !(Platform.isIOS), child: SizedBox( width: double.infinity, height: NewMainNavBar.barHeight + NewMainNavBar.barBottomPadding, child: AbsorbPointer( absorbing: true, child: Container(color: Colors.transparent), ), ), ), NewMainNavBar( dashboardViewModel: widget.dashboardViewModel, selectedIndex: _selectedPage, onItemTap: (index) { setState(() { _selectedPage = index; }); }, ) ], ), ), ), ); } void _showChangelog(BuildContext context) async { final sharedPrefs = await SharedPreferences.getInstance(); final currentAppVersion = VersionComparator.getExtendedVersionNumber( widget.dashboardViewModel.settingsStore.appVersion); final lastSeenAppVersion = sharedPrefs.getInt(PreferencesKey.lastSeenAppVersion); final isNewInstall = sharedPrefs.getBool(PreferencesKey.isNewInstall) ?? true; if (currentAppVersion != lastSeenAppVersion && !isNewInstall) { Future.delayed( Duration(seconds: 1), () { if (context.mounted) { showModalBottomSheet( isScrollControlled: true, context: context, builder: (context) { return ChangelogModal( version: widget.dashboardViewModel.settingsStore.appVersion, ); }); } }, ); sharedPrefs.setInt(PreferencesKey.lastSeenAppVersion, currentAppVersion); } else if (isNewInstall) { sharedPrefs.setInt(PreferencesKey.lastSeenAppVersion, currentAppVersion); } } void _showVulnerableSeedsPopup(BuildContext context) async { final List affectedWalletNames = await widget.dashboardViewModel.checkAffectedWallets(); if (affectedWalletNames.isNotEmpty) { Future.delayed( Duration(seconds: 1), () { if (context.mounted) { showPopUp( context: context, builder: (BuildContext context) { return VulnerableSeedsPopup(affectedWalletNames); }, ); } }, ); } } }