|
|
@ -1,8 +1,8 @@ |
|
|
|
// @flow
|
|
|
|
/* eslint-disable react/jsx-no-literals */ // FIXME
|
|
|
|
|
|
|
|
import React, { PureComponent } from 'react' |
|
|
|
import { translate } from 'react-i18next' |
|
|
|
import React, { PureComponent, Fragment } from 'react' |
|
|
|
import { translate, Trans } from 'react-i18next' |
|
|
|
import isEqual from 'lodash/isEqual' |
|
|
|
import isEmpty from 'lodash/isEmpty' |
|
|
|
import invariant from 'invariant' |
|
|
@ -17,6 +17,9 @@ import installOsuFirmware from 'commands/installOsuFirmware' |
|
|
|
|
|
|
|
import Box, { Card } from 'components/base/Box' |
|
|
|
import Text from 'components/base/Text' |
|
|
|
import Modal, { ModalBody, ModalFooter, ModalTitle, ModalContent } from 'components/base/Modal' |
|
|
|
import Button from 'components/base/Button' |
|
|
|
// import Progress from 'components/base/Progress'
|
|
|
|
|
|
|
|
import NanoS from 'icons/device/NanoS' |
|
|
|
import CheckFull from 'icons/CheckFull' |
|
|
@ -25,11 +28,16 @@ import UpdateFirmwareButton from './UpdateFirmwareButton' |
|
|
|
|
|
|
|
let CACHED_LATEST_FIRMWARE = null |
|
|
|
|
|
|
|
export const getCleanVersion = (input: string): string => |
|
|
|
input.endsWith('-osu') ? input.replace('-osu', '') : input |
|
|
|
|
|
|
|
type DeviceInfos = { |
|
|
|
targetId: number | string, |
|
|
|
version: string, |
|
|
|
} |
|
|
|
|
|
|
|
type ModalStatus = 'closed' | 'disclaimer' | 'installing' | 'error' | 'success' |
|
|
|
|
|
|
|
type Props = { |
|
|
|
t: T, |
|
|
|
device: Device, |
|
|
@ -38,11 +46,13 @@ type Props = { |
|
|
|
|
|
|
|
type State = { |
|
|
|
latestFirmware: ?LedgerScriptParams, |
|
|
|
modal: ModalStatus, |
|
|
|
} |
|
|
|
|
|
|
|
class FirmwareUpdate extends PureComponent<Props, State> { |
|
|
|
state = { |
|
|
|
latestFirmware: null, |
|
|
|
modal: 'closed', |
|
|
|
} |
|
|
|
|
|
|
|
componentDidMount() { |
|
|
@ -86,6 +96,7 @@ class FirmwareUpdate extends PureComponent<Props, State> { |
|
|
|
const { |
|
|
|
device: { path: devicePath }, |
|
|
|
} = this.props |
|
|
|
this.setState({ modal: 'installing' }) |
|
|
|
const { success } = await installOsuFirmware |
|
|
|
.send({ devicePath, firmware: latestFirmware, targetId: infos.targetId }) |
|
|
|
.toPromise() |
|
|
@ -97,6 +108,46 @@ class FirmwareUpdate extends PureComponent<Props, State> { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
handleCloseModal = () => this.setState({ modal: 'closed' }) |
|
|
|
|
|
|
|
handleInstallModal = () => this.setState({ modal: 'disclaimer' }) |
|
|
|
|
|
|
|
renderModal = () => { |
|
|
|
const { t } = this.props |
|
|
|
const { modal, latestFirmware } = this.state |
|
|
|
return ( |
|
|
|
<Modal |
|
|
|
isOpened={modal !== 'closed'} |
|
|
|
render={() => ( |
|
|
|
<ModalBody grow align="center" justify="center" mt={3}> |
|
|
|
<Fragment> |
|
|
|
<ModalTitle>{t('app:manager.firmware.update')}</ModalTitle> |
|
|
|
<ModalContent> |
|
|
|
<Text ff="Open Sans|Regular" fontSize={4} color="graphite" align="center"> |
|
|
|
<Trans i18nKey="app:manager.firmware.disclaimerTitle"> |
|
|
|
You are about to install the latest |
|
|
|
<Text ff="Open Sans|SemiBold" color="dark"> |
|
|
|
{`firmware ${latestFirmware ? getCleanVersion(latestFirmware.name) : ''}`} |
|
|
|
</Text> |
|
|
|
</Trans> |
|
|
|
</Text> |
|
|
|
<Text ff="Open Sans|Regular" fontSize={4} color="graphite" align="center"> |
|
|
|
{t('app:manager.firmware.disclaimerAppDelete')} |
|
|
|
{t('app:manager.firmware.disclaimerAppReinstall')} |
|
|
|
</Text> |
|
|
|
</ModalContent> |
|
|
|
<ModalFooter horizontal justifyContent="flex-end" style={{ width: '100%' }}> |
|
|
|
<Button primary padded onClick={this.installFirmware}> |
|
|
|
{t('app:manager.firmware.continue')} |
|
|
|
</Button> |
|
|
|
</ModalFooter> |
|
|
|
</Fragment> |
|
|
|
</ModalBody> |
|
|
|
)} |
|
|
|
/> |
|
|
|
) |
|
|
|
} |
|
|
|
|
|
|
|
render() { |
|
|
|
const { infos, t } = this.props |
|
|
|
const { latestFirmware } = this.state |
|
|
@ -122,8 +173,12 @@ class FirmwareUpdate extends PureComponent<Props, State> { |
|
|
|
})} |
|
|
|
</Text> |
|
|
|
</Box> |
|
|
|
<UpdateFirmwareButton firmware={latestFirmware} installFirmware={this.installFirmware} /> |
|
|
|
<UpdateFirmwareButton |
|
|
|
firmware={latestFirmware} |
|
|
|
installFirmware={this.handleInstallModal} |
|
|
|
/> |
|
|
|
</Box> |
|
|
|
{this.renderModal()} |
|
|
|
</Card> |
|
|
|
) |
|
|
|
} |
|
|
|