fix: handle unexpected ViewModel in ledger connection process (#2716)

* fix: handle unexpected ViewModel in ledger connection process * fix: add missing exception handler for `_QueuedFuture.execute` in `exception_handler.dart`

Konstantin Ullrich committed Dec 12, 2025 at 16:32 UTC f122ce0c57e67b8362d70577b33df40d00cb8874
3 files changed +19 -5
lib/reactions/on_authentication_state_change.dart
+14 -1
@@ -61,8 +61,21 @@ void startAuthenticationStateChange(
61 walletType: WalletType.monero,
62 hardwareWalletType: HardwareWalletType.ledger,
63 onConnectDevice: (context, ledgerVM) async {
64 - if (ledgerVM is LedgerViewModel)
64 + if (ledgerVM is LedgerViewModel) {
65 monero!.setGlobalLedgerConnection(ledgerVM.connection);
66 + } else {
67 + await showPopUp<void>(
68 + context: context,
69 + builder: (context) => AlertWithOneAction(
70 + alertTitle: "Unexpected Error",
71 + alertContent:
72 + "Unexpected Error while trying to connect to the device (UnexpectedViewModel: ${ledgerVM.toString()})",
73 + buttonText: S.of(context).try_again,
74 + buttonAction: Navigator.of(context).pop,
75 + ),
76 + );
77 + return;
78 + }
79 showPopUp<void>(
80 context: context,
81 builder: (context) => AlertWithOneAction(
lib/src/screens/wallet_list/wallet_list_page.dart
+4 -4
@@ -29,7 +29,6 @@ import 'package:cake_wallet/view_model/wallet_list/wallet_list_view_model.dart';
29 import 'package:cake_wallet/wallet_type_utils.dart';
30 import 'package:cw_core/currency_for_wallet_type.dart';
31 import 'package:cw_core/wallet_info.dart';
32 -import 'package:cw_core/utils/print_verbose.dart';
32 import 'package:cw_core/wallet_type.dart';
33 import 'package:flutter/material.dart';
34 import 'package:flutter_mobx/flutter_mobx.dart';
@@ -484,10 +483,11 @@ class WalletListBodyState extends State<WalletListBody> {
483 walletType: WalletType.monero,
484 hardwareWalletType: HardwareWalletType.ledger,
485 onConnectDevice: (context, ledgerVM) async {
487 - if (ledgerVM is LedgerViewModel)
486 + if (ledgerVM is LedgerViewModel) {
487 monero!.setGlobalLedgerConnection(ledgerVM.connection);
489 - didConnect = true;
490 - Navigator.of(context).pop();
488 + didConnect = true;
489 + Navigator.of(context).pop();
490 + }
491 },
492 isReconnect: true,
493 ),
lib/utils/exception_handler.dart
+1
@@ -293,6 +293,7 @@ class ExceptionHandler {
293
294 "FocusScopeNode was used after being disposed",
295 "_getDismissibleFlushbar",
296 + "_QueuedFuture.execute (package:universal_ble/src/queue.dart:65)",
297 ];
298
299 static Future<void> _addDeviceInfo(File file) async {