Browse Source

Merge pull request #490 from gre/fix-disconnect-event

The rare event of a open() fail can still occur when you switch app
master
Meriadec Pillet 7 years ago
committed by GitHub
parent
commit
f4b6a15f7a
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  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_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_OPERATION_DETAILS = 'MODAL_OPERATION_DETAILS'

3
src/helpers/deviceAccess.js

@ -2,6 +2,7 @@
import createSemaphore from 'semaphore'
import type Transport from '@ledgerhq/hw-transport'
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
// 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 =>
takeSemaphorePromise(sem, async () => {
const t = await TransportNodeHid.open(devicePath)
const t = await retry(() => TransportNodeHid.open(devicePath), { maxRetry: 1 })
try {
const res = await job(t)
// $FlowFixMe

Loading…
Cancel
Save