From 650e8ea2ad1afcb3c1f3f8b6c7b3d7aca6214fcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Renaudeau?= Date: Wed, 6 Jun 2018 10:35:35 +0200 Subject: [PATCH] more dynamic refresh rate on EnsureDeviceApp check needs to be faster when the app is not opened --- src/components/EnsureDeviceApp/index.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/components/EnsureDeviceApp/index.js b/src/components/EnsureDeviceApp/index.js index 5f0d6f00..36faaafe 100644 --- a/src/components/EnsureDeviceApp/index.js +++ b/src/components/EnsureDeviceApp/index.js @@ -10,6 +10,9 @@ import type { State as StoreState } from 'reducers/index' import getAddress from 'commands/getAddress' import isCurrencyAppOpened from 'commands/isCurrencyAppOpened' +const CHECK_APP_INTERVAL_WHEN_INVALID = 300 +const CHECK_APP_INTERVAL_WHEN_VALID = 1000 + type OwnProps = { currency?: ?CryptoCurrency, deviceSelected: ?Device, @@ -108,6 +111,8 @@ class EnsureDeviceApp extends PureComponent { return } + let isSuccess = true + try { if (account) { const { address } = await getAddress @@ -148,11 +153,15 @@ class EnsureDeviceApp extends PureComponent { } } catch (e) { this.handleStatusChange(this.state.deviceStatus, 'fail', e.message) + isSuccess = false } // TODO: refacto to more generic/global way if (!this._unmounted) { - this._timeout = setTimeout(this.checkAppOpened, 1e3) + this._timeout = setTimeout( + this.checkAppOpened, + isSuccess ? CHECK_APP_INTERVAL_WHEN_VALID : CHECK_APP_INTERVAL_WHEN_INVALID, + ) } }