handle more ledger cases [skip ci]

This commit is contained in:
OmarHatem
2025-08-04 03:47:52 +03:00
parent 155b9ab32c
commit 1312bd00de
5 changed files with 15 additions and 20 deletions
-1
View File
@@ -22,7 +22,6 @@ import 'package:cw_monero/ledger.dart';
import 'package:cw_monero/monero_wallet.dart';
import 'package:hive/hive.dart';
import 'package:ledger_flutter_plus/ledger_flutter_plus.dart';
import 'package:monero/src/monero.dart' as m;
import 'package:monero/monero.dart' as monero;
import 'package:polyseed/polyseed.dart';
+3 -10
View File
@@ -7,12 +7,8 @@ import 'package:cake_wallet/core/wallet_loading_service.dart';
Future<void> loadCurrentWallet({String? password}) async {
final appStore = getIt.get<AppStore>();
final name = getIt
.get<SharedPreferences>()
.getString(PreferencesKey.currentWalletName);
final typeRaw =
getIt.get<SharedPreferences>().getInt(PreferencesKey.currentWalletType) ??
0;
final name = getIt.get<SharedPreferences>().getString(PreferencesKey.currentWalletName);
final typeRaw = getIt.get<SharedPreferences>().getInt(PreferencesKey.currentWalletType) ?? 0;
if (name == null) {
throw Exception('Incorrect current wallet name: $name');
@@ -20,9 +16,6 @@ Future<void> loadCurrentWallet({String? password}) async {
final type = deserializeFromInt(typeRaw);
final walletLoadingService = getIt.get<WalletLoadingService>();
final wallet = await walletLoadingService.load(
type,
name,
password: password);
final wallet = await walletLoadingService.load(type, name, password: password);
await appStore.changeCurrentWallet(wallet);
}
@@ -78,18 +78,13 @@ void startAuthenticationStateChange(
await loadCurrentWallet();
tryOpening = false;
} on Exception catch (e) {
final errorCode = RegExp(r'0x\S*?(?= )').firstMatch(
e.toString());
final errorMessage = ledgerVM.interpretErrorCode(
errorCode?.group(0).toString().replaceAll("0x", "") ??
"");
if (errorMessage != null) {
final ledgerErrorMessage = ledgerVM.interpretErrorCode(e.toString());
if (ledgerErrorMessage != null) {
await showPopUp<void>(
context: context,
builder: (context) => AlertWithTwoActions(
alertTitle: "Ledger Error",
alertContent: errorMessage,
alertContent: ledgerErrorMessage,
leftButtonText: S.of(context).try_again,
alertBarrierDismissible: false,
actionLeftButton: () => Navigator.of(context).pop(),
+1
View File
@@ -191,6 +191,7 @@ class ExceptionHandler {
'PlatformException(133, Failed to write: (Unknown Error: 133), null, null)',
'PlatformException(IllegalArgument, Unknown deviceId:',
'ServiceNotSupportedException(ConnectionType.ble, Required service not supported. Write characteristic: false, Notify characteristic: false)',
'Make sure no other program is communicating with the Ledger',
'Exception: 6e01', // Wrong App
'Exception: 6d02',
'Exception: 6511',
@@ -173,7 +173,14 @@ abstract class LedgerViewModelBase with Store {
}
}
String? interpretErrorCode(String errorCode) {
String? interpretErrorCode(String error) {
if (error.contains("Make sure no other program is communicating with the Ledger")) {
return error;
}
var errorRegex = RegExp(r'0x\S*?(?= )').firstMatch(error.toString());
String errorCode = errorRegex?.group(0).toString().replaceAll("0x", "") ?? "";
if (errorCode.contains("6985")) {
return S.current.ledger_error_tx_rejected_by_user;
} else if (errorCode.contains("5515")) {