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

Retool the ledger updates into the 0.13.1-branch #6706

Merged
merged 3 commits into from
Jan 20, 2017
Merged
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
2 changes: 1 addition & 1 deletion app/extensions/brave/locales/en-US/preferences.properties
Original file line number Diff line number Diff line change
@@ -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!
72 changes: 53 additions & 19 deletions app/ledger.js
Original file line number Diff line number Diff line change
@@ -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')
9 changes: 8 additions & 1 deletion js/about/preferences.js
Original file line number Diff line number Diff line change
@@ -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`
}
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",