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

Commit

Permalink
In Add funds notification add button to turn off notifications
Browse files Browse the repository at this point in the history
Fix #5418

Auditors: @bsclifton

Test plan:
1. Trigger "Add funds" notification by having Payments enabled and editing session-store-1 reconcileDate to in the past
2. Observe notification with new "Turn off notification" button.
3. Click it
4. Open Preferences > Payments and click Advanced Settings... and observe notifications are disabled.
  • Loading branch information
ayumi committed Nov 8, 2016
1 parent e2ecdad commit aa08129
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 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
34 changes: 20 additions & 14 deletions app/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,12 +320,14 @@ 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
// Turn off notifications
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 Down Expand Up @@ -1495,23 +1497,26 @@ const showDisabledNotifications = () => {
const showEnabledNotifications = () => {
const reconcileStamp = ledgerInfo.reconcileStamp
if (reconcileStamp && reconcileStamp - underscore.now() < msecs.day) {
if (shouldShowNotificationAddFunds()) {
if (sufficientBalanceToReconcile()) {
if (shouldShowNotificationReviewPublishers()) {
showNotificationReviewPublishers()
}
} else if (shouldShowNotificationAddFunds()) {
showNotificationAddFunds()
} else if (shouldShowNotificationReviewPublishers()) {
showNotificationReviewPublishers()
}
}
}

const shouldShowNotificationAddFunds = () => {
const sufficientBalanceToReconcile = () => {
const balance = Number(ledgerInfo.balance || 0)
const unconfirmed = Number(ledgerInfo.unconfirmed || 0)
const nextTime = getSetting(settings.PAYMENTS_NOTIFICATION_ADD_FUNDS_TIMESTAMP)
if (nextTime && (nextTime > underscore.now())) {
return false
}
return ledgerInfo.btc &&
(balance + unconfirmed < 0.9 * Number(ledgerInfo.btc))
(balance + unconfirmed > 0.9 * Number(ledgerInfo.btc))
}

const shouldShowNotificationAddFunds = () => {
const nextTime = getSetting(settings.PAYMENTS_NOTIFICATION_ADD_FUNDS_TIMESTAMP)
return !nextTime || (underscore.now() > nextTime)
}

const showNotificationAddFunds = () => {
Expand All @@ -1523,6 +1528,7 @@ const showNotificationAddFunds = () => {
greeting: locale.translation('updateHello'),
message: addFundsMessage,
buttons: [
{text: locale.translation('turnOffNotifications')},
{text: locale.translation('updateLater')},
{text: locale.translation('addFunds'), className: 'primary'}
],
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: 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 aa08129

Please sign in to comment.