Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
Moves reducer for ledger
Browse files Browse the repository at this point in the history
  • Loading branch information
NejcZdovc committed Jun 16, 2017
1 parent a1cf4f5 commit 51127ac
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
27 changes: 21 additions & 6 deletions app/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ const uuid = require('uuid')
const appActions = require('../js/actions/appActions')
const appConfig = require('../js/constants/appConfig')
const appConstants = require('../js/constants/appConstants')
const appDispatcher = require('../js/dispatcher/appDispatcher')
const messages = require('../js/constants/messages')
const settings = require('../js/constants/settings')
const request = require('../js/lib/request')
Expand Down Expand Up @@ -145,7 +144,7 @@ let notificationTryPaymentsMessage
let notificationTimeout = null

// TODO(bridiver) - create a better way to get setting changes
const doAction = (action) => {
const doAction = (state, action) => {
var i, publisher

/* TBD: handle
Expand All @@ -163,13 +162,27 @@ const doAction = (action) => {
}

switch (action.actionType) {
case appConstants.APP_SET_STATE:
init()
break

case appConstants.APP_BACKUP_KEYS:
state = backupKeys(state, action)
break

case appConstants.APP_RECOVER_WALLET:
state = recoverKeys(state, action)
break

case appConstants.APP_SHUTTING_DOWN:
quit()
break

case appConstants.APP_ON_CLEAR_BROWSING_DATA:
// TODO
// if (action.clearDataDetail.get('browserHistory') && !getSetting(settings.PAYMENTS_ENABLED)) reset(true)
console.log(state.get('clearBrowsingDataDefaults'))
if (state.getIn(['clearBrowsingDataDefaults', 'browserHistory']) && !getSetting(settings.PAYMENTS_ENABLED)) {
reset(true)
}
break

case appConstants.APP_IDLE_STATE_CHANGED:
Expand Down Expand Up @@ -265,6 +278,8 @@ const doAction = (action) => {
default:
break
}

return state
}

/*
Expand All @@ -273,7 +288,6 @@ const doAction = (action) => {

var init = () => {
try {
appDispatcher.register(doAction)
initialize(getSetting(settings.PAYMENTS_ENABLED))
} catch (ex) { console.log('ledger.js initialization failed: ' + ex.toString() + '\n' + ex.stack) }
}
Expand Down Expand Up @@ -2251,5 +2265,6 @@ module.exports = {
backupKeys: backupKeys,
quit: quit,
boot: boot,
reset: reset
reset: reset,
doAction
}
12 changes: 2 additions & 10 deletions js/stores/appStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,6 @@ function handleChangeSettingAction (settingKey, settingValue) {
}

let reducers = []
let ledger = null

const applyReducers = (state, action, immutableAction) => reducers.reduce(
(appState, reducer) => {
Expand All @@ -385,7 +384,6 @@ const applyReducers = (state, action, immutableAction) => reducers.reduce(

const handleAppAction = (action) => {
if (action.actionType === appConstants.APP_SET_STATE) {
ledger = require('../../app/ledger')
reducers = [
require('../../app/browser/reducers/downloadsReducer'),
require('../../app/browser/reducers/flashReducer'),
Expand All @@ -404,7 +402,8 @@ const handleAppAction = (action) => {
require('../../app/browser/reducers/dragDropReducer'),
require('../../app/browser/reducers/extensionsReducer'),
require('../../app/browser/reducers/shareReducer'),
require('../../app/browser/reducers/updatesReducer')
require('../../app/browser/reducers/updatesReducer'),
require('../../app/ledger').doAction
]
initialized = true
appState = action.appState
Expand All @@ -430,7 +429,6 @@ const handleAppAction = (action) => {
appState = profiles.init(appState, action, appStore)
appState = require('../../app/browser/menu').init(appState, action, appStore)
appState = require('../../app/sync').init(appState, action, appStore)
ledger.init()
break
case appConstants.APP_SHUTTING_DOWN:
AppDispatcher.shutdown()
Expand Down Expand Up @@ -651,12 +649,6 @@ const handleAppAction = (action) => {
case appConstants.APP_SET_DICTIONARY:
appState = appState.setIn(['dictionary', 'locale'], action.locale)
break
case appConstants.APP_BACKUP_KEYS:
appState = ledger.backupKeys(appState, action)
break
case appConstants.APP_RECOVER_WALLET:
appState = ledger.recoverKeys(appState, action)
break
case appConstants.APP_LEDGER_RECOVERY_STATUS_CHANGED:
{
const date = new Date().getTime()
Expand Down

0 comments on commit 51127ac

Please sign in to comment.