|
|
@ -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) |
|
|
|