diff --git a/app/extensions/brave/locales/en-US/app.properties b/app/extensions/brave/locales/en-US/app.properties index de5e0370aa4..3071e13f17b 100644 --- a/app/extensions/brave/locales/en-US/app.properties +++ b/app/extensions/brave/locales/en-US/app.properties @@ -55,6 +55,8 @@ reloadButton.title=Reload page homeButton.title=Open Homepage stopButton.title=Stop loading noScriptButton.title=Allow scripts +enablePublisher.title=Enable publisher for payments +disablePublisher.title=Disable publisher for payments braveMenu.title=Open Brave Shields Panel muteTab=Mute tab unmuteTab=Unmute tab diff --git a/app/extensions/brave/locales/en-US/preferences.properties b/app/extensions/brave/locales/en-US/preferences.properties index 8a9cdded959..e30be3bd8a2 100644 --- a/app/extensions/brave/locales/en-US/preferences.properties +++ b/app/extensions/brave/locales/en-US/preferences.properties @@ -21,6 +21,7 @@ paymentsWelcomeText5=Note: Brave Payments uses a country-lookup service in order paymentsWelcomeText6=Need more info? paymentsWelcomeText7=for Brave Payments… paymentsWelcomeLink=View the FAQ +paymentsFAQLink.title=View the FAQ paymentsSidebarText1=Our Partners paymentsSidebarText2=All transaction IP addresses are anonymized with technology from: paymentsSidebarText3=Brave Bitcoin Wallets are provided through a partnership with: @@ -52,7 +53,7 @@ viewPaymentHistory=View Payment History… paymentHistoryTitle=Your Payment History paymentHistoryFooterText=Your next payment contribution is {{reconcileDate}}. paymentHistoryOKText=OK -hideExcluded=hide excluded sites +hideExcluded=Only show included sites bravePayments=Brave Payments beta=beta contributionDate=Contribution Date @@ -85,6 +86,7 @@ off=off on=on ok=Ok minimumPercentage=Hide sites with less than 1% usage +autoSuggestSites=auto-suggest sites notifications=Show notifications moneyAdd=Use your debit/credit card moneyAddSubTitle=No Bitcoin needed! diff --git a/app/ledger.js b/app/ledger.js index a7bc54ec716..18142e1ade6 100644 --- a/app/ledger.js +++ b/app/ledger.js @@ -519,7 +519,7 @@ eventStore.addChangeListener(() => { // NB: in theory we have already seen every element in info except for (perhaps) the last one... underscore.rest(info, info.length - 1).forEach((page) => { - var entry, faviconURL, publisher, siteSetting + var entry, faviconURL, pattern, publisher, siteSetting var location = page.url if ((location.match(/^about/)) || ((locations[location]) && (locations[location].publisher))) return @@ -540,6 +540,10 @@ eventStore.addChangeListener(() => { if (!page.publisher) return publisher = page.publisher + pattern = `https?://${publisher}` + if ((!synopsis.publishers[publisher]) && (!getSetting(settings.AUTO_SUGGEST_SITES))) { + appActions.changeSiteSetting(pattern, 'ledgerPayments', false) + } synopsis.initPublisher(publisher) entry = synopsis.publishers[publisher] if ((page.protocol) && (!entry.protocol)) entry.protocol = page.protocol diff --git a/app/renderer/components/publisherToggle.js b/app/renderer/components/publisherToggle.js new file mode 100644 index 00000000000..ee37326117f --- /dev/null +++ b/app/renderer/components/publisherToggle.js @@ -0,0 +1,96 @@ +/* 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 React = require('react') +const tldjs = require('tldjs') +const ImmutableComponent = require('../../../js/components/immutableComponent') +const appActions = require('../../../js/actions/appActions') +const settings = require('../../../js/constants/settings') +const getSetting = require('../../../js/settings').getSetting +const cx = require('../../../js/lib/classSet') +const Button = require('../../../js/components/button') + +class PublisherToggle extends ImmutableComponent { + constructor () { + super() + this.onAuthorizePublisher = this.onAuthorizePublisher.bind(this) + } + + get domain () { + return tldjs.getDomain(this.props.url) + } + + get hostPattern () { + return `https?://${this.domain}` + } + + get hostSettings () { + // hostPattern defines it's own identifier for authorized publishers + // sites that do not match criteria would populate siteSettings + // with their default protocol, not hostPattern + return this.props.hostSettings.get(this.hostPattern) + } + + get validPublisherSynopsis () { + // If session is clear then siteSettings is undefined and icon will never be shown, + // but synopsis may not be empty. In such cases let's check if synopsis matches current domain + return this.props.synopsis.map(entry => entry.get('site')).includes(this.domain) + } + + get enabledPublisher () { + // If we can't get ledgerPayments, then it's likely that we are + // on a clean session. Let's then check for publisher's synopsis + return this.hostSettings + ? this.hostSettings.get('ledgerPayments') !== false + : this.validPublisherSynopsis + } + + get visiblePublisher () { + // ledgerPaymentsShown is undefined by default until user decide to permanently hide the publisher + // so for icon to be shown it can be everything but false + const ledgerPaymentsShown = this.hostSettings && this.hostSettings.get('ledgerPaymentsShown') + return ledgerPaymentsShown === 'undefined' || ledgerPaymentsShown !== false + } + + get shouldShowAddPublisherButton () { + if ((!!this.hostSettings || !!this.validPublisherSynopsis) && this.visiblePublisher) { + // Only show publisher icon if autoSuggest option is OFF + return !getSetting(settings.AUTO_SUGGEST_SITES) + } + return false + } + + onAuthorizePublisher () { + // if payments disabled, enable it + if (!getSetting(settings.AUTO_SUGGEST_SITES)) { + appActions.changeSetting(settings.PAYMENTS_ENABLED, true) + } + + this.enabledPublisher + ? appActions.changeSiteSetting(this.hostPattern, 'ledgerPayments', false) + : appActions.changeSiteSetting(this.hostPattern, 'ledgerPayments', true) + } + + render () { + return this.shouldShowAddPublisherButton + ? +