Skip to content

Commit

Permalink
clients/sidesail: make zside not crash horribly
Browse files Browse the repository at this point in the history
  • Loading branch information
octobocto committed Dec 3, 2024
1 parent e406681 commit 9bab799
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 103 deletions.
2 changes: 2 additions & 0 deletions clients/bitwindow/lib/pages/overview_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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');
Expand Down
40 changes: 22 additions & 18 deletions clients/sidesail/lib/pages/tabs/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,26 +109,31 @@ class _HomePageState extends State<HomePage> {
homeIndex: Tabs.ParentChainPeg.index,
routes: routes,
builder: (context, children, tabsRouter) {
return TopNav(
child: Stack(
children: [
children[tabsRouter.activeIndex],
ValueListenableBuilder<List<Widget>>(
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)),
],
),
);
Expand All @@ -153,7 +158,6 @@ class _HomePageState extends State<HomePage> {
context: context,
title: 'Shutdown status',
subtitle: 'Shutting down nodes...',
maxWidth: 536,
child: SailColumn(
spacing: SailStyleValues.padding20,
mainAxisAlignment: MainAxisAlignment.start,
Expand Down
26 changes: 10 additions & 16 deletions clients/sidesail/lib/widgets/containers/tabs/home/bottom_nav.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,33 +126,27 @@ class BottomNavViewModel extends BaseViewModel {
await widgetDialog(
context: context,
title: 'Daemon status',
maxWidth: 566,
child: ViewModelBuilder.reactive(
viewModelBuilder: () => BottomNavViewModel(navigateToSettings: navigateToSettings),
builder: ((context, model, child) {
return SailColumn(
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(
Expand Down
110 changes: 41 additions & 69 deletions clients/sidesail/lib/widgets/containers/tabs/home/top_nav.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -26,88 +26,60 @@ class _TopNavState extends State<TopNav> {

@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(),
],
);
}),
Expand Down

0 comments on commit 9bab799

Please sign in to comment.