cake_wallet/lib/entities/main_actions.dart
2024-12-26 22:05:00 -05:00

78 lines
No EOL
2.5 KiB
Dart

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<void> Function(
BuildContext context, DashboardViewModel viewModel) onTap;
MainActions._({
required this.name,
required this.image,
this.isEnabled,
this.canShow,
required this.onTap,
});
static List<MainActions> all = [
showWalletsAction,
receiveAction,
swapAction,
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 swapAction = MainActions._(
name: (context) => S.of(context).swap,
image: 'assets/images/transfer.png',
isEnabled: (viewModel) => viewModel.isEnabledSwapAction,
canShow: (viewModel) => viewModel.hasSwapAction,
onTap: (BuildContext context, DashboardViewModel viewModel) async {
if (viewModel.isEnabledSwapAction) {
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).exchange,
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);
},
);
}