Browse Source

Merge pull request #722 from amougel/feature/app_categories

Filter apps based on developer mode
master
Gaëtan Renaudeau 7 years ago
committed by GitHub
parent
commit
79e094858e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      src/commands/index.js
  2. 15
      src/commands/listAppVersions.js
  3. 11
      src/commands/listApps.js
  4. 16
      src/commands/listCategories.js
  5. 62
      src/components/ManagerPage/AppsList.js
  6. 31
      src/helpers/apps/listAppVersions.js
  7. 23
      src/helpers/apps/listApps.js
  8. 15
      src/helpers/apps/listCategories.js
  9. 2
      src/helpers/urls.js

4
src/commands/index.js

@ -22,6 +22,8 @@ import libcoreSignAndBroadcast from 'commands/libcoreSignAndBroadcast'
import libcoreSyncAccount from 'commands/libcoreSyncAccount'
import libcoreValidAddress from 'commands/libcoreValidAddress'
import listApps from 'commands/listApps'
import listAppVersions from 'commands/listAppVersions'
import listCategories from 'commands/listCategories'
import listenDevices from 'commands/listenDevices'
import signTransaction from 'commands/signTransaction'
import testApdu from 'commands/testApdu'
@ -49,6 +51,8 @@ const all: Array<Command<any, any>> = [
libcoreSyncAccount,
libcoreValidAddress,
listApps,
listAppVersions,
listCategories,
listenDevices,
signTransaction,
testApdu,

15
src/commands/listAppVersions.js

@ -0,0 +1,15 @@
// @flow
import { createCommand, Command } from 'helpers/ipc'
import { fromPromise } from 'rxjs/observable/fromPromise'
import type { DeviceInfo } from 'helpers/devices/getDeviceInfo'
import listAppVersions from 'helpers/apps/listAppVersions'
type Result = *
const cmd: Command<DeviceInfo, Result> = createCommand('listAppVersions', deviceInfo =>
fromPromise(listAppVersions(deviceInfo)),
)
export default cmd

11
src/commands/listApps.js

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

16
src/commands/listCategories.js

@ -0,0 +1,16 @@
// @flow
import { createCommand, Command } from 'helpers/ipc'
import { fromPromise } from 'rxjs/observable/fromPromise'
import listCategories from 'helpers/apps/listCategories'
type Input = {}
type Result = *
const cmd: Command<Input, Result> = createCommand('listCategories', () =>
fromPromise(listCategories()),
)
export default cmd

62
src/components/ManagerPage/AppsList.js

@ -4,11 +4,16 @@
import React, { PureComponent, Fragment } from 'react'
import styled from 'styled-components'
import { translate } from 'react-i18next'
import { connect } from 'react-redux'
import { compose } from 'redux'
import type { Device, T } from 'types/common'
import type { LedgerScriptParams } from 'helpers/common'
import type { DeviceInfo } from 'helpers/devices/getDeviceInfo'
import { developerModeSelector } from 'reducers/settings'
import listApps from 'commands/listApps'
import listAppVersions from 'commands/listAppVersions'
import installApp from 'commands/installApp'
import uninstallApp from 'commands/uninstallApp'
@ -30,6 +35,10 @@ import CheckCircle from 'icons/CheckCircle'
import ManagerApp from './ManagerApp'
import AppSearchBar from './AppSearchBar'
const mapStateToProps = state => ({
isDevMode: developerModeSelector(state),
})
const List = styled(Box).attrs({
horizontal: true,
m: -3,
@ -46,16 +55,15 @@ type Mode = 'home' | 'installing' | 'uninstalling'
type Props = {
device: Device,
targetId: string | number,
deviceInfo: DeviceInfo,
t: T,
fullVersion: string,
provider: number,
isDevMode: boolean,
}
type State = {
status: Status,
error: ?Error,
appsList: LedgerScriptParams[],
filteredAppVersionsList: LedgerScriptParams[],
appsLoaded: boolean,
app: string,
mode: Mode,
@ -65,7 +73,7 @@ class AppsList extends PureComponent<Props, State> {
state = {
status: 'loading',
error: null,
appsList: [],
filteredAppVersionsList: [],
appsLoaded: false,
app: '',
mode: 'home',
@ -81,12 +89,31 @@ class AppsList extends PureComponent<Props, State> {
_unmounted = false
filterAppVersions = (applicationsList, compatibleAppVersionsList) => {
if (!this.props.isDevMode) {
return compatibleAppVersionsList.filter(
version => applicationsList.find(e => e.id === version.app).category !== 2,
)
}
return applicationsList
}
async fetchAppList() {
try {
const { targetId, fullVersion, provider } = this.props
const appsList = await listApps.send({ targetId, fullVersion, provider }).toPromise()
const { deviceInfo } = this.props
const applicationsList = await listApps.send({}).toPromise()
const compatibleAppVersionsList = await listAppVersions.send(deviceInfo).toPromise()
const filteredAppVersionsList = this.filterAppVersions(
applicationsList,
compatibleAppVersionsList,
)
if (!this._unmounted) {
this.setState({ appsList, status: 'idle', appsLoaded: true })
this.setState({
status: 'idle',
filteredAppVersionsList,
appsLoaded: true,
})
}
} catch (err) {
this.setState({ status: 'error', error: err })
@ -98,9 +125,9 @@ class AppsList extends PureComponent<Props, State> {
try {
const {
device: { path: devicePath },
targetId,
deviceInfo,
} = this.props
const data = { app, devicePath, targetId }
const data = { app, devicePath, targetId: deviceInfo.targetId }
await installApp.send(data).toPromise()
this.setState({ status: 'success' })
} catch (err) {
@ -113,9 +140,9 @@ class AppsList extends PureComponent<Props, State> {
try {
const {
device: { path: devicePath },
targetId,
deviceInfo,
} = this.props
const data = { app, devicePath, targetId }
const data = { app, devicePath, targetId: deviceInfo.targetId }
await uninstallApp.send(data).toPromise()
this.setState({ status: 'success' })
} catch (err) {
@ -214,10 +241,10 @@ class AppsList extends PureComponent<Props, State> {
}
renderList() {
const { appsList, appsLoaded } = this.state
const { filteredAppVersionsList, appsLoaded } = this.state
return appsLoaded ? (
<Box>
<AppSearchBar list={appsList}>
<AppSearchBar list={filteredAppVersionsList}>
{items => (
<List>
{items.map(c => (
@ -268,4 +295,7 @@ class AppsList extends PureComponent<Props, State> {
}
}
export default translate()(AppsList)
export default compose(
translate(),
connect(mapStateToProps),
)(AppsList)

31
src/helpers/apps/listAppVersions.js

@ -0,0 +1,31 @@
// @flow
import network from 'api/network'
import type { DeviceInfo } from 'helpers/devices/getDeviceInfo'
import { APPLICATIONS_BY_DEVICE } from 'helpers/urls'
import getDeviceVersion from 'helpers/devices/getDeviceVersion'
import getCurrentFirmware from 'helpers/devices/getCurrentFirmware'
export default async (deviceInfo: DeviceInfo) => {
try {
const deviceData = await getDeviceVersion(deviceInfo.targetId, deviceInfo.providerId)
const firmwareData = await getCurrentFirmware({
deviceId: deviceData.id,
fullVersion: deviceInfo.fullVersion,
provider: deviceInfo.providerId,
})
const params = {
provider: deviceInfo.providerId,
current_se_firmware_final_version: firmwareData.id,
device_version: deviceData.id,
}
const {
data: { application_versions },
} = await network({ method: 'POST', url: APPLICATIONS_BY_DEVICE, data: params })
return application_versions.length > 0 ? application_versions : []
} catch (err) {
const error = Error(err.message)
error.stack = err.stack
throw err
}
}

23
src/helpers/apps/listApps.js

@ -1,27 +1,12 @@
// @flow
import network from 'api/network'
import { APPLICATIONS_BY_DEVICE } from 'helpers/urls'
import getDeviceVersion from 'helpers/devices/getDeviceVersion'
import getCurrentFirmware from 'helpers/devices/getCurrentFirmware'
import { GET_APPLICATIONS } from 'helpers/urls'
export default async (targetId: string | number, fullVersion: string, provider: number) => {
export default async () => {
try {
const deviceData = await getDeviceVersion(targetId, provider)
const firmwareData = await getCurrentFirmware({
deviceId: deviceData.id,
fullVersion,
provider,
})
const params = {
provider,
current_se_firmware_final_version: firmwareData.id,
device_version: deviceData.id,
}
const {
data: { application_versions },
} = await network({ method: 'POST', url: APPLICATIONS_BY_DEVICE, data: params })
return application_versions.length > 0 ? application_versions : []
const { data } = await network({ method: 'GET', url: GET_APPLICATIONS })
return data.length > 0 ? data : []
} catch (err) {
const error = Error(err.message)
error.stack = err.stack

15
src/helpers/apps/listCategories.js

@ -0,0 +1,15 @@
// @flow
import network from 'api/network'
import { GET_CATEGORIES } from 'helpers/urls'
export default async () => {
try {
const { data } = await network({ method: 'GET', url: GET_CATEGORIES })
return data.length > 0 ? data : []
} catch (err) {
const error = Error(err.message)
error.stack = err.stack
throw err
}
}

2
src/helpers/urls.js

@ -21,6 +21,8 @@ export const GET_CURRENT_FIRMWARE: string = managerUrlbuilder('get_firmware_vers
export const GET_CURRENT_OSU: string = managerUrlbuilder('get_osu_version')
export const GET_LATEST_FIRMWARE: string = managerUrlbuilder('get_latest_firmware')
export const GET_NEXT_MCU: string = managerUrlbuilder('mcu_versions_bootloader')
export const GET_CATEGORIES: string = managerUrlbuilder('categories')
export const GET_APPLICATIONS: string = managerUrlbuilder('applications')
export const WS_INSTALL: (arg: LedgerScriptParams) => string = wsURLBuilder('install')
export const WS_GENUINE: (arg: {

Loading…
Cancel
Save