From 670ea1b1d92eb7bc289de47d5a23be5cc37431e2 Mon Sep 17 00:00:00 2001 From: Dimitri Sabadie Date: Fri, 1 Feb 2019 15:17:29 +0100 Subject: [PATCH 1/8] =?UTF-8?q?Use=20the=20freshResetAll=20libcore?= =?UTF-8?q?=E2=80=99s=20function=20when=20resetting=20the=20app.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also, bump libcore’s version to 2.5.0 (release-candidate). --- package.json | 2 +- src/helpers/reset.js | 17 +++++------------ yarn.lock | 8 ++++---- 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index 5a256f90..cd1acc86 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "@ledgerhq/hw-app-xrp": "^4.35.0", "@ledgerhq/hw-transport": "^4.35.0", "@ledgerhq/hw-transport-node-hid": "^4.35.0", - "@ledgerhq/ledger-core": "2.0.0-rc.16", + "@ledgerhq/ledger-core": "2.0.0-rc.19", "@ledgerhq/live-common": "4.16.1", "animated": "^0.2.2", "async": "^2.6.1", diff --git a/src/helpers/reset.js b/src/helpers/reset.js index 28439120..a8103a6b 100644 --- a/src/helpers/reset.js +++ b/src/helpers/reset.js @@ -1,23 +1,16 @@ // @flow -import fs from 'fs' import { shell, remote } from 'electron' -import path from 'path' -import rimraf from 'rimraf' import resolveUserDataDirectory from 'helpers/resolveUserDataDirectory' import { disable as disableDBMiddleware } from 'middlewares/db' import db from 'helpers/db' import { delay } from 'helpers/promise' import killInternalProcess from 'commands/killInternalProcess' -import { DBNotReset } from '@ledgerhq/errors' +import withLibcore from 'helpers/withLibcore' -async function resetLibcoreDatabase() { +async function resetLibcore() { await killInternalProcess.send().toPromise() - const dbpath = path.resolve(resolveUserDataDirectory(), 'sqlite/') - rimraf.sync(dbpath, { glob: false }) - if (fs.existsSync(dbpath)) { - throw new DBNotReset() - } + withLibcore(core => core.freshResetAll()) } function reload() { @@ -30,7 +23,7 @@ export async function hardReset() { disableDBMiddleware() db.resetAll() await delay(500) - await resetLibcoreDatabase() + await resetLibcore() reload() } @@ -38,7 +31,7 @@ export async function softReset({ cleanAccountsCache }: *) { cleanAccountsCache() await delay(500) await db.cleanCache() - await resetLibcoreDatabase() + await resetLibcore() reload() } diff --git a/yarn.lock b/yarn.lock index 3ed0695a..8040cfb1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1722,10 +1722,10 @@ dependencies: events "^3.0.0" -"@ledgerhq/ledger-core@2.0.0-rc.16": - version "2.0.0-rc.16" - resolved "https://registry.yarnpkg.com/@ledgerhq/ledger-core/-/ledger-core-2.0.0-rc.16.tgz#51f141c0143edb020e38855bf2e2619e3446e74f" - integrity sha512-gmbeXRBg4NSqzH6+EajYTzaQlwN5ugaN1nH0SI6BvRqMfcorxNRE8byfh3F2u+7TNchBW72vOZnKPDShaR9/pQ== +"@ledgerhq/ledger-core@2.0.0-rc.19": + version "2.0.0-rc.19" + resolved "https://registry.yarnpkg.com/@ledgerhq/ledger-core/-/ledger-core-2.0.0-rc.19.tgz#f8cd0bdc4e8f067bd95aced895d3e1190bb63f06" + integrity sha512-pkSVOFNGYYiujJFCJ7JkQrwK5YMVx6MoyXBD4jA+SKthlZ8zo3X3jfhRJdZ1rUiI87GP/ncdh0Kc+epuWTqlDQ== dependencies: bindings "^1.3.0" nan "^2.6.2" From 0484c3aaf959330c2c8a76a3e158435a8f1a83a5 Mon Sep 17 00:00:00 2001 From: Dimitri Sabadie Date: Fri, 15 Feb 2019 15:41:57 +0100 Subject: [PATCH 2/8] Fix IPC code for resetting libcore. --- src/commands/index.js | 2 ++ src/commands/libcoreReset.js | 15 +++++++++++++++ src/helpers/reset.js | 4 ++-- 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 src/commands/libcoreReset.js diff --git a/src/commands/index.js b/src/commands/index.js index 893c6d53..f158dba1 100644 --- a/src/commands/index.js +++ b/src/commands/index.js @@ -16,6 +16,7 @@ import installApp from 'commands/installApp' import killInternalProcess from 'commands/killInternalProcess' import libcoreGetFees from 'commands/libcoreGetFees' import libcoreGetVersion from 'commands/libcoreGetVersion' +import libcoreReset from 'commands/libcoreReset' import libcoreScanAccounts from 'commands/libcoreScanAccounts' import libcoreScanFromXPUB from 'commands/libcoreScanFromXPUB' import libcoreSignAndBroadcast from 'commands/libcoreSignAndBroadcast' @@ -44,6 +45,7 @@ const all: Array> = [ killInternalProcess, libcoreGetFees, libcoreGetVersion, + libcoreReset, libcoreScanAccounts, libcoreScanFromXPUB, libcoreSignAndBroadcast, diff --git a/src/commands/libcoreReset.js b/src/commands/libcoreReset.js new file mode 100644 index 00000000..6ca30cd0 --- /dev/null +++ b/src/commands/libcoreReset.js @@ -0,0 +1,15 @@ +// @flow + +import { createCommand, Command } from 'helpers/ipc' +import { of } from 'rxjs' +import withLibcore from 'helpers/withLibcore' + +type Input = void +type Result = boolean + +const cmd: Command = createCommand('libcoreReset', () => { + withLibcore(core => core.getPoolInstance().freshResetAll()) + return of(true) +}) + +export default cmd diff --git a/src/helpers/reset.js b/src/helpers/reset.js index a8103a6b..f198a60d 100644 --- a/src/helpers/reset.js +++ b/src/helpers/reset.js @@ -6,11 +6,11 @@ import { disable as disableDBMiddleware } from 'middlewares/db' import db from 'helpers/db' import { delay } from 'helpers/promise' import killInternalProcess from 'commands/killInternalProcess' -import withLibcore from 'helpers/withLibcore' +import libcoreReset from 'commands/libcoreReset' async function resetLibcore() { + await libcoreReset.send().toPromise() await killInternalProcess.send().toPromise() - withLibcore(core => core.freshResetAll()) } function reload() { From 404f036e1598e24d29ccef58ce292abad2f60e5c Mon Sep 17 00:00:00 2001 From: Dimitri Sabadie Date: Fri, 15 Feb 2019 16:42:41 +0100 Subject: [PATCH 3/8] Use a safer way to call the reset code in the libcoreReset cmd. --- src/commands/libcoreReset.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/commands/libcoreReset.js b/src/commands/libcoreReset.js index 6ca30cd0..30d56139 100644 --- a/src/commands/libcoreReset.js +++ b/src/commands/libcoreReset.js @@ -1,15 +1,15 @@ // @flow import { createCommand, Command } from 'helpers/ipc' -import { of } from 'rxjs' +import { from } from 'rxjs' import withLibcore from 'helpers/withLibcore' type Input = void type Result = boolean -const cmd: Command = createCommand('libcoreReset', () => { - withLibcore(core => core.getPoolInstance().freshResetAll()) - return of(true) -}) +const cmd: Command = createCommand( + 'libcoreReset', + () => from(withLibcore(core => core.getPoolInstance().freshResetAll())) +) export default cmd From 51e9dfb320ea9564b2e5744b4e21fb9817cfbc2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Renaudeau?= Date: Tue, 19 Feb 2019 14:02:31 +0100 Subject: [PATCH 4/8] stop the sync when opening the Clean/Reset modals --- src/components/SettingsPage/CleanButton.js | 5 ++++- src/components/SettingsPage/ResetButton.js | 5 ++++- src/components/base/Modal/ConfirmModal.js | 2 ++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/components/SettingsPage/CleanButton.js b/src/components/SettingsPage/CleanButton.js index 8a3081ea..f1954aa4 100644 --- a/src/components/SettingsPage/CleanButton.js +++ b/src/components/SettingsPage/CleanButton.js @@ -6,6 +6,7 @@ import { translate } from 'react-i18next' import logger from 'logger' import type { T } from 'types/common' import { cleanAccountsCache } from 'actions/accounts' +import SyncSkipUnderPriority from 'components/SyncSkipUnderPriority' import Button from 'components/base/Button' import ConfirmModal from 'components/base/Modal/ConfirmModal' import { softReset } from 'helpers/reset' @@ -69,7 +70,9 @@ class CleanButton extends PureComponent { title={t('settings.softResetModal.title')} subTitle={t('common.areYouSure')} desc={t('settings.softResetModal.desc')} - /> + > + + diff --git a/src/components/SettingsPage/ResetButton.js b/src/components/SettingsPage/ResetButton.js index 2708c75e..daa282b2 100644 --- a/src/components/SettingsPage/ResetButton.js +++ b/src/components/SettingsPage/ResetButton.js @@ -7,6 +7,7 @@ import { translate } from 'react-i18next' import logger from 'logger' import type { T } from 'types/common' import { hardReset } from 'helpers/reset' +import SyncSkipUnderPriority from 'components/SyncSkipUnderPriority' import Box from 'components/base/Box' import Button from 'components/base/Button' import ConfirmModal from 'components/base/Modal/ConfirmModal' @@ -73,7 +74,9 @@ class ResetButton extends PureComponent { )} - /> + > + + diff --git a/src/components/base/Modal/ConfirmModal.js b/src/components/base/Modal/ConfirmModal.js index 416eb5a7..06066bc9 100644 --- a/src/components/base/Modal/ConfirmModal.js +++ b/src/components/base/Modal/ConfirmModal.js @@ -50,6 +50,7 @@ class ConfirmModal extends PureComponent { t, analyticsName, centered, + children, ...props } = this.props @@ -91,6 +92,7 @@ class ConfirmModal extends PureComponent { {desc} + {children} )} /> From 986032e7c83f312619c3b89ac3a87c3b5a0a67b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Renaudeau?= Date: Tue, 19 Feb 2019 14:02:50 +0100 Subject: [PATCH 5/8] kill before clearing --- src/commands/libcoreReset.js | 5 ++--- src/helpers/reset.js | 4 +++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/commands/libcoreReset.js b/src/commands/libcoreReset.js index 30d56139..9e3d9f3e 100644 --- a/src/commands/libcoreReset.js +++ b/src/commands/libcoreReset.js @@ -7,9 +7,8 @@ import withLibcore from 'helpers/withLibcore' type Input = void type Result = boolean -const cmd: Command = createCommand( - 'libcoreReset', - () => from(withLibcore(core => core.getPoolInstance().freshResetAll())) +const cmd: Command = createCommand('libcoreReset', () => + from(withLibcore(core => core.getPoolInstance().freshResetAll())), ) export default cmd diff --git a/src/helpers/reset.js b/src/helpers/reset.js index f198a60d..d0ead9ca 100644 --- a/src/helpers/reset.js +++ b/src/helpers/reset.js @@ -9,8 +9,10 @@ import killInternalProcess from 'commands/killInternalProcess' import libcoreReset from 'commands/libcoreReset' async function resetLibcore() { - await libcoreReset.send().toPromise() + // we need to stop everything that is happening right now, like syncs await killInternalProcess.send().toPromise() + // we can now ask libcore to reset itself + await libcoreReset.send().toPromise() } function reload() { From 1c4b0fc073d6a82c16cf2f074d44700663500d8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Renaudeau?= Date: Tue, 19 Feb 2019 14:36:05 +0100 Subject: [PATCH 6/8] bugfixes killInternalProcess --- src/commands/killInternalProcess.js | 7 ++++--- src/helpers/reset.js | 5 ++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/commands/killInternalProcess.js b/src/commands/killInternalProcess.js index 428fecd4..33ad0102 100644 --- a/src/commands/killInternalProcess.js +++ b/src/commands/killInternalProcess.js @@ -1,10 +1,10 @@ // @flow import { createCommand, Command } from 'helpers/ipc' -import { of } from 'rxjs' +import { never } from 'rxjs' type Input = void -type Result = boolean +type Result = void const cmd: Command = createCommand('killInternalProcess', () => { setTimeout(() => { @@ -12,7 +12,8 @@ const cmd: Command = createCommand('killInternalProcess', () => { // special exit code for better identification process.exit(42) }) - return of(true) + // The command shouldn't finish now because process.exit will make it end! + return never() }) export default cmd diff --git a/src/helpers/reset.js b/src/helpers/reset.js index d0ead9ca..7a8e51ac 100644 --- a/src/helpers/reset.js +++ b/src/helpers/reset.js @@ -10,7 +10,10 @@ import libcoreReset from 'commands/libcoreReset' async function resetLibcore() { // we need to stop everything that is happening right now, like syncs - await killInternalProcess.send().toPromise() + await killInternalProcess + .send() + .toPromise() + .catch(() => {}) // this is a normal error due to the crash of the process, we ignore it // we can now ask libcore to reset itself await libcoreReset.send().toPromise() } From ad2fe2d403d2b0d070f9160d79f24ca5684a5a25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Renaudeau?= Date: Tue, 19 Feb 2019 14:39:08 +0100 Subject: [PATCH 7/8] fixes flow --- src/components/base/Modal/ConfirmModal.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/base/Modal/ConfirmModal.js b/src/components/base/Modal/ConfirmModal.js index 06066bc9..a2ff1e83 100644 --- a/src/components/base/Modal/ConfirmModal.js +++ b/src/components/base/Modal/ConfirmModal.js @@ -29,6 +29,7 @@ type Props = { analyticsName: string, cancellable?: boolean, centered?: boolean, + children?: *, } class ConfirmModal extends PureComponent { From 8c10c73167f28c05fa97c34eb8942c455a8303a8 Mon Sep 17 00:00:00 2001 From: Dimitri Sabadie Date: Tue, 19 Feb 2019 15:35:22 +0100 Subject: [PATCH 8/8] Bump @ledgerhq/ledger-core version up to 2.0.0-rc.21. --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index a63150a4..7df684a5 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "@ledgerhq/hw-app-xrp": "^4.39.0", "@ledgerhq/hw-transport": "^4.39.0", "@ledgerhq/hw-transport-node-hid": "^4.40.0", - "@ledgerhq/ledger-core": "2.0.0-rc.19", + "@ledgerhq/ledger-core": "2.0.0-rc.21", "@ledgerhq/live-common": "4.16.1", "animated": "^0.2.2", "async": "^2.6.1", diff --git a/yarn.lock b/yarn.lock index 0a8ba716..a09487a3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1733,10 +1733,10 @@ "@ledgerhq/errors" "^4.39.0" events "^3.0.0" -"@ledgerhq/ledger-core@2.0.0-rc.19": - version "2.0.0-rc.19" - resolved "https://registry.yarnpkg.com/@ledgerhq/ledger-core/-/ledger-core-2.0.0-rc.19.tgz#f8cd0bdc4e8f067bd95aced895d3e1190bb63f06" - integrity sha512-pkSVOFNGYYiujJFCJ7JkQrwK5YMVx6MoyXBD4jA+SKthlZ8zo3X3jfhRJdZ1rUiI87GP/ncdh0Kc+epuWTqlDQ== +"@ledgerhq/ledger-core@2.0.0-rc.21": + version "2.0.0-rc.21" + resolved "https://registry.yarnpkg.com/@ledgerhq/ledger-core/-/ledger-core-2.0.0-rc.21.tgz#f9e48cf162150ef3d5089ac19e9effcef4626697" + integrity sha512-DqBY1D95wz3a56k8bx7e8YhTsVake/4ZBxH5RgUnXl4OQYRQNKyrtqt94yKvYi+JkRqtU2z60XgB5mo58jaq+w== dependencies: bindings "^1.3.0" nan "^2.6.2"