Browse Source

Refine the FU calls

gre-patch-1
Gaëtan Renaudeau 6 years ago
parent
commit
a9115825fb
No known key found for this signature in database GPG Key ID: 7B66B85F042E5451
  1. 2
      package.json
  2. 2
      src/commands/firmwareMain.js
  3. 8
      src/commands/firmwarePrepare.js
  4. 2
      src/commands/firmwareRepair.js
  5. 4
      src/commands/index.js
  6. 39
      src/components/SettingsPage/RepairDeviceButton.js
  7. 4
      src/components/modals/UpdateFirmware/steps/01-step-install-full-firmware.js
  8. 35
      src/components/modals/UpdateFirmware/steps/02-step-flash-mcu.js
  9. 8
      yarn.lock

2
package.json

@ -41,7 +41,7 @@
"@ledgerhq/hw-transport": "^4.32.0",
"@ledgerhq/hw-transport-node-hid": "^4.32.0",
"@ledgerhq/ledger-core": "2.0.0-rc.14",
"@ledgerhq/live-common": "4.8.0-beta.12",
"@ledgerhq/live-common": "4.8.0-beta.13",
"animated": "^0.2.2",
"async": "^2.6.1",
"axios": "^0.18.0",

2
src/commands/firmwareMain.js

@ -8,7 +8,7 @@ type Input = {
finalFirmware: FinalFirmware,
}
type Result = *
type Result = { progress: number, installing: ?string }
const cmd: Command<Input, Result> = createCommand(
'firmwareMain',

8
src/commands/firmwareCheckId.js → src/commands/firmwarePrepare.js

@ -1,6 +1,6 @@
// @flow
import checkId from '@ledgerhq/live-common/lib/hw/firmwareUpdate-checkId'
import prepare from '@ledgerhq/live-common/lib/hw/firmwareUpdate-prepare'
import type { OsuFirmware } from '@ledgerhq/live-common/lib/types/manager'
import { createCommand, Command } from 'helpers/ipc'
@ -9,11 +9,11 @@ type Input = {
osuFirmware: OsuFirmware,
}
type Result = *
type Result = { progress: number }
const cmd: Command<Input, Result> = createCommand(
'firmwareCheckId',
({ devicePath, osuFirmware }) => checkId(devicePath, osuFirmware),
'firmwarePrepare',
({ devicePath, osuFirmware }) => prepare(devicePath, osuFirmware),
)
export default cmd

2
src/commands/firmwareRepair.js

@ -4,7 +4,7 @@ import repair from '@ledgerhq/live-common/lib/hw/firmwareUpdate-repair'
import { createCommand, Command } from 'helpers/ipc'
type Input = void
type Result = *
type Result = { progress: number }
const cmd: Command<Input, Result> = createCommand(
'firmwareRepair',

4
src/commands/index.js

@ -4,7 +4,7 @@ import invariant from 'invariant'
import type { Command } from 'helpers/ipc'
import debugAppInfosForCurrency from 'commands/debugAppInfosForCurrency'
import firmwareCheckId from 'commands/firmwareCheckId'
import firmwarePrepare from 'commands/firmwarePrepare'
import firmwareMain from 'commands/firmwareMain'
import firmwareRepair from 'commands/firmwareRepair'
import getAddress from 'commands/getAddress'
@ -30,7 +30,7 @@ import uninstallApp from 'commands/uninstallApp'
const all: Array<Command<any, any>> = [
debugAppInfosForCurrency,
firmwareCheckId,
firmwarePrepare,
firmwareMain,
firmwareRepair,
getAddress,

39
src/components/SettingsPage/RepairDeviceButton.js

@ -16,13 +16,15 @@ type State = {
opened: boolean,
isLoading: boolean,
error: ?Error,
progress: number,
}
class CleanButton extends PureComponent<Props, State> {
class RepairDeviceButton extends PureComponent<Props, State> {
state = {
opened: false,
isLoading: false,
error: null,
progress: 0,
}
open = () => this.setState({ opened: true })
@ -37,32 +39,25 @@ class CleanButton extends PureComponent<Props, State> {
action = () => {
if (this.state.isLoading) return
this.setState({ isLoading: true })
this.sub = firmwareRepair
.send()
.pipe(
tap(e => console.log(e)), // eslint-disable-line no-console
// ^ TODO remove at the end
filter(e => e.type === 'bulk-progress'),
)
.subscribe({
next: () => {
// TODO cc @val
},
error: error => {
this.setState({ error, opened: false, isLoading: false })
},
complete: () => {
this.setState({ opened: false, isLoading: false })
},
})
this.sub = firmwareRepair.send().subscribe({
next: patch => {
this.setState(patch)
},
error: error => {
this.setState({ error, opened: false, isLoading: false })
},
complete: () => {
this.setState({ opened: false, isLoading: false })
},
})
}
render() {
const { t } = this.props
const { opened, isLoading, error } = this.state
const { opened, isLoading, error, progress } = this.state
// @val basically I think we want to diverge from the traditional ConfirmModal to make our own version
// with the progress and the error cases handled.
console.log({ error }) // eslint-disable-line no-console
console.log({ error, progress }) // eslint-disable-line no-console
// ^ TODO use error to pass in that custom thing
return (
<Fragment>
@ -87,4 +82,4 @@ class CleanButton extends PureComponent<Props, State> {
}
}
export default translate()(CleanButton)
export default translate()(RepairDeviceButton)

4
src/components/modals/UpdateFirmware/steps/01-step-install-full-firmware.js

@ -4,7 +4,7 @@ import React, { PureComponent, Fragment } from 'react'
import styled from 'styled-components'
import { connect } from 'react-redux'
import firmwareCheckId from 'commands/firmwareCheckId'
import firmwarePrepare from 'commands/firmwarePrepare'
import { getCurrentDevice } from 'reducers/devices'
import TrackPage from 'analytics/TrackPage'
import Box from 'components/base/Box'
@ -56,7 +56,7 @@ class StepFullFirmwareInstall extends PureComponent<Props> {
return
}
this.sub = firmwareCheckId
this.sub = firmwarePrepare
.send({
devicePath: device.path,
osuFirmware: osu,

35
src/components/modals/UpdateFirmware/steps/02-step-flash-mcu.js

@ -56,29 +56,18 @@ class StepFlashMcu extends PureComponent<Props, State> {
componentDidMount() {
const { final: finalFirmware, transitionTo, setError } = this.props
this.sub = firmwareMain
.send({ finalFirmware })
.pipe(
tap(e => console.log(e)), // eslint-disable-line no-console
// ^ TODO remove at the end
filter(e => e.type === 'bulk-progress' || e.type === 'install'),
)
.subscribe({
next: e => {
if (e.type === 'install') {
this.setState({ installing: e.step, progress: 0 })
} else {
this.setState({ progress: e.progress })
}
},
complete: () => {
transitionTo('finish')
},
error: error => {
setError(error)
transitionTo('finish')
},
})
this.sub = firmwareMain.send({ finalFirmware }).subscribe({
next: patch => {
this.setState(patch)
},
complete: () => {
transitionTo('finish')
},
error: error => {
setError(error)
transitionTo('finish')
},
})
}
componentWillUnmount() {

8
yarn.lock

@ -1725,10 +1725,10 @@
bindings "^1.3.0"
nan "^2.6.2"
"@ledgerhq/live-common@4.8.0-beta.12":
version "4.8.0-beta.12"
resolved "https://registry.yarnpkg.com/@ledgerhq/live-common/-/live-common-4.8.0-beta.12.tgz#4319aa397896f242d753ea63ff7ac4223788eb88"
integrity sha512-J2gaXqQkDuqZl2SgjNE7ZOSX0nMl9xqHu5jwHqiyBSlXvykdXWMmaPLcBcP8F+xszpKCIB0N6XaJFUAHHbD0Nw==
"@ledgerhq/live-common@4.8.0-beta.13":
version "4.8.0-beta.13"
resolved "https://registry.yarnpkg.com/@ledgerhq/live-common/-/live-common-4.8.0-beta.13.tgz#64ecb2a8a8845f92519dfb9552623a42a9e3824e"
integrity sha512-Y66m+3q/6L8CAFUPXjlpS8jPE2168Y/X8JMC05voFKTC2U3Y1RGaRd/nEBA53Z2BFrbwZ2yIViylew4nFvH2Sg==
dependencies:
"@aeternity/ledger-app-api" "0.0.4"
"@ledgerhq/hw-app-btc" "^4.32.0"

Loading…
Cancel
Save