Browse Source

Start sync/Stop sync, if Application is locked

master
Loëck Vézien 7 years ago
parent
commit
333683a321
No known key found for this signature in database GPG Key ID: CBCDCE384E853AC4
  1. 8
      src/actions/accounts.js
  2. 15
      src/components/IsUnlocked.js

8
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)
}
}

15
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<Props, State> {
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()
}
}

Loading…
Cancel
Save