Skip to content

Commit

Permalink
Merge pull request #1124 from get10101/chore/refactor-status-screen
Browse files Browse the repository at this point in the history
Change thermostat colour when services are down
  • Loading branch information
klochowicz authored Aug 21, 2023
2 parents 864cdd2 + eb3dbf6 commit ac48bce
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 115 deletions.
51 changes: 18 additions & 33 deletions mobile/lib/common/app_bar_wrapper.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import 'package:flutter/material.dart';
import 'package:get_10101/common/channel_status_notifier.dart';
import 'package:get_10101/common/color.dart';
import 'package:get_10101/common/settings_screen.dart';
import 'package:get_10101/common/status_icon_button.dart';
import 'package:get_10101/features/trade/trade_screen.dart';
import 'package:get_10101/features/wallet/wallet_screen.dart';
import 'package:get_10101/features/wallet/status_screen.dart';
import 'package:go_router/go_router.dart';
import 'package:provider/provider.dart';

class AppBarWrapper extends StatelessWidget {
const AppBarWrapper({
Expand All @@ -18,20 +16,6 @@ class AppBarWrapper extends StatelessWidget {
final currentRoute = GoRouterState.of(context).location;
const appBarHeight = 35.0;

ChannelStatusNotifier channelStatusNotifier = context.watch<ChannelStatusNotifier>();

var actionButtons = [
IconButton(
icon: channelStatusNotifier.isClosing()
? const Icon(Icons.thermostat, color: Colors.red)
: const Icon(Icons.thermostat),
tooltip: 'Status',
onPressed: () {
context.go(WalletStatusScreen.route);
},
)
];

Widget? leadingButton;

if (currentRoute == WalletScreen.route) {
Expand All @@ -40,7 +24,7 @@ class AppBarWrapper extends StatelessWidget {
icon: const Icon(Icons.settings),
tooltip: 'Settings',
onPressed: () {
Navigator.of(context).push(_createRoute());
Navigator.of(context).push(_createSettingsRoute());
},
)
]);
Expand All @@ -52,7 +36,7 @@ class AppBarWrapper extends StatelessWidget {
icon: const Icon(Icons.settings),
tooltip: 'Settings',
onPressed: () {
Navigator.of(context).push(_createRoute());
Navigator.of(context).push(_createSettingsRoute());
},
)
]);
Expand All @@ -61,23 +45,24 @@ class AppBarWrapper extends StatelessWidget {
return Container(
margin: const EdgeInsets.only(left: 6.0),
child: AppBar(
elevation: 0,
backgroundColor: Colors.transparent,
iconTheme: const IconThemeData(
color: tenTenOnePurple,
// Without adjustment, the icon appears off-center from the title (logo)
size: appBarHeight - 8.0),
leading: leadingButton,
title: SizedBox(
height: appBarHeight - 10.0,
child: Image.asset('assets/10101_logo_icon.png'),
),
actions: actionButtons,
));
elevation: 0,
backgroundColor: Colors.transparent,
iconTheme: const IconThemeData(
color: tenTenOnePurple,
// Without adjustment, the icon appears off-center from the title (logo)
size: appBarHeight - 8.0),
leading: leadingButton,
title: SizedBox(
height: appBarHeight - 10.0,
child: Image.asset('assets/10101_logo_icon.png'),
),
actions: const [
StatusIconButton(),
]));
}
}

Route _createRoute() {
Route _createSettingsRoute() {
return PageRouteBuilder(
pageBuilder: (context, animation, secondaryAnimation) => const SettingsScreen(),
transitionsBuilder: (context, animation, secondaryAnimation, child) {
Expand Down
2 changes: 0 additions & 2 deletions mobile/lib/common/settings_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import 'package:package_info_plus/package_info_plus.dart';
import 'package:get_10101/ffi.dart' as rust;

class SettingsScreen extends StatefulWidget {
static const subRouteName = "settings";

const SettingsScreen({super.key});

@override
Expand Down
48 changes: 48 additions & 0 deletions mobile/lib/common/status_icon_button.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import 'package:flutter/material.dart';
import 'package:get_10101/common/channel_status_notifier.dart';
import 'package:get_10101/common/service_status_notifier.dart';
import 'package:get_10101/common/status_screen.dart';
import 'package:get_10101/bridge_generated/bridge_definitions.dart' as rust;
import 'package:provider/provider.dart';

class StatusIconButton extends StatelessWidget {
const StatusIconButton({super.key});

@override
Widget build(BuildContext context) {
final channelStatusNotifier = context.watch<ChannelStatusNotifier>();
final serviceStatusNotifier = context.watch<ServiceStatusNotifier>();

final overallStatus = serviceStatusNotifier.overall();

return IconButton(
icon: channelStatusNotifier.isClosing() || overallStatus == rust.ServiceStatus.Offline
? const Icon(Icons.thermostat, color: Colors.red)
: overallStatus == rust.ServiceStatus.Unknown
? const Icon(Icons.thermostat, color: Colors.yellow)
: const Icon(Icons.thermostat),
tooltip: 'Status',
onPressed: () {
Navigator.of(context).push(_createStatusRoute());
},
);
}
}

Route _createStatusRoute() {
return PageRouteBuilder(
pageBuilder: (context, animation, secondaryAnimation) => const StatusScreen(),
transitionsBuilder: (context, animation, secondaryAnimation, child) {
const begin = Offset(1.0, 0.0);
const end = Offset.zero;
const curve = Curves.ease;

var tween = Tween(begin: begin, end: end).chain(CurveTween(curve: curve));

return SlideTransition(
position: animation.drive(tween),
child: child,
);
},
);
}
41 changes: 20 additions & 21 deletions mobile/lib/common/status_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import 'package:get_10101/common/value_data_row.dart';
import 'package:provider/provider.dart';

class StatusScreen extends StatefulWidget {
const StatusScreen({required this.fromRoute, super.key});

final String fromRoute;
const StatusScreen({super.key});

@override
State<StatusScreen> createState() => _StatusScreenState();
Expand All @@ -30,7 +28,7 @@ class _StatusScreenState extends State<StatusScreen> {

final channelStatus = channelStatusToString(channelStatusNotifier.getChannelStatus());

var widgets = [
final widgets = [
Padding(
padding: const EdgeInsets.all(32.0),
child: Column(
Expand Down Expand Up @@ -67,25 +65,26 @@ class _StatusScreenState extends State<StatusScreen> {
),
],
)),
Visibility(
visible: channelStatusNotifier.isClosing(),
child: Padding(
padding: const EdgeInsets.all(32.0),
child: RichText(
text: const TextSpan(
style: TextStyle(color: Colors.black, fontSize: 18),
children: [
TextSpan(
text: "Your channel with 10101 is being closed on-chain!\n\n",
style: TextStyle(fontWeight: FontWeight.bold)),
TextSpan(
text:
"Your Lightning funds will return back to your on-chain wallet after some time. You will have to reopen the app at some point in the future so that your node can claim them back.\n\n"),
TextSpan(
text:
"If you had a position open your payout will arrive in your on-chain wallet soon after the expiry time. \n")
]))))
];

if (channelStatusNotifier.isClosing()) {
widgets.add(Padding(
padding: const EdgeInsets.all(32.0),
child: RichText(
text: const TextSpan(style: TextStyle(color: Colors.black, fontSize: 18), children: [
TextSpan(
text: "Your channel with 10101 is being closed on-chain!\n\n",
style: TextStyle(fontWeight: FontWeight.bold)),
TextSpan(
text:
"Your Lightning funds will return back to your on-chain wallet after some time. You will have to reopen the app at some point in the future so that your node can claim them back.\n\n"),
TextSpan(
text:
"If you had a position open your payout will arrive in your on-chain wallet soon after the expiry time. \n")
]))));
}

return Scaffold(
appBar: AppBar(title: const Text("Status")),
body: ScrollableSafeArea(
Expand Down
15 changes: 0 additions & 15 deletions mobile/lib/features/trade/status_screen.dart

This file was deleted.

15 changes: 0 additions & 15 deletions mobile/lib/features/wallet/status_screen.dart

This file was deleted.

30 changes: 1 addition & 29 deletions mobile/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import 'package:get_10101/features/trade/domain/position.dart';
import 'package:get_10101/common/domain/service_status.dart';
import 'package:get_10101/features/trade/order_change_notifier.dart';
import 'package:get_10101/features/trade/position_change_notifier.dart';
import 'package:get_10101/features/trade/status_screen.dart';
import 'package:get_10101/features/trade/submit_order_change_notifier.dart';
import 'package:get_10101/features/trade/trade_value_change_notifier.dart';
import 'package:get_10101/features/trade/trade_theme.dart';
Expand All @@ -38,7 +37,6 @@ import 'package:get_10101/features/wallet/share_invoice_screen.dart';
import 'package:get_10101/features/wallet/scanner_screen.dart';
import 'package:get_10101/features/wallet/send_screen.dart';
import 'package:get_10101/features/trade/trade_screen.dart';
import 'package:get_10101/features/wallet/status_screen.dart';
import 'package:get_10101/features/wallet/wallet_change_notifier.dart';
import 'package:get_10101/features/wallet/wallet_screen.dart';
import 'package:get_10101/common/app_bar_wrapper.dart';
Expand All @@ -57,7 +55,6 @@ import 'package:get_10101/features/trade/domain/price.dart';
import 'package:get_10101/features/wallet/domain/wallet_info.dart';
import 'package:get_10101/ffi.dart' as rust;
import 'package:version/version.dart';
import 'common/settings_screen.dart';

final GlobalKey<NavigatorState> _rootNavigatorKey = GlobalKey<NavigatorState>(debugLabel: 'root');
final GlobalKey<NavigatorState> _shellNavigatorKey = GlobalKey<NavigatorState>(debugLabel: 'shell');
Expand Down Expand Up @@ -177,39 +174,14 @@ class _TenTenOneAppState extends State<TenTenOneApp> {
return const ScannerScreen();
},
),
GoRoute(
path: SettingsScreen.subRouteName,
parentNavigatorKey: _rootNavigatorKey,
builder: (BuildContext context, GoRouterState state) {
return const SettingsScreen();
}),
GoRoute(
path: WalletStatusScreen.subRouteName,
parentNavigatorKey: _rootNavigatorKey,
builder: (BuildContext context, GoRouterState state) {
return const WalletStatusScreen();
})
],
),
GoRoute(
path: TradeScreen.route,
builder: (BuildContext context, GoRouterState state) {
return const TradeScreen();
},
routes: <RouteBase>[
GoRoute(
path: SettingsScreen.subRouteName,
parentNavigatorKey: _rootNavigatorKey,
builder: (BuildContext context, GoRouterState state) {
return const SettingsScreen();
}),
GoRoute(
path: TradeStatusScreen.subRouteName,
parentNavigatorKey: _rootNavigatorKey,
builder: (BuildContext context, GoRouterState state) {
return const TradeStatusScreen();
})
],
routes: const [],
),
],
),
Expand Down
12 changes: 12 additions & 0 deletions mobile/macos/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
PODS:
- device_info_plus (0.0.1):
- FlutterMacOS
- Firebase/CoreOnly (10.12.0):
- FirebaseCore (= 10.12.0)
- Firebase/Messaging (10.12.0):
Expand Down Expand Up @@ -72,8 +74,11 @@ PODS:
- shared_preferences_foundation (0.0.1):
- Flutter
- FlutterMacOS
- url_launcher_macos (0.0.1):
- FlutterMacOS

DEPENDENCIES:
- device_info_plus (from `Flutter/ephemeral/.symlinks/plugins/device_info_plus/macos`)
- firebase_core (from `Flutter/ephemeral/.symlinks/plugins/firebase_core/macos`)
- firebase_messaging (from `Flutter/ephemeral/.symlinks/plugins/firebase_messaging/macos`)
- flutter_local_notifications (from `Flutter/ephemeral/.symlinks/plugins/flutter_local_notifications/macos`)
Expand All @@ -82,6 +87,7 @@ DEPENDENCIES:
- path_provider_foundation (from `Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/darwin`)
- share_plus (from `Flutter/ephemeral/.symlinks/plugins/share_plus/macos`)
- shared_preferences_foundation (from `Flutter/ephemeral/.symlinks/plugins/shared_preferences_foundation/darwin`)
- url_launcher_macos (from `Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos`)

SPEC REPOS:
trunk:
Expand All @@ -96,6 +102,8 @@ SPEC REPOS:
- PromisesObjC

EXTERNAL SOURCES:
device_info_plus:
:path: Flutter/ephemeral/.symlinks/plugins/device_info_plus/macos
firebase_core:
:path: Flutter/ephemeral/.symlinks/plugins/firebase_core/macos
firebase_messaging:
Expand All @@ -112,8 +120,11 @@ EXTERNAL SOURCES:
:path: Flutter/ephemeral/.symlinks/plugins/share_plus/macos
shared_preferences_foundation:
:path: Flutter/ephemeral/.symlinks/plugins/shared_preferences_foundation/darwin
url_launcher_macos:
:path: Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos

SPEC CHECKSUMS:
device_info_plus: 5401765fde0b8d062a2f8eb65510fb17e77cf07f
Firebase: 07150e75d142fb9399f6777fa56a187b17f833a0
firebase_core: ff59797157ca9adda4440071643761b41fcd03b3
firebase_messaging: d489df2f5cf5eb4b1ffb0b920f1d8c6b911f6166
Expand All @@ -131,6 +142,7 @@ SPEC CHECKSUMS:
PromisesObjC: c50d2056b5253dadbd6c2bea79b0674bd5a52fa4
share_plus: 76dd39142738f7a68dd57b05093b5e8193f220f7
shared_preferences_foundation: 5b919d13b803cadd15ed2dc053125c68730e5126
url_launcher_macos: d2691c7dd33ed713bf3544850a623080ec693d95

PODFILE CHECKSUM: f429f80f5470aff39540e8333365097246b857cb

Expand Down

0 comments on commit ac48bce

Please sign in to comment.