2021-11-02 09:17:24 +00:00
|
|
|
import 'dart:async';
|
2023-04-21 18:21:31 +03:00
|
|
|
import 'package:cake_wallet/entities/preferences_key.dart';
|
2023-04-14 06:39:08 +02:00
|
|
|
import 'package:cake_wallet/di.dart';
|
|
|
|
import 'package:cake_wallet/entities/main_actions.dart';
|
|
|
|
import 'package:cake_wallet/src/screens/dashboard/desktop_widgets/desktop_sidebar_wrapper.dart';
|
2022-07-28 18:03:16 +01:00
|
|
|
import 'package:cake_wallet/src/screens/dashboard/widgets/market_place_page.dart';
|
2023-04-21 18:21:31 +03:00
|
|
|
import 'package:cake_wallet/utils/version_comparator.dart';
|
2023-06-08 02:16:52 +03:00
|
|
|
import 'package:cake_wallet/view_model/dashboard/market_place_view_model.dart';
|
2020-07-06 23:09:03 +03:00
|
|
|
import 'package:cake_wallet/generated/i18n.dart';
|
|
|
|
import 'package:cake_wallet/routes.dart';
|
2021-11-02 09:17:24 +00:00
|
|
|
import 'package:cake_wallet/src/screens/yat_emoji_id.dart';
|
2021-04-26 21:06:21 +03:00
|
|
|
import 'package:cake_wallet/src/widgets/alert_with_one_action.dart';
|
2020-12-16 22:45:45 +02:00
|
|
|
import 'package:cake_wallet/themes/theme_base.dart';
|
2023-04-14 06:39:08 +02:00
|
|
|
import 'package:cake_wallet/utils/responsive_layout_util.dart';
|
2021-04-26 21:06:21 +03:00
|
|
|
import 'package:cake_wallet/utils/show_pop_up.dart';
|
2020-01-04 21:31:52 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2020-07-23 15:20:52 +03:00
|
|
|
import 'package:cake_wallet/view_model/dashboard/dashboard_view_model.dart';
|
2020-07-06 23:09:03 +03:00
|
|
|
import 'package:cake_wallet/src/screens/base_page.dart';
|
2020-05-29 18:10:11 +03:00
|
|
|
import 'package:cake_wallet/src/screens/dashboard/widgets/menu_widget.dart';
|
2020-07-21 20:22:41 +03:00
|
|
|
import 'package:cake_wallet/src/screens/dashboard/widgets/action_button.dart';
|
|
|
|
import 'package:cake_wallet/src/screens/dashboard/widgets/balance_page.dart';
|
2020-07-23 15:20:52 +03:00
|
|
|
import 'package:cake_wallet/src/screens/dashboard/widgets/transactions_page.dart';
|
2020-07-22 13:04:11 +03:00
|
|
|
import 'package:cake_wallet/src/screens/dashboard/widgets/sync_indicator.dart';
|
2020-07-27 20:07:37 +03:00
|
|
|
import 'package:cake_wallet/view_model/wallet_address_list/wallet_address_list_view_model.dart';
|
2021-03-03 20:54:23 +02:00
|
|
|
import 'package:flutter_mobx/flutter_mobx.dart';
|
2021-05-11 16:52:48 +03:00
|
|
|
import 'package:mobx/mobx.dart';
|
2023-04-21 18:21:31 +03:00
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
2020-07-31 22:55:26 +03:00
|
|
|
import 'package:smooth_page_indicator/smooth_page_indicator.dart';
|
2021-11-02 09:17:24 +00:00
|
|
|
import 'package:cake_wallet/main.dart';
|
2023-04-21 18:21:31 +03:00
|
|
|
import 'package:cake_wallet/src/screens/release_notes/release_notes_screen.dart';
|
2020-01-04 21:31:52 +02:00
|
|
|
|
2023-04-14 06:39:08 +02:00
|
|
|
class DashboardPage extends StatelessWidget {
|
2020-07-27 20:07:37 +03:00
|
|
|
DashboardPage({
|
2022-10-12 13:09:57 -04:00
|
|
|
required this.balancePage,
|
2023-04-14 06:39:08 +02:00
|
|
|
required this.dashboardViewModel,
|
2022-10-12 13:09:57 -04:00
|
|
|
required this.addressListViewModel,
|
2020-07-27 20:07:37 +03:00
|
|
|
});
|
2023-04-14 06:39:08 +02:00
|
|
|
|
2022-03-18 16:47:57 +06:00
|
|
|
final BalancePage balancePage;
|
2023-04-14 06:39:08 +02:00
|
|
|
final DashboardViewModel dashboardViewModel;
|
|
|
|
final WalletAddressListViewModel addressListViewModel;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
2023-06-14 02:04:52 +03:00
|
|
|
body: ResponsiveLayoutUtil.instance.isMobile
|
2023-04-14 06:39:08 +02:00
|
|
|
? _DashboardPageView(
|
|
|
|
balancePage: balancePage,
|
|
|
|
dashboardViewModel: dashboardViewModel,
|
|
|
|
addressListViewModel: addressListViewModel,
|
|
|
|
)
|
|
|
|
: getIt.get<DesktopSidebarWrapper>(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class _DashboardPageView extends BasePage {
|
|
|
|
_DashboardPageView({
|
|
|
|
required this.balancePage,
|
|
|
|
required this.dashboardViewModel,
|
|
|
|
required this.addressListViewModel,
|
|
|
|
});
|
|
|
|
|
|
|
|
final BalancePage balancePage;
|
|
|
|
|
2020-04-14 21:15:47 +03:00
|
|
|
@override
|
2021-05-11 16:52:48 +03:00
|
|
|
Color get backgroundLightColor =>
|
|
|
|
currentTheme.type == ThemeType.bright ? Colors.transparent : Colors.white;
|
2020-01-04 21:31:52 +02:00
|
|
|
|
|
|
|
@override
|
2020-08-19 20:57:06 +03:00
|
|
|
Color get backgroundDarkColor => Colors.transparent;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget Function(BuildContext, Widget) get rootWrapper =>
|
2020-09-01 14:18:07 +03:00
|
|
|
(BuildContext context, Widget scaffold) => Container(
|
2020-08-19 20:57:06 +03:00
|
|
|
decoration: BoxDecoration(
|
|
|
|
gradient: LinearGradient(colors: [
|
2023-05-24 20:19:51 -03:00
|
|
|
Theme.of(context).colorScheme.secondary,
|
2020-09-01 14:18:07 +03:00
|
|
|
Theme.of(context).scaffoldBackgroundColor,
|
|
|
|
Theme.of(context).primaryColor,
|
|
|
|
], begin: Alignment.topRight, end: Alignment.bottomLeft)),
|
2020-08-19 20:57:06 +03:00
|
|
|
child: scaffold);
|
2020-01-04 21:31:52 +02:00
|
|
|
|
2020-07-28 19:03:34 +03:00
|
|
|
@override
|
2021-04-26 21:06:21 +03:00
|
|
|
bool get resizeToAvoidBottomInset => false;
|
2020-07-28 19:03:34 +03:00
|
|
|
|
2020-07-31 18:29:21 +03:00
|
|
|
@override
|
2023-04-14 06:39:08 +02:00
|
|
|
Widget get endDrawer => MenuWidget(dashboardViewModel);
|
2020-07-31 18:29:21 +03:00
|
|
|
|
2020-07-22 13:04:11 +03:00
|
|
|
@override
|
|
|
|
Widget middle(BuildContext context) {
|
2023-04-14 06:39:08 +02:00
|
|
|
return SyncIndicator(
|
|
|
|
dashboardViewModel: dashboardViewModel,
|
|
|
|
onTap: () => Navigator.of(context, rootNavigator: true).pushNamed(Routes.connectionSync));
|
2020-07-22 13:04:11 +03:00
|
|
|
}
|
|
|
|
|
2020-01-04 21:31:52 +02:00
|
|
|
@override
|
2020-07-06 23:09:03 +03:00
|
|
|
Widget trailing(BuildContext context) {
|
2021-05-11 16:52:48 +03:00
|
|
|
final menuButton = Image.asset('assets/images/menu.png',
|
2023-05-24 20:19:51 -03:00
|
|
|
color: Theme.of(context)
|
|
|
|
.accentTextTheme!
|
|
|
|
.displayMedium!
|
|
|
|
.backgroundColor);
|
2020-07-06 23:09:03 +03:00
|
|
|
|
|
|
|
return Container(
|
2020-09-01 14:18:07 +03:00
|
|
|
alignment: Alignment.centerRight,
|
|
|
|
width: 40,
|
2022-10-12 13:09:57 -04:00
|
|
|
child: TextButton(
|
|
|
|
// FIX-ME: Style
|
|
|
|
//highlightColor: Colors.transparent,
|
|
|
|
//splashColor: Colors.transparent,
|
|
|
|
//padding: EdgeInsets.all(0),
|
2020-09-01 14:18:07 +03:00
|
|
|
onPressed: () => onOpenEndDrawer(),
|
2023-04-18 17:36:56 +00:00
|
|
|
child: Semantics(label: 'Menu', child: menuButton)));
|
2020-07-06 23:09:03 +03:00
|
|
|
}
|
2020-04-14 21:15:47 +03:00
|
|
|
|
2023-04-14 06:39:08 +02:00
|
|
|
final DashboardViewModel dashboardViewModel;
|
2020-07-27 20:07:37 +03:00
|
|
|
final WalletAddressListViewModel addressListViewModel;
|
2023-04-16 14:45:35 +01:00
|
|
|
int get initialPage => dashboardViewModel.shouldShowMarketPlaceInDashboard ? 1 : 0;
|
|
|
|
ObservableList<Widget> pages = ObservableList<Widget>();
|
2020-07-21 20:22:41 +03:00
|
|
|
bool _isEffectsInstalled = false;
|
2022-10-12 13:09:57 -04:00
|
|
|
StreamSubscription<bool>? _onInactiveSub;
|
2020-07-06 23:09:03 +03:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget body(BuildContext context) {
|
2023-04-16 14:45:35 +01:00
|
|
|
final controller = PageController(initialPage: initialPage);
|
2023-04-21 18:21:31 +03:00
|
|
|
|
2023-04-16 14:45:35 +01:00
|
|
|
reaction((_) => dashboardViewModel.shouldShowMarketPlaceInDashboard, (bool value) {
|
|
|
|
if (!dashboardViewModel.shouldShowMarketPlaceInDashboard) {
|
|
|
|
controller.jumpToPage(0);
|
|
|
|
}
|
|
|
|
pages.clear();
|
|
|
|
_isEffectsInstalled = false;
|
|
|
|
_setEffects(context);
|
|
|
|
|
|
|
|
if (value) {
|
|
|
|
controller.jumpToPage(1);
|
|
|
|
} else {
|
|
|
|
controller.jumpToPage(0);
|
|
|
|
}
|
2023-04-21 18:21:31 +03:00
|
|
|
});
|
2021-05-11 16:52:48 +03:00
|
|
|
_setEffects(context);
|
2020-07-21 20:22:41 +03:00
|
|
|
|
|
|
|
return SafeArea(
|
2023-04-14 06:39:08 +02:00
|
|
|
minimum: EdgeInsets.only(bottom: 24),
|
2020-09-01 14:18:07 +03:00
|
|
|
child: Column(
|
2023-04-14 06:39:08 +02:00
|
|
|
mainAxisSize: MainAxisSize.max,
|
|
|
|
children: <Widget>[
|
|
|
|
Expanded(
|
2023-04-16 14:45:35 +01:00
|
|
|
child: Observer(builder: (context) {
|
|
|
|
return PageView.builder(
|
|
|
|
controller: controller,
|
|
|
|
itemCount: pages.length,
|
|
|
|
itemBuilder: (context, index) => pages[index]);
|
|
|
|
})),
|
2023-04-14 06:39:08 +02:00
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.only(bottom: 24, top: 10),
|
2023-04-16 14:45:35 +01:00
|
|
|
child: Observer(builder: (context) {
|
2023-04-18 17:36:56 +00:00
|
|
|
return ExcludeSemantics(
|
|
|
|
child: SmoothPageIndicator(
|
|
|
|
controller: controller,
|
|
|
|
count: pages.length,
|
|
|
|
effect: ColorTransitionEffect(
|
|
|
|
spacing: 6.0,
|
|
|
|
radius: 6.0,
|
|
|
|
dotWidth: 6.0,
|
|
|
|
dotHeight: 6.0,
|
|
|
|
dotColor: Theme.of(context).indicatorColor,
|
|
|
|
activeDotColor: Theme.of(context)
|
|
|
|
.accentTextTheme!
|
2023-05-24 20:19:51 -03:00
|
|
|
.headlineMedium!
|
2023-04-18 17:36:56 +00:00
|
|
|
.backgroundColor!),
|
|
|
|
),
|
2023-04-16 14:45:35 +01:00
|
|
|
);
|
|
|
|
}
|
2023-04-14 06:39:08 +02:00
|
|
|
)),
|
|
|
|
Observer(builder: (_) {
|
|
|
|
return ClipRect(
|
2022-03-30 17:57:04 +02:00
|
|
|
child: Container(
|
2023-04-14 06:39:08 +02:00
|
|
|
margin: const EdgeInsets.only(left: 16, right: 16),
|
|
|
|
child: Container(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
borderRadius: BorderRadius.circular(50.0),
|
|
|
|
border: Border.all(
|
|
|
|
color: currentTheme.type == ThemeType.bright
|
|
|
|
? Color.fromRGBO(255, 255, 255, 0.2)
|
|
|
|
: Colors.transparent,
|
|
|
|
width: 1,
|
|
|
|
),
|
2023-05-24 20:19:51 -03:00
|
|
|
color: Theme.of(context)
|
|
|
|
.textTheme!
|
|
|
|
.titleLarge!
|
|
|
|
.backgroundColor!,
|
2023-04-14 06:39:08 +02:00
|
|
|
),
|
|
|
|
child: Container(
|
|
|
|
padding: EdgeInsets.only(left: 32, right: 32),
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: MainActions.all
|
|
|
|
.where((element) => element.canShow?.call(dashboardViewModel) ?? true)
|
2023-04-18 17:36:56 +00:00
|
|
|
.map((action) => Semantics(
|
|
|
|
button: true,
|
|
|
|
enabled: (action.isEnabled
|
|
|
|
?.call(dashboardViewModel) ??
|
|
|
|
true),
|
|
|
|
child: ActionButton(
|
|
|
|
image: Image.asset(action.image,
|
|
|
|
height: 24,
|
|
|
|
width: 24,
|
|
|
|
color: action.isEnabled?.call(
|
|
|
|
dashboardViewModel) ??
|
|
|
|
true
|
|
|
|
? Theme.of(context)
|
2023-05-24 20:19:51 -03:00
|
|
|
.accentTextTheme!
|
|
|
|
.displayMedium!
|
2023-04-18 17:36:56 +00:00
|
|
|
.backgroundColor!
|
|
|
|
: Theme.of(context)
|
2023-05-24 20:19:51 -03:00
|
|
|
.accentTextTheme!
|
|
|
|
.displaySmall!
|
2023-04-18 17:36:56 +00:00
|
|
|
.backgroundColor!),
|
|
|
|
title: action.name(context),
|
|
|
|
onClick: () async => await action.onTap(
|
|
|
|
context, dashboardViewModel),
|
|
|
|
textColor: action.isEnabled
|
|
|
|
?.call(dashboardViewModel) ??
|
|
|
|
true
|
|
|
|
? null
|
|
|
|
: Theme.of(context)
|
2023-05-24 20:19:51 -03:00
|
|
|
.accentTextTheme!
|
|
|
|
.displaySmall!
|
2023-04-18 17:36:56 +00:00
|
|
|
.backgroundColor!,
|
|
|
|
),
|
2023-04-14 06:39:08 +02:00
|
|
|
))
|
|
|
|
.toList(),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
));
|
2020-07-06 23:09:03 +03:00
|
|
|
}
|
|
|
|
|
2021-10-01 18:13:10 +03:00
|
|
|
void _setEffects(BuildContext context) async {
|
2020-07-21 20:22:41 +03:00
|
|
|
if (_isEffectsInstalled) {
|
|
|
|
return;
|
|
|
|
}
|
2023-04-16 14:45:35 +01:00
|
|
|
if (dashboardViewModel.shouldShowMarketPlaceInDashboard) {
|
2023-04-18 17:36:56 +00:00
|
|
|
pages.add(Semantics(
|
|
|
|
label: 'Marketplace Page',
|
2023-06-08 02:16:52 +03:00
|
|
|
child: MarketPlacePage(
|
|
|
|
dashboardViewModel: dashboardViewModel,
|
|
|
|
marketPlaceViewModel: getIt.get<MarketPlaceViewModel>(),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
2023-04-16 14:45:35 +01:00
|
|
|
}
|
2023-04-18 17:36:56 +00:00
|
|
|
pages.add(Semantics(label: 'Balance Page', child: balancePage));
|
|
|
|
pages.add(Semantics(
|
|
|
|
label: 'Transactions Page',
|
|
|
|
child: TransactionsPage(dashboardViewModel: dashboardViewModel)));
|
2021-11-02 09:17:24 +00:00
|
|
|
_isEffectsInstalled = true;
|
2022-01-14 00:10:27 +06:00
|
|
|
|
2021-05-11 16:52:48 +03:00
|
|
|
autorun((_) async {
|
2023-04-14 06:39:08 +02:00
|
|
|
if (!dashboardViewModel.isOutdatedElectrumWallet) {
|
2021-05-11 16:52:48 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
await Future<void>.delayed(Duration(seconds: 1));
|
2023-02-27 15:59:20 +02:00
|
|
|
if (context.mounted) {
|
|
|
|
await showPopUp<void>(
|
2021-05-11 16:52:48 +03:00
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return AlertWithOneAction(
|
|
|
|
alertTitle: S.of(context).pre_seed_title,
|
2023-04-14 06:39:08 +02:00
|
|
|
alertContent: S.of(context).outdated_electrum_wallet_description,
|
2021-05-11 16:52:48 +03:00
|
|
|
buttonText: S.of(context).understand,
|
|
|
|
buttonAction: () => Navigator.of(context).pop());
|
|
|
|
});
|
2023-02-27 15:59:20 +02:00
|
|
|
}
|
2021-05-11 16:52:48 +03:00
|
|
|
});
|
|
|
|
|
2023-04-21 18:21:31 +03:00
|
|
|
final sharedPrefs = await SharedPreferences.getInstance();
|
|
|
|
final currentAppVersion =
|
|
|
|
VersionComparator.getExtendedVersionNumber(dashboardViewModel.settingsStore.appVersion);
|
|
|
|
final lastSeenAppVersion = sharedPrefs.getInt(PreferencesKey.lastSeenAppVersion);
|
|
|
|
final isNewInstall = sharedPrefs.getBool(PreferencesKey.isNewInstall);
|
|
|
|
|
|
|
|
if (currentAppVersion != lastSeenAppVersion && !isNewInstall!) {
|
|
|
|
await Future<void>.delayed(Duration(seconds: 1));
|
|
|
|
await showPopUp<void>(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return ReleaseNotesScreen(
|
|
|
|
title: 'Version ${dashboardViewModel.settingsStore.appVersion}');
|
|
|
|
});
|
|
|
|
sharedPrefs.setInt(PreferencesKey.lastSeenAppVersion, currentAppVersion);
|
|
|
|
} else if (isNewInstall!) {
|
|
|
|
sharedPrefs.setInt(PreferencesKey.lastSeenAppVersion, currentAppVersion);
|
|
|
|
}
|
|
|
|
|
2021-11-02 09:17:24 +00:00
|
|
|
var needToPresentYat = false;
|
|
|
|
var isInactive = false;
|
|
|
|
|
2022-10-12 13:09:57 -04:00
|
|
|
_onInactiveSub = rootKey.currentState!.isInactive.listen((inactive) {
|
2021-11-02 09:17:24 +00:00
|
|
|
isInactive = inactive;
|
|
|
|
|
|
|
|
if (needToPresentYat) {
|
|
|
|
Future<void>.delayed(Duration(milliseconds: 500)).then((_) {
|
|
|
|
showPopUp<void>(
|
2022-10-12 13:09:57 -04:00
|
|
|
context: navigatorKey.currentContext!,
|
2023-04-14 06:39:08 +02:00
|
|
|
builder: (_) => YatEmojiId(dashboardViewModel.yatStore.emoji));
|
2021-11-02 09:17:24 +00:00
|
|
|
needToPresentYat = false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-04-14 06:39:08 +02:00
|
|
|
dashboardViewModel.yatStore.emojiIncommingStream.listen((String emoji) {
|
2021-11-02 09:17:24 +00:00
|
|
|
if (!_isEffectsInstalled || emoji.isEmpty) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
needToPresentYat = true;
|
|
|
|
});
|
2020-07-21 20:22:41 +03:00
|
|
|
}
|
2022-03-30 17:57:04 +02:00
|
|
|
}
|