| 1 | import 'package:cake_wallet/generated/i18n.dart'; |
| 2 | import 'package:cake_wallet/routes.dart'; |
| 3 | import 'package:cake_wallet/view_model/dashboard/dashboard_view_model.dart'; |
| 4 | import 'package:flutter/material.dart'; |
| 5 | |
| 6 | class MainActions { |
| 7 | final String Function(BuildContext context) name; |
| 8 | final String image; |
| 9 | final Key key; |
| 10 | final bool Function(DashboardViewModel viewModel)? isEnabled; |
| 11 | final bool Function(DashboardViewModel viewModel)? canShow; |
| 12 | final Future<void> Function(BuildContext context, DashboardViewModel viewModel) onTap; |
| 13 | |
| 14 | MainActions._({ |
| 15 | required this.name, |
| 16 | required this.image, |
| 17 | required this.key, |
| 18 | this.isEnabled, |
| 19 | this.canShow, |
| 20 | required this.onTap, |
| 21 | }); |
| 22 | |
| 23 | static List<MainActions> all = [ |
| 24 | showWalletsAction, |
| 25 | receiveAction, |
| 26 | swapAction, |
| 27 | sendAction, |
| 28 | tradeAction, |
| 29 | ]; |
| 30 | |
| 31 | static MainActions showWalletsAction = MainActions._( |
| 32 | name: (context) => S.of(context).wallets, |
| 33 | image: 'assets/images/wallet_icon.png', |
| 34 | key: ValueKey('dashboard_page__wallet_list_button_key'), |
| 35 | onTap: (BuildContext context, DashboardViewModel viewModel) async { |
| 36 | Navigator.pushNamed( |
| 37 | context, |
| 38 | Routes.walletList, |
| 39 | arguments: (BuildContext context) => |
| 40 | Navigator.of(context).pushNamedAndRemoveUntil(Routes.dashboard, (route) => false), |
| 41 | ); |
| 42 | }, |
| 43 | ); |
| 44 | |
| 45 | static MainActions receiveAction = MainActions._( |
| 46 | name: (context) => S.of(context).receive, |
| 47 | image: 'assets/images/receive.png', |
| 48 | key: ValueKey('dashboard_page_receive_action_button_key'), |
| 49 | onTap: (BuildContext context, DashboardViewModel viewModel) async { |
| 50 | Navigator.pushNamed(context, Routes.addressPage); |
| 51 | }, |
| 52 | ); |
| 53 | |
| 54 | static MainActions swapAction = MainActions._( |
| 55 | name: (context) => S.of(context).swap, |
| 56 | image: 'assets/images/swap.png', |
| 57 | key: ValueKey('dashboard_page_swap_action_button_key'), |
| 58 | isEnabled: (viewModel) => viewModel.isEnabledSwapAction, |
| 59 | canShow: (viewModel) => viewModel.hasSwapAction, |
| 60 | onTap: (BuildContext context, DashboardViewModel viewModel) async { |
| 61 | if (viewModel.isEnabledSwapAction) { |
| 62 | await Navigator.of(context).pushNamed(Routes.exchange); |
| 63 | } |
| 64 | }, |
| 65 | ); |
| 66 | |
| 67 | static MainActions sendAction = MainActions._( |
| 68 | name: (context) => S.of(context).send, |
| 69 | image: 'assets/images/send2.png', |
| 70 | key: ValueKey('dashboard_page_send_action_button_key'), |
| 71 | isEnabled: (viewModel) => viewModel.canSend, |
| 72 | onTap: (BuildContext context, DashboardViewModel viewModel) async { |
| 73 | Navigator.pushNamed(context, Routes.send); |
| 74 | }, |
| 75 | ); |
| 76 | |
| 77 | static MainActions tradeAction = MainActions._( |
| 78 | name: (context) => S.of(context).buy, |
| 79 | image: 'assets/images/buy.png', |
| 80 | key: ValueKey('dashboard_page_buy_action_button_key'), |
| 81 | isEnabled: (viewModel) => viewModel.isEnabledTradeAction, |
| 82 | canShow: (viewModel) => viewModel.hasTradeAction, |
| 83 | onTap: (BuildContext context, DashboardViewModel viewModel) async { |
| 84 | if (!viewModel.isEnabledTradeAction) return; |
| 85 | await Navigator.of(context).pushNamed(Routes.buySellPage, arguments: false); |
| 86 | }, |
| 87 | ); |
| 88 | } |