@@ -3,12 +3,12 @@ import React from 'react'
3import Maybe from 'folktale/maybe'
3import Maybe from 'folktale/maybe'
4import { Button } from '../components/Base'
4import { Button } from '../components/Base'
5import { Row, Col, H1, P, H2 } from '../components/Base'
5import { Row, Col, H1, P, H2 } from '../components/Base'
6−import { Input, InnerLabel } from '../components/Base'
6+import { Input, InnerLabel, InnerLabelDropdown } from '../components/Base'
7import Transport from '@ledgerhq/hw-transport-u2f'
7import Transport from '@ledgerhq/hw-transport-u2f'
8import Eth from '@ledgerhq/hw-app-eth'
8import Eth from '@ledgerhq/hw-app-eth'
9import * as secp256k1 from 'secp256k1'
9import * as secp256k1 from 'secp256k1'
11−import { LEDGER_BASE_PATH } from '../lib/ledger'
11+import { LEDGER_LIVE_PATH, LEDGER_LEGACY_PATH } from '../lib/ledger'
12import { ROUTE_NAMES } from '../lib/router'
12import { ROUTE_NAMES } from '../lib/router'
14const chopHdPrefix = str =>
14const chopHdPrefix = str =>
@@ -26,11 +26,32 @@ class Ledger extends React.Component {
26 super(props)
26 super(props)
28 this.state = {
28 this.state = {
29− hdpath: LEDGER_BASE_PATH
29+ basePath: LEDGER_LIVE_PATH,
30+ hdpath: LEDGER_LIVE_PATH.replace(/x/g, 0),
32 this.pollDevice = this.pollDevice.bind(this)
34 this.pollDevice = this.pollDevice.bind(this)
33 this.handleHdPathInput = this.handleHdPathInput.bind(this)
35 this.handleHdPathInput = this.handleHdPathInput.bind(this)
36+ this.handlePathSelection = this.handlePathSelection.bind(this);
37+ this.handleAccountSelection = this.handleAccountSelection.bind(this);
38+ this.updateHdPath = this.updateHdPath.bind(this);
41+ handlePathSelection(basePath) {
42+ this.updateHdPath(basePath, this.state.account);
45+ handleAccountSelection(account) {
46+ this.updateHdPath(this.state.basePath, account);
49+ updateHdPath(basePath, account) {
50+ let hdpath = this.state.hdpath;
51+ if (basePath !== 'custom') {
52+ hdpath = basePath.replace(/x/g, account);
54+ this.setState({ basePath, account, hdpath });
36 handleHdPathInput(hdpath) {
57 handleHdPathInput(hdpath) {
@@ -60,7 +81,66 @@ class Ledger extends React.Component {
61 render() {
82 render() {
62 const { pushRoute, popRoute, wallet } = this.props
83 const { pushRoute, popRoute, wallet } = this.props
63− const { hdpath } = this.state
84+ const { basePath, hdpath, account } = this.state;
85+ const { handlePathSelection, handleAccountSelection } = this;
87+ const pathOptions = [
88+ { title: 'Ledger Live',
89+ value: LEDGER_LIVE_PATH
91+ { title: 'Ledger Legacy',
92+ value: LEDGER_LEGACY_PATH
95+ title: 'Custom path',
99+ let basePathTitle = pathOptions.find(o => (o.value === basePath)).title;
101+ let accountOptions = [];
102+ for (let i = 0; i < 20; i++) {
103+ accountOptions.push({
104+ title: 'Account #' + (i+1),
108+ let accountTitle = accountOptions.find(o => (o.value === account)).title;
110+ const basePathSelection = (
113+ options={pathOptions}
114+ handleUpdate={handlePathSelection}
115+ title={'Derivation path'}
116+ currentSelectionTitle={basePathTitle}
119+ </InnerLabelDropdown>
122+ const truePathSelection = (basePath === 'custom')
124+ className='pt-8 mt-4 text-mono'
126+ prop-format='innerLabel'
128+ value={ addHdPrefix(hdpath) }
130+ onChange={ this.handleHdPathInput }>
131+ <InnerLabel>{'HD Path'}</InnerLabel>
133+ : ( <InnerLabelDropdown
136+ prop-format='innerLabel'
137+ options={accountOptions}
138+ handleUpdate={handleAccountSelection}
140+ currentSelectionTitle={accountTitle}
143+ </InnerLabelDropdown> );
@@ -99,16 +179,8 @@ class Ledger extends React.Component {
99 <li className={'mt-4'}>{'Run '}<code>{'python bridge-https.py'}</code></li>
179 <li className={'mt-4'}>{'Run '}<code>{'python bridge-https.py'}</code></li>
102− <Input
182+ { basePathSelection }
103− className='pt-8 mt-8 text-mono'
183+ { truePathSelection }
105− prop-format='innerLabel'
107− value={ addHdPrefix(hdpath) }
109− onChange={ this.handleHdPathInput }>
110− <InnerLabel>{'HD Path'}</InnerLabel>
114 prop-size={'wide lg'}
186 prop-size={'wide lg'}