diff --git a/src/commands/installApp.js b/src/commands/installApp.js
index c4f1df13..88844ae9 100644
--- a/src/commands/installApp.js
+++ b/src/commands/installApp.js
@@ -9,14 +9,17 @@ import installApp from 'helpers/apps/installApp'
import type { LedgerScriptParams } from 'helpers/common'
type Input = {
- appParams: LedgerScriptParams,
+ app: LedgerScriptParams,
devicePath: string,
+ targetId: string | number,
}
type Result = *
-const cmd: Command = createCommand('installApp', ({ devicePath, ...rest }) =>
- fromPromise(withDevice(devicePath)(transport => installApp(transport, rest))),
+const cmd: Command = createCommand(
+ 'installApp',
+ ({ devicePath, targetId, ...app }) =>
+ fromPromise(withDevice(devicePath)(transport => installApp(transport, targetId, app))),
)
export default cmd
diff --git a/src/commands/listApps.js b/src/commands/listApps.js
index b600aef4..e4d5a153 100644
--- a/src/commands/listApps.js
+++ b/src/commands/listApps.js
@@ -7,12 +7,13 @@ import listApps from 'helpers/apps/listApps'
type Input = {
targetId: string | number,
+ version: string,
}
type Result = *
-const cmd: Command = createCommand('listApps', ({ targetId }) =>
- fromPromise(listApps(targetId)),
+const cmd: Command = createCommand('listApps', ({ targetId, version }) =>
+ fromPromise(listApps(targetId, version)),
)
export default cmd
diff --git a/src/commands/uninstallApp.js b/src/commands/uninstallApp.js
index e8e3b3f7..573439fa 100644
--- a/src/commands/uninstallApp.js
+++ b/src/commands/uninstallApp.js
@@ -9,14 +9,17 @@ import uninstallApp from 'helpers/apps/uninstallApp'
import type { LedgerScriptParams } from 'helpers/common'
type Input = {
- appParams: LedgerScriptParams,
+ app: LedgerScriptParams,
devicePath: string,
+ targetId: string | number,
}
type Result = *
-const cmd: Command = createCommand('uninstallApp', ({ devicePath, ...rest }) =>
- fromPromise(withDevice(devicePath)(transport => uninstallApp(transport, rest))),
+const cmd: Command = createCommand(
+ 'uninstallApp',
+ ({ devicePath, targetId, ...rest }) =>
+ fromPromise(withDevice(devicePath)(transport => uninstallApp(transport, targetId, rest))),
)
export default cmd
diff --git a/src/components/ManagerPage/AppSearchBar.js b/src/components/ManagerPage/AppSearchBar.js
index 4dcdd81b..e728a91a 100644
--- a/src/components/ManagerPage/AppSearchBar.js
+++ b/src/components/ManagerPage/AppSearchBar.js
@@ -4,6 +4,8 @@ import styled from 'styled-components'
import { color, fontSize, space } from 'styled-system'
import fontFamily from 'styles/styled/fontFamily'
+import type { LedgerScriptParams } from 'helpers/common'
+
import { ff } from 'styles/helpers'
import Box from 'components/base/Box'
@@ -12,20 +14,9 @@ import Search from 'components/base/Search'
import SearchIcon from 'icons/Search'
import CrossIcon from 'icons/Cross'
-type LedgerApp = {
- name: string,
- version: string,
- icon: string,
- app: Object,
- bolos_version: {
- min: number,
- max: number,
- },
-}
-
type Props = {
- list: Array,
- children: (list: Array) => React$Node,
+ list: Array,
+ children: (list: Array) => React$Node,
}
type State = {
diff --git a/src/components/ManagerPage/AppsList.js b/src/components/ManagerPage/AppsList.js
index 7e07312b..2333f396 100644
--- a/src/components/ManagerPage/AppsList.js
+++ b/src/components/ManagerPage/AppsList.js
@@ -6,6 +6,7 @@ import styled from 'styled-components'
import { translate } from 'react-i18next'
import type { Device, T } from 'types/common'
+import type { LedgerScriptParams } from 'helpers/common'
import listApps from 'commands/listApps'
import installApp from 'commands/installApp'
@@ -43,27 +44,17 @@ const ICONS_FALLBACK = {
type Status = 'loading' | 'idle' | 'busy' | 'success' | 'error'
type Mode = 'home' | 'installing' | 'uninstalling'
-type LedgerApp = {
- name: string,
- version: string,
- icon: string,
- app: Object,
- bolos_version: {
- min: number,
- max: number,
- },
-}
-
type Props = {
device: Device,
targetId: string | number,
t: T,
+ version: string,
}
type State = {
status: Status,
error: string | null,
- appsList: LedgerApp[],
+ appsList: LedgerScriptParams[] | Array<*>,
app: string,
mode: Mode,
}
@@ -89,8 +80,8 @@ class AppsList extends PureComponent {
async fetchAppList() {
try {
- const { targetId } = this.props
- const appsList = CACHED_APPS || (await listApps.send({ targetId }).toPromise())
+ const { targetId, version } = this.props
+ const appsList = CACHED_APPS || (await listApps.send({ targetId, version }).toPromise())
CACHED_APPS = appsList
if (!this._unmounted) {
this.setState({ appsList, status: 'idle' })
@@ -100,14 +91,14 @@ class AppsList extends PureComponent {
}
}
- handleInstallApp = (args: { app: any, name: string }) => async () => {
- const { app: appParams, name } = args
- this.setState({ status: 'busy', app: name, mode: 'installing' })
+ handleInstallApp = (app: LedgerScriptParams) => async () => {
+ this.setState({ status: 'busy', app: app.name, mode: 'installing' })
try {
const {
device: { path: devicePath },
+ targetId,
} = this.props
- const data = { appParams, devicePath }
+ const data = { app, devicePath, targetId }
await installApp.send(data).toPromise()
this.setState({ status: 'success', app: '' })
} catch (err) {
@@ -115,14 +106,14 @@ class AppsList extends PureComponent {
}
}
- handleUninstallApp = (args: { app: any, name: string }) => async () => {
- const { app: appParams, name } = args
- this.setState({ status: 'busy', app: name, mode: 'uninstalling' })
+ handleUninstallApp = (app: LedgerScriptParams) => async () => {
+ this.setState({ status: 'busy', app: app.name, mode: 'uninstalling' })
try {
const {
device: { path: devicePath },
+ targetId,
} = this.props
- const data = { appParams, devicePath }
+ const data = { app, devicePath, targetId }
await uninstallApp.send(data).toPromise()
this.setState({ status: 'success', app: '' })
} catch (err) {
@@ -192,7 +183,7 @@ class AppsList extends PureComponent {
{items.map(c => (
(
-
+ /> */}
-
+
)
diff --git a/src/components/Workflow/index.js b/src/components/Workflow/index.js
index 0fe0cbbf..e3db974f 100644
--- a/src/components/Workflow/index.js
+++ b/src/components/Workflow/index.js
@@ -34,6 +34,7 @@ type Props = {
renderMcuUpdate?: (device: Device, deviceInfo: DeviceInfo) => Node,
renderFinalUpdate?: (device: Device, deviceInfo: DeviceInfo) => Node,
renderDashboard?: (device: Device, deviceInfo: DeviceInfo, isGenuine: boolean) => Node,
+ onGenuineCheck?: (isGenuine: boolean) => void,
renderError?: (dashboardError: ?Error, genuineError: ?Error) => Node,
}
type State = {}
@@ -47,14 +48,13 @@ class Workflow extends PureComponent {
renderMcuUpdate,
renderError,
renderDefault,
+ onGenuineCheck,
} = this.props
return (
{(device: Device) => (
{(deviceInfo: ?DeviceInfo, dashboardError: ?Error) => {
- console.log('deviceInfo', deviceInfo)
-
if (deviceInfo && deviceInfo.mcu && renderMcuUpdate) {
return renderMcuUpdate(device, deviceInfo)
}
diff --git a/src/helpers/apps/installApp.js b/src/helpers/apps/installApp.js
index 89373c42..2183d639 100644
--- a/src/helpers/apps/installApp.js
+++ b/src/helpers/apps/installApp.js
@@ -2,7 +2,7 @@
import qs from 'qs'
import type Transport from '@ledgerhq/hw-transport'
-import { BASE_SOCKET_URL } from 'helpers/constants'
+import { BASE_SOCKET_URL_SECURE } from 'config/constants'
import { createDeviceSocket } from 'helpers/socket'
import type { LedgerScriptParams } from 'helpers/common'
@@ -12,8 +12,14 @@ import type { LedgerScriptParams } from 'helpers/common'
*/
export default async function installApp(
transport: Transport<*>,
- { appParams }: { appParams: LedgerScriptParams },
+ targetId: string | number,
+ { app }: { app: LedgerScriptParams },
): Promise<*> {
- const url = `${BASE_SOCKET_URL}/install?${qs.stringify(appParams)}`
+ const params = {
+ targetId,
+ ...app,
+ firmwareKey: app.firmware_key,
+ }
+ const url = `${BASE_SOCKET_URL_SECURE}/install?${qs.stringify(params)}`
return createDeviceSocket(transport, url).toPromise()
}
diff --git a/src/helpers/apps/listApps.js b/src/helpers/apps/listApps.js
index becd8373..55ba298d 100644
--- a/src/helpers/apps/listApps.js
+++ b/src/helpers/apps/listApps.js
@@ -1,20 +1,31 @@
// @flow
import axios from 'axios'
-import { MANAGER_API_BASE } from 'config/constants'
+import {
+ DEVICE_VERSION_BY_TARGET_ID,
+ APPLICATIONS_BY_DEVICE,
+ FIRMWARE_FINAL_VERSIONS_NAME,
+} from 'helpers/urls'
-export default async (targetId: string | number) => {
+export default async (targetId: string | number, version: string) => {
try {
- const { data: deviceData } = await axios.get(
- `${MANAGER_API_BASE}/device_versions_target_id/${targetId}`,
- )
- const { data } = await axios.get('https://api.ledgerwallet.com/update/applications')
-
- if (deviceData.name in data) {
- return data[deviceData.name]
- }
-
- return data['nanos-1.4']
+ const provider = 1
+ const { data: deviceData } = await axios.post(DEVICE_VERSION_BY_TARGET_ID, {
+ provider,
+ target_id: targetId,
+ })
+ const { data: firmwareData } = await axios.post(FIRMWARE_FINAL_VERSIONS_NAME, {
+ device_version: deviceData.id,
+ se_firmware_name: version,
+ })
+ const {
+ data: { application_versions },
+ } = await axios.post(APPLICATIONS_BY_DEVICE, {
+ providers: [1],
+ current_se_firmware_final_version: firmwareData.id,
+ device_version: deviceData.id,
+ })
+ return application_versions.length > 0 ? application_versions : []
} catch (err) {
const error = Error(err.message)
error.stack = err.stack
diff --git a/src/helpers/apps/uninstallApp.js b/src/helpers/apps/uninstallApp.js
index 113cd29c..570e361c 100644
--- a/src/helpers/apps/uninstallApp.js
+++ b/src/helpers/apps/uninstallApp.js
@@ -2,7 +2,7 @@
import qs from 'qs'
import type Transport from '@ledgerhq/hw-transport'
-import { BASE_SOCKET_URL } from 'helpers/constants'
+import { BASE_SOCKET_URL_SECURE } from 'config/constants'
import { createDeviceSocket } from 'helpers/socket'
import type { LedgerScriptParams } from 'helpers/common'
@@ -12,13 +12,15 @@ import type { LedgerScriptParams } from 'helpers/common'
*/
export default async function uninstallApp(
transport: Transport<*>,
- { appParams }: { appParams: LedgerScriptParams },
+ targetId: string | number,
+ { app }: { app: LedgerScriptParams },
): Promise<*> {
const params = {
- ...appParams,
- firmware: appParams.delete,
- firmwareKey: appParams.deleteKey,
+ targetId,
+ ...app,
+ firmware: app.delete,
+ firmwareKey: app.delete_key,
}
- const url = `${BASE_SOCKET_URL}/install?${qs.stringify(params)}`
+ const url = `${BASE_SOCKET_URL_SECURE}/install?${qs.stringify(params)}`
return createDeviceSocket(transport, url).toPromise()
}
diff --git a/src/helpers/common.js b/src/helpers/common.js
index 34b34f09..6966af72 100644
--- a/src/helpers/common.js
+++ b/src/helpers/common.js
@@ -16,10 +16,14 @@ const APDUS = {
export type LedgerScriptParams = {
firmware?: string,
- firmwareKey?: string,
+ firmware_key?: string,
delete?: string,
- deleteKey?: string,
+ delete_key?: string,
targetId?: string | number,
+ name: string,
+ version: string,
+ icon: string,
+ app?: number,
}
type FirmwareUpdateType = 'osu' | 'final'
diff --git a/src/helpers/devices/getIsGenuine.js b/src/helpers/devices/getIsGenuine.js
index 6e500142..86f9d70f 100644
--- a/src/helpers/devices/getIsGenuine.js
+++ b/src/helpers/devices/getIsGenuine.js
@@ -1,7 +1,7 @@
// @flow
import qs from 'qs'
import type Transport from '@ledgerhq/hw-transport'
-import { SKIP_GENUINE, MANAGER_API_BASE } from 'config/constants'
+import { SKIP_GENUINE, BASE_SOCKET_URL_SECURE } from 'config/constants'
import { createDeviceSocket } from 'helpers/socket'
@@ -9,7 +9,7 @@ export default async (
transport: Transport<*>,
params: { targetId: string | number },
): Promise => {
- const url = `${MANAGER_API_BASE}/genuine?${qs.stringify(params)}`
+ const url = `${BASE_SOCKET_URL_SECURE}/genuine?${qs.stringify(params)}`
return SKIP_GENUINE
? new Promise(resolve => setTimeout(() => resolve('0000'), 1000))
: createDeviceSocket(transport, url).toPromise()
diff --git a/src/helpers/firmware/installFinalFirmware.js b/src/helpers/firmware/installFinalFirmware.js
index 9247646d..7eed7932 100644
--- a/src/helpers/firmware/installFinalFirmware.js
+++ b/src/helpers/firmware/installFinalFirmware.js
@@ -2,7 +2,7 @@
import qs from 'qs'
import type Transport from '@ledgerhq/hw-transport'
-import { BASE_SOCKET_URL } from 'helpers/constants'
+import { BASE_SOCKET_URL_SECURE } from 'config/constants'
import { createDeviceSocket } from 'helpers/socket'
import { buildParamsFromFirmware } from 'helpers/common'
@@ -14,7 +14,7 @@ const buildFinalParams = buildParamsFromFirmware('final')
export default async (transport: Transport<*>, firmware: Input): Result => {
try {
const finalData = buildFinalParams(firmware)
- const url = `${BASE_SOCKET_URL}/install?${qs.stringify(finalData)}`
+ const url = `${BASE_SOCKET_URL_SECURE}/install?${qs.stringify(finalData)}`
await createDeviceSocket(transport, url).toPromise()
return { success: true }
} catch (err) {
diff --git a/src/helpers/firmware/installMcu.js b/src/helpers/firmware/installMcu.js
index bb9a9d81..56fe5448 100644
--- a/src/helpers/firmware/installMcu.js
+++ b/src/helpers/firmware/installMcu.js
@@ -2,7 +2,7 @@
import qs from 'qs'
import type Transport from '@ledgerhq/hw-transport'
-import { MANAGER_API_URL } from 'helpers/constants'
+import { MANAGER_API_BASE } from 'config/constants'
import { createDeviceSocket } from 'helpers/socket'
type Result = Promise<*>
@@ -11,6 +11,6 @@ export default async (
transport: Transport<*>,
params: { targetId: string | number, version: string },
): Result => {
- const url = `${MANAGER_API_URL}/mcu?${qs.stringify(params)}`
+ const url = `${MANAGER_API_BASE}/mcu?${qs.stringify(params)}`
return createDeviceSocket(transport, url).toPromise()
}
diff --git a/src/helpers/firmware/installOsuFirmware.js b/src/helpers/firmware/installOsuFirmware.js
index 24c26b91..d86eb5ce 100644
--- a/src/helpers/firmware/installOsuFirmware.js
+++ b/src/helpers/firmware/installOsuFirmware.js
@@ -2,7 +2,7 @@
import qs from 'qs'
import type Transport from '@ledgerhq/hw-transport'
-import { BASE_SOCKET_URL } from 'helpers/constants'
+import { BASE_SOCKET_URL_SECURE } from 'config/constants'
import { createDeviceSocket } from 'helpers/socket'
import { buildParamsFromFirmware } from 'helpers/common'
@@ -15,7 +15,7 @@ const buildOsuParams = buildParamsFromFirmware('osu')
export default async (transport: Transport<*>, firmware: Input): Result => {
try {
const osuData = buildOsuParams(firmware)
- const url = `${BASE_SOCKET_URL}/install?${qs.stringify(osuData)}`
+ const url = `${BASE_SOCKET_URL_SECURE}/install?${qs.stringify(osuData)}`
await createDeviceSocket(transport, url).toPromise()
return { success: true }
} catch (err) {
diff --git a/src/helpers/urls.js b/src/helpers/urls.js
new file mode 100644
index 00000000..0f322997
--- /dev/null
+++ b/src/helpers/urls.js
@@ -0,0 +1,18 @@
+// @flow
+import qs from 'qs'
+
+import { MANAGER_API_BASE, BASE_SOCKET_URL_SECURE } from 'config/constants'
+
+const urlBuilder = (base: string) => (endpoint: string): string => `${base}/${endpoint}`
+const managerUrlbuilder = urlBuilder(MANAGER_API_BASE)
+
+const wsURLBuilder = (endpoint: string) => (params?: Object) =>
+ `${BASE_SOCKET_URL_SECURE}/${endpoint}${params ? `?${qs.stringify(params)}` : ''}`
+
+export const DEVICE_VERSION_BY_TARGET_ID = managerUrlbuilder('device_versions_target_id')
+export const APPLICATIONS_BY_DEVICE = managerUrlbuilder('get_apps')
+export const FIRMWARE_FINAL_VERSIONS_NAME = managerUrlbuilder('firmware_final_versions_name')
+
+export const WS_INSTALL = wsURLBuilder('install')
+export const WS_GENUINE = wsURLBuilder('genuine')
+export const WS_MCU = wsURLBuilder('genuine')