Skip to content

Commit

Permalink
tweak: still show main screen after registration failure
Browse files Browse the repository at this point in the history
  • Loading branch information
Restioson committed Jun 12, 2024
1 parent dc9a5f4 commit b7e8788
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
27 changes: 23 additions & 4 deletions mobile/lib/features/welcome/loading_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class _LoadingScreenState extends State<LoadingScreen> {
}

Future<void> initAsync() async {
bool failedRegistration = false;

try {
await widget.task?.future;
} catch (error, stackTrace) {
Expand All @@ -54,8 +56,7 @@ class _LoadingScreenState extends State<LoadingScreen> {
),
]));

GoRouter.of(rootNavigatorKey.currentContext!).go(Onboarding.route);
return;
failedRegistration = true;
}

final [position, seedPresent, backupRequired, registeredForBeta] = await Future.wait<dynamic>([
Expand All @@ -67,11 +68,29 @@ class _LoadingScreenState extends State<LoadingScreen> {
FlutterNativeSplash.remove();

if (seedPresent) {
if (!registeredForBeta) {
if (!failedRegistration && !registeredForBeta) {
logger.w("Registering for beta program despite having a seed; "
"onboarding flow was probably previously interrupted");
setState(() => message = "Registering for beta program");
await resumeRegisterForBeta();

try {
await resumeRegisterForBeta();
} catch (error, stackTrace) {
logger.e(registerErrorTitle, error: error, stackTrace: stackTrace);
await showDialog(
context: rootNavigatorKey.currentContext!,
builder: (context) => AlertDialog(
title: const Text(registerErrorTitle),
content: const Text(registerErrorBody),
actions: [
TextButton(
onPressed: () {
Navigator.pop(context, 'OK');
},
child: const Text('OK'),
),
]));
}
}

if (backupRequired) {
Expand Down
13 changes: 7 additions & 6 deletions mobile/lib/features/welcome/welcome_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,8 @@ class _WelcomeScreenState extends State<WelcomeScreen> {
_formKey.currentState!.validate()) {
final task = LoadingScreenTask(
future: setupWallet(),
errorTitle: "Failed to register",
errorHelp: "Failed to register "
"for the beta program.\n"
"Check your internet connection. "
"Otherwise, 10101 services may "
"be down for maintenance.");
errorTitle: registerErrorTitle,
errorHelp: registerErrorBody);
GoRouter.of(context).go(LoadingScreen.route, extra: task);
}
},
Expand Down Expand Up @@ -284,6 +280,11 @@ class _WelcomeScreenState extends State<WelcomeScreen> {
}
}

const String registerErrorTitle = "Failed to register";
const String registerErrorBody = "Failed to register for the beta program.\n"
"Check your internet connection. Otherwise, 10101 services may "
"be down for maintenance.";

/// Resume a previously incomplete onboarding flow by registering for beta
Future<void> resumeRegisterForBeta() async {
await api.registerBeta(
Expand Down

0 comments on commit b7e8788

Please sign in to comment.