Browse Source

refactor firmware update

master
amougel 7 years ago
parent
commit
0576e1ce8c
  1. 8
      src/commands/installFinalFirmware.js
  2. 12
      src/components/ManagerPage/FirmwareFinalUpdate.js
  3. 2
      src/helpers/devices/getOsuFirmware.js
  4. 14
      src/helpers/firmware/installFinalFirmware.js

8
src/commands/installFinalFirmware.js

@ -3,13 +3,13 @@
import { createCommand, Command } from 'helpers/ipc'
import { fromPromise } from 'rxjs/observable/fromPromise'
import { withDevice } from 'helpers/deviceAccess'
import type { DeviceInfo } from 'helpers/devices/getDeviceInfo'
import installFinalFirmware from 'helpers/firmware/installFinalFirmware'
type Input = {
devicePath: string,
targetId: string | number,
version: string,
deviceInfo: DeviceInfo,
}
type Result = {
@ -18,8 +18,8 @@ type Result = {
const cmd: Command<Input, Result> = createCommand(
'installFinalFirmware',
({ devicePath, ...rest }) =>
fromPromise(withDevice(devicePath)(transport => installFinalFirmware(transport, { ...rest }))),
({ devicePath, deviceInfo }) =>
fromPromise(withDevice(devicePath)(transport => installFinalFirmware(transport, deviceInfo))),
)
export default cmd

12
src/components/ManagerPage/FirmwareFinalUpdate.js

@ -3,6 +3,7 @@
import React, { PureComponent } from 'react'
import { translate } from 'react-i18next'
import logger from 'logger'
import type { DeviceInfo } from 'helpers/devices/getDeviceInfo'
import type { Device, T } from 'types/common'
@ -11,15 +12,10 @@ import installFinalFirmware from 'commands/installFinalFirmware'
import Box, { Card } from 'components/base/Box'
// import Button from 'components/base/Button'
type DeviceInfos = {
targetId: number,
version: string,
}
type Props = {
t: T,
device: Device,
infos: DeviceInfos,
deviceInfo: DeviceInfo,
}
type State = {}
@ -35,9 +31,9 @@ class FirmwareFinalUpdate extends PureComponent<Props, State> {
installFinalFirmware = async () => {
try {
const { device, infos } = this.props
const { device, deviceInfo } = this.props
const { success } = await installFinalFirmware
.send({ devicePath: device.path, targetId: infos.targetId, version: infos.version })
.send({ devicePath: device.path, deviceInfo })
.toPromise()
if (success) {
this.setState()

2
src/helpers/devices/getOsuFirmware.js

@ -15,7 +15,7 @@ export default async (input: Input): Promise<*> => {
url: GET_CURRENT_OSU,
data: {
device_version: input.deviceId,
version_name: input.version,
version_name: `${input.version}-osu`,
provider,
},
})

14
src/helpers/firmware/installFinalFirmware.js

@ -1,5 +1,6 @@
// @flow
import type Transport from '@ledgerhq/hw-transport'
import type { DeviceInfo } from 'helpers/devices/getDeviceInfo'
import { WS_INSTALL } from 'helpers/urls'
import { createDeviceSocket } from 'helpers/socket'
@ -7,22 +8,17 @@ import getDeviceVersion from 'helpers/devices/getDeviceVersion'
import getOsuFirmware from 'helpers/devices/getOsuFirmware'
import getFinalFirmwareById from './getFinalFirmwareById'
type Input = {
targetId: number | string,
version: string,
}
type Result = *
export default async (transport: Transport<*>, app: Input): Result => {
export default async (transport: Transport<*>, deviceInfo: DeviceInfo): Result => {
try {
const { targetId, version } = app
const device = await getDeviceVersion(targetId)
const firmware = await getOsuFirmware({ deviceId: device.id, version })
const device = await getDeviceVersion(deviceInfo.targetId, deviceInfo.providerId)
const firmware = await getOsuFirmware({ deviceId: device.id, version: deviceInfo.fullVersion })
const { next_se_firmware_final_version } = firmware
const nextFirmware = await getFinalFirmwareById(next_se_firmware_final_version)
const params = {
targetId,
targetId: deviceInfo.targetId,
...nextFirmware,
firmwareKey: nextFirmware.firmware_key,
}

Loading…
Cancel
Save