Skip to content

Commit

Permalink
Adds non-verified option to the payment page
Browse files Browse the repository at this point in the history
Resolves brave#8231

Auditors: @mrose17 @bsclifton

Test Plan:
- go to payments page
- click on advance settings
- disabled option "Allow contributions to non-verified sites"
- all non-verified sites should be hidden from a table
  • Loading branch information
NejcZdovc committed Apr 21, 2017
1 parent 90d9290 commit 229de66
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 12 deletions.
1 change: 1 addition & 0 deletions app/extensions/brave/locales/en-US/preferences.properties
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ on=on
ok=Ok
autoSuggestSites=auto-include
notifications=Show notifications
nonVerifiedPublishers=Allow contributions to non-verified sites
moneyAdd=Use your debit/credit card
moneyAddSubTitle=No Bitcoin needed!
outsideUSAPayment=Buy Bitcoin at our recommended source
Expand Down
40 changes: 28 additions & 12 deletions app/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ const doAction = (action) => {
updatePublisherInfo()
break

case settings.PAYMENTS_NON_VERIFIED:
synopsis.options.showOnlyVerified = action.value
updatePublisherInfo()
break

default:
break
}
Expand Down Expand Up @@ -1039,11 +1044,16 @@ var eligibleP = (publisher) => {
}

var visibleP = (publisher) => {
const onlyVerified = !synopsis.options.showOnlyVerified
return (
eligibleP(publisher) &&
(
synopsis.publishers[publisher].options.exclude !== true ||
stickyP(publisher)
) &&
(
(onlyVerified && synopsis.publishers[publisher].options && synopsis.publishers[publisher].options.verified) ||
!onlyVerified
)
) &&
!blockedP(publisher)
Expand Down Expand Up @@ -1160,18 +1170,25 @@ var synopsisNormalizer = (changedPublisher) => {

// round if over 100% of pinned publishers
if (pinnedTotal > 100) {
const changedObject = dataPinned.filter(publisher => publisher.site === changedPublisher)[0]
const setOne = changedObject.pinPercentage > (100 - dataPinned.length - 1)
if (changedPublisher) {
const changedObject = dataPinned.filter(publisher => publisher.site === changedPublisher)[0]
const setOne = changedObject.pinPercentage > (100 - dataPinned.length - 1)

if (setOne) {
changedObject.pinPercentage = 100 - dataPinned.length + 1
changedObject.weight = changedObject.pinPercentage
}
if (setOne) {
changedObject.pinPercentage = 100 - dataPinned.length + 1
changedObject.weight = changedObject.pinPercentage
}

const pinnedRestTotal = pinnedTotal - changedObject.pinPercentage
dataPinned = dataPinned.filter(publisher => publisher.site !== changedPublisher)
dataPinned = normalizePinned(dataPinned, pinnedRestTotal, (100 - changedObject.pinPercentage), setOne)
dataPinned = roundToTarget(dataPinned, (100 - changedObject.pinPercentage), 'pinPercentage')
const pinnedRestTotal = pinnedTotal - changedObject.pinPercentage
dataPinned = dataPinned.filter(publisher => publisher.site !== changedPublisher)
dataPinned = normalizePinned(dataPinned, pinnedRestTotal, (100 - changedObject.pinPercentage), setOne)
dataPinned = roundToTarget(dataPinned, (100 - changedObject.pinPercentage), 'pinPercentage')

dataPinned.push(changedObject)
} else {
dataPinned = normalizePinned(dataPinned, pinnedTotal, 100)
dataPinned = roundToTarget(dataPinned, 100, 'pinPercentage')
}

dataUnPinned = dataUnPinned.map((result) => {
let publisher = getPublisherData(result)
Expand All @@ -1180,8 +1197,6 @@ var synopsisNormalizer = (changedPublisher) => {
return publisher
})

dataPinned.push(changedObject)

// sync app store
appActions.changeLedgerPinnedPercentages(dataPinned)
} else if (dataUnPinned.length === 0 && pinnedTotal < 100) {
Expand Down Expand Up @@ -1485,6 +1500,7 @@ var ledgerInfo = {
// advanced ledger settings
minPublisherDuration: undefined,
minPublisherVisits: undefined,
showOnlyVerified: undefined,

hasBitcoinHandler: false,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ class AdvancedSettingsContent extends ImmutableComponent {
prefKey={settings.PAYMENTS_NOTIFICATIONS}
settings={this.props.settings}
onChangeSetting={this.props.onChangeSetting}
className={css(styles.listItem)}
switchClassName={css(styles.checkboxSwitch)}
labelClassName={css(commonStyles.noMarginBottom)}
/>
<SettingCheckbox
dataL10nId='nonVerifiedPublishers'
prefKey={settings.PAYMENTS_NON_VERIFIED}
settings={this.props.settings}
onChangeSetting={this.props.onChangeSetting}
className={css(styles.listItem, commonStyles.noMarginBottom)}
switchClassName={css(styles.checkboxSwitch)}
labelClassName={css(commonStyles.noMarginBottom)}
Expand Down
1 change: 1 addition & 0 deletions js/constants/appConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ module.exports = {
'bookmarks.toolbar.showOnlyFavicon': false,
'payments.enabled': false,
'payments.notifications': false,
'payments.non-verified-publishers': true,
// "Add funds to your wallet" -- Limit to once every n days to reduce nagging.
'payments.notification-add-funds-timestamp': null,
// "Out of money, pls add" / "In 24h we'll pay publishers [Review]"
Expand Down
1 change: 1 addition & 0 deletions js/constants/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const settings = {
PAYMENTS_NOTIFICATION_RECONCILE_SOON_TIMESTAMP: 'notification-reconcile-soon-timestamp',
PAYMENTS_NOTIFICATION_TRY_PAYMENTS_DISMISSED: 'payments.notificationTryPaymentsDismissed',
PAYMENTS_CONTRIBUTION_AMOUNT: 'payments.contribution-amount',
PAYMENTS_NON_VERIFIED: 'payments.non-verified-publishers',
// Advanced settings
HARDWARE_ACCELERATION_ENABLED: 'advanced.hardware-acceleration-enabled',
PDFJS_ENABLED: 'advanced.pdfjs-enabled',
Expand Down

0 comments on commit 229de66

Please sign in to comment.