mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-06-28 20:39:51 +00:00
CW-1090-ledger-issues (#2314)
* build: bump ledger_flutter_plus dependencies * fix: handle connection errors occurring during connecting to a ledger device * fix: enhance ledger error handling and improve wallet connection reliability * fix: enhance ledger error handling and improve wallet connection reliability * feat: add localized strings for "Try again" and update Ledger error handling on auth * fix: handle rethrow behavior in onAuthenticationStateChange * fix: improve Ledger error handling and refine error code interpretation * fix: refine Ledger error code interpretation and enhance error handling [skip-ci] * add missing ledger error codes --------- Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
This commit is contained in:
parent
4b137bc968
commit
18c2ba9366
36 changed files with 159 additions and 31 deletions
|
@ -4,8 +4,10 @@ import 'package:cake_wallet/di.dart';
|
|||
import 'package:cake_wallet/entities/preferences_key.dart';
|
||||
import 'package:cake_wallet/generated/i18n.dart';
|
||||
import 'package:cake_wallet/main.dart';
|
||||
import 'package:cake_wallet/src/widgets/alert_with_one_action.dart';
|
||||
import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart';
|
||||
import 'package:cake_wallet/store/app_store.dart';
|
||||
import 'package:cake_wallet/utils/package_info.dart';
|
||||
import 'package:cake_wallet/utils/show_bar.dart';
|
||||
import 'package:cake_wallet/utils/show_pop_up.dart';
|
||||
import 'package:cw_core/root_dir.dart';
|
||||
|
@ -15,7 +17,6 @@ import 'package:flutter/foundation.dart';
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_mailer/flutter_mailer.dart';
|
||||
import 'package:cake_wallet/utils/package_info.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
class ExceptionHandler {
|
||||
|
@ -113,6 +114,8 @@ class ExceptionHandler {
|
|||
}
|
||||
|
||||
static Future<void> onError(FlutterErrorDetails errorDetails) async {
|
||||
if (await onLedgerError(errorDetails)) return;
|
||||
|
||||
if (kDebugMode || kProfileMode) {
|
||||
FlutterError.presentError(errorDetails);
|
||||
printV(errorDetails.toString());
|
||||
|
@ -183,6 +186,57 @@ class ExceptionHandler {
|
|||
_hasError = false;
|
||||
}
|
||||
|
||||
static const List<String> _ledgerErrors = [
|
||||
'Wrong Device Status',
|
||||
'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)',
|
||||
'Exception: 6e01', // Wrong App
|
||||
'Exception: 6d02',
|
||||
'Exception: 6511',
|
||||
'Exception: 6e00',
|
||||
'Exception: 6985',
|
||||
'Exception: 5515',
|
||||
];
|
||||
|
||||
static bool isLedgerError(Object exception) =>
|
||||
_ledgerErrors.any((element) => exception.toString().contains(element));
|
||||
|
||||
static Future<bool> onLedgerError(FlutterErrorDetails errorDetails) async {
|
||||
if (!isLedgerError(errorDetails.exception)) return false;
|
||||
|
||||
String? interpretErrorCode(String errorCode) {
|
||||
if (errorCode.contains("6985")) {
|
||||
return S.current.ledger_error_tx_rejected_by_user;
|
||||
} else if (errorCode.contains("5515")) {
|
||||
return S.current.ledger_error_device_locked;
|
||||
} else
|
||||
if (["6e01", "6d02", "6511", "6e00"].any((e) => errorCode.contains(e))) {
|
||||
return S.current.ledger_error_wrong_app;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
printV(errorDetails.exception);
|
||||
|
||||
if (navigatorKey.currentContext != null) {
|
||||
await showPopUp<void>(
|
||||
context: navigatorKey.currentContext!,
|
||||
builder: (context) => AlertWithOneAction(
|
||||
alertTitle: "Ledger Error",
|
||||
alertContent:
|
||||
interpretErrorCode(errorDetails.exception.toString()) ??
|
||||
S.of(context).ledger_connection_error,
|
||||
buttonText: S.of(context).close,
|
||||
buttonAction: () => Navigator.of(context).pop(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
_hasError = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Ignore User related errors or system errors
|
||||
static bool _ignoreError(String error) =>
|
||||
_ignoredErrors.any((element) => error.contains(element));
|
||||
|
@ -227,6 +281,7 @@ class ExceptionHandler {
|
|||
"core/auth_service.dart:64",
|
||||
"core/key_service.dart:14",
|
||||
"core/wallet_loading_service.dart:139",
|
||||
"Wrong Device Status: 0x5515 (UNKNOWN)",
|
||||
];
|
||||
|
||||
static Future<void> _addDeviceInfo(File file) async {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue