Browse Source

Merge pull request #1780 from phaazon/feature/libcore-2.5.0-integration

Use the freshResetAll libcore’s function when resetting the app.
develop
Gaëtan Renaudeau 6 years ago
committed by GitHub
parent
commit
32e1537931
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      package.json
  2. 2
      src/commands/index.js
  3. 7
      src/commands/killInternalProcess.js
  4. 14
      src/commands/libcoreReset.js
  5. 5
      src/components/SettingsPage/CleanButton.js
  6. 5
      src/components/SettingsPage/ResetButton.js
  7. 3
      src/components/base/Modal/ConfirmModal.js
  8. 24
      src/helpers/reset.js
  9. 8
      yarn.lock

2
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.16",
"@ledgerhq/ledger-core": "2.0.0-rc.21",
"@ledgerhq/live-common": "4.16.1",
"animated": "^0.2.2",
"async": "^2.6.1",

2
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<Command<any, any>> = [
killInternalProcess,
libcoreGetFees,
libcoreGetVersion,
libcoreReset,
libcoreScanAccounts,
libcoreScanFromXPUB,
libcoreSignAndBroadcast,

7
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<Input, Result> = createCommand('killInternalProcess', () => {
setTimeout(() => {
@ -12,7 +12,8 @@ const cmd: Command<Input, Result> = 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

14
src/commands/libcoreReset.js

@ -0,0 +1,14 @@
// @flow
import { createCommand, Command } from 'helpers/ipc'
import { from } from 'rxjs'
import withLibcore from 'helpers/withLibcore'
type Input = void
type Result = boolean
const cmd: Command<Input, Result> = createCommand('libcoreReset', () =>
from(withLibcore(core => core.getPoolInstance().freshResetAll())),
)
export default cmd

5
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<Props, State> {
title={t('settings.softResetModal.title')}
subTitle={t('common.areYouSure')}
desc={t('settings.softResetModal.desc')}
/>
>
<SyncSkipUnderPriority priority={999} />
</ConfirmModal>
<ResetFallbackModal isOpened={fallbackOpened} onClose={this.closeFallback} />
</Fragment>

5
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<Props, State> {
<IconTriangleWarning width={23} height={21} />
</IconWrapperCircle>
)}
/>
>
<SyncSkipUnderPriority priority={999} />
</ConfirmModal>
<ResetFallbackModal isOpened={fallbackOpened} onClose={this.closeFallback} />
</Fragment>

3
src/components/base/Modal/ConfirmModal.js

@ -29,6 +29,7 @@ type Props = {
analyticsName: string,
cancellable?: boolean,
centered?: boolean,
children?: *,
}
class ConfirmModal extends PureComponent<Props> {
@ -50,6 +51,7 @@ class ConfirmModal extends PureComponent<Props> {
t,
analyticsName,
centered,
children,
...props
} = this.props
@ -91,6 +93,7 @@ class ConfirmModal extends PureComponent<Props> {
<Box ff="Open Sans" color="smoke" fontSize={4} textAlign="center">
{desc}
</Box>
{children}
</Box>
)}
/>

24
src/helpers/reset.js

@ -1,23 +1,21 @@
// @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 libcoreReset from 'commands/libcoreReset'
async function resetLibcoreDatabase() {
await killInternalProcess.send().toPromise()
const dbpath = path.resolve(resolveUserDataDirectory(), 'sqlite/')
rimraf.sync(dbpath, { glob: false })
if (fs.existsSync(dbpath)) {
throw new DBNotReset()
}
async function resetLibcore() {
// we need to stop everything that is happening right now, like syncs
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()
}
function reload() {
@ -30,7 +28,7 @@ export async function hardReset() {
disableDBMiddleware()
db.resetAll()
await delay(500)
await resetLibcoreDatabase()
await resetLibcore()
reload()
}
@ -38,7 +36,7 @@ export async function softReset({ cleanAccountsCache }: *) {
cleanAccountsCache()
await delay(500)
await db.cleanCache()
await resetLibcoreDatabase()
await resetLibcore()
reload()
}

8
yarn.lock

@ -1733,10 +1733,10 @@
"@ledgerhq/errors" "^4.39.0"
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.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"

Loading…
Cancel
Save