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

Commit

Permalink
Temporary fix for startup problem
Browse files Browse the repository at this point in the history
  • Loading branch information
NejcZdovc committed Oct 3, 2017
1 parent 22bb84e commit a4deb1b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 14 deletions.
1 change: 0 additions & 1 deletion app/browser/api/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -1867,7 +1867,6 @@ const initialize = (state, paymentsEnabled) => {
}

const onInitRead = (state, parsedData) => {
parsedData = parsedData.toJS()
state = getStateInfo(state, parsedData)

try {
Expand Down
19 changes: 14 additions & 5 deletions app/browser/reducers/ledgerReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
}
}
Expand Down
19 changes: 15 additions & 4 deletions js/stores/appStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions test/unit/app/browser/reducers/ledgerReducerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down

0 comments on commit a4deb1b

Please sign in to comment.