diff --git a/lib/entities/desktop_dropdown_item.dart b/lib/entities/desktop_dropdown_item.dart new file mode 100644 index 000000000..235aa6d55 --- /dev/null +++ b/lib/entities/desktop_dropdown_item.dart @@ -0,0 +1,20 @@ +import 'package:cw_core/wallet_type.dart'; + +abstract class DesktopDropdownItem { + + final String name; + final WalletType type; + final bool isCurrent; + final dynamic key; + final bool isEnabled; + final String? optionName; + + DesktopDropdownItem({this.name = '', this.type = WalletType.none, this.isCurrent = false, this.key, this.isEnabled = true, this.optionName}); +} + +class DropdownOption extends DesktopDropdownItem { + DropdownOption({required this.name, required this.optionName}); + + final String name; + final String optionName; +} \ No newline at end of file diff --git a/lib/reactions/on_authentication_state_change.dart b/lib/reactions/on_authentication_state_change.dart index f7078a45e..0adea5128 100644 --- a/lib/reactions/on_authentication_state_change.dart +++ b/lib/reactions/on_authentication_state_change.dart @@ -1,5 +1,4 @@ import 'package:cake_wallet/routes.dart'; -import 'package:cake_wallet/src/screens/dashboard/desktop_widgets/desktop_dashboard_view.dart'; import 'package:flutter/widgets.dart'; import 'package:mobx/mobx.dart'; import 'package:cake_wallet/entities/load_current_wallet.dart'; diff --git a/lib/src/screens/dashboard/desktop_dashboard_page.dart b/lib/src/screens/dashboard/desktop_dashboard_page.dart index f79d2f9e2..c2b7285b7 100644 --- a/lib/src/screens/dashboard/desktop_dashboard_page.dart +++ b/lib/src/screens/dashboard/desktop_dashboard_page.dart @@ -24,6 +24,7 @@ class DesktopDashboardPage extends StatelessWidget { final WalletAddressListViewModel addressListViewModel; static final GlobalKey desktopKey = GlobalKey(); + static final GlobalKey kex = GlobalKey(); bool _isEffectsInstalled = false; StreamSubscription? _onInactiveSub; diff --git a/lib/src/screens/dashboard/desktop_widgets/desktop_wallet_selection_dropdown.dart b/lib/src/screens/dashboard/desktop_widgets/desktop_wallet_selection_dropdown.dart index fe98a0af9..5c5cd557e 100644 --- a/lib/src/screens/dashboard/desktop_widgets/desktop_wallet_selection_dropdown.dart +++ b/lib/src/screens/dashboard/desktop_widgets/desktop_wallet_selection_dropdown.dart @@ -1,4 +1,5 @@ import 'package:another_flushbar/flushbar.dart'; +import 'package:cake_wallet/entities/desktop_dropdown_item.dart'; import 'package:cake_wallet/generated/i18n.dart'; import 'package:cake_wallet/routes.dart'; import 'package:cake_wallet/src/screens/auth/auth_page.dart'; @@ -7,6 +8,7 @@ import 'package:cake_wallet/utils/show_bar.dart'; import 'package:cake_wallet/utils/show_pop_up.dart'; import 'package:cake_wallet/view_model/wallet_list/wallet_list_item.dart'; import 'package:cake_wallet/view_model/wallet_list/wallet_list_view_model.dart'; +import 'package:cake_wallet/wallet_type_utils.dart'; import 'package:cw_core/wallet_type.dart'; import 'package:flutter/material.dart'; @@ -33,8 +35,8 @@ class _DesktopWalletSelectionDropDownState extends State( - items: widget.walletListViewModel.wallets + return DropdownButton( + items: widget.walletListViewModel.dropdownItems .map((wallet) => DropdownMenuItem( child: ConstrainedBox( constraints: BoxConstraints(maxWidth: 500), @@ -47,7 +49,12 @@ class _DesktopWalletSelectionDropDownState extends State( context: context, builder: (dialogContext) { @@ -61,25 +68,25 @@ class _DesktopWalletSelectionDropDownState extends State widget.walletListViewModel.wallets + selectedItemBuilder: (context) => widget.walletListViewModel.dropdownItems .map((wallet) => ConstrainedBox( constraints: BoxConstraints(maxWidth: 500), child: walletListItemTile(wallet), )) .toList(), - value: widget.walletListViewModel.wallets.firstWhere((element) => element.isCurrent), + value: widget.walletListViewModel.dropdownItems.firstWhere((element) => element.isCurrent), underline: const SizedBox(), focusColor: Colors.transparent, ); } - Widget walletListItemTile(WalletListItem wallet) { + Widget walletListItemTile(DesktopDropdownItem wallet) { return Container( height: tileHeight, padding: EdgeInsets.symmetric(horizontal: 20), @@ -152,6 +159,32 @@ class _DesktopWalletSelectionDropDownState extends State(text, duration: null)..show(context); } diff --git a/lib/src/screens/settings/desktop_settings/dashboard_settings_page.dart b/lib/src/screens/settings/desktop_settings/dashboard_settings_page.dart index 69cd2ad27..f4312aba4 100644 --- a/lib/src/screens/settings/desktop_settings/dashboard_settings_page.dart +++ b/lib/src/screens/settings/desktop_settings/dashboard_settings_page.dart @@ -16,7 +16,8 @@ class DesktopSettingsPage extends StatefulWidget { } class _DesktopSettingsPageState extends State { - final int itemCount = SettingActions.all.length; + final List _allItems = []; + int? currentPage; void _onItemChange(int index) { @@ -25,6 +26,13 @@ class _DesktopSettingsPageState extends State { }); } + @override + void initState() { + final allActions = List.from(SettingActions.all); + allActions.remove(SettingActions.walletSettingAction); + _allItems.addAll(allActions); super.initState(); + } + @override Widget build(BuildContext context) { return Scaffold( @@ -48,8 +56,8 @@ class _DesktopSettingsPageState extends State { child: ListView.separated( padding: EdgeInsets.only(top: 0), itemBuilder: (_, index) { - final item = SettingActions.all[index]; - final isLastTile = index == itemCount; + final item = _allItems[index]; + final isLastTile = index == _allItems.length - 1; return SettingActionButton( isLastTile: isLastTile, selectionActive: currentPage != null, @@ -71,7 +79,7 @@ class _DesktopSettingsPageState extends State { height: 1, color: Theme.of(context).primaryTextTheme.caption!.decorationColor!, ), - itemCount: itemCount, + itemCount: _allItems.length, ), ), ], diff --git a/lib/src/screens/wallet_list/wallet_list_page.dart b/lib/src/screens/wallet_list/wallet_list_page.dart index 235b59fbc..8acc14d2f 100644 --- a/lib/src/screens/wallet_list/wallet_list_page.dart +++ b/lib/src/screens/wallet_list/wallet_list_page.dart @@ -234,7 +234,7 @@ class WalletListBodyState extends State { auth.hideProgressText(); auth.close(); WidgetsBinding.instance.addPostFrameCallback((_) { - navigatorKey.currentState!.pushNamedAndRemoveUntil(Routes.dashboard, (route) => false); + Navigator.of(context).pop(); }); } catch (e) { auth.changeProcessText( @@ -246,7 +246,7 @@ class WalletListBodyState extends State { changeProcessText(S.of(context).wallet_list_loading_wallet(wallet.name)); await widget.walletListViewModel.loadWallet(wallet); hideProgressText(); - navigatorKey.currentState!.pushNamedAndRemoveUntil(Routes.dashboard, (route) => false); + Navigator.of(context).pop(); } catch (e) { changeProcessText(S.of(context).wallet_list_failed_to_load(wallet.name, e.toString())); } diff --git a/lib/view_model/wallet_list/wallet_list_item.dart b/lib/view_model/wallet_list/wallet_list_item.dart index af30b9bea..ec03bdb64 100644 --- a/lib/view_model/wallet_list/wallet_list_item.dart +++ b/lib/view_model/wallet_list/wallet_list_item.dart @@ -1,17 +1,18 @@ -import 'package:flutter/foundation.dart'; +import 'package:cake_wallet/entities/desktop_dropdown_item.dart'; import 'package:cw_core/wallet_type.dart'; -class WalletListItem { - const WalletListItem( +class WalletListItem extends DesktopDropdownItem { + WalletListItem( {required this.name, required this.type, required this.key, this.isCurrent = false, - this.isEnabled = true}); + this.isEnabled = true, this.optionName = '',}); final String name; final WalletType type; final bool isCurrent; final dynamic key; final bool isEnabled; + final String optionName; } diff --git a/lib/view_model/wallet_list/wallet_list_view_model.dart b/lib/view_model/wallet_list/wallet_list_view_model.dart index 6d63675ba..9c89da1c7 100644 --- a/lib/view_model/wallet_list/wallet_list_view_model.dart +++ b/lib/view_model/wallet_list/wallet_list_view_model.dart @@ -1,5 +1,7 @@ import 'package:cake_wallet/core/auth_service.dart'; import 'package:cake_wallet/core/wallet_loading_service.dart'; +import 'package:cake_wallet/entities/desktop_dropdown_item.dart'; +import 'package:cake_wallet/generated/i18n.dart'; import 'package:hive/hive.dart'; import 'package:mobx/mobx.dart'; import 'package:cake_wallet/di.dart'; @@ -27,6 +29,21 @@ abstract class WalletListViewModelBase with Store { @observable ObservableList wallets; + @computed + ObservableList get dropdownItems { + final items = []; + + for (final wallet in wallets) { + items.add(wallet); + } + items.addAll([ + DropdownOption(name: S.current.create_new, optionName: "create_wallet"), + DropdownOption(name: S.current.restore_wallet, optionName: "restore_wallet"), + ]); + + return ObservableList.of(items); + } + final AppStore _appStore; final Box _walletInfoSource; final WalletLoadingService _walletLoadingService;