From 333683a321999c8571cdd2791f32ad482abcb29a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=ABck=20V=C3=A9zien?= Date: Wed, 14 Mar 2018 16:20:52 +0100 Subject: [PATCH] Start sync/Stop sync, if Application is locked --- src/actions/accounts.js | 8 +++++--- src/components/IsUnlocked.js | 15 +++++++++++++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/actions/accounts.js b/src/actions/accounts.js index 9336d059..dd859e16 100644 --- a/src/actions/accounts.js +++ b/src/actions/accounts.js @@ -9,7 +9,7 @@ import type { Account } from 'types/common' import { fetchCounterValues } from 'actions/counterValues' -import { startSyncAccounts } from 'renderer/events' +import { startSyncAccounts, startSyncCounterValues } from 'renderer/events' function sortAccounts(accounts, orderAccounts) { const [order, sort] = orderAccounts.split('|') @@ -43,7 +43,7 @@ export const updateOrderAccounts: UpdateOrderAccounts = (orderAccounts: string) export type AddAccount = Account => (Function, Function) => void export const addAccount: AddAccount = payload => (dispatch, getState) => { - const { settings: { orderAccounts }, accounts } = getState() + const { settings: { counterValue, orderAccounts }, accounts } = getState() dispatch({ type: 'ADD_ACCOUNT', payload, @@ -52,7 +52,9 @@ export const addAccount: AddAccount = payload => (dispatch, getState) => { // Start sync accounts the first time you add an account if (accounts.length === 0) { - startSyncAccounts([payload]) + const accounts = [payload] + startSyncCounterValues(counterValue, accounts) + startSyncAccounts(accounts) } } diff --git a/src/components/IsUnlocked.js b/src/components/IsUnlocked.js index 9dae0c42..3401f45d 100644 --- a/src/components/IsUnlocked.js +++ b/src/components/IsUnlocked.js @@ -10,12 +10,18 @@ import type { Settings, Accounts, T } from 'types/common' import get from 'lodash/get' -import { startSyncAccounts, stopSyncAccounts } from 'renderer/events' +import { + startSyncCounterValues, + startSyncAccounts, + stopSyncAccounts, + stopSyncCounterValues, +} from 'renderer/events' import { setEncryptionKey } from 'helpers/db' import { fetchAccounts } from 'actions/accounts' import { getAccounts } from 'reducers/accounts' import { isLocked, unlock } from 'reducers/application' +import { getCounterValue } from 'reducers/settings' import Box from 'components/base/Box' import Input from 'components/base/Input' @@ -27,6 +33,7 @@ type InputValue = { type Props = { accounts: Accounts, children: any, + counterValue: string, fetchAccounts: Function, isLocked: boolean, settings: Settings, @@ -39,8 +46,9 @@ type State = { const mapStateToProps = state => ({ accounts: getAccounts(state), - settings: state.settings, + counterValue: getCounterValue(state), isLocked: isLocked(state), + settings: state.settings, }) const mapDispatchToProps: Object = { @@ -61,16 +69,19 @@ class IsUnlocked extends Component { componentWillMount() { if (this.props.isLocked) { + stopSyncCounterValues() stopSyncAccounts() } } componentWillReceiveProps(nextProps) { if (this.props.isLocked && !nextProps.isLocked) { + startSyncCounterValues(nextProps.counterValue, nextProps.accounts) startSyncAccounts(nextProps.accounts) } if (!this.props.isLocked && nextProps.isLocked) { + stopSyncCounterValues() stopSyncAccounts() } }