diff --git a/app/ledger.js b/app/ledger.js index 11bf33ad1f6..de434050443 100644 --- a/app/ledger.js +++ b/app/ledger.js @@ -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) @@ -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 @@ -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)