persist active wallet on desktop

This commit is contained in:
julian 2022-11-26 13:39:52 -06:00
parent 178565a190
commit 18da658a65
3 changed files with 70 additions and 7 deletions

View file

@ -9,12 +9,19 @@ import 'package:stackwallet/pages_desktop_specific/home/notifications/desktop_no
import 'package:stackwallet/pages_desktop_specific/home/support_and_about_view/desktop_about_view.dart'; import 'package:stackwallet/pages_desktop_specific/home/support_and_about_view/desktop_about_view.dart';
import 'package:stackwallet/pages_desktop_specific/home/support_and_about_view/desktop_support_view.dart'; import 'package:stackwallet/pages_desktop_specific/home/support_and_about_view/desktop_support_view.dart';
import 'package:stackwallet/providers/desktop/current_desktop_menu_item.dart'; import 'package:stackwallet/providers/desktop/current_desktop_menu_item.dart';
import 'package:stackwallet/providers/global/auto_swb_service_provider.dart';
import 'package:stackwallet/providers/global/notifications_provider.dart'; import 'package:stackwallet/providers/global/notifications_provider.dart';
import 'package:stackwallet/providers/global/prefs_provider.dart';
import 'package:stackwallet/providers/global/wallets_provider.dart';
import 'package:stackwallet/providers/ui/transaction_filter_provider.dart';
import 'package:stackwallet/providers/ui/unread_notifications_provider.dart'; import 'package:stackwallet/providers/ui/unread_notifications_provider.dart';
import 'package:stackwallet/route_generator.dart'; import 'package:stackwallet/route_generator.dart';
import 'package:stackwallet/utilities/enums/backup_frequency_type.dart';
import 'package:stackwallet/utilities/theme/stack_colors.dart'; import 'package:stackwallet/utilities/theme/stack_colors.dart';
import 'package:stackwallet/widgets/background.dart'; import 'package:stackwallet/widgets/background.dart';
final currentWalletIdProvider = StateProvider<String?>((_) => null);
class DesktopHomeView extends ConsumerStatefulWidget { class DesktopHomeView extends ConsumerStatefulWidget {
const DesktopHomeView({Key? key}) : super(key: key); const DesktopHomeView({Key? key}) : super(key: key);
@ -25,12 +32,25 @@ class DesktopHomeView extends ConsumerStatefulWidget {
} }
class _DesktopHomeViewState extends ConsumerState<DesktopHomeView> { class _DesktopHomeViewState extends ConsumerState<DesktopHomeView> {
final Map<DesktopMenuItemId, Widget> contentViews = { final GlobalKey key = GlobalKey<NavigatorState>();
DesktopMenuItemId.myStack: const Navigator( late final Navigator myStackViewNav;
key: Key("desktopStackHomeKey"),
@override
void initState() {
myStackViewNav = Navigator(
key: key,
onGenerateRoute: RouteGenerator.generateRoute, onGenerateRoute: RouteGenerator.generateRoute,
initialRoute: MyStackView.routeName, initialRoute: MyStackView.routeName,
), );
super.initState();
}
final Map<DesktopMenuItemId, Widget> contentViews = {
DesktopMenuItemId.myStack: Container(
// key: Key("desktopStackHomeKey"),
// onGenerateRoute: RouteGenerator.generateRoute,
// initialRoute: MyStackView.routeName,
),
DesktopMenuItemId.exchange: const Navigator( DesktopMenuItemId.exchange: const Navigator(
key: Key("desktopExchangeHomeKey"), key: Key("desktopExchangeHomeKey"),
onGenerateRoute: RouteGenerator.generateRoute, onGenerateRoute: RouteGenerator.generateRoute,
@ -63,7 +83,30 @@ class _DesktopHomeViewState extends ConsumerState<DesktopHomeView> {
), ),
}; };
DesktopMenuItemId prev = DesktopMenuItemId.myStack;
void onMenuSelectionWillChange(DesktopMenuItemId newKey) { void onMenuSelectionWillChange(DesktopMenuItemId newKey) {
if (prev == DesktopMenuItemId.myStack && prev == newKey) {
Navigator.of(key.currentContext!)
.popUntil(ModalRoute.withName(MyStackView.routeName));
if (ref.read(currentWalletIdProvider.state).state != null) {
final managerProvider = ref
.read(walletsChangeNotifierProvider)
.getManagerProvider(ref.read(currentWalletIdProvider.state).state!);
if (ref.read(managerProvider).shouldAutoSync) {
ref.read(managerProvider).shouldAutoSync = false;
}
ref.read(transactionFilterProvider.state).state = null;
if (ref.read(prefsChangeNotifierProvider).isAutoBackupEnabled &&
ref.read(prefsChangeNotifierProvider).backupFrequencyType ==
BackupFrequencyType.afterClosingAWallet) {
ref.read(autoSWBServiceProvider).doBackup();
}
ref.read(managerProvider.notifier).isActiveWallet = false;
}
}
prev = newKey;
// check for unread notifications and refresh provider before // check for unread notifications and refresh provider before
// showing notifications view // showing notifications view
if (newKey == DesktopMenuItemId.notifications) { if (newKey == DesktopMenuItemId.notifications) {
@ -111,9 +154,25 @@ class _DesktopHomeViewState extends ConsumerState<DesktopHomeView> {
color: Theme.of(context).extension<StackColors>()!.background, color: Theme.of(context).extension<StackColors>()!.background,
), ),
Expanded( Expanded(
child: contentViews[ child: IndexedStack(
ref.watch(currentDesktopMenuItemProvider.state).state]!, index: ref
.watch(currentDesktopMenuItemProvider.state)
.state
.index >
0
? 1
: 0,
children: [
myStackViewNav,
contentViews[
ref.watch(currentDesktopMenuItemProvider.state).state]!,
],
),
), ),
// Expanded(
// child: contentViews[
// ref.watch(currentDesktopMenuItemProvider.state).state]!,
// ),
], ],
), ),
), ),

View file

@ -1,5 +1,6 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:stackwallet/pages_desktop_specific/home/desktop_home_view.dart';
import 'package:stackwallet/pages_desktop_specific/home/my_stack_view/wallet_view/desktop_wallet_view.dart'; import 'package:stackwallet/pages_desktop_specific/home/my_stack_view/wallet_view/desktop_wallet_view.dart';
import 'package:stackwallet/utilities/constants.dart'; import 'package:stackwallet/utilities/constants.dart';
import 'package:stackwallet/utilities/theme/stack_colors.dart'; import 'package:stackwallet/utilities/theme/stack_colors.dart';
@ -51,6 +52,9 @@ class CoinWalletsTable extends ConsumerWidget {
Positioned.fill( Positioned.fill(
child: WalletRowHoverOverlay( child: WalletRowHoverOverlay(
onPressed: () async { onPressed: () async {
ref.read(currentWalletIdProvider.state).state =
walletIds[i];
await Navigator.of(context).pushNamed( await Navigator.of(context).pushNamed(
DesktopWalletView.routeName, DesktopWalletView.routeName,
arguments: walletIds[i], arguments: walletIds[i],

View file

@ -81,13 +81,13 @@ class _DesktopWalletViewState extends ConsumerState<DesktopWalletView> {
// disable auto sync if it was enabled only when loading wallet // disable auto sync if it was enabled only when loading wallet
ref.read(managerProvider).shouldAutoSync = false; ref.read(managerProvider).shouldAutoSync = false;
} }
ref.read(managerProvider.notifier).isActiveWallet = false;
ref.read(transactionFilterProvider.state).state = null; ref.read(transactionFilterProvider.state).state = null;
if (ref.read(prefsChangeNotifierProvider).isAutoBackupEnabled && if (ref.read(prefsChangeNotifierProvider).isAutoBackupEnabled &&
ref.read(prefsChangeNotifierProvider).backupFrequencyType == ref.read(prefsChangeNotifierProvider).backupFrequencyType ==
BackupFrequencyType.afterClosingAWallet) { BackupFrequencyType.afterClosingAWallet) {
unawaited(ref.read(autoSWBServiceProvider).doBackup()); unawaited(ref.read(autoSWBServiceProvider).doBackup());
} }
ref.read(managerProvider.notifier).isActiveWallet = false;
} }
void _loadCNData() { void _loadCNData() {