From 695222ae44af2809778539f46343f6572c8ef30c Mon Sep 17 00:00:00 2001 From: Dennis Fokin Date: Mon, 24 Jul 2023 14:15:19 +0200 Subject: [PATCH] l10n: account already exists --- lib/l10n/app_en.arb | 1 + lib/oath/views/migrate_account_page.dart | 21 ++++++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 75a8b19c..deaccc6e 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -247,6 +247,7 @@ }, "l_account_name_required": "Your account must have a name", "l_name_already_exists": "This name already exists for the issuer", + "l_account_already_exists": "This account already exists on the YubiKey", "l_invalid_character_issuer": "Invalid character: ':' is not allowed in issuer", "l_select_accounts" : "Select account(s) to add to the YubiKey", "s_pinned": "Pinned", diff --git a/lib/oath/views/migrate_account_page.dart b/lib/oath/views/migrate_account_page.dart index 3cc570aa..2025518f 100644 --- a/lib/oath/views/migrate_account_page.dart +++ b/lib/oath/views/migrate_account_page.dart @@ -2,10 +2,12 @@ import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:logging/logging.dart'; import 'package:yubico_authenticator/app/logging.dart'; +import 'package:yubico_authenticator/exception/apdu_exception.dart'; import 'package:yubico_authenticator/theme.dart'; import '../../android/oath/state.dart'; import '../../app/models.dart'; +import '../../desktop/models.dart'; import '../../widgets/responsive_dialog.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; @@ -148,7 +150,7 @@ class _MigrateAccountPageState extends ConsumerState { softWrap: false), if (!uniqueCreds[cred]!) Text( - l10n.l_name_already_exists, + l10n.l_account_already_exists, style: const TextStyle( color: primaryRed, fontSize: 12, @@ -250,6 +252,7 @@ class _MigrateAccountPageState extends ConsumerState { {DevicePath? devicePath, required Uri credUri, bool? requireTouch}) async { + final l10n = AppLocalizations.of(context)!; try { if (devicePath == null) { assert(isAndroid, 'devicePath is only optional for Android'); @@ -261,13 +264,25 @@ class _MigrateAccountPageState extends ConsumerState { } if (!mounted) return; //Navigator.of(context).pop(); - showMessage(context, 'added'); + showMessage(context, l10n.s_account_added); } on CancellationException catch (_) { // ignored } catch (e) { - _log.debug('Failed to add account'); + _log.error('Failed to add account', e); final String errorMessage; // TODO: Make this cleaner than importing desktop specific RpcError. + if (e is RpcError) { + errorMessage = e.message; + } else if (e is ApduException) { + errorMessage = e.message; + } else { + errorMessage = e.toString(); + } + showMessage( + context, + l10n.l_account_add_failed(errorMessage), + duration: const Duration(seconds: 4), + ); } } }