Browse Source

hard reset and 'clear cache' will drop the libcore db that we can fully restore

master
Gaëtan Renaudeau 6 years ago
parent
commit
2efc40a09c
No known key found for this signature in database GPG Key ID: 7B66B85F042E5451
  1. 2
      src/commands/index.js
  2. 19
      src/commands/libcoreHardReset.js
  3. 2
      src/components/IsUnlocked.js
  4. 2
      src/components/RenderError.js
  5. 20
      src/components/SettingsPage/CleanButton.js
  6. 2
      src/components/SettingsPage/ResetButton.js
  7. 13
      src/helpers/hardReset.js
  8. 35
      src/helpers/reset.js

2
src/commands/index.js

@ -17,7 +17,6 @@ import installOsuFirmware from 'commands/installOsuFirmware'
import isDashboardOpen from 'commands/isDashboardOpen'
import libcoreGetFees from 'commands/libcoreGetFees'
import libcoreGetVersion from 'commands/libcoreGetVersion'
import libcoreHardReset from 'commands/libcoreHardReset'
import libcoreScanAccounts from 'commands/libcoreScanAccounts'
import libcoreSignAndBroadcast from 'commands/libcoreSignAndBroadcast'
import libcoreSyncAccount from 'commands/libcoreSyncAccount'
@ -49,7 +48,6 @@ const all: Array<Command<any, any>> = [
isDashboardOpen,
libcoreGetFees,
libcoreGetVersion,
libcoreHardReset,
libcoreScanAccounts,
libcoreSignAndBroadcast,
libcoreSyncAccount,

19
src/commands/libcoreHardReset.js

@ -1,19 +0,0 @@
// @flow
import { createCommand } from 'helpers/ipc'
import { fromPromise } from 'rxjs/observable/fromPromise'
import withLibcore from 'helpers/withLibcore'
import { HardResetFail } from 'config/errors'
const cmd = createCommand('libcoreHardReset', () =>
fromPromise(
withLibcore(async core => {
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

2
src/components/IsUnlocked.js

@ -12,7 +12,7 @@ import { i } from 'helpers/staticPath'
import IconTriangleWarning from 'icons/TriangleWarning'
import db from 'helpers/db'
import hardReset from 'helpers/hardReset'
import { hardReset } from 'helpers/reset'
import { fetchAccounts } from 'actions/accounts'
import { isLocked, unlock } from 'reducers/application'

2
src/components/RenderError.js

@ -8,7 +8,7 @@ import { translate } from 'react-i18next'
import { urls } from 'config/urls'
import { i } from 'helpers/staticPath'
import hardReset from 'helpers/hardReset'
import { hardReset } from 'helpers/reset'
import type { T } from 'types/common'

20
src/components/SettingsPage/CleanButton.js

@ -4,12 +4,10 @@ import React, { Fragment, PureComponent } from 'react'
import { connect } from 'react-redux'
import { translate } from 'react-i18next'
import type { T } from 'types/common'
import { remote } from 'electron'
import { cleanAccountsCache } from 'actions/accounts'
import db from 'helpers/db'
import { delay } from 'helpers/promise'
import Button from 'components/base/Button'
import { ConfirmModal } from 'components/base/Modal'
import { softReset } from 'helpers/reset'
const mapDispatchToProps = {
cleanAccountsCache,
@ -22,11 +20,13 @@ type Props = {
type State = {
opened: boolean,
isLoading: boolean,
}
class CleanButton extends PureComponent<Props, State> {
state = {
opened: false,
isLoading: false,
}
open = () => this.setState({ opened: true })
@ -34,15 +34,18 @@ class CleanButton extends PureComponent<Props, State> {
close = () => this.setState({ opened: false })
action = async () => {
this.props.cleanAccountsCache()
await delay(500)
db.cleanCache()
remote.getCurrentWindow().webContents.reload()
if (this.state.isLoading) return
try {
this.setState({ isLoading: true })
await softReset({ cleanAccountsCache: this.props.cleanAccountsCache })
} finally {
this.setState({ isLoading: false })
}
}
render() {
const { t } = this.props
const { opened } = this.state
const { opened, isLoading } = this.state
return (
<Fragment>
<Button small primary onClick={this.open} event="ClearCacheIntent">
@ -55,6 +58,7 @@ class CleanButton extends PureComponent<Props, State> {
onClose={this.close}
onReject={this.close}
onConfirm={this.action}
isLoading={isLoading}
title={t('app:settings.softResetModal.title')}
subTitle={t('app:common.areYouSure')}
desc={t('app:settings.softResetModal.desc')}

2
src/components/SettingsPage/ResetButton.js

@ -5,7 +5,7 @@ import styled from 'styled-components'
import { remote } from 'electron'
import { translate } from 'react-i18next'
import type { T } from 'types/common'
import hardReset from 'helpers/hardReset'
import { hardReset } from 'helpers/reset'
import Box from 'components/base/Box'
import Button from 'components/base/Button'
import { ConfirmModal } from 'components/base/Modal'

13
src/helpers/hardReset.js

@ -1,13 +0,0 @@
import libcoreHardReset from 'commands/libcoreHardReset'
import { disable as disableDBMiddleware } from 'middlewares/db'
import db from 'helpers/db'
import { delay } from 'helpers/promise'
export default async function hardReset() {
await libcoreHardReset.send()
disableDBMiddleware()
db.resetAll()
await delay(500)
window.location.href = ''
}

35
src/helpers/reset.js

@ -0,0 +1,35 @@
// @flow
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'
function resetLibcoreDatabase() {
const dbpath = path.resolve(resolveUserDataDirectory(), 'sqlite/')
rimraf.sync(dbpath, { glob: false })
}
function reload() {
require('electron')
.remote.getCurrentWindow()
.webContents.reload()
}
export async function hardReset() {
resetLibcoreDatabase()
disableDBMiddleware()
db.resetAll()
await delay(500)
reload()
}
export async function softReset({ cleanAccountsCache }: *) {
resetLibcoreDatabase()
cleanAccountsCache()
await delay(500)
db.cleanCache()
reload()
}
Loading…
Cancel
Save