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

Limit 24 hour payment notification to once per reconcile period #5296

Merged
merged 1 commit into from
Oct 31, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️ ++

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
Copy link
Member

@bsclifton bsclifton Oct 31, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be more of a @bradleyrichter question... but I wonder if this should this be covering both cases?

Let's say you're within 24 hours of reconciling and you only have the ~5 dollars in your account. You'd dismiss the nag window but then you're out of budget after reconciliation happens. This is a case where you might want to get nagged again sometime before the next reconciliation period (especially since getting funds in might take > 24 hours)

(if action needed, can be done in a follow up 😄)

'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