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

Fixed ledger state update #11000

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 112 additions & 0 deletions app/browser/reducers/siteSettingsReducer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/* This SourceCode 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/. */

'use strict'
const Immutable = require('immutable')
const appConstants = require('../../../js/constants/appConstants')
const siteSettings = require('../../../js/state/siteSettings')
const urlUtil = require('../../../js/lib/urlutil')
const {makeImmutable} = require('../../common/state/immutableUtil')

const siteSettingsReducer = (state, action, immutableAction) => {
action = immutableAction || makeImmutable(action)
switch (action.get('actionType')) {
case appConstants.APP_ALLOW_FLASH_ONCE:
{
const propertyName = action.get('isPrivate') ? 'temporarySiteSettings' : 'siteSettings'
state = state.set(propertyName,
siteSettings.mergeSiteSetting(state.get(propertyName), urlUtil.getOrigin(action.get('url')), 'flash', 1))
break
}
case appConstants.APP_ALLOW_FLASH_ALWAYS:
{
const propertyName = action.get('isPrivate') ? 'temporarySiteSettings' : 'siteSettings'
const expirationTime = Date.now() + (7 * 24 * 3600 * 1000)
state = state.set(propertyName,
siteSettings.mergeSiteSetting(state.get(propertyName), urlUtil.getOrigin(action.get('url')), 'flash', expirationTime))
break
}
case appConstants.APP_CHANGE_SITE_SETTING:
{
console.log('appStore')
let propertyName = action.get('temporary') ? 'temporarySiteSettings' : 'siteSettings'
let newSiteSettings = siteSettings.mergeSiteSetting(state.get(propertyName), action.get('hostPattern'), action.get('key'), action.get('value'))
if (action.get('skipSync')) {
newSiteSettings = newSiteSettings.setIn([action.get('hostPattern'), 'skipSync'], true)
}
state = state.set(propertyName, newSiteSettings)
break
}
case appConstants.APP_REMOVE_SITE_SETTING:
{
let propertyName = action.get('temporary') ? 'temporarySiteSettings' : 'siteSettings'
let newSiteSettings = siteSettings.removeSiteSetting(state.get(propertyName),
action.get('hostPattern'), action.get('key'))
if (action.get('skipSync')) {
newSiteSettings = newSiteSettings.setIn([action.get('hostPattern'), 'skipSync'], true)
}
state = state.set(propertyName, newSiteSettings)
break
}
case appConstants.APP_CLEAR_SITE_SETTINGS:
{
let propertyName = action.get('temporary') ? 'temporarySiteSettings' : 'siteSettings'
let newSiteSettings = new Immutable.Map()
state.get(propertyName).map((entry, hostPattern) => {
let newEntry = entry.delete(action.get('key'))
if (action.get('skipSync')) {
newEntry = newEntry.set('skipSync', true)
}
newSiteSettings = newSiteSettings.set(hostPattern, newEntry)
})
state = state.set(propertyName, newSiteSettings)
break
}
case appConstants.APP_ADD_NOSCRIPT_EXCEPTIONS:
{
const origin = action.get('origins')
const hostPattern = action.get('hostPattern')
const propertyName = action.get('temporary') ? 'temporarySiteSettings' : 'siteSettings'
// Note that this is always cleared on restart or reload, so should not
// be synced or persisted.
const key = 'noScriptExceptions'
if (!origin || !origin.size) {
// Clear the exceptions
state = state.setIn([propertyName, hostPattern, key], new Immutable.Map())
} else {
const currentExceptions = state.getIn([propertyName, hostPattern, key]) || new Immutable.Map()
state = state.setIn([propertyName, hostPattern, key], currentExceptions.merge(origin))
}
break
}

case appConstants.APP_ENABLE_UNDEFINED_PUBLISHERS:
{
const sitesObject = state.get('siteSettings')
action.get('publishers', Immutable.Map()).map((item, index) => {
const pattern = `https?://${index}`
const siteSetting = sitesObject.get(pattern)
const result = (siteSetting) && (siteSetting.get('ledgerPayments'))

if (result === undefined) {
let newSiteSettings = siteSettings.mergeSiteSetting(state.get('siteSettings'), pattern, 'ledgerPayments', true)
state = state.set('siteSettings', newSiteSettings)
}
})
break
}
case appConstants.APP_CHANGE_LEDGER_PINNED_PERCENTAGES:
{
action.get('publishers', Immutable.Map()).map((item, index) => {
const pattern = `https?://${index}`
let newSiteSettings = siteSettings.mergeSiteSetting(state.get('siteSettings'), pattern, 'ledgerPinPercentage', action.getIn(['publishers', pattern, 'pinPercentage'], 0))
state = state.set('siteSettings', newSiteSettings)
})
break
}
}
return state
}

module.exports = siteSettingsReducer
2 changes: 2 additions & 0 deletions app/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,7 @@ var updatePublisherInfo = (changedPublisher) => {
}

var blockedP = (publisher) => {
console.log('blocked')
var siteSetting = appStore.getState().get('siteSettings').get(`https?://${publisher}`)

return ((!!siteSetting) && (siteSetting.get('ledgerPaymentsShown') === false))
Expand Down Expand Up @@ -1193,6 +1194,7 @@ var synopsisNormalizer = (changedPublisher) => {
const scorekeeper = synopsis.options.scorekeeper

results = []
console.log('visible')
underscore.keys(synopsis.publishers).forEach((publisher) => {
if (!visibleP(publisher)) return

Expand Down
87 changes: 1 addition & 86 deletions js/stores/appStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const AppDispatcher = require('../dispatcher/appDispatcher')
const settings = require('../constants/settings')
const {STATE_SITES} = require('../constants/stateConstants')
const syncUtil = require('../state/syncUtil')
const siteSettings = require('../state/siteSettings')
const electron = require('electron')
const app = electron.app
const messages = require('../constants/messages')
Expand Down Expand Up @@ -195,6 +194,7 @@ const handleAppAction = (action) => {
require('../../app/browser/reducers/updatesReducer'),
require('../../app/browser/reducers/topSitesReducer'),
require('../../app/browser/reducers/braverySettingsReducer'),
require('../../app/browser/reducers/siteSettingsReducer'),
require('../../app/ledger').doAction,
require('../../app/browser/menu')
]
Expand Down Expand Up @@ -281,78 +281,13 @@ const handleAppAction = (action) => {
appState = appState.setIn(['settings', action.key], action.value)
appState = handleChangeSettingAction(appState, action.key, action.value)
break
case appConstants.APP_ALLOW_FLASH_ONCE:
{
const propertyName = action.isPrivate ? 'temporarySiteSettings' : 'siteSettings'
appState = appState.set(propertyName,
siteSettings.mergeSiteSetting(appState.get(propertyName), urlUtil.getOrigin(action.url), 'flash', 1))
break
}
case appConstants.APP_ALLOW_FLASH_ALWAYS:
{
const propertyName = action.isPrivate ? 'temporarySiteSettings' : 'siteSettings'
const expirationTime = Date.now() + (7 * 24 * 3600 * 1000)
appState = appState.set(propertyName,
siteSettings.mergeSiteSetting(appState.get(propertyName), urlUtil.getOrigin(action.url), 'flash', expirationTime))
break
}
case appConstants.APP_CHANGE_SITE_SETTING:
{
let propertyName = action.temporary ? 'temporarySiteSettings' : 'siteSettings'
let newSiteSettings = siteSettings.mergeSiteSetting(appState.get(propertyName), action.hostPattern, action.key, action.value)
if (action.skipSync) {
newSiteSettings = newSiteSettings.setIn([action.hostPattern, 'skipSync'], true)
}
appState = appState.set(propertyName, newSiteSettings)
break
}
case appConstants.APP_REMOVE_SITE_SETTING:
{
let propertyName = action.temporary ? 'temporarySiteSettings' : 'siteSettings'
let newSiteSettings = siteSettings.removeSiteSetting(appState.get(propertyName),
action.hostPattern, action.key)
if (action.skipSync) {
newSiteSettings = newSiteSettings.setIn([action.hostPattern, 'skipSync'], true)
}
appState = appState.set(propertyName, newSiteSettings)
break
}
case appConstants.APP_CLEAR_SITE_SETTINGS:
{
let propertyName = action.temporary ? 'temporarySiteSettings' : 'siteSettings'
let newSiteSettings = new Immutable.Map()
appState.get(propertyName).map((entry, hostPattern) => {
let newEntry = entry.delete(action.key)
if (action.skipSync) {
newEntry = newEntry.set('skipSync', true)
}
newSiteSettings = newSiteSettings.set(hostPattern, newEntry)
})
appState = appState.set(propertyName, newSiteSettings)
break
}
case appConstants.APP_SET_SKIP_SYNC:
{
if (appState.getIn(action.path)) {
appState = appState.setIn(action.path.concat(['skipSync']), action.skipSync)
}
break
}
case appConstants.APP_ADD_NOSCRIPT_EXCEPTIONS:
{
const propertyName = action.temporary ? 'temporarySiteSettings' : 'siteSettings'
// Note that this is always cleared on restart or reload, so should not
// be synced or persisted.
const key = 'noScriptExceptions'
if (!action.origins || !action.origins.size) {
// Clear the exceptions
appState = appState.setIn([propertyName, action.hostPattern, key], new Immutable.Map())
} else {
const currentExceptions = appState.getIn([propertyName, action.hostPattern, key]) || new Immutable.Map()
appState = appState.setIn([propertyName, action.hostPattern, key], currentExceptions.merge(action.origins))
}
}
break
case appConstants.APP_UPDATE_LEDGER_INFO:
appState = appState.set('ledgerInfo', Immutable.fromJS(action.ledgerInfo))
break
Expand Down Expand Up @@ -648,26 +583,6 @@ const handleAppAction = (action) => {
case appConstants.APP_HIDE_DOWNLOAD_DELETE_CONFIRMATION:
appState = appState.set('deleteConfirmationVisible', false)
break
case appConstants.APP_ENABLE_UNDEFINED_PUBLISHERS:
const sitesObject = appState.get('siteSettings')
Object.keys(action.publishers).map((item) => {
const pattern = `https?://${item}`
const siteSetting = sitesObject.get(pattern)
const result = (siteSetting) && (siteSetting.get('ledgerPayments'))

if (result === undefined) {
let newSiteSettings = siteSettings.mergeSiteSetting(appState.get('siteSettings'), pattern, 'ledgerPayments', true)
appState = appState.set('siteSettings', newSiteSettings)
}
})
break
case appConstants.APP_CHANGE_LEDGER_PINNED_PERCENTAGES:
Object.keys(action.publishers).map((item) => {
const pattern = `https?://${item}`
let newSiteSettings = siteSettings.mergeSiteSetting(appState.get('siteSettings'), pattern, 'ledgerPinPercentage', action.publishers[item].pinPercentage)
appState = appState.set('siteSettings', newSiteSettings)
})
break
case appConstants.APP_DEFAULT_SEARCH_ENGINE_LOADED:
appState = appState.set('searchDetail', action.searchDetail)
break
Expand Down
3 changes: 1 addition & 2 deletions test/about/ledgerTableTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,7 @@ describe('Ledger table', function () {
.waitForVisible(`${firstTableFirstRow} [data-switch-status="true"]`)
})

// TODO re-enable when #9641 is fixed
it.skip('check pinned sites amount, when you have 0 eligible unpinned sites', function * () {
it('check pinned sites amount, when you have 0 eligible unpinned sites', function * () {
yield this.app.client
.tabByIndex(0)
.click(`${secondTableFirstRow} [data-test-pinned="false"]`)
Expand Down