Browse Source

add mcu flash call

master
Valentin D. Pinkman 7 years ago
parent
commit
0d68f8a7ab
No known key found for this signature in database GPG Key ID: E7D110669FFB8D3E
  1. 24
      src/commands/installMcu.js
  2. 48
      src/components/ManagerPage/FlashMcu.js
  3. 7
      src/components/ManagerPage/index.js
  4. 63
      src/components/Workflow/index.js
  5. 17
      src/helpers/firmware/installMcu.js

24
src/commands/installMcu.js

@ -3,24 +3,20 @@
import { createCommand, Command } from 'helpers/ipc'
import { fromPromise } from 'rxjs/observable/fromPromise'
// import { withDevice } from 'helpers/deviceAccess'
import { withDevice } from 'helpers/deviceAccess'
import installMcu from 'helpers/firmware/installMcu'
// type Input = {
// devicePath: string,
// firmware: Object,
// }
type Input = {
devicePath: string,
targetId: string | number,
}
// type Result = {
// targetId: number | string,
// version: string,
// final: boolean,
// mcu: boolean,
// }
type Input = *
type Result = *
const cmd: Command<Input, Result> = createCommand('installMcu', () => fromPromise(installMcu()))
const cmd: Command<Input, Result> = createCommand('installMcu', ({ devicePath, targetId }) =>
fromPromise(
withDevice(devicePath)(transport => installMcu(transport, { targetId, version: '1.5' })),
),
)
export default cmd

48
src/components/ManagerPage/FlashMcu.js

@ -0,0 +1,48 @@
// @flow
import React, { PureComponent } from 'react'
import type { Device } from 'types/common'
import installMcu from 'commands/installMcu'
type DeviceInfo = {
targetId: number | string,
version: string,
final: boolean,
mcu: boolean,
}
type Props = {
device: Device,
deviceInfo: DeviceInfo,
}
type State = {
flashing: boolean,
}
class FlashMcu extends PureComponent<Props, State> {
state = {
flashing: false,
}
componentDidMount() {
this.flasMCU()
}
flasMCU = async () => {
const { device, deviceInfo } = this.props
const { flashing } = this.state
if (!flashing) {
this.setState(state => ({ ...state, flashing: true }))
await installMcu.send({ devicePath: device.path, targetId: deviceInfo.targetId }).toPromise()
this.setState(state => ({ ...state, flashing: false }))
}
}
render() {
return <div>Flashing MCU</div>
}
}
export default FlashMcu

7
src/components/ManagerPage/index.js

@ -9,6 +9,7 @@ import type { Device } from 'types/common'
import Workflow from 'components/Workflow'
import WorkflowWithIcon from 'components/Workflow/WorkflowWithIcon'
import Dashboard from './Dashboard'
import FlashMcu from './FlashMcu'
type DeviceInfo = {
targetId: number | string,
@ -25,11 +26,11 @@ type Error = {
function ManagerPage(): Node {
return (
<Workflow
renderFinalUpdate={(deviceInfo: DeviceInfo) => (
renderFinalUpdate={(device: Device, deviceInfo: DeviceInfo) => (
<p>UPDATE FINAL FIRMARE (TEMPLATE + ACTION WIP) {deviceInfo.final}</p>
)}
renderMcuUpdate={(deviceInfo: DeviceInfo) => (
<p>FLASH MCU (TEMPLATE + ACTION WIP) {deviceInfo.mcu}</p>
renderMcuUpdate={(device: Device, deviceInfo: DeviceInfo) => (
<FlashMcu device={device} deviceInfo={deviceInfo} />
)}
renderDashboard={(device: Device, deviceInfo: DeviceInfo) => (
<Dashboard device={device} deviceInfo={deviceInfo} />

63
src/components/Workflow/index.js

@ -31,8 +31,8 @@ type Props = {
genuineError: ?Error,
},
) => Node,
renderMcuUpdate?: (deviceInfo: DeviceInfo) => Node,
renderFinalUpdate?: (deviceInfo: DeviceInfo) => Node,
renderMcuUpdate?: (device: Device, deviceInfo: DeviceInfo) => Node,
renderFinalUpdate?: (device: Device, deviceInfo: DeviceInfo) => Node,
renderDashboard?: (device: Device, deviceInfo: DeviceInfo, isGenuine: boolean) => Node,
renderError?: (dashboardError: ?Error, genuineError: ?Error) => Node,
}
@ -52,37 +52,42 @@ class Workflow extends PureComponent<Props, State> {
<EnsureDevice>
{(device: Device) => (
<EnsureDashboard device={device}>
{(deviceInfo: ?DeviceInfo, dashboardError: ?Error) => (
<EnsureGenuine device={device} infos={deviceInfo}>
{(isGenuine: ?boolean, genuineError: ?Error) => {
if (dashboardError || genuineError) {
return renderError
? renderError(dashboardError, genuineError)
: renderDefault(device, deviceInfo, isGenuine, {
genuineError,
dashboardError,
})
}
{(deviceInfo: ?DeviceInfo, dashboardError: ?Error) => {
if (deviceInfo && deviceInfo.mcu && renderMcuUpdate) {
return renderMcuUpdate(deviceInfo)
}
if (deviceInfo && deviceInfo.mcu && renderMcuUpdate) {
return renderMcuUpdate(device, deviceInfo)
}
if (deviceInfo && deviceInfo.final && renderFinalUpdate) {
return renderFinalUpdate(deviceInfo)
}
if (deviceInfo && deviceInfo.final && renderFinalUpdate) {
return renderFinalUpdate(device, deviceInfo)
}
if (isGenuine && deviceInfo && device && !dashboardError && !genuineError) {
if (renderDashboard) return renderDashboard(device, deviceInfo, isGenuine)
}
return (
<EnsureGenuine device={device} infos={deviceInfo}>
{(isGenuine: ?boolean, genuineError: ?Error) => {
if (dashboardError || genuineError) {
return renderError
? renderError(dashboardError, genuineError)
: renderDefault(device, deviceInfo, isGenuine, {
genuineError,
dashboardError,
})
}
return renderDefault(device, deviceInfo, isGenuine, {
genuineError,
dashboardError,
})
}}
</EnsureGenuine>
)}
if (isGenuine && deviceInfo && device && !dashboardError && !genuineError) {
if (onGenuineCheck) onGenuineCheck(isGenuine)
if (renderDashboard) return renderDashboard(device, deviceInfo, isGenuine)
}
return renderDefault(device, deviceInfo, isGenuine, {
genuineError,
dashboardError,
})
}}
</EnsureGenuine>
)
}}
</EnsureDashboard>
)}
</EnsureDevice>

17
src/helpers/firmware/installMcu.js

@ -1,8 +1,15 @@
// @flow
import type Transport from '@ledgerhq/hw-transport'
import qs from 'qs'
import { MANAGER_API_URL } from 'helpers/constants'
import { createDeviceSocket } from 'helpers/socket'
type Result = Promise<boolean>
type Result = Promise<*>
// TODO: IMPLEMENTATION FOR FLASHING FIRMWARE
// GETTING APDUS FROM SERVER
// SEND THE APDUS TO DEVICE
export default async (): Result => new Promise(resolve => resolve(true))
export default async (
transport: Transport<*>,
params: { targetId: string | number, version: string },
): Result => {
const url = `${MANAGER_API_URL}/mcu?${qs.stringify(params)}`
return createDeviceSocket(transport, url).toPromise()
}

Loading…
Cancel
Save