Browse Source

using provider

master
amougel 7 years ago
parent
commit
7317c8d605
  1. 3
      src/commands/getCurrentFirmware.js
  2. 12
      src/commands/getIsGenuine.js
  3. 8
      src/commands/getLatestFirmwareForDevice.js
  4. 8
      src/commands/listApps.js
  5. 2
      src/components/EnsureDeviceApp/index.js
  6. 7
      src/components/ManagerPage/AppsList.js
  7. 5
      src/components/ManagerPage/Dashboard.js
  8. 23
      src/components/ManagerPage/FirmwareUpdate.js
  9. 19
      src/components/Workflow/EnsureGenuine.js
  10. 2
      src/components/Workflow/index.js
  11. 11
      src/helpers/apps/listApps.js
  12. 8
      src/helpers/devices/getCurrentFirmware.js
  13. 13
      src/helpers/devices/getDeviceInfo.js
  14. 3
      src/helpers/devices/getDeviceVersion.js
  15. 18
      src/helpers/devices/getIsGenuine.js
  16. 20
      src/helpers/devices/getLatestFirmwareForDevice.js
  17. 4
      src/helpers/devices/isDashboardOpen.js
  18. 5
      src/helpers/urls.js

3
src/commands/getCurrentFirmware.js

@ -7,7 +7,8 @@ import getCurrentFirmware from 'helpers/devices/getCurrentFirmware'
type Input = {
deviceId: string | number,
version: string,
fullVersion: string,
provider: number,
}
type Result = *

12
src/commands/getIsGenuine.js

@ -2,23 +2,19 @@
import { createCommand, Command } from 'helpers/ipc'
import { fromPromise } from 'rxjs/observable/fromPromise'
import type { DeviceInfo } from 'helpers/devices/getDeviceInfo'
import getIsGenuine from 'helpers/devices/getIsGenuine'
import { withDevice } from 'helpers/deviceAccess'
type Input = {
devicePath: string,
targetId: string | number,
version: string,
deviceInfo: DeviceInfo,
}
type Result = string
const cmd: Command<Input, Result> = createCommand(
'getIsGenuine',
({ devicePath, targetId, version }) =>
fromPromise(
withDevice(devicePath)(transport => getIsGenuine(transport, { targetId, version })),
),
const cmd: Command<Input, Result> = createCommand('getIsGenuine', ({ devicePath, deviceInfo }) =>
fromPromise(withDevice(devicePath)(transport => getIsGenuine(transport, deviceInfo))),
)
export default cmd

8
src/commands/getLatestFirmwareForDevice.js

@ -2,17 +2,13 @@
import { createCommand, Command } from 'helpers/ipc'
import { fromPromise } from 'rxjs/observable/fromPromise'
import type { DeviceInfo } from 'helpers/devices/getDeviceInfo'
import getLatestFirmwareForDevice from '../helpers/devices/getLatestFirmwareForDevice'
type Input = {
targetId: string | number,
version: string,
}
type Result = *
const cmd: Command<Input, Result> = createCommand('getLatestFirmwareForDevice', data =>
const cmd: Command<DeviceInfo, Result> = createCommand('getLatestFirmwareForDevice', data =>
fromPromise(getLatestFirmwareForDevice(data)),
)

8
src/commands/listApps.js

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

2
src/components/EnsureDeviceApp/index.js

@ -159,7 +159,7 @@ class EnsureDeviceApp extends PureComponent<Props, State> {
}
} else {
logger.warn('EnsureDeviceApp for using dashboard is DEPRECATED !!!')
// FIXME REMOVE THIS ! should use EnsureDashboard dedicated component.
// TODO: FIXME REMOVE THIS ! should use EnsureDashboard dedicated component.
const isDashboard = isDashboardOpen.send({ devicePath: deviceSelected.path }).toPromise()
if (!isDashboard) {

7
src/components/ManagerPage/AppsList.js

@ -48,7 +48,8 @@ type Props = {
device: Device,
targetId: string | number,
t: T,
version: string,
fullVersion: string,
provider: number,
}
type State = {
@ -82,8 +83,8 @@ class AppsList extends PureComponent<Props, State> {
async fetchAppList() {
try {
const { targetId, version } = this.props
const appsList = await listApps.send({ targetId, version }).toPromise()
const { targetId, fullVersion, provider } = this.props
const appsList = await listApps.send({ targetId, fullVersion, provider }).toPromise()
if (!this._unmounted) {
this.setState({ appsList, status: 'idle', appsLoaded: true })
}

5
src/components/ManagerPage/Dashboard.js

@ -34,10 +34,7 @@ const Dashboard = ({ device, deviceInfo, t }: Props) => (
</Text>
</Box>
<Box mt={5}>
<FirmwareUpdate
infos={{ targetId: deviceInfo.targetId, version: deviceInfo.version }}
device={device}
/>
<FirmwareUpdate deviceInfo={deviceInfo} device={device} />
</Box>
<Box mt={5}>
<AppsList device={device} targetId={deviceInfo.targetId} version={deviceInfo.version} />

23
src/components/ManagerPage/FirmwareUpdate.js

@ -14,6 +14,7 @@ import type { LedgerScriptParams } from 'helpers/common'
import getLatestFirmwareForDevice from 'commands/getLatestFirmwareForDevice'
import installOsuFirmware from 'commands/installOsuFirmware'
import type { DeviceInfo } from 'helpers/devices/getDeviceInfo'
import Box, { Card } from 'components/base/Box'
import Text from 'components/base/Text'
@ -32,17 +33,12 @@ 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,
infos: DeviceInfos,
deviceInfo: DeviceInfo,
}
type State = {
@ -73,12 +69,9 @@ class FirmwareUpdate extends PureComponent<Props, State> {
_unmounting = false
fetchLatestFirmware = async () => {
const { infos } = this.props
const { deviceInfo } = this.props
const latestFirmware =
CACHED_LATEST_FIRMWARE ||
(await getLatestFirmwareForDevice
.send({ targetId: infos.targetId, version: infos.version })
.toPromise())
CACHED_LATEST_FIRMWARE || (await getLatestFirmwareForDevice.send(deviceInfo).toPromise())
if (
!isEmpty(latestFirmware) &&
!isEqual(this.state.latestFirmware, latestFirmware) &&
@ -92,14 +85,14 @@ class FirmwareUpdate extends PureComponent<Props, State> {
installFirmware = async () => {
try {
const { latestFirmware } = this.state
const { infos } = this.props
const { deviceInfo } = this.props
invariant(latestFirmware, 'did not find a new firmware or firmware is not set')
const {
device: { path: devicePath },
} = this.props
this.setState({ modal: 'installing' })
const { success } = await installOsuFirmware
.send({ devicePath, firmware: latestFirmware, targetId: infos.targetId })
.send({ devicePath, firmware: latestFirmware, targetId: deviceInfo.targetId })
.toPromise()
if (success) {
this.fetchLatestFirmware()
@ -150,7 +143,7 @@ class FirmwareUpdate extends PureComponent<Props, State> {
}
render() {
const { infos, t } = this.props
const { deviceInfo, t } = this.props
const { latestFirmware, modal } = this.state
return (
@ -170,7 +163,7 @@ class FirmwareUpdate extends PureComponent<Props, State> {
</Box>
<Text ff="Open Sans|SemiBold" fontSize={2}>
{t('app:manager.firmware.installed', {
version: infos.version,
version: deviceInfo.fullVersion,
})}
</Text>
</Box>

19
src/components/Workflow/EnsureGenuine.js

@ -5,6 +5,7 @@ import isEqual from 'lodash/isEqual'
import { GENUINE_TIMEOUT } from 'config/constants'
import type { Device } from 'types/common'
import type { DeviceInfo } from 'helpers/devices/getDeviceInfo'
import getIsGenuine from 'commands/getIsGenuine'
@ -13,15 +14,9 @@ type Error = {
stack: string,
}
type DeviceInfos = {
targetId: number | string,
seVersion: string,
providerName: string,
}
type Props = {
device: ?Device,
infos: ?DeviceInfos,
deviceInfo: ?DeviceInfo,
children: (isGenuine: ?boolean, error: ?Error) => *,
}
@ -57,18 +52,14 @@ class EnsureGenuine extends PureComponent<Props, State> {
_unmounting = false
async checkIsGenuine() {
const { device, infos } = this.props
if (device && infos && !this._checking) {
const { device, deviceInfo } = this.props
if (device && deviceInfo && !this._checking) {
this._checking = true
try {
const versionName = `${infos.seVersion}${
infos.providerName ? `-${infos.providerName}` : ''
}`
const res = await getIsGenuine
.send({
devicePath: device.path,
targetId: infos.targetId,
version: versionName,
deviceInfo,
})
.pipe(timeout(GENUINE_TIMEOUT))
.toPromise()

2
src/components/Workflow/index.js

@ -58,7 +58,7 @@ class Workflow extends PureComponent<Props, State> {
}
return (
<EnsureGenuine device={device} infos={deviceInfo}>
<EnsureGenuine device={device} deviceInfo={deviceInfo}>
{(isGenuine: ?boolean, genuineError: ?Error) => {
if (dashboardError || genuineError) {
return renderError

11
src/helpers/apps/listApps.js

@ -5,11 +5,14 @@ import { APPLICATIONS_BY_DEVICE } from 'helpers/urls'
import getDeviceVersion from 'helpers/devices/getDeviceVersion'
import getCurrentFirmware from 'helpers/devices/getCurrentFirmware'
export default async (targetId: string | number, version: string) => {
export default async (targetId: string | number, fullVersion: string, provider: number) => {
try {
const provider = 1
const deviceData = await getDeviceVersion(targetId)
const firmwareData = await getCurrentFirmware({ deviceId: deviceData.id, version })
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,

8
src/helpers/devices/getCurrentFirmware.js

@ -4,21 +4,21 @@ import network from 'api/network'
import { GET_CURRENT_FIRMWARE } from 'helpers/urls'
type Input = {
version: string,
fullVersion: string,
deviceId: string | number,
provider: number,
}
let error
export default async (input: Input): Promise<*> => {
try {
const provider = 1
const { data } = await network({
method: 'POST',
url: GET_CURRENT_FIRMWARE,
data: {
device_version: input.deviceId,
version_name: input.version,
provider,
version_name: input.fullVersion,
provider: input.provider,
},
})
return data

13
src/helpers/devices/getDeviceInfo.js

@ -12,6 +12,8 @@ export type DeviceInfo = {
mcuVersion: string,
isOSU: boolean,
providerName: string,
providerId: number,
fullVersion: string,
}
const DETECT_CLUBCOIN = [
@ -164,6 +166,13 @@ const DETECT_CLUBCOIN = [
],
]
const PROVIDERS = {
'': 1,
das: 2,
club: 3,
shitcoins: 4,
}
export default async (transport: Transport<*>): Promise<DeviceInfo> => {
const res = await getFirmwareInfo(transport)
let { seVersion } = res
@ -181,9 +190,11 @@ export default async (transport: Transport<*>): Promise<DeviceInfo> => {
const parsedVersion = seVersion.match(/[0-9]+.[0-9]+(.[0-9]+)?(-[a-z]+)?(-osu)?/) || []
const isOSU = typeof parsedVersion[5] !== 'undefined'
const providerName = parsedVersion[4] || ''
const providerId = PROVIDERS[providerName]
const isBootloader = targetId === 0x01000001
const majMin = parsedVersion[1]
const patch = parsedVersion[2] || '.0'
const fullVersion = `${seVersion}${providerName ? `-${providerName}` : ''}`
return {
targetId,
seVersion: majMin + patch,
@ -191,6 +202,8 @@ export default async (transport: Transport<*>): Promise<DeviceInfo> => {
mcuVersion,
isBootloader,
providerName,
providerId,
flags,
fullVersion,
}
}

3
src/helpers/devices/getDeviceVersion.js

@ -2,8 +2,7 @@
import { GET_DEVICE_VERSION } from 'helpers/urls'
import network from 'api/network'
export default async (targetId: string | number): Promise<*> => {
const provider = 1
export default async (targetId: string | number, provider: number): Promise<*> => {
const { data } = await network({
method: 'POST',
url: GET_DEVICE_VERSION,

18
src/helpers/devices/getIsGenuine.js

@ -2,21 +2,21 @@
import type Transport from '@ledgerhq/hw-transport'
import { SKIP_GENUINE } from 'config/constants'
import { WS_GENUINE } from 'helpers/urls'
import type { DeviceInfo } from 'helpers/devices/getDeviceInfo'
import { createDeviceSocket } from 'helpers/socket'
import getCurrentFirmware from './getCurrentFirmware'
import getDeviceVersion from './getDeviceVersion'
export default async (
transport: Transport<*>,
app: { targetId: string | number, version: string },
): Promise<string> => {
const { targetId, version } = app
const device = await getDeviceVersion(app.targetId)
const firmware = await getCurrentFirmware({ deviceId: device.id, version })
export default async (transport: Transport<*>, deviceInfo: DeviceInfo): Promise<string> => {
const deviceVersion = await getDeviceVersion(deviceInfo.targetId, deviceInfo.providerId)
const firmware = await getCurrentFirmware({
deviceId: deviceVersion.id,
fullVersion: deviceInfo.fullVersion,
provider: deviceInfo.providerId,
})
const params = {
targetId,
version,
targetId: deviceInfo.targetId,
perso: firmware.perso,
}
const url = WS_GENUINE(params)

20
src/helpers/devices/getLatestFirmwareForDevice.js

@ -1,24 +1,22 @@
// @flow
import network from 'api/network'
import { GET_LATEST_FIRMWARE } from 'helpers/urls'
import type { DeviceInfo } from 'helpers/devices/getDeviceInfo'
import getCurrentFirmware from './getCurrentFirmware'
import getDeviceVersion from './getDeviceVersion'
type Input = {
version: string,
targetId: string | number,
}
export default async (input: Input) => {
export default async (deviceInfo: DeviceInfo) => {
try {
const provider = 1
const { targetId, version } = input
// Get device infos from targetId
const deviceVersion = await getDeviceVersion(targetId)
const deviceVersion = await getDeviceVersion(deviceInfo.targetId, deviceInfo.providerId)
// Get firmware infos with firmware name and device version
const seFirmwareVersion = await getCurrentFirmware({ version, deviceId: deviceVersion.id })
const seFirmwareVersion = await getCurrentFirmware({
fullVersion: deviceInfo.fullVersion,
deviceId: deviceVersion.id,
provider: deviceInfo.providerId,
})
// Fetch next possible firmware
const { data } = await network({
@ -27,7 +25,7 @@ export default async (input: Input) => {
data: {
current_se_firmware_final_version: seFirmwareVersion.id,
device_version: deviceVersion.id,
provider,
provider: deviceInfo.providerId,
},
})

4
src/helpers/devices/isDashboardOpen.js

@ -8,8 +8,8 @@ type Result = boolean
export default async (transport: Transport<*>): Promise<Result> => {
try {
const { targetId, version } = await getFirmwareInfo(transport)
if (targetId && version) {
const { targetId, seVersion } = await getFirmwareInfo(transport)
if (targetId && seVersion) {
return true
}

5
src/helpers/urls.js

@ -23,7 +23,10 @@ export const GET_LATEST_FIRMWARE: string = managerUrlbuilder('get_latest_firmwar
export const GET_NEXT_MCU: string = managerUrlbuilder('mcu_versions_bootloader')
export const WS_INSTALL: (arg: LedgerScriptParams) => string = wsURLBuilder('install')
export const WS_GENUINE: (arg: { targetId: string | number }) => string = wsURLBuilder('genuine')
export const WS_GENUINE: (arg: {
targetId: string | number,
perso: string,
}) => string = wsURLBuilder('genuine')
export const WS_MCU: (arg: { targetId: string | number, version: string }) => string = wsURLBuilder(
'mcu',
)

Loading…
Cancel
Save