diff --git a/src/commands/index.js b/src/commands/index.js index 91d0df7b..463c7248 100644 --- a/src/commands/index.js +++ b/src/commands/index.js @@ -14,6 +14,7 @@ import installMcu from 'commands/installMcu' import installOsuFirmware from 'commands/installOsuFirmware' import isDashboardOpen from 'commands/isDashboardOpen' 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' @@ -38,6 +39,7 @@ const all: Array> = [ installOsuFirmware, isDashboardOpen, libcoreGetVersion, + libcoreHardReset, libcoreScanAccounts, libcoreSignAndBroadcast, libcoreSyncAccount, diff --git a/src/commands/libcoreHardReset.js b/src/commands/libcoreHardReset.js new file mode 100644 index 00000000..7da0f3c6 --- /dev/null +++ b/src/commands/libcoreHardReset.js @@ -0,0 +1,20 @@ +// @flow + +import { createCommand } from 'helpers/ipc' +import { Observable } from 'rxjs' +import withLibcore from 'helpers/withLibcore' + +const cmd = createCommand('libcoreHardReset', () => + Observable.create(o => { + withLibcore(async (core, njsWalletPool) => { + try { + njsWalletPool.eraseDataSince(new Date(0)) + o.complete() + } catch (e) { + o.error(e) + } + }) + }), +) + +export default cmd diff --git a/src/components/SettingsPage/sections/Profile.js b/src/components/SettingsPage/sections/Profile.js index 27b859b3..70f59d2a 100644 --- a/src/components/SettingsPage/sections/Profile.js +++ b/src/components/SettingsPage/sections/Profile.js @@ -5,6 +5,7 @@ import { connect } from 'react-redux' import { remote } from 'electron' import bcrypt from 'bcryptjs' +import libcoreHardReset from 'commands/libcoreHardReset' import { cleanAccountsCache } from 'actions/accounts' import { unlock } from 'reducers/application' // FIXME should be in actions import db, { setEncryptionKey } from 'helpers/db' @@ -47,6 +48,7 @@ type State = { isSoftResetModalOpened: boolean, isPasswordModalOpened: boolean, isDisablePasswordModalOpened: boolean, + isHardResetting: boolean, } class TabProfile extends PureComponent { @@ -55,6 +57,7 @@ class TabProfile extends PureComponent { isSoftResetModalOpened: false, isPasswordModalOpened: false, isDisablePasswordModalOpened: false, + isHardResetting: false, } setPassword = password => { @@ -89,9 +92,17 @@ class TabProfile extends PureComponent { } handleHardReset = async () => { - db.resetAll() - await delay(500) - remote.getCurrentWindow().webContents.reload() + this.setState({ isHardResetting: true }) + try { + // TODO: wait for the libcoreHardReset to be finished + // actually, libcore doesnt goes back to js thread + await Promise.race([libcoreHardReset.send().toPromise(), delay(500)]) + db.resetAll() + await delay(500) + remote.getCurrentWindow().webContents.reload() + } catch (err) { + this.setState({ isHardResetting: false }) + } } handleChangePasswordCheck = isChecked => { @@ -125,6 +136,7 @@ class TabProfile extends PureComponent { isHardResetModalOpened, isPasswordModalOpened, isDisablePasswordModalOpened, + isHardResetting, } = this.state const isPasswordEnabled = settings.password.isEnabled === true return ( @@ -200,6 +212,7 @@ class TabProfile extends PureComponent {