diff --git a/app/extensions/brave/locales/en-US/app.properties b/app/extensions/brave/locales/en-US/app.properties index 393da974902..8b14d320e83 100644 --- a/app/extensions/brave/locales/en-US/app.properties +++ b/app/extensions/brave/locales/en-US/app.properties @@ -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 diff --git a/app/ledger.js b/app/ledger.js index e3ce6b1101e..69bc0b9fd4a 100644 --- a/app/ledger.js +++ b/app/ledger.js @@ -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 }) @@ -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) { @@ -1494,29 +1500,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 = () => { @@ -1533,8 +1557,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', @@ -1554,6 +1579,7 @@ const showNotificationPaymentDone = (transactionContributionFiat) => { greeting: locale.translation('updateHello'), message: notificationPaymentDoneMessage, buttons: [ + {text: locale.translation('turnOffNotifications')}, {text: locale.translation('Ok'), className: 'primary'} ], options: { diff --git a/app/locale.js b/app/locale.js index 903cda383df..f0fdc9e1ee4 100644 --- a/app/locale.js +++ b/app/locale.js @@ -193,6 +193,7 @@ var rendererIdentifiers = function () { 'reconciliationNotification', 'reviewSites', 'addFunds', + 'turnOffNotifications', 'copyToClipboard', 'smartphoneTitle', 'displayQRCode', diff --git a/js/constants/appConfig.js b/js/constants/appConfig.js index 2a0ce0f20d2..59c28c728c6 100644 --- a/js/constants/appConfig.js +++ b/js/constants/appConfig.js @@ -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, diff --git a/js/constants/settings.js b/js/constants/settings.js index 4e3f6786ebd..63994072dd6 100644 --- a/js/constants/settings.js +++ b/js/constants/settings.js @@ -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', diff --git a/less/notificationBar.less b/less/notificationBar.less index 8c3bcdf1d81..94388ea0cdb 100644 --- a/less/notificationBar.less +++ b/less/notificationBar.less @@ -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;