chore: Improved error handling for recovery key

This commit is contained in:
Krille 2024-02-01 07:56:39 +01:00
commit 2af8691536
No known key found for this signature in database
GPG key ID: E067ECD60F1A0652
2 changed files with 17 additions and 9 deletions

View file

@ -266,6 +266,7 @@ class BootstrapDialogState extends State<BootstrapDialog> {
), ),
hintText: L10n.of(context)!.recoveryKey, hintText: L10n.of(context)!.recoveryKey,
errorText: _recoveryKeyInputError, errorText: _recoveryKeyInputError,
errorMaxLines: 2,
), ),
), ),
const SizedBox(height: 16), const SizedBox(height: 16),
@ -290,6 +291,7 @@ class BootstrapDialogState extends State<BootstrapDialog> {
final key = _recoveryKeyTextEditingController final key = _recoveryKeyTextEditingController
.text .text
.trim(); .trim();
if (key.isEmpty) return;
await bootstrap.newSsssKey!.unlock( await bootstrap.newSsssKey!.unlock(
keyOrPassphrase: key, keyOrPassphrase: key,
); );
@ -317,6 +319,11 @@ class BootstrapDialogState extends State<BootstrapDialog> {
() => _recoveryKeyInputError = () => _recoveryKeyInputError =
e.toLocalizedString(context), e.toLocalizedString(context),
); );
} on FormatException catch (_) {
setState(
() => _recoveryKeyInputError =
L10n.of(context)!.wrongRecoveryKey,
);
} catch (e, s) { } catch (e, s) {
ErrorReporter( ErrorReporter(
context, context,

View file

@ -163,15 +163,16 @@ class HomeserverPickerController extends State<HomeserverPicker> {
List<IdentityProvider>? get identityProviders { List<IdentityProvider>? get identityProviders {
final loginTypes = _rawLoginTypes; final loginTypes = _rawLoginTypes;
if (loginTypes == null) return null; if (loginTypes == null) return null;
final List? rawProviders = loginTypes.tryGetList('flows')!.singleWhere( final List? rawProviders =
(flow) => flow['type'] == AuthenticationTypes.sso, loginTypes.tryGetList('flows')?.singleWhereOrNull(
)['identity_providers'] ?? (flow) => flow['type'] == AuthenticationTypes.sso,
[ )['identity_providers'] ??
{'id': null}, [
]; {'id': null},
final list = (rawProviders as List) ];
.map((json) => IdentityProvider.fromJson(json)) if (rawProviders == null) return null;
.toList(); final list =
rawProviders.map((json) => IdentityProvider.fromJson(json)).toList();
if (PlatformInfos.isCupertinoStyle) { if (PlatformInfos.isCupertinoStyle) {
list.sort((a, b) => a.brand == 'apple' ? -1 : 1); list.sort((a, b) => a.brand == 'apple' ? -1 : 1);
} }