diff --git a/lib/pages/add_wallet_views/restore_wallet_view/sub_widgets/restore_failed_dialog.dart b/lib/pages/add_wallet_views/restore_wallet_view/sub_widgets/restore_failed_dialog.dart index ea77f9d33..02f4e714b 100644 --- a/lib/pages/add_wallet_views/restore_wallet_view/sub_widgets/restore_failed_dialog.dart +++ b/lib/pages/add_wallet_views/restore_wallet_view/sub_widgets/restore_failed_dialog.dart @@ -13,6 +13,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:stackwallet/providers/global/secure_store_provider.dart'; import 'package:stackwallet/providers/providers.dart'; import 'package:stackwallet/themes/stack_colors.dart'; +import 'package:stackwallet/utilities/logger.dart'; import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/wallets/isar/providers/wallet_info_provider.dart'; import 'package:stackwallet/widgets/stack_dialog.dart'; @@ -65,13 +66,21 @@ class _RestoreFailedDialogState extends ConsumerState { style: STextStyles.itemSubtitle12(context), ), onPressed: () async { - await ref.read(pWallets).deleteWallet( - ref.read(pWalletInfo(walletId)), - ref.read(secureStoreProvider), - ); - - if (mounted) { - Navigator.of(context).pop(); + try { + await ref.read(pWallets).deleteWallet( + ref.read(pWalletInfo(walletId)), + ref.read(secureStoreProvider), + ); + } catch (e, s) { + Logging.instance.log( + "Error while getting wallet info in restore failed dialog\n" + "Error: $e\nStack trace: $s", + level: LogLevel.Error, + ); + } finally { + if (mounted) { + Navigator.of(context).pop(); + } } }, ), diff --git a/lib/services/wallets.dart b/lib/services/wallets.dart index b56a6b090..729b863ee 100644 --- a/lib/services/wallets.dart +++ b/lib/services/wallets.dart @@ -42,7 +42,13 @@ class Wallets { final Map _wallets = {}; - Wallet getWallet(String walletId) => _wallets[walletId]!; + Wallet getWallet(String walletId) { + if (_wallets[walletId] != null) { + return _wallets[walletId]!; + } else { + throw Exception("Wallet with id $walletId not found"); + } + } void addWallet(Wallet wallet) { if (_wallets[wallet.walletId] != null) {