diff options
author | brunobar79 <brunobar79@gmail.com> | 2018-07-12 09:21:36 +0800 |
---|---|---|
committer | brunobar79 <brunobar79@gmail.com> | 2018-07-12 09:21:36 +0800 |
commit | 80e875308b4447ed38d7e0f677570d73956dd9de (patch) | |
tree | fb2f0bdf95c6358295e3894b8302867bc8a16d51 /ui | |
parent | 89cc48789af2bb6f0925384abe4d4a53179a3956 (diff) | |
download | tangerine-wallet-browser-80e875308b4447ed38d7e0f677570d73956dd9de.tar tangerine-wallet-browser-80e875308b4447ed38d7e0f677570d73956dd9de.tar.gz tangerine-wallet-browser-80e875308b4447ed38d7e0f677570d73956dd9de.tar.bz2 tangerine-wallet-browser-80e875308b4447ed38d7e0f677570d73956dd9de.tar.lz tangerine-wallet-browser-80e875308b4447ed38d7e0f677570d73956dd9de.tar.xz tangerine-wallet-browser-80e875308b4447ed38d7e0f677570d73956dd9de.tar.zst tangerine-wallet-browser-80e875308b4447ed38d7e0f677570d73956dd9de.zip |
forget device and autiload account features added
Diffstat (limited to 'ui')
-rw-r--r-- | ui/app/actions.js | 44 | ||||
-rw-r--r-- | ui/app/components/pages/create-account/connect-hardware/account-list.js | 10 | ||||
-rw-r--r-- | ui/app/components/pages/create-account/connect-hardware/index.js | 31 | ||||
-rw-r--r-- | ui/app/css/itcss/components/new-account.scss | 11 |
4 files changed, 95 insertions, 1 deletions
diff --git a/ui/app/actions.js b/ui/app/actions.js index 3bdd548d3..9330a864b 100644 --- a/ui/app/actions.js +++ b/ui/app/actions.js @@ -79,6 +79,8 @@ var actions = { importNewAccount, addNewAccount, connectHardware, + checkHardwareStatus, + forgetDevice, unlockTrezorAccount, NEW_ACCOUNT_SCREEN: 'NEW_ACCOUNT_SCREEN', 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) { log.debug(`background.connectHardware`, deviceName, page) return (dispatch, getState) => { diff --git a/ui/app/components/pages/create-account/connect-hardware/account-list.js b/ui/app/components/pages/create-account/connect-hardware/account-list.js index 170d8f0b3..3bd6a00a7 100644 --- a/ui/app/components/pages/create-account/connect-hardware/account-list.js +++ b/ui/app/components/pages/create-account/connect-hardware/account-list.js @@ -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 () { return h('div', {}, [ this.renderAccounts(), this.renderPagination(), this.renderButtons(), + this.renderForgetDevice(), ]) } @@ -104,6 +113,7 @@ class AccountList extends Component { AccountList.propTypes = { accounts: PropTypes.array.isRequired, onAccountChange: PropTypes.func.isRequired, + onForgetDevice: PropTypes.func.isRequired, getPage: PropTypes.func.isRequired, network: PropTypes.string, selectedAccount: PropTypes.string, diff --git a/ui/app/components/pages/create-account/connect-hardware/index.js b/ui/app/components/pages/create-account/connect-hardware/index.js index 126102235..9aef36cfb 100644 --- a/ui/app/components/pages/create-account/connect-hardware/index.js +++ b/ui/app/components/pages/create-account/connect-hardware/index.js @@ -13,13 +13,19 @@ class ConnectHardwareForm extends Component { super(props) this.state = { error: null, - response: null, btnText: context.t('connectToTrezor'), selectedAccount: null, accounts: [], } } + async componentDidMount () { + const unlocked = await this.props.checkHardwareStatus('trezor') + if (unlocked) { + this.getPage(0) + } + } + connectToTrezor = () => { if (this.state.accounts.length) { 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 = () => { if (this.state.selectedAccount === null) { @@ -110,6 +130,7 @@ class ConnectHardwareForm extends Component { getPage: this.getPage, history: this.props.history, onUnlockAccount: this.onUnlockAccount, + onForgetDevice: this.onForgetDevice, onCancel: this.onCancel, }) } @@ -127,6 +148,8 @@ ConnectHardwareForm.propTypes = { showImportPage: PropTypes.func, showConnectPage: PropTypes.func, connectHardware: PropTypes.func, + checkHardwareStatus: PropTypes.func, + forgetDevice: PropTypes.func, unlockTrezorAccount: PropTypes.func, numberOfExistingAccounts: PropTypes.number, history: PropTypes.object, @@ -154,6 +177,12 @@ const mapDispatchToProps = dispatch => { 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 => { return dispatch(actions.unlockTrezorAccount(index)) }, diff --git a/ui/app/css/itcss/components/new-account.scss b/ui/app/css/itcss/components/new-account.scss index 66eb47378..e11c10dfe 100644 --- a/ui/app/css/itcss/components/new-account.scss +++ b/ui/app/css/itcss/components/new-account.scss @@ -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 { display: flex; |