diff --git a/src/components/GenuineCheck.js b/src/components/GenuineCheck.js
index 50cb9d28..fd333647 100644
--- a/src/components/GenuineCheck.js
+++ b/src/components/GenuineCheck.js
@@ -5,13 +5,14 @@ import { timeout } from 'rxjs/operators/timeout'
import { connect } from 'react-redux'
import { compose } from 'redux'
import { translate, Trans } from 'react-i18next'
+import { delay, createCancelablePolling } from 'helpers/promise'
+import logger from 'logger'
import type { T, Device } from 'types/common'
import type { DeviceInfo } from 'helpers/devices/getDeviceInfo'
-import { GENUINE_TIMEOUT, DEVICE_INFOS_TIMEOUT } from 'config/constants'
+import { GENUINE_TIMEOUT, DEVICE_INFOS_TIMEOUT, GENUINE_CACHE_DELAY } from 'config/constants'
-import { createCancelablePolling } from 'helpers/promise'
import { getCurrentDevice } from 'reducers/devices'
import { createCustomErrorClass } from 'helpers/errors'
@@ -46,12 +47,7 @@ const mapStateToProps = state => ({
const Bold = props =>
// to speed up genuine check, cache result by device id
-const GENUINITY_CACHE = {}
-const getDeviceId = (device: Device) => device.path
-const setDeviceGenuinity = (device: Device, isGenuine: boolean) =>
- (GENUINITY_CACHE[getDeviceId(device)] = isGenuine)
-const getDeviceGenuinity = (device: Device): ?boolean =>
- GENUINITY_CACHE[getDeviceId(device)] || null
+const genuineDevices = new WeakSet()
class GenuineCheck extends PureComponent {
connectInteractionHandler = () =>
@@ -76,7 +72,9 @@ class GenuineCheck extends PureComponent {
device: Device,
deviceInfo: DeviceInfo,
}) => {
- if (getDeviceGenuinity(device) === true) {
+ if (genuineDevices.has(device)) {
+ logger.log("genuine was already checked. don't check again")
+ await delay(GENUINE_CACHE_DELAY)
return true
}
const res = await getIsGenuine
@@ -85,10 +83,10 @@ class GenuineCheck extends PureComponent {
.toPromise()
const isGenuine = res === '0000'
if (!isGenuine) {
- return Promise.reject(new DeviceNotGenuineError())
+ throw new DeviceNotGenuineError()
}
- setDeviceGenuinity(device, true)
- return Promise.resolve(true)
+ genuineDevices.add(device)
+ return true
}
handleFail = (err: Error) => {
diff --git a/src/config/constants.js b/src/config/constants.js
index f873cdcc..ec61c419 100644
--- a/src/config/constants.js
+++ b/src/config/constants.js
@@ -19,23 +19,21 @@ export const MIN_WIDTH = intFromEnv('LEDGER_MIN_WIDTH', 1024)
// time and delays...
-export const GET_CALLS_TIMEOUT = intFromEnv('GET_CALLS_TIMEOUT', 30 * 1000)
+export const CHECK_APP_INTERVAL_WHEN_INVALID = 600
+export const CHECK_APP_INTERVAL_WHEN_VALID = 1200
+export const CHECK_UPDATE_DELAY = 5000
+export const DEVICE_DISCONNECT_DEBOUNCE = intFromEnv('LEDGER_DEVICE_DISCONNECT_DEBOUNCE', 1000)
+export const DEVICE_INFOS_TIMEOUT = intFromEnv('DEVICE_INFOS_TIMEOUT', 5 * 1000)
+export const GENUINE_CACHE_DELAY = intFromEnv('GENUINE_CACHE_DELAY', 1000)
+export const GENUINE_TIMEOUT = intFromEnv('GENUINE_TIMEOUT', 120 * 1000)
export const GET_CALLS_RETRY = intFromEnv('GET_CALLS_RETRY', 2)
+export const GET_CALLS_TIMEOUT = intFromEnv('GET_CALLS_TIMEOUT', 30 * 1000)
export const LISTEN_DEVICES_POLLING_INTERVAL = intFromEnv('LISTEN_DEVICES_POLLING_INTERVAL', 100)
-
-export const SYNC_MAX_CONCURRENT = intFromEnv('LEDGER_SYNC_MAX_CONCURRENT', 1)
-export const SYNC_BOOT_DELAY = 2 * 1000
+export const OUTDATED_CONSIDERED_DELAY = intFromEnv('OUTDATED_CONSIDERED_DELAY', 5 * 60 * 1000)
export const SYNC_ALL_INTERVAL = 120 * 1000
-export const DEVICE_INFOS_TIMEOUT = intFromEnv('DEVICE_INFOS_TIMEOUT', 5 * 1000)
-export const GENUINE_TIMEOUT = intFromEnv('GENUINE_TIMEOUT', 120 * 1000)
+export const SYNC_BOOT_DELAY = 2 * 1000
+export const SYNC_MAX_CONCURRENT = intFromEnv('LEDGER_SYNC_MAX_CONCURRENT', 1)
export const SYNC_TIMEOUT = intFromEnv('SYNC_TIMEOUT', 30 * 1000)
-export const OUTDATED_CONSIDERED_DELAY = intFromEnv('OUTDATED_CONSIDERED_DELAY', 5 * 60 * 1000)
-
-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 = intFromEnv('LEDGER_DEVICE_DISCONNECT_DEBOUNCE', 1000)
// Endpoints...