From 51f8eacd9a05e45b1bc126fd9d44d529dfba5b42 Mon Sep 17 00:00:00 2001 From: "Valentin D. Pinkman" Date: Fri, 27 Jul 2018 17:14:41 +0200 Subject: [PATCH] removed unwanted params for GET http calls, also removed helpers/common --- src/commands/installApp.js | 2 +- src/commands/uninstallApp.js | 2 +- src/components/ManagerPage/AppSearchBar.js | 2 +- src/components/ManagerPage/AppsList.js | 2 +- src/components/ManagerPage/FirmwareUpdate.js | 2 +- src/components/modals/UpdateFirmware/index.js | 2 +- src/helpers/apps/installApp.js | 9 ++++++--- src/helpers/apps/uninstallApp.js | 6 ++++-- src/helpers/devices/getDeviceInfo.js | 2 +- src/helpers/devices/getMemInfo.js | 2 +- src/helpers/devices/isDashboardOpen.js | 2 +- .../{common.js => firmware/getFirmwareInfo.js} | 16 +--------------- src/helpers/types.js | 14 ++++++++++++++ src/helpers/urls.js | 2 +- 14 files changed, 35 insertions(+), 30 deletions(-) rename src/helpers/{common.js => firmware/getFirmwareInfo.js} (79%) create mode 100644 src/helpers/types.js diff --git a/src/commands/installApp.js b/src/commands/installApp.js index 88844ae9..7fcc7db7 100644 --- a/src/commands/installApp.js +++ b/src/commands/installApp.js @@ -6,7 +6,7 @@ import { fromPromise } from 'rxjs/observable/fromPromise' import { withDevice } from 'helpers/deviceAccess' import installApp from 'helpers/apps/installApp' -import type { LedgerScriptParams } from 'helpers/common' +import type { LedgerScriptParams } from 'helpers/types' type Input = { app: LedgerScriptParams, diff --git a/src/commands/uninstallApp.js b/src/commands/uninstallApp.js index 573439fa..59a61a3d 100644 --- a/src/commands/uninstallApp.js +++ b/src/commands/uninstallApp.js @@ -6,7 +6,7 @@ import { withDevice } from 'helpers/deviceAccess' import uninstallApp from 'helpers/apps/uninstallApp' -import type { LedgerScriptParams } from 'helpers/common' +import type { LedgerScriptParams } from 'helpers/types' type Input = { app: LedgerScriptParams, diff --git a/src/components/ManagerPage/AppSearchBar.js b/src/components/ManagerPage/AppSearchBar.js index 2a1685b9..cad33077 100644 --- a/src/components/ManagerPage/AppSearchBar.js +++ b/src/components/ManagerPage/AppSearchBar.js @@ -3,7 +3,7 @@ import React, { PureComponent, Fragment } from 'react' import styled from 'styled-components' -import type { LedgerScriptParams } from 'helpers/common' +import type { LedgerScriptParams } from 'helpers/types' import Box from 'components/base/Box' import Space from 'components/base/Space' diff --git a/src/components/ManagerPage/AppsList.js b/src/components/ManagerPage/AppsList.js index d405c192..ae2644fe 100644 --- a/src/components/ManagerPage/AppsList.js +++ b/src/components/ManagerPage/AppsList.js @@ -7,7 +7,7 @@ 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 { LedgerScriptParams } from 'helpers/types' import type { DeviceInfo } from 'helpers/devices/getDeviceInfo' import { developerModeSelector } from 'reducers/settings' diff --git a/src/components/ManagerPage/FirmwareUpdate.js b/src/components/ManagerPage/FirmwareUpdate.js index 3f4b8bbc..c289054c 100644 --- a/src/components/ManagerPage/FirmwareUpdate.js +++ b/src/components/ManagerPage/FirmwareUpdate.js @@ -9,7 +9,7 @@ import invariant from 'invariant' import type { Device, T } from 'types/common' -import type { LedgerScriptParams } from 'helpers/common' +import type { LedgerScriptParams } from 'helpers/types' import type { StepId } from 'components/modals/UpdateFirmware' import getLatestFirmwareForDevice from 'commands/getLatestFirmwareForDevice' diff --git a/src/components/modals/UpdateFirmware/index.js b/src/components/modals/UpdateFirmware/index.js index bde990fa..b6aac554 100644 --- a/src/components/modals/UpdateFirmware/index.js +++ b/src/components/modals/UpdateFirmware/index.js @@ -10,7 +10,7 @@ import SyncSkipUnderPriority from 'components/SyncSkipUnderPriority' import type { StepProps as DefaultStepProps, Step } from 'components/base/Stepper' import type { ModalStatus } from 'components/ManagerPage/FirmwareUpdate' -import type { LedgerScriptParams } from 'helpers/common' +import type { LedgerScriptParams } from 'helpers/types' import { FreezeDeviceChangeEvents } from '../../ManagerPage/HookDeviceChange' import StepFullFirmwareInstall from './steps/01-step-install-full-firmware' diff --git a/src/helpers/apps/installApp.js b/src/helpers/apps/installApp.js index 7d81742b..b5bb00f9 100644 --- a/src/helpers/apps/installApp.js +++ b/src/helpers/apps/installApp.js @@ -5,9 +5,9 @@ import type Transport from '@ledgerhq/hw-transport' import { BASE_SOCKET_URL } from 'config/constants' import { createDeviceSocket } from 'helpers/socket' -import type { LedgerScriptParams } from 'helpers/common' +import type { LedgerScriptParams } from 'helpers/types' -import { createCustomErrorClass } from '../errors' +import { createCustomErrorClass } from 'helpers/errors' const ManagerNotEnoughSpaceError = createCustomErrorClass('ManagerNotEnoughSpace') const ManagerDeviceLockedError = createCustomErrorClass('ManagerDeviceLocked') @@ -41,8 +41,11 @@ export default async function installApp( ): Promise<*> { const params = { targetId, - ...app, + perso: app.perso, + deleteKey: app.delete_key, + firmware: app.firmware, firmwareKey: app.firmware_key, + hash: app.hash, } const url = `${BASE_SOCKET_URL}/install?${qs.stringify(params)}` return remapError(createDeviceSocket(transport, url).toPromise()) diff --git a/src/helpers/apps/uninstallApp.js b/src/helpers/apps/uninstallApp.js index 15bb93a0..5bf3dd68 100644 --- a/src/helpers/apps/uninstallApp.js +++ b/src/helpers/apps/uninstallApp.js @@ -5,7 +5,7 @@ import type Transport from '@ledgerhq/hw-transport' import { BASE_SOCKET_URL } from 'config/constants' import { createDeviceSocket } from 'helpers/socket' -import type { LedgerScriptParams } from 'helpers/common' +import type { LedgerScriptParams } from 'helpers/types' import { createCustomErrorClass } from '../errors' const ManagerDeviceLockedError = createCustomErrorClass('ManagerDeviceLocked') @@ -34,9 +34,11 @@ export default async function uninstallApp( ): Promise<*> { const params = { targetId, - ...app, + perso: app.perso, + deleteKey: app.delete_key, firmware: app.delete, firmwareKey: app.delete_key, + hash: app.hash, } const url = `${BASE_SOCKET_URL}/install?${qs.stringify(params)}` return remapError(createDeviceSocket(transport, url).toPromise()) diff --git a/src/helpers/devices/getDeviceInfo.js b/src/helpers/devices/getDeviceInfo.js index 2af475ee..c3972e3d 100644 --- a/src/helpers/devices/getDeviceInfo.js +++ b/src/helpers/devices/getDeviceInfo.js @@ -2,7 +2,7 @@ import type Transport from '@ledgerhq/hw-transport' -import { getFirmwareInfo } from 'helpers/common' +import getFirmwareInfo from 'helpers/firmware/getFirmwareInfo' import { FORCE_PROVIDER } from 'config/constants' export type DeviceInfo = { diff --git a/src/helpers/devices/getMemInfo.js b/src/helpers/devices/getMemInfo.js index bf0e2f45..04c5a833 100644 --- a/src/helpers/devices/getMemInfo.js +++ b/src/helpers/devices/getMemInfo.js @@ -2,7 +2,7 @@ import type Transport from '@ledgerhq/hw-transport' -import { getFirmwareInfo } from 'helpers/common' +import getFirmwareInfo from 'helpers/firmware/getFirmwareInfo' export default async function getMemInfos(transport: Transport<*>): Promise { const { targetId } = await getFirmwareInfo(transport) // eslint-disable-line diff --git a/src/helpers/devices/isDashboardOpen.js b/src/helpers/devices/isDashboardOpen.js index a10c76fd..e49d64d1 100644 --- a/src/helpers/devices/isDashboardOpen.js +++ b/src/helpers/devices/isDashboardOpen.js @@ -2,7 +2,7 @@ import type Transport from '@ledgerhq/hw-transport' -import { getFirmwareInfo } from 'helpers/common' +import getFirmwareInfo from 'helpers/firmware/getFirmwareInfo' type Result = boolean diff --git a/src/helpers/common.js b/src/helpers/firmware/getFirmwareInfo.js similarity index 79% rename from src/helpers/common.js rename to src/helpers/firmware/getFirmwareInfo.js index c8d8eaf0..fc3033a1 100644 --- a/src/helpers/common.js +++ b/src/helpers/firmware/getFirmwareInfo.js @@ -1,6 +1,5 @@ // @flow -// FIXME remove this file! 'helpers/common.js' RLY? :P import type Transport from '@ledgerhq/hw-transport' const APDUS = { @@ -10,23 +9,10 @@ const APDUS = { GET_FIRMWARE_FALLBACK: [0xe0, 0xc4, 0x00, 0x00], } -export type LedgerScriptParams = { - firmware?: string, - firmware_key?: string, - delete?: string, - delete_key?: string, - targetId?: string | number, - name: string, - version: string, - icon: string, - app?: number, - hash?: string, -} - /** * Retrieve targetId and firmware version from device */ -export async function getFirmwareInfo(transport: Transport<*>) { +export default async function getFirmwareInfo(transport: Transport<*>) { const res = await transport.send(...APDUS.GET_FIRMWARE) const byteArray = [...res] const data = byteArray.slice(0, byteArray.length - 2) diff --git a/src/helpers/types.js b/src/helpers/types.js new file mode 100644 index 00000000..56ac3f50 --- /dev/null +++ b/src/helpers/types.js @@ -0,0 +1,14 @@ +// @flow +export type LedgerScriptParams = { + firmware?: string, + firmware_key?: string, + delete?: string, + delete_key?: string, + targetId?: string | number, + name: string, + version: string, + icon: string, + app?: number, + hash?: string, + perso?: string, +} diff --git a/src/helpers/urls.js b/src/helpers/urls.js index c40da8eb..8d953b53 100644 --- a/src/helpers/urls.js +++ b/src/helpers/urls.js @@ -2,7 +2,7 @@ import qs from 'qs' import { MANAGER_API_BASE, BASE_SOCKET_URL } from 'config/constants' -import type { LedgerScriptParams } from 'helpers/common' +import type { LedgerScriptParams } from 'helpers/types' const urlBuilder = (base: string) => (endpoint: string): string => `${base}/${endpoint}`