Browse Source

Merge pull request #728 from gre/disconnect-error-event

Add disconnected device event. also sort errors by alphabetic
master
Meriadec Pillet 7 years ago
committed by GitHub
parent
commit
2cfd57cc05
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      src/helpers/deviceAccess.js
  2. 47
      static/i18n/en/errors.yml

13
src/helpers/deviceAccess.js

@ -4,6 +4,7 @@ import type Transport from '@ledgerhq/hw-transport'
import TransportNodeHid from '@ledgerhq/hw-transport-node-hid'
import { DEBUG_DEVICE } from 'config/constants'
import { retry } from './promise'
import { createCustomErrorClass } from './errors'
// all open to device must use openDevice so we can prevent race conditions
// and guarantee we do one device access at a time. It also will handle the .close()
@ -13,6 +14,16 @@ type WithDevice = (devicePath: string) => <T>(job: (Transport<*>) => Promise<T>)
const semaphorePerDevice = {}
const DisconnectedDevice = createCustomErrorClass('DisconnectedDevice')
const remapError = <T>(p: Promise<T>): Promise<T> =>
p.catch(e => {
if (e && e.message && e.message.indexOf('HID') >= 0) {
throw new DisconnectedDevice(e.message)
}
throw e
})
export const withDevice: WithDevice = devicePath => {
const sem =
semaphorePerDevice[devicePath] || (semaphorePerDevice[devicePath] = createSemaphore(1))
@ -23,7 +34,7 @@ export const withDevice: WithDevice = devicePath => {
if (DEBUG_DEVICE) t.setDebugMode(true)
try {
const res = await job(t)
const res = await remapError(job(t))
// $FlowFixMe
return res
} finally {

47
static/i18n/en/errors.yml

@ -1,33 +1,32 @@
generic: Oops, an unknown error occurred. Please try again or contact Ledger Support.
RangeError: '{{message}}'
Error: '{{message}}'
LedgerAPIErrorWithMessage: '{{message}}'
TransportStatusError: '{{message}}'
TimeoutError: 'The request timed out.'
FeeEstimationFailed: 'Fee estimation error. Try again or set a custom fee (status: {{status}})'
NotEnoughBalance: 'Insufficient funds to proceed.'
BtcUnmatchedApp: 'Open the ‘{{currencyName}}’ app on your Ledger device to proceed.'
WrongAppOpened: 'Open the ‘{{currencyName}}’ app on your Ledger device to proceed.'
WrongDeviceForAccount: 'Use the device associated with the account ‘{{accountName}}’.'
LedgerAPINotAvailable: 'Ledger API not available for {{currencyName}}.'
LedgerAPIError: 'Ledger API error. Try again. (HTTP {{status}})'
NetworkDown: 'Your internet connection seems down.'
NoAddressesFound: 'No accounts were found.'
UserRefusedOnDevice: Transaction refused on device.
WebsocketConnectionError: Oops, device connection failed. Please try again. [web-err]
WebsocketConnectionFailed: Oops, device connection failed. Please try again. [web-fail]
DeviceNotGenuine: Device is not genuine
DeviceSocketFail: Oops, device connection failed. Please try again. [device-fail]
DeviceSocketNoBulkStatus: Oops, device connection failed. Please try again [bulk].
DeviceSocketNoHandler: Oops, device connection failed (handler {{query}}). Please try again.
LatestMCUInstalledError: MCU on device already up to date.
DisconnectedDevice: 'The device was disconnected.'
Error: '{{message}}'
FeeEstimationFailed: 'Fee estimation error. Try again or set a custom fee (status: {{status}})'
generic: Oops, an unknown error occurred. Please try again or contact Ledger Support.
HardResetFail: Reset failed. Please try again.
LatestMCUInstalledError: MCU on device already up to date.
LedgerAPIError: 'Ledger API error. Try again. (HTTP {{status}})'
LedgerAPIErrorWithMessage: '{{message}}'
LedgerAPINotAvailable: 'Ledger API not available for {{currencyName}}.'
ManagerAPIsFail: Services are unavailable. Please try again.
ManagerUnexpected: Unexpected error occurred ({{msg}}). Please try again.
ManagerNotEnoughSpace: Not enough storage on device. Uninstall some apps and try again.
ManagerDeviceLocked: Device is locked
ManagerAppAlreadyInstalled: App is already installed
ManagerAppRelyOnBTC: You must install Bitcoin application first
ManagerDeviceLocked: Device is locked
ManagerNotEnoughSpace: Not enough storage on device. Uninstall some apps and try again.
ManagerUnexpected: Unexpected error occurred ({{msg}}). Please try again.
ManagerUninstallBTCDep: You must uninstall other altcoins first
DeviceNotGenuine: Device is not genuine
NetworkDown: 'Your internet connection seems down.'
NoAddressesFound: 'No accounts were found.'
NotEnoughBalance: 'Insufficient funds to proceed.'
RangeError: '{{message}}'
TimeoutError: 'The request timed out.'
TransportStatusError: '{{message}}'
UserRefusedOnDevice: Transaction refused on device.
WebsocketConnectionError: Oops, device connection failed. Please try again. [web-err]
WebsocketConnectionFailed: Oops, device connection failed. Please try again. [web-fail]
WrongAppOpened: 'Open the ‘{{currencyName}}’ app on your Ledger device to proceed.'
WrongDeviceForAccount: 'Use the device associated with the account ‘{{accountName}}’.'

Loading…
Cancel
Save