diff --git a/app/browser/api/ledger.js b/app/browser/api/ledger.js index a5d54831a5c..651b1aed501 100644 --- a/app/browser/api/ledger.js +++ b/app/browser/api/ledger.js @@ -1867,7 +1867,6 @@ const initialize = (state, paymentsEnabled) => { } const onInitRead = (state, parsedData) => { - parsedData = parsedData.toJS() state = getStateInfo(state, parsedData) try { diff --git a/app/browser/reducers/ledgerReducer.js b/app/browser/reducers/ledgerReducer.js index a9639b6881f..934c3bda992 100644 --- a/app/browser/reducers/ledgerReducer.js +++ b/app/browser/reducers/ledgerReducer.js @@ -18,8 +18,17 @@ const {makeImmutable} = require('../../common/state/immutableUtil') const getSetting = require('../../../js/settings').getSetting const ledgerReducer = (state, action, immutableAction) => { - action = immutableAction || makeImmutable(action) - switch (action.get('actionType')) { + let actionType = action.actionType + if ( + action.actionType !== appConstants.APP_ON_FIRST_LEDGER_SYNC && + action.actionType !== appConstants.APP_ON_BRAVERY_PROPERTIES && + action.actionType !== appConstants.APP_ON_LEDGER_INIT_READ + ) { + action = immutableAction || makeImmutable(action) + actionType = action.get('actionType') + } + + switch (actionType) { case appConstants.APP_SET_STATE: { state = ledgerApi.migration(state) @@ -264,12 +273,12 @@ const ledgerReducer = (state, action, immutableAction) => { } case appConstants.APP_ON_BRAVERY_PROPERTIES: { - state = ledgerApi.onBraveryProperties(state, action.get('error'), action.get('result')) + state = ledgerApi.onBraveryProperties(state, action.error, action.result) break } case appConstants.APP_ON_FIRST_LEDGER_SYNC: { - state = ledgerApi.onLedgerFirstSync(state, action.get('parsedData')) + state = ledgerApi.onLedgerFirstSync(state, action.parsedData) break } case appConstants.APP_ON_LEDGER_CALLBACK: @@ -299,7 +308,7 @@ const ledgerReducer = (state, action, immutableAction) => { } case appConstants.APP_ON_LEDGER_INIT_READ: { - state = ledgerApi.onInitRead(state, action.get('parsedData')) + state = ledgerApi.onInitRead(state, action.parsedData) break } } diff --git a/js/stores/appStore.js b/js/stores/appStore.js index 7039fc699cf..ed2ca3a86e8 100644 --- a/js/stores/appStore.js +++ b/js/stores/appStore.js @@ -173,6 +173,7 @@ const applyReducers = (state, action, immutableAction) => reducers.reduce( }, appState) const handleAppAction = (action) => { + const ledgerReducer = require('../../app/browser/reducers/ledgerReducer') const timeStart = process.hrtime() if (action.actionType === appConstants.APP_SET_STATE) { reducers = [ @@ -203,7 +204,7 @@ const handleAppAction = (action) => { require('../../app/browser/reducers/bookmarkToolbarReducer'), require('../../app/browser/reducers/siteSettingsReducer'), require('../../app/browser/reducers/pageDataReducer'), - require('../../app/browser/reducers/ledgerReducer'), + ledgerReducer, require('../../app/browser/menu') ] initialized = true @@ -215,9 +216,19 @@ const handleAppAction = (action) => { return } - // maintain backwards compatibility for now by adding an additional param for immutableAction - const immutableAction = makeImmutable(action) - appState = applyReducers(appState, action, immutableAction) + let immutableAction = Immutable.Map() + // exclude big chucks that have regular JS in it + if ( + action.actionType === appConstants.APP_ON_FIRST_LEDGER_SYNC || + action.actionType === appConstants.APP_ON_BRAVERY_PROPERTIES || + action.actionType === appConstants.APP_ON_LEDGER_INIT_READ + ) { + appState = ledgerReducer(appState, action, immutableAction) + } else { + // maintain backwards compatibility for now by adding an additional param for immutableAction + immutableAction = makeImmutable(action) + appState = applyReducers(appState, action, immutableAction) + } switch (action.actionType) { case appConstants.APP_SET_STATE: diff --git a/test/unit/app/browser/reducers/ledgerReducerTest.js b/test/unit/app/browser/reducers/ledgerReducerTest.js index 57658534b63..faae36e58d4 100644 --- a/test/unit/app/browser/reducers/ledgerReducerTest.js +++ b/test/unit/app/browser/reducers/ledgerReducerTest.js @@ -386,11 +386,11 @@ describe('ledgerReducer unit tests', function () { let onBraveryPropertiesSpy before(function () { onBraveryPropertiesSpy = sinon.spy(fakeLedgerApi, 'onBraveryProperties') - returnedState = ledgerReducer(appState, Immutable.fromJS({ + returnedState = ledgerReducer(appState, { actionType: appConstants.APP_ON_BRAVERY_PROPERTIES, error: 'error-goes-here', result: 'result-goes-here' - })) + }) }) after(function () { onBraveryPropertiesSpy.restore() @@ -407,10 +407,10 @@ describe('ledgerReducer unit tests', function () { let onLedgerFirstSyncSpy before(function () { onLedgerFirstSyncSpy = sinon.spy(fakeLedgerApi, 'onLedgerFirstSync') - returnedState = ledgerReducer(appState, Immutable.fromJS({ + returnedState = ledgerReducer(appState, { actionType: appConstants.APP_ON_FIRST_LEDGER_SYNC, parsedData: 'parsed-data-goes-here' - })) + }) }) after(function () { onLedgerFirstSyncSpy.restore()