Browse Source

Implement hard reset on libcore side

master
meriadec 7 years ago
parent
commit
d1cf946ef0
No known key found for this signature in database GPG Key ID: 1D2FC2305E2CB399
  1. 2
      src/commands/index.js
  2. 20
      src/commands/libcoreHardReset.js
  3. 19
      src/components/SettingsPage/sections/Profile.js

2
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<Command<any, any>> = [
installOsuFirmware,
isDashboardOpen,
libcoreGetVersion,
libcoreHardReset,
libcoreScanAccounts,
libcoreSignAndBroadcast,
libcoreSyncAccount,

20
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

19
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<Props, State> {
@ -55,6 +57,7 @@ class TabProfile extends PureComponent<Props, State> {
isSoftResetModalOpened: false,
isPasswordModalOpened: false,
isDisablePasswordModalOpened: false,
isHardResetting: false,
}
setPassword = password => {
@ -89,9 +92,17 @@ class TabProfile extends PureComponent<Props, State> {
}
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<Props, State> {
isHardResetModalOpened,
isPasswordModalOpened,
isDisablePasswordModalOpened,
isHardResetting,
} = this.state
const isPasswordEnabled = settings.password.isEnabled === true
return (
@ -200,6 +212,7 @@ class TabProfile extends PureComponent<Props, State> {
<ConfirmModal
isDanger
isLoading={isHardResetting}
isOpened={isHardResetModalOpened}
onClose={this.handleCloseHardResetModal}
onReject={this.handleCloseHardResetModal}

Loading…
Cancel
Save