From cdc018bd34fcfb1c9f858ccfc0653852a58dca80 Mon Sep 17 00:00:00 2001 From: "Valentin D. Pinkman" Date: Mon, 11 Jun 2018 17:32:24 +0200 Subject: [PATCH] use new production api (temporary url) for commands --- src/commands/listApps.js | 11 +++++------ src/components/ManagerPage/AppsList.js | 6 +++--- src/helpers/apps/listApps.js | 16 ++++++++-------- src/helpers/constants.js | 1 + src/helpers/devices/getFirmwareInfo.js | 2 +- .../devices/getLatestFirmwareForDevice.js | 3 +-- 6 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/commands/listApps.js b/src/commands/listApps.js index c497111c..b600aef4 100644 --- a/src/commands/listApps.js +++ b/src/commands/listApps.js @@ -5,15 +5,14 @@ import { fromPromise } from 'rxjs/observable/fromPromise' import listApps from 'helpers/apps/listApps' -// type Input = { -// targetId: string | number, -// } +type Input = { + targetId: string | number, +} -type Input = * type Result = * -const cmd: Command = createCommand('listApps', () => - /* { targetId } */ fromPromise(listApps(/* targetId */)), +const cmd: Command = createCommand('listApps', ({ targetId }) => + fromPromise(listApps(targetId)), ) export default cmd diff --git a/src/components/ManagerPage/AppsList.js b/src/components/ManagerPage/AppsList.js index 1d8bf733..5e614894 100644 --- a/src/components/ManagerPage/AppsList.js +++ b/src/components/ManagerPage/AppsList.js @@ -46,7 +46,7 @@ type LedgerApp = { type Props = { device: Device, - // targetId: string | number, + targetId: string | number, t: T, } @@ -75,8 +75,8 @@ class AppsList extends PureComponent { async fetchAppList() { try { - // const { targetId } = this.props // TODO: REUSE THIS WHEN SERVER IS UP - const appsList = CACHED_APPS || (await listApps.send().toPromise()) + const { targetId } = this.props + const appsList = CACHED_APPS || (await listApps.send({ targetId }).toPromise()) CACHED_APPS = appsList if (!this._unmounted) { this.setState({ appsList, status: 'idle' }) diff --git a/src/helpers/apps/listApps.js b/src/helpers/apps/listApps.js index 7a5cf43e..edd54366 100644 --- a/src/helpers/apps/listApps.js +++ b/src/helpers/apps/listApps.js @@ -1,18 +1,18 @@ // @flow import axios from 'axios' -// const { API_BASE_URL } = process.env +import { API_BASE_URL } from 'helpers/constants' -export default async (/* targetId: string | number */) => { +export default async (targetId: string | number) => { try { - // const { data: deviceData } = await axios.get( - // `${API_BASE_URL}/device_versions_target_id/${targetId}`, - // ) + const { data: deviceData } = await axios.get( + `${API_BASE_URL}/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] - // } + if (deviceData.name in data) { + return data[deviceData.name] + } return data['nanos-1.4'] } catch (err) { diff --git a/src/helpers/constants.js b/src/helpers/constants.js index 2a669b8e..becafa8f 100644 --- a/src/helpers/constants.js +++ b/src/helpers/constants.js @@ -2,6 +2,7 @@ export const BASE_SOCKET_URL = 'ws://api.ledgerwallet.com' export const BASE_SOCKET_URL_TEMP = 'ws://manager.ledger.fr:3500' +export const API_BASE_URL = process.env.API_BASE_URL || 'https://beta.manager.live.ledger.fr/api' // If you want to test locally with https://github.com/LedgerHQ/ledger-update-python-api // export const BASE_SOCKET_URL = 'ws://localhost:3001/update' diff --git a/src/helpers/devices/getFirmwareInfo.js b/src/helpers/devices/getFirmwareInfo.js index 71e2ed02..f0fd05fa 100644 --- a/src/helpers/devices/getFirmwareInfo.js +++ b/src/helpers/devices/getFirmwareInfo.js @@ -2,7 +2,7 @@ import axios from 'axios' import isEmpty from 'lodash/isEmpty' -const { API_BASE_URL } = process.env +import { API_BASE_URL } from 'helpers/constants' type Input = { version: string, diff --git a/src/helpers/devices/getLatestFirmwareForDevice.js b/src/helpers/devices/getLatestFirmwareForDevice.js index 5711a2b8..9b081681 100644 --- a/src/helpers/devices/getLatestFirmwareForDevice.js +++ b/src/helpers/devices/getLatestFirmwareForDevice.js @@ -1,11 +1,10 @@ // @flow import axios from 'axios' import isEmpty from 'lodash/isEmpty' +import { API_BASE_URL } from 'helpers/constants' import getFirmwareInfo from './getFirmwareInfo' -const { API_BASE_URL } = process.env - type Input = { targetId: string | number, version: string,