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

Commit

Permalink
Fixes overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
NejcZdovc committed Oct 23, 2017
1 parent d037100 commit 37b6568
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
25 changes: 20 additions & 5 deletions app/browser/api/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -1756,7 +1756,14 @@ const setPaymentInfo = (amount) => {
amount = parseInt(amount, 10)
if (isNaN(amount) || (amount <= 0)) return

underscore.extend(bravery.fee, { amount: amount, currency: client.getWalletAddresses().BAT ? 'BAT' : 'USD' })
let currency = 'USD'
const addresses = client.getWalletAddresses()

if (addresses && addresses.BAT) {
currency = 'BAT'
}

underscore.extend(bravery.fee, { amount: amount, currency: currency })
client.setBraveryProperties(bravery, (err, result) => {
if (err) {
err = err.toString()
Expand Down Expand Up @@ -1917,6 +1924,7 @@ const initialize = (state, paymentsEnabled) => {

if (!paymentsEnabled) {
client = null
newClient = false
return ledgerState.resetInfo(state)
}

Expand Down Expand Up @@ -2218,7 +2226,7 @@ const migration = (state) => {
}
})
} catch (err) {
console.log('Error migrating file', err.toString())
console.log(err.toString())
}

// Delete ledgerInfo
Expand Down Expand Up @@ -2285,6 +2293,10 @@ const checkBtcBatMigrated = (state, status) => {
}

let newClient = null
const getNewClient = () => {
return newClient
}

const transitionWalletToBat = () => {
let newPaymentId, result

Expand Down Expand Up @@ -2334,7 +2346,9 @@ const transitionWalletToBat = () => {

if (typeof delayTime === 'undefined') delayTime = random.randomInt({ min: 1, max: 500 })

muonWriter(newClientPath, newClient.state)
if (newClient) {
muonWriter(newClientPath, newClient.state)
}

setTimeout(() => transitionWalletToBat(), delayTime)
})
Expand All @@ -2350,7 +2364,7 @@ const transitionWalletToBat = () => {

try {
client.transition(newPaymentId, (err, properties) => {
if (err) {
if (err || newClient == null) {
console.error('ledger client transition error: ', err)
} else {
result = newClient.transitioned(properties)
Expand Down Expand Up @@ -2398,5 +2412,6 @@ module.exports = {
onInitRead,
notifications,
deleteSynopsis,
transitionWalletToBat
transitionWalletToBat,
getNewClient
}
6 changes: 4 additions & 2 deletions app/browser/reducers/ledgerReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,10 @@ const ledgerReducer = (state, action, immutableAction) => {
case appConstants.APP_ON_LEDGER_WALLET_CREATE:
{
ledgerApi.boot()
state = migrationState.setConversionTimestamp(state, new Date().getTime())
state = migrationState.setTransitionStatus(state, false)
if (ledgerApi.getNewClient() === null) {
state = migrationState.setConversionTimestamp(state, new Date().getTime())
state = migrationState.setTransitionStatus(state, false)
}
break
}
case appConstants.APP_ON_BOOT_STATE_FILE:
Expand Down
7 changes: 4 additions & 3 deletions test/unit/app/browser/reducers/ledgerReducerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ describe('ledgerReducer unit tests', function () {
onCallback: dummyModifyState,
onTimeUntilReconcile: dummyModifyState,
run: () => {},
onNetworkConnected: dummyModifyState
onNetworkConnected: dummyModifyState,
getNewClient: () => {}
}
fakeLedgerState = {
resetSynopsis: dummyModifyState,
Expand Down Expand Up @@ -257,8 +258,8 @@ describe('ledgerReducer unit tests', function () {
it('calls ledgerApi.boot', function () {
assert(bootSpy.calledOnce)
})
it('returns a modified state', function () {
assert.notDeepEqual(returnedState, appState)
it('returns a non-modified state, if no transition in progress', function () {
assert.deepEqual(returnedState, appState)
})
})

Expand Down

0 comments on commit 37b6568

Please sign in to comment.