From 5dbe566c19a7d67475f180ccc2ce16e197ee1818 Mon Sep 17 00:00:00 2001 From: NejcZdovc Date: Mon, 26 Mar 2018 17:00:26 +0200 Subject: [PATCH] Fixes recover flow when seed is corrupted Resolves #13583 Auditors: Test Plan: --- app/browser/api/ledger.js | 16 +++++++++++++--- app/common/state/ledgerState.js | 10 ++++++++++ test/unit/app/common/state/ledgerStateTest.js | 13 +++++++++++++ 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/app/browser/api/ledger.js b/app/browser/api/ledger.js index 31b03b03d33..91ed6302831 100644 --- a/app/browser/api/ledger.js +++ b/app/browser/api/ledger.js @@ -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) { @@ -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) diff --git a/app/common/state/ledgerState.js b/app/common/state/ledgerState.js index 92c3b1786f0..567e7fc7a7b 100644 --- a/app/common/state/ledgerState.js +++ b/app/common/state/ledgerState.js @@ -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]) } } diff --git a/test/unit/app/common/state/ledgerStateTest.js b/test/unit/app/common/state/ledgerStateTest.js index eacec64d78a..b899d670e7e 100644 --- a/test/unit/app/common/state/ledgerStateTest.js +++ b/test/unit/app/common/state/ledgerStateTest.js @@ -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') + }) + }) })