-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathledger.ts
More file actions
68 lines (57 loc) · 2.95 KB
/
Copy pathledger.ts
File metadata and controls
68 lines (57 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/**
* Used to "translate" error codes (inside the messages) returned by the Ledger
* device into a human-readable messages. Although alongside the raw error codes
* there is a message incoming from Ledger too, it's not self-explanatory and
* can be difficult for the end users to understand.
*/
const BENIGN_LEDGER_USER_INTERACTIONS = new Set(['', 'none', 'None'])
export const isBenignLedgerUserInteraction = (interaction?: string) => {
if (!interaction) return true
return BENIGN_LEDGER_USER_INTERACTIONS.has(interaction)
}
export const normalizeLedgerMessage = (error?: string): string => {
if (
!error ||
// Generic error returned by the Ledger transport (@ledgerhq/hw-transport)
error.toLowerCase().includes('access denied')
)
return 'Cannot connect to your Ledger device. Please make sure it is connected.'
if (
error.toLowerCase().includes('no response from device') ||
error.toLowerCase() === 'none' ||
error.toLowerCase() === '<none>'
) {
return 'Cannot connect to your Ledger device. Please make sure it is unlocked and the Ethereum app is open.'
}
if (error.includes('unlock-device')) return 'Please unlock your Ledger device first.'
if (error.includes('confirm-open-app'))
return 'Please open the Ethereum app on your Ledger device first.'
if (
error.includes('5515') ||
error.includes('6b0c') ||
error.includes('650f') ||
error.includes('6511')
) {
return 'Cannot connect to your Ledger device. Please make sure it is unlocked and running the Ethereum app.'
}
if (error.includes('DeviceDisconnectedWhileSendingError'))
return 'Ledger device got disconnected. Please reconnect and try again.'
if (error.includes('6e00') || error.includes('6b00')) {
return 'Your Ledger device requires a firmware and Ethereum App update.'
}
if (error.includes('6d00')) {
return "Your Ledger doesn't recognize the command sent. Please update device firmware and Ethereum App and try again."
}
if (error.includes('6985') || error.includes('5501')) {
return 'Rejected by your Ledger device.'
}
if (error.toLowerCase().includes('please enable blind signing') || error.includes('6a80')) {
return 'Blind Signing is disabled on your Ledger device. To sign this transaction, please enable Blind Signing (formerly called Contract Data) in the Ethereum app settings on your Ledger device, then try again.'
}
// Indicates a custom timeout error, no need to normalize
if (error.includes('Cannot connect to your Ledger device for an extended period')) return error
if (error.includes('The device is already open'))
return 'Ledger device busy. Please make sure there are no pending requests on the device.'
console.error('Unknown Ledger error:', error)
return `Cannot connect to your Ledger device. Close all other apps that may be accessing it (including apps on your computer). Ensure device is responsive. Ensure Ledger firmware and Ethereum App are up to date. Device error: ${error}`
}