From bd7b3924ffa46d0e6118c70f9d5331c9e9f32f30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=ABck=20V=C3=A9zien?= Date: Fri, 26 Jan 2018 13:09:52 +0100 Subject: [PATCH 1/2] Hide Synchronizing when you don't have accounts --- src/components/TopBar.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/components/TopBar.js b/src/components/TopBar.js index 761d0941..a70dde7a 100644 --- a/src/components/TopBar.js +++ b/src/components/TopBar.js @@ -9,6 +9,7 @@ import type { Devices } from 'types/common' import type { SetCurrentDevice } from 'actions/devices' import { getDevices, getCurrentDevice } from 'reducers/devices' +import { getAccounts } from 'reducers/accounts' import { setCurrentDevice } from 'actions/devices' import { lock } from 'reducers/application' import { hasPassword } from 'reducers/settings' @@ -16,8 +17,9 @@ import { hasPassword } from 'reducers/settings' import Box from 'components/base/Box' const mapStateToProps: MapStateToProps<*, *, *> = state => ({ - devices: getDevices(state), + hasAccounts: Object.keys(getAccounts(state)).length > 0, currentDevice: getCurrentDevice(state), + devices: getDevices(state), hasPassword: hasPassword(state), }) @@ -27,10 +29,11 @@ const mapDispatchToProps: MapDispatchToProps<*, *, *> = { } type Props = { - setCurrentDevice: SetCurrentDevice, - lock: Function, - hasPassword: boolean, + hasAccounts: boolean, devices: Devices, + hasPassword: boolean, + lock: Function, + setCurrentDevice: SetCurrentDevice, } type State = { sync: { @@ -93,15 +96,16 @@ class TopBar extends PureComponent { handleLock = () => this.props.lock() render() { - const { devices, hasPassword } = this.props + const { devices, hasPassword, hasAccounts } = this.props const { sync } = this.state return ( - {sync.progress === true - ? 'Synchronizing...' - : sync.fail === true ? 'Synchronization fail :(' : 'Synchronisation finished!'} + {hasAccounts && + (sync.progress === true + ? 'Synchronizing...' + : sync.fail === true ? 'Synchronization fail :(' : 'Synchronisation finished!')} {hasPassword && } From 9f3a378f69402ebe9dd27d3eeacaf898fd1fdbed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=ABck=20V=C3=A9zien?= Date: Fri, 26 Jan 2018 13:56:39 +0100 Subject: [PATCH 2/2] Sync each account one by one instead of all accounts --- src/internals/accounts/sync.js | 8 ++++++-- src/renderer/events.js | 34 ++++++++++++++++++++-------------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/internals/accounts/sync.js b/src/internals/accounts/sync.js index 0dd24e30..f660f96b 100644 --- a/src/internals/accounts/sync.js +++ b/src/internals/accounts/sync.js @@ -17,9 +17,13 @@ export default (send: Function) => ({ send('accounts.sync.progress', null, { kill: false }) try { - const result = await Promise.all(accounts.map(syncAccount)) + await Promise.all( + accounts.map(a => + syncAccount(a).then(account => send('account.sync.success', account, { kill: false })), + ), + ) - send('accounts.sync.success', result) + send('accounts.sync.success') } catch (err) { send('accounts.sync.fail', err.stack || err) } diff --git a/src/renderer/events.js b/src/renderer/events.js index a08f42c1..a90b4310 100644 --- a/src/renderer/events.js +++ b/src/renderer/events.js @@ -63,24 +63,30 @@ export function checkUpdates() { export default ({ store, locked }: { store: Object, locked: boolean }) => { const handlers = { + account: { + sync: { + success: account => { + if (syncAccounts) { + const currentAccountData = getAccountData(store.getState(), account.id) || {} + const transactions = uniqBy( + [...currentAccountData.transactions, ...account.transactions], + tx => tx.hash, + ) + + if (currentAccountData.transactions.length !== transactions.length) { + store.dispatch(syncAccount(account)) + } + } + }, + }, + }, accounts: { sync: { - success: accounts => { + success: () => { if (syncAccounts) { - const currentState = store.getState() - accounts.forEach(account => { - const currentAccountData = getAccountData(currentState, account.id) || {} - const transactions = uniqBy( - [...currentAccountData.transactions, ...account.transactions], - tx => tx.hash, - ) - if (currentAccountData.transactions.length !== transactions.length) { - store.dispatch(syncAccount(account)) - } - }) syncTimeout = setTimeout(() => { - const newAccounts = getAccounts(store.getState()) - startSyncAccounts(newAccounts) + const accounts = getAccounts(store.getState()) + startSyncAccounts(accounts) }, SYNC_ACCOUNT_TIMEOUT) } },