diff --git a/src/commands/index.js b/src/commands/index.js index 4700692c..c8b06136 100644 --- a/src/commands/index.js +++ b/src/commands/index.js @@ -25,6 +25,7 @@ import listApps from 'commands/listApps' import listAppVersions from 'commands/listAppVersions' import listCategories from 'commands/listCategories' import listenDevices from 'commands/listenDevices' +import ping from 'commands/ping' import signTransaction from 'commands/signTransaction' import testApdu from 'commands/testApdu' import testCrash from 'commands/testCrash' @@ -54,6 +55,7 @@ const all: Array> = [ listAppVersions, listCategories, listenDevices, + ping, signTransaction, testApdu, testCrash, diff --git a/src/commands/ping.js b/src/commands/ping.js new file mode 100644 index 00000000..a034967c --- /dev/null +++ b/src/commands/ping.js @@ -0,0 +1,15 @@ +// @flow + +// This is a test example for dev testing purpose. + +import { Observable } from 'rxjs' +import { createCommand, Command } from 'helpers/ipc' + +const cmd: Command = createCommand('ping', () => + Observable.create(o => { + o.next('pong') + o.complete() + }), +) + +export default cmd diff --git a/src/components/EnsureDevice.js b/src/components/EnsureDevice.js deleted file mode 100644 index bf0a5f6d..00000000 --- a/src/components/EnsureDevice.js +++ /dev/null @@ -1,45 +0,0 @@ -// @flow -/* eslint-disable react/no-multi-comp */ - -import { Component, PureComponent } from 'react' -import { connect } from 'react-redux' - -import type { Node } from 'react' -import type { Device } from 'types/common' - -import { getCurrentDevice } from 'reducers/devices' - -type Props = { - device: Device, - children: (device: Device) => Node, -} - -let prevents = 0 -export class PreventDeviceChangeRecheck extends PureComponent<{}> { - componentDidMount() { - prevents++ - } - componentWillUnmount() { - prevents-- - } - render() { - return null - } -} - -class EnsureDevice extends Component { - shouldComponentUpdate(nextProps) { - if (prevents > 0) return false - return nextProps.device !== this.props.device - } - render() { - const { device, children } = this.props - return children(device) - } -} - -const mapStateToProps = state => ({ - device: getCurrentDevice(state), -}) - -export default connect(mapStateToProps)(EnsureDevice) diff --git a/src/components/ManagerPage/FirmwareUpdate.js b/src/components/ManagerPage/FirmwareUpdate.js index a10ebf6d..a83d8a09 100644 --- a/src/components/ManagerPage/FirmwareUpdate.js +++ b/src/components/ManagerPage/FirmwareUpdate.js @@ -27,7 +27,6 @@ import Text from 'components/base/Text' import NanoS from 'icons/device/NanoS' import CheckFull from 'icons/CheckFull' -import { PreventDeviceChangeRecheck } from 'components/EnsureDevice' import UpdateFirmwareButton from './UpdateFirmwareButton' export const getCleanVersion = (input: string): string => @@ -143,7 +142,6 @@ class FirmwareUpdate extends PureComponent { - {modal !== 'closed' ? : null} {latestFirmware && ( { state = { @@ -37,18 +42,13 @@ class Debug extends Component<*, *> { const currency = getCryptoCurrencyById('bitcoin') const derivation = last(getDerivations(currency)) for (let x = 0; x < 20; x++) { - const obj = { - path: derivation({ currency, segwit: true, x }), - currencyId: currency.id, - devicePath: device.path, - } - - // we start one in parallel just to stress device even more. this test race condition! - getAddress.send(obj) - getAddress.send(obj) - - const { address, path } = await getAddress.send(obj).toPromise() - + const { address, path } = await getAddress + .send({ + path: derivation({ currency, segwit: true, x }), + currencyId: currency.id, + devicePath: device.path, + }) + .toPromise() this.log(`derivated ${path} = ${address}`) } } catch (e) { @@ -72,6 +72,38 @@ class Debug extends Component<*, *> { .subscribe(o => this.log(o.responseHex), e => this.error(e)) } + benchmark = (device: *) => async () => { + const run = async (name, job) => { + const before = window.performance.now() + const res = await job() + const after = window.performance.now() + this.log( + `benchmark: ${Math.round((after - before) * 100) / 100}ms: ${name} => ${String(res)}`, + ) + } + + await run('ping process', () => ping.send().toPromise()) + await run('libcore version', () => + libcoreGetVersion + .send() + .toPromise() + .then(o => o.stringVersion), + ) + const currency = getCryptoCurrencyById('bitcoin') + const derivation = last(getDerivations(currency)) + const obj = { + path: derivation({ currency, segwit: true, x: 0 }), + currencyId: currency.id, + devicePath: device.path, + } + await run('getAddress', () => + getAddress + .send(obj) + .toPromise() + .then(o => o.address), + ) + } + log = (txt: string) => { this.setState(({ logs }) => ({ logs: logs.concat({ txt, type: 'log' }) })) } @@ -83,6 +115,7 @@ class Debug extends Component<*, *> { } render() { + const { device } = this.props const { logs } = this.state return ( { onHide={this.onHide} render={({ onClose }: *) => ( + developer internal tools - - - {device => ( - - )} - - + {device && ( + + + + )} + {device && ( + + + + )} - - {device => ( - - - this.setState({ apdu })} - /> - - - - )} - + device && ( + + + this.setState({ apdu })} + /> + + + + ) { } } -export default Debug +export default connect( + createStructuredSelector({ + device: getCurrentDevice, + }), +)(Debug)