From 2efc40a09cad7d8cc11d10414027a479a52bf301 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Renaudeau?= Date: Thu, 30 Aug 2018 16:25:53 +0200 Subject: [PATCH] hard reset and 'clear cache' will drop the libcore db that we can fully restore --- src/commands/index.js | 2 -- src/commands/libcoreHardReset.js | 19 ------------ src/components/IsUnlocked.js | 2 +- src/components/RenderError.js | 2 +- src/components/SettingsPage/CleanButton.js | 20 ++++++++----- src/components/SettingsPage/ResetButton.js | 2 +- src/helpers/hardReset.js | 13 -------- src/helpers/reset.js | 35 ++++++++++++++++++++++ 8 files changed, 50 insertions(+), 45 deletions(-) delete mode 100644 src/commands/libcoreHardReset.js delete mode 100644 src/helpers/hardReset.js create mode 100644 src/helpers/reset.js diff --git a/src/commands/index.js b/src/commands/index.js index 758e1416..8b1ff369 100644 --- a/src/commands/index.js +++ b/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> = [ isDashboardOpen, libcoreGetFees, libcoreGetVersion, - libcoreHardReset, libcoreScanAccounts, libcoreSignAndBroadcast, libcoreSyncAccount, diff --git a/src/commands/libcoreHardReset.js b/src/commands/libcoreHardReset.js deleted file mode 100644 index fa06e17d..00000000 --- a/src/commands/libcoreHardReset.js +++ /dev/null @@ -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 diff --git a/src/components/IsUnlocked.js b/src/components/IsUnlocked.js index 381edfff..f9dc5fc8 100644 --- a/src/components/IsUnlocked.js +++ b/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' diff --git a/src/components/RenderError.js b/src/components/RenderError.js index ac591aa3..d22a2151 100644 --- a/src/components/RenderError.js +++ b/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' diff --git a/src/components/SettingsPage/CleanButton.js b/src/components/SettingsPage/CleanButton.js index a5cd8c7f..7c3ff1d4 100644 --- a/src/components/SettingsPage/CleanButton.js +++ b/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 { state = { opened: false, + isLoading: false, } open = () => this.setState({ opened: true }) @@ -34,15 +34,18 @@ class CleanButton extends PureComponent { 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 (