From af794ac6232ad297e412de7df6e1380dc8f857db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Renaudeau?= Date: Sat, 9 Jun 2018 08:30:31 +0200 Subject: [PATCH] The rare event of a open() fail can still occur when you switch app this will fix it --- src/config/constants.js | 2 +- src/helpers/deviceAccess.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/config/constants.js b/src/config/constants.js index 90be4ff9..38fb7347 100644 --- a/src/config/constants.js +++ b/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' diff --git a/src/helpers/deviceAccess.js b/src/helpers/deviceAccess.js index a077248e..b71920a8 100644 --- a/src/helpers/deviceAccess.js +++ b/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