2021-01-18 20:52:12 +00:00
|
|
|
import 'package:cake_wallet/palette.dart';
|
2020-10-22 16:50:53 +00:00
|
|
|
import 'package:cake_wallet/src/screens/dashboard/wallet_menu_item.dart';
|
2020-09-25 15:32:44 +00:00
|
|
|
import 'package:cake_wallet/utils/show_pop_up.dart';
|
2020-01-04 19:31:52 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:cake_wallet/routes.dart';
|
|
|
|
import 'package:cake_wallet/generated/i18n.dart';
|
2020-01-08 12:26:34 +00:00
|
|
|
import 'package:cake_wallet/src/screens/auth/auth_page.dart';
|
2020-05-04 20:12:36 +00:00
|
|
|
import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart';
|
2021-12-30 17:20:00 +00:00
|
|
|
import 'package:cake_wallet/wallet_type_utils.dart';
|
2020-01-04 19:31:52 +00:00
|
|
|
|
2020-08-27 16:54:34 +00:00
|
|
|
// FIXME: terrible design
|
|
|
|
|
2020-01-04 19:31:52 +00:00
|
|
|
class WalletMenu {
|
2020-12-16 19:16:47 +00:00
|
|
|
WalletMenu(this.context, this.reconnect, this.hasRescan) : items = [] {
|
|
|
|
items.addAll([
|
|
|
|
WalletMenuItem(
|
|
|
|
title: S.current.reconnect,
|
|
|
|
image: Image.asset('assets/images/reconnect_menu.png',
|
2021-12-30 19:14:48 +00:00
|
|
|
height: 16, width: 16),
|
|
|
|
handler: () => _presentReconnectAlert(context)),
|
2020-12-16 19:16:47 +00:00
|
|
|
if (hasRescan)
|
|
|
|
WalletMenuItem(
|
|
|
|
title: S.current.rescan,
|
|
|
|
image: Image.asset('assets/images/filter_icon.png',
|
2021-12-30 19:14:48 +00:00
|
|
|
height: 16, width: 16, color: Palette.darkBlue),
|
|
|
|
handler: () => Navigator.of(context).pushNamed(Routes.rescan)),
|
2020-12-16 19:16:47 +00:00
|
|
|
WalletMenuItem(
|
|
|
|
title: S.current.wallets,
|
|
|
|
image: Image.asset('assets/images/wallet_menu.png',
|
2021-12-30 19:14:48 +00:00
|
|
|
height: 16, width: 16),
|
|
|
|
handler: () => Navigator.of(context).pushNamed(Routes.walletList)),
|
2020-12-16 19:16:47 +00:00
|
|
|
WalletMenuItem(
|
|
|
|
title: S.current.nodes,
|
|
|
|
image: Image.asset('assets/images/nodes_menu.png',
|
2021-12-30 19:14:48 +00:00
|
|
|
height: 16, width: 16),
|
|
|
|
handler: () => Navigator.of(context).pushNamed(Routes.nodeList)),
|
2020-12-16 19:16:47 +00:00
|
|
|
WalletMenuItem(
|
|
|
|
title: S.current.show_keys,
|
|
|
|
image:
|
2021-12-30 19:14:48 +00:00
|
|
|
Image.asset('assets/images/key_menu.png', height: 16, width: 16),
|
|
|
|
handler: () {
|
|
|
|
Navigator.of(context).pushNamed(Routes.auth,
|
|
|
|
arguments: (bool isAuthenticatedSuccessfully, AuthPageState auth) {
|
|
|
|
if (isAuthenticatedSuccessfully) {
|
2022-10-26 18:13:44 +00:00
|
|
|
auth.close(route: Routes.showKeys);
|
2021-12-30 19:14:48 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}),
|
2020-12-16 19:16:47 +00:00
|
|
|
WalletMenuItem(
|
|
|
|
title: S.current.address_book_menu,
|
|
|
|
image: Image.asset('assets/images/open_book_menu.png',
|
2021-12-30 19:14:48 +00:00
|
|
|
height: 16, width: 16),
|
|
|
|
handler: () => Navigator.of(context).pushNamed(Routes.addressBook)),
|
2022-10-26 19:28:27 +00:00
|
|
|
WalletMenuItem(
|
|
|
|
title: S.current.backup,
|
|
|
|
image: Image.asset('assets/images/restore_wallet.png',
|
|
|
|
height: 16,
|
|
|
|
width: 16,
|
|
|
|
color: Palette.darkBlue),
|
|
|
|
handler: () {
|
|
|
|
Navigator.of(context).pushNamed(
|
|
|
|
Routes.auth,
|
|
|
|
arguments: (bool isAuthenticatedSuccessfully, AuthPageState auth) {
|
|
|
|
if (isAuthenticatedSuccessfully) {
|
|
|
|
auth.close(route:Routes.backup);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}),
|
2020-12-16 19:16:47 +00:00
|
|
|
WalletMenuItem(
|
|
|
|
title: S.current.settings_title,
|
|
|
|
image: Image.asset('assets/images/settings_menu.png',
|
2021-12-30 19:14:48 +00:00
|
|
|
height: 16, width: 16),
|
|
|
|
handler: () => Navigator.of(context).pushNamed(Routes.settings)),
|
2021-02-25 18:25:52 +00:00
|
|
|
WalletMenuItem(
|
|
|
|
title: S.current.settings_support,
|
|
|
|
image: Image.asset('assets/images/question_mark.png',
|
2021-12-30 19:14:48 +00:00
|
|
|
height: 16, width: 16, color: Palette.darkBlue),
|
|
|
|
handler: () => Navigator.of(context).pushNamed(Routes.support)),
|
2020-12-16 19:16:47 +00:00
|
|
|
]);
|
|
|
|
}
|
2020-01-04 19:31:52 +00:00
|
|
|
|
2020-12-16 19:16:47 +00:00
|
|
|
final List<WalletMenuItem> items;
|
2020-01-08 12:26:34 +00:00
|
|
|
final BuildContext context;
|
2020-08-27 16:54:34 +00:00
|
|
|
final Future<void> Function() reconnect;
|
2020-12-16 19:16:47 +00:00
|
|
|
final bool hasRescan;
|
2020-01-04 19:31:52 +00:00
|
|
|
|
|
|
|
void action(int index) {
|
2021-12-30 19:14:48 +00:00
|
|
|
final item = items[index];
|
|
|
|
item?.handler();
|
2020-01-04 19:31:52 +00:00
|
|
|
}
|
|
|
|
|
2020-01-08 12:26:34 +00:00
|
|
|
Future<void> _presentReconnectAlert(BuildContext context) async {
|
2020-09-25 15:32:44 +00:00
|
|
|
await showPopUp<void>(
|
2020-01-04 19:31:52 +00:00
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
2020-05-04 20:12:36 +00:00
|
|
|
return AlertWithTwoActions(
|
|
|
|
alertTitle: S.of(context).reconnection,
|
|
|
|
alertContent: S.of(context).reconnect_alert_text,
|
2020-09-14 19:07:44 +00:00
|
|
|
rightButtonText: S.of(context).ok,
|
|
|
|
leftButtonText: S.of(context).cancel,
|
|
|
|
actionRightButton: () async {
|
2020-05-04 20:12:36 +00:00
|
|
|
Navigator.of(context).pop();
|
2020-10-01 16:46:23 +00:00
|
|
|
await reconnect?.call();
|
2020-05-04 20:12:36 +00:00
|
|
|
},
|
2020-09-14 19:07:44 +00:00
|
|
|
actionLeftButton: () => Navigator.of(context).pop());
|
2020-01-04 19:31:52 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|