Browse Source

add testApdu tool

master
Gaëtan Renaudeau 7 years ago
parent
commit
ddad19f4f5
  1. 2
      src/commands/index.js
  2. 26
      src/commands/testApdu.js
  3. 25
      src/components/modals/Debug.js

2
src/commands/index.js

@ -18,6 +18,7 @@ import installOsuFirmware from 'commands/installOsuFirmware'
import installFinalFirmware from 'commands/installFinalFirmware'
import installMcu from 'commands/installMcu'
import listApps from 'commands/listApps'
import testApdu from 'commands/testApdu'
import testInterval from 'commands/testInterval'
import testCrash from 'commands/testCrash'
@ -38,6 +39,7 @@ const all: Array<Command<any, any>> = [
installFinalFirmware,
installMcu,
listApps,
testApdu,
testInterval,
testCrash,
]

26
src/commands/testApdu.js

@ -0,0 +1,26 @@
// @flow
// This is a test example for dev testing purpose.
import { createCommand, Command } from 'helpers/ipc'
import { fromPromise } from 'rxjs/observable/fromPromise'
import { withDevice } from 'helpers/deviceAccess'
type Input = {
devicePath: string,
apduHex: string,
}
type Result = {
responseHex: string,
}
const cmd: Command<Input, Result> = createCommand('testApdu', ({ apduHex, devicePath }) =>
fromPromise(
withDevice(devicePath)(async transport => {
const res = await transport.exchange(Buffer.from(apduHex, 'hex'))
return { responseHex: res.toString('hex') }
}),
),
)
export default cmd

25
src/components/modals/Debug.js

@ -5,15 +5,18 @@ import React, { Component } from 'react'
import Modal, { ModalBody, ModalTitle, ModalContent } from 'components/base/Modal'
import Button from 'components/base/Button'
import Box from 'components/base/Box'
import Input from 'components/base/Input'
import EnsureDevice from 'components/ManagerPage/EnsureDevice'
import { getDerivations } from 'helpers/derivations'
import getAddress from 'commands/getAddress'
import testInterval from 'commands/testInterval'
import testCrash from 'commands/testCrash'
import testApdu from 'commands/testApdu'
class Debug extends Component<*, *> {
state = {
logs: [],
apdu: '',
}
onStartPeriod = (period: number) => () => {
@ -62,6 +65,12 @@ class Debug extends Component<*, *> {
}
periodSubs = []
runApdu = (device: *) => () => {
testApdu
.send({ devicePath: device.path, apduHex: this.state.apdu })
.subscribe(o => this.log(o.responseHex), e => this.error(e))
}
log = (txt: string) => {
this.setState(({ logs }) => ({ logs: logs.concat({ txt, type: 'log' }) }))
}
@ -103,6 +112,22 @@ class Debug extends Component<*, *> {
</Button>
<Button onClick={this.cancelAllPeriods}>Cancel</Button>
</Box>
<EnsureDevice>
{device => (
<Box horizontal style={{ padding: 10 }}>
<Box grow>
<Input
placeholder="APDU hex ( e.g. E016000000 )"
value={this.state.apdu}
onChange={apdu => this.setState({ apdu })}
/>
</Box>
<Button onClick={this.runApdu(device)} primary>
RUN
</Button>
</Box>
)}
</EnsureDevice>
</Box>
<Box
style={{

Loading…
Cancel
Save