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 { fetchCounterValues } from 'actions/counterValues'
import { startSyncAccounts } from 'renderer/events' import { startSyncAccounts, startSyncCounterValues } from 'renderer/events'
function sortAccounts(accounts, orderAccounts) { function sortAccounts(accounts, orderAccounts) {
const [order, sort] = orderAccounts.split('|') const [order, sort] = orderAccounts.split('|')
@ -43,7 +43,7 @@ export const updateOrderAccounts: UpdateOrderAccounts = (orderAccounts: string)
export type AddAccount = Account => (Function, Function) => void export type AddAccount = Account => (Function, Function) => void
export const addAccount: AddAccount = payload => (dispatch, getState) => { export const addAccount: AddAccount = payload => (dispatch, getState) => {
const { settings: { orderAccounts }, accounts } = getState() const { settings: { counterValue, orderAccounts }, accounts } = getState()
dispatch({ dispatch({
type: 'ADD_ACCOUNT', type: 'ADD_ACCOUNT',
payload, payload,
@ -52,7 +52,9 @@ export const addAccount: AddAccount = payload => (dispatch, getState) => {
// Start sync accounts the first time you add an account // Start sync accounts the first time you add an account
if (accounts.length === 0) { 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 get from 'lodash/get'
import { startSyncAccounts, stopSyncAccounts } from 'renderer/events' import {
startSyncCounterValues,
startSyncAccounts,
stopSyncAccounts,
stopSyncCounterValues,
} from 'renderer/events'
import { setEncryptionKey } from 'helpers/db' import { setEncryptionKey } from 'helpers/db'
import { fetchAccounts } from 'actions/accounts' import { fetchAccounts } from 'actions/accounts'
import { getAccounts } from 'reducers/accounts' import { getAccounts } from 'reducers/accounts'
import { isLocked, unlock } from 'reducers/application' import { isLocked, unlock } from 'reducers/application'
import { getCounterValue } from 'reducers/settings'
import Box from 'components/base/Box' import Box from 'components/base/Box'
import Input from 'components/base/Input' import Input from 'components/base/Input'
@ -27,6 +33,7 @@ type InputValue = {
type Props = { type Props = {
accounts: Accounts, accounts: Accounts,
children: any, children: any,
counterValue: string,
fetchAccounts: Function, fetchAccounts: Function,
isLocked: boolean, isLocked: boolean,
settings: Settings, settings: Settings,
@ -39,8 +46,9 @@ type State = {
const mapStateToProps = state => ({ const mapStateToProps = state => ({
accounts: getAccounts(state), accounts: getAccounts(state),
settings: state.settings, counterValue: getCounterValue(state),
isLocked: isLocked(state), isLocked: isLocked(state),
settings: state.settings,
}) })
const mapDispatchToProps: Object = { const mapDispatchToProps: Object = {
@ -61,16 +69,19 @@ class IsUnlocked extends Component<Props, State> {
componentWillMount() { componentWillMount() {
if (this.props.isLocked) { if (this.props.isLocked) {
stopSyncCounterValues()
stopSyncAccounts() stopSyncAccounts()
} }
} }
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
if (this.props.isLocked && !nextProps.isLocked) { if (this.props.isLocked && !nextProps.isLocked) {
startSyncCounterValues(nextProps.counterValue, nextProps.accounts)
startSyncAccounts(nextProps.accounts) startSyncAccounts(nextProps.accounts)
} }
if (!this.props.isLocked && nextProps.isLocked) { if (!this.props.isLocked && nextProps.isLocked) {
stopSyncCounterValues()
stopSyncAccounts() stopSyncAccounts()
} }
} }

Loading…
Cancel
Save