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

Commit

Permalink
Move ledger state manipulation out into a helper file (can be refacto…
Browse files Browse the repository at this point in the history
…red later to be a more event based process and code can be turned into a reducer).

Auditors: @cezaraugusto
  • Loading branch information
bsclifton committed Dec 28, 2016
1 parent caa2865 commit a6cc6a5
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 14 deletions.
31 changes: 31 additions & 0 deletions app/common/state/publisherState.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

const {makeImmutable} = require('./immutableUtil')
const ledger = require('../../ledger')

const publisherState = {
setLocation: (state) => {
state = makeImmutable(state)
return state.set('publisherLocation', makeImmutable(ledger.locations))
},
setPublisherInfo: (state, action) => {
state = makeImmutable(state)
return state.set('publisherInfo', makeImmutable(action.publisherInfo))
},
setLedgerInfo: (state, action) => {
state = makeImmutable(state)
return state.set('ledgerInfo', makeImmutable(action.ledgerInfo))
},
onBackupKeys: (state, action) => {
state = makeImmutable(state)
return ledger.backupKeys(state, action)
},
onRecoverKeys: (state, action) => {
state = makeImmutable(state)
return ledger.recoverKeys(state, action)
}
}

module.exports = publisherState
2 changes: 1 addition & 1 deletion js/components/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,7 @@ class Main extends ImmutableComponent {
noScriptIsVisible={noScriptIsVisible}
menubarVisible={customTitlebar.menubarVisible}
allSiteSettings={allSiteSettings}
publisherInfo={this.props.appState.get('publisherInfo') || new Immutable.Map()}
publisherLocation={this.props.appState.get('publisherLocation') || new Immutable.Map()}
/>
<div className='topLevelEndButtons'>
<div className={cx({
Expand Down
7 changes: 3 additions & 4 deletions js/components/navigationBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,11 @@ class NavigationBar extends ImmutableComponent {
}

get shouldShowAddPublisherButton () {
const publisherLocation = this.props.publisherInfo.get('location')
const hostSettings = this.props.allSiteSettings.get(this.hostPattern)

if (hostSettings && publisherLocation) {
if (hostSettings && this.props.publisherLocation) {
const ledgerPaymentsShown = hostSettings.get('ledgerPaymentsShown')
const validPublisher = !!publisherLocation.get(this.props.location)
const validPublisher = !!this.props.publisherLocation.get(this.props.location)

if (validPublisher && ledgerPaymentsShown !== false) {
return !getSetting(settings.AUTO_SUGGEST_SITES) && !getSetting(settings.HIDE_EXCLUDED_SITES)
Expand Down Expand Up @@ -173,7 +172,7 @@ class NavigationBar extends ImmutableComponent {
if (this.props.activeFrameKey === undefined) {
return null
}
console.log('LOCATION HERE -----------------', !!this.props.publisherInfo)
console.log('LOCATION HERE -----------------', JSON.stringify(this.props.publisherLocation))

return <div id='navigator'
ref='navigator'
Expand Down
15 changes: 6 additions & 9 deletions js/stores/appStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const basicAuthState = require('../../app/common/state/basicAuthState')
const extensionState = require('../../app/common/state/extensionState')
const aboutNewTabState = require('../../app/common/state/aboutNewTabState')
const aboutHistoryState = require('../../app/common/state/aboutHistoryState')
const publisherState = require('../../app/common/state/publisherState')
const windowState = require('../../app/common/state/windowState')

const webtorrent = require('../../app/browser/webtorrent')
Expand Down Expand Up @@ -369,8 +370,6 @@ const handleAppAction = (action) => {
return
}

const ledger = require('../../app/ledger')

appState = applyReducers(appState, action)

switch (action.actionType) {
Expand Down Expand Up @@ -499,9 +498,7 @@ const handleAppAction = (action) => {
}
appState = aboutNewTabState.setSites(appState, action)
appState = aboutHistoryState.setHistory(appState, action)

const location = ledger.locations
appState = appState.setIn(['publisherInfo', 'location'], Immutable.fromJS(location))
appState = publisherState.setLocation(appState)
break
case appConstants.APP_REMOVE_SITE:
appState = appState.set('sites', siteUtil.removeSite(appState.get('sites'), action.siteDetail, action.tag))
Expand Down Expand Up @@ -614,10 +611,10 @@ const handleAppAction = (action) => {
break
}
case appConstants.APP_UPDATE_LEDGER_INFO:
appState = appState.set('ledgerInfo', Immutable.fromJS(action.ledgerInfo))
appState = publisherState.setLedgerInfo(appState, action)
break
case appConstants.APP_UPDATE_PUBLISHER_INFO:
appState = appState.set('publisherInfo', Immutable.fromJS(action.publisherInfo))
appState = publisherState.setPublisherInfo(appState, action)
break
case appConstants.APP_SHOW_MESSAGE_BOX:
let notifications = appState.get('notifications')
Expand Down Expand Up @@ -675,10 +672,10 @@ const handleAppAction = (action) => {
appState = appState.setIn(['dictionary', 'locale'], action.locale)
break
case appConstants.APP_BACKUP_KEYS:
appState = ledger.backupKeys(appState, action)
appState = publisherState.onBackupKeys(appState, action)
break
case appConstants.APP_RECOVER_WALLET:
appState = ledger.recoverKeys(appState, action)
appState = publisherState.onRecoverKeys(appState, action)
break
case appConstants.APP_LEDGER_RECOVERY_SUCCEEDED:
appState = appState.setIn(['ui', 'about', 'preferences', 'recoverySucceeded'], true)
Expand Down

0 comments on commit a6cc6a5

Please sign in to comment.