Browse Source

check for device type before returning app list

master
Valentin D. Pinkman 7 years ago
parent
commit
90fbaf4c0f
No known key found for this signature in database GPG Key ID: E7D110669FFB8D3E
  1. 2
      src/commands/installOsuFirmware.js
  2. 9
      src/commands/listApps.js
  3. 15
      src/components/ManagerPage/AppsList.js
  4. 72
      src/components/ManagerPage/index.js
  5. 17
      src/helpers/apps/listApps.js
  6. 2
      src/internals/devices/index.js
  7. 3
      src/internals/manager/index.js

2
src/commands/installOsuFirmware.js

@ -2,8 +2,8 @@
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 installOsuFirmware from 'helpers/firmware/installOsuFirmware' import installOsuFirmware from 'helpers/firmware/installOsuFirmware'
type Input = { type Input = {

9
src/commands/listApps.js

@ -3,13 +3,16 @@
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 listApps from 'helpers/apps/listApps' import listApps from 'helpers/apps/listApps'
type Input = * type Input = {
devicePath: string,
}
type Result = * type Result = *
const cmd: Command<Input, Result> = createCommand('manager', 'listApps', () => const cmd: Command<Input, Result> = createCommand('devices', 'listApps', ({ devicePath }) =>
fromPromise(listApps()), fromPromise(withDevice(devicePath)(transport => listApps(transport))),
) )
export default cmd export default cmd

15
src/components/ManagerPage/AppsList.js

@ -69,10 +69,17 @@ class AppsList extends PureComponent<Props, State> {
_unmounted = false _unmounted = false
async fetchAppList() { async fetchAppList() {
const appsList = CACHED_APPS || (await listApps.send().toPromise()) try {
CACHED_APPS = appsList const {
if (!this._unmounted) { device: { path: devicePath },
this.setState({ appsList, status: 'idle' }) } = this.props
const appsList = CACHED_APPS || (await listApps.send({ devicePath }).toPromise())
CACHED_APPS = appsList
if (!this._unmounted) {
this.setState({ appsList, status: 'idle' })
}
} catch (err) {
this.setState({ status: 'error', error: err.message })
} }
} }

72
src/components/ManagerPage/index.js

@ -1,8 +1,9 @@
// @flow // @flow
import React, { Component, Fragment } from 'react' import React, { Fragment } from 'react'
import { translate } from 'react-i18next' import { translate } from 'react-i18next'
import type { Node } from 'react'
import type { T } from 'types/common' import type { T } from 'types/common'
import AppsList from './AppsList' import AppsList from './AppsList'
@ -16,44 +17,35 @@ type Props = {
t: T, t: T,
} }
type State = {} const ManagerPage = ({ t }: Props): Node => (
<Fragment>
class ManagerPage extends Component<Props, State> { <EnsureDevice>
render() { {device => (
const { t } = this.props <EnsureDashboard device={device}>
{deviceInfo => (
return ( <Fragment>
<Fragment> {deviceInfo.mcu && <span>bootloader mode</span>}
<EnsureDevice> {deviceInfo.final && <span>osu mode</span>}
{device => (
<EnsureDashboard device={device}> {!deviceInfo.mcu &&
{deviceInfo => ( !deviceInfo.final && (
<Fragment> <EnsureGenuine device={device} t={t}>
{deviceInfo.mcu && <span>bootloader mode</span>} <FirmwareUpdate
{deviceInfo.final && <span>osu mode</span>} infos={{
targetId: deviceInfo.targetId,
{!deviceInfo.mcu && version: deviceInfo.version,
!deviceInfo.final && ( }}
<EnsureGenuine device={device} t={t}> device={device}
<FirmwareUpdate t={t}
infos={{ />
targetId: deviceInfo.targetId, <AppsList device={device} />
version: deviceInfo.version, </EnsureGenuine>
}} )}
device={device} </Fragment>
t={t}
/>
<AppsList device={device} />
</EnsureGenuine>
)}
</Fragment>
)}
</EnsureDashboard>
)} )}
</EnsureDevice> </EnsureDashboard>
</Fragment> )}
) </EnsureDevice>
} </Fragment>
} )
export default translate()(ManagerPage) export default translate()(ManagerPage)

17
src/helpers/apps/listApps.js

@ -1,10 +1,23 @@
// @flow // @flow
import axios from 'axios' import axios from 'axios'
import type Transport from '@ledgerhq/hw-transport'
import { getFirmwareInfo } from 'helpers/common'
const { API_BASE_URL } = process.env
export default async () => { export default async (transport: Transport<*>) => {
try { try {
const { targetId } = await getFirmwareInfo(transport)
const { data: deviceData } = await axios.get(
`${API_BASE_URL}/device_versions_target_id/${targetId}`,
)
const { data } = await axios.get('https://api.ledgerwallet.com/update/applications') const { data } = await axios.get('https://api.ledgerwallet.com/update/applications')
if (deviceData.name in data) {
return data[deviceData.name]
}
return data['nanos-1.4'] return data['nanos-1.4']
} catch (err) { } catch (err) {
const error = Error(err.message) const error = Error(err.message)

2
src/internals/devices/index.js

@ -15,6 +15,7 @@ import uninstallApp from 'commands/uninstallApp'
import installOsuFirmware from 'commands/installOsuFirmware' import installOsuFirmware from 'commands/installOsuFirmware'
import installFinalFirmware from 'commands/installFinalFirmware' import installFinalFirmware from 'commands/installFinalFirmware'
import installMcu from 'commands/installMcu' import installMcu from 'commands/installMcu'
import listApps from 'commands/listApps'
export const commands: Array<Command<any, any>> = [ export const commands: Array<Command<any, any>> = [
getAddress, getAddress,
@ -31,4 +32,5 @@ export const commands: Array<Command<any, any>> = [
installOsuFirmware, installOsuFirmware,
installFinalFirmware, installFinalFirmware,
installMcu, installMcu,
listApps,
] ]

3
src/internals/manager/index.js

@ -1,7 +1,6 @@
// @flow // @flow
import type { Command } from 'helpers/ipc' import type { Command } from 'helpers/ipc'
import listApps from 'commands/listApps'
import getMemInfo from 'commands/getMemInfo' import getMemInfo from 'commands/getMemInfo'
/** /**
@ -20,4 +19,4 @@ import getMemInfo from 'commands/getMemInfo'
* *
*/ */
export const commands: Array<Command<any, any>> = [listApps, getMemInfo] export const commands: Array<Command<any, any>> = [getMemInfo]

Loading…
Cancel
Save