diff --git a/lib/pages/exchange_view/choose_from_stack_view.dart b/lib/pages/exchange_view/choose_from_stack_view.dart index d4cc11dac..99ba9bc75 100644 --- a/lib/pages/exchange_view/choose_from_stack_view.dart +++ b/lib/pages/exchange_view/choose_from_stack_view.dart @@ -14,6 +14,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart'; import '../../providers/providers.dart'; import '../../themes/stack_colors.dart'; import '../../utilities/constants.dart'; +import '../../utilities/logger.dart'; import '../../utilities/text_styles.dart'; import '../../wallets/crypto_currency/crypto_currency.dart'; import '../../wallets/isar/providers/wallet_info_provider.dart'; @@ -50,7 +51,16 @@ class _ChooseFromStackViewState extends ConsumerState { ref .watch(pWallets) .wallets - .where((e) => e.info.coin == coin) + .where((e) { + try { + return e.info.coin == coin; + } catch (ex) { + Logging.instance.e( + "Error while filtering wallets for ${coin.ticker}: $ex", + ); + return false; + } + }) .map((e) => e.walletId) .toList(); diff --git a/lib/pages/wallets_view/wallets_overview.dart b/lib/pages/wallets_view/wallets_overview.dart index 7ba524713..5da519908 100644 --- a/lib/pages/wallets_view/wallets_overview.dart +++ b/lib/pages/wallets_view/wallets_overview.dart @@ -23,6 +23,7 @@ import '../../services/event_bus/global_event_bus.dart'; import '../../themes/stack_colors.dart'; import '../../utilities/assets.dart'; import '../../utilities/constants.dart'; +import '../../utilities/logger.dart'; import '../../utilities/text_styles.dart'; import '../../utilities/util.dart'; import '../../wallets/crypto_currency/crypto_currency.dart'; @@ -130,7 +131,17 @@ class _EthWalletsOverviewState extends ConsumerState { void updateWallets() { final walletsData = ref.read(pAllWalletsInfo); - walletsData.removeWhere((e) => e.coin != widget.coin); + walletsData.removeWhere((e) { + try { + return e.coin != widget.coin; + } catch (ex) { + // Remove wallets with unknown/unsupported coins. + Logging.instance.e( + "Error while filtering wallets for ${e.coin.ticker}: $ex", + ); + return true; + } + }); if (widget.coin is Ethereum) { for (final data in walletsData) { diff --git a/lib/pages_desktop_specific/my_stack_view/coin_wallets_table.dart b/lib/pages_desktop_specific/my_stack_view/coin_wallets_table.dart index aaf1d1402..9a137a28c 100644 --- a/lib/pages_desktop_specific/my_stack_view/coin_wallets_table.dart +++ b/lib/pages_desktop_specific/my_stack_view/coin_wallets_table.dart @@ -17,6 +17,7 @@ import '../../providers/global/prefs_provider.dart'; import '../../providers/global/wallets_provider.dart'; import '../../themes/stack_colors.dart'; import '../../utilities/constants.dart'; +import '../../utilities/logger.dart'; import '../../utilities/show_loading.dart'; import '../../utilities/show_node_tor_settings_mismatch.dart'; import '../../utilities/util.dart'; @@ -27,21 +28,28 @@ import '../../widgets/wallet_info_row/wallet_info_row.dart'; import 'wallet_view/desktop_wallet_view.dart'; class CoinWalletsTable extends ConsumerWidget { - const CoinWalletsTable({ - super.key, - required this.coin, - }); + const CoinWalletsTable({super.key, required this.coin}); final CryptoCurrency coin; @override Widget build(BuildContext context, WidgetRef ref) { - final walletIds = ref - .watch(pWallets) - .wallets - .where((e) => e.info.coin == coin) - .map((e) => e.walletId) - .toList(); + final walletIds = + ref + .watch(pWallets) + .wallets + .where((e) { + try { + return e.info.coin == coin; + } catch (ex) { + Logging.instance.e( + "Error while filtering wallets for ${coin.ticker}: $ex", + ); + return false; + } + }) + .map((e) => e.walletId) + .toList(); return Container( decoration: BoxDecoration( diff --git a/lib/wallets/isar/models/wallet_info.dart b/lib/wallets/isar/models/wallet_info.dart index 9d790a830..f5dd4a78e 100644 --- a/lib/wallets/isar/models/wallet_info.dart +++ b/lib/wallets/isar/models/wallet_info.dart @@ -102,7 +102,13 @@ class WalletInfo implements IsarId { } @ignore - CryptoCurrency get coin => AppConfig.getCryptoCurrencyFor(coinName)!; + CryptoCurrency get coin { + final result = AppConfig.getCryptoCurrencyFor(coinName); + if (result == null) { + throw Exception('Unknown cryptocurrency: $coinName for wallet $walletId'); + } + return result; + } @ignore Balance get cachedBalance { diff --git a/lib/widgets/node_card.dart b/lib/widgets/node_card.dart index 85f16a135..70c7fa541 100644 --- a/lib/widgets/node_card.dart +++ b/lib/widgets/node_card.dart @@ -26,6 +26,7 @@ import '../utilities/assets.dart'; import '../utilities/constants.dart'; import '../utilities/default_nodes.dart'; import '../utilities/enums/sync_type_enum.dart'; +import '../utilities/logger.dart'; import '../utilities/test_node_connection.dart'; import '../utilities/text_styles.dart'; import '../utilities/tor_plain_net_option_enum.dart'; @@ -59,8 +60,16 @@ class _NodeCardState extends ConsumerState { bool _advancedIsExpanded = false; Future _notifyWalletsOfUpdatedNode(WidgetRef ref) async { - final wallets = - ref.read(pWallets).wallets.where((e) => e.info.coin == widget.coin); + final wallets = ref.read(pWallets).wallets.where((e) { + try { + return e.info.coin == widget.coin; + } catch (ex) { + Logging.instance.e( + "Error while filtering wallets for ${widget.coin}: $ex", + ); + return false; + } + }); final prefs = ref.read(prefsChangeNotifierProvider); switch (prefs.syncType) { diff --git a/lib/widgets/node_options_sheet.dart b/lib/widgets/node_options_sheet.dart index 511be2395..0b17ec62d 100644 --- a/lib/widgets/node_options_sheet.dart +++ b/lib/widgets/node_options_sheet.dart @@ -25,6 +25,7 @@ import '../utilities/assets.dart'; import '../utilities/constants.dart'; import '../utilities/default_nodes.dart'; import '../utilities/enums/sync_type_enum.dart'; +import '../utilities/logger.dart'; import '../utilities/test_node_connection.dart'; import '../utilities/text_styles.dart'; import '../utilities/tor_plain_net_option_enum.dart'; @@ -44,8 +45,16 @@ class NodeOptionsSheet extends ConsumerWidget { final String popBackToRoute; Future _notifyWalletsOfUpdatedNode(WidgetRef ref) async { - final wallets = - ref.read(pWallets).wallets.where((e) => e.info.coin == coin); + final wallets = ref.read(pWallets).wallets.where((e) { + try { + return e.info.coin == coin; + } catch (ex) { + Logging.instance.e( + "Error while filtering wallets for ${coin.ticker}: $ex", + ); + return false; + } + }); final prefs = ref.read(prefsChangeNotifierProvider); switch (prefs.syncType) {