diff --git a/package.json b/package.json index f044185c..50f76b46 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.3", "@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..e8cad9b4 100644 --- a/src/commands/libcoreHardReset.js +++ b/src/commands/libcoreHardReset.js @@ -1,20 +1,21 @@ // @flow import { createCommand } from 'helpers/ipc' -import { Observable } from 'rxjs' +import { fromPromise } from 'rxjs/observable/fromPromise' import withLibcore from 'helpers/withLibcore' +import createCustomErrorClass from 'helpers/createCustomErrorClass' + +const HardResetFail = createCustomErrorClass('HardResetFail') const cmd = createCommand('libcoreHardReset', () => - Observable.create(o => { + fromPromise( 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)`) } - }) - }), + }), + ), ) export default cmd diff --git a/src/helpers/hardReset.js b/src/helpers/hardReset.js index 24477872..aacbdd87 100644 --- a/src/helpers/hardReset.js +++ b/src/helpers/hardReset.js @@ -5,9 +5,7 @@ import db from 'helpers/db' 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() 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