Valentin D. Pinkman
7 years ago
14 changed files with 121 additions and 43 deletions
@ -0,0 +1,26 @@ |
|||||
|
// @flow
|
||||
|
import axios from 'axios' |
||||
|
|
||||
|
import { GET_NEXT_MCU } from 'helpers/urls' |
||||
|
import createCustomErrorClass from 'helpers/createCustomErrorClass' |
||||
|
|
||||
|
const LatestMCUInstalledError = createCustomErrorClass('LatestMCUInstalledError') |
||||
|
|
||||
|
export default async (bootloaderVersion: string): Promise<*> => { |
||||
|
try { |
||||
|
const { data } = await axios.post(GET_NEXT_MCU, { |
||||
|
bootloader_version: bootloaderVersion, |
||||
|
}) |
||||
|
|
||||
|
// FIXME: nextVersion will not be able to "default" when Error
|
||||
|
// handling is standardize on the API side
|
||||
|
if (data === 'default' || !data.name) { |
||||
|
throw new LatestMCUInstalledError('there is no next mcu version to install') |
||||
|
} |
||||
|
return data |
||||
|
} catch (err) { |
||||
|
const error = Error(err.message) |
||||
|
error.stack = err.stack |
||||
|
throw err |
||||
|
} |
||||
|
} |
@ -1,16 +1,23 @@ |
|||||
// @flow
|
// @flow
|
||||
import qs from 'qs' |
|
||||
import type Transport from '@ledgerhq/hw-transport' |
import type Transport from '@ledgerhq/hw-transport' |
||||
|
|
||||
import { MANAGER_API_BASE } from 'config/constants' |
import { WS_MCU } from 'helpers/urls' |
||||
import { createDeviceSocket } from 'helpers/socket' |
import { createDeviceSocket } from 'helpers/socket' |
||||
|
import getNextMCU from 'helpers/devices/getNextMCU' |
||||
|
|
||||
type Result = Promise<*> |
type Result = Promise<*> |
||||
|
|
||||
export default async ( |
export default async ( |
||||
transport: Transport<*>, |
transport: Transport<*>, |
||||
params: { targetId: string | number, version: string }, |
args: { targetId: string | number, version: string }, |
||||
): Result => { |
): Result => { |
||||
const url = `${MANAGER_API_BASE}/mcu?${qs.stringify(params)}` |
const { version } = args |
||||
|
const nextVersion = await getNextMCU(version) |
||||
|
|
||||
|
const params = { |
||||
|
targetId: args.targetId, |
||||
|
version: nextVersion.name, |
||||
|
} |
||||
|
const url = WS_MCU(params) |
||||
return createDeviceSocket(transport, url).toPromise() |
return createDeviceSocket(transport, url).toPromise() |
||||
} |
} |
||||
|
Loading…
Reference in new issue