From 3b7642e1ec6a0ef7906d27dbf2d122d45a5e2067 Mon Sep 17 00:00:00 2001 From: KhalilBellakrid Date: Wed, 20 Jun 2018 18:30:25 +0200 Subject: [PATCH 1/4] 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 From e4396b7c62e5def28844be945abb744c6e1c8d24 Mon Sep 17 00:00:00 2001 From: meriadec Date: Wed, 20 Jun 2018 18:45:45 +0200 Subject: [PATCH 2/4] update ledger-core to 2.0.0-rc.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 62af24ce..cd937cb6 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.2", + "@ledgerhq/ledger-core": "2.0.0-rc.3", "@ledgerhq/live-common": "2.31.0", "async": "^2.6.1", "axios": "^0.18.0", From 8c6577658c6aaa3068c3b684cdbb91e9f14d5930 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Renaudeau?= Date: Wed, 20 Jun 2018 19:42:28 +0200 Subject: [PATCH 3/4] Fix lint & actually return a correct observable from promise --- src/commands/libcoreHardReset.js | 11 ++++++----- src/helpers/hardReset.js | 4 +++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/commands/libcoreHardReset.js b/src/commands/libcoreHardReset.js index 7e148a1a..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 => { const result = await core.getPoolInstance().eraseDataSince(new Date(0)) - if (result != core.ERROR_CODE.FUTURE_WAS_SUCCESSFULL) { + 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 b2fc3514..2ae2589e 100644 --- a/src/helpers/hardReset.js +++ b/src/helpers/hardReset.js @@ -8,7 +8,9 @@ export default async function hardReset() { // TODO: wait for the libcoreHardReset to be finished // actually, libcore doesnt goes back to js thread await libcoreHardReset.send() - //await Promise.race([libcoreHardReset.send().toPromise(), delay(500)]) + + // await Promise.race([libcoreHardReset.send().toPromise(), delay(500)]) + disableDBMiddleware() db.resetAll() await delay(500) From 3055ced9f0094faed6bb7b8d7386f84ff5dfa6e8 Mon Sep 17 00:00:00 2001 From: meriadec Date: Thu, 21 Jun 2018 09:16:13 +0200 Subject: [PATCH 4/4] Remove unused comments --- src/helpers/hardReset.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/helpers/hardReset.js b/src/helpers/hardReset.js index 2ae2589e..aacbdd87 100644 --- a/src/helpers/hardReset.js +++ b/src/helpers/hardReset.js @@ -5,12 +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 libcoreHardReset.send() - - // await Promise.race([libcoreHardReset.send().toPromise(), delay(500)]) - disableDBMiddleware() db.resetAll() await delay(500)