Browse Source

plugged update actions to modals

master
Valentin D. Pinkman 7 years ago
parent
commit
c259edd23b
No known key found for this signature in database GPG Key ID: E7D110669FFB8D3E
  1. 8
      src/commands/installFinalFirmware.js
  2. 8
      src/commands/installMcu.js
  3. 2
      src/commands/installOsuFirmware.js
  4. 67
      src/components/ManagerPage/FirmwareFinalUpdate.js
  5. 64
      src/components/ManagerPage/FirmwareUpdate.js
  6. 50
      src/components/ManagerPage/FlashMcu.js
  7. 6
      src/components/ManagerPage/UpdateFirmwareButton.js
  8. 4
      src/components/ManagerPage/index.js
  9. 2
      src/components/modals/ReleaseNotes.js
  10. 12
      src/components/modals/UpdateFirmware/Disclaimer.js
  11. 97
      src/components/modals/UpdateFirmware/index.js
  12. 80
      src/components/modals/UpdateFirmware/steps/01-step-install-full-firmware.js
  13. 57
      src/components/modals/UpdateFirmware/steps/01-step-osu-installer.js
  14. 149
      src/components/modals/UpdateFirmware/steps/02-step-flash-mcu.js
  15. 21
      src/helpers/devices/getLatestFirmwareForDevice.js
  16. 19
      src/helpers/firmware/getMcus.js
  17. 0
      src/helpers/firmware/getNextMCU.js
  18. 6
      src/helpers/firmware/installFinalFirmware.js
  19. 12
      src/helpers/firmware/installMcu.js
  20. 24
      src/helpers/firmware/installOsuFirmware.js
  21. 1
      src/helpers/urls.js
  22. BIN
      static/images/logos/bootloaderMode.png
  23. BIN
      static/images/logos/unplugDevice.png

8
src/commands/installFinalFirmware.js

@ -3,23 +3,19 @@
import { createCommand, Command } from 'helpers/ipc' import { createCommand, Command } from 'helpers/ipc'
import { fromPromise } from 'rxjs/observable/fromPromise' import { fromPromise } from 'rxjs/observable/fromPromise'
import { withDevice } from 'helpers/deviceAccess' import { withDevice } from 'helpers/deviceAccess'
import type { DeviceInfo } from 'helpers/devices/getDeviceInfo'
import installFinalFirmware from 'helpers/firmware/installFinalFirmware' import installFinalFirmware from 'helpers/firmware/installFinalFirmware'
type Input = { type Input = {
devicePath: string, devicePath: string,
deviceInfo: DeviceInfo,
} }
type Result = { type Result = {
success: boolean, success: boolean,
} }
const cmd: Command<Input, Result> = createCommand( const cmd: Command<Input, Result> = createCommand('installFinalFirmware', ({ devicePath }) =>
'installFinalFirmware', fromPromise(withDevice(devicePath)(transport => installFinalFirmware(transport))),
({ devicePath, deviceInfo }) =>
fromPromise(withDevice(devicePath)(transport => installFinalFirmware(transport, deviceInfo))),
) )
export default cmd export default cmd

8
src/commands/installMcu.js

@ -8,16 +8,12 @@ import installMcu from 'helpers/firmware/installMcu'
type Input = { type Input = {
devicePath: string, devicePath: string,
targetId: string | number,
version: string,
} }
type Result = * type Result = *
const cmd: Command<Input, Result> = createCommand( const cmd: Command<Input, Result> = createCommand('installMcu', ({ devicePath }) =>
'installMcu', fromPromise(withDevice(devicePath)(transport => installMcu(transport))),
({ devicePath, targetId, version }) =>
fromPromise(withDevice(devicePath)(transport => installMcu(transport, { targetId, version }))),
) )
export default cmd export default cmd

2
src/commands/installOsuFirmware.js

@ -11,7 +11,7 @@ import type { LedgerScriptParams } from 'helpers/common'
type Input = { type Input = {
devicePath: string, devicePath: string,
targetId: string | number, targetId: string | number,
firmware: LedgerScriptParams, firmware: LedgerScriptParams & { shouldUpdateMcu: boolean },
} }
type Result = * type Result = *

67
src/components/ManagerPage/FirmwareFinalUpdate.js

@ -1,67 +0,0 @@
// @flow
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'
import installFinalFirmware from 'commands/installFinalFirmware'
import Box, { Card } from 'components/base/Box'
import Button from 'components/base/Button'
type Props = {
t: T,
device: Device,
deviceInfo: DeviceInfo,
}
type State = {}
class FirmwareFinalUpdate extends PureComponent<Props, State> {
componentDidMount() {}
componentWillUnmount() {
this._unmounting = true
}
_unmounting = false
installFinalFirmware = async () => {
try {
const { device, deviceInfo } = this.props
const { success } = await installFinalFirmware
.send({
devicePath: device.path,
deviceInfo,
})
.toPromise()
if (success) {
this.setState()
}
} catch (err) {
logger.log(err)
}
}
render() {
const { t, ...props } = this.props
return (
<Box flow={4} {...props}>
<Box color="dark" ff="Museo Sans" fontSize={6}>
{t('app:manager.firmware.update')}
</Box>
<Card flow={2} {...props}>
<Box horizontal align="center" flow={2}>
<Button onClick={this.installFinalFirmware}>Install Final Firmware</Button>
</Box>
</Card>
</Box>
)
}
}
export default translate()(FirmwareFinalUpdate)

64
src/components/ManagerPage/FirmwareUpdate.js

@ -1,7 +1,7 @@
// @flow // @flow
/* eslint-disable react/jsx-no-literals */ // FIXME /* eslint-disable react/jsx-no-literals */ // FIXME
import React, { PureComponent } from 'react' import React, { PureComponent, Fragment } from 'react'
import { translate } from 'react-i18next' import { translate } from 'react-i18next'
import isEqual from 'lodash/isEqual' import isEqual from 'lodash/isEqual'
import isEmpty from 'lodash/isEmpty' import isEmpty from 'lodash/isEmpty'
@ -14,6 +14,8 @@ import type { LedgerScriptParams } from 'helpers/common'
import getLatestFirmwareForDevice from 'commands/getLatestFirmwareForDevice' import getLatestFirmwareForDevice from 'commands/getLatestFirmwareForDevice'
import installOsuFirmware from 'commands/installOsuFirmware' import installOsuFirmware from 'commands/installOsuFirmware'
import installFinalFirmware from 'commands/installFinalFirmware'
import installMcu from 'commands/installMcu'
import DisclaimerModal from 'components/modals/UpdateFirmware/Disclaimer' import DisclaimerModal from 'components/modals/UpdateFirmware/Disclaimer'
import UpdateModal from 'components/modals/UpdateFirmware' import UpdateModal from 'components/modals/UpdateFirmware'
import type { DeviceInfo } from 'helpers/devices/getDeviceInfo' import type { DeviceInfo } from 'helpers/devices/getDeviceInfo'
@ -40,7 +42,7 @@ type Props = {
} }
type State = { type State = {
latestFirmware: ?LedgerScriptParams, latestFirmware: ?LedgerScriptParams & ?{ shouldUpdateMcu: boolean },
modal: ModalStatus, modal: ModalStatus,
} }
@ -78,26 +80,42 @@ class FirmwareUpdate extends PureComponent<Props, State> {
} }
} }
installFirmware = async () => { installOsuFirmware = async () => {
try { try {
const { latestFirmware } = this.state const { latestFirmware } = this.state
const { deviceInfo } = this.props
invariant(latestFirmware, 'did not find a new firmware or firmware is not set')
const { const {
deviceInfo,
device: { path: devicePath }, device: { path: devicePath },
} = this.props } = this.props
invariant(latestFirmware, 'did not find a new firmware or firmware is not set')
this.setState({ modal: 'install' }) this.setState({ modal: 'install' })
const { success } = await installOsuFirmware const { success } = await installOsuFirmware
.send({ devicePath, firmware: latestFirmware, targetId: deviceInfo.targetId }) .send({ devicePath, firmware: latestFirmware, targetId: deviceInfo.targetId })
.toPromise() .toPromise()
if (success) { return success
this.fetchLatestFirmware()
}
} catch (err) { } catch (err) {
logger.log(err) logger.log(err)
throw err
} }
} }
installFinalFirmware = async () => {
try {
const { device } = this.props
const { success } = await installFinalFirmware.send({ devicePath: device.path }).toPromise()
return success
} catch (err) {
logger.log(err)
throw err
}
}
flashMCU = async () => {
const { device } = this.props
await installMcu.send({ devicePath: device.path }).toPromise()
}
handleCloseModal = () => this.setState({ modal: 'closed' }) handleCloseModal = () => this.setState({ modal: 'closed' })
handleDisclaimerModal = () => this.setState({ modal: 'disclaimer' }) handleDisclaimerModal = () => this.setState({ modal: 'disclaimer' })
@ -130,19 +148,27 @@ class FirmwareUpdate extends PureComponent<Props, State> {
})} })}
</Text> </Text>
</Box> </Box>
<UpdateFirmwareButton <UpdateFirmwareButton firmware={latestFirmware} onClick={this.handleDisclaimerModal} />
firmware={latestFirmware}
installFirmware={this.handleDisclaimerModal}
/>
</Box> </Box>
{modal !== 'closed' ? <PreventDeviceChangeRecheck /> : null} {modal !== 'closed' ? <PreventDeviceChangeRecheck /> : null}
<DisclaimerModal {latestFirmware && (
firmware={latestFirmware} <Fragment>
status={modal} <DisclaimerModal
goToNextStep={this.handleInstallModal} firmware={latestFirmware}
onClose={this.handleCloseModal} status={modal}
/> goToNextStep={this.handleInstallModal}
<UpdateModal status={modal} onClose={this.handleCloseModal} firmware={latestFirmware} /> onClose={this.handleCloseModal}
/>
<UpdateModal
status={modal}
onClose={this.handleCloseModal}
firmware={latestFirmware}
installOsuFirmware={this.installOsuFirmware}
installFinalFirmware={this.installFinalFirmware}
flashMCU={this.flashMCU}
/>
</Fragment>
)}
</Card> </Card>
) )
} }

50
src/components/ManagerPage/FlashMcu.js

@ -1,50 +0,0 @@
// @flow
import React, { PureComponent } from 'react'
import type { Device } from 'types/common'
import installMcu from 'commands/installMcu'
import type { DeviceInfo } from 'helpers/devices/getDeviceInfo'
type Props = {
device: Device,
deviceInfo: DeviceInfo,
}
type State = {
flashing: boolean,
}
class FlashMcu extends PureComponent<Props, State> {
state = {
flashing: false,
}
flashMCU = async () => {
const { device, deviceInfo } = this.props
const { flashing } = this.state
if (!flashing) {
this.setState({ flashing: true })
await installMcu
.send({
devicePath: device.path,
targetId: deviceInfo.targetId,
version: deviceInfo.seVersion,
})
.toPromise()
this.setState({ flashing: false })
}
}
render() {
return (
<div>
<h1>{'Flashing MCU'}</h1>
<button onClick={this.flashMCU}>{'flash'}</button>
</div>
)
}
}
export default FlashMcu

6
src/components/ManagerPage/UpdateFirmwareButton.js

@ -18,16 +18,16 @@ type FirmwareInfos = {
type Props = { type Props = {
t: T, t: T,
firmware: ?FirmwareInfos, firmware: ?FirmwareInfos,
installFirmware: () => void, onClick: () => void,
} }
const UpdateFirmwareButton = ({ t, firmware, installFirmware }: Props) => const UpdateFirmwareButton = ({ t, firmware, onClick }: Props) =>
firmware ? ( firmware ? (
<Fragment> <Fragment>
<Text ff="Open Sans|Regular" fontSize={4} style={{ marginLeft: 'auto', marginRight: 15 }}> <Text ff="Open Sans|Regular" fontSize={4} style={{ marginLeft: 'auto', marginRight: 15 }}>
{t('app:manager.firmware.latest', { version: getCleanVersion(firmware.name) })} {t('app:manager.firmware.latest', { version: getCleanVersion(firmware.name) })}
</Text> </Text>
<Button primary onClick={installFirmware}> <Button primary onClick={onClick}>
{t('app:manager.firmware.update')} {t('app:manager.firmware.update')}
</Button> </Button>
</Fragment> </Fragment>

4
src/components/ManagerPage/index.js

@ -40,10 +40,6 @@ class ManagerPage extends PureComponent<Props, State> {
invariant(device, 'Inexistant device considered genuine') invariant(device, 'Inexistant device considered genuine')
invariant(deviceInfo, 'Inexistant device infos for genuine device') invariant(deviceInfo, 'Inexistant device infos for genuine device')
// TODO
// renderFinalUpdate
// renderMcuUpdate
return <Dashboard device={device} deviceInfo={deviceInfo} /> return <Dashboard device={device} deviceInfo={deviceInfo} />
} }
} }

2
src/components/modals/ReleaseNotes.js

@ -25,7 +25,7 @@ type State = {
markdown: ?string, markdown: ?string,
} }
const Notes = styled(Box).attrs({ export const Notes = styled(Box).attrs({
ff: 'Open Sans', ff: 'Open Sans',
fontSize: 4, fontSize: 4,
color: 'smoke', color: 'smoke',

12
src/components/modals/UpdateFirmware/Disclaimer.js

@ -3,6 +3,7 @@
import React, { PureComponent, Fragment } from 'react' import React, { PureComponent, Fragment } from 'react'
import { translate, Trans } from 'react-i18next' import { translate, Trans } from 'react-i18next'
import ReactMarkdown from 'react-markdown'
import type { T } from 'types/common' import type { T } from 'types/common'
@ -11,11 +12,12 @@ import Text from 'components/base/Text'
import Button from 'components/base/Button' import Button from 'components/base/Button'
import GrowScroll from 'components/base/GrowScroll' import GrowScroll from 'components/base/GrowScroll'
import GradientBox from 'components/GradientBox' import GradientBox from 'components/GradientBox'
import { Notes } from 'components/modals/ReleaseNotes'
import { getCleanVersion } from 'components/ManagerPage/FirmwareUpdate'
import type { ModalStatus } from 'components/ManagerPage/FirmwareUpdate' import type { ModalStatus } from 'components/ManagerPage/FirmwareUpdate'
import { getCleanVersion } from 'components/ManagerPage/FirmwareUpdate'
type FirmwareInfos = { type FirmwareInfos = {
name: string, name: string,
notes: string, notes: string,
@ -58,9 +60,9 @@ class DisclaimerModal extends PureComponent<Props, State> {
</ModalContent> </ModalContent>
<ModalContent style={{ height: 250, width: '100%' }}> <ModalContent style={{ height: 250, width: '100%' }}>
<GrowScroll> <GrowScroll>
<Text ff="Open Sans|Regular" fontSize={4} color="graphite"> <Notes>
{firmware.notes} <ReactMarkdown>{firmware.notes}</ReactMarkdown>
</Text> </Notes>
</GrowScroll> </GrowScroll>
<GradientBox /> <GradientBox />
</ModalContent> </ModalContent>

97
src/components/modals/UpdateFirmware/index.js

@ -14,18 +14,20 @@ import type { ModalStatus } from 'components/ManagerPage/FirmwareUpdate'
import type { LedgerScriptParams } from 'helpers/common' import type { LedgerScriptParams } from 'helpers/common'
import StepOSUInstaller from './steps/01-step-osu-installer' import StepOSUInstaller from './steps/01-step-osu-installer'
import StepFullFirmwareInstall from './steps/01-step-install-full-firmware'
import StepFlashMcu from './steps/02-step-flash-mcu' import StepFlashMcu from './steps/02-step-flash-mcu'
import StepConfirmation, { StepConfirmFooter } from './steps/03-step-confirmation' import StepConfirmation, { StepConfirmFooter } from './steps/03-step-confirmation'
export type StepProps = DefaultStepProps & { export type StepProps = DefaultStepProps & {
firmware: ?LedgerScriptParams, firmware: ?LedgerScriptParams,
onCloseModal: () => void, onCloseModal: () => void,
installOsuFirmware: () => void,
installFinalFirmware: () => void,
flashMcu: () => void,
} }
type StepId = 'idCheck' | 'updateMCU' | 'finish' type StepId = 'idCheck' | 'updateMCU' | 'finish'
// FIXME: Debugging for now to move between steps
// Remove when plugged to firmware update
function DebugFooter({ function DebugFooter({
transitionTo, transitionTo,
where, where,
@ -36,45 +38,74 @@ function DebugFooter({
return <Button onClick={() => transitionTo(where)}>{where}</Button> return <Button onClick={() => transitionTo(where)}>{where}</Button>
} }
const createSteps = ({ t }: { t: T }) => [ const createSteps = ({
{ t,
id: 'idCheck', firmware,
label: t('app:manager.modal.steps.idCheck'), }: {
component: StepOSUInstaller, t: T,
footer: ({ firmware, ...props }: StepProps) => ( firmware: LedgerScriptParams & { shouldUpdateMcu: boolean },
<DebugFooter firmware={firmware} {...props} where="updateMCU" /> }): Array<*> => {
), const finalStep = {
onBack: null,
hideFooter: false,
},
{
id: 'updateMCU',
label: t('app:manager.modal.steps.updateMCU'),
component: StepFlashMcu,
footer: ({ firmware, ...props }: StepProps) => (
<Fragment>
<DebugFooter firmware={firmware} {...props} where="idCheck" />
<DebugFooter firmware={firmware} {...props} where="finish" />
</Fragment>
),
onBack: null,
hideFooter: false,
},
{
id: 'finish', id: 'finish',
label: t('app:addAccounts.breadcrumb.finish'), label: t('app:addAccounts.breadcrumb.finish'),
component: StepConfirmation, component: StepConfirmation,
footer: StepConfirmFooter, footer: StepConfirmFooter,
onBack: null, onBack: null,
hideFooter: false, hideFooter: false,
}, }
]
if (firmware.shouldUpdateMcu) {
return [
{
id: 'idCheck',
label: t('app:manager.modal.steps.idCheck'),
component: StepOSUInstaller,
footer: ({ firmware, ...props }: StepProps) => (
<DebugFooter firmware={firmware} {...props} where="updateMCU" />
),
onBack: null,
hideFooter: false,
},
{
id: 'updateMCU',
label: t('app:manager.modal.steps.updateMCU'),
component: StepFlashMcu,
footer: ({ firmware, ...props }: StepProps) => (
<Fragment>
<DebugFooter firmware={firmware} {...props} where="idCheck" />
<DebugFooter firmware={firmware} {...props} where="finish" />
</Fragment>
),
onBack: null,
hideFooter: false,
},
finalStep,
]
}
return [
{
id: 'idCheck',
label: t('app:manager.modal.steps.idCheck'),
component: StepFullFirmwareInstall,
footer: ({ firmware, ...props }: StepProps) => (
<DebugFooter firmware={firmware} {...props} where="finish" />
),
onBack: null,
hideFooter: false,
},
finalStep,
]
}
type Props = { type Props = {
t: T, t: T,
status: ModalStatus, status: ModalStatus,
onClose: () => void, onClose: () => void,
firmware: ?LedgerScriptParams, firmware: LedgerScriptParams & { shouldUpdateMcu: boolean },
installOsuFirmware: () => void,
installFinalFirmware: () => void,
flashMcu: () => void,
} }
type State = { type State = {
@ -86,17 +117,18 @@ class UpdateModal extends PureComponent<Props, State> {
stepId: 'idCheck', stepId: 'idCheck',
} }
STEPS = createSteps({ t: this.props.t }) STEPS = createSteps({ t: this.props.t, firmware: this.props.firmware })
handleStepChange = (step: Step) => this.setState({ stepId: step.id }) handleStepChange = (step: Step) => this.setState({ stepId: step.id })
render(): React$Node { render(): React$Node {
const { status, t, firmware, onClose } = this.props const { status, t, firmware, onClose, ...props } = this.props
const { stepId } = this.state const { stepId } = this.state
const additionalProps = { const additionalProps = {
firmware, firmware,
onCloseModal: onClose, onCloseModal: onClose,
...props,
} }
return ( return (
@ -104,6 +136,7 @@ class UpdateModal extends PureComponent<Props, State> {
onClose={onClose} onClose={onClose}
isOpened={status === 'install'} isOpened={status === 'install'}
refocusWhenChange={stepId} refocusWhenChange={stepId}
preventBackdropClick={false}
render={() => ( render={() => (
<Stepper <Stepper
title={t('app:manager.firmware.update')} title={t('app:manager.firmware.update')}

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

@ -1,11 +1,11 @@
// @flow // @flow
import React from 'react' import React, { PureComponent, Fragment } from 'react'
import styled from 'styled-components' import styled from 'styled-components'
import Box from 'components/base/Box' import Box from 'components/base/Box'
import Text from 'components/base/Text' import Text from 'components/base/Text'
import Button from 'components/base/Button' import Progress from 'components/base/Progress'
import DeviceConfirm from 'components/DeviceConfirm' import DeviceConfirm from 'components/DeviceConfirm'
import type { StepProps } from '../' import type { StepProps } from '../'
@ -46,27 +46,63 @@ const Ellipsis = styled.span`
width: 100%; width: 100%;
` `
// TODO: Change to class component and add osu firmware install class StepFullFirmwareInstall extends PureComponent<StepProps, *> {
function StepFullFirmwareInstall({ t, firmware }: StepProps) { componentDidMount() {
return ( this.install()
<Container> }
<Title>{t('app:manager.modal.confirmIdentifier')}</Title>
<Text ff="Open Sans|Regular" align="center" color="smoke"> install = async () => {
{t('app:manager.modal.confirmIdentifierText')} const { installOsuFirmware, installFinalFirmware, transitionTo } = this.props
</Text> const success = await installOsuFirmware()
<Box mx={7} mt={5}> if (success) {
<Text ff="Open Sans|SemiBold" align="center" color="smoke"> const finalSuccess = await installFinalFirmware()
{t('app:manager.modal.identifier')} if (finalSuccess) {
transitionTo('finish')
}
}
}
renderBody = () => {
const { installing } = this.state
const { firmware, t } = this.props
if (installing) {
return (
<Box mx={7}>
<Progress infinite style={{ width: '100%' }} />
</Box>
)
}
return (
<Fragment>
<Box mx={7} mt={5}>
<Text ff="Open Sans|SemiBold" align="center" color="smoke">
{t('app:manager.modal.identifier')}
</Text>
<Address>
<Ellipsis>{firmware && firmware.hash}</Ellipsis>
</Address>
</Box>
<Box mt={5}>
<DeviceConfirm />
</Box>
</Fragment>
)
}
render() {
const { t } = this.props
return (
<Container>
<Title>{t('app:manager.modal.confirmIdentifier')}</Title>
<Text ff="Open Sans|Regular" align="center" color="smoke">
{t('app:manager.modal.confirmIdentifierText')}
</Text> </Text>
<Address> {this.renderBody()}
<Ellipsis>{firmware && firmware.hash}</Ellipsis> </Container>
</Address> )
</Box> }
<Box mt={5}>
<DeviceConfirm />
</Box>
</Container>
)
} }
export default StepFullFirmwareInstall export default StepFullFirmwareInstall

57
src/components/modals/UpdateFirmware/steps/01-step-osu-installer.js

@ -1,11 +1,10 @@
// @flow // @flow
import React from 'react' import React, { PureComponent } from 'react'
import styled from 'styled-components' import styled from 'styled-components'
import Box from 'components/base/Box' import Box from 'components/base/Box'
import Text from 'components/base/Text' import Text from 'components/base/Text'
import Button from 'components/base/Button'
import DeviceConfirm from 'components/DeviceConfirm' import DeviceConfirm from 'components/DeviceConfirm'
import type { StepProps } from '../' import type { StepProps } from '../'
@ -46,27 +45,41 @@ const Ellipsis = styled.span`
width: 100%; width: 100%;
` `
// TODO: Change to class component and add osu firmware install class StepOSUInstaller extends PureComponent<StepProps, *> {
function StepOSUInstaller({ t, firmware }: StepProps) { componentDidMount() {
return ( this.install()
<Container> }
<Title>{t('app:manager.modal.confirmIdentifier')}</Title>
<Text ff="Open Sans|Regular" align="center" color="smoke"> install = async () => {
{t('app:manager.modal.confirmIdentifierText')} const { installOsuFirmware, transitionTo } = this.props
</Text> const success = await installOsuFirmware()
<Box mx={7} mt={5}> if (success) {
<Text ff="Open Sans|SemiBold" align="center" color="smoke"> transitionTo('updateMCU')
{t('app:manager.modal.identifier')} }
}
render() {
const { t, firmware } = this.props
return (
<Container>
<Title>{t('app:manager.modal.confirmIdentifier')}</Title>
<Text ff="Open Sans|Regular" align="center" color="smoke">
{t('app:manager.modal.confirmIdentifierText')}
</Text> </Text>
<Address> <Box mx={7} mt={5}>
<Ellipsis>{firmware && firmware.hash}</Ellipsis> <Text ff="Open Sans|SemiBold" align="center" color="smoke">
</Address> {t('app:manager.modal.identifier')}
</Box> </Text>
<Box mt={5}> <Address>
<DeviceConfirm /> <Ellipsis>{firmware && firmware.hash}</Ellipsis>
</Box> </Address>
</Container> </Box>
) <Box mt={5}>
<DeviceConfirm />
</Box>
</Container>
)
}
} }
export default StepOSUInstaller export default StepOSUInstaller

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

@ -1,12 +1,21 @@
// @flow // @flow
import React from 'react' import React, { PureComponent, Fragment } from 'react'
import styled from 'styled-components' import styled from 'styled-components'
import { connect } from 'react-redux'
import { timeout } from 'rxjs/operators/timeout'
import { DEVICE_INFOS_TIMEOUT } from 'config/constants'
import { i } from 'helpers/staticPath' import { i } from 'helpers/staticPath'
import { getCurrentDevice } from 'reducers/devices'
import { createCancelablePolling } from 'helpers/promise'
import getDeviceInfo from 'commands/getDeviceInfo'
import Box from 'components/base/Box' import Box from 'components/base/Box'
import Text from 'components/base/Text' import Text from 'components/base/Text'
import Progress from 'components/base/Progress'
import type { Device } from 'types/common'
import type { StepProps } from '../' import type { StepProps } from '../'
@ -35,36 +44,112 @@ const Separator = styled(Box).attrs({
background-color: currentColor; background-color: currentColor;
` `
// TODO: Change to class component and add flash mcu and final const mapStateToProps = state => ({
function StepFlashMcu({ t }: StepProps) { device: getCurrentDevice(state),
return ( })
<Container>
<Title>{t('app:manager.modal.mcuTitle')}</Title> type Props = StepProps & { device?: Device }
<Box mx={7}>
<Text ff="Open Sans|Regular" align="center" color="smoke"> type State = {
<Bullet>{'1.'}</Bullet> installing: boolean,
{t('app:manager.modal.mcuFirst')} }
</Text>
<img class StepFlashMcu extends PureComponent<Props, State> {
src={i('logos/unplugDevice.png')} state = {
style={{ width: '100%', maxWidth: 330, marginTop: 30 }} installing: false,
alt={t('app:manager.modal.mcuFirst')} }
/>
</Box> componentDidMount() {
<Separator my={6} /> this.install()
<Box mx={7}> }
<Text ff="Open Sans|Regular" align="center" color="smoke">
<Bullet>{'2.'}</Bullet> componentWillUnmount() {
{t('app:manager.modal.mcuSecond')} this._unsubConnect()
</Text> }
<img
src={i('logos/unplugDevice.png')} waitForDeviceInBootloader = () => {
style={{ width: '100%', maxWidth: 330, marginTop: 30 }} const { unsubscribe, promise } = createCancelablePolling(async () => {
alt={t('app:manager.modal.mcuFirst')} const { device } = this.props
/> if (!device) {
</Box> throw new Error('No device')
</Container> }
) const deviceInfo = await getDeviceInfo
.send({ devicePath: device.path })
.pipe(timeout(DEVICE_INFOS_TIMEOUT))
.toPromise()
if (!deviceInfo.isBootloader) {
throw new Error('Device is not in bootloader')
}
return { device, deviceInfo }
})
this._unsubConnect = unsubscribe
return promise
}
install = async () => {
await this.waitForDeviceInBootloader()
const { flashMcu, installFinalFirmware, transitionTo } = this.props
this.setState({ installing: true })
await flashMcu()
const finalSuccess = await installFinalFirmware()
if (finalSuccess) {
transitionTo('finish')
}
}
renderBody = () => {
const { installing } = this.state
const { t } = this.props
if (installing) {
return (
<Box mx={7}>
<Progress infinite style={{ width: '100%' }} />
</Box>
)
}
return (
<Fragment>
<Box mx={7}>
<Text ff="Open Sans|Regular" align="center" color="smoke">
<Bullet>{'1.'}</Bullet>
{t('app:manager.modal.mcuFirst')}
</Text>
<img
src={i('logos/unplugDevice.png')}
style={{ width: '100%', maxWidth: 368, marginTop: 30 }}
alt={t('app:manager.modal.mcuFirst')}
/>
</Box>
<Separator my={6} />
<Box mx={7}>
<Text ff="Open Sans|Regular" align="center" color="smoke">
<Bullet>{'2.'}</Bullet>
{t('app:manager.modal.mcuSecond')}
</Text>
<img
src={i('logos/bootloaderMode.png')}
style={{ width: '100%', maxWidth: 368, marginTop: 30 }}
alt={t('app:manager.modal.mcuFirst')}
/>
</Box>
</Fragment>
)
}
_unsubConnect: *
render() {
const { t } = this.props
return (
<Container>
<Title>{t('app:manager.modal.mcuTitle')}</Title>
{this.renderBody()}
</Container>
)
}
} }
export default StepFlashMcu export default connect(mapStateToProps)(StepFlashMcu)

21
src/helpers/devices/getLatestFirmwareForDevice.js

@ -3,6 +3,9 @@ import network from 'api/network'
import { GET_LATEST_FIRMWARE } from 'helpers/urls' import { GET_LATEST_FIRMWARE } from 'helpers/urls'
import type { DeviceInfo } from 'helpers/devices/getDeviceInfo' import type { DeviceInfo } from 'helpers/devices/getDeviceInfo'
import getFinalFirmwareById from 'helpers/firmware/getFinalFirmwareById'
import getMcus from 'helpers/firmware/getMcus'
import getCurrentFirmware from './getCurrentFirmware' import getCurrentFirmware from './getCurrentFirmware'
import getDeviceVersion from './getDeviceVersion' import getDeviceVersion from './getDeviceVersion'
@ -34,7 +37,23 @@ export default async (deviceInfo: DeviceInfo) => {
} }
const { se_firmware_osu_version } = data const { se_firmware_osu_version } = data
return se_firmware_osu_version const { next_se_firmware_final_version } = se_firmware_osu_version
const seFirmwareFinalVersion = await getFinalFirmwareById(next_se_firmware_final_version)
const mcus = await getMcus()
const currentMcuVersionId = mcus
.filter(mcu => mcu.name === deviceInfo.mcuVersion)
.map(mcu => mcu.id)
if (!seFirmwareFinalVersion.mcu_versions.includes(...currentMcuVersionId)) {
return {
...se_firmware_osu_version,
shouldUpdateMcu: true,
}
}
return { ...se_firmware_osu_version, shouldUpdateMcu: false }
} catch (err) { } catch (err) {
const error = Error(err.message) const error = Error(err.message)
error.stack = err.stack error.stack = err.stack

19
src/helpers/firmware/getMcus.js

@ -0,0 +1,19 @@
// @flow
import network from 'api/network'
import { GET_MCUS } from 'helpers/urls'
export default async (): Promise<*> => {
try {
const { data } = await network({
method: 'GET',
url: GET_MCUS,
})
return data
} catch (err) {
const error = Error(err.message)
error.stack = err.stack
throw err
}
}

0
src/helpers/devices/getNextMCU.js → src/helpers/firmware/getNextMCU.js

6
src/helpers/firmware/installFinalFirmware.js

@ -6,12 +6,14 @@ import { WS_INSTALL } from 'helpers/urls'
import { createDeviceSocket } from 'helpers/socket' import { createDeviceSocket } from 'helpers/socket'
import getDeviceVersion from 'helpers/devices/getDeviceVersion' import getDeviceVersion from 'helpers/devices/getDeviceVersion'
import getOsuFirmware from 'helpers/devices/getOsuFirmware' import getOsuFirmware from 'helpers/devices/getOsuFirmware'
import getDeviceInfo from 'helpers/devices/getDeviceInfo'
import getFinalFirmwareById from './getFinalFirmwareById' import getFinalFirmwareById from './getFinalFirmwareById'
type Result = * type Result = Promise<{ success: boolean, error?: string }>
export default async (transport: Transport<*>, deviceInfo: DeviceInfo): Result => { export default async (transport: Transport<*>): Result => {
try { try {
const deviceInfo: DeviceInfo = await getDeviceInfo(transport)
const device = await getDeviceVersion(deviceInfo.targetId, deviceInfo.providerId) const device = await getDeviceVersion(deviceInfo.targetId, deviceInfo.providerId)
const firmware = await getOsuFirmware({ deviceId: device.id, version: deviceInfo.fullVersion }) const firmware = await getOsuFirmware({ deviceId: device.id, version: deviceInfo.fullVersion })
const { next_se_firmware_final_version } = firmware const { next_se_firmware_final_version } = firmware

12
src/helpers/firmware/installMcu.js

@ -3,18 +3,16 @@ import type Transport from '@ledgerhq/hw-transport'
import { WS_MCU } from 'helpers/urls' import { WS_MCU } from 'helpers/urls'
import { createDeviceSocket } from 'helpers/socket' import { createDeviceSocket } from 'helpers/socket'
import getNextMCU from 'helpers/devices/getNextMCU' import getNextMCU from 'helpers/firmware/getNextMCU'
import getDeviceInfo from 'helpers/devices/getDeviceInfo'
type Result = Promise<*> type Result = Promise<*>
export default async ( export default async (transport: Transport<*>): Result => {
transport: Transport<*>, const { seVersion: version, targetId } = await getDeviceInfo(transport)
args: { targetId: string | number, version: string },
): Result => {
const { version } = args
const nextVersion = await getNextMCU(version) const nextVersion = await getNextMCU(version)
const params = { const params = {
targetId: args.targetId, targetId,
version: nextVersion.name, version: nextVersion.name,
} }
const url = WS_MCU(params) const url = WS_MCU(params)

24
src/helpers/firmware/installOsuFirmware.js

@ -6,12 +6,31 @@ import { createDeviceSocket } from 'helpers/socket'
import type { LedgerScriptParams } from 'helpers/common' import type { LedgerScriptParams } from 'helpers/common'
import { createCustomErrorClass } from '../errors'
const ManagerUnexpectedError = createCustomErrorClass('ManagerUnexpected')
const ManagerNotEnoughSpaceError = createCustomErrorClass('ManagerNotEnoughSpace')
const ManagerDeviceLockedError = createCustomErrorClass('ManagerDeviceLocked')
function remapError(promise) {
return promise.catch((e: Error) => {
switch (true) {
case e.message.endsWith('6982'):
throw new ManagerDeviceLockedError()
case e.message.endsWith('6a84') || e.message.endsWith('6a85'):
throw new ManagerNotEnoughSpaceError()
default:
throw new ManagerUnexpectedError(e.message, { msg: e.message })
}
})
}
type Result = Promise<{ success: boolean, error?: any }> type Result = Promise<{ success: boolean, error?: any }>
export default async ( export default async (
transport: Transport<*>, transport: Transport<*>,
targetId: string | number, targetId: string | number,
firmware: LedgerScriptParams, firmware: LedgerScriptParams & { shouldUpdateMcu: boolean },
): Result => { ): Result => {
try { try {
const params = { const params = {
@ -19,8 +38,9 @@ export default async (
...firmware, ...firmware,
firmwareKey: firmware.firmware_key, firmwareKey: firmware.firmware_key,
} }
delete params.shouldUpdateMcu
const url = WS_INSTALL(params) const url = WS_INSTALL(params)
await createDeviceSocket(transport, url).toPromise() await remapError(createDeviceSocket(transport, url).toPromise())
return { success: true } return { success: true }
} catch (error) { } catch (error) {
const result = { success: false, error } const result = { success: false, error }

1
src/helpers/urls.js

@ -21,6 +21,7 @@ export const GET_CURRENT_FIRMWARE: string = managerUrlbuilder('get_firmware_vers
export const GET_CURRENT_OSU: string = managerUrlbuilder('get_osu_version') export const GET_CURRENT_OSU: string = managerUrlbuilder('get_osu_version')
export const GET_LATEST_FIRMWARE: string = managerUrlbuilder('get_latest_firmware') export const GET_LATEST_FIRMWARE: string = managerUrlbuilder('get_latest_firmware')
export const GET_NEXT_MCU: string = managerUrlbuilder('mcu_versions_bootloader') export const GET_NEXT_MCU: string = managerUrlbuilder('mcu_versions_bootloader')
export const GET_MCUS: string = managerUrlbuilder('mcu_versions')
export const GET_CATEGORIES: string = managerUrlbuilder('categories') export const GET_CATEGORIES: string = managerUrlbuilder('categories')
export const GET_APPLICATIONS: string = managerUrlbuilder('applications') export const GET_APPLICATIONS: string = managerUrlbuilder('applications')

BIN
static/images/logos/bootloaderMode.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

BIN
static/images/logos/unplugDevice.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Loading…
Cancel
Save