Browse Source

The rare event of a open() fail can still occur when you switch app

this will fix it
master
Gaëtan Renaudeau 7 years ago
parent
commit
af794ac623
  1. 2
      src/config/constants.js
  2. 3
      src/helpers/deviceAccess.js

2
src/config/constants.js

@ -6,7 +6,7 @@ export const CHECK_APP_INTERVAL_WHEN_INVALID = 600
export const CHECK_APP_INTERVAL_WHEN_VALID = 1200 export const CHECK_APP_INTERVAL_WHEN_VALID = 1200
export const CHECK_UPDATE_DELAY = 5e3 export const CHECK_UPDATE_DELAY = 5e3
export const DEVICE_DISCONNECT_DEBOUNCE = 1000 export const DEVICE_DISCONNECT_DEBOUNCE = 500
export const MODAL_ADD_ACCOUNT = 'MODAL_ADD_ACCOUNT' export const MODAL_ADD_ACCOUNT = 'MODAL_ADD_ACCOUNT'
export const MODAL_OPERATION_DETAILS = 'MODAL_OPERATION_DETAILS' export const MODAL_OPERATION_DETAILS = 'MODAL_OPERATION_DETAILS'

3
src/helpers/deviceAccess.js

@ -2,6 +2,7 @@
import createSemaphore from 'semaphore' import createSemaphore from 'semaphore'
import type Transport from '@ledgerhq/hw-transport' import type Transport from '@ledgerhq/hw-transport'
import TransportNodeHid from '@ledgerhq/hw-transport-node-hid' import TransportNodeHid from '@ledgerhq/hw-transport-node-hid'
import { retry } from './promise'
// all open to device must use openDevice so we can prevent race conditions // 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() // and guarantee we do one device access at a time. It also will handle the .close()
@ -17,7 +18,7 @@ export const withDevice: WithDevice = devicePath => {
return job => return job =>
takeSemaphorePromise(sem, async () => { takeSemaphorePromise(sem, async () => {
const t = await TransportNodeHid.open(devicePath) const t = await retry(() => TransportNodeHid.open(devicePath), { maxRetry: 1 })
try { try {
const res = await job(t) const res = await job(t)
// $FlowFixMe // $FlowFixMe

Loading…
Cancel
Save