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-08-17 12:28:31 -03:00
|
|
|
import 'package:cake_wallet/src/widgets/gradient_background.dart';
|
|
|
|
import 'package:cake_wallet/themes/extensions/sync_indicator_theme.dart';
|
2023-07-13 16:05:52 +03:00
|
|
|
import 'package:cake_wallet/utils/device_info.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';
|
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';
|
2023-08-17 12:28:31 -03:00
|
|
|
import 'package:cake_wallet/themes/extensions/dashboard_page_theme.dart';
|
|
|
|
import 'package:cake_wallet/themes/extensions/balance_page_theme.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) {
|
2023-08-08 16:09:51 +01:00
|
|
|
return Scaffold(
|
|
|
|
body: LayoutBuilder(
|
|
|
|
builder: (context, constraints) {
|
|
|
|
if (DeviceInfo.instance.isDesktop) {
|
|
|
|
if (constraints.maxWidth > ResponsiveLayoutUtil.kDesktopMaxDashBoardWidthConstraint) {
|
|
|
|
return getIt.get<DesktopSidebarWrapper>();
|
|
|
|
} else {
|
|
|
|
return _DashboardPageView(
|
|
|
|
balancePage: balancePage,
|
|
|
|
dashboardViewModel: dashboardViewModel,
|
|
|
|
addressListViewModel: addressListViewModel,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} else if (ResponsiveLayoutUtil.instance.shouldRenderMobileUI()) {
|
2023-07-13 16:05:52 +03:00
|
|
|
return _DashboardPageView(
|
2023-04-14 06:39:08 +02:00
|
|
|
balancePage: balancePage,
|
|
|
|
dashboardViewModel: dashboardViewModel,
|
|
|
|
addressListViewModel: addressListViewModel,
|
2023-07-13 16:05:52 +03:00
|
|
|
);
|
2023-08-08 16:09:51 +01:00
|
|
|
} else {
|
|
|
|
return getIt.get<DesktopSidebarWrapper>();
|
2023-07-13 16:05:52 +03:00
|
|
|
}
|
2023-08-08 16:09:51 +01:00
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
2023-04-14 06:39:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2023-08-17 12:28:31 -03:00
|
|
|
bool get gradientBackground => true;
|
2020-08-19 20:57:06 +03:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget Function(BuildContext, Widget) get rootWrapper =>
|
2023-08-17 12:28:31 -03:00
|
|
|
(BuildContext context, Widget scaffold) => GradientBackground(scaffold: 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(
|
2023-08-08 16:09:51 +01:00
|
|
|
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) {
|
2023-08-08 16:09:51 +01:00
|
|
|
final menuButton = Image.asset(
|
|
|
|
'assets/images/menu.png',
|
2023-08-18 18:37:17 +03:00
|
|
|
color: Theme.of(context).extension<DashboardPageTheme>()!.pageTitleTextColor,
|
2023-08-08 16:09:51 +01:00
|
|
|
);
|
2020-07-06 23:09:03 +03:00
|
|
|
|
|
|
|
return Container(
|
2023-08-08 16:09:51 +01:00
|
|
|
alignment: Alignment.centerRight,
|
|
|
|
width: 40,
|
|
|
|
child: TextButton(
|
|
|
|
// FIX-ME: Style
|
|
|
|
//highlightColor: Colors.transparent,
|
|
|
|
//splashColor: Colors.transparent,
|
|
|
|
//padding: EdgeInsets.all(0),
|
|
|
|
onPressed: () => onOpenEndDrawer(),
|
|
|
|
child: Semantics(label: S.of(context).wallet_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-08-18 18:37:17 +03:00
|
|
|
|
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-08-08 16:09:51 +01:00
|
|
|
reaction(
|
|
|
|
(_) => dashboardViewModel.shouldShowMarketPlaceInDashboard,
|
|
|
|
(bool value) {
|
|
|
|
if (!dashboardViewModel.shouldShowMarketPlaceInDashboard) {
|
|
|
|
controller.jumpToPage(0);
|
|
|
|
}
|
|
|
|
pages.clear();
|
|
|
|
_isEffectsInstalled = false;
|
|
|
|
_setEffects(context);
|
2023-04-16 14:45:35 +01:00
|
|
|
|
2023-08-08 16:09:51 +01:00
|
|
|
if (value) {
|
|
|
|
controller.jumpToPage(1);
|
|
|
|
} else {
|
|
|
|
controller.jumpToPage(0);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
2021-05-11 16:52:48 +03:00
|
|
|
_setEffects(context);
|
2020-07-21 20:22:41 +03:00
|
|
|
|
|
|
|
return SafeArea(
|
2023-08-08 16:09:51 +01:00
|
|
|
minimum: EdgeInsets.only(bottom: 24),
|
|
|
|
child: Column(
|
|
|
|
mainAxisSize: MainAxisSize.max,
|
|
|
|
children: <Widget>[
|
|
|
|
Expanded(
|
|
|
|
child: Observer(
|
|
|
|
builder: (context) {
|
|
|
|
return PageView.builder(
|
2023-04-16 14:45:35 +01:00
|
|
|
controller: controller,
|
|
|
|
itemCount: pages.length,
|
2023-08-08 16:09:51 +01:00
|
|
|
itemBuilder: (context, index) => pages[index],
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.only(bottom: 24, top: 10),
|
|
|
|
child: Observer(
|
|
|
|
builder: (context) {
|
|
|
|
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,
|
2023-08-17 12:28:31 -03:00
|
|
|
activeDotColor: Theme.of(context)
|
|
|
|
.extension<DashboardPageTheme>()!
|
|
|
|
.indicatorDotTheme
|
|
|
|
.activeIndicatorColor,
|
2023-04-18 17:36:56 +00:00
|
|
|
),
|
2023-08-08 16:09:51 +01:00
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Observer(
|
|
|
|
builder: (_) {
|
2023-04-14 06:39:08 +02:00
|
|
|
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(
|
2023-08-17 12:28:31 -03:00
|
|
|
color: Theme.of(context).extension<BalancePageTheme>()!.cardBorderColor,
|
2023-04-14 06:39:08 +02:00
|
|
|
width: 1,
|
|
|
|
),
|
2023-08-17 12:28:31 -03:00
|
|
|
color:
|
|
|
|
Theme.of(context).extension<SyncIndicatorTheme>()!.syncedBackgroundColor,
|
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-08-08 16:09:51 +01: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-08-17 12:28:31 -03:00
|
|
|
.extension<DashboardPageTheme>()!
|
|
|
|
.mainActionsIconColor
|
2023-04-18 17:36:56 +00:00
|
|
|
: Theme.of(context)
|
2023-08-17 12:28:31 -03:00
|
|
|
.extension<BalancePageTheme>()!
|
|
|
|
.labelTextColor,
|
2023-04-18 17:36:56 +00:00
|
|
|
),
|
2023-08-08 16:09:51 +01:00
|
|
|
title: action.name(context),
|
|
|
|
onClick: () async =>
|
|
|
|
await action.onTap(context, dashboardViewModel),
|
|
|
|
textColor: action.isEnabled?.call(dashboardViewModel) ?? true
|
|
|
|
? null
|
|
|
|
: Theme.of(context)
|
2023-08-17 12:28:31 -03:00
|
|
|
.extension<BalancePageTheme>()!
|
|
|
|
.labelTextColor,
|
2023-08-08 16:09:51 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
2023-04-14 06:39:08 +02:00
|
|
|
.toList(),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
2023-08-08 16:09:51 +01:00
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
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-08-08 16:09:51 +01:00
|
|
|
pages.add(
|
|
|
|
Semantics(
|
2023-07-11 18:21:59 -03:00
|
|
|
label: S.of(context).market_place,
|
2023-06-08 02:16:52 +03:00
|
|
|
child: MarketPlacePage(
|
2023-07-13 16:05:52 +03:00
|
|
|
dashboardViewModel: dashboardViewModel,
|
2023-06-08 02:16:52 +03:00
|
|
|
marketPlaceViewModel: getIt.get<MarketPlaceViewModel>(),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
2023-04-16 14:45:35 +01:00
|
|
|
}
|
2023-07-11 18:21:59 -03:00
|
|
|
pages.add(Semantics(label: S.of(context).balance_page, child: balancePage));
|
2023-08-08 16:09:51 +01:00
|
|
|
pages.add(
|
|
|
|
Semantics(
|
2023-07-11 18:21:59 -03:00
|
|
|
label: S.of(context).settings_transactions,
|
2023-08-08 16:09:51 +01:00
|
|
|
child: TransactionsPage(dashboardViewModel: dashboardViewModel),
|
|
|
|
),
|
|
|
|
);
|
2021-11-02 09:17:24 +00:00
|
|
|
_isEffectsInstalled = true;
|
2022-01-14 00:10:27 +06:00
|
|
|
|
2023-08-08 16:09:51 +01:00
|
|
|
autorun(
|
|
|
|
(_) async {
|
|
|
|
if (!dashboardViewModel.isOutdatedElectrumWallet) {
|
|
|
|
return;
|
|
|
|
}
|
2021-05-11 16:52:48 +03:00
|
|
|
|
2023-08-08 16:09:51 +01:00
|
|
|
await Future<void>.delayed(Duration(seconds: 1));
|
|
|
|
if (context.mounted) {
|
|
|
|
await showPopUp<void>(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return AlertWithOneAction(
|
2021-05-11 16:52:48 +03:00
|
|
|
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,
|
2023-08-08 16:09:51 +01:00
|
|
|
buttonAction: () => Navigator.of(context).pop(),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
2021-05-11 16:52:48 +03:00
|
|
|
|
2023-08-07 14:43:04 +03:00
|
|
|
_showReleaseNotesPopup(context);
|
2023-04-21 18:21:31 +03:00
|
|
|
|
2021-11-02 09:17:24 +00:00
|
|
|
var needToPresentYat = false;
|
|
|
|
var isInactive = false;
|
|
|
|
|
2023-08-08 16:09:51 +01:00
|
|
|
_onInactiveSub = rootKey.currentState!.isInactive.listen(
|
|
|
|
(inactive) {
|
|
|
|
isInactive = inactive;
|
2021-11-02 09:17:24 +00:00
|
|
|
|
2023-08-08 16:09:51 +01:00
|
|
|
if (needToPresentYat) {
|
|
|
|
Future<void>.delayed(Duration(milliseconds: 500)).then(
|
|
|
|
(_) {
|
|
|
|
showPopUp<void>(
|
|
|
|
context: navigatorKey.currentContext!,
|
|
|
|
builder: (_) => YatEmojiId(dashboardViewModel.yatStore.emoji),
|
|
|
|
);
|
|
|
|
needToPresentYat = false;
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
2021-11-02 09:17:24 +00:00
|
|
|
|
2023-08-08 16:09:51 +01:00
|
|
|
dashboardViewModel.yatStore.emojiIncommingStream.listen(
|
|
|
|
(String emoji) {
|
|
|
|
if (!_isEffectsInstalled || emoji.isEmpty) {
|
|
|
|
return;
|
|
|
|
}
|
2021-11-02 09:17:24 +00:00
|
|
|
|
2023-08-08 16:09:51 +01:00
|
|
|
needToPresentYat = true;
|
|
|
|
},
|
|
|
|
);
|
2020-07-21 20:22:41 +03:00
|
|
|
}
|
2023-08-07 14:43:04 +03:00
|
|
|
|
|
|
|
void _showReleaseNotesPopup(BuildContext context) async {
|
|
|
|
final sharedPrefs = await SharedPreferences.getInstance();
|
|
|
|
final currentAppVersion =
|
2023-08-08 16:09:51 +01:00
|
|
|
VersionComparator.getExtendedVersionNumber(dashboardViewModel.settingsStore.appVersion);
|
2023-08-07 14:43:04 +03:00
|
|
|
final lastSeenAppVersion = sharedPrefs.getInt(PreferencesKey.lastSeenAppVersion);
|
|
|
|
final isNewInstall = sharedPrefs.getBool(PreferencesKey.isNewInstall);
|
|
|
|
|
|
|
|
if (currentAppVersion != lastSeenAppVersion && !isNewInstall!) {
|
2023-08-08 16:09:51 +01:00
|
|
|
Future<void>.delayed(
|
|
|
|
Duration(seconds: 1),
|
|
|
|
() {
|
|
|
|
showPopUp<void>(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return ReleaseNotesScreen(
|
|
|
|
title: 'Version ${dashboardViewModel.settingsStore.appVersion}',
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
2023-08-07 14:43:04 +03:00
|
|
|
|
|
|
|
sharedPrefs.setInt(PreferencesKey.lastSeenAppVersion, currentAppVersion);
|
|
|
|
} else if (isNewInstall!) {
|
|
|
|
sharedPrefs.setInt(PreferencesKey.lastSeenAppVersion, currentAppVersion);
|
|
|
|
}
|
|
|
|
}
|
2022-03-30 17:57:04 +02:00
|
|
|
}
|