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 libcoreSyncAccount from 'commands/libcoreSyncAccount'
import libcoreValidAddress from 'commands/libcoreValidAddress' import libcoreValidAddress from 'commands/libcoreValidAddress'
import listApps from 'commands/listApps' import listApps from 'commands/listApps'
import listAppVersions from 'commands/listAppVersions'
import listCategories from 'commands/listCategories'
import listenDevices from 'commands/listenDevices' import listenDevices from 'commands/listenDevices'
import signTransaction from 'commands/signTransaction' import signTransaction from 'commands/signTransaction'
import testApdu from 'commands/testApdu' import testApdu from 'commands/testApdu'
@ -49,6 +51,8 @@ const all: Array<Command<any, any>> = [
libcoreSyncAccount, libcoreSyncAccount,
libcoreValidAddress, libcoreValidAddress,
listApps, listApps,
listAppVersions,
listCategories,
listenDevices, listenDevices,
signTransaction, signTransaction,
testApdu, 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' import listApps from 'helpers/apps/listApps'
type Input = { type Input = {}
targetId: string | number,
fullVersion: string,
provider: number,
}
type Result = * type Result = *
const cmd: Command<Input, Result> = createCommand( const cmd: Command<Input, Result> = createCommand('listApps', () => fromPromise(listApps()))
'listApps',
({ targetId, fullVersion, provider }) => fromPromise(listApps(targetId, fullVersion, provider)),
)
export default cmd 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 React, { PureComponent, Fragment } from 'react'
import styled from 'styled-components' import styled from 'styled-components'
import { translate } from 'react-i18next' import { translate } from 'react-i18next'
import { connect } from 'react-redux'
import { compose } from 'redux'
import type { Device, T } from 'types/common' import type { Device, T } from 'types/common'
import type { LedgerScriptParams } from 'helpers/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 listApps from 'commands/listApps'
import listAppVersions from 'commands/listAppVersions'
import installApp from 'commands/installApp' import installApp from 'commands/installApp'
import uninstallApp from 'commands/uninstallApp' import uninstallApp from 'commands/uninstallApp'
@ -30,6 +35,10 @@ import CheckCircle from 'icons/CheckCircle'
import ManagerApp from './ManagerApp' import ManagerApp from './ManagerApp'
import AppSearchBar from './AppSearchBar' import AppSearchBar from './AppSearchBar'
const mapStateToProps = state => ({
isDevMode: developerModeSelector(state),
})
const List = styled(Box).attrs({ const List = styled(Box).attrs({
horizontal: true, horizontal: true,
m: -3, m: -3,
@ -46,16 +55,15 @@ type Mode = 'home' | 'installing' | 'uninstalling'
type Props = { type Props = {
device: Device, device: Device,
targetId: string | number, deviceInfo: DeviceInfo,
t: T, t: T,
fullVersion: string, isDevMode: boolean,
provider: number,
} }
type State = { type State = {
status: Status, status: Status,
error: ?Error, error: ?Error,
appsList: LedgerScriptParams[], filteredAppVersionsList: LedgerScriptParams[],
appsLoaded: boolean, appsLoaded: boolean,
app: string, app: string,
mode: Mode, mode: Mode,
@ -65,7 +73,7 @@ class AppsList extends PureComponent<Props, State> {
state = { state = {
status: 'loading', status: 'loading',
error: null, error: null,
appsList: [], filteredAppVersionsList: [],
appsLoaded: false, appsLoaded: false,
app: '', app: '',
mode: 'home', mode: 'home',
@ -81,12 +89,31 @@ class AppsList extends PureComponent<Props, State> {
_unmounted = false _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() { async fetchAppList() {
try { try {
const { targetId, fullVersion, provider } = this.props const { deviceInfo } = this.props
const appsList = await listApps.send({ targetId, fullVersion, provider }).toPromise() const applicationsList = await listApps.send({}).toPromise()
const compatibleAppVersionsList = await listAppVersions.send(deviceInfo).toPromise()
const filteredAppVersionsList = this.filterAppVersions(
applicationsList,
compatibleAppVersionsList,
)
if (!this._unmounted) { if (!this._unmounted) {
this.setState({ appsList, status: 'idle', appsLoaded: true }) this.setState({
status: 'idle',
filteredAppVersionsList,
appsLoaded: true,
})
} }
} catch (err) { } catch (err) {
this.setState({ status: 'error', error: err }) this.setState({ status: 'error', error: err })
@ -98,9 +125,9 @@ class AppsList extends PureComponent<Props, State> {
try { try {
const { const {
device: { path: devicePath }, device: { path: devicePath },
targetId, deviceInfo,
} = this.props } = this.props
const data = { app, devicePath, targetId } const data = { app, devicePath, targetId: deviceInfo.targetId }
await installApp.send(data).toPromise() await installApp.send(data).toPromise()
this.setState({ status: 'success' }) this.setState({ status: 'success' })
} catch (err) { } catch (err) {
@ -113,9 +140,9 @@ class AppsList extends PureComponent<Props, State> {
try { try {
const { const {
device: { path: devicePath }, device: { path: devicePath },
targetId, deviceInfo,
} = this.props } = this.props
const data = { app, devicePath, targetId } const data = { app, devicePath, targetId: deviceInfo.targetId }
await uninstallApp.send(data).toPromise() await uninstallApp.send(data).toPromise()
this.setState({ status: 'success' }) this.setState({ status: 'success' })
} catch (err) { } catch (err) {
@ -214,10 +241,10 @@ class AppsList extends PureComponent<Props, State> {
} }
renderList() { renderList() {
const { appsList, appsLoaded } = this.state const { filteredAppVersionsList, appsLoaded } = this.state
return appsLoaded ? ( return appsLoaded ? (
<Box> <Box>
<AppSearchBar list={appsList}> <AppSearchBar list={filteredAppVersionsList}>
{items => ( {items => (
<List> <List>
{items.map(c => ( {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 // @flow
import network from 'api/network' import network from 'api/network'
import { APPLICATIONS_BY_DEVICE } from 'helpers/urls' import { GET_APPLICATIONS } from 'helpers/urls'
import getDeviceVersion from 'helpers/devices/getDeviceVersion'
import getCurrentFirmware from 'helpers/devices/getCurrentFirmware'
export default async (targetId: string | number, fullVersion: string, provider: number) => { export default async () => {
try { try {
const deviceData = await getDeviceVersion(targetId, provider) const { data } = await network({ method: 'GET', url: GET_APPLICATIONS })
const firmwareData = await getCurrentFirmware({ return data.length > 0 ? data : []
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 : []
} catch (err) { } catch (err) {
const error = Error(err.message) const error = Error(err.message)
error.stack = err.stack 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_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_CATEGORIES: string = managerUrlbuilder('categories')
export const GET_APPLICATIONS: string = managerUrlbuilder('applications')
export const WS_INSTALL: (arg: LedgerScriptParams) => string = wsURLBuilder('install') export const WS_INSTALL: (arg: LedgerScriptParams) => string = wsURLBuilder('install')
export const WS_GENUINE: (arg: { export const WS_GENUINE: (arg: {

Loading…
Cancel
Save