Browse Source

Merge pull request #388 from valpinkman/list-apps-for-device

check for device type before returning app list
master
Gaëtan Renaudeau 7 years ago
committed by GitHub
parent
commit
996da6eeef
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/commands/installOsuFirmware.js
  2. 9
      src/commands/listApps.js
  3. 14
      src/components/ManagerPage/AppsList.js
  4. 74
      src/components/ManagerPage/index.js
  5. 13
      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 { fromPromise } from 'rxjs/observable/fromPromise'
import { withDevice } from 'helpers/deviceAccess'
import { withDevice } from 'helpers/deviceAccess'
import installOsuFirmware from 'helpers/firmware/installOsuFirmware'
type Input = {

9
src/commands/listApps.js

@ -5,11 +5,14 @@ import { fromPromise } from 'rxjs/observable/fromPromise'
import listApps from 'helpers/apps/listApps'
type Input = *
type Input = {
targetId: string | number,
}
type Result = *
const cmd: Command<Input, Result> = createCommand('manager', 'listApps', () =>
fromPromise(listApps()),
const cmd: Command<Input, Result> = createCommand('devices', 'listApps', ({ targetId }) =>
fromPromise(listApps(targetId)),
)
export default cmd

14
src/components/ManagerPage/AppsList.js

@ -42,6 +42,7 @@ type LedgerApp = {
type Props = {
device: Device,
targetId: string | number,
t: T,
}
@ -69,10 +70,15 @@ class AppsList extends PureComponent<Props, State> {
_unmounted = false
async fetchAppList() {
const appsList = CACHED_APPS || (await listApps.send().toPromise())
CACHED_APPS = appsList
if (!this._unmounted) {
this.setState({ appsList, status: 'idle' })
try {
const { targetId } = this.props
const appsList = CACHED_APPS || (await listApps.send({ targetId }).toPromise())
CACHED_APPS = appsList
if (!this._unmounted) {
this.setState({ appsList, status: 'idle' })
}
} catch (err) {
this.setState({ status: 'error', error: err.message })
}
}

74
src/components/ManagerPage/index.js

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

13
src/helpers/apps/listApps.js

@ -1,10 +1,19 @@
// @flow
import axios from 'axios'
export default async () => {
const { API_BASE_URL } = process.env
export default async (targetId: string | number) => {
try {
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')
if (deviceData.name in data) {
return data[deviceData.name]
}
return data['nanos-1.4']
} catch (err) {
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 installFinalFirmware from 'commands/installFinalFirmware'
import installMcu from 'commands/installMcu'
import listApps from 'commands/listApps'
export const commands: Array<Command<any, any>> = [
getAddress,
@ -31,4 +32,5 @@ export const commands: Array<Command<any, any>> = [
installOsuFirmware,
installFinalFirmware,
installMcu,
listApps,
]

3
src/internals/manager/index.js

@ -1,7 +1,6 @@
// @flow
import type { Command } from 'helpers/ipc'
import listApps from 'commands/listApps'
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