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 #12593 from NejcZdovc/hotfix/#12592-delete
Browse files Browse the repository at this point in the history
Fixes qr code when it is new
  • Loading branch information
bsclifton committed Jan 11, 2018
1 parent 8b002f0 commit f679930
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 4 deletions.
14 changes: 13 additions & 1 deletion app/browser/api/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ const paymentPresent = (state, tabId, present) => {
}

const getPublisherTimestamp = (updateList) => {
if (!client) {
return
}

client.publisherTimestamp((err, result) => {
if (err) {
console.error('Error while retrieving publisher timestamp', err.toString())
Expand Down Expand Up @@ -1716,6 +1720,13 @@ const onCallback = (state, result, delayTime) => {
return state
}

const newAddress = result.getIn(['properties', 'wallet', 'addresses', 'BAT'])
const oldAddress = ledgerState.getInfoProps(state).getIn(['addresses', 'BAT'])

if (newAddress !== oldAddress) {
state = ledgerState.setInfoProp(state, 'walletQR', Immutable.Map())
}

const regularResults = result.toJS()

if (client && result.getIn(['properties', 'wallet'])) {
Expand Down Expand Up @@ -2644,7 +2655,8 @@ const getMethods = () => {
observeTransactions,
onWalletRecovery,
getStateInfo,
lockInContributionAmount
lockInContributionAmount,
callback
}
}

Expand Down
43 changes: 40 additions & 3 deletions test/unit/app/browser/api/ledgerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -1802,9 +1802,9 @@ describe('ledger api unit tests', function () {

it('check multiple publishers', function () {
const multiple = stateWithData
.setIn(['ledger', 'synopsis', 'publishers', 'brave.com'], Immutable.fromJS({
visits: 1
}))
.setIn(['ledger', 'synopsis', 'publishers', 'brave.com'], Immutable.fromJS({
visits: 1
}))
ledgerApi.onPublisherTimestamp(multiple, 10, 20)

assert.equal(checkVerifiedStatusSpy.getCall(0).args[1], 'clifton.io')
Expand Down Expand Up @@ -1841,4 +1841,41 @@ describe('ledger api unit tests', function () {
})
})
})

describe('onCallback', function () {
describe('wallet QR', function () {
const resultParam = Immutable.fromJS({
properties: {
wallet: {
addresses: {
BAT: 'address'
}
}
}
})

it('do not clear QR codes when address is the same', function () {
const stateWithData = defaultAppState
.setIn(['ledger', 'info', 'addresses', 'BAT'], 'address')
.setIn(['ledger', 'info', 'walletQR', 'BAT', 'qr'])

const result = ledgerApi.onCallback(stateWithData, resultParam)
assert.deepEqual(result.toJS(), stateWithData.toJS())
})

it('clear QR code when we get new addresses', function () {
const stateWithData = defaultAppState
.setIn(['ledger', 'info', 'addresses', 'BAT'], 'old address')
.setIn(['ledger', 'info', 'walletQR', 'BAT'], 'qr')

// address is not different because we get it from the client in another call
const expectedState = defaultAppState
.setIn(['ledger', 'info', 'addresses', 'BAT'], 'old address')
.setIn(['ledger', 'info', 'walletQR'], Immutable.Map())

const result = ledgerApi.onCallback(stateWithData, resultParam)
assert.deepEqual(result.toJS(), expectedState.toJS())
})
})
})
})

0 comments on commit f679930

Please sign in to comment.