From 2efbad0501c58d7169d19e683f940df439ed5c8f Mon Sep 17 00:00:00 2001 From: Dain Nilsson Date: Tue, 5 Apr 2022 13:02:11 +0200 Subject: [PATCH] Show message on OATH add account failure. --- lib/oath/views/add_account_page.dart | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/oath/views/add_account_page.dart b/lib/oath/views/add_account_page.dart index 506b36d5..5575f031 100755 --- a/lib/oath/views/add_account_page.dart +++ b/lib/oath/views/add_account_page.dart @@ -4,6 +4,7 @@ import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:logging/logging.dart'; import '../../app/message.dart'; import '../../app/state.dart'; @@ -14,6 +15,8 @@ import '../models.dart'; import '../state.dart'; import 'utils.dart'; +final _log = Logger('oath.view.add_account_page'); + final _secretFormatterPattern = RegExp('[abcdefghijklmnopqrstuvwxyz234567 ]', caseSensitive: false); @@ -340,7 +343,7 @@ class _OathAddAccountPageState extends ConsumerState { actions: [ TextButton( onPressed: isValid - ? () { + ? () async { if (secretLengthValid) { final issuer = _issuerController.text; @@ -354,12 +357,17 @@ class _OathAddAccountPageState extends ConsumerState { period: period, ); - ref - .read( - credentialListProvider(widget.devicePath).notifier) - .addAccount(cred.toUri(), requireTouch: _touch); - Navigator.of(context).pop(); - showMessage(context, 'Account added'); + try { + await ref + .read(credentialListProvider(widget.devicePath) + .notifier) + .addAccount(cred.toUri(), requireTouch: _touch); + Navigator.of(context).pop(); + showMessage(context, 'Account added'); + } catch (e) { + _log.severe('Failed to add account', e); + showMessage(context, 'Failed adding account'); + } } else { setState(() { _validateSecretLength = true;