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

Commit

Permalink
Limit 24 hour payment notification to once per reconcile period
Browse files Browse the repository at this point in the history
Fix #4481

Auditors: @bsclifton

Test Plan:
1. Trigger the "Payment in 24 hours, please review" notification.
  - Update reconcileStamp to <24 hours from now
  - Have sufficient funds; OR disable the sufficient funds conditional by adding false to ledger.js L1485 (showEnabledNotifications())
  - Change startup notification delay in ledger.js L484 from 15m to 5s
2. Open Brave and observe 24h review notification
3. Close Brave and reopen. Notification should not reappear.
(Next 24h notification timestamp is set in Application Support/brave-development/session-store-1)
  • Loading branch information
ayumi committed Oct 31, 2016
1 parent d299153 commit c4d20f6
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,

reconcilePeriod: 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.reconcilePeriod = 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.reconcilePeriod - 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
reconcilePeriod: number, // duration of each reconciliation period 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 c4d20f6

Please sign in to comment.