diff --git a/app/ledger.js b/app/ledger.js index 4a41564319b..13cb370c2fd 100644 --- a/app/ledger.js +++ b/app/ledger.js @@ -594,9 +594,14 @@ eventStore.addChangeListener(() => { pattern = `https?://${publisher}` initP = !synopsis.publishers[publisher] synopsis.initPublisher(publisher) - if ((initP) && (getSetting(settings.AUTO_SUGGEST_SITES))) { + if (initP) { excludeP(publisher, (unused, exclude) => { - appActions.changeSiteSetting(pattern, 'ledgerPayments', !exclude) + if (!getSetting(settings.AUTO_SUGGEST_SITES)) { + exclude = false + } else { + exclude = !exclude + } + appActions.changeSiteSetting(pattern, 'ledgerPayments', exclude) updatePublisherInfo() }) } @@ -849,6 +854,9 @@ var enable = (paymentsEnabled) => { }) updatePublisherInfo() + // change undefined include publishers to include publishers + appActions.enableUndefinedPublishers(synopsis.publishers) + fs.readFile(pathName(publisherPath), (err, data) => { if (err) { if (err.code !== 'ENOENT') console.log('publisherPath read error: ' + err.toString()) @@ -985,7 +993,12 @@ var stickyP = (publisher) => { result = synopsis.publishers[publisher].options.stickyP appActions.changeSiteSetting(pattern, 'ledgerPayments', result) } - delete synopsis.publishers[publisher].options.stickyP + + if (synopsis.publishers[publisher] && + synopsis.publishers[publisher].options && + synopsis.publishers[publisher].options.stickyP) { + delete synopsis.publishers[publisher].options.stickyP + } return (result || false) } diff --git a/app/renderer/components/preferences/payment/ledgerTable.js b/app/renderer/components/preferences/payment/ledgerTable.js index b235ae97b85..82f8f494194 100644 --- a/app/renderer/components/preferences/payment/ledgerTable.js +++ b/app/renderer/components/preferences/payment/ledgerTable.js @@ -59,7 +59,7 @@ class LedgerTable extends ImmutableComponent { return result } } - return true + return getSetting(settings.AUTO_SUGGEST_SITES, this.props.settings) } shouldShow (synopsis) { @@ -101,7 +101,7 @@ class LedgerTable extends ImmutableComponent { const publisherURL = synopsis.get('publisherURL') const percentage = synopsis.get('percentage') const site = synopsis.get('site') - const defaultSiteSetting = true + const defaultAutoInclude = this.enabledForSite(synopsis) return [ { @@ -131,7 +131,7 @@ class LedgerTable extends ImmutableComponent { { html: , diff --git a/docs/appActions.md b/docs/appActions.md index 7d18c235ebd..f2884d8431d 100644 --- a/docs/appActions.md +++ b/docs/appActions.md @@ -798,6 +798,17 @@ Open dialog for default download path setting +### enableUndefinedPublishers(publishers) + +Change all undefined publishers in site settings to defined sites +also change all undefined ledgerPayments to value true + +**Parameters** + +**publishers**: `Object`, publishers from the synopsis + + + * * * diff --git a/js/actions/appActions.js b/js/actions/appActions.js index 09d2268b3a7..942fdbd3d6c 100644 --- a/js/actions/appActions.js +++ b/js/actions/appActions.js @@ -979,6 +979,18 @@ const appActions = { AppDispatcher.dispatch({ actionType: appConstants.APP_DOWNLOAD_DEFAULT_PATH }) + }, + + /** + * Change all undefined publishers in site settings to defined sites + * also change all undefined ledgerPayments to value true + * @param publishers {Object} publishers from the synopsis + */ + enableUndefinedPublishers: function (publishers) { + AppDispatcher.dispatch({ + actionType: appConstants.APP_ENABLE_UNDEFINED_PUBLISHERS, + publishers + }) } } diff --git a/js/constants/appConstants.js b/js/constants/appConstants.js index 2e3785d1203..262874397d6 100644 --- a/js/constants/appConstants.js +++ b/js/constants/appConstants.js @@ -98,7 +98,8 @@ const appConstants = { APP_TAB_MESSAGE_BOX_DISMISSED: _, APP_TAB_MESSAGE_BOX_UPDATED: _, APP_NAVIGATOR_HANDLER_REGISTERED: _, - APP_NAVIGATOR_HANDLER_UNREGISTERED: _ + APP_NAVIGATOR_HANDLER_UNREGISTERED: _, + APP_ENABLE_UNDEFINED_PUBLISHERS: _ } module.exports = mapValuesByKeys(appConstants) diff --git a/js/stores/appStore.js b/js/stores/appStore.js index 4a51697c477..00a60d81322 100644 --- a/js/stores/appStore.js +++ b/js/stores/appStore.js @@ -896,6 +896,21 @@ 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) + const syncObject = siteUtil.setObjectId(newSiteSettings.get(pattern)) + newSiteSettings = newSiteSettings.set(pattern, syncObject) + appState = appState.set('siteSettings', newSiteSettings) + } + }) + break default: } diff --git a/test/components/ledgerPanelTest.js b/test/components/ledgerPanelTest.js index a976cf41cf8..cf8d98b1005 100644 --- a/test/components/ledgerPanelTest.js +++ b/test/components/ledgerPanelTest.js @@ -3,6 +3,7 @@ const Brave = require('../lib/brave') const {urlInput, advancedSettingsButton, addFundsButton, paymentsWelcomePage, paymentsTab, walletSwitch, siteSettingItem, ledgerTable} = require('../lib/selectors') const assert = require('assert') +const settings = require('../../js/constants/settings') const prefsUrl = 'about:preferences' const ledgerAPIWaitTimeout = 20000 @@ -113,6 +114,110 @@ describe('Regular payment panel tests', function () { .waitForEnabled(addFundsButton) }) }) + + describe('auto include', function () { + Brave.beforeAll(this) + + before(function * () { + yield setup(this.app.client) + yield this.app.client + .changeSetting(settings.AUTO_SUGGEST_SITES, true) + .tabByIndex(0) + .loadUrl(prefsUrl) + .waitForVisible(paymentsTab) + .click(paymentsTab) + .waitForVisible(paymentsWelcomePage) + .waitForVisible(walletSwitch) + .click(walletSwitch) + .waitForEnabled(addFundsButton) + }) + + it('site is added automatically', function * () { + const site1 = 'http://example.com/' + const site2 = 'https://www.eff.org/' + yield this.app.client + .loadUrl(site1) + .windowByUrl(Brave.browserWindowUrl) + .waitForSiteEntry(site1) + .tabByUrl(site1) + .loadUrl(site2) + .windowByUrl(Brave.browserWindowUrl) + .waitForSiteEntry(site2) + .tabByUrl(site2) + .loadUrl(prefsUrl) + .waitForVisible(paymentsTab) + .click(paymentsTab) + .waitForVisible('[data-l10n-id="publisher"]') + .waitUntil(function () { + return this.getAppState().then((val) => { + return val.value.siteSettings['https?://example.com'].ledgerPayments === true + }) + }) + .waitUntil(function () { + return this.getAppState().then((val) => { + return val.value.siteSettings['https?://eff.org'].ledgerPayments === true + }) + }) + }) + + it('site is not added automatically', function * () { + const site1 = 'http://example.com/' + const site2 = 'https://www.eff.org/' + yield this.app.client + .changeSetting(settings.AUTO_SUGGEST_SITES, false) + .loadUrl(site1) + .windowByUrl(Brave.browserWindowUrl) + .waitForSiteEntry(site1) + .tabByUrl(site1) + .loadUrl(site2) + .windowByUrl(Brave.browserWindowUrl) + .waitForSiteEntry(site2) + .tabByUrl(site2) + .loadUrl(prefsUrl) + .waitForVisible(paymentsTab) + .click(paymentsTab) + .waitForVisible('[data-l10n-id="publisher"]') + .waitUntil(function () { + return this.getAppState().then((val) => { + return val.value.siteSettings['https?://example.com'].ledgerPayments === false + }) + }) + .waitUntil(function () { + return this.getAppState().then((val) => { + return val.value.siteSettings['https?://eff.org'].ledgerPayments === false + }) + }) + }) + + it('first site included, second site excluded', function * () { + const site1 = 'http://example.com/' + const site2 = 'https://www.eff.org/' + yield this.app.client + .loadUrl(site1) + .windowByUrl(Brave.browserWindowUrl) + .waitForSiteEntry(site1) + .tabByUrl(site1) + .changeSetting(settings.AUTO_SUGGEST_SITES, false) + .loadUrl(site2) + .windowByUrl(Brave.browserWindowUrl) + .waitForSiteEntry(site2) + .tabByUrl(site2) + .loadUrl(prefsUrl) + .waitForVisible(paymentsTab) + .click(paymentsTab) + .waitForVisible('[data-l10n-id="publisher"]') + .waitUntil(function () { + return this.getAppState().then((val) => { + return val.value.siteSettings['https?://example.com'].ledgerPayments === true + }) + }) + .waitUntil(function () { + return this.getAppState().then((val) => { + return val.value.siteSettings['https?://eff.org'].ledgerPayments === false + }) + }) + }) + }) }) describe('synopsis', function () {