handle more ledger cases [skip ci]
OmarHatem committed
Aug 4, 2025 at 03:47 UTC
1312bd00de6146875570829f7c304ee4044fbe08
5 files changed
+15
-20
cw_monero/lib/monero_wallet_service.dart
-1
@@ -22,7 +22,6 @@ import 'package:cw_monero/ledger.dart';
22
import 'package:cw_monero/monero_wallet.dart';
23
import 'package:hive/hive.dart';
24
import 'package:ledger_flutter_plus/ledger_flutter_plus.dart';
25
-import 'package:monero/src/monero.dart' as m;
25
import 'package:monero/monero.dart' as monero;
26
import 'package:polyseed/polyseed.dart';
27
lib/entities/load_current_wallet.dart
+3
-10
@@ -7,12 +7,8 @@ import 'package:cake_wallet/core/wallet_loading_service.dart';
7
8
Future<void> loadCurrentWallet({String? password}) async {
9
final appStore = getIt.get<AppStore>();
10
- final name = getIt
11
- .get<SharedPreferences>()
12
- .getString(PreferencesKey.currentWalletName);
13
- final typeRaw =
14
- getIt.get<SharedPreferences>().getInt(PreferencesKey.currentWalletType) ??
15
- 0;
10
+ final name = getIt.get<SharedPreferences>().getString(PreferencesKey.currentWalletName);
11
+ final typeRaw = getIt.get<SharedPreferences>().getInt(PreferencesKey.currentWalletType) ?? 0;
12
13
if (name == null) {
14
throw Exception('Incorrect current wallet name: $name');
@@ -20,9 +16,6 @@ Future<void> loadCurrentWallet({String? password}) async {
16
17
final type = deserializeFromInt(typeRaw);
18
final walletLoadingService = getIt.get<WalletLoadingService>();
23
- final wallet = await walletLoadingService.load(
24
- type,
25
- name,
26
- password: password);
19
+ final wallet = await walletLoadingService.load(type, name, password: password);
20
await appStore.changeCurrentWallet(wallet);
21
}
lib/reactions/on_authentication_state_change.dart
+3
-8
@@ -78,18 +78,13 @@ void startAuthenticationStateChange(
78
await loadCurrentWallet();
79
tryOpening = false;
80
} on Exception catch (e) {
81
- final errorCode = RegExp(r'0x\S*?(?= )').firstMatch(
82
- e.toString());
83
-
84
- final errorMessage = ledgerVM.interpretErrorCode(
85
- errorCode?.group(0).toString().replaceAll("0x", "") ??
86
- "");
87
- if (errorMessage != null) {
81
+ final ledgerErrorMessage = ledgerVM.interpretErrorCode(e.toString());
82
+ if (ledgerErrorMessage != null) {
83
await showPopUp<void>(
84
context: context,
85
builder: (context) => AlertWithTwoActions(
86
alertTitle: "Ledger Error",
92
- alertContent: errorMessage,
87
+ alertContent: ledgerErrorMessage,
88
leftButtonText: S.of(context).try_again,
89
alertBarrierDismissible: false,
90
actionLeftButton: () => Navigator.of(context).pop(),
lib/utils/exception_handler.dart
+1
@@ -191,6 +191,7 @@ class ExceptionHandler {
191
'PlatformException(133, Failed to write: (Unknown Error: 133), null, null)',
192
'PlatformException(IllegalArgument, Unknown deviceId:',
193
'ServiceNotSupportedException(ConnectionType.ble, Required service not supported. Write characteristic: false, Notify characteristic: false)',
194
+ 'Make sure no other program is communicating with the Ledger',
195
'Exception: 6e01', // Wrong App
196
'Exception: 6d02',
197
'Exception: 6511',
lib/view_model/hardware_wallet/ledger_view_model.dart
+8
-1
@@ -173,7 +173,14 @@ abstract class LedgerViewModelBase with Store {
173
}
174
}
175
176
- String? interpretErrorCode(String errorCode) {
176
+ String? interpretErrorCode(String error) {
177
+ if (error.contains("Make sure no other program is communicating with the Ledger")) {
178
+ return error;
179
+ }
180
+
181
+ var errorRegex = RegExp(r'0x\S*?(?= )').firstMatch(error.toString());
182
+
183
+ String errorCode = errorRegex?.group(0).toString().replaceAll("0x", "") ?? "";
184
if (errorCode.contains("6985")) {
185
return S.current.ledger_error_tx_rejected_by_user;
186
} else if (errorCode.contains("5515")) {