From 2af86915362ab929ebe97e3fd966e3c7d8f8cd30 Mon Sep 17 00:00:00 2001 From: Krille Date: Thu, 1 Feb 2024 07:56:39 +0100 Subject: [PATCH] chore: Improved error handling for recovery key --- lib/pages/bootstrap/bootstrap_dialog.dart | 7 +++++++ .../homeserver_picker/homeserver_picker.dart | 19 ++++++++++--------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/lib/pages/bootstrap/bootstrap_dialog.dart b/lib/pages/bootstrap/bootstrap_dialog.dart index 7aa27fa82..8bf4f4b02 100644 --- a/lib/pages/bootstrap/bootstrap_dialog.dart +++ b/lib/pages/bootstrap/bootstrap_dialog.dart @@ -266,6 +266,7 @@ class BootstrapDialogState extends State { ), hintText: L10n.of(context)!.recoveryKey, errorText: _recoveryKeyInputError, + errorMaxLines: 2, ), ), const SizedBox(height: 16), @@ -290,6 +291,7 @@ class BootstrapDialogState extends State { final key = _recoveryKeyTextEditingController .text .trim(); + if (key.isEmpty) return; await bootstrap.newSsssKey!.unlock( keyOrPassphrase: key, ); @@ -317,6 +319,11 @@ class BootstrapDialogState extends State { () => _recoveryKeyInputError = e.toLocalizedString(context), ); + } on FormatException catch (_) { + setState( + () => _recoveryKeyInputError = + L10n.of(context)!.wrongRecoveryKey, + ); } catch (e, s) { ErrorReporter( context, diff --git a/lib/pages/homeserver_picker/homeserver_picker.dart b/lib/pages/homeserver_picker/homeserver_picker.dart index 9cfbf911a..659f5ff77 100644 --- a/lib/pages/homeserver_picker/homeserver_picker.dart +++ b/lib/pages/homeserver_picker/homeserver_picker.dart @@ -163,15 +163,16 @@ class HomeserverPickerController extends State { List? get identityProviders { final loginTypes = _rawLoginTypes; if (loginTypes == null) return null; - final List? rawProviders = loginTypes.tryGetList('flows')!.singleWhere( - (flow) => flow['type'] == AuthenticationTypes.sso, - )['identity_providers'] ?? - [ - {'id': null}, - ]; - final list = (rawProviders as List) - .map((json) => IdentityProvider.fromJson(json)) - .toList(); + final List? rawProviders = + loginTypes.tryGetList('flows')?.singleWhereOrNull( + (flow) => flow['type'] == AuthenticationTypes.sso, + )['identity_providers'] ?? + [ + {'id': null}, + ]; + if (rawProviders == null) return null; + final list = + rawProviders.map((json) => IdentityProvider.fromJson(json)).toList(); if (PlatformInfos.isCupertinoStyle) { list.sort((a, b) => a.brand == 'apple' ? -1 : 1); }