From 3b7642e1ec6a0ef7906d27dbf2d122d45a5e2067 Mon Sep 17 00:00:00 2001 From: KhalilBellakrid Date: Wed, 20 Jun 2018 18:30:25 +0200 Subject: [PATCH] Fix hard reset which is async now, update ledger-core to 2.0.0-rc.2 --- package.json | 2 +- src/commands/libcoreHardReset.js | 10 +++++----- src/helpers/hardReset.js | 3 ++- static/i18n/en/errors.yml | 1 + 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 8d6c79ed..62af24ce 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "@ledgerhq/hw-app-xrp": "^4.13.0", "@ledgerhq/hw-transport": "^4.13.0", "@ledgerhq/hw-transport-node-hid": "^4.13.0", - "@ledgerhq/ledger-core": "2.0.0-rc.1", + "@ledgerhq/ledger-core": "2.0.0-rc.2", "@ledgerhq/live-common": "2.31.0", "async": "^2.6.1", "axios": "^0.18.0", diff --git a/src/commands/libcoreHardReset.js b/src/commands/libcoreHardReset.js index a195d520..7e148a1a 100644 --- a/src/commands/libcoreHardReset.js +++ b/src/commands/libcoreHardReset.js @@ -3,15 +3,15 @@ import { createCommand } from 'helpers/ipc' import { Observable } from 'rxjs' import withLibcore from 'helpers/withLibcore' +import createCustomErrorClass from 'helpers/createCustomErrorClass' +const HardResetFail = createCustomErrorClass('HardResetFail') const cmd = createCommand('libcoreHardReset', () => Observable.create(o => { withLibcore(async core => { - try { - core.getPoolInstance().eraseDataSince(new Date(0)) - o.complete() - } catch (e) { - o.error(e) + const result = await core.getPoolInstance().eraseDataSince(new Date(0)) + if (result != core.ERROR_CODE.FUTURE_WAS_SUCCESSFULL) { + throw new HardResetFail(`Hard reset fail with ${result} (check core.ERROR_CODE)`) } }) }), diff --git a/src/helpers/hardReset.js b/src/helpers/hardReset.js index 24477872..b2fc3514 100644 --- a/src/helpers/hardReset.js +++ b/src/helpers/hardReset.js @@ -7,7 +7,8 @@ import { delay } from 'helpers/promise' export default async function hardReset() { // TODO: wait for the libcoreHardReset to be finished // actually, libcore doesnt goes back to js thread - await Promise.race([libcoreHardReset.send().toPromise(), delay(500)]) + await libcoreHardReset.send() + //await Promise.race([libcoreHardReset.send().toPromise(), delay(500)]) disableDBMiddleware() db.resetAll() await delay(500) diff --git a/static/i18n/en/errors.yml b/static/i18n/en/errors.yml index 108a9402..768cd711 100644 --- a/static/i18n/en/errors.yml +++ b/static/i18n/en/errors.yml @@ -20,3 +20,4 @@ DeviceSocketFail: Device socket failure DeviceSocketNoBulkStatus: Device socket failure (bulk) DeviceSocketNoHandler: Device socket failure (handler {{query}}) LatestMCUInstalledError: The latest MCU is already installed on the Device +HardResetFail: Hard reset failure