Browse Source

We must always use network() not axios. avoid circular ref issue

master
Gaëtan Renaudeau 7 years ago
parent
commit
d89dc5437a
  1. 8
      src/components/modals/ReleaseNotes.js
  2. 4
      src/helpers/apps/listApps.js
  3. 14
      src/helpers/devices/getCurrentFirmware.js
  4. 21
      src/helpers/devices/getDeviceVersion.js
  5. 14
      src/helpers/devices/getLatestFirmwareForDevice.js
  6. 10
      src/helpers/devices/getNextMCU.js

8
src/components/modals/ReleaseNotes.js

@ -3,7 +3,7 @@ import React, { PureComponent } from 'react'
import { translate } from 'react-i18next'
import ReactMarkdown from 'react-markdown'
import styled from 'styled-components'
import axios from 'axios'
import network from 'api/network'
import { MODAL_RELEASES_NOTES } from 'config/constants'
import Modal, { ModalBody, ModalTitle, ModalContent, ModalFooter } from 'components/base/Modal'
@ -160,8 +160,10 @@ class ReleaseNotes extends PureComponent<Props, State> {
if (!this.loading) {
this.loading = true
axios
.get(`https://api.github.com/repos/LedgerHQ/ledger-live-desktop/releases/tags/v${version}`)
network({
method: 'GET',
url: `https://api.github.com/repos/LedgerHQ/ledger-live-desktop/releases/tags/v${version}`,
})
.then(response => {
const { body } = response.data

4
src/helpers/apps/listApps.js

@ -1,5 +1,5 @@
// @flow
import axios from 'axios'
import network from 'api/network'
import { APPLICATIONS_BY_DEVICE } from 'helpers/urls'
import getDeviceVersion from 'helpers/devices/getDeviceVersion'
@ -17,7 +17,7 @@ export default async (targetId: string | number, version: string) => {
}
const {
data: { application_versions },
} = await axios.post(APPLICATIONS_BY_DEVICE, params)
} = await network({ method: 'POST', url: APPLICATIONS_BY_DEVICE, data: params })
return application_versions.length > 0 ? application_versions : []
} catch (err) {
const error = Error(err.message)

14
src/helpers/devices/getCurrentFirmware.js

@ -1,5 +1,5 @@
// @flow
import axios from 'axios'
import network from 'api/network'
import { GET_CURRENT_FIRMWARE } from 'helpers/urls'
@ -12,10 +12,14 @@ let error
export default async (input: Input): Promise<*> => {
try {
const provider = 1
const { data } = await axios.post(GET_CURRENT_FIRMWARE, {
device_version: input.deviceId,
version_name: input.version,
provider,
const { data } = await network({
method: 'POST',
url: GET_CURRENT_FIRMWARE,
data: {
device_version: input.deviceId,
version_name: input.version,
provider,
},
})
return data
} catch (err) {

21
src/helpers/devices/getDeviceVersion.js

@ -1,19 +1,16 @@
// @flow
import axios from 'axios'
import { GET_DEVICE_VERSION } from 'helpers/urls'
import network from 'api/network'
export default async (targetId: string | number): Promise<*> => {
try {
const provider = 1
const { data } = await axios.post(GET_DEVICE_VERSION, {
const provider = 1
const { data } = await network({
method: 'POST',
url: GET_DEVICE_VERSION,
data: {
provider,
target_id: targetId,
})
return data
} catch (err) {
const error = Error(err.message)
error.stack = err.stack
throw err
}
},
})
return data
}

14
src/helpers/devices/getLatestFirmwareForDevice.js

@ -1,5 +1,5 @@
// @flow
import axios from 'axios'
import network from 'api/network'
import { GET_LATEST_FIRMWARE } from 'helpers/urls'
import getCurrentFirmware from './getCurrentFirmware'
@ -21,10 +21,14 @@ export default async (input: Input) => {
const seFirmwareVersion = await getCurrentFirmware({ version, deviceId: deviceVersion.id })
// Fetch next possible firmware
const { data } = await axios.post(GET_LATEST_FIRMWARE, {
current_se_firmware_final_version: seFirmwareVersion.id,
device_version: deviceVersion.id,
provider,
const { data } = await network({
method: 'POST',
url: GET_LATEST_FIRMWARE,
data: {
current_se_firmware_final_version: seFirmwareVersion.id,
device_version: deviceVersion.id,
provider,
},
})
if (data.result === 'null') {

10
src/helpers/devices/getNextMCU.js

@ -1,5 +1,5 @@
// @flow
import axios from 'axios'
import network from 'api/network'
import { GET_NEXT_MCU } from 'helpers/urls'
import createCustomErrorClass from 'helpers/createCustomErrorClass'
@ -8,8 +8,12 @@ const LatestMCUInstalledError = createCustomErrorClass('LatestMCUInstalledError'
export default async (bootloaderVersion: string): Promise<*> => {
try {
const { data } = await axios.post(GET_NEXT_MCU, {
bootloader_version: bootloaderVersion,
const { data } = await network({
method: 'POST',
url: GET_NEXT_MCU,
data: {
bootloader_version: bootloaderVersion,
},
})
// FIXME: nextVersion will not be able to "default" when Error

Loading…
Cancel
Save