diff --git a/src/bridge/BridgeSyncContext.js b/src/bridge/BridgeSyncContext.js index 99099fb0..9ef266cf 100644 --- a/src/bridge/BridgeSyncContext.js +++ b/src/bridge/BridgeSyncContext.js @@ -16,7 +16,7 @@ import { updateAccountWithUpdater } from 'actions/accounts' import { setAccountSyncState } from 'actions/bridgeSync' import { bridgeSyncSelector, syncStateLocalSelector } from 'reducers/bridgeSync' import type { BridgeSyncState } from 'reducers/bridgeSync' -import { accountsSelector } from 'reducers/accounts' +import { accountsSelector, isUpToDateSelector } from 'reducers/accounts' import { SYNC_MAX_CONCURRENT, SYNC_TIMEOUT } from 'config/constants' import { getBridgeForCurrency } from '.' @@ -27,6 +27,7 @@ type BridgeSyncProviderProps = { type BridgeSyncProviderOwnProps = BridgeSyncProviderProps & { bridgeSync: BridgeSyncState, accounts: Account[], + isUpToDate: boolean, updateAccountWithUpdater: (string, (Account) => Account) => void, setAccountSyncState: (string, AsyncState) => *, } @@ -50,6 +51,7 @@ const BridgeSyncContext = React.createContext((_: BehaviorAction) => {}) const mapStateToProps = createStructuredSelector({ accounts: accountsSelector, bridgeSync: bridgeSyncSelector, + isUpToDate: isUpToDateSelector, }) const actions = { @@ -101,6 +103,7 @@ class Provider extends Component { // by convention we remove concurrent tasks with same priority // FIXME this is somehow a hack. ideally we should just dedup the account ids in the pending queue... syncQueue.remove(o => priority === o.priority) + logger.debug('schedule', { type: 'syncQueue', ids }) syncQueue.push(ids, -priority) } @@ -118,6 +121,10 @@ class Provider extends Component { if (priority === skipUnderPriority) return skipUnderPriority = priority syncQueue.remove(({ priority }) => priority < skipUnderPriority) + if (priority === -1 && !this.props.isUpToDate) { + // going back to -1 priority => retriggering a background sync if it is "Paused" + schedule(shuffledAccountIds(), -1) + } }, SYNC_ALL_ACCOUNTS: ({ priority }) => { @@ -136,10 +143,11 @@ class Provider extends Component { const sync = (action: BehaviorAction) => { const handler = handlers[action.type] if (handler) { + logger.debug(`action ${action.type}`, { action, type: 'syncQueue' }) // $FlowFixMe handler(action) } else { - logger.warn('BridgeSyncContext unsupported action', action) + logger.warn('BridgeSyncContext unsupported action', { action, type: 'syncQueue' }) } } diff --git a/src/config/constants.js b/src/config/constants.js index 1fd94965..516df479 100644 --- a/src/config/constants.js +++ b/src/config/constants.js @@ -32,7 +32,9 @@ 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', 1000) -export const OUTDATED_CONSIDERED_DELAY = intFromEnv('OUTDATED_CONSIDERED_DELAY', 5 * 60 * 1000) +// NB: technically speaking OUTDATED_CONSIDERED_DELAY should be set to ZERO. +// but we'll only do that when we're sure the sync is performant and all is working smoothly +export const OUTDATED_CONSIDERED_DELAY = intFromEnv('OUTDATED_CONSIDERED_DELAY', 2 * 60 * 1000) export const SYNC_ALL_INTERVAL = 120 * 1000 export const SYNC_BOOT_DELAY = 2 * 1000 export const SYNC_PENDING_INTERVAL = 10 * 1000