Skip to content

Commit

Permalink
Fixes recover flow when seed is corrupted
Browse files Browse the repository at this point in the history
Resolves brave#13583

Auditors:

Test Plan:
  • Loading branch information
NejcZdovc committed Mar 26, 2018
1 parent 68ecb38 commit 5dbe566
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
16 changes: 13 additions & 3 deletions app/browser/api/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,12 @@ const onWalletRecovery = (state, error, result) => {
state = ledgerState.setInfoProp(state, 'walletQR', Immutable.Map())
state = ledgerState.setInfoProp(state, 'addresses', Immutable.Map())

const status = ledgerState.getAboutProp(state, 'status')

if (status === ledgerStatuses.CORRUPTED_SEED) {
state = ledgerState.setAboutProp(state, 'status', '')
}

callback(error, result)

if (balanceTimeoutId) {
Expand Down Expand Up @@ -1647,9 +1653,13 @@ const getStateInfo = (state, parsedData) => {
state = ledgerState.setAboutProp(state, 'status', ledgerStatuses.IN_PROGRESS)
}

let passphrase = ledgerClient.prototype.getWalletPassphrase(parsedData)
if (passphrase) {
newInfo.passphrase = passphrase.join(' ')
try {
let passphrase = ledgerClient.prototype.getWalletPassphrase(parsedData)
if (passphrase) {
newInfo.passphrase = passphrase.join(' ')
}
} catch (e) {
console.error(e)
}

state = ledgerState.mergeInfoProp(state, newInfo)
Expand Down
10 changes: 10 additions & 0 deletions app/common/state/ledgerState.js
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,16 @@ const ledgerState = {
}

return state.setIn(['ledger', 'about', prop], value)
},

getAboutProp: (state, prop) => {
state = validateState(state)

if (prop == null) {
return null
}

return state.getIn(['ledger', 'about', prop])
}
}

Expand Down
13 changes: 13 additions & 0 deletions test/unit/app/common/state/ledgerStateTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -609,4 +609,17 @@ describe('ledgerState unit test', function () {
assert.deepEqual(result.toJS(), expectedState.toJS())
})
})

describe('getAboutProp', function () {
it('null case', function () {
const result = ledgerState.getAboutProp(defaultState)
assert.equal(result, null)
})

it('prop is set', function () {
const state = defaultState.setIn(['ledger', 'about', 'status'], 'corrupted')
const result = ledgerState.getAboutProp(state, 'status')
assert.equal(result, 'corrupted')
})
})
})

0 comments on commit 5dbe566

Please sign in to comment.