diff --git a/app/extensions/brave/locales/en-US/preferences.properties b/app/extensions/brave/locales/en-US/preferences.properties index e30be3bd8a2..3e9b48b23b9 100644 --- a/app/extensions/brave/locales/en-US/preferences.properties +++ b/app/extensions/brave/locales/en-US/preferences.properties @@ -86,7 +86,7 @@ off=off on=on ok=Ok minimumPercentage=Hide sites with less than 1% usage -autoSuggestSites=auto-suggest sites +autoSuggestSites=auto-include sites notifications=Show notifications moneyAdd=Use your debit/credit card moneyAddSubTitle=No Bitcoin needed! diff --git a/app/ledger.js b/app/ledger.js index 18142e1ade6..319ad157704 100644 --- a/app/ledger.js +++ b/app/ledger.js @@ -170,23 +170,37 @@ const doAction = (action) => { break case appConstants.APP_CHANGE_SITE_SETTING: + i = action.hostPattern.indexOf('://') + if (i === -1) break + + publisher = action.hostPattern.substr(i + 3) if (action.key === 'ledgerPaymentsShown') { if (action.value === false) { - i = action.hostPattern.indexOf('://') - if (i !== -1) { - publisher = action.hostPattern.substr(i + 3) - if (publisherInfo._internal.verboseP) console.log('\npurging ' + publisher) - delete synopsis.publishers[publisher] - delete publishers[publisher] - updatePublisherInfo() - } + if (publisherInfo._internal.verboseP) console.log('\npurging ' + publisher) + delete synopsis.publishers[publisher] + delete publishers[publisher] + updatePublisherInfo() } + } else if (action.key === 'ledgerPayments') { + if (!synopsis.publishers[publisher]) break + + if (publisherInfo._internal.verboseP) console.log('\nupdating ' + publisher + ' stickyP=' + action.value) + synopsis.publishers[publisher].options.stickyP = action.value + updatePublisherInfo() } break case appConstants.APP_REMOVE_SITE_SETTING: - if (action.key === 'ledgerPaymentsShown') { - // TODO + i = action.hostPattern.indexOf('://') + if (i === -1) break + + publisher = action.hostPattern.substr(i + 3) + if (action.key === 'ledgerPayments') { + if (!synopsis.publishers[publisher]) break + + if (publisherInfo._internal.verboseP) console.log('\nupdating ' + publisher + ' stickyP=' + true) + synopsis.publishers[publisher].options.stickyP = true + updatePublisherInfo() } break @@ -710,7 +724,8 @@ var enable = (paymentsEnabled) => { synopsis = new (ledgerPublisher.Synopsis)() fs.readFile(pathName(synopsisPath), (err, data) => { var initSynopsis = () => { - var value + var updateP, value + var siteSettings = appStore.getState().get('siteSettings') // cf., the `Synopsis` constructor, https://github.com/brave/ledger-publisher/blob/master/index.js#L167 value = getSetting(settings.MINIMUM_VISIT_TIME) @@ -743,6 +758,18 @@ var enable = (paymentsEnabled) => { synopsis.options.minPublisherVisits = ledgerClient.prototype.numbion(process.env.LEDGER_PUBLISHER_MIN_VISITS) } } + + underscore.keys(synopsis.publishers).forEach((publisher) => { + var siteSetting + + if (typeof synopsis.publishers[publisher].options.stickyP !== 'undefined') return + + updateP = true + siteSetting = siteSettings.get(`https?://${publisher}`) + synopsis.publishers[publisher].options.stickyP = siteSetting && siteSetting.get('ledgerPayments') + }) + + if (updateP) updatePublisherInfo() } if (publisherInfo._internal.verboseP) console.log('\nstarting up ledger publisher integration') @@ -849,10 +876,11 @@ var synopsisNormalizer = () => { results = [] underscore.keys(synopsis.publishers).forEach((publisher) => { - if (synopsis.publishers[publisher].scores[scorekeeper] <= 0) return - - if ((synopsis.options.minPublisherDuration > synopsis.publishers[publisher].duration) || - (synopsis.options.minPublisherVisits > synopsis.publishers[publisher].visits)) return + if ((getSetting(settings.AUTO_SUGGEST_SITES)) && (!synopsis.publishers[publisher].options.stickyP)) { + if ((synopsis.publishers[publisher].scores[scorekeeper] <= 0) || + (synopsis.options.minPublisherDuration > synopsis.publishers[publisher].duration) || + (synopsis.options.minPublisherVisits > synopsis.publishers[publisher].visits)) return + } results.push(underscore.extend({ publisher: publisher }, underscore.omit(synopsis.publishers[publisher], 'window'))) }, synopsis) @@ -1678,14 +1706,21 @@ const showDisabledNotifications = () => { */ const showEnabledNotifications = () => { const reconcileStamp = ledgerInfo.reconcileStamp - if (reconcileStamp && reconcileStamp - underscore.now() < msecs.day) { + + if (!reconcileStamp) return + + if (reconcileStamp - underscore.now() < msecs.day) { if (sufficientBalanceToReconcile()) { if (shouldShowNotificationReviewPublishers()) { - showNotificationReviewPublishers() + showNotificationReviewPublishers(reconcileStamp + (ledgerInfo.reconcileFrequency - 2) * msecs.day) } } else if (shouldShowNotificationAddFunds()) { showNotificationAddFunds() } + } else if (reconcileStamp - underscore.now() < 2 * msecs.day) { + if (sufficientBalanceToReconcile() && (shouldShowNotificationReviewPublishers())) { + showNotificationReviewPublishers(underscore.now() + msecs.day) + } } } @@ -1726,8 +1761,7 @@ const shouldShowNotificationReviewPublishers = () => { return !nextTime || (underscore.now() > nextTime) } -const showNotificationReviewPublishers = () => { - const nextTime = ledgerInfo.reconcileStamp + (ledgerInfo.reconcileFrequency - 1) * msecs.day +const showNotificationReviewPublishers = (nextTime) => { appActions.changeSetting(settings.PAYMENTS_NOTIFICATION_RECONCILE_SOON_TIMESTAMP, nextTime) reconciliationMessage = reconciliationMessage || locale.translation('reconciliationNotification') diff --git a/js/about/preferences.js b/js/about/preferences.js index f02414d2cf9..db4987e32b6 100644 --- a/js/about/preferences.js +++ b/js/about/preferences.js @@ -1252,7 +1252,14 @@ class PaymentsTab extends ImmutableComponent { } if (this.props.ledgerData.get('btc') && typeof this.props.ledgerData.get('amount') === 'number') { const btcValue = this.props.ledgerData.get('btc') / this.props.ledgerData.get('amount') - return `${currency} ${(balance / btcValue).toFixed(2)}` + const fiatValue = (balance / btcValue).toFixed(2) + let roundedValue = Math.floor(fiatValue) + const diff = fiatValue - roundedValue + + if (diff > 0.74) roundedValue += 0.75 + else if (diff > 0.49) roundedValue += 0.50 + else if (diff > 0.24) roundedValue += 0.25 + return `${currency} ${roundedValue.toFixed(2)}` } return `${balance} BTC` } diff --git a/package.json b/package.json index 4e90a07a286..986a03a6438 100644 --- a/package.json +++ b/package.json @@ -95,10 +95,10 @@ "immutablepatch": "brave/immutable-js-patch", "keytar": "^3.0.0", "l20n": "^3.5.1", - "ledger-balance": "^0.8.63", - "ledger-client": "^0.8.97", - "ledger-geoip": "^0.8.73", - "ledger-publisher": "^0.8.97", + "ledger-balance": "^0.8.64", + "ledger-client": "^0.8.106", + "ledger-geoip": "^0.8.75", + "ledger-publisher": "^0.8.108", "lru_cache": "^1.0.0", "moment": "^2.15.1", "normalize-url": "^1.7.0",