From b7e878828e23ad3881552aaabd8b63425f84b6fb Mon Sep 17 00:00:00 2001 From: Restioson Date: Wed, 12 Jun 2024 15:00:53 +0200 Subject: [PATCH] tweak: still show main screen after registration failure --- .../lib/features/welcome/loading_screen.dart | 27 ++++++++++++++++--- .../lib/features/welcome/welcome_screen.dart | 13 ++++----- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/mobile/lib/features/welcome/loading_screen.dart b/mobile/lib/features/welcome/loading_screen.dart index 946461fa5..cf655f1d8 100644 --- a/mobile/lib/features/welcome/loading_screen.dart +++ b/mobile/lib/features/welcome/loading_screen.dart @@ -36,6 +36,8 @@ class _LoadingScreenState extends State { } Future initAsync() async { + bool failedRegistration = false; + try { await widget.task?.future; } catch (error, stackTrace) { @@ -54,8 +56,7 @@ class _LoadingScreenState extends State { ), ])); - GoRouter.of(rootNavigatorKey.currentContext!).go(Onboarding.route); - return; + failedRegistration = true; } final [position, seedPresent, backupRequired, registeredForBeta] = await Future.wait([ @@ -67,11 +68,29 @@ class _LoadingScreenState extends State { 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) { diff --git a/mobile/lib/features/welcome/welcome_screen.dart b/mobile/lib/features/welcome/welcome_screen.dart index 0737b2050..fac1c66b1 100644 --- a/mobile/lib/features/welcome/welcome_screen.dart +++ b/mobile/lib/features/welcome/welcome_screen.dart @@ -208,12 +208,8 @@ class _WelcomeScreenState extends State { _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); } }, @@ -284,6 +280,11 @@ class _WelcomeScreenState extends State { } } +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 resumeRegisterForBeta() async { await api.registerBeta(