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

Commit

Permalink
tweak on publisher logic
Browse files Browse the repository at this point in the history
  • Loading branch information
cezaraugusto committed Dec 28, 2016
1 parent 3f1a302 commit caa2865
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 13 deletions.
3 changes: 2 additions & 1 deletion app/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -1676,5 +1676,6 @@ module.exports = {
recoverKeys: recoverKeys,
backupKeys: backupKeys,
quit: quit,
boot: boot
boot: boot,
locations: locations
}
9 changes: 9 additions & 0 deletions docs/state.md
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,15 @@ WindowStore
}
},
publisherInfo: {
location: {
[url] { // Publisher location
timestamp: number,
protocol: string, // http or https
faviconURL: string, // URL of the favicon
publisher: string // publisher site, e.g., "https://wikipedia.org/"
}
},

synopsis: [ { // one entry for each publisher having a non-zero `score`
rank: number, // i.e., 1, 2, 3, ...
verified: boolean, // there is a verified wallet for this publisher
Expand Down
1 change: 1 addition & 0 deletions js/components/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,7 @@ class Main extends ImmutableComponent {
noScriptIsVisible={noScriptIsVisible}
menubarVisible={customTitlebar.menubarVisible}
allSiteSettings={allSiteSettings}
publisherInfo={this.props.appState.get('publisherInfo') || new Immutable.Map()}
/>
<div className='topLevelEndButtons'>
<div className={cx({
Expand Down
28 changes: 16 additions & 12 deletions js/components/navigationBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,21 @@ class NavigationBar extends ImmutableComponent {

get enabledPublisher () {
const hostSettings = this.props.allSiteSettings.get(this.hostPattern)
return hostSettings && hostSettings.get('ledgerPayments') !== false
}

get shouldShowAddPublisherButton () {
const publisherLocation = this.props.publisherInfo.get('location')
const hostSettings = this.props.allSiteSettings.get(this.hostPattern)

if (hostSettings) {
const result = hostSettings.get('ledgerPayments')
if (typeof result === 'boolean') {
return result
} else {
// Sometimes result can be {}. If so, assume it's true
return true
if (hostSettings && publisherLocation) {
const ledgerPaymentsShown = hostSettings.get('ledgerPaymentsShown')
const validPublisher = !!publisherLocation.get(this.props.location)

if (validPublisher && ledgerPaymentsShown !== false) {
return !getSetting(settings.AUTO_SUGGEST_SITES) && !getSetting(settings.HIDE_EXCLUDED_SITES)
}
}
// Return false if we can't find the hostPattern
return false
}

Expand All @@ -162,14 +166,14 @@ class NavigationBar extends ImmutableComponent {
// Left Publisher disabled after inserted on Payments
// until the user toggle enabled payment option
this.enabledPublisher
this.shouldShowAddPublisherButton
}

render () {
if (this.props.activeFrameKey === undefined) {
return null
}

const showAddPublisherButton = !getSetting(settings.AUTO_SUGGEST_SITES) && !getSetting(settings.HIDE_EXCLUDED_SITES)
console.log('LOCATION HERE -----------------', !!this.props.publisherInfo)

return <div id='navigator'
ref='navigator'
Expand Down Expand Up @@ -247,7 +251,7 @@ class NavigationBar extends ImmutableComponent {
urlbar={this.props.navbar.get('urlbar')}
onStop={this.onStop}
menubarVisible={this.props.menubarVisible}
noBorderRadius={showAddPublisherButton}
noBorderRadius={this.shouldShowAddPublisherButton}
/>
{
isSourceAboutUrl(this.props.location)
Expand All @@ -256,7 +260,7 @@ class NavigationBar extends ImmutableComponent {
</div>
: <div className='endButtons'>
{
showAddPublisherButton
this.shouldShowAddPublisherButton
? <span className={cx({
addPublisherButtonContainer: true,
authorizedPublisher: this.enabledPublisher
Expand Down
3 changes: 3 additions & 0 deletions js/stores/appStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,9 @@ const handleAppAction = (action) => {
}
appState = aboutNewTabState.setSites(appState, action)
appState = aboutHistoryState.setHistory(appState, action)

const location = ledger.locations
appState = appState.setIn(['publisherInfo', 'location'], Immutable.fromJS(location))
break
case appConstants.APP_REMOVE_SITE:
appState = appState.set('sites', siteUtil.removeSite(appState.get('sites'), action.siteDetail, action.tag))
Expand Down

0 comments on commit caa2865

Please sign in to comment.