import 'package:cake_wallet/generated/i18n.dart'; import 'package:cake_wallet/routes.dart'; import 'package:cake_wallet/view_model/dashboard/dashboard_view_model.dart'; import 'package:flutter/material.dart'; class MainActions { final String Function(BuildContext context) name; final String image; final bool Function(DashboardViewModel viewModel)? isEnabled; final bool Function(DashboardViewModel viewModel)? canShow; final Future Function( BuildContext context, DashboardViewModel viewModel) onTap; MainActions._({ required this.name, required this.image, this.isEnabled, this.canShow, required this.onTap, }); static List all = [ showWalletsAction, receiveAction, exchangeAction, sendAction, tradeAction, ]; static MainActions showWalletsAction = MainActions._( name: (context) => S.of(context).wallets, image: 'assets/images/wallet_new.png', onTap: (BuildContext context, DashboardViewModel viewModel) async { Navigator.pushNamed(context, Routes.walletList); }, ); static MainActions receiveAction = MainActions._( name: (context) => S.of(context).receive, image: 'assets/images/received.png', onTap: (BuildContext context, DashboardViewModel viewModel) async { Navigator.pushNamed(context, Routes.addressPage); }, ); static MainActions exchangeAction = MainActions._( name: (context) => S.of(context).exchange, image: 'assets/images/transfer.png', isEnabled: (viewModel) => viewModel.isEnabledExchangeAction, canShow: (viewModel) => viewModel.hasExchangeAction, onTap: (BuildContext context, DashboardViewModel viewModel) async { if (viewModel.isEnabledExchangeAction) { await Navigator.of(context).pushNamed(Routes.exchange); } }, ); static MainActions sendAction = MainActions._( name: (context) => S.of(context).send, image: 'assets/images/upload.png', onTap: (BuildContext context, DashboardViewModel viewModel) async { Navigator.pushNamed(context, Routes.send); }, ); static MainActions tradeAction = MainActions._( name: (context) => '${S.of(context).buy}/${S.of(context).sell}', image: 'assets/images/buy_sell.png', isEnabled: (viewModel) => viewModel.isEnabledTradeAction, canShow: (viewModel) => viewModel.hasTradeAction, onTap: (BuildContext context, DashboardViewModel viewModel) async { if (!viewModel.isEnabledTradeAction) return; await Navigator.of(context).pushNamed(Routes.buySellPage, arguments: false); }, ); }