diff --git a/app/browser/api/ledger.js b/app/browser/api/ledger.js index 3377d23d25c..023f8239bd2 100644 --- a/app/browser/api/ledger.js +++ b/app/browser/api/ledger.js @@ -1675,12 +1675,6 @@ const getStateInfo = (state, parsedData) => { reconcileStamp: parsedData.reconcileStamp } - const oldReconcileStamp = ledgerState.getInfoProp(state, 'reconcileStamp') - - if (oldReconcileStamp && newInfo.reconcileStamp > oldReconcileStamp) { - state = ledgerState.setAboutProp(state, 'status', ledgerStatuses.IN_PROGRESS) - } - try { let passphrase = ledgerClient.prototype.getWalletPassphrase(parsedData) if (passphrase) { @@ -2035,6 +2029,10 @@ const onCallback = (state, result, delayTime) => { return state } + if (result.getIn(['currentReconcile', 'timestamp']) === 0) { + state = ledgerState.setAboutProp(state, 'status', ledgerStatuses.IN_PROGRESS) + } + const newAddress = result.getIn(['properties', 'wallet', 'addresses', 'BAT']) const oldAddress = ledgerState.getInfoProps(state).getIn(['addresses', 'BAT']) @@ -2462,8 +2460,8 @@ const run = (state, delayTime) => { return } - const publishers = ledgerState.getPublisher(state) - if (publishers.isEmpty() && client.isReadyToReconcile(synopsis)) { + const publishers = ledgerState.getAboutProp(state, 'synopsis') || Immutable.List() + if (isList(publishers) && publishers.isEmpty() && client.isReadyToReconcile(synopsis)) { setNewTimeUntilReconcile() } diff --git a/app/common/lib/ledgerUtil.js b/app/common/lib/ledgerUtil.js index 17631f24f2e..c59832fa203 100644 --- a/app/common/lib/ledgerUtil.js +++ b/app/common/lib/ledgerUtil.js @@ -95,7 +95,7 @@ const formattedDateFromTimestamp = (timestamp, dateFormat) => { return format(new Date(timestamp), dateFormat, {locale: navigator.language}) } -const walletStatus = (ledgerData) => { +const walletStatus = (ledgerData, settings) => { let status = {} if (ledgerData == null) { @@ -110,7 +110,7 @@ const walletStatus = (ledgerData) => { const transactions = ledgerData.get('transactions') const pendingFunds = Number(ledgerData.get('unconfirmed') || 0) const balance = Number(ledgerData.get('balance') || 0) - const minBalance = ledgerState.getContributionAmount(null, ledgerData.get('contributionAmount')) + const minBalance = ledgerState.getContributionAmount(null, ledgerData.get('contributionAmount'), settings) if (pendingFunds + balance < minBalance) { status.id = 'insufficientFundsStatus' diff --git a/app/renderer/components/preferences/payment/enabledContent.js b/app/renderer/components/preferences/payment/enabledContent.js index 2fef87fba40..c089be4f07b 100644 --- a/app/renderer/components/preferences/payment/enabledContent.js +++ b/app/renderer/components/preferences/payment/enabledContent.js @@ -373,7 +373,7 @@ class EnabledContent extends ImmutableComponent { render () { const ledgerData = this.props.ledgerData - const walletStatusText = walletStatus(ledgerData) + const walletStatusText = walletStatus(ledgerData, this.props.settings) const contributionAmount = ledgerState.getContributionAmount(null, ledgerData.get('contributionAmount'), this.props.settings) const amountList = ledgerData.get('monthlyAmounts') || ledgerUtil.defaultMonthlyAmounts diff --git a/app/renderer/components/preferences/paymentsTab.js b/app/renderer/components/preferences/paymentsTab.js index e39a757f917..286d8c4a707 100644 --- a/app/renderer/components/preferences/paymentsTab.js +++ b/app/renderer/components/preferences/paymentsTab.js @@ -371,7 +371,8 @@ class PaymentsTab extends ImmutableComponent { { this.enabled - ? {}, setPromotion: () => {}, setTimeUntilReconcile: () => {}, - isReadyToReconcile: () => {} + isReadyToReconcile: () => isReadyToReconcile } window.getWalletPassphrase = (parsedData) => { if (walletPassphraseReturn === 'error') { @@ -2155,6 +2156,40 @@ describe('ledger api unit tests', function () { assert.deepEqual(result.toJS(), expectedState.toJS()) }) }) + + describe('status', function () { + it('null case', function () { + const result = ledgerApi.onCallback(defaultAppState, null) + assert.deepEqual(result.toJS(), defaultAppState.toJS()) + }) + + it('reconcile is not in progress', function () { + const result = ledgerApi.onCallback(defaultAppState, Immutable.fromJS({ + properties: {} + })) + assert.deepEqual(result.toJS(), defaultAppState.toJS()) + }) + + it('reconcile is in progress (first time)', function () { + const result = ledgerApi.onCallback(defaultAppState, Immutable.fromJS({ + currentReconcile: { + timestamp: 0 + } + })) + const expectedState = defaultAppState + .setIn(['ledger', 'about', 'status'], ledgerStatuses.IN_PROGRESS) + assert.deepEqual(result.toJS(), expectedState.toJS()) + }) + + it('reconcile is in progress (second time)', function () { + const result = ledgerApi.onCallback(defaultAppState, Immutable.fromJS({ + currentReconcile: { + timestamp: 1 + } + })) + assert.deepEqual(result.toJS(), defaultAppState.toJS()) + }) + }) }) describe('uintKeySeed', function () { @@ -2875,50 +2910,110 @@ describe('ledger api unit tests', function () { }) }) - describe('BSCrun', function () { - let clientBallotsSpy + describe('run', function () { + describe('ballots', function () { + let clientBallotsSpy - before(() => { - ledgerApi.setSynopsis({ - toJSON: () => { - return { - publishers: { - 'clifton.io': { - visits: 1 + before(() => { + ledgerApi.setSynopsis({ + toJSON: () => { + return { + publishers: { + 'clifton.io': { + visits: 1 + } } } + }, + winners: () => { + return [] } - }, - winners: () => { - return [] - } + }) + ledgerApi.setClient(ledgerClientObject) + clientBallotsSpy = sinon.spy(ledgerClientObject, 'ballots') }) - ledgerApi.setClient(ledgerClientObject) - clientBallotsSpy = sinon.spy(ledgerClientObject, 'ballots') - }) - afterEach(() => { - clientBallotsSpy.reset() - }) + afterEach(() => { + clientBallotsSpy.reset() + }) - after(() => { - clientBallotsSpy.restore() - ledgerApi.setSynopsis(undefined) - }) + after(() => { + clientBallotsSpy.restore() + ledgerApi.setSynopsis(undefined) + }) - it('exits if state is undefined', function () { - ledgerApi.run(undefined, 10) - assert.equal(clientBallotsSpy.notCalled, true) - }) + it('exits if state is undefined', function () { + ledgerApi.run(undefined, 10) + assert.equal(clientBallotsSpy.notCalled, true) + }) + + it('exits if delayTime is undefined', function () { + ledgerApi.run(defaultAppState) + assert.equal(clientBallotsSpy.notCalled, true) + }) - it('exits if delayTime is undefined', function () { - ledgerApi.run(defaultAppState) - assert.equal(clientBallotsSpy.notCalled, true) + it('gets balance count from client', function () { + ledgerApi.run(defaultAppState, 10) + assert.equal(clientBallotsSpy.calledOnce, true) + }) }) - it('gets balance count from client', function () { - ledgerApi.run(defaultAppState, 10) - assert.equal(clientBallotsSpy.calledOnce, true) + describe('publishers check', function () { + before(() => { + ledgerApi.setClient(ledgerClientObject) + ledgerSetTimeUntilReconcile.reset() + }) + + afterEach(() => { + ledgerSetTimeUntilReconcile.reset() + isReadyToReconcile = false + }) + + it('null check', function () { + ledgerApi.run(defaultAppState, 10) + assert(ledgerSetTimeUntilReconcile.notCalled) + }) + + it('synopsis is broken', function () { + const state = defaultAppState + .setIn(['ledger', 'about', 'synopsis'], 'test') + ledgerApi.run(state, 10) + assert(ledgerSetTimeUntilReconcile.notCalled) + }) + + it('table is empty and we are not ready to reconcile', function () { + const state = defaultAppState + .setIn(['ledger', 'about', 'synopsis'], Immutable.fromJS([{ + publisherKey: 'clifton.io' + }])) + ledgerApi.run(state, 10) + assert(ledgerSetTimeUntilReconcile.notCalled) + }) + + it('table is not empty and we are not ready to reconcile', function () { + const state = defaultAppState + .setIn(['ledger', 'about', 'synopsis'], Immutable.fromJS([{ + publisherKey: 'clifton.io' + }])) + ledgerApi.run(state, 10) + assert(ledgerSetTimeUntilReconcile.notCalled) + }) + + it('table is not empty and we are ready to reconcile', function () { + isReadyToReconcile = true + const state = defaultAppState + .setIn(['ledger', 'about', 'synopsis'], Immutable.fromJS([{ + publisherKey: 'clifton.io' + }])) + ledgerApi.run(state, 10) + assert(ledgerSetTimeUntilReconcile.notCalled) + }) + + it('table is empty and we are ready to reconcile', function () { + isReadyToReconcile = true + ledgerApi.run(defaultAppState, 10) + assert(ledgerSetTimeUntilReconcile.calledOnce) + }) }) })