Skip to content

Commit

Permalink
tabs/home: refactor nav, move pegs to mainchain dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
octobocto committed Nov 6, 2023
1 parent ab47d79 commit b4eaee0
Show file tree
Hide file tree
Showing 10 changed files with 304 additions and 65 deletions.
51 changes: 6 additions & 45 deletions lib/pages/tabs/dashboard_tab_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:logger/logger.dart';
import 'package:sail_ui/sail_ui.dart';
import 'package:sail_ui/theme/theme.dart';
import 'package:sail_ui/widgets/core/sail_text.dart';
import 'package:sidesail/config/sidechains.dart';
import 'package:sidesail/providers/transactions_provider.dart';
import 'package:sidesail/routing/router.dart';
import 'package:sidesail/rpc/rpc_sidechain.dart';
Expand Down Expand Up @@ -36,31 +37,15 @@ class DashboardTabPage extends StatelessWidget {
title: 'Actions',
children: [
ActionTile(
title: 'Peg-out to mainchain',
category: Category.mainchain,
icon: Icons.remove,
onTap: () {
viewModel.pegOut(context);
},
),
ActionTile(
title: 'Peg-in from mainchain',
category: Category.mainchain,
icon: Icons.add,
onTap: () {
viewModel.pegIn(context);
},
),
ActionTile(
title: 'Send on sidechain',
title: 'Send ${viewModel.chain.ticker}',
category: Category.sidechain,
icon: Icons.remove,
onTap: () {
viewModel.send(context);
},
),
ActionTile(
title: 'Receive on sidechain',
title: 'Receive ${viewModel.chain.ticker}',
category: Category.sidechain,
icon: Icons.add,
onTap: () {
Expand Down Expand Up @@ -204,40 +189,16 @@ class ExpandedTXView extends StatelessWidget {
class DashboardTabViewModel extends BaseViewModel {
final log = Logger(level: Level.debug);
TransactionsProvider get _transactionsProvider => GetIt.I.get<TransactionsProvider>();
SidechainRPC get _sideRPC => GetIt.I.get<SidechainRPC>();

List<Transaction> get transactions => _transactionsProvider.transactions;

Sidechain get chain => _sideRPC.chain;

DashboardTabViewModel() {
// by adding a listener, we subscribe to changes to the balance
// provider. We don't use the updates for anything other than
// showing the new value though, so we keep it simple, and just
// pass notifyListeners of this view model directly
_transactionsProvider.addListener(notifyListeners);
}

void pegOut(BuildContext context) async {
final theme = SailTheme.of(context);

await showDialog(
context: context,
barrierColor: theme.colors.background.withOpacity(0.4),
builder: (BuildContext context) {
return const PegOutAction();
},
);
}

void pegIn(BuildContext context) async {
final theme = SailTheme.of(context);
await showDialog(
context: context,
barrierColor: theme.colors.background.withOpacity(0.4),
builder: (BuildContext context) {
return const PegInAction();
},
);
}

void send(BuildContext context) async {
final theme = SailTheme.of(context);
await showDialog(
Expand Down
131 changes: 115 additions & 16 deletions lib/pages/tabs/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class HomePage extends StatelessWidget {
routes: const [
SidechainExplorerTabRoute(),
DashboardTabRoute(),
TransferMainchainTabRoute(),
WithdrawalBundleTabRoute(),
BlindMergedMiningTabRoute(),
SettingsTabRoute(),
Expand All @@ -36,7 +37,7 @@ class HomePage extends StatelessWidget {
backgroundColor: theme.colors.background,
body: SideNav(
child: children[tabsRouter.activeIndex],
navigateToSettings: () => tabsRouter.setActiveIndex(4),
navigateToSettings: () => tabsRouter.setActiveIndex(5),
),
);
},
Expand Down Expand Up @@ -97,27 +98,38 @@ class _SideNavState extends State<SideNav> {
},
),
NavEntry(
title: 'Withdrawal bundles',
icon: SailSVGAsset.iconWithdrawalBundleTab,
title: 'Mainchain Dashboard',
icon: SailSVGAsset.iconDashboardTab,
selected: tabsRouter.activeIndex == 2,
onPressed: () {
tabsRouter.setActiveIndex(2);
},
),
NavEntry(
title: 'Blind-merged-mining',
icon: SailSVGAsset.iconBMMTab,
selected: tabsRouter.activeIndex == 3,
onPressed: () {
tabsRouter.setActiveIndex(3);
},
SubNavEntryContainer(
open: tabsRouter.activeIndex == 2 || tabsRouter.activeIndex == 3 || tabsRouter.activeIndex == 4,
subs: [
SubNavEntry(
title: 'Withdrawal explorer',
selected: tabsRouter.activeIndex == 3,
onPressed: () {
tabsRouter.setActiveIndex(3);
},
),
SubNavEntry(
title: 'Blind Merged Mining',
selected: tabsRouter.activeIndex == 4,
onPressed: () {
tabsRouter.setActiveIndex(4);
},
),
],
),
NavEntry(
title: 'Settings',
icon: SailSVGAsset.iconBMMTab,
selected: tabsRouter.activeIndex == 4,
selected: tabsRouter.activeIndex == 5,
onPressed: () {
tabsRouter.setActiveIndex(4);
tabsRouter.setActiveIndex(5);
},
),
Expanded(child: Container()),
Expand Down Expand Up @@ -155,10 +167,6 @@ class HomePageViewModel extends BaseViewModel {
Sidechain get chain => _sideRPC.chain;

HomePageViewModel() {
// by adding a listener, we subscribe to changes to the balance
// provider. We don't use the updates for anything other than
// showing the new value though, so we keep it simple, and just
// pass notifyListeners of this view model directly
_sideRPC.addListener(notifyListeners);
_mainRPC.addListener(notifyListeners);
_balanceProvider.addListener(notifyListeners);
Expand Down Expand Up @@ -250,3 +258,94 @@ class NavEntry extends StatelessWidget {
);
}
}

class SubNavEntry extends StatelessWidget {
final String title;

final bool selected;
final VoidCallback onPressed;

const SubNavEntry({
super.key,
required this.title,
required this.selected,
required this.onPressed,
});

@override
Widget build(BuildContext context) {
final theme = SailTheme.of(context);

return ConstrainedBox(
constraints: const BoxConstraints(minWidth: 153, maxWidth: 153),
child: SailScaleButton(
onPressed: onPressed,
child: DecoratedBox(
decoration: BoxDecoration(
color: selected ? theme.colors.actionHeader : Colors.transparent,
borderRadius: BorderRadius.circular(4),
),
child: SailColumn(
spacing: 0,
children: [
Padding(
padding: const EdgeInsets.symmetric(
horizontal: SailStyleValues.padding08,
vertical: SailStyleValues.padding05,
),
child: SailText.primary12(title, bold: true),
),
],
),
),
),
);
}
}

class SubNavEntryContainer extends StatelessWidget {
final bool open;
final List<SubNavEntry> subs;

const SubNavEntryContainer({
super.key,
required this.open,
required this.subs,
});

@override
Widget build(BuildContext context) {
final theme = SailTheme.of(context);

if (!open) {
return Container();
}

return Padding(
padding: const EdgeInsets.only(left: SailStyleValues.padding30),
child: DecoratedBox(
decoration: BoxDecoration(
border: Border(
left: BorderSide(
color: theme.colors.divider,
width: 1.0,
),
),
),
child: SailRow(
spacing: 0,
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SailSpacing(SailStyleValues.padding08),
Column(
children: [
for (final sub in subs) sub,
],
),
],
),
),
);
}
}
125 changes: 125 additions & 0 deletions lib/pages/tabs/transfer_mainchain_tab_route.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:get_it/get_it.dart';
import 'package:logger/logger.dart';
import 'package:sail_ui/sail_ui.dart';
import 'package:sail_ui/theme/theme.dart';
import 'package:sail_ui/widgets/core/sail_text.dart';
import 'package:sidesail/pages/tabs/dashboard_tab_page.dart';
import 'package:sidesail/providers/transactions_provider.dart';
import 'package:sidesail/routing/router.dart';
import 'package:sidesail/rpc/rpc_sidechain.dart';
import 'package:sidesail/widgets/containers/tabs/dashboard_tab_widgets.dart';
import 'package:stacked/stacked.dart';

@RoutePage()
class TransferMainchainTabPage extends StatelessWidget {
AppRouter get router => GetIt.I.get<AppRouter>();

const TransferMainchainTabPage({super.key});

@override
Widget build(BuildContext context) {
return ViewModelBuilder.reactive(
viewModelBuilder: () => TransferMainchainTabViewModel(),
builder: ((context, viewModel, child) {
return SailPage(
title: '',
body: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.only(bottom: SailStyleValues.padding30),
child: Column(
children: [
DashboardGroup(
title: 'Actions',
children: [
ActionTile(
title: 'Peg-out to mainchain',
category: Category.mainchain,
icon: Icons.remove,
onTap: () {
viewModel.pegOut(context);
},
),
ActionTile(
title: 'Peg-in from mainchain',
category: Category.mainchain,
icon: Icons.add,
onTap: () {
viewModel.pegIn(context);
},
),
],
),
const SailSpacing(SailStyleValues.padding30),
DashboardGroup(
title: 'Transactions',
widgetTrailing: SailText.secondary13(viewModel.transactions.length.toString()),
children: [
SailColumn(
spacing: 0,
withDivider: true,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ListView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemCount: viewModel.transactions.length,
itemBuilder: (context, index) => TxView(
key: ValueKey<String>(viewModel.transactions[index].txid),
tx: viewModel.transactions[index],
),
),
],
),
],
),
],
),
),
),
);
}),
);
}
}

class TransferMainchainTabViewModel extends BaseViewModel {
final log = Logger(level: Level.debug);
TransactionsProvider get _transactionsProvider => GetIt.I.get<TransactionsProvider>();

List<Transaction> get transactions => _transactionsProvider.mainchainTransactions;

TransferMainchainTabViewModel() {
_transactionsProvider.addListener(notifyListeners);
}

void pegOut(BuildContext context) async {
final theme = SailTheme.of(context);

await showDialog(
context: context,
barrierColor: theme.colors.background.withOpacity(0.4),
builder: (BuildContext context) {
return const PegOutAction();
},
);
}

void pegIn(BuildContext context) async {
final theme = SailTheme.of(context);
await showDialog(
context: context,
barrierColor: theme.colors.background.withOpacity(0.4),
builder: (BuildContext context) {
return const PegInAction();
},
);
}

@override
void dispose() {
super.dispose();
_transactionsProvider.removeListener(notifyListeners);
}
}
Loading

0 comments on commit b4eaee0

Please sign in to comment.