From 9bab7990bd0c58cc68178c89bcbee81a93c9e0af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Olav?= Date: Tue, 3 Dec 2024 09:24:47 +0100 Subject: [PATCH] clients/sidesail: make zside not crash horribly --- .../bitwindow/lib/pages/overview_page.dart | 2 + .../sidesail/lib/pages/tabs/home_page.dart | 40 ++++--- .../containers/tabs/home/bottom_nav.dart | 26 ++--- .../widgets/containers/tabs/home/top_nav.dart | 110 +++++++----------- 4 files changed, 75 insertions(+), 103 deletions(-) diff --git a/clients/bitwindow/lib/pages/overview_page.dart b/clients/bitwindow/lib/pages/overview_page.dart index 157586f2..96676c3f 100644 --- a/clients/bitwindow/lib/pages/overview_page.dart +++ b/clients/bitwindow/lib/pages/overview_page.dart @@ -673,6 +673,7 @@ class BroadcastNewsViewModel extends BaseViewModel { try { await _api.misc.broadcastNews(topic.topic, headlineController.text); + if (!context.mounted) return; showSnackBar(context, 'news broadcast successfully!'); } catch (e) { showSnackBar(context, 'could not broadcast news: $e'); @@ -766,6 +767,7 @@ class CreateTopicViewModel extends BaseViewModel { try { await _api.misc.createTopic(identifierController.text, nameController.text); + if (!context.mounted) return; showSnackBar(context, 'topic created successfully!'); } catch (e) { showSnackBar(context, 'could not create topic: $e'); diff --git a/clients/sidesail/lib/pages/tabs/home_page.dart b/clients/sidesail/lib/pages/tabs/home_page.dart index 4500aab8..2c1da7fe 100644 --- a/clients/sidesail/lib/pages/tabs/home_page.dart +++ b/clients/sidesail/lib/pages/tabs/home_page.dart @@ -109,26 +109,31 @@ class _HomePageState extends State { homeIndex: Tabs.ParentChainPeg.index, routes: routes, builder: (context, children, tabsRouter) { - return TopNav( - child: Stack( - children: [ - children[tabsRouter.activeIndex], - ValueListenableBuilder>( - valueListenable: notificationsNotifier, - builder: (context, val, child) { - return Positioned( - bottom: 10, - right: 10, - child: Column( - crossAxisAlignment: CrossAxisAlignment.end, - children: val, - ), - ); + return Scaffold( + backgroundColor: theme.colors.background, + appBar: PreferredSize( + preferredSize: const Size.fromHeight(80), + child: DecoratedBox( + decoration: BoxDecoration( + color: theme.colors.background, + ), + child: Builder( + builder: (context) { + final tabsRouter = AutoTabsRouter.of(context); + return TopNav(tabsRouter: tabsRouter); }, ), - BottomNav( - navigateToSettings: () => tabsRouter.setActiveIndex(Tabs.SettingsHome.index), + ), + ), + body: Column( + children: [ + const Divider( + height: 1, + thickness: 1, + color: Colors.grey, ), + Expanded(child: children[tabsRouter.activeIndex]), + BottomNav(navigateToSettings: () => tabsRouter.setActiveIndex(Tabs.SettingsHome.index)), ], ), ); @@ -153,7 +158,6 @@ class _HomePageState extends State { context: context, title: 'Shutdown status', subtitle: 'Shutting down nodes...', - maxWidth: 536, child: SailColumn( spacing: SailStyleValues.padding20, mainAxisAlignment: MainAxisAlignment.start, diff --git a/clients/sidesail/lib/widgets/containers/tabs/home/bottom_nav.dart b/clients/sidesail/lib/widgets/containers/tabs/home/bottom_nav.dart index 4a63ae7a..08678be7 100644 --- a/clients/sidesail/lib/widgets/containers/tabs/home/bottom_nav.dart +++ b/clients/sidesail/lib/widgets/containers/tabs/home/bottom_nav.dart @@ -126,7 +126,6 @@ class BottomNavViewModel extends BaseViewModel { await widgetDialog( context: context, title: 'Daemon status', - maxWidth: 566, child: ViewModelBuilder.reactive( viewModelBuilder: () => BottomNavViewModel(navigateToSettings: navigateToSettings), builder: ((context, model, child) { @@ -134,25 +133,20 @@ class BottomNavViewModel extends BaseViewModel { spacing: SailStyleValues.padding20, mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, children: [ const SailSpacing(SailStyleValues.padding08), if (!_mainRPC.connected || !_sideRPC.rpc.connected) SailText.secondary12('You cannot use ${_sideRPC.rpc.chain.name} until nodes are connected'), - SailRow( - spacing: SailStyleValues.padding12, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - DaemonConnectionCard( - connection: _mainRPC, - restartDaemon: () => initMainchainBinary(context), - infoMessage: null, - ), - DaemonConnectionCard( - connection: _sideRPC.rpc, - infoMessage: _mainRPC.inIBD ? 'Waiting for L1 initial block download to complete...' : null, - restartDaemon: () => initSidechainBinary(context), - ), - ], + DaemonConnectionCard( + connection: _mainRPC, + restartDaemon: () => initMainchainBinary(context), + infoMessage: null, + ), + DaemonConnectionCard( + connection: _sideRPC.rpc, + infoMessage: _mainRPC.inIBD ? 'Waiting for L1 initial block download to complete...' : null, + restartDaemon: () => initSidechainBinary(context), ), const SailSpacing(SailStyleValues.padding10), SailRow( diff --git a/clients/sidesail/lib/widgets/containers/tabs/home/top_nav.dart b/clients/sidesail/lib/widgets/containers/tabs/home/top_nav.dart index fd83e80f..35ece4c8 100644 --- a/clients/sidesail/lib/widgets/containers/tabs/home/top_nav.dart +++ b/clients/sidesail/lib/widgets/containers/tabs/home/top_nav.dart @@ -10,11 +10,11 @@ import 'package:sidesail/rpc/rpc_sidechain.dart'; import 'package:stacked/stacked.dart'; class TopNav extends StatefulWidget { - final Widget child; + final auto_router.TabsRouter tabsRouter; const TopNav({ super.key, - required this.child, + required this.tabsRouter, }); @override @@ -26,88 +26,60 @@ class _TopNavState extends State { @override Widget build(BuildContext context) { - final tabsRouter = auto_router.AutoTabsRouter.of(context); final theme = SailTheme.of(context); return ViewModelBuilder.reactive( viewModelBuilder: () => TopNavViewModel(), fireOnViewModelReadyOnce: true, builder: ((context, model, child) { - final sidechainNav = _navForSidechain(_sidechain.rpc.chain, model, tabsRouter); - final trailingSidechainNav = _navForSidechainTrailing(_sidechain.rpc.chain, model, tabsRouter); + final sidechainNav = _navForSidechain(_sidechain.rpc.chain, model, widget.tabsRouter); + final trailingSidechainNav = _navForSidechainTrailing(_sidechain.rpc.chain, model, widget.tabsRouter); - return Column( + return SailRow( + spacing: 0, children: [ - SailRow( - spacing: 0, + Row( children: [ - NavContainer( - title: 'Parent Chain', - subs: [ - QtTab( - label: 'Deposit/Withdraw', - active: tabsRouter.activeIndex == Tabs.ParentChainPeg.index, - onTap: () { - tabsRouter.setActiveIndex(Tabs.ParentChainPeg.index); - }, - icon: SailSVGAsset.iconTabPeg, - ), - if (_sidechain.rpc.chain.type == ChainType.testchain) - QtTab( - label: 'Withdrawal Explorer', - active: tabsRouter.activeIndex == Tabs.ParentChainWithdrawalExplorer.index, - onTap: () { - tabsRouter.setActiveIndex(Tabs.ParentChainWithdrawalExplorer.index); - }, - icon: SailSVGAsset.iconTabWithdrawalExplorer, - ), - if (_sidechain.rpc.chain.type == ChainType.testchain) - QtTab( - label: 'Blind Merged Mining', - active: tabsRouter.activeIndex == Tabs.ParentChainBMM.index, - onTap: () { - tabsRouter.setActiveIndex(Tabs.ParentChainBMM.index); - }, - icon: SailSVGAsset.iconTabBMM, - ), - ], + QtTab( + label: 'Deposit/Withdraw', + active: widget.tabsRouter.activeIndex == Tabs.ParentChainPeg.index, + onTap: () { + widget.tabsRouter.setActiveIndex(Tabs.ParentChainPeg.index); + }, + icon: SailSVGAsset.iconTabPeg, ), - SizedBox( - height: 50, - child: VerticalDivider( - width: 1, - thickness: 1, - color: theme.colors.icon.withOpacity(0.2), + if (_sidechain.rpc.chain.type == ChainType.testchain) + QtTab( + label: 'Withdrawal Explorer', + active: widget.tabsRouter.activeIndex == Tabs.ParentChainWithdrawalExplorer.index, + onTap: () { + widget.tabsRouter.setActiveIndex(Tabs.ParentChainWithdrawalExplorer.index); + }, + icon: SailSVGAsset.iconTabWithdrawalExplorer, ), - ), - NavContainer( - title: 'Sidechain', - subs: sidechainNav, - ), - SizedBox( - height: 50, - child: VerticalDivider( - width: 1, - thickness: 1, - color: theme.colors.icon.withOpacity(0.2), + if (_sidechain.rpc.chain.type == ChainType.testchain) + QtTab( + label: 'Blind Merged Mining', + active: widget.tabsRouter.activeIndex == Tabs.ParentChainBMM.index, + onTap: () { + widget.tabsRouter.setActiveIndex(Tabs.ParentChainBMM.index); + }, + icon: SailSVGAsset.iconTabBMM, ), - ), - NavContainer( - title: 'General', - subs: trailingSidechainNav, - ), - Expanded(child: Container()), - const ToggleThemeButton(), ], ), - Divider( - height: 1, - thickness: 1, - color: theme.colors.divider, - ), - Expanded( - child: widget.child, + SizedBox( + height: 50, + child: VerticalDivider( + width: 1, + thickness: 1, + color: theme.colors.icon.withOpacity(0.2), + ), ), + ...sidechainNav, + ...trailingSidechainNav, + Expanded(child: Container()), + const ToggleThemeButton(), ], ); }),