10 changed files with 150 additions and 2 deletions
@ -0,0 +1,28 @@ |
|||
// @flow
|
|||
|
|||
import { getCryptoCurrencyById } from '@ledgerhq/live-common/lib/helpers/currencies' |
|||
import { createCommand, Command } from 'helpers/ipc' |
|||
import { fromPromise } from 'rxjs/observable/fromPromise' |
|||
import { withDevice } from 'helpers/deviceAccess' |
|||
import debugAppInfosForCurrency from 'helpers/debugAppInfosForCurrency' |
|||
|
|||
type Input = { |
|||
currencyId: string, |
|||
devicePath: string, |
|||
} |
|||
|
|||
type Result = { |
|||
version?: string, |
|||
} |
|||
|
|||
const cmd: Command<Input, Result> = createCommand( |
|||
'debugAppInfosForCurrency', |
|||
({ currencyId, devicePath }) => |
|||
fromPromise( |
|||
withDevice(devicePath)(transport => |
|||
debugAppInfosForCurrency(transport, getCryptoCurrencyById(currencyId)), |
|||
), |
|||
), |
|||
) |
|||
|
|||
export default cmd |
@ -0,0 +1,51 @@ |
|||
// @flow
|
|||
import { Component } from 'react' |
|||
import { connect } from 'react-redux' |
|||
import { createStructuredSelector } from 'reselect' |
|||
import { getCurrentDevice } from 'reducers/devices' |
|||
import debugAppInfosForCurrency from 'commands/debugAppInfosForCurrency' |
|||
|
|||
class DebugAppInfosForCurrency extends Component< |
|||
{ |
|||
children?: (?string) => React$Node, |
|||
currencyId: string, |
|||
device: *, |
|||
}, |
|||
{ |
|||
version: ?string, |
|||
}, |
|||
> { |
|||
state = { |
|||
version: null, |
|||
} |
|||
componentDidMount() { |
|||
const { device, currencyId } = this.props |
|||
if (device) { |
|||
debugAppInfosForCurrency |
|||
.send({ currencyId, devicePath: device.path }) |
|||
.toPromise() |
|||
.then( |
|||
({ version }) => { |
|||
if (this.unmounted) return |
|||
this.setState({ version }) |
|||
}, |
|||
() => {}, |
|||
) |
|||
} |
|||
} |
|||
componentWillUnmount() { |
|||
this.unmounted = true |
|||
} |
|||
unmounted = false |
|||
render() { |
|||
const { children } = this.props |
|||
const { version } = this.state |
|||
return children ? children(version) : null |
|||
} |
|||
} |
|||
|
|||
export default connect( |
|||
createStructuredSelector({ |
|||
device: getCurrentDevice, |
|||
}), |
|||
)(DebugAppInfosForCurrency) |
@ -0,0 +1,12 @@ |
|||
// @flow
|
|||
|
|||
import type Transport from '@ledgerhq/hw-transport' |
|||
import { createCustomErrorClass } from '../errors' |
|||
|
|||
export const BtcUnmatchedApp = createCustomErrorClass('BtcUnmatchedApp') |
|||
|
|||
export default async (transport: Transport<*>) => { |
|||
const r = await transport.send(0xe0, 0xc4, 0, 0) |
|||
const version = `${r[2]}.${r[3]}.${r[4]}` |
|||
return { version } |
|||
} |
@ -0,0 +1,10 @@ |
|||
// @flow
|
|||
|
|||
import Eth from '@ledgerhq/hw-app-eth' |
|||
import type Transport from '@ledgerhq/hw-transport' |
|||
|
|||
export default async (transport: Transport<*>) => { |
|||
const eth = new Eth(transport) |
|||
const { version } = await eth.getAppConfiguration() |
|||
return { version } |
|||
} |
@ -0,0 +1,29 @@ |
|||
// @flow
|
|||
|
|||
import type { CryptoCurrency } from '@ledgerhq/live-common/lib/types' |
|||
import invariant from 'invariant' |
|||
import type Transport from '@ledgerhq/hw-transport' |
|||
import bitcoin from './btc' |
|||
import ethereum from './ethereum' |
|||
import ripple from './ripple' |
|||
|
|||
type Resolver = ( |
|||
transport: Transport<*>, |
|||
currency: CryptoCurrency, |
|||
) => Promise<{ |
|||
version?: string, |
|||
}> |
|||
|
|||
const perFamily: { [_: string]: * } = { |
|||
bitcoin, |
|||
ethereum, |
|||
ripple, |
|||
} |
|||
|
|||
const proxy: Resolver = (transport, currency) => { |
|||
const getAddress = perFamily[currency.family] |
|||
invariant(getAddress, `getAddress not implemented for ${currency.id}`) |
|||
return getAddress(transport) |
|||
} |
|||
|
|||
export default proxy |
@ -0,0 +1,10 @@ |
|||
// @flow
|
|||
|
|||
import Xrp from '@ledgerhq/hw-app-xrp' |
|||
import type Transport from '@ledgerhq/hw-transport' |
|||
|
|||
export default async (transport: Transport<*>) => { |
|||
const xrp = new Xrp(transport) |
|||
const { version } = await xrp.getAppConfiguration() |
|||
return { version } |
|||
} |
Loading…
Reference in new issue