Skip to content

Commit

Permalink
Merge branch 'no-connection-dialog'
Browse files Browse the repository at this point in the history
* no-connection-dialog:
  Show an error dialog if no connection when checking updates
  Rename "no connection" to "unexpected error"
  • Loading branch information
roeierez committed Jun 20, 2021
2 parents 2c99685 + c6aae8b commit 7c99429
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 16 deletions.
28 changes: 18 additions & 10 deletions lib/handlers/check_version_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,23 @@ import 'package:flushbar/flushbar.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:breez/widgets/no_connection_dialog.dart';

class CheckVersionHandler {
final BuildContext context;
final UserProfileBloc userProfileBloc;

CheckVersionHandler(this.context, this.userProfileBloc) {
CheckVersion action = CheckVersion();
userProfileBloc.userActionsSink.add(action);
action.future.catchError((err) {
void checkVersionDialog(BuildContext context, UserProfileBloc userProfileBloc) {
CheckVersion action = CheckVersion();
userProfileBloc.userActionsSink.add(action);
action.future.catchError((err) {
if (err.contains('connection error')) {
showNoConnectionDialog(context).then((retry) {
print("-- showNoConnectionDialog --");
print(retry);
if (retry == true) {
Future.delayed(Duration(seconds: 1), () {
checkVersionDialog(context, userProfileBloc);
});
}
});
} else {
showFlushbar(context, buttonText: "UPDATE", onDismiss: () {
if (defaultTargetPlatform == TargetPlatform.iOS) {
launch("https://testflight.apple.com/join/wPju2Du7");
Expand All @@ -28,6 +36,6 @@ class CheckVersionHandler {
duration: Duration.zero,
messageWidget: Text("Please update Breez to the latest version.",
style: theme.snackBarStyle, textAlign: TextAlign.center));
});
}
}
});
}
6 changes: 3 additions & 3 deletions lib/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ import 'handlers/sync_ui_handler.dart';
import 'routes/account_required_actions.dart';
import 'routes/connect_to_pay/connect_to_pay_page.dart';
import 'routes/home/account_page.dart';
import 'routes/no_connection_dialog.dart';
import 'routes/unexpected_error_dialog.dart';

final GlobalKey firstPaymentItemKey = GlobalKey();
final ScrollController scrollController = ScrollController();
Expand Down Expand Up @@ -106,7 +106,7 @@ class HomeState extends State<Home> with WidgetsBindingObserver {
audioBloc.transitionLifecycleState(LifecyleState.resume);

_registerNotificationHandlers();
listenNoConnection(context, widget.accountBloc);
listenUnexpectedError(context, widget.accountBloc);
_listenBackupConflicts();
_listenWhitelistPermissionsRequest();
_listenLSPSelectionPrompt();
Expand Down Expand Up @@ -712,7 +712,7 @@ class HomeState extends State<Home> with WidgetsBindingObserver {
messageWidget: LoadingAnimatedText("Broadcasting your transaction",
textStyle: theme.snackBarStyle, textAlign: TextAlign.left));
});
CheckVersionHandler(context, widget.userProfileBloc);
checkVersionDialog(context, widget.userProfileBloc);
}

void _listenBackupConflicts() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:share_extend/share_extend.dart';

void listenNoConnection(BuildContext context, AccountBloc accountBloc) {
void listenUnexpectedError(BuildContext context, AccountBloc accountBloc) {
accountBloc.lightningDownStream.listen((allowRetry) {
promptError(
context,
"No Internet Connection",
"Unexpected Error",
RichText(
text: TextSpan(
style: Theme.of(context).dialogTheme.contentTextStyle,
Expand Down Expand Up @@ -86,7 +86,9 @@ void listenNoConnection(BuildContext context, AccountBloc accountBloc) {
// "You can try:\n• Turning off airplane mode\n• Turning on mobile data or Wi-Fi\n• Checking the signal in your area",
// style: Theme.of(context).dialogTheme.contentTextStyle),
okText: allowRetry ? "TRY AGAIN" : "EXIT",
okFunc: allowRetry ? () => accountBloc.userActionsSink.add(RestartDaemon()) : () => exit(0),
okFunc: allowRetry
? () => accountBloc.userActionsSink.add(RestartDaemon())
: () => exit(0),
optionText: allowRetry ? "EXIT" : null,
optionFunc: () => exit(0),
disableBack: true,
Expand Down
76 changes: 76 additions & 0 deletions lib/widgets/no_connection_dialog.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import 'dart:async';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/gestures.dart';

import 'package:share_extend/share_extend.dart';

import 'package:breez/services/injector.dart';
import 'package:breez/theme_data.dart' as theme;

Future<bool> showNoConnectionDialog(BuildContext context) {
return showDialog<bool>(
useRootNavigator: false,
context: context,
barrierDismissible: false, // user must tap button!
builder: (BuildContext context) {
return AlertDialog(
contentPadding: EdgeInsets.fromLTRB(16.0, 16.0, 16.0, 0.0),
title: Text(
"No Internet Connection",
style: Theme.of(context).dialogTheme.titleTextStyle,
),
content: SingleChildScrollView(
child: RichText(
text: TextSpan(
style: Theme.of(context).dialogTheme.contentTextStyle,
text: "You can try:\n",
children: <TextSpan>[
TextSpan(
text: "• Turning off airplane mode\n",
style: Theme.of(context).dialogTheme.contentTextStyle),
TextSpan(
text: "• Turning on mobile data or Wi-Fi\n",
style: Theme.of(context).dialogTheme.contentTextStyle),
TextSpan(
text: "• Checking the signal in your area\n",
style: Theme.of(context).dialogTheme.contentTextStyle),
TextSpan(
text: "• ",
style: Theme.of(context).dialogTheme.contentTextStyle),
TextSpan(
text: "View ",
style: theme.blueLinkStyle,
recognizer: TapGestureRecognizer()
..onTap = () async {
var logPath = await ServiceInjector()
.breezBridge
.getLogPath();
ShareExtend.share(logPath, "file");
}),
TextSpan(
text: "your logs \n",
style: Theme.of(context).dialogTheme.contentTextStyle),
]),
),
),
actions: <Widget>[
TextButton(
child: Text("CANCEL",
style: Theme.of(context).primaryTextTheme.button),
onPressed: () {
Navigator.of(context).pop(false);
},
),
TextButton(
child: Text("TRY AGAIN",
style: Theme.of(context).primaryTextTheme.button),
onPressed: () {
Navigator.of(context).pop(true);
},
),
],
);
});
}

0 comments on commit 7c99429

Please sign in to comment.