mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-22 02:34:59 +00:00
Add create and restore wallet options to dropdown menu
This commit is contained in:
parent
75d52794f4
commit
4bc81242fc
8 changed files with 97 additions and 18 deletions
20
lib/entities/desktop_dropdown_item.dart
Normal file
20
lib/entities/desktop_dropdown_item.dart
Normal file
|
@ -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;
|
||||
}
|
|
@ -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';
|
||||
|
|
|
@ -24,6 +24,7 @@ class DesktopDashboardPage extends StatelessWidget {
|
|||
final WalletAddressListViewModel addressListViewModel;
|
||||
|
||||
static final GlobalKey<NavigatorState> desktopKey = GlobalKey<NavigatorState>();
|
||||
static final GlobalKey kex = GlobalKey();
|
||||
|
||||
bool _isEffectsInstalled = false;
|
||||
StreamSubscription<bool>? _onInactiveSub;
|
||||
|
|
|
@ -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<DesktopWalletSelectionD
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final themeData = Theme.of(context);
|
||||
return DropdownButton<WalletListItem>(
|
||||
items: widget.walletListViewModel.wallets
|
||||
return DropdownButton<DesktopDropdownItem>(
|
||||
items: widget.walletListViewModel.dropdownItems
|
||||
.map((wallet) => DropdownMenuItem(
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(maxWidth: 500),
|
||||
|
@ -47,7 +49,12 @@ class _DesktopWalletSelectionDropDownState extends State<DesktopWalletSelectionD
|
|||
if (selectedWallet!.isCurrent || !selectedWallet.isEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if(selectedWallet is DropdownOption){
|
||||
_handleCreateOption(selectedWallet);
|
||||
|
||||
return;
|
||||
}
|
||||
final confirmed = await showPopUp<bool>(
|
||||
context: context,
|
||||
builder: (dialogContext) {
|
||||
|
@ -61,25 +68,25 @@ class _DesktopWalletSelectionDropDownState extends State<DesktopWalletSelectionD
|
|||
}) ??
|
||||
false;
|
||||
|
||||
if (confirmed) {
|
||||
if (confirmed && selectedWallet is WalletListItem) {
|
||||
await _loadWallet(selectedWallet);
|
||||
}
|
||||
},
|
||||
dropdownColor: themeData.textTheme.bodyText1?.decorationColor,
|
||||
style: TextStyle(color: themeData.primaryTextTheme.headline6?.color),
|
||||
selectedItemBuilder: (context) => 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<DesktopWalletSelectionD
|
|||
}
|
||||
}
|
||||
|
||||
void _handleCreateOption(DropdownOption option) {
|
||||
if (option.optionName == 'create_wallet') {
|
||||
_navigateToCreateWallet();
|
||||
} else {
|
||||
_navigateToRestoreWallet();
|
||||
}
|
||||
}
|
||||
|
||||
void _navigateToCreateWallet(){
|
||||
|
||||
if (isSingleCoin) {
|
||||
Navigator.of(context).pushNamed(Routes.newWallet, arguments: widget.walletListViewModel.currentWalletType);
|
||||
} else {
|
||||
Navigator.of(context).pushNamed(Routes.newWalletType);
|
||||
}
|
||||
}
|
||||
|
||||
void _navigateToRestoreWallet(){
|
||||
|
||||
if (isSingleCoin) {
|
||||
Navigator.of(context).pushNamed(Routes.restoreWallet, arguments: widget.walletListViewModel.currentWalletType);
|
||||
} else {
|
||||
Navigator.of(context).pushNamed(Routes.restoreWalletType);
|
||||
}
|
||||
}
|
||||
|
||||
void changeProcessText(String text) {
|
||||
_progressBar = createBar<void>(text, duration: null)..show(context);
|
||||
}
|
||||
|
|
|
@ -16,7 +16,8 @@ class DesktopSettingsPage extends StatefulWidget {
|
|||
}
|
||||
|
||||
class _DesktopSettingsPageState extends State<DesktopSettingsPage> {
|
||||
final int itemCount = SettingActions.all.length;
|
||||
final List<SettingActions> _allItems = [];
|
||||
|
||||
int? currentPage;
|
||||
|
||||
void _onItemChange(int index) {
|
||||
|
@ -25,6 +26,13 @@ class _DesktopSettingsPageState extends State<DesktopSettingsPage> {
|
|||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
final allActions = List<SettingActions>.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<DesktopSettingsPage> {
|
|||
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<DesktopSettingsPage> {
|
|||
height: 1,
|
||||
color: Theme.of(context).primaryTextTheme.caption!.decorationColor!,
|
||||
),
|
||||
itemCount: itemCount,
|
||||
itemCount: _allItems.length,
|
||||
),
|
||||
),
|
||||
],
|
||||
|
|
|
@ -234,7 +234,7 @@ class WalletListBodyState extends State<WalletListBody> {
|
|||
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<WalletListBody> {
|
|||
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()));
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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<WalletListItem> wallets;
|
||||
|
||||
@computed
|
||||
ObservableList<DesktopDropdownItem> get dropdownItems {
|
||||
final items = <DesktopDropdownItem>[];
|
||||
|
||||
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<DesktopDropdownItem>.of(items);
|
||||
}
|
||||
|
||||
final AppStore _appStore;
|
||||
final Box<WalletInfo> _walletInfoSource;
|
||||
final WalletLoadingService _walletLoadingService;
|
||||
|
|
Loading…
Reference in a new issue