Browse Source

Merge pull request #902 from gre/fix-error-imprecision

Fix error imprecision in all Manager calls
master
Gaëtan Renaudeau 7 years ago
committed by GitHub
parent
commit
5c52d3b33d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      src/helpers/apps/listAppVersions.js
  2. 6
      src/helpers/apps/listApps.js
  3. 6
      src/helpers/apps/listCategories.js
  4. 6
      src/helpers/common.js
  5. 7
      src/helpers/devices/getCurrentFirmware.js
  6. 6
      src/helpers/devices/getLatestFirmwareForDevice.js
  7. 6
      src/helpers/devices/isDashboardOpen.js
  8. 6
      src/helpers/devices/shouldFlashMcu.js
  9. 6
      src/helpers/firmware/getMcus.js
  10. 6
      src/helpers/firmware/getNextMCU.js
  11. 2
      src/helpers/urls.js

6
src/helpers/apps/listAppVersions.js

@ -7,7 +7,6 @@ import getDeviceVersion from 'helpers/devices/getDeviceVersion'
import getCurrentFirmware from 'helpers/devices/getCurrentFirmware' import getCurrentFirmware from 'helpers/devices/getCurrentFirmware'
export default async (deviceInfo: DeviceInfo) => { export default async (deviceInfo: DeviceInfo) => {
try {
const deviceData = await getDeviceVersion(deviceInfo.targetId, deviceInfo.providerId) const deviceData = await getDeviceVersion(deviceInfo.targetId, deviceInfo.providerId)
const firmwareData = await getCurrentFirmware({ const firmwareData = await getCurrentFirmware({
deviceId: deviceData.id, deviceId: deviceData.id,
@ -23,9 +22,4 @@ export default async (deviceInfo: DeviceInfo) => {
data: { application_versions }, data: { application_versions },
} = await network({ method: 'POST', url: APPLICATIONS_BY_DEVICE, data: params }) } = await network({ method: 'POST', url: APPLICATIONS_BY_DEVICE, data: params })
return application_versions.length > 0 ? application_versions : [] return application_versions.length > 0 ? application_versions : []
} catch (err) {
const error = Error(err.message)
error.stack = err.stack
throw err
}
} }

6
src/helpers/apps/listApps.js

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

6
src/helpers/apps/listCategories.js

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

6
src/helpers/common.js

@ -27,7 +27,6 @@ export type LedgerScriptParams = {
* Retrieve targetId and firmware version from device * Retrieve targetId and firmware version from device
*/ */
export async function getFirmwareInfo(transport: Transport<*>) { export async function getFirmwareInfo(transport: Transport<*>) {
try {
const res = await transport.send(...APDUS.GET_FIRMWARE) const res = await transport.send(...APDUS.GET_FIRMWARE)
const byteArray = [...res] const byteArray = [...res]
const data = byteArray.slice(0, byteArray.length - 2) const data = byteArray.slice(0, byteArray.length - 2)
@ -62,9 +61,4 @@ export async function getFirmwareInfo(transport: Transport<*>) {
} }
return { targetId, seVersion, flags, mcuVersion } return { targetId, seVersion, flags, mcuVersion }
} catch (err) {
const error = new Error(err.message)
error.stack = err.stack
throw error
}
} }

7
src/helpers/devices/getCurrentFirmware.js

@ -9,9 +9,7 @@ type Input = {
provider: number, provider: number,
} }
let error
export default async (input: Input): Promise<*> => { export default async (input: Input): Promise<*> => {
try {
const { data } = await network({ const { data } = await network({
method: 'POST', method: 'POST',
url: GET_CURRENT_FIRMWARE, url: GET_CURRENT_FIRMWARE,
@ -22,9 +20,4 @@ export default async (input: Input): Promise<*> => {
}, },
}) })
return data return data
} catch (err) {
error = Error(err.message)
error.stack = err.stack
throw error
}
} }

6
src/helpers/devices/getLatestFirmwareForDevice.js

@ -10,7 +10,6 @@ import getCurrentFirmware from './getCurrentFirmware'
import getDeviceVersion from './getDeviceVersion' import getDeviceVersion from './getDeviceVersion'
export default async (deviceInfo: DeviceInfo) => { export default async (deviceInfo: DeviceInfo) => {
try {
// Get device infos from targetId // Get device infos from targetId
const deviceVersion = await getDeviceVersion(deviceInfo.targetId, deviceInfo.providerId) const deviceVersion = await getDeviceVersion(deviceInfo.targetId, deviceInfo.providerId)
@ -54,9 +53,4 @@ export default async (deviceInfo: DeviceInfo) => {
} }
return { ...se_firmware_osu_version, shouldFlashMcu: false } return { ...se_firmware_osu_version, shouldFlashMcu: false }
} catch (err) {
const error = Error(err.message)
error.stack = err.stack
throw error
}
} }

6
src/helpers/devices/isDashboardOpen.js

@ -7,16 +7,10 @@ import { getFirmwareInfo } from 'helpers/common'
type Result = boolean type Result = boolean
export default async (transport: Transport<*>): Promise<Result> => { export default async (transport: Transport<*>): Promise<Result> => {
try {
const { targetId, seVersion } = await getFirmwareInfo(transport) const { targetId, seVersion } = await getFirmwareInfo(transport)
if (targetId && seVersion) { if (targetId && seVersion) {
return true return true
} }
return false return false
} catch (err) {
const error = Error(err.message)
error.stack = err.stack
throw error
}
} }

6
src/helpers/devices/shouldFlashMcu.js

@ -10,7 +10,6 @@ import getOsuFirmware from './getOsuFirmware'
import getDeviceVersion from './getDeviceVersion' import getDeviceVersion from './getDeviceVersion'
export default async (deviceInfo: DeviceInfo): Promise<boolean> => { export default async (deviceInfo: DeviceInfo): Promise<boolean> => {
try {
// Get device infos from targetId // Get device infos from targetId
const deviceVersion = await getDeviceVersion(deviceInfo.targetId, deviceInfo.providerId) const deviceVersion = await getDeviceVersion(deviceInfo.targetId, deviceInfo.providerId)
@ -47,9 +46,4 @@ export default async (deviceInfo: DeviceInfo): Promise<boolean> => {
.map(mcu => mcu.id) .map(mcu => mcu.id)
return !seFirmwareFinalVersion.mcu_versions.includes(...currentMcuVersionId) return !seFirmwareFinalVersion.mcu_versions.includes(...currentMcuVersionId)
} catch (err) {
const error = Error(err.message)
error.stack = err.stack
throw error
}
} }

6
src/helpers/firmware/getMcus.js

@ -4,16 +4,10 @@ import network from 'api/network'
import { GET_MCUS } from 'helpers/urls' import { GET_MCUS } from 'helpers/urls'
export default async (): Promise<*> => { export default async (): Promise<*> => {
try {
const { data } = await network({ const { data } = await network({
method: 'GET', method: 'GET',
url: GET_MCUS, url: GET_MCUS,
}) })
return data return data
} catch (err) {
const error = Error(err.message)
error.stack = err.stack
throw err
}
} }

6
src/helpers/firmware/getNextMCU.js

@ -7,7 +7,6 @@ import { createCustomErrorClass } from 'helpers/errors'
const LatestMCUInstalledError = createCustomErrorClass('LatestMCUInstalledError') const LatestMCUInstalledError = createCustomErrorClass('LatestMCUInstalledError')
export default async (bootloaderVersion: string): Promise<*> => { export default async (bootloaderVersion: string): Promise<*> => {
try {
const { data } = await network({ const { data } = await network({
method: 'POST', method: 'POST',
url: GET_NEXT_MCU, url: GET_NEXT_MCU,
@ -22,9 +21,4 @@ export default async (bootloaderVersion: string): Promise<*> => {
throw new LatestMCUInstalledError('there is no next mcu version to install') throw new LatestMCUInstalledError('there is no next mcu version to install')
} }
return data return data
} catch (err) {
const error = Error(err.message)
error.stack = err.stack
throw err
}
} }

2
src/helpers/urls.js

@ -14,6 +14,8 @@ const wsURLBuilder = (endpoint: string) => (params?: Object) =>
// const wsURLBuilderProxy = (endpoint: string) => (params?: Object) => // const wsURLBuilderProxy = (endpoint: string) => (params?: Object) =>
// `ws://manager.ledger.fr:3501/${endpoint}${params ? `?${qs.stringify(params)}` : ''}` // `ws://manager.ledger.fr:3501/${endpoint}${params ? `?${qs.stringify(params)}` : ''}`
// FIXME we shouldn't do this here. we should just collocate these where it's used.
export const GET_FINAL_FIRMWARE: string = managerUrlbuilder('firmware_final_versions') export const GET_FINAL_FIRMWARE: string = managerUrlbuilder('firmware_final_versions')
export const GET_DEVICE_VERSION: string = managerUrlbuilder('get_device_version') export const GET_DEVICE_VERSION: string = managerUrlbuilder('get_device_version')
export const APPLICATIONS_BY_DEVICE: string = managerUrlbuilder('get_apps') export const APPLICATIONS_BY_DEVICE: string = managerUrlbuilder('get_apps')

Loading…
Cancel
Save