From fff0d8129490a679be192f7bb4f86ca41ef5e455 Mon Sep 17 00:00:00 2001 From: M Date: Thu, 30 Dec 2021 21:14:48 +0200 Subject: [PATCH] Fixes for wallet menu --- lib/src/screens/dashboard/wallet_menu.dart | 101 +++++++----------- .../screens/dashboard/wallet_menu_item.dart | 4 +- 2 files changed, 44 insertions(+), 61 deletions(-) diff --git a/lib/src/screens/dashboard/wallet_menu.dart b/lib/src/screens/dashboard/wallet_menu.dart index 52dde56dc..fdcb34bf7 100644 --- a/lib/src/screens/dashboard/wallet_menu.dart +++ b/lib/src/screens/dashboard/wallet_menu.dart @@ -16,43 +16,71 @@ class WalletMenu { WalletMenuItem( title: S.current.reconnect, image: Image.asset('assets/images/reconnect_menu.png', - height: 16, width: 16)), + height: 16, width: 16), + handler: () => _presentReconnectAlert(context)), if (hasRescan) WalletMenuItem( title: S.current.rescan, image: Image.asset('assets/images/filter_icon.png', - height: 16, width: 16, color: Palette.darkBlue)), + height: 16, width: 16, color: Palette.darkBlue), + handler: () => Navigator.of(context).pushNamed(Routes.rescan)), WalletMenuItem( title: S.current.wallets, image: Image.asset('assets/images/wallet_menu.png', - height: 16, width: 16)), + height: 16, width: 16), + handler: () => Navigator.of(context).pushNamed(Routes.walletList)), WalletMenuItem( title: S.current.nodes, image: Image.asset('assets/images/nodes_menu.png', - height: 16, width: 16)), + height: 16, width: 16), + handler: () => Navigator.of(context).pushNamed(Routes.nodeList)), WalletMenuItem( title: S.current.show_keys, image: - Image.asset('assets/images/key_menu.png', height: 16, width: 16)), + 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) { + auth.close(); + Navigator.of(auth.context).pushNamed(Routes.showKeys); + } + }); + }), WalletMenuItem( title: S.current.address_book_menu, image: Image.asset('assets/images/open_book_menu.png', - height: 16, width: 16)), + height: 16, width: 16), + handler: () => Navigator.of(context).pushNamed(Routes.addressBook)), if(!isMoneroOnly) WalletMenuItem( title: S.current.backup, image: Image.asset('assets/images/restore_wallet.png', - height: 16, - width: 16, - color: Palette.darkBlue)), + height: 16, + width: 16, + color: Palette.darkBlue), + handler: () { + Navigator + .of(context) + .pushNamed( + Routes.auth, + arguments: (bool isAuthenticatedSuccessfully, AuthPageState auth) { + if (isAuthenticatedSuccessfully) { + auth.close(); + Navigator.of(auth.context).pushNamed(Routes.backup); + } + }); + }), WalletMenuItem( title: S.current.settings_title, image: Image.asset('assets/images/settings_menu.png', - height: 16, width: 16)), + height: 16, width: 16), + handler: () => Navigator.of(context).pushNamed(Routes.settings)), WalletMenuItem( title: S.current.settings_support, image: Image.asset('assets/images/question_mark.png', - height: 16, width: 16, color: Palette.darkBlue)), + height: 16, width: 16, color: Palette.darkBlue), + handler: () => Navigator.of(context).pushNamed(Routes.support)), ]); } @@ -62,55 +90,8 @@ class WalletMenu { final bool hasRescan; void action(int index) { - var indx = index; - - if (index > 0 && !hasRescan) { - indx += 1; - } - - switch (indx) { - case 0: - _presentReconnectAlert(context); - break; - case 1: - Navigator.of(context).pushNamed(Routes.rescan); - break; - case 2: - Navigator.of(context).pushNamed(Routes.walletList); - break; - case 3: - Navigator.of(context).pushNamed(Routes.nodeList); - break; - case 4: - Navigator.of(context).pushNamed(Routes.auth, - arguments: (bool isAuthenticatedSuccessfully, AuthPageState auth) { - if (isAuthenticatedSuccessfully) { - auth.close(); - Navigator.of(auth.context).pushNamed(Routes.showKeys); - } - }); - break; - case 5: - Navigator.of(context).pushNamed(Routes.addressBook); - break; - case 6: - Navigator.of(context).pushNamed(Routes.auth, - arguments: (bool isAuthenticatedSuccessfully, AuthPageState auth) { - if (isAuthenticatedSuccessfully) { - auth.close(); - Navigator.of(auth.context).pushNamed(Routes.backup); - } - }); - break; - case 7: - Navigator.of(context).pushNamed(Routes.settings); - break; - case 8: - Navigator.of(context).pushNamed(Routes.support); - break; - default: - break; - } + final item = items[index]; + item?.handler(); } Future _presentReconnectAlert(BuildContext context) async { diff --git a/lib/src/screens/dashboard/wallet_menu_item.dart b/lib/src/screens/dashboard/wallet_menu_item.dart index de2ea465a..3beeb643a 100644 --- a/lib/src/screens/dashboard/wallet_menu_item.dart +++ b/lib/src/screens/dashboard/wallet_menu_item.dart @@ -3,8 +3,10 @@ import 'package:flutter/material.dart'; class WalletMenuItem { WalletMenuItem({ @required this.title, - @required this.image}); + @required this.image, + @required this.handler}); final String title; final Image image; + final void Function() handler; } \ No newline at end of file