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 #5296 from brave/fix/calm-ledger-notifications
Browse files Browse the repository at this point in the history
Limit 24 hour payment notification to once per reconcile period
  • Loading branch information
bsclifton authored Oct 31, 2016
2 parents 8d41f61 + addfd70 commit 26ee3a8
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 24 deletions.
55 changes: 31 additions & 24 deletions app/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ let addFundsMessage
let reconciliationMessage
let notificationPaymentDoneMessage
let notificationTryPaymentsMessage
let suppressNotifications = false
let reconciliationNotificationShown = false
let notificationTimeout = null

// TODO(bridiver) - create a better way to get setting changes
Expand Down Expand Up @@ -323,9 +321,9 @@ if (ipc) {
if (message === addFundsMessage) {
appActions.hideMessageBox(message)
if (buttonIndex === 0) {
// Don't show notifications for the next 6 hours.
suppressNotifications = true
setTimeout(() => { suppressNotifications = false }, 6 * msecs.hour)
// "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
if (win) {
Expand All @@ -339,9 +337,6 @@ if (ipc) {
win.webContents.send(messages.SHORTCUT_NEW_FRAME,
'about:preferences#payments', { singleFrame: true })
}
// If > 24 hours has passed, it might be time to show the reconciliation
// message again
setTimeout(() => { reconciliationNotificationShown = false }, 1 * msecs.day)
} else if (message === notificationPaymentDoneMessage) {
appActions.hideMessageBox(message)
} else if (message === notificationTryPaymentsMessage) {
Expand Down Expand Up @@ -889,6 +884,7 @@ var ledgerInfo = {
creating: false,
created: false,

reconcileFrequency: undefined,
reconcileStamp: undefined,

transactions:
Expand Down Expand Up @@ -1194,6 +1190,7 @@ var getStateInfo = (state) => {
ledgerInfo.created = !!state.properties.wallet
ledgerInfo.creating = !ledgerInfo.created

ledgerInfo.reconcileFrequency = state.properties.days
ledgerInfo.reconcileStamp = state.reconcileStamp

if (info) {
Expand Down Expand Up @@ -1442,8 +1439,7 @@ var pathName = (name) => {

const showNotifications = () => {
if (getSetting(settings.PAYMENTS_ENABLED) &&
getSetting(settings.PAYMENTS_NOTIFICATIONS) &&
!suppressNotifications) {
getSetting(settings.PAYMENTS_NOTIFICATIONS)) {
showEnabledNotifications()
} else if (!getSetting(settings.PAYMENTS_ENABLED)) {
showDisabledNotifications()
Expand Down Expand Up @@ -1500,24 +1496,35 @@ const showEnabledNotifications = () => {
persist: false
}
})
} else if (!reconciliationNotificationShown) {
reconciliationMessage = reconciliationMessage || locale.translation('reconciliationNotification')
appActions.showMessageBox({
greeting: locale.translation('updateHello'),
message: reconciliationMessage,
buttons: [
{text: locale.translation('reviewSites'), className: 'primary'}
],
options: {
style: 'greetingStyle',
persist: false
}
})
reconciliationNotificationShown = true
} else if (shouldShowNotificationReviewPublishers()) {
showNotificationReviewPublishers()
}
}
}

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

const showNotificationReviewPublishers = () => {
const nextTime = ledgerInfo.reconcileStamp + (ledgerInfo.reconcileFrequency - 1) * msecs.day
appActions.changeSetting(settings.PAYMENTS_NOTIFICATION_RECONCILE_SOON_TIMESTAMP, nextTime)

reconciliationMessage = reconciliationMessage || locale.translation('reconciliationNotification')
appActions.showMessageBox({
greeting: locale.translation('updateHello'),
message: reconciliationMessage,
buttons: [
{text: locale.translation('reviewSites'), className: 'primary'}
],
options: {
style: 'greetingStyle',
persist: false
}
})
}

// Called from observeTransactions() when we see a new payment (transaction).
const showNotificationPaymentDone = (transactionContributionFiat) => {
notificationPaymentDoneMessage = locale.translation('notificationPaymentDone')
Expand Down
1 change: 1 addition & 0 deletions docs/state.md
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ WindowStore
ledgerInfo: {
creating: boolean, // wallet is being created
created: boolean, // wallet is created
reconcileFrequency: number, // duration between each reconciliation in days
reconcileStamp: number, // timestamp for the next reconcilation
transactions: [ { // contributions reconciling/reconciled
viewingId: string, // UUIDv4 for this contribution
Expand Down
3 changes: 3 additions & 0 deletions js/constants/appConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ module.exports = {
'bookmarks.toolbar.showOnlyFavicon': false,
'payments.enabled': false,
'payments.notifications': false,
// "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,
'payments.notificationTryPaymentsDismissed': false, // True if you dismiss the message or enable Payments
'payments.contribution-amount': 5, // USD
'privacy.autofill-enabled': true,
Expand Down
1 change: 1 addition & 0 deletions js/constants/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const settings = {
// Payments Tab
PAYMENTS_ENABLED: 'payments.enabled',
PAYMENTS_NOTIFICATIONS: 'payments.notifications',
PAYMENTS_NOTIFICATION_RECONCILE_SOON_TIMESTAMP: 'notification-reconcile-soon-timestamp',
PAYMENTS_NOTIFICATION_TRY_PAYMENTS_DISMISSED: 'payments.notificationTryPaymentsDismissed',
PAYMENTS_CONTRIBUTION_AMOUNT: 'payments.contribution-amount',
// Advanced settings
Expand Down

0 comments on commit 26ee3a8

Please sign in to comment.