Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add tab bar #4

Merged
merged 6 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/console.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_highlighter/flutter_highlighter.dart';
import 'package:flutter_highlighter/themes/github.dart';
import 'package:get_it/get_it.dart';
import 'package:sail_ui/widgets/core/sail_text.dart';
import 'package:sidesail/logger.dart';
import 'package:sidesail/rpc/rpc.dart';

Expand Down Expand Up @@ -71,7 +72,7 @@ class RpcWidgetState extends State<RpcWidget> {
children: [
Row(
children: [
const Text(
SailText.primary14(
'RPC:',
),
Expanded(
Expand All @@ -81,12 +82,12 @@ class RpcWidgetState extends State<RpcWidget> {
),
ElevatedButton(
onPressed: _handleSubmit,
child: const Text('Submit'),
child: SailText.primary14('Submit'),
),
],
),
if (_result != null) _JsonViewer(_result),
if (_error != null) Text('Error: $_command: $_error'),
if (_error != null) SailText.primary14('Error: $_command: $_error'),
],
),
);
Expand Down
12 changes: 5 additions & 7 deletions lib/deposit_address.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:sail_ui/widgets/core/sail_text.dart';

class DepositAddress extends StatelessWidget {
const DepositAddress(this.address, {super.key});
Expand All @@ -14,22 +15,19 @@ class DepositAddress extends StatelessWidget {
children: [
Row(
children: [
const Text(
SailText.primary14(
'Deposit to this address from the mainchain: ',
),
ElevatedButton(
onPressed: () {
Clipboard.setData(ClipboardData(text: address));
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Copied address'),
SnackBar(
content: SailText.primary14('Copied address'),
),
);
},
child: Text(
address,
style: const TextStyle(color: Colors.white),
),
child: SailText.primary14(address),
),
],
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import 'dart:async';

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/widgets/core/sail_text.dart';
import 'package:sidesail/console.dart';
import 'package:sidesail/deposit_address.dart';
import 'package:sidesail/rpc/rpc.dart';
import 'package:stacked/stacked.dart';

@RoutePage()
class HomePage extends StatelessWidget {
const HomePage({super.key});
class DashboardTabPage extends StatelessWidget {
const DashboardTabPage({super.key});

@override
Widget build(BuildContext context) {
Expand All @@ -31,15 +30,15 @@ class HomePage extends StatelessWidget {
Expanded(child: RpcWidget()),
],
),
const Row(
children: [Text('Deposit stuff')],
Row(
children: [SailText.primary14('Deposit stuff')],
),
Row(
children: [
DepositAddress(viewModel.depositAddress),
ElevatedButton(
onPressed: viewModel.generateDepositAddress,
child: const Text('Generate'),
child: SailText.primary14('Generate'),
),
],
),
Expand Down
60 changes: 60 additions & 0 deletions lib/pages/tabs/home_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:sail_ui/sail_ui.dart';
import 'package:sail_ui/theme/theme.dart';
import 'package:sidesail/routing/router.dart';

@RoutePage()
class HomePage extends StatelessWidget {
const HomePage({super.key});

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

return AutoTabsRouter.pageView(
homeIndex: 1,
routes: const [
DashboardTabRoute(),
WithdrawalBundleTabRoute(),
WithdrawalTabRoute(),
],
builder: (context, child, _) {
final tabsRouter = AutoTabsRouter.of(context);
return Scaffold(
body: child,
bottomNavigationBar: BottomNavigationBar(
backgroundColor: theme.colors.backgroundSecondary,
unselectedItemColor: theme.colors.text,
selectedItemColor: theme.colors.orange,
currentIndex: tabsRouter.activeIndex,
onTap: tabsRouter.setActiveIndex,
items: [
BottomNavigationBarItem(
label: 'Dashboard',
icon: SailSVG.icon(
SailSVGAsset.iconDashboardTab,
isHighlighted: tabsRouter.activeIndex == 0,
),
),
BottomNavigationBarItem(
label: 'Withdrawal Bundles',
icon: SailSVG.icon(
SailSVGAsset.iconDashboardTab,
isHighlighted: tabsRouter.activeIndex == 1,
),
),
BottomNavigationBarItem(
label: 'Withdrawals',
icon: SailSVG.icon(
SailSVGAsset.iconDashboardTab,
isHighlighted: tabsRouter.activeIndex == 2,
),
),
],
),
);
},
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ import 'package:sidesail/rpc/rpc.dart';
import 'package:stacked/stacked.dart';

@RoutePage()
class WithdrawalBundlePage extends StatelessWidget {
const WithdrawalBundlePage({super.key});
class WithdrawalBundleTabPage extends StatelessWidget {
const WithdrawalBundleTabPage({super.key});

@override
Widget build(BuildContext context) {
return SailPage(
title: 'Withdrawal bundles',
body: ViewModelBuilder.reactive(
viewModelBuilder: () => WithdrawalBundlePageViewModel(),
viewModelBuilder: () => WithdrawalBundleTabPageViewModel(),
builder: ((context, viewModel, child) {
return SailText.mediumText20(
return SailText.primary14(
'Withdrawal bundle status: ${viewModel.withdrawalBundleStatus}',
);
}),
Expand All @@ -28,10 +28,10 @@ class WithdrawalBundlePage extends StatelessWidget {
}
}

class WithdrawalBundlePageViewModel extends BaseViewModel {
class WithdrawalBundleTabPageViewModel extends BaseViewModel {
RPC get _rpc => GetIt.I.get<RPC>();

WithdrawalBundlePageViewModel() {
WithdrawalBundleTabPageViewModel() {
_startWithdrawalBundleFetch();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get_it/get_it.dart';
import 'package:sail_ui/sail_ui.dart';
import 'package:sail_ui/widgets/core/sail_text.dart';
import 'package:sidesail/logger.dart';
import 'package:sidesail/rpc/rpc.dart';
import 'package:sidesail/withdrawals.dart';
Expand All @@ -15,22 +16,22 @@ import 'package:stacked/stacked.dart';
// SBTC?

@RoutePage()
class WithdrawalPage extends StatelessWidget {
const WithdrawalPage({super.key});
class WithdrawalTabPage extends StatelessWidget {
const WithdrawalTabPage({super.key});

@override
Widget build(BuildContext context) {
return SailPage(
title: 'Withdraw',
body: ViewModelBuilder.reactive(
viewModelBuilder: () => WithdrawalPageViewModel(),
viewModelBuilder: () => WithdrawalTabPageViewModel(),
builder: ((context, viewModel, child) {
return Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
SailText.primary14(
'Your sidechain balance: ${viewModel.sidechainBalance} SCO',
),
const SizedBox(height: 20),
Expand Down Expand Up @@ -88,9 +89,9 @@ class WithdrawalPage extends StatelessWidget {
const SizedBox(height: 20),
Row(
children: [
const Text('Total cost:'),
SailText.primary14('Total cost:'),
const SizedBox(width: 10),
Text(
SailText.primary14(
'${(viewModel.withdrawalAmount + viewModel.mainchainFee + viewModel.transactionFee)} SCO',
),
],
Expand All @@ -100,7 +101,9 @@ class WithdrawalPage extends StatelessWidget {
onPressed: () {
viewModel.onWithdraw(context);
},
child: const Text('Withdraw'),
child: SailText.primary14(
'Withdraw',
),
),
// TODO: this just caps the table...
const SingleChildScrollView(
Expand All @@ -118,7 +121,7 @@ class WithdrawalPage extends StatelessWidget {
}
}

class WithdrawalPageViewModel extends MultipleFutureViewModel {
class WithdrawalTabPageViewModel extends MultipleFutureViewModel {
RPC get _rpc => GetIt.I.get<RPC>();

// TODO: how to take this on creation? Async operation, possible
Expand All @@ -135,7 +138,7 @@ class WithdrawalPageViewModel extends MultipleFutureViewModel {

Timer? balanceTimer;

WithdrawalPageViewModel() {
WithdrawalTabPageViewModel() {
balanceTimer = Timer.periodic(const Duration(seconds: 1), (timer) async {
// fetchAndUpdateBalance();
});
Expand Down Expand Up @@ -191,14 +194,16 @@ class WithdrawalPageViewModel extends MultipleFutureViewModel {
await showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Text('Confirm withdrawal'),
content: Text(
title: SailText.primary14(
'Confirm withdrawal',
),
content: SailText.primary14(
'Confirm withdrawal: $withdrawalAmount BTC to $address for $transactionFee SC fee and $mainchainFee MC fee',
),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: const Text('Cancel'),
child: SailText.primary14('Cancel'),
),
TextButton(
onPressed: () {
Expand All @@ -214,7 +219,9 @@ class WithdrawalPageViewModel extends MultipleFutureViewModel {
transactionFee,
);
},
child: const Text('OK'),
child: SailText.primary14(
'OK',
),
),
],
),
Expand Down Expand Up @@ -251,14 +258,16 @@ class WithdrawalPageViewModel extends MultipleFutureViewModel {
await showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Text('Success'),
content: Text(
title: SailText.primary14(
'Success',
),
content: SailText.primary14(
'Submitted withdrawal successfully! TXID: $withdrawalTxid',
),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: const Text('OK'),
child: SailText.primary14('OK'),
),
],
),
Expand Down
29 changes: 18 additions & 11 deletions lib/routing/router.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import 'package:auto_route/auto_route.dart';
import 'package:flutter/widgets.dart';
import 'package:sidesail/pages/withdrawal_bundle_page.dart';
import 'package:sidesail/pages/withdrawal_page.dart';
import 'package:sidesail/routing/routes_export.dart';
import 'package:sidesail/pages/tabs/dashboard_tab_page.dart';
import 'package:sidesail/pages/tabs/home_page.dart';
import 'package:sidesail/pages/tabs/withdrawal_bundle_tab_page.dart';
import 'package:sidesail/pages/tabs/withdrawal_tab_page.dart';
import 'package:sidesail/pages/test_page.dart';

part 'router.gr.dart';

Expand All @@ -14,7 +16,7 @@ part 'router.gr.dart';
* Use the [watch] flag to watch the files' system for edits and rebuild as necessary.
* $ flutter packages pub run build_runner watch
* if you want the generator to run one time and exit, use
* $ flutter packages pub run build_runner build
* $ flutter packages pub run build_runner build --delete-conflicting-outputs

*/
@AutoRouterConfig(replaceInRouteName: 'Page,Route')
Expand All @@ -27,13 +29,18 @@ class AppRouter extends _$AppRouter {
AutoRoute(
page: HomeRoute.page,
initial: true,
),
AutoRoute(
page: WithdrawalBundleRoute.page,
),

AutoRoute(
page: WithdrawalRoute.page,
children: [
AutoRoute(
page: DashboardTabRoute.page,
initial: true,
),
AutoRoute(
page: WithdrawalBundleTabRoute.page,
),
AutoRoute(
page: WithdrawalTabRoute.page,
),
],
),

/// This route is used in tests so that we can pump a widget into a route
Expand Down
Loading