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

Commit

Permalink
Notification suggesting the user try Payments
Browse files Browse the repository at this point in the history
Auditors: @bsclifton @diracdeltas

Test Plan:
1. Edit `ledger.js` to reduce showNotifications delay interval to 3 * msecs.second
2. Run Brave with an existing profile
3. Confirm there's no notification
4. Close Brave
5. Update userData session-store-1 firstRunTimestamp to be way in the past e.g. from '14..' to '13..' (~/Library/Application\ Support/session-store-1)
6. Open Brave
7. Confirm notification
  • Loading branch information
ayumi committed Sep 22, 2016
1 parent 2850702 commit 35971f5
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 16 deletions.
3 changes: 3 additions & 0 deletions app/extensions/brave/locales/en-US/app.properties
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,12 @@ notificationPasswordWithUserName=Would you like Brave to remember the password f
notificationPassword=Would you like Brave to remember your password on {{origin}}?
notificationPasswordSettings=[Password settings]
notificationPaymentDone=Your contribution of {{amount}} {{currency}} has been processed. Thanks for supporting your favorite websites!
notificationTryPayments=Are you ready to support the sites you use most?
notificationTryPaymentsYes=Sure, I'll try
prefsRestart=Do you want to restart now?
yes=Yes
no=No
noThanks=No thanks
neverForThisSite=Never for this site
browserHistory=Browser history
downloadHistory=Download history
Expand Down
73 changes: 57 additions & 16 deletions app/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const underscore = require('underscore')
const uuid = require('node-uuid')

const appActions = require('../js/actions/appActions')
const appConfig = require('../js/constants/appConfig')
const appConstants = require('../js/constants/appConstants')
const appDispatcher = require('../js/dispatcher/appDispatcher')
const messages = require('../js/constants/messages')
Expand Down Expand Up @@ -100,6 +101,7 @@ const msecs = { year: 365 * 24 * 60 * 60 * 1000,
let addFundsMessage
let reconciliationMessage
let notificationPaymentDoneMessage
let notificationTryPaymentsMessage
let suppressNotifications = false
let reconciliationNotificationShown = false
let notificationTimeout = null
Expand Down Expand Up @@ -252,6 +254,13 @@ if (ipc) {
setTimeout(() => { reconciliationNotificationShown = false }, 1 * msecs.day)
} else if (message === notificationPaymentDoneMessage) {
appActions.hideMessageBox(message)
} else if (message === notificationTryPaymentsMessage) {
appActions.hideMessageBox(message)
if (buttonIndex === 1 && win) {
win.webContents.send(messages.SHORTCUT_NEW_FRAME,
'about:preferences#payments', { singleFrame: true })
}
appActions.changeSetting(settings.PAYMENTS_NOTIFICATION_TRY_PAYMENTS_DISMISSED, true)
}
})

Expand Down Expand Up @@ -383,6 +392,12 @@ eventStore.addChangeListener(() => {
var initialize = (onoff) => {
enable(onoff)

// Check if relevant browser notifications should be shown every 15 minutes
if (notificationTimeout) {
clearInterval(notificationTimeout)
}
notificationTimeout = setInterval(showNotifications, 15 * msecs.minute)

if (!onoff) {
client = null
return appActions.updateLedgerInfo({})
Expand Down Expand Up @@ -430,12 +445,12 @@ var initialize = (onoff) => {
}

var enable = (onoff) => {
if (onoff && !getSetting(settings.PAYMENTS_NOTIFICATION_TRY_PAYMENTS_DISMISSED)) {
appActions.changeSetting(settings.PAYMENTS_NOTIFICATION_TRY_PAYMENTS_DISMISSED, true)
}

if (!onoff) {
synopsis = null
if (notificationTimeout) {
clearInterval(notificationTimeout)
notificationTimeout = null
}
return updatePublisherInfo()
}

Expand Down Expand Up @@ -475,9 +490,6 @@ var enable = (onoff) => {
})
updatePublisherInfo()

// Check if relevant browser notifications should be shown every 15 minutes
notificationTimeout = setInterval(showNotifications, 15 * msecs.minute)

fs.readFile(pathName(publisherPath), (err, data) => {
if (err) {
if (err.code !== 'ENOENT') console.log('publisherPath read error: ' + err.toString())
Expand Down Expand Up @@ -1290,17 +1302,46 @@ var pathName = (name) => {
* UI controller functionality
*/

/**
* Show message that it's time to add funds if reconciliation is less than
* a day in the future and balance is too low.
* 24 hours prior to reconciliation, show message asking user to review
* their votes.
*/
const showNotifications = () => {
if (!getSetting(settings.PAYMENTS_ENABLED) ||
!getSetting(settings.PAYMENTS_NOTIFICATIONS) || suppressNotifications) {
return
if (getSetting(settings.PAYMENTS_ENABLED) &&
getSetting(settings.PAYMENTS_NOTIFICATIONS) &&
!suppressNotifications) {
showEnabledNotifications()
} else if (!getSetting(settings.PAYMENTS_ENABLED)) {
showDisabledNotifications()
}
}

// When Payments is disabled
const showDisabledNotifications = () => {
if (!getSetting(settings.PAYMENTS_NOTIFICATION_TRY_PAYMENTS_DISMISSED)) {
const firstRunTimestamp = appStore.getState().get('firstRunTimestamp')
if (new Date().getTime() - firstRunTimestamp < appConfig.payments.delayNotificationTryPayments) {
return
}
notificationTryPaymentsMessage = locale.translation('notificationTryPayments')
appActions.showMessageBox({
greeting: locale.translation('updateHello'),
message: notificationTryPaymentsMessage,
buttons: [
{text: locale.translation('noThanks')},
{text: locale.translation('notificationTryPaymentsYes'), className: 'primary'}
],
options: {
style: 'greetingStyle',
persist: false
}
})
}
}

/**
* Show message that it's time to add funds if reconciliation is less than
* a day in the future and balance is too low.
* 24 hours prior to reconciliation, show message asking user to review
* their votes.
*/
const showEnabledNotifications = () => {
const reconcileStamp = ledgerInfo.reconcileStamp
const balance = Number(ledgerInfo.balance || 0)
const unconfirmed = Number(ledgerInfo.unconfirmed || 0)
Expand Down
3 changes: 3 additions & 0 deletions app/locale.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,12 @@ var rendererIdentifiers = function () {
'notificationPassword',
'notificationPasswordSettings',
'notificationPaymentDone',
'notificationTryPayments',
'notificationTryPaymentsYes',
'prefsRestart',
'yes',
'no',
'noThanks',
'neverForThisSite',
'passwordsManager',
'downloadItemPause',
Expand Down
4 changes: 4 additions & 0 deletions js/constants/appConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ module.exports = {
crashes: {
crashSubmitUrl: crashURL
},
payments: {
delayNotificationTryPayments: 1000 * 60 * 60 * 24 * 10 // 10 days (from firstRunTimestamp)
},
updates: {
// Check for front end updates every hour
appUpdateCheckFrequency: 1000 * 60 * 60,
Expand Down Expand Up @@ -103,6 +106,7 @@ module.exports = {
'bookmarks.toolbar.showOnlyFavicon': false,
'payments.enabled': false,
'payments.notifications': false,
'payments.notificationTryPaymentsDismissed': false, // True if you dismiss the message or enable Payments
'payments.contribution-amount': 5, // USD
'privacy.autofill-enabled': true,
'privacy.do-not-track': false,
Expand Down
1 change: 1 addition & 0 deletions js/constants/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const settings = {
// Payments Tab
PAYMENTS_ENABLED: 'payments.enabled',
PAYMENTS_NOTIFICATIONS: 'payments.notifications',
PAYMENTS_NOTIFICATION_TRY_PAYMENTS_DISMISSED: 'payments.notificationTryPaymentsDismissed',
PAYMENTS_CONTRIBUTION_AMOUNT: 'payments.contribution-amount',
// Advanced settings
HARDWARE_ACCELERATION_ENABLED: 'advanced.hardware-acceleration-enabled',
Expand Down

0 comments on commit 35971f5

Please sign in to comment.