Browse Source

Merge pull request #627 from gre/timeouts

Add timeout for genuine and sync
master
Meriadec Pillet 7 years ago
committed by GitHub
parent
commit
a645dd88df
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 37
      src/bridge/BridgeSyncContext.js
  2. 3
      src/components/Workflow/EnsureGenuine.js
  3. 2
      src/config/constants.js
  4. 1
      static/i18n/en/errors.yml

37
src/bridge/BridgeSyncContext.js

@ -6,6 +6,7 @@
import invariant from 'invariant'
import logger from 'logger'
import shuffle from 'lodash/shuffle'
import { timeout } from 'rxjs/operators/timeout'
import React, { Component } from 'react'
import priorityQueue from 'async/priorityQueue'
import { connect } from 'react-redux'
@ -16,7 +17,12 @@ import { setAccountSyncState } from 'actions/bridgeSync'
import { bridgeSyncSelector, syncStateLocalSelector } from 'reducers/bridgeSync'
import type { BridgeSyncState } from 'reducers/bridgeSync'
import { accountsSelector } from 'reducers/accounts'
import { SYNC_BOOT_DELAY, SYNC_ALL_INTERVAL, SYNC_MAX_CONCURRENT } from 'config/constants'
import {
SYNC_BOOT_DELAY,
SYNC_ALL_INTERVAL,
SYNC_MAX_CONCURRENT,
SYNC_TIMEOUT,
} from 'config/constants'
import { getBridgeForCurrency } from '.'
type BridgeSyncProviderProps = {
@ -73,19 +79,22 @@ class Provider extends Component<BridgeSyncProviderOwnProps, Sync> {
this.props.setAccountSyncState(accountId, { pending: true, error: null })
// TODO use Subscription to unsubscribe at relevant time
bridge.synchronize(account).subscribe({
next: accountUpdater => {
this.props.updateAccountWithUpdater(accountId, accountUpdater)
},
complete: () => {
this.props.setAccountSyncState(accountId, { pending: false, error: null })
next()
},
error: error => {
this.props.setAccountSyncState(accountId, { pending: false, error })
next()
},
})
bridge
.synchronize(account)
.pipe(timeout(SYNC_TIMEOUT))
.subscribe({
next: accountUpdater => {
this.props.updateAccountWithUpdater(accountId, accountUpdater)
},
complete: () => {
this.props.setAccountSyncState(accountId, { pending: false, error: null })
next()
},
error: error => {
this.props.setAccountSyncState(accountId, { pending: false, error })
next()
},
})
}
const syncQueue = priorityQueue(synchronize, SYNC_MAX_CONCURRENT)

3
src/components/Workflow/EnsureGenuine.js

@ -1,7 +1,9 @@
// @flow
import { timeout } from 'rxjs/operators/timeout'
import { PureComponent } from 'react'
import isEqual from 'lodash/isEqual'
import { GENUINE_TIMEOUT } from 'config/constants'
import type { Device } from 'types/common'
import getIsGenuine from 'commands/getIsGenuine'
@ -60,6 +62,7 @@ class EnsureGenuine extends PureComponent<Props, State> {
try {
const res = await getIsGenuine
.send({ devicePath: device.path, targetId: infos.targetId })
.pipe(timeout(GENUINE_TIMEOUT))
.toPromise()
if (this._unmounting) return
const isGenuine = res === '0000'

2
src/config/constants.js

@ -20,6 +20,8 @@ export const GET_CALLS_RETRY = intFromEnv('GET_CALLS_RETRY', 2)
export const SYNC_MAX_CONCURRENT = intFromEnv('LEDGER_SYNC_MAX_CONCURRENT', 6)
export const SYNC_BOOT_DELAY = 2 * 1000
export const SYNC_ALL_INTERVAL = 60 * 1000
export const GENUINE_TIMEOUT = intFromEnv('GENUINE_TIMEOUT', 60 * 1000)
export const SYNC_TIMEOUT = intFromEnv('SYNC_TIMEOUT', 30 * 1000)
export const CHECK_APP_INTERVAL_WHEN_INVALID = 600
export const CHECK_APP_INTERVAL_WHEN_VALID = 1200

1
static/i18n/en/errors.yml

@ -3,6 +3,7 @@ RangeError: '{{message}}'
Error: '{{message}}'
LedgerAPIErrorWithMessage: '{{message}}'
TransportStatusError: '{{message}}'
TimeoutError: 'Timeout reached'
FeeEstimationFailed: 'fee estimation failed (status: {{status}})'
NotEnoughBalance: 'Not enough balance'
BtcUnmatchedApp: 'You must open application ‘{{currencyName}}’ on the device'

Loading…
Cancel
Save