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 #4516 from brave/ensure-reconcile-time-is-not-hist…
Browse files Browse the repository at this point in the history
…oric

reset reconciliation time when publisher window is closed
  • Loading branch information
mrose17 authored Oct 4, 2016
2 parents 0274699 + d6c3a7a commit 44ecd3b
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions app/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ const doAction = (action) => {
case appConstants.APP_CHANGE_SETTING:
switch (action.key) {
case settings.PAYMENTS_ENABLED:
initialize(action.value, 'changeSettingPaymentsEnabled')
initialize(action.value)
break
case settings.PAYMENTS_CONTRIBUTION_AMOUNT:
setPaymentInfo(action.value)
Expand Down Expand Up @@ -415,7 +415,7 @@ eventStore.addChangeListener(() => {
* module initialization
*/

var initialize = (paymentsEnabled, reason) => {
var initialize = (paymentsEnabled) => {
enable(paymentsEnabled)

// Check if relevant browser notifications should be shown every 15 minutes
Expand Down Expand Up @@ -458,17 +458,19 @@ var initialize = (paymentsEnabled, reason) => {
// Scenario: User enables Payments, disables it, waits 30+ days, then
// enables it again -> reconcileStamp is in the past.
// In this case reset reconcileStamp to the future.
if (reason === 'changeSettingPaymentsEnabled') {
let timeUntilReconcile = client.timeUntilReconcile()
if (typeof timeUntilReconcile === 'number' && timeUntilReconcile < 0) {
client.setTimeUntilReconcile(null, (_, stateResult) => {
if (!stateResult) {
return
}
ledgerInfo.reconcileStamp = stateResult.reconcileStamp
syncWriter(pathName(statePath), stateResult, () => {})
})
}
let timeUntilReconcile = client.timeUntilReconcile()
let ledgerWindow = (synopsis.options.numFrames - 1) * synopsis.options.frameSize
if (typeof timeUntilReconcile === 'number' && timeUntilReconcile < -ledgerWindow) {
client.setTimeUntilReconcile(null, (err, stateResult) => {
if (err) return console.log('ledger setTimeUntilReconcile error: ' + err.toString())

if (!stateResult) {
return
}
getStateInfo(stateResult)

syncWriter(pathName(statePath), stateResult, () => {})
})
}
} catch (ex) {
return console.log('ledger client creation error: ' + ex.toString() + '\n' + ex.stack)
Expand Down

0 comments on commit 44ecd3b

Please sign in to comment.