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 #5469 from brave/fix/payments-add-funds-quiet
Browse files Browse the repository at this point in the history
"Add funds" notification: Reduce nag level and add button to "Turn off notifications"
  • Loading branch information
bsclifton authored Nov 9, 2016
2 parents eb3351d + 967e5de commit 08f1860
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 28 deletions.
1 change: 1 addition & 0 deletions app/extensions/brave/locales/en-US/app.properties
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ flashSubtext=from {{source}} on {{site}}.
flashExpirationText=Approvals reset 7 days after last visit.
addFundsNotification=Your Brave Payments account is waiting for a deposit.
reconciliationNotification=Good news! Brave will pay your favorite publisher sites in less than 24 hours.
turnOffNotifications=Turn off notifications
reviewSites=Review your chosen sites
dismiss=Dismiss
addFunds=Add funds
Expand Down
80 changes: 53 additions & 27 deletions app/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,12 +320,13 @@ if (ipc) {
const win = electron.BrowserWindow.getFocusedWindow()
if (message === addFundsMessage) {
appActions.hideMessageBox(message)
// See showNotificationAddFunds() for buttons.
// buttonIndex === 1 is "Later"; the timestamp until which to delay is set
// in showNotificationAddFunds() when triggering this notification.
if (buttonIndex === 0) {
// "Later" -- wait 6 hours to re-show "reconciliation soon" notification.
const nextTime = ledgerInfo.reconcileStamp + 6 * msecs.hour
appActions.changeSetting(settings.PAYMENTS_NOTIFICATION_RECONCILE_SOON_TIMESTAMP, nextTime)
} else {
// Open payments panel
appActions.changeSetting(settings.PAYMENTS_NOTIFICATIONS, false)
} else if (buttonIndex === 2) {
// Add funds: Open payments panel
if (win) {
win.webContents.send(messages.SHORTCUT_NEW_FRAME,
'about:preferences#payments', { singleFrame: true })
Expand All @@ -334,12 +335,17 @@ if (ipc) {
} else if (message === reconciliationMessage) {
appActions.hideMessageBox(message)
// buttonIndex === 1 is Dismiss
if (buttonIndex === 0 && win) {
if (buttonIndex === 0) {
appActions.changeSetting(settings.PAYMENTS_NOTIFICATIONS, false)
} else if (buttonIndex === 2 && win) {
win.webContents.send(messages.SHORTCUT_NEW_FRAME,
'about:preferences#payments', { singleFrame: true })
}
} else if (message === notificationPaymentDoneMessage) {
appActions.hideMessageBox(message)
if (buttonIndex === 0) {
appActions.changeSetting(settings.PAYMENTS_NOTIFICATIONS, false)
}
} else if (message === notificationTryPaymentsMessage) {
appActions.hideMessageBox(message)
if (buttonIndex === 1 && win) {
Expand Down Expand Up @@ -1493,29 +1499,47 @@ const showDisabledNotifications = () => {
*/
const showEnabledNotifications = () => {
const reconcileStamp = ledgerInfo.reconcileStamp
if (reconcileStamp && reconcileStamp - underscore.now() < msecs.day) {
if (sufficientBalanceToReconcile()) {
if (shouldShowNotificationReviewPublishers()) {
showNotificationReviewPublishers()
}
} else if (shouldShowNotificationAddFunds()) {
showNotificationAddFunds()
}
}
}

const sufficientBalanceToReconcile = () => {
const balance = Number(ledgerInfo.balance || 0)
const unconfirmed = Number(ledgerInfo.unconfirmed || 0)
return ledgerInfo.btc &&
(balance + unconfirmed > 0.9 * Number(ledgerInfo.btc))
}

if (reconcileStamp && reconcileStamp - underscore.now() < msecs.day) {
if (ledgerInfo.btc &&
balance + unconfirmed < 0.9 * Number(ledgerInfo.btc)) {
addFundsMessage = addFundsMessage || locale.translation('addFundsNotification')
appActions.showMessageBox({
greeting: locale.translation('updateHello'),
message: addFundsMessage,
buttons: [
{text: locale.translation('updateLater')},
{text: locale.translation('addFunds'), className: 'primary'}
],
options: {
style: 'greetingStyle',
persist: false
}
})
} else if (shouldShowNotificationReviewPublishers()) {
showNotificationReviewPublishers()
const shouldShowNotificationAddFunds = () => {
const nextTime = getSetting(settings.PAYMENTS_NOTIFICATION_ADD_FUNDS_TIMESTAMP)
return !nextTime || (underscore.now() > nextTime)
}

const showNotificationAddFunds = () => {
const nextTime = underscore.now() + 3 * msecs.day
appActions.changeSetting(settings.PAYMENTS_NOTIFICATION_ADD_FUNDS_TIMESTAMP, nextTime)

addFundsMessage = addFundsMessage || locale.translation('addFundsNotification')
appActions.showMessageBox({
greeting: locale.translation('updateHello'),
message: addFundsMessage,
buttons: [
{text: locale.translation('turnOffNotifications')},
{text: locale.translation('updateLater')},
{text: locale.translation('addFunds'), className: 'primary'}
],
options: {
style: 'greetingStyle',
persist: false
}
}
})
}

const shouldShowNotificationReviewPublishers = () => {
Expand All @@ -1532,8 +1556,9 @@ const showNotificationReviewPublishers = () => {
greeting: locale.translation('updateHello'),
message: reconciliationMessage,
buttons: [
{text: locale.translation('reviewSites'), className: 'primary'},
{text: locale.translation('dismiss')}
{text: locale.translation('turnOffNotifications')},
{text: locale.translation('dismiss')},
{text: locale.translation('reviewSites'), className: 'primary'}
],
options: {
style: 'greetingStyle',
Expand All @@ -1553,6 +1578,7 @@ const showNotificationPaymentDone = (transactionContributionFiat) => {
greeting: locale.translation('updateHello'),
message: notificationPaymentDoneMessage,
buttons: [
{text: locale.translation('turnOffNotifications')},
{text: locale.translation('Ok'), className: 'primary'}
],
options: {
Expand Down
1 change: 1 addition & 0 deletions app/locale.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ var rendererIdentifiers = function () {
'reconciliationNotification',
'reviewSites',
'addFunds',
'turnOffNotifications',
'copyToClipboard',
'smartphoneTitle',
'displayQRCode',
Expand Down
2 changes: 2 additions & 0 deletions js/constants/appConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ module.exports = {
'bookmarks.toolbar.showOnlyFavicon': false,
'payments.enabled': false,
'payments.notifications': false,
// "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]"
// After shown, set timestamp to next reconcile time - 1 day.
'payments.notification-reconcile-soon-timestamp': null,
Expand Down
1 change: 1 addition & 0 deletions js/constants/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const settings = {
// Payments Tab
PAYMENTS_ENABLED: 'payments.enabled',
PAYMENTS_NOTIFICATIONS: 'payments.notifications',
PAYMENTS_NOTIFICATION_ADD_FUNDS_TIMESTAMP: 'notification-add-funds-timestamp',
PAYMENTS_NOTIFICATION_RECONCILE_SOON_TIMESTAMP: 'notification-reconcile-soon-timestamp',
PAYMENTS_NOTIFICATION_TRY_PAYMENTS_DISMISSED: 'payments.notificationTryPaymentsDismissed',
PAYMENTS_CONTRIBUTION_AMOUNT: 'payments.contribution-amount',
Expand Down
2 changes: 1 addition & 1 deletion less/notificationBar.less
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
font-size: 14px;
height: 25px;
line-height: 27px;
margin: auto 4px;
margin: auto 0 auto 4px;
padding: 0px 25px;
width: auto;

Expand Down

0 comments on commit 08f1860

Please sign in to comment.