checkbox remove or keep imported accounts on forgetting device
This commit is contained in:
parent
4d2941bffb
commit
6a3a9a4d54
|
@ -740,10 +740,14 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||
* @returns {Promise<boolean>}
|
||||
*/
|
||||
async forgetDevice (deviceName, clearAccounts) {
|
||||
|
||||
const keyring = await this.getKeyringForDevice(deviceName)
|
||||
keyring.forgetDevice(clearAccounts)
|
||||
return true
|
||||
const accountsToForget = await keyring.forgetDevice(clearAccounts)
|
||||
for (const acc of accountsToForget) {
|
||||
const accToLower = acc.toLowerCase()
|
||||
await this.preferencesController.removeAddress(accToLower)
|
||||
await this.accountTracker.removeAccount([accToLower])
|
||||
}
|
||||
return accountsToForget
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -32,7 +32,7 @@ const ConfirmAddTokenScreen = require('./components/confirm-add-token')
|
|||
const RemoveTokenScreen = require('./remove-token')
|
||||
const AddSuggestedTokenScreen = require('./add-suggested-token')
|
||||
const Import = require('./accounts/import')
|
||||
const ForgetDevice = require('./components/connect-hardware/forget-screen')
|
||||
const ForgetDeviceScreen = require('./components/connect-hardware/forget-screen')
|
||||
import ConnectHardwareForm from './components/connect-hardware/index'
|
||||
const InfoScreen = require('./info')
|
||||
const AppBar = require('./components/app-bar')
|
||||
|
@ -287,7 +287,7 @@ App.prototype.renderPrimary = function () {
|
|||
|
||||
case 'forget-device':
|
||||
log.debug('rendering forget device screen')
|
||||
return h(ForgetDevice, {key: 'forget-device'})
|
||||
return h(ForgetDeviceScreen, {key: 'forget-device'})
|
||||
|
||||
case 'hardware-wallets-menu':
|
||||
log.debug('rendering hardware wallet menu screen')
|
||||
|
|
|
@ -5,13 +5,13 @@ import { connect } from 'react-redux'
|
|||
class ConfirmScreen extends Component {
|
||||
static propTypes = {
|
||||
subtitle: PropTypes.string.isRequired,
|
||||
additionalData: PropTypes.func,
|
||||
renderAdditionalData: PropTypes.func,
|
||||
question: PropTypes.string.isRequired,
|
||||
withDescription: PropTypes.bool,
|
||||
description: PropTypes.string,
|
||||
onCancelClick: PropTypes.func.isRequired,
|
||||
onNoClick: PropTypes.bool.isRequired,
|
||||
onYesClick: PropTypes.bool.isRequired,
|
||||
onNoClick: PropTypes.func.isRequired,
|
||||
onYesClick: PropTypes.func.isRequired,
|
||||
}
|
||||
|
||||
render () {
|
||||
|
@ -40,7 +40,7 @@ class ConfirmScreen extends Component {
|
|||
<div className="error">{this.props.description}</div>
|
||||
</div>
|
||||
) : null}
|
||||
{this.props.additionalData}
|
||||
{this.props.renderAdditionalData()}
|
||||
<p className="confirm-label"
|
||||
style={{
|
||||
textAlign: 'center',
|
||||
|
|
|
@ -1,24 +1,44 @@
|
|||
import ConfirmScreen from '../confirm'
|
||||
import React from 'react'
|
||||
import React, { Component } from 'react'
|
||||
import { connect } from 'react-redux'
|
||||
import actions from '../../../../ui/app/actions'
|
||||
import { capitalizeFirstLetter } from '../../../../app/scripts/lib/util'
|
||||
|
||||
class ForgetDeviceScreen extends Component {
|
||||
constructor (props) {
|
||||
super(props)
|
||||
this.state = {
|
||||
clearAccounts: false
|
||||
}
|
||||
}
|
||||
|
||||
class ForgetDevice extends ConfirmScreen {
|
||||
render () {
|
||||
return (
|
||||
<ConfirmScreen
|
||||
subtitle="Forget device"
|
||||
question={`Are you sure to forget this device ?`}
|
||||
question={`Are you sure you want to forget this ${capitalizeFirstLetter(this.props.device)} ?`}
|
||||
onCancelClick={() => this.props.dispatch(actions.showConnectHWWalletPage())}
|
||||
additionalData={() => {
|
||||
// todo: checkbox
|
||||
renderAdditionalData={() => {
|
||||
return (
|
||||
<span>Remove imported associated accounts</span>
|
||||
)
|
||||
<div style={{
|
||||
margin: '0px 30px 20px'
|
||||
}}>
|
||||
<input
|
||||
type='checkbox'
|
||||
value={this.state.clearAccounts}
|
||||
onChange={(e) => {
|
||||
const clearAccountsPrev = this.state.clearAccounts
|
||||
const clearAccountsNew = !clearAccountsPrev
|
||||
this.setState({clearAccounts: clearAccountsNew})
|
||||
}}
|
||||
/>
|
||||
<span style={{'paddingLeft': '5px'}}>Remove associated accounts from the list of imported accounts in the wallet</span>
|
||||
</div>
|
||||
)
|
||||
}}
|
||||
onNoClick={() => this.props.dispatch(actions.showConnectHWWalletPage())}
|
||||
onYesClick={() => {
|
||||
this.props.forgetDevice(this.props.device)
|
||||
this.props.dispatch(actions.forgetDevice(this.props.device, this.state.clearAccounts))
|
||||
.then(_ => {
|
||||
this.setState({
|
||||
error: null,
|
||||
|
@ -27,13 +47,23 @@ class ForgetDevice extends ConfirmScreen {
|
|||
accounts: [],
|
||||
unlocked: false,
|
||||
})
|
||||
}).catch(e => {
|
||||
})
|
||||
.catch(e => {
|
||||
this.setState({ error: (e.message || e.toString()) })
|
||||
})
|
||||
.finally(() => {
|
||||
this.props.dispatch(actions.goHome())
|
||||
})
|
||||
}}
|
||||
/>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = connect()(ForgetDevice)
|
||||
const mapStateToProps = (state) => {
|
||||
return {
|
||||
device: state.appState.currentView.device,
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = connect(mapStateToProps)(ForgetDeviceScreen)
|
||||
|
|
|
@ -10514,7 +10514,7 @@
|
|||
}
|
||||
},
|
||||
"eth-ledger-bridge-keyring": {
|
||||
"version": "github:vbaranov/eth-ledger-bridge-keyring#4de923c0559bebe4f2e92465a21e911ed9ec2ee8",
|
||||
"version": "github:vbaranov/eth-ledger-bridge-keyring#c36b34d131a585274e8c7bb69ff985bba4816624",
|
||||
"from": "github:vbaranov/eth-ledger-bridge-keyring#0.1.0-clear-accounts-flag",
|
||||
"requires": {
|
||||
"eth-sig-util": "^1.4.2",
|
||||
|
@ -10935,7 +10935,7 @@
|
|||
}
|
||||
},
|
||||
"eth-trezor-keyring": {
|
||||
"version": "github:vbaranov/eth-trezor-keyring#3525a09d99a141afab0d298f3b5a8250e881bba1",
|
||||
"version": "github:vbaranov/eth-trezor-keyring#ec3df8a71ff8733e525d5609faeb5b711678dd11",
|
||||
"from": "github:vbaranov/eth-trezor-keyring#0.2.0--clear-accounts-flag",
|
||||
"requires": {
|
||||
"eth-sig-util": "^1.4.2",
|
||||
|
|
|
@ -749,12 +749,12 @@ function checkHardwareStatus (deviceName, hdPath) {
|
|||
}
|
||||
}
|
||||
|
||||
function forgetDevice (deviceName) {
|
||||
function forgetDevice (deviceName, clearAccounts) {
|
||||
log.debug(`background.forgetDevice`, deviceName)
|
||||
return (dispatch, getState) => {
|
||||
dispatch(actions.showLoadingIndication())
|
||||
return new Promise((resolve, reject) => {
|
||||
background.forgetDevice(deviceName, (err, response) => {
|
||||
background.forgetDevice(deviceName, clearAccounts, (err, accountsToForget) => {
|
||||
if (err) {
|
||||
log.error(err)
|
||||
dispatch(actions.displayWarning(err.message))
|
||||
|
@ -764,7 +764,7 @@ function forgetDevice (deviceName) {
|
|||
dispatch(actions.hideLoadingIndication())
|
||||
|
||||
forceUpdateMetamaskState(dispatch)
|
||||
return resolve()
|
||||
return resolve(accountsToForget)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue