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

Commit

Permalink
Fixes add founds dialog
Browse files Browse the repository at this point in the history
Resolves #12078

Auditors:

Test Plan:
  • Loading branch information
NejcZdovc committed Dec 1, 2017
1 parent 1a00314 commit 02fd0e6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
7 changes: 4 additions & 3 deletions app/browser/api/ledgerNotifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ const nextAddFundsTime = 3 * ledgerUtil.milliseconds.day
const sufficientBalanceToReconcile = (state) => {
const balance = Number(ledgerState.getInfoProp(state, 'balance') || 0)
const unconfirmed = Number(ledgerState.getInfoProp(state, 'unconfirmed') || 0)
const bat = ledgerState.getInfoProp(state, 'bat')
return bat && (balance + unconfirmed > 0.9 * Number(bat))
const budget = parseInt(getSetting(settings.PAYMENTS_CONTRIBUTION_AMOUNT), 10) || 25
return balance + unconfirmed >= budget
}
const hasFunds = (state) => {
const balance = getSetting(settings.PAYMENTS_ENABLED)
Expand Down Expand Up @@ -435,7 +435,8 @@ const getMethods = () => {
getPollingInterval: () => {
return pollingInterval
},
onDynamicResponse
onDynamicResponse,
sufficientBalanceToReconcile
}
}

Expand Down
30 changes: 29 additions & 1 deletion test/unit/app/browser/api/ledgerNotificationsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ describe('ledgerNotifications unit test', function () {
let paymentsEnabled
let paymentsNotifications
let paymentsMinVisitTime = 5000
let paymentsContributionAmount = 25

const defaultAppState = Immutable.fromJS({
ledger: {},
Expand All @@ -38,14 +39,16 @@ describe('ledgerNotifications unit test', function () {
mockery.registerMock('ad-block', fakeAdBlock)
mockery.registerMock('level', fakeLevel)
mockery.registerMock('../../../js/settings', {
getSetting: (settingKey, settingsCollection, value) => {
getSetting: (settingKey) => {
switch (settingKey) {
case settings.PAYMENTS_ENABLED:
return paymentsEnabled
case settings.PAYMENTS_NOTIFICATIONS:
return paymentsNotifications
case settings.PAYMENTS_MINIMUM_VISIT_TIME:
return paymentsMinVisitTime
case settings.PAYMENTS_CONTRIBUTION_AMOUNT:
return paymentsContributionAmount
}
return false
}
Expand Down Expand Up @@ -637,4 +640,29 @@ describe('ledgerNotifications unit test', function () {
assert(hideNotificationSpy.calledOnce)
})
})

describe('sufficientBalanceToReconcile', function () {
it('null case', function () {
const result = ledgerNotificationsApi.sufficientBalanceToReconcile(defaultAppState)
assert.equal(result, false)
})

it('balance is bellow budget', function () {
const state = defaultAppState.setIn(['ledger', 'info', 'balance'], 10)
const result = ledgerNotificationsApi.sufficientBalanceToReconcile(state)
assert.equal(result, false)
})

it('balance is the same as budget', function () {
const state = defaultAppState.setIn(['ledger', 'info', 'balance'], 25)
const result = ledgerNotificationsApi.sufficientBalanceToReconcile(state)
assert.equal(result, true)
})

it('balance is above budget', function () {
const state = defaultAppState.setIn(['ledger', 'info', 'balance'], 30)
const result = ledgerNotificationsApi.sufficientBalanceToReconcile(state)
assert.equal(result, true)
})
})
})

0 comments on commit 02fd0e6

Please sign in to comment.