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 f0538bf commit 9c8f3b5
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 16 deletions.
37 changes: 26 additions & 11 deletions app/browser/api/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -1792,7 +1792,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 @@ -1835,7 +1842,7 @@ const callback = (err, result, delayTime) => {
}

if (err) {
console.log('ledger client error(1): ' + JSON.stringify(err, null, 2) + (err.stack ? ('\n' + err.stack) : ''))
console.error('ledger client error(1): ' + JSON.stringify(err, null, 2) + (err.stack ? ('\n' + err.stack) : ''))
if (!client) return

if (typeof delayTime === 'undefined') {
Expand Down Expand Up @@ -1958,6 +1965,7 @@ const initialize = (state, paymentsEnabled) => {

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

Expand Down Expand Up @@ -2160,7 +2168,7 @@ const run = (state, delayTime) => {
})
if (stateData) muonWriter(statePath, stateData)
} catch (ex) {
console.log('ledger client error(2): ' + ex.toString() + (ex.stack ? ('\n' + ex.stack) : ''))
console.error('ledger client error(2): ' + ex.toString() + (ex.stack ? ('\n' + ex.stack) : ''))
}

if (delayTime === 0) {
Expand All @@ -2187,7 +2195,7 @@ const run = (state, delayTime) => {
if (active !== client) return

if (!client) {
return console.log('\n\n*** MTR says this can\'t happen(1)... please tell him that he\'s wrong!\n\n')
return console.error('\n\n*** MTR says this can\'t happen(1)... please tell him that he\'s wrong!\n\n')
}

if (client.sync(callback) === true) {
Expand Down Expand Up @@ -2259,7 +2267,7 @@ const migration = (state) => {
}
})
} catch (err) {
console.log('Error migrating file', err.toString())
console.error(err.toString())
}

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

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

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

Expand All @@ -2338,7 +2350,7 @@ const transitionWalletToBat = () => {
fs.accessSync(pathName(newClientPath), fs.FF_OK)
fs.readFile(pathName(newClientPath), (error, data) => {
if (error) {
console.log(`ledger client: can't read ${newClientPath} to restore newClient`)
console.error(`ledger client: can't read ${newClientPath} to restore newClient`)
return
}
const parsedData = JSON.parse(data)
Expand All @@ -2350,7 +2362,7 @@ const transitionWalletToBat = () => {
})
return
} catch (err) {
console.log(err.toString())
console.error(err.toString())
}
}

Expand All @@ -2370,12 +2382,14 @@ const transitionWalletToBat = () => {
if (!newPaymentId) {
newClient.sync((err, result, delayTime) => {
if (err) {
return console.log('ledger client error(3): ' + JSON.stringify(err, null, 2) + (err.stack ? ('\n' + err.stack) : ''))
return console.error('ledger client error(3): ' + JSON.stringify(err, null, 2) + (err.stack ? ('\n' + err.stack) : ''))
}

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 @@ -2391,7 +2405,7 @@ const transitionWalletToBat = () => {

try {
client.transition(newPaymentId, (err, properties) => {
if (err) {
if (err || !newClient) {
console.error('ledger client transition error: ', err)
} else {
result = newClient.transitioned(properties)
Expand Down Expand Up @@ -2438,5 +2452,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 @@ -227,8 +227,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
4 changes: 4 additions & 0 deletions app/common/state/migrationState.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,15 @@ const migrationState = {
return state.get('firstRunTimestamp') === state.getIn(['migrations', 'batMercuryTimestamp'])
},

// we set this values when we initialize 0.19 state and this will be only true when transition is done
// or when you create wallet on 0.19+ version
hasUpgradedWallet: (state) => {
state = validateState(state)
return state.getIn(['migrations', 'batMercuryTimestamp']) !== state.getIn(['migrations', 'btc2BatTimestamp'])
},

// we set this values when we initialize 0.19 state and this will be only true when transition is done
// or when you create wallet on 0.19+ version
hasBeenNotified: (state) => {
state = validateState(state)
return state.getIn(['migrations', 'batMercuryTimestamp']) !== state.getIn(['migrations', 'btc2BatNotifiedTimestamp'])
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 @@ -270,8 +271,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 9c8f3b5

Please sign in to comment.