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

Commit

Permalink
Addresses review comments 2
Browse files Browse the repository at this point in the history
  • Loading branch information
NejcZdovc committed Oct 3, 2017
1 parent 108ff07 commit c340c89
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 51 deletions.
13 changes: 6 additions & 7 deletions app/browser/api/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ const getPublisherData = (result, scorekeeper) => {

let data = {
verified: result.options.verified || false,
exclude: result.options.exclude || false,
site: result.publisherKey,
views: result.visits,
duration: duration,
Expand Down Expand Up @@ -890,10 +891,9 @@ const pageDataChanged = (state) => {
excludeP(publisherKey, (unused, exclude) => {
if (!getSetting(settings.PAYMENTS_SITES_AUTO_SUGGEST)) {
exclude = false
} else {
exclude = !exclude
}
appActions.onPublisherOptionUpdate(publisherKey, 'exclude', exclude, true)
appActions.onPublisherOptionUpdate(publisherKey, 'exclude', exclude)
savePublisherOption(publisherKey, 'exclude', exclude)
})
}

Expand Down Expand Up @@ -1081,6 +1081,7 @@ const initSynopsis = (state) => {
const publisherKey = item[0]
excludeP(publisherKey, (unused, exclude) => {
appActions.onPublisherOptionUpdate(publisherKey, 'exclude', exclude)
savePublisherOption(publisherKey, 'exclude', exclude)
})

state = verifiedP(state, publisherKey, (error, result) => {
Expand Down Expand Up @@ -1134,9 +1135,6 @@ const enable = (state, paymentsEnabled) => {
}
})

// change undefined include publishers to include publishers
state = ledgerState.enableUndefinedPublishers(state, stateSynopsis.get('publishers'))

return state
}

Expand Down Expand Up @@ -1769,6 +1767,7 @@ const onCallback = (state, result, delayTime) => {
const publisherKey = item[0]
excludeP(publisherKey, (unused, exclude) => {
appActions.onPublisherOptionUpdate(publisherKey, 'exclude', exclude)
savePublisherOption(publisherKey, 'exclude', exclude)
})
}
})
Expand Down Expand Up @@ -1838,7 +1837,7 @@ const initialize = (state, paymentsEnabled) => {
const fs = require('fs')
fs.access(pathName(statePath), fs.FF_OK, (err) => {
if (err) {
return console.error('access error: ' + err.toString())
return
}

fs.readFile(pathName(statePath), (err, data) => {
Expand Down
11 changes: 0 additions & 11 deletions app/browser/reducers/ledgerReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ const settings = require('../../../js/constants/settings')

// State
const ledgerState = require('../../common/state/ledgerState')
const siteSettingsState = require('../../common/state/siteSettingsState')

// Utils
const ledgerApi = require('../../browser/api/ledger')
const urlUtil = require('../../../js/lib/urlutil')
const {makeImmutable} = require('../../common/state/immutableUtil')
const getSetting = require('../../../js/settings').getSetting

Expand Down Expand Up @@ -209,10 +207,8 @@ const ledgerReducer = (state, action, immutableAction) => {
case appConstants.APP_ON_EXCLUSION_STATUS:
{
const key = action.get('publisherKey')
const pattern = urlUtil.getHostPattern(key)
const value = action.get('excluded')
ledgerApi.savePublisherOption(key, 'exclude', value)
state = siteSettingsState.setSettingsProp(state, pattern, 'ledgerPayments', value)
state = ledgerState.setPublishersProp(state, key, ['options', 'exclude'], value)
state = ledgerApi.updatePublisherInfo(state)
break
Expand All @@ -229,13 +225,6 @@ const ledgerReducer = (state, action, immutableAction) => {
const key = action.get('publisherKey')
const prop = action.get('prop')
state = ledgerState.setPublisherOption(state, key, prop, value)

if (action.get('saveIntoSettings')) {
const pattern = urlUtil.getHostPattern(key)
if (prop === 'exclude') {
state = siteSettingsState.setSettingsProp(state, pattern, 'ledgerPayments', value)
}
}
break
}
case appConstants.APP_ON_LEDGER_WALLET_CREATE:
Expand Down
14 changes: 8 additions & 6 deletions app/common/lib/ledgerUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,17 +161,11 @@ const visibleP = (state, publisherKey) => {

// Publisher Options
const deletedByUser = blockedP(state, publisherKey)
const includeExclude = stickyP(state, publisherKey)
const eligibleByStats = eligibleP(state, publisherKey) // num of visits and time spent
const isInExclusionList = publisherOptions.get('exclude')
const verifiedPublisher = publisherOptions.get('verified')

return (
eligibleByStats &&
(
isInExclusionList !== true ||
includeExclude
) &&
(
(onlyVerified && verifiedPublisher) ||
!onlyVerified
Expand Down Expand Up @@ -199,6 +193,14 @@ const stickyP = (state, publisherKey) => {
const pattern = urlUtil.getHostPattern(publisherKey)
let result = siteSettingsState.getSettingsProp(state, pattern, 'ledgerPayments')

if (result == null) {
const excluded = ledgerState.getPublisherOption(state, publisherKey, 'exclude')

if (excluded != null) {
result = !excluded
}
}

return (result === undefined || result)
}

Expand Down
24 changes: 1 addition & 23 deletions app/common/state/ledgerState.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ const ledgerState = {
state = validateState(state)

if (key == null || prop == null) {
return state
return null
}

return state.getIn(['ledger', 'synopsis', 'publishers', key, 'options', prop])
Expand Down Expand Up @@ -298,28 +298,6 @@ const ledgerState = {
return state
},

enableUndefinedPublishers: (state, publishers) => {
state = validateState(state)
const sitesObject = state.get('siteSettings')

if (publishers == null) {
return state
}

for (let item of publishers) {
const key = item[0]
const pattern = urlUtil.getHostPattern(key)
const result = sitesObject.getIn([pattern, 'ledgerPayments'])

if (result === undefined) {
const newSiteSettings = siteSettings.mergeSiteSetting(state.get('siteSettings'), pattern, 'ledgerPayments', true)
state = state.set('siteSettings', newSiteSettings)
}
}

return state
},

// TODO (optimization) don't have two almost identical object in state (synopsi->publishers and about->synopsis)
saveAboutSynopsis: (state, publishers) => {
state = validateState(state)
Expand Down
3 changes: 2 additions & 1 deletion app/renderer/components/preferences/payment/ledgerTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ class LedgerTable extends ImmutableComponent {
return result
}
}
return getSetting(settings.PAYMENTS_SITES_AUTO_SUGGEST, this.props.settings)

return !synopsis.get('exclude')
}

shouldShow (synopsis) {
Expand Down
5 changes: 2 additions & 3 deletions js/actions/appActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1576,13 +1576,12 @@ const appActions = {
})
},

onPublisherOptionUpdate: function (publisherKey, prop, value, saveIntoSettings = false) {
onPublisherOptionUpdate: function (publisherKey, prop, value) {
dispatch({
actionType: appConstants.APP_ON_PUBLISHER_OPTION_UPDATE,
publisherKey,
prop,
value,
saveIntoSettings
value
})
},

Expand Down

0 comments on commit c340c89

Please sign in to comment.