1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

forget device and autiload account features added

This commit is contained in:
brunobar79 2018-07-11 21:21:36 -04:00
parent 89cc48789a
commit 80e875308b
6 changed files with 134 additions and 2 deletions

View File

@ -339,6 +339,9 @@
"followTwitter": { "followTwitter": {
"message": "Follow us on Twitter" "message": "Follow us on Twitter"
}, },
"forgetDevice": {
"message": "Forget this device"
},
"from": { "from": {
"message": "From" "message": "From"
}, },

View File

@ -357,8 +357,12 @@ module.exports = class MetamaskController extends EventEmitter {
removeAccount: nodeify(this.removeAccount, this), removeAccount: nodeify(this.removeAccount, this),
importAccountWithStrategy: nodeify(this.importAccountWithStrategy, this), importAccountWithStrategy: nodeify(this.importAccountWithStrategy, this),
// trezor // hardware wallets
connectHardware: nodeify(this.connectHardware, this), connectHardware: nodeify(this.connectHardware, this),
forgetDevice: nodeify(this.forgetDevice, this),
checkHardwareStatus: nodeify(this.checkHardwareStatus, this),
// TREZOR
unlockTrezorAccount: nodeify(this.unlockTrezorAccount, this), unlockTrezorAccount: nodeify(this.unlockTrezorAccount, this),
// vault management // vault management
@ -561,6 +565,37 @@ module.exports = class MetamaskController extends EventEmitter {
} }
} }
async checkHardwareStatus (deviceName) {
switch (deviceName) {
case 'trezor':
const keyringController = this.keyringController
const keyring = await keyringController.getKeyringsByType(
'Trezor Hardware'
)[0]
if (!keyring) {
return false
}
return keyring.isUnlocked()
}
}
async forgetDevice (deviceName) {
switch (deviceName) {
case 'trezor':
const keyringController = this.keyringController
const keyring = await keyringController.getKeyringsByType(
'Trezor Hardware'
)[0]
if (!keyring) {
return false
}
keyring.forgetDevice()
return true
}
}
/** /**
* Imports an account from a trezor device. * Imports an account from a trezor device.
* *

View File

@ -79,6 +79,8 @@ var actions = {
importNewAccount, importNewAccount,
addNewAccount, addNewAccount,
connectHardware, connectHardware,
checkHardwareStatus,
forgetDevice,
unlockTrezorAccount, unlockTrezorAccount,
NEW_ACCOUNT_SCREEN: 'NEW_ACCOUNT_SCREEN', NEW_ACCOUNT_SCREEN: 'NEW_ACCOUNT_SCREEN',
navigateToNewAccountScreen, navigateToNewAccountScreen,
@ -622,6 +624,48 @@ function addNewAccount () {
} }
} }
function checkHardwareStatus (deviceName) {
log.debug(`background.checkHardwareStatus`, deviceName)
return (dispatch, getState) => {
dispatch(actions.showLoadingIndication())
return new Promise((resolve, reject) => {
background.checkHardwareStatus(deviceName, (err, unlocked) => {
if (err) {
log.error(err)
dispatch(actions.displayWarning(err.message))
return reject(err)
}
dispatch(actions.hideLoadingIndication())
forceUpdateMetamaskState(dispatch)
return resolve(unlocked)
})
})
}
}
function forgetDevice (deviceName) {
log.debug(`background.forgetDevice`, deviceName)
return (dispatch, getState) => {
dispatch(actions.showLoadingIndication())
return new Promise((resolve, reject) => {
background.forgetDevice(deviceName, (err, response) => {
if (err) {
log.error(err)
dispatch(actions.displayWarning(err.message))
return reject(err)
}
dispatch(actions.hideLoadingIndication())
forceUpdateMetamaskState(dispatch)
return resolve()
})
})
}
}
function connectHardware (deviceName, page) { function connectHardware (deviceName, page) {
log.debug(`background.connectHardware`, deviceName, page) log.debug(`background.connectHardware`, deviceName, page)
return (dispatch, getState) => { return (dispatch, getState) => {

View File

@ -90,11 +90,20 @@ class AccountList extends Component {
]) ])
} }
renderForgetDevice () {
return h('div.hw-forget-device-container', {}, [
h('a', {
onClick: this.props.onForgetDevice.bind(this),
}, this.context.t('forgetDevice')),
])
}
render () { render () {
return h('div', {}, [ return h('div', {}, [
this.renderAccounts(), this.renderAccounts(),
this.renderPagination(), this.renderPagination(),
this.renderButtons(), this.renderButtons(),
this.renderForgetDevice(),
]) ])
} }
@ -104,6 +113,7 @@ class AccountList extends Component {
AccountList.propTypes = { AccountList.propTypes = {
accounts: PropTypes.array.isRequired, accounts: PropTypes.array.isRequired,
onAccountChange: PropTypes.func.isRequired, onAccountChange: PropTypes.func.isRequired,
onForgetDevice: PropTypes.func.isRequired,
getPage: PropTypes.func.isRequired, getPage: PropTypes.func.isRequired,
network: PropTypes.string, network: PropTypes.string,
selectedAccount: PropTypes.string, selectedAccount: PropTypes.string,

View File

@ -13,13 +13,19 @@ class ConnectHardwareForm extends Component {
super(props) super(props)
this.state = { this.state = {
error: null, error: null,
response: null,
btnText: context.t('connectToTrezor'), btnText: context.t('connectToTrezor'),
selectedAccount: null, selectedAccount: null,
accounts: [], accounts: [],
} }
} }
async componentDidMount () {
const unlocked = await this.props.checkHardwareStatus('trezor')
if (unlocked) {
this.getPage(0)
}
}
connectToTrezor = () => { connectToTrezor = () => {
if (this.state.accounts.length) { if (this.state.accounts.length) {
return null return null
@ -70,6 +76,20 @@ class ConnectHardwareForm extends Component {
}) })
} }
onForgetDevice = () => {
this.props.forgetDevice('trezor')
.then(_ => {
this.setState({
error: null,
btnText: this.context.t('connectToTrezor'),
selectedAccount: null,
accounts: [],
})
}).catch(e => {
this.setState({ error: e.toString() })
})
}
onUnlockAccount = () => { onUnlockAccount = () => {
if (this.state.selectedAccount === null) { if (this.state.selectedAccount === null) {
@ -110,6 +130,7 @@ class ConnectHardwareForm extends Component {
getPage: this.getPage, getPage: this.getPage,
history: this.props.history, history: this.props.history,
onUnlockAccount: this.onUnlockAccount, onUnlockAccount: this.onUnlockAccount,
onForgetDevice: this.onForgetDevice,
onCancel: this.onCancel, onCancel: this.onCancel,
}) })
} }
@ -127,6 +148,8 @@ ConnectHardwareForm.propTypes = {
showImportPage: PropTypes.func, showImportPage: PropTypes.func,
showConnectPage: PropTypes.func, showConnectPage: PropTypes.func,
connectHardware: PropTypes.func, connectHardware: PropTypes.func,
checkHardwareStatus: PropTypes.func,
forgetDevice: PropTypes.func,
unlockTrezorAccount: PropTypes.func, unlockTrezorAccount: PropTypes.func,
numberOfExistingAccounts: PropTypes.number, numberOfExistingAccounts: PropTypes.number,
history: PropTypes.object, history: PropTypes.object,
@ -154,6 +177,12 @@ const mapDispatchToProps = dispatch => {
connectHardware: (deviceName, page) => { connectHardware: (deviceName, page) => {
return dispatch(actions.connectHardware(deviceName, page)) return dispatch(actions.connectHardware(deviceName, page))
}, },
checkHardwareStatus: (deviceName) => {
return dispatch(actions.checkHardwareStatus(deviceName))
},
forgetDevice: (deviceName) => {
return dispatch(actions.forgetDevice(deviceName))
},
unlockTrezorAccount: index => { unlockTrezorAccount: index => {
return dispatch(actions.unlockTrezorAccount(index)) return dispatch(actions.unlockTrezorAccount(index))
}, },

View File

@ -270,6 +270,17 @@
} }
} }
.hw-forget-device-container {
display: flex;
flex-flow: column;
align-items: center;
padding: 30px 30px 0;
a {
color: #2f9ae0;
cursor: pointer;
}
}
.new-account-create-form { .new-account-create-form {
display: flex; display: flex;