From 5ef80495cfd47a8f5e4caf4b16842155420de62e Mon Sep 17 00:00:00 2001 From: brunobar79 Date: Fri, 10 Aug 2018 21:54:34 -0400 Subject: refactor to support multiple hw wallets --- .../pages/create-account/connect-hardware/index.js | 39 ++++++++++++---------- 1 file changed, 22 insertions(+), 17 deletions(-) (limited to 'ui/app/components/pages/create-account/connect-hardware/index.js') 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 3f66e7098..646ba8bec 100644 --- a/ui/app/components/pages/create-account/connect-hardware/index.js +++ b/ui/app/components/pages/create-account/connect-hardware/index.js @@ -18,6 +18,7 @@ class ConnectHardwareForm extends Component { accounts: [], browserSupported: true, unlocked: false, + device: null } } @@ -38,19 +39,22 @@ class ConnectHardwareForm extends Component { } async checkIfUnlocked () { - const unlocked = await this.props.checkHardwareStatus('trezor') - if (unlocked) { - this.setState({unlocked: true}) - this.getPage(0) - } + ['trezor', 'ledger'].forEach(async device => { + const unlocked = await this.props.checkHardwareStatus(device) + if (unlocked) { + this.setState({unlocked: true}) + this.getPage(0, device) + } + }) } - connectToTrezor = () => { + connectToHardwareWallet = (device) => { + debugger if (this.state.accounts.length) { return null } this.setState({ btnText: this.context.t('connecting')}) - this.getPage(0) + this.getPage(0, device) } onAccountChange = (account) => { @@ -65,9 +69,9 @@ class ConnectHardwareForm extends Component { }, 5000) } - getPage = (page) => { + getPage = (page, device) => { this.props - .connectHardware('trezor', page) + .connectHardware(device, page) .then(accounts => { if (accounts.length) { @@ -77,7 +81,7 @@ class ConnectHardwareForm extends Component { this.showTemporaryAlert() } - const newState = { unlocked: true } + const newState = { unlocked: true, device } // Default to the first account if (this.state.selectedAccount === null) { accounts.forEach((a, i) => { @@ -110,8 +114,8 @@ class ConnectHardwareForm extends Component { }) } - onForgetDevice = () => { - this.props.forgetDevice('trezor') + onForgetDevice = (device) => { + this.props.forgetDevice(device) .then(_ => { this.setState({ error: null, @@ -131,7 +135,7 @@ class ConnectHardwareForm extends Component { this.setState({ error: this.context.t('accountSelectionRequired') }) } - this.props.unlockTrezorAccount(this.state.selectedAccount) + this.props.unlockHardwareWalletAccount(this.state.selectedAccount, this.state.device) .then(_ => { this.props.history.push(DEFAULT_ROUTE) }).catch(e => { @@ -152,13 +156,14 @@ class ConnectHardwareForm extends Component { renderContent () { if (!this.state.accounts.length) { return h(ConnectScreen, { - connectToTrezor: this.connectToTrezor, + connectToHardwareWallet: this.connectToHardwareWallet, btnText: this.state.btnText, browserSupported: this.state.browserSupported, }) } return h(AccountList, { + device: this.state.device, accounts: this.state.accounts, selectedAccount: this.state.selectedAccount, onAccountChange: this.onAccountChange, @@ -188,7 +193,7 @@ ConnectHardwareForm.propTypes = { forgetDevice: PropTypes.func, showAlert: PropTypes.func, hideAlert: PropTypes.func, - unlockTrezorAccount: PropTypes.func, + unlockHardwareWalletAccount: PropTypes.func, numberOfExistingAccounts: PropTypes.number, history: PropTypes.object, t: PropTypes.func, @@ -222,8 +227,8 @@ const mapDispatchToProps = dispatch => { forgetDevice: (deviceName) => { return dispatch(actions.forgetDevice(deviceName)) }, - unlockTrezorAccount: index => { - return dispatch(actions.unlockTrezorAccount(index)) + unlockHardwareWalletAccount: (index, deviceName) => { + return dispatch(actions.unlockHardwareWalletAccount(index, deviceName)) }, showImportPage: () => dispatch(actions.showImportPage()), showConnectPage: () => dispatch(actions.showConnectPage()), -- cgit From 78a1cd3314455d6e4e08839a3eea3ec2868f4f59 Mon Sep 17 00:00:00 2001 From: brunobar79 Date: Sat, 11 Aug 2018 02:35:20 -0400 Subject: iframe communication working --- ui/app/components/pages/create-account/connect-hardware/index.js | 1 - 1 file changed, 1 deletion(-) (limited to 'ui/app/components/pages/create-account/connect-hardware/index.js') 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 646ba8bec..86a4d7257 100644 --- a/ui/app/components/pages/create-account/connect-hardware/index.js +++ b/ui/app/components/pages/create-account/connect-hardware/index.js @@ -49,7 +49,6 @@ class ConnectHardwareForm extends Component { } connectToHardwareWallet = (device) => { - debugger if (this.state.accounts.length) { return null } -- cgit From 8e842a8947997b7ea47cf35d1348788d21f2f467 Mon Sep 17 00:00:00 2001 From: brunobar79 Date: Sat, 11 Aug 2018 05:02:02 -0400 Subject: able to add accounts --- ui/app/components/pages/create-account/connect-hardware/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ui/app/components/pages/create-account/connect-hardware/index.js') 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 86a4d7257..644742172 100644 --- a/ui/app/components/pages/create-account/connect-hardware/index.js +++ b/ui/app/components/pages/create-account/connect-hardware/index.js @@ -128,13 +128,13 @@ class ConnectHardwareForm extends Component { }) } - onUnlockAccount = () => { + onUnlockAccount = (device) => { if (this.state.selectedAccount === null) { this.setState({ error: this.context.t('accountSelectionRequired') }) } - this.props.unlockHardwareWalletAccount(this.state.selectedAccount, this.state.device) + this.props.unlockHardwareWalletAccount(this.state.selectedAccount, device) .then(_ => { this.props.history.push(DEFAULT_ROUTE) }).catch(e => { -- cgit From 4e1d8ba19db729f5c282c4e3c6b43433b562a45e Mon Sep 17 00:00:00 2001 From: brunobar79 Date: Mon, 13 Aug 2018 19:29:43 -0400 Subject: good progress adding paths --- .../pages/create-account/connect-hardware/index.js | 43 ++++++++++++++++------ 1 file changed, 31 insertions(+), 12 deletions(-) (limited to 'ui/app/components/pages/create-account/connect-hardware/index.js') 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 644742172..0eb2aa16f 100644 --- a/ui/app/components/pages/create-account/connect-hardware/index.js +++ b/ui/app/components/pages/create-account/connect-hardware/index.js @@ -18,7 +18,7 @@ class ConnectHardwareForm extends Component { accounts: [], browserSupported: true, unlocked: false, - device: null + device: null, } } @@ -40,10 +40,10 @@ class ConnectHardwareForm extends Component { async checkIfUnlocked () { ['trezor', 'ledger'].forEach(async device => { - const unlocked = await this.props.checkHardwareStatus(device) + const unlocked = await this.props.checkHardwareStatus(device, this.props.defaultHdPaths[device]) if (unlocked) { this.setState({unlocked: true}) - this.getPage(0, device) + this.getPage(0, device, this.props.defaultHdPaths[device]) } }) } @@ -52,8 +52,16 @@ class ConnectHardwareForm extends Component { if (this.state.accounts.length) { return null } + + // Default values this.setState({ btnText: this.context.t('connecting')}) - this.getPage(0, device) + this.getPage(0, device, this.props.defaultHdPaths[device]) + } + + onPathChange = (path) => { + console.log('BRUNO: path changed', path) + this.props.setHardwareWalletDefaultHdPath({device: this.state.device, path}) + this.getPage(0, this.state.device, path) } onAccountChange = (account) => { @@ -68,9 +76,9 @@ class ConnectHardwareForm extends Component { }, 5000) } - getPage = (page, device) => { + getPage = (page, device, hdPath) => { this.props - .connectHardware(device, page) + .connectHardware(device, page, hdPath) .then(accounts => { if (accounts.length) { @@ -162,6 +170,8 @@ class ConnectHardwareForm extends Component { } return h(AccountList, { + onPathChange: this.onPathChange, + selectedPath: this.props.defaultHdPaths[this.state.device], device: this.state.device, accounts: this.state.accounts, selectedAccount: this.state.selectedAccount, @@ -193,12 +203,14 @@ ConnectHardwareForm.propTypes = { showAlert: PropTypes.func, hideAlert: PropTypes.func, unlockHardwareWalletAccount: PropTypes.func, + setHardwareWalletDefaultHdPath: PropTypes.func, numberOfExistingAccounts: PropTypes.number, history: PropTypes.object, t: PropTypes.func, network: PropTypes.string, accounts: PropTypes.object, address: PropTypes.string, + defaultHdPaths: PropTypes.object, } const mapStateToProps = state => { @@ -206,28 +218,35 @@ const mapStateToProps = state => { metamask: { network, selectedAddress, identities = {}, accounts = [] }, } = state const numberOfExistingAccounts = Object.keys(identities).length + const { + appState: { defaultHdPaths }, + } = state return { network, accounts, address: selectedAddress, numberOfExistingAccounts, + defaultHdPaths, } } const mapDispatchToProps = dispatch => { return { - connectHardware: (deviceName, page) => { - return dispatch(actions.connectHardware(deviceName, page)) + setHardwareWalletDefaultHdPath: ({device, path}) => { + return dispatch(actions.setHardwareWalletDefaultHdPath({device, path})) + }, + connectHardware: (deviceName, page, hdPath) => { + return dispatch(actions.connectHardware(deviceName, hdPath, page)) }, - checkHardwareStatus: (deviceName) => { - return dispatch(actions.checkHardwareStatus(deviceName)) + checkHardwareStatus: (deviceName, hdPath) => { + return dispatch(actions.checkHardwareStatus(deviceName, hdPath)) }, forgetDevice: (deviceName) => { return dispatch(actions.forgetDevice(deviceName)) }, - unlockHardwareWalletAccount: (index, deviceName) => { - return dispatch(actions.unlockHardwareWalletAccount(index, deviceName)) + unlockHardwareWalletAccount: (index, deviceName, hdPath) => { + return dispatch(actions.unlockHardwareWalletAccount(index, deviceName, hdPath)) }, showImportPage: () => dispatch(actions.showImportPage()), showConnectPage: () => dispatch(actions.showConnectPage()), -- cgit From 61a279204a804ddf4815d0db6103c19c5640bbb9 Mon Sep 17 00:00:00 2001 From: brunobar79 Date: Tue, 14 Aug 2018 01:26:18 -0400 Subject: legacy and new hd path working --- .../pages/create-account/connect-hardware/index.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'ui/app/components/pages/create-account/connect-hardware/index.js') 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 0eb2aa16f..e7e94686a 100644 --- a/ui/app/components/pages/create-account/connect-hardware/index.js +++ b/ui/app/components/pages/create-account/connect-hardware/index.js @@ -43,7 +43,7 @@ class ConnectHardwareForm extends Component { const unlocked = await this.props.checkHardwareStatus(device, this.props.defaultHdPaths[device]) if (unlocked) { this.setState({unlocked: true}) - this.getPage(0, device, this.props.defaultHdPaths[device]) + this.getPage(device, 0, this.props.defaultHdPaths[device]) } }) } @@ -55,19 +55,23 @@ class ConnectHardwareForm extends Component { // Default values this.setState({ btnText: this.context.t('connecting')}) - this.getPage(0, device, this.props.defaultHdPaths[device]) + this.getPage(device, 0, this.props.defaultHdPaths[device]) } onPathChange = (path) => { console.log('BRUNO: path changed', path) this.props.setHardwareWalletDefaultHdPath({device: this.state.device, path}) - this.getPage(0, this.state.device, path) + this.getPage(this.state.device, 0, path) } onAccountChange = (account) => { this.setState({selectedAccount: account.toString(), error: null}) } + onAccountRestriction = () => { + this.setState({error: this.context.t('ledgerAccountRestriction') }) + } + showTemporaryAlert () { this.props.showAlert(this.context.t('hardwareWalletConnected')) // Autohide the alert after 5 seconds @@ -76,7 +80,7 @@ class ConnectHardwareForm extends Component { }, 5000) } - getPage = (page, device, hdPath) => { + getPage = (device, page, hdPath) => { this.props .connectHardware(device, page, hdPath) .then(accounts => { @@ -182,6 +186,7 @@ class ConnectHardwareForm extends Component { onUnlockAccount: this.onUnlockAccount, onForgetDevice: this.onForgetDevice, onCancel: this.onCancel, + onAccountRestriction: this.onAccountRestriction, }) } @@ -237,7 +242,7 @@ const mapDispatchToProps = dispatch => { return dispatch(actions.setHardwareWalletDefaultHdPath({device, path})) }, connectHardware: (deviceName, page, hdPath) => { - return dispatch(actions.connectHardware(deviceName, hdPath, page)) + return dispatch(actions.connectHardware(deviceName, page, hdPath)) }, checkHardwareStatus: (deviceName, hdPath) => { return dispatch(actions.checkHardwareStatus(deviceName, hdPath)) -- cgit From c72ced79aeb3d79d12ae240b680e0561122e5209 Mon Sep 17 00:00:00 2001 From: brunobar79 Date: Tue, 14 Aug 2018 19:22:00 -0400 Subject: ui fixes --- .../pages/create-account/connect-hardware/index.js | 24 +++++++++++++--------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'ui/app/components/pages/create-account/connect-hardware/index.js') 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 e7e94686a..068b27cc2 100644 --- a/ui/app/components/pages/create-account/connect-hardware/index.js +++ b/ui/app/components/pages/create-account/connect-hardware/index.js @@ -6,14 +6,14 @@ const actions = require('../../../../actions') const ConnectScreen = require('./connect-screen') const AccountList = require('./account-list') const { DEFAULT_ROUTE } = require('../../../../routes') -const { formatBalance } = require('../../../../util') +const { formatBalance, getPlatform } = require('../../../../../../app/scripts/lib/util') +const { PLATFORM_FIREFOX } = require('../../../../../../app/scripts/lib/enums') class ConnectHardwareForm extends Component { constructor (props, context) { super(props) this.state = { error: null, - btnText: context.t('connectToTrezor'), selectedAccount: null, accounts: [], browserSupported: true, @@ -49,17 +49,22 @@ class ConnectHardwareForm extends Component { } connectToHardwareWallet = (device) => { + // None of the hardware wallets are supported + // At least for now + if (getPlatform() === PLATFORM_FIREFOX) { + this.setState({ browserSupported: false, error: null}) + return null + } + if (this.state.accounts.length) { return null } // Default values - this.setState({ btnText: this.context.t('connecting')}) this.getPage(device, 0, this.props.defaultHdPaths[device]) } onPathChange = (path) => { - console.log('BRUNO: path changed', path) this.props.setHardwareWalletDefaultHdPath({device: this.state.device, path}) this.getPage(this.state.device, 0, path) } @@ -92,7 +97,7 @@ class ConnectHardwareForm extends Component { this.showTemporaryAlert() } - const newState = { unlocked: true, device } + const newState = { unlocked: true, device, error: null } // Default to the first account if (this.state.selectedAccount === null) { accounts.forEach((a, i) => { @@ -119,9 +124,10 @@ class ConnectHardwareForm extends Component { }) .catch(e => { if (e === 'Window blocked') { - this.setState({ browserSupported: false }) + this.setState({ browserSupported: false, error: null}) + } else { + this.setState({ error: e.toString() }) } - this.setState({ btnText: this.context.t('connectToTrezor') }) }) } @@ -130,7 +136,6 @@ class ConnectHardwareForm extends Component { .then(_ => { this.setState({ error: null, - btnText: this.context.t('connectToTrezor'), selectedAccount: null, accounts: [], unlocked: false, @@ -160,7 +165,7 @@ class ConnectHardwareForm extends Component { renderError () { return this.state.error - ? h('span.error', { style: { marginBottom: 40 } }, this.state.error) + ? h('span.error', { style: { margin: '20px 20px 10px', display: 'block', textAlign: 'center' } }, this.state.error) : null } @@ -168,7 +173,6 @@ class ConnectHardwareForm extends Component { if (!this.state.accounts.length) { return h(ConnectScreen, { connectToHardwareWallet: this.connectToHardwareWallet, - btnText: this.state.btnText, browserSupported: this.state.browserSupported, }) } -- cgit From 19d1988715edfb6ee3ba8251af8ee9da20342234 Mon Sep 17 00:00:00 2001 From: brunobar79 Date: Tue, 14 Aug 2018 19:24:15 -0400 Subject: fix --- ui/app/components/pages/create-account/connect-hardware/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ui/app/components/pages/create-account/connect-hardware/index.js') 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 068b27cc2..4f01a2b0c 100644 --- a/ui/app/components/pages/create-account/connect-hardware/index.js +++ b/ui/app/components/pages/create-account/connect-hardware/index.js @@ -125,7 +125,7 @@ class ConnectHardwareForm extends Component { .catch(e => { if (e === 'Window blocked') { this.setState({ browserSupported: false, error: null}) - } else { + } else if (e !== 'Window closed') { this.setState({ error: e.toString() }) } }) -- cgit From 53dcad5a3b89ca4f3a67c3f6b4d6b8f73ebd02e5 Mon Sep 17 00:00:00 2001 From: brunobar79 Date: Tue, 14 Aug 2018 19:38:23 -0400 Subject: more ui --- ui/app/components/pages/create-account/connect-hardware/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'ui/app/components/pages/create-account/connect-hardware/index.js') 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 4f01a2b0c..547df5223 100644 --- a/ui/app/components/pages/create-account/connect-hardware/index.js +++ b/ui/app/components/pages/create-account/connect-hardware/index.js @@ -6,7 +6,8 @@ const actions = require('../../../../actions') const ConnectScreen = require('./connect-screen') const AccountList = require('./account-list') const { DEFAULT_ROUTE } = require('../../../../routes') -const { formatBalance, getPlatform } = require('../../../../../../app/scripts/lib/util') +const { formatBalance } = require('../../../../util') +const { getPlatform } = require('../../../../../../app/scripts/lib/util') const { PLATFORM_FIREFOX } = require('../../../../../../app/scripts/lib/enums') class ConnectHardwareForm extends Component { -- cgit