Browse Source

more dynamic refresh rate on EnsureDeviceApp

check needs to be faster when the app is not opened
master
Gaëtan Renaudeau 7 years ago
parent
commit
650e8ea2ad
  1. 11
      src/components/EnsureDeviceApp/index.js

11
src/components/EnsureDeviceApp/index.js

@ -10,6 +10,9 @@ import type { State as StoreState } from 'reducers/index'
import getAddress from 'commands/getAddress' import getAddress from 'commands/getAddress'
import isCurrencyAppOpened from 'commands/isCurrencyAppOpened' import isCurrencyAppOpened from 'commands/isCurrencyAppOpened'
const CHECK_APP_INTERVAL_WHEN_INVALID = 300
const CHECK_APP_INTERVAL_WHEN_VALID = 1000
type OwnProps = { type OwnProps = {
currency?: ?CryptoCurrency, currency?: ?CryptoCurrency,
deviceSelected: ?Device, deviceSelected: ?Device,
@ -108,6 +111,8 @@ class EnsureDeviceApp extends PureComponent<Props, State> {
return return
} }
let isSuccess = true
try { try {
if (account) { if (account) {
const { address } = await getAddress const { address } = await getAddress
@ -148,11 +153,15 @@ class EnsureDeviceApp extends PureComponent<Props, State> {
} }
} catch (e) { } catch (e) {
this.handleStatusChange(this.state.deviceStatus, 'fail', e.message) this.handleStatusChange(this.state.deviceStatus, 'fail', e.message)
isSuccess = false
} }
// TODO: refacto to more generic/global way // TODO: refacto to more generic/global way
if (!this._unmounted) { 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,
)
} }
} }

Loading…
Cancel
Save