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

Commit

Permalink
Merge pull request #13913 from ryanml/publisher-toggle-context-menu
Browse files Browse the repository at this point in the history
Allowing publisher toggle to include a site outside of the minimum payment requirements
  • Loading branch information
NejcZdovc committed Apr 26, 2018
2 parents 3d3ec33 + 93254a6 commit 9a04a69
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/browser/api/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,7 @@ const shouldTrackTab = (state, tabId) => {

const addNewLocation = (state, location, tabId = tabState.TAB_ID_NONE, keepInfo = false, manualAdd = false) => {
// We always want to have the latest active tabId
const currentTabId = manualAdd ? tabState.TAB_ID_NONE : pageDataState.getLastActiveTabId(state)
const currentTabId = manualAdd ? tabId : pageDataState.getLastActiveTabId(state)
state = pageDataState.setLastActiveTabId(state, tabId)
if (location === currentUrl && !manualAdd) {
return state
Expand Down
5 changes: 4 additions & 1 deletion app/browser/reducers/ledgerReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,16 @@ const ledgerReducer = (state, action, immutableAction) => {
}
case appConstants.APP_ADD_PUBLISHER_TO_LEDGER:
{
const tabId = action.get('tabId')
const location = action.get('location')

if (!location) {
break
}

state = ledgerApi.addNewLocation(state, location, tabState.TAB_ID_NONE, false, true)
const passedTabId = tabId || tabState.TAB_ID_NONE

state = ledgerApi.addNewLocation(state, location, passedTabId, false, true)
state = ledgerApi.pageDataChanged(state, {}, true)
break
}
Expand Down
2 changes: 1 addition & 1 deletion app/extensions/brave/locales/en-US/app.properties
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ notificationTryPaymentsYes=Sure, I'll try
notificationUpdatePassword=Would you like Brave to update your password on {{origin}}?
notificationUpdatePasswordWithUserName=Would you like Brave to update the password for {{username}} on {{origin}}?
notNow=Not Now
notVisiblePublisher.title=Publisher is not yet added to the ledger, because it doesn't meet criteria yet.
notVisiblePublisher.title=Publisher is not yet added to the ledger, click to include in Brave Payments.
ok=OK
openTypeInNewPrivateTab=Open {{type}} in a new private tab
openTypeInNewTab=Open {{type}} in a new tab
Expand Down
7 changes: 7 additions & 0 deletions app/renderer/components/navigation/publisherToggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const BrowserButton = require('../common/browserButton')
const appActions = require('../../../../js/actions/appActions')

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

// Utils
Expand Down Expand Up @@ -51,18 +52,24 @@ class PublisherToggle extends React.Component {
onAuthorizePublisher () {
if (this.props.isVisibleInLedger) {
appActions.changeSiteSetting(this.props.hostPattern, 'ledgerPayments', !this.props.isEnabledForPaymentsPublisher)
} else {
appActions.addPublisherToLedger(this.props.location, this.props.tabId)
appActions.changeSiteSetting(this.props.hostPattern, 'ledgerPayments', true)
}
}

mergeProps (state, ownProps) {
const currentWindow = state.get('currentWindow')
const activeFrame = frameStateUtil.getActiveFrame(currentWindow) || Immutable.Map()
const tabId = activeFrame.get('tabId', tabState.TAB_ID_NONE)
const location = activeFrame.get('location', '')
const locationId = getBaseUrl(location)
const publisherKey = ledgerState.getVerifiedPublisherLocation(state, locationId)

const props = {}
// used in renderer
props.tabId = tabId
props.location = location
props.isVisibleInLedger = ledgerUtil.visibleP(state, publisherKey)
props.isEnabledForPaymentsPublisher = ledgerUtil.stickyP(state, publisherKey)
props.isVerifiedPublisher = ledgerState.getPublisherOption(state, publisherKey, 'verified')
Expand Down
5 changes: 3 additions & 2 deletions js/actions/appActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1834,10 +1834,11 @@ const appActions = {
* Dispatches a message to add a given publisher to the ledger.
* @param location - the URL of the publisher
*/
addPublisherToLedger: function (location) {
addPublisherToLedger: function (location, tabId = false) {
dispatch({
actionType: appConstants.APP_ADD_PUBLISHER_TO_LEDGER,
location
location,
tabId
})
},

Expand Down
37 changes: 35 additions & 2 deletions test/unit/app/browser/reducers/ledgerReducerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,8 @@ describe('ledgerReducer unit tests', function () {
describe('APP_ADD_PUBLISHER_TO_LEDGER', function () {
let addNewLocationSpy
let pageDataChangedSpy
const tabIdNone = -1
const testTabId = 7

beforeEach(function () {
addNewLocationSpy = sinon.spy(fakeLedgerApi, 'addNewLocation')
Expand All @@ -736,7 +738,8 @@ describe('ledgerReducer unit tests', function () {
it('executes', function () {
const newState = ledgerReducer(appState, Immutable.fromJS({
actionType: appConstants.APP_ADD_PUBLISHER_TO_LEDGER,
location: 'https://brave.com'
location: 'https://brave.com',
tabId: false
}))
assert(addNewLocationSpy.calledOnce)
assert(pageDataChangedSpy.calledOnce)
Expand All @@ -746,11 +749,41 @@ describe('ledgerReducer unit tests', function () {
it('takes no action with a null location', function () {
const newState = ledgerReducer(appState, Immutable.fromJS({
actionType: appConstants.APP_ADD_PUBLISHER_TO_LEDGER,
location: null
location: null,
tabId: false
}))
assert(addNewLocationSpy.notCalled)
assert(pageDataChangedSpy.notCalled)
assert.deepEqual(newState, appState)
})

it('tab Id passed is equal to tabState.TAB_ID_NONE when not added via toggle', function () {
ledgerReducer(appState, Immutable.fromJS({
actionType: appConstants.APP_ADD_PUBLISHER_TO_LEDGER,
location: 'https://brave.com',
tabId: false
}))
assert.equal(tabIdNone, addNewLocationSpy.getCall(0).args[2])
})

it('executes when dispatched with a tab id', function () {
const newState = ledgerReducer(appState, Immutable.fromJS({
actionType: appConstants.APP_ADD_PUBLISHER_TO_LEDGER,
location: 'https://brave.com',
tabId: testTabId
}))
assert(addNewLocationSpy.calledOnce)
assert(pageDataChangedSpy.calledOnce)
assert.notDeepEqual(newState, appState)
})

it('tab Id passed to addNewLocation is equal to passed tabId', function () {
ledgerReducer(appState, Immutable.fromJS({
actionType: appConstants.APP_ADD_PUBLISHER_TO_LEDGER,
location: 'https://brave.com',
tabId: testTabId
}))
assert.equal(testTabId, addNewLocationSpy.getCall(0).args[2])
})
})
})

0 comments on commit 9a04a69

Please sign in to comment.