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

legacy and new hd path working

This commit is contained in:
brunobar79 2018-08-14 01:26:18 -04:00
parent 4e1d8ba19d
commit 61a279204a
5 changed files with 53 additions and 25 deletions
app
ui/app
components/pages/create-account/connect-hardware
reducers

@ -538,6 +538,9 @@
"learnMore": { "learnMore": {
"message": "Learn more" "message": "Learn more"
}, },
"ledgerAccountRestriction": {
"message": "You need to make use your last account before you can add a new one."
},
"lessThanMax": { "lessThanMax": {
"message": "must be less than or equal to $1.", "message": "must be less than or equal to $1.",
"description": "helper for inputting hex as decimal input" "description": "helper for inputting hex as decimal input"
@ -922,6 +925,9 @@
"selectAnAccountHelp": { "selectAnAccountHelp": {
"message": "These are the accounts available in your hardware wallet. Select the one youd like to use in MetaMask." "message": "These are the accounts available in your hardware wallet. Select the one youd like to use in MetaMask."
}, },
"selectPathHelp": {
"message": "If you don't see your existing Ledger address(es), please try selecting a different HD Path \"Legacy (MEW / MyCrypto)\""
},
"sendTokensAnywhere": { "sendTokensAnywhere": {
"message": "Send Tokens to anyone with an Ethereum account" "message": "Send Tokens to anyone with an Ethereum account"
}, },

@ -556,10 +556,11 @@ module.exports = class MetamaskController extends EventEmitter {
keyring = await this.keyringController.addNewKeyring(keyringName) keyring = await this.keyringController.addNewKeyring(keyringName)
} }
if (hdPath) { if (hdPath) {
console.log('[LEDGER]: HDPATH set', hdPath)
keyring.hdPath = hdPath keyring.hdPath = hdPath
} }
keyring.network = this.networkController.getProviderConfig().type
return keyring return keyring
} }

@ -12,21 +12,34 @@ class AccountList extends Component {
getHdPaths () { getHdPaths () {
return [ return [
{ {
label: `m/44'/60'/0' (Legacy)`, label: `Ledger Live`,
value: `m/44'/60'/0'`, value: `m/44'/60'/0'/0/0`,
}, },
{ {
label: `m/44'/60'/0'/0`, label: `Legacy (MEW / MyCrypto)`,
value: `m/44'/60'/0'/0'`, value: `m/44'/60'/0'`,
}, },
] ]
} }
goToNextPage = () => {
if (this.props.accounts === 5) {
this.props.getPage(this.props.device, 1, this.props.selectedPath)
} else {
this.props.onAccountRestriction()
}
}
goToPreviousPage = () => {
this.props.getPage(this.props.device, -1, this.props.selectedPath)
}
renderHdPathSelector () { renderHdPathSelector () {
const { onPathChange, selectedPath } = this.props const { onPathChange, selectedPath } = this.props
const options = this.getHdPaths() const options = this.getHdPaths()
return h('div.hw-connect__hdPath', [ return h('div', [
h('div.hw-connect__hdPath', [
h('h3.hw-connect__hdPath__title', {}, `HD Path`), h('h3.hw-connect__hdPath__title', {}, `HD Path`),
h(Select, { h(Select, {
className: 'hw-connect__hdPath__select', className: 'hw-connect__hdPath__select',
@ -38,6 +51,8 @@ class AccountList extends Component {
onPathChange(opt.value) onPathChange(opt.value)
}, },
}), }),
]),
h('p.hw-connect__msg', {}, this.context.t('selectPathHelp')),
]) ])
} }
renderHeader () { renderHeader () {
@ -98,7 +113,7 @@ class AccountList extends Component {
h( h(
'button.hw-list-pagination__button', 'button.hw-list-pagination__button',
{ {
onClick: () => this.props.getPage(-1, this.props.device), onClick: this.goToPreviousPage,
}, },
`< ${this.context.t('prev')}` `< ${this.context.t('prev')}`
), ),
@ -106,7 +121,7 @@ class AccountList extends Component {
h( h(
'button.hw-list-pagination__button', 'button.hw-list-pagination__button',
{ {
onClick: () => this.props.getPage(1, this.props.device), onClick: this.goToNextPage,
}, },
`${this.context.t('next')} >` `${this.context.t('next')} >`
), ),
@ -174,6 +189,7 @@ AccountList.propTypes = {
history: PropTypes.object, history: PropTypes.object,
onUnlockAccount: PropTypes.func, onUnlockAccount: PropTypes.func,
onCancel: PropTypes.func, onCancel: PropTypes.func,
onAccountRestriction: PropTypes.func,
} }
AccountList.contextTypes = { AccountList.contextTypes = {

@ -43,7 +43,7 @@ class ConnectHardwareForm extends Component {
const unlocked = await this.props.checkHardwareStatus(device, this.props.defaultHdPaths[device]) const unlocked = await this.props.checkHardwareStatus(device, this.props.defaultHdPaths[device])
if (unlocked) { if (unlocked) {
this.setState({unlocked: true}) 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 // Default values
this.setState({ btnText: this.context.t('connecting')}) 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) => { onPathChange = (path) => {
console.log('BRUNO: path changed', path) console.log('BRUNO: path changed', path)
this.props.setHardwareWalletDefaultHdPath({device: this.state.device, 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) => { onAccountChange = (account) => {
this.setState({selectedAccount: account.toString(), error: null}) this.setState({selectedAccount: account.toString(), error: null})
} }
onAccountRestriction = () => {
this.setState({error: this.context.t('ledgerAccountRestriction') })
}
showTemporaryAlert () { showTemporaryAlert () {
this.props.showAlert(this.context.t('hardwareWalletConnected')) this.props.showAlert(this.context.t('hardwareWalletConnected'))
// Autohide the alert after 5 seconds // Autohide the alert after 5 seconds
@ -76,7 +80,7 @@ class ConnectHardwareForm extends Component {
}, 5000) }, 5000)
} }
getPage = (page, device, hdPath) => { getPage = (device, page, hdPath) => {
this.props this.props
.connectHardware(device, page, hdPath) .connectHardware(device, page, hdPath)
.then(accounts => { .then(accounts => {
@ -182,6 +186,7 @@ class ConnectHardwareForm extends Component {
onUnlockAccount: this.onUnlockAccount, onUnlockAccount: this.onUnlockAccount,
onForgetDevice: this.onForgetDevice, onForgetDevice: this.onForgetDevice,
onCancel: this.onCancel, onCancel: this.onCancel,
onAccountRestriction: this.onAccountRestriction,
}) })
} }
@ -237,7 +242,7 @@ const mapDispatchToProps = dispatch => {
return dispatch(actions.setHardwareWalletDefaultHdPath({device, path})) return dispatch(actions.setHardwareWalletDefaultHdPath({device, path}))
}, },
connectHardware: (deviceName, page, hdPath) => { connectHardware: (deviceName, page, hdPath) => {
return dispatch(actions.connectHardware(deviceName, hdPath, page)) return dispatch(actions.connectHardware(deviceName, page, hdPath))
}, },
checkHardwareStatus: (deviceName, hdPath) => { checkHardwareStatus: (deviceName, hdPath) => {
return dispatch(actions.checkHardwareStatus(deviceName, hdPath)) return dispatch(actions.checkHardwareStatus(deviceName, hdPath))

@ -69,7 +69,7 @@ function reduceApp (state, action) {
networkNonce: null, networkNonce: null,
defaultHdPaths: { defaultHdPaths: {
trezor: `m/44'/60'/0'/0`, trezor: `m/44'/60'/0'/0`,
ledger: `m/44'/60'/0'`, ledger: `m/44'/60'/0'/0/0`,
}, },
}, state.appState) }, state.appState)