Browse Source

centralize custom errors. fixes #1116

master
Valentin D. Pinkman 7 years ago
parent
commit
166cd11ae6
No known key found for this signature in database GPG Key ID: E7D110669FFB8D3E
  1. 4
      src/api/Ethereum.js
  2. 4
      src/api/Fees.js
  3. 6
      src/api/network.js
  4. 4
      src/bridge/EthereumJSBridge.js
  5. 3
      src/bridge/LibcoreBridge.js
  6. 4
      src/bridge/RippleJSBridge.js
  7. 4
      src/commands/libcoreGetFees.js
  8. 4
      src/commands/libcoreHardReset.js
  9. 3
      src/components/EnsureDeviceApp.js
  10. 4
      src/components/IsUnlocked.js
  11. 4
      src/components/SettingsPage/DisablePasswordModal.js
  12. 4
      src/components/SettingsPage/PasswordForm.js
  13. 4
      src/components/SettingsPage/PasswordModal.js
  14. 5
      src/components/modals/AccountSettingRenderBody.js
  15. 4
      src/components/modals/Send/fields/RecipientField.js
  16. 36
      src/config/errors.js
  17. 12
      src/helpers/apps/installApp.js
  18. 5
      src/helpers/apps/uninstallApp.js
  19. 3
      src/helpers/debugAppInfosForCurrency/btc.js
  20. 4
      src/helpers/firmware/getNextMCU.js
  21. 5
      src/helpers/firmware/installFinalFirmware.js
  22. 4
      src/helpers/firmware/installMcu.js
  23. 10
      src/helpers/firmware/installOsuFirmware.js
  24. 4
      src/helpers/getAddressForCurrency/btc.js
  25. 5
      src/helpers/libcore.js
  26. 14
      src/helpers/socket.js

4
src/api/Ethereum.js

@ -1,12 +1,10 @@
// @flow // @flow
import type { CryptoCurrency } from '@ledgerhq/live-common/lib/types' import type { CryptoCurrency } from '@ledgerhq/live-common/lib/types'
import { BigNumber } from 'bignumber.js' import { BigNumber } from 'bignumber.js'
import { createCustomErrorClass } from 'helpers/errors' import { LedgerAPINotAvailable } from 'config/errors'
import network from './network' import network from './network'
import { blockchainBaseURL } from './Ledger' import { blockchainBaseURL } from './Ledger'
export const LedgerAPINotAvailable = createCustomErrorClass('LedgerAPINotAvailable')
export type Block = { height: number } // TODO more fields actually export type Block = { height: number } // TODO more fields actually
export type Tx = { export type Tx = {
hash: string, hash: string,

4
src/api/Fees.js

@ -2,12 +2,10 @@
import invariant from 'invariant' import invariant from 'invariant'
import LRU from 'lru-cache' import LRU from 'lru-cache'
import type { Currency } from '@ledgerhq/live-common/lib/types' import type { Currency } from '@ledgerhq/live-common/lib/types'
import { createCustomErrorClass } from 'helpers/errors' import { FeeEstimationFailed } from 'config/errors'
import { blockchainBaseURL } from './Ledger' import { blockchainBaseURL } from './Ledger'
import network from './network' import network from './network'
const FeeEstimationFailed = createCustomErrorClass('FeeEstimationFailed')
export type Fees = { export type Fees = {
[_: string]: number, [_: string]: number,
} }

6
src/api/network.js

@ -3,13 +3,9 @@ import axios from 'axios'
import { GET_CALLS_RETRY, GET_CALLS_TIMEOUT } from 'config/constants' import { GET_CALLS_RETRY, GET_CALLS_TIMEOUT } from 'config/constants'
import { retry } from 'helpers/promise' import { retry } from 'helpers/promise'
import logger from 'logger' import logger from 'logger'
import { createCustomErrorClass } from 'helpers/errors' import { LedgerAPIErrorWithMessage, LedgerAPIError, NetworkDown } from 'config/errors'
import anonymizer from 'helpers/anonymizer' import anonymizer from 'helpers/anonymizer'
export const LedgerAPIErrorWithMessage = createCustomErrorClass('LedgerAPIErrorWithMessage')
export const LedgerAPIError = createCustomErrorClass('LedgerAPIError')
export const NetworkDown = createCustomErrorClass('NetworkDown')
const userFriendlyError = <A>(p: Promise<A>, { url, method, startTime }): Promise<A> => const userFriendlyError = <A>(p: Promise<A>, { url, method, startTime }): Promise<A> =>
p.catch(error => { p.catch(error => {
let errorToThrow let errorToThrow

4
src/bridge/EthereumJSBridge.js

@ -15,11 +15,9 @@ import { getDerivations } from 'helpers/derivations'
import getAddressCommand from 'commands/getAddress' import getAddressCommand from 'commands/getAddress'
import signTransactionCommand from 'commands/signTransaction' import signTransactionCommand from 'commands/signTransaction'
import { getAccountPlaceholderName, getNewAccountPlaceholderName } from 'helpers/accountName' import { getAccountPlaceholderName, getNewAccountPlaceholderName } from 'helpers/accountName'
import { createCustomErrorClass } from 'helpers/errors' import { NotEnoughBalance } from 'config/errors'
import type { EditProps, WalletBridge } from './types' import type { EditProps, WalletBridge } from './types'
const NotEnoughBalance = createCustomErrorClass('NotEnoughBalance')
// TODO in future it would be neat to support eip55 // TODO in future it would be neat to support eip55
type Transaction = { type Transaction = {

3
src/bridge/LibcoreBridge.js

@ -11,11 +11,10 @@ import libcoreSyncAccount from 'commands/libcoreSyncAccount'
import libcoreSignAndBroadcast from 'commands/libcoreSignAndBroadcast' import libcoreSignAndBroadcast from 'commands/libcoreSignAndBroadcast'
import libcoreGetFees from 'commands/libcoreGetFees' import libcoreGetFees from 'commands/libcoreGetFees'
import libcoreValidAddress from 'commands/libcoreValidAddress' import libcoreValidAddress from 'commands/libcoreValidAddress'
import { createCustomErrorClass } from 'helpers/errors' import { NotEnoughBalance } from 'config/errors'
import type { WalletBridge, EditProps } from './types' import type { WalletBridge, EditProps } from './types'
const NOT_ENOUGH_FUNDS = 52 const NOT_ENOUGH_FUNDS = 52
const NotEnoughBalance = createCustomErrorClass('NotEnoughBalance')
const notImplemented = new Error('LibcoreBridge: not implemented') const notImplemented = new Error('LibcoreBridge: not implemented')

4
src/bridge/RippleJSBridge.js

@ -20,11 +20,9 @@ import {
import FeesRippleKind from 'components/FeesField/RippleKind' import FeesRippleKind from 'components/FeesField/RippleKind'
import AdvancedOptionsRippleKind from 'components/AdvancedOptions/RippleKind' import AdvancedOptionsRippleKind from 'components/AdvancedOptions/RippleKind'
import { getAccountPlaceholderName, getNewAccountPlaceholderName } from 'helpers/accountName' import { getAccountPlaceholderName, getNewAccountPlaceholderName } from 'helpers/accountName'
import { createCustomErrorClass } from 'helpers/errors' import { NotEnoughBalance } from 'config/errors'
import type { WalletBridge, EditProps } from './types' import type { WalletBridge, EditProps } from './types'
const NotEnoughBalance = createCustomErrorClass('NotEnoughBalance')
type Transaction = { type Transaction = {
amount: BigNumber, amount: BigNumber,
recipient: string, recipient: string,

4
src/commands/libcoreGetFees.js

@ -6,9 +6,7 @@ import withLibcore from 'helpers/withLibcore'
import { createCommand, Command } from 'helpers/ipc' import { createCommand, Command } from 'helpers/ipc'
import * as accountIdHelper from 'helpers/accountId' import * as accountIdHelper from 'helpers/accountId'
import { isValidAddress, libcoreAmountToBigNumber, bigNumberToLibcoreAmount } from 'helpers/libcore' import { isValidAddress, libcoreAmountToBigNumber, bigNumberToLibcoreAmount } from 'helpers/libcore'
import { createCustomErrorClass } from 'helpers/errors' import { InvalidAddress } from 'config/errors'
const InvalidAddress = createCustomErrorClass('InvalidAddress')
type BitcoinLikeTransaction = { type BitcoinLikeTransaction = {
// TODO we rename this Transaction concept into transactionInput // TODO we rename this Transaction concept into transactionInput

4
src/commands/libcoreHardReset.js

@ -3,9 +3,7 @@
import { createCommand } from 'helpers/ipc' import { createCommand } from 'helpers/ipc'
import { fromPromise } from 'rxjs/observable/fromPromise' import { fromPromise } from 'rxjs/observable/fromPromise'
import withLibcore from 'helpers/withLibcore' import withLibcore from 'helpers/withLibcore'
import { createCustomErrorClass } from 'helpers/errors' import { HardResetFail } from 'config/errors'
const HardResetFail = createCustomErrorClass('HardResetFail')
const cmd = createCommand('libcoreHardReset', () => const cmd = createCommand('libcoreHardReset', () =>
fromPromise( fromPromise(

3
src/components/EnsureDeviceApp.js

@ -12,7 +12,6 @@ import getAddress from 'commands/getAddress'
import { createCancelablePolling } from 'helpers/promise' import { createCancelablePolling } from 'helpers/promise'
import { standardDerivation } from 'helpers/derivations' import { standardDerivation } from 'helpers/derivations'
import { isSegwitPath } from 'helpers/bip32' import { isSegwitPath } from 'helpers/bip32'
import { BtcUnmatchedApp } from 'helpers/getAddressForCurrency/btc'
import DeviceInteraction from 'components/DeviceInteraction' import DeviceInteraction from 'components/DeviceInteraction'
import Text from 'components/base/Text' import Text from 'components/base/Text'
@ -21,7 +20,7 @@ import IconUsb from 'icons/Usb'
import type { Device } from 'types/common' import type { Device } from 'types/common'
import { WrongDeviceForAccount, CantOpenDevice } from 'config/errors' import { WrongDeviceForAccount, CantOpenDevice, BtcUnmatchedApp } from 'config/errors'
import { getCurrentDevice } from 'reducers/devices' import { getCurrentDevice } from 'reducers/devices'
const usbIcon = <IconUsb size={16} /> const usbIcon = <IconUsb size={16} />

4
src/components/IsUnlocked.js

@ -17,7 +17,7 @@ import hardReset from 'helpers/hardReset'
import { fetchAccounts } from 'actions/accounts' import { fetchAccounts } from 'actions/accounts'
import { isLocked, unlock } from 'reducers/application' import { isLocked, unlock } from 'reducers/application'
import { createCustomErrorClass } from 'helpers/errors' import { PasswordIncorrectError } from 'config/errors'
import Box from 'components/base/Box' import Box from 'components/base/Box'
import InputPassword from 'components/base/InputPassword' import InputPassword from 'components/base/InputPassword'
@ -26,8 +26,6 @@ import IconArrowRight from 'icons/ArrowRight'
import Button from './base/Button/index' import Button from './base/Button/index'
import ConfirmModal from './base/Modal/ConfirmModal' import ConfirmModal from './base/Modal/ConfirmModal'
const PasswordIncorrectError = createCustomErrorClass('PasswordIncorrect')
type InputValue = { type InputValue = {
password: string, password: string,
} }

4
src/components/SettingsPage/DisablePasswordModal.js

@ -1,7 +1,7 @@
// @flow // @flow
import React, { PureComponent } from 'react' import React, { PureComponent } from 'react'
import { createCustomErrorClass } from 'helpers/errors' import { PasswordIncorrectError } from 'config/errors'
import db from 'helpers/db' import db from 'helpers/db'
import Box from 'components/base/Box' import Box from 'components/base/Box'
@ -12,8 +12,6 @@ import { Modal, ModalContent, ModalBody, ModalTitle, ModalFooter } from 'compone
import type { T } from 'types/common' import type { T } from 'types/common'
const PasswordIncorrectError = createCustomErrorClass('PasswordIncorrect')
type Props = { type Props = {
t: T, t: T,
onClose: Function, onClose: Function,

4
src/components/SettingsPage/PasswordForm.js

@ -6,12 +6,10 @@ import Box from 'components/base/Box'
import InputPassword from 'components/base/InputPassword' import InputPassword from 'components/base/InputPassword'
import Label from 'components/base/Label' import Label from 'components/base/Label'
import { createCustomErrorClass } from 'helpers/errors' import { PasswordsDontMatchError } from 'config/errors'
import type { T } from 'types/common' import type { T } from 'types/common'
const PasswordsDontMatchError = createCustomErrorClass('PasswordsDontMatch')
type Props = { type Props = {
t: T, t: T,
hasPassword: boolean, hasPassword: boolean,

4
src/components/SettingsPage/PasswordModal.js

@ -5,15 +5,13 @@ import React, { PureComponent } from 'react'
import type { T } from 'types/common' import type { T } from 'types/common'
import db from 'helpers/db' import db from 'helpers/db'
import { createCustomErrorClass } from 'helpers/errors' import { PasswordIncorrectError } from 'config/errors'
import Box from 'components/base/Box' import Box from 'components/base/Box'
import Button from 'components/base/Button' import Button from 'components/base/Button'
import { Modal, ModalContent, ModalBody, ModalTitle, ModalFooter } from 'components/base/Modal' import { Modal, ModalContent, ModalBody, ModalTitle, ModalFooter } from 'components/base/Modal'
import PasswordForm from './PasswordForm' import PasswordForm from './PasswordForm'
const PasswordIncorrectError = createCustomErrorClass('PasswordIncorrect')
type Props = { type Props = {
t: T, t: T,
onClose: () => void, onClose: () => void,

5
src/components/modals/AccountSettingRenderBody.js

@ -17,7 +17,7 @@ import { setDataModal } from 'reducers/modals'
import { getBridgeForCurrency } from 'bridge' import { getBridgeForCurrency } from 'bridge'
import { createCustomErrorClass } from 'helpers/errors' import { AccountNameRequiredError, EnpointConfigError } from 'config/errors'
import TrackPage from 'analytics/TrackPage' import TrackPage from 'analytics/TrackPage'
import Spoiler from 'components/base/Spoiler' import Spoiler from 'components/base/Spoiler'
@ -36,9 +36,6 @@ import {
ConfirmModal, ConfirmModal,
} from 'components/base/Modal' } from 'components/base/Modal'
const AccountNameRequiredError = createCustomErrorClass('AccountNameRequired')
const EnpointConfigError = createCustomErrorClass('EnpointConfig')
type State = { type State = {
accountName: ?string, accountName: ?string,
accountUnit: ?Unit, accountUnit: ?Unit,

4
src/components/modals/Send/fields/RecipientField.js

@ -9,7 +9,7 @@ import Box from 'components/base/Box'
import LabelWithExternalIcon from 'components/base/LabelWithExternalIcon' import LabelWithExternalIcon from 'components/base/LabelWithExternalIcon'
import RecipientAddress from 'components/RecipientAddress' import RecipientAddress from 'components/RecipientAddress'
import { track } from 'analytics/segment' import { track } from 'analytics/segment'
import { createCustomErrorClass } from 'helpers/errors' import { InvalidAddress } from 'config/errors'
type Props<Transaction> = { type Props<Transaction> = {
t: T, t: T,
@ -20,8 +20,6 @@ type Props<Transaction> = {
autoFocus?: boolean, autoFocus?: boolean,
} }
const InvalidAddress = createCustomErrorClass('InvalidAddress')
class RecipientField<Transaction> extends Component<Props<Transaction>, { isValid: boolean }> { class RecipientField<Transaction> extends Component<Props<Transaction>, { isValid: boolean }> {
state = { state = {
isValid: true, isValid: true,

36
src/config/errors.js

@ -4,15 +4,41 @@
import { createCustomErrorClass } from 'helpers/errors' import { createCustomErrorClass } from 'helpers/errors'
export const DisconnectedDevice = createCustomErrorClass('DisconnectedDevice') export const AccountNameRequiredError = createCustomErrorClass('AccountNameRequired')
export const UserRefusedOnDevice = createCustomErrorClass('UserRefusedOnDevice') // TODO rename because it's just for transaction refusal export const BtcUnmatchedApp = createCustomErrorClass('BtcUnmatchedApp')
export const CantOpenDevice = createCustomErrorClass('CantOpenDevice') export const CantOpenDevice = createCustomErrorClass('CantOpenDevice')
export const DeviceAppVerifyNotSupported = createCustomErrorClass('DeviceAppVerifyNotSupported') export const DeviceAppVerifyNotSupported = createCustomErrorClass('DeviceAppVerifyNotSupported')
export const UserRefusedAddress = createCustomErrorClass('UserRefusedAddress')
export const WrongDeviceForAccount = createCustomErrorClass('WrongDeviceForAccount')
export const DeviceNotGenuineError = createCustomErrorClass('DeviceNotGenuine')
export const DeviceGenuineSocketEarlyClose = createCustomErrorClass('DeviceGenuineSocketEarlyClose') export const DeviceGenuineSocketEarlyClose = createCustomErrorClass('DeviceGenuineSocketEarlyClose')
export const DeviceNotGenuineError = createCustomErrorClass('DeviceNotGenuine')
export const DeviceSocketFail = createCustomErrorClass('DeviceSocketFail')
export const DeviceSocketNoBulkStatus = createCustomErrorClass('DeviceSocketNoBulkStatus')
export const DeviceSocketNoHandler = createCustomErrorClass('DeviceSocketNoHandler')
export const DisconnectedDevice = createCustomErrorClass('DisconnectedDevice')
export const EnpointConfigError = createCustomErrorClass('EnpointConfig')
export const FeeEstimationFailed = createCustomErrorClass('FeeEstimationFailed')
export const HardResetFail = createCustomErrorClass('HardResetFail')
export const InvalidAddress = createCustomErrorClass('InvalidAddress')
export const LatestMCUInstalledError = createCustomErrorClass('LatestMCUInstalledError')
export const LedgerAPIError = createCustomErrorClass('LedgerAPIError')
export const LedgerAPIErrorWithMessage = createCustomErrorClass('LedgerAPIErrorWithMessage')
export const LedgerAPINotAvailable = createCustomErrorClass('LedgerAPINotAvailable')
export const ManagerAppAlreadyInstalledError = createCustomErrorClass('ManagerAppAlreadyInstalled')
export const ManagerAppRelyOnBTCError = createCustomErrorClass('ManagerAppRelyOnBTC')
export const ManagerDeviceLockedError = createCustomErrorClass('ManagerDeviceLocked')
export const ManagerNotEnoughSpaceError = createCustomErrorClass('ManagerNotEnoughSpace')
export const ManagerUninstallBTCDep = createCustomErrorClass('ManagerUninstallBTCDep')
export const NetworkDown = createCustomErrorClass('NetworkDown')
export const NoAddressesFound = createCustomErrorClass('NoAddressesFound')
export const NotEnoughBalance = createCustomErrorClass('NotEnoughBalance')
export const PasswordsDontMatchError = createCustomErrorClass('PasswordsDontMatch')
export const PasswordIncorrectError = createCustomErrorClass('PasswordIncorrect')
export const TimeoutTagged = createCustomErrorClass('TimeoutTagged') export const TimeoutTagged = createCustomErrorClass('TimeoutTagged')
export const UserRefusedAddress = createCustomErrorClass('UserRefusedAddress')
export const UserRefusedFirmwareUpdate = createCustomErrorClass('UserRefusedFirmwareUpdate')
export const UserRefusedOnDevice = createCustomErrorClass('UserRefusedOnDevice') // TODO rename because it's just for transaction refusal
export const WebsocketConnectionError = createCustomErrorClass('WebsocketConnectionError')
export const WebsocketConnectionFailed = createCustomErrorClass('WebsocketConnectionFailed')
export const WrongDeviceForAccount = createCustomErrorClass('WrongDeviceForAccount')
// db stuff, no need to translate // db stuff, no need to translate
export const NoDBPathGiven = createCustomErrorClass('NoDBPathGiven') export const NoDBPathGiven = createCustomErrorClass('NoDBPathGiven')

12
src/helpers/apps/installApp.js

@ -4,14 +4,14 @@ import type Transport from '@ledgerhq/hw-transport'
import { createDeviceSocket } from 'helpers/socket' import { createDeviceSocket } from 'helpers/socket'
import type { ApplicationVersion } from 'helpers/types' import type { ApplicationVersion } from 'helpers/types'
import { createCustomErrorClass } from 'helpers/errors'
import { WS_INSTALL } from 'helpers/urls' import { WS_INSTALL } from 'helpers/urls'
const ManagerNotEnoughSpaceError = createCustomErrorClass('ManagerNotEnoughSpace') import {
const ManagerDeviceLockedError = createCustomErrorClass('ManagerDeviceLocked') ManagerNotEnoughSpaceError,
const ManagerAppAlreadyInstalledError = createCustomErrorClass('ManagerAppAlreadyInstalled') ManagerDeviceLockedError,
const ManagerAppRelyOnBTCError = createCustomErrorClass('ManagerAppRelyOnBTC') ManagerAppAlreadyInstalledError,
ManagerAppRelyOnBTCError,
} from 'config/errors'
function remapError(promise) { function remapError(promise) {
return promise.catch((e: Error) => { return promise.catch((e: Error) => {

5
src/helpers/apps/uninstallApp.js

@ -4,12 +4,9 @@ import type Transport from '@ledgerhq/hw-transport'
import { createDeviceSocket } from 'helpers/socket' import { createDeviceSocket } from 'helpers/socket'
import type { ApplicationVersion } from 'helpers/types' import type { ApplicationVersion } from 'helpers/types'
import { createCustomErrorClass } from 'helpers/errors' import { ManagerDeviceLockedError, ManagerUninstallBTCDep } from 'config/errors'
import { WS_INSTALL } from 'helpers/urls' import { WS_INSTALL } from 'helpers/urls'
const ManagerDeviceLockedError = createCustomErrorClass('ManagerDeviceLocked')
const ManagerUninstallBTCDep = createCustomErrorClass('ManagerUninstallBTCDep')
function remapError(promise) { function remapError(promise) {
return promise.catch((e: Error) => { return promise.catch((e: Error) => {
switch (true) { switch (true) {

3
src/helpers/debugAppInfosForCurrency/btc.js

@ -1,9 +1,6 @@
// @flow // @flow
import type Transport from '@ledgerhq/hw-transport' import type Transport from '@ledgerhq/hw-transport'
import { createCustomErrorClass } from '../errors'
export const BtcUnmatchedApp = createCustomErrorClass('BtcUnmatchedApp')
export default async (transport: Transport<*>) => { export default async (transport: Transport<*>) => {
const r = await transport.send(0xe0, 0xc4, 0, 0) const r = await transport.send(0xe0, 0xc4, 0, 0)

4
src/helpers/firmware/getNextMCU.js

@ -2,10 +2,8 @@
import network from 'api/network' import network from 'api/network'
import { GET_NEXT_MCU } from 'helpers/urls' import { GET_NEXT_MCU } from 'helpers/urls'
import { createCustomErrorClass } from 'helpers/errors'
import type { OsuFirmware } from 'helpers/types' import type { OsuFirmware } from 'helpers/types'
import { LatestMCUInstalledError } from 'config/errors'
const LatestMCUInstalledError = createCustomErrorClass('LatestMCUInstalledError')
type NetworkResponse = { data: OsuFirmware | 'default' } type NetworkResponse = { data: OsuFirmware | 'default' }

5
src/helpers/firmware/installFinalFirmware.js

@ -4,13 +4,12 @@ import type { DeviceInfo, DeviceVersion, OsuFirmware, FinalFirmware } from 'help
import { WS_INSTALL } from 'helpers/urls' import { WS_INSTALL } from 'helpers/urls'
import { createDeviceSocket } from 'helpers/socket' import { createDeviceSocket } from 'helpers/socket'
import { createCustomErrorClass } from 'helpers/errors'
import getDeviceVersion from 'helpers/devices/getDeviceVersion' import getDeviceVersion from 'helpers/devices/getDeviceVersion'
import getOsuFirmware from 'helpers/devices/getOsuFirmware' import getOsuFirmware from 'helpers/devices/getOsuFirmware'
import getDeviceInfo from 'helpers/devices/getDeviceInfo' import getDeviceInfo from 'helpers/devices/getDeviceInfo'
import getFinalFirmwareById from './getFinalFirmwareById' import { ManagerDeviceLockedError } from 'config/errors'
const ManagerDeviceLockedError = createCustomErrorClass('ManagerDeviceLocked') import getFinalFirmwareById from './getFinalFirmwareById'
function remapSocketError(promise) { function remapSocketError(promise) {
return promise.catch((e: Error) => { return promise.catch((e: Error) => {

4
src/helpers/firmware/installMcu.js

@ -5,12 +5,10 @@ import { WS_MCU } from 'helpers/urls'
import { createDeviceSocket } from 'helpers/socket' import { createDeviceSocket } from 'helpers/socket'
import getNextMCU from 'helpers/firmware/getNextMCU' import getNextMCU from 'helpers/firmware/getNextMCU'
import getDeviceInfo from 'helpers/devices/getDeviceInfo' import getDeviceInfo from 'helpers/devices/getDeviceInfo'
import { createCustomErrorClass } from 'helpers/errors' import { ManagerDeviceLockedError } from 'config/errors'
import type { DeviceInfo } from 'helpers/types' import type { DeviceInfo } from 'helpers/types'
const ManagerDeviceLockedError = createCustomErrorClass('ManagerDeviceLocked')
function remapSocketError(promise) { function remapSocketError(promise) {
return promise.catch((e: Error) => { return promise.catch((e: Error) => {
switch (true) { switch (true) {

10
src/helpers/firmware/installOsuFirmware.js

@ -6,11 +6,11 @@ import { createDeviceSocket } from 'helpers/socket'
import type { Firmware } from 'components/modals/UpdateFirmware' import type { Firmware } from 'components/modals/UpdateFirmware'
import { createCustomErrorClass } from '../errors' import {
ManagerNotEnoughSpaceError,
const ManagerNotEnoughSpaceError = createCustomErrorClass('ManagerNotEnoughSpace') ManagerDeviceLockedError,
const ManagerDeviceLockedError = createCustomErrorClass('ManagerDeviceLocked') UserRefusedFirmwareUpdate,
const UserRefusedFirmwareUpdate = createCustomErrorClass('UserRefusedFirmwareUpdate') } from 'config/errors'
function remapError(promise) { function remapError(promise) {
return promise.catch((e: Error) => { return promise.catch((e: Error) => {

4
src/helpers/getAddressForCurrency/btc.js

@ -3,10 +3,8 @@
import type { CryptoCurrency } from '@ledgerhq/live-common/lib/types' import type { CryptoCurrency } from '@ledgerhq/live-common/lib/types'
import Btc from '@ledgerhq/hw-app-btc' import Btc from '@ledgerhq/hw-app-btc'
import type Transport from '@ledgerhq/hw-transport' import type Transport from '@ledgerhq/hw-transport'
import { BtcUnmatchedApp } from 'config/errors'
import getBitcoinLikeInfo from '../devices/getBitcoinLikeInfo' import getBitcoinLikeInfo from '../devices/getBitcoinLikeInfo'
import { createCustomErrorClass } from '../errors'
export const BtcUnmatchedApp = createCustomErrorClass('BtcUnmatchedApp')
export default async ( export default async (
transport: Transport<*>, transport: Transport<*>,

5
src/helpers/libcore.js

@ -14,12 +14,11 @@ import type { NJSAccount, NJSOperation } from '@ledgerhq/ledger-core/src/ledgerc
import { isSegwitPath, isUnsplitPath } from 'helpers/bip32' import { isSegwitPath, isUnsplitPath } from 'helpers/bip32'
import * as accountIdHelper from 'helpers/accountId' import * as accountIdHelper from 'helpers/accountId'
import { createCustomErrorClass, deserializeError } from './errors' import { NoAddressesFound } from 'config/errors'
import { deserializeError } from './errors'
import { getAccountPlaceholderName, getNewAccountPlaceholderName } from './accountName' import { getAccountPlaceholderName, getNewAccountPlaceholderName } from './accountName'
import { timeoutTagged } from './promise' import { timeoutTagged } from './promise'
const NoAddressesFound = createCustomErrorClass('NoAddressesFound')
// TODO: put that info inside currency itself // TODO: put that info inside currency itself
const SPLITTED_CURRENCIES = { const SPLITTED_CURRENCIES = {
bitcoin_cash: { bitcoin_cash: {

14
src/helpers/socket.js

@ -5,13 +5,13 @@ import logger from 'logger'
import Websocket from 'ws' import Websocket from 'ws'
import type Transport from '@ledgerhq/hw-transport' import type Transport from '@ledgerhq/hw-transport'
import { Observable } from 'rxjs' import { Observable } from 'rxjs'
import { createCustomErrorClass } from './errors' import {
WebsocketConnectionError,
const WebsocketConnectionError = createCustomErrorClass('WebsocketConnectionError') WebsocketConnectionFailed,
const WebsocketConnectionFailed = createCustomErrorClass('WebsocketConnectionFailed') DeviceSocketFail,
const DeviceSocketFail = createCustomErrorClass('DeviceSocketFail') DeviceSocketNoBulkStatus,
const DeviceSocketNoBulkStatus = createCustomErrorClass('DeviceSocketNoBulkStatus') DeviceSocketNoHandler,
const DeviceSocketNoHandler = createCustomErrorClass('DeviceSocketNoHandler') } from 'config/errors'
/** /**
* use Ledger WebSocket API to exchange data with the device * use Ledger WebSocket API to exchange data with the device

Loading…
Cancel
Save