Fix currency fetch 400 error

This commit is contained in:
Mikhail Mikheev 2020-05-12 16:50:26 +04:00 committed by fernandomg
parent c2c100550f
commit 7c141ca1ad
3 changed files with 8 additions and 7 deletions

View File

@ -5,8 +5,8 @@ import { getExchangeRatesUrl } from '~/config'
import { AVAILABLE_CURRENCIES } from '~/logic/currencyValues/store/model/currencyValues' import { AVAILABLE_CURRENCIES } from '~/logic/currencyValues/store/model/currencyValues'
const fetchCurrenciesRates = async ( const fetchCurrenciesRates = async (
baseCurrency: AVAILABLE_CURRENCIES, baseCurrency: $Keys<typeof AVAILABLE_CURRENCIES>,
targetCurrencyValue: AVAILABLE_CURRENCIES, targetCurrencyValue: $Keys<typeof AVAILABLE_CURRENCIES>,
): Promise<number> => { ): Promise<number> => {
let rate = 0 let rate = 0
const url = `${getExchangeRatesUrl()}?base=${baseCurrency}&symbols=${targetCurrencyValue}` const url = `${getExchangeRatesUrl()}?base=${baseCurrency}&symbols=${targetCurrencyValue}`

View File

@ -1,5 +1,5 @@
// @flow // @flow
import { Dispatch as ReduxDispatch } from 'redux' import { type Dispatch as ReduxDispatch } from 'redux'
import fetchCurrenciesRates from '~/logic/currencyValues/api/fetchCurrenciesRates' import fetchCurrenciesRates from '~/logic/currencyValues/api/fetchCurrenciesRates'
import { setCurrencyRate } from '~/logic/currencyValues/store/actions/setCurrencyRate' import { setCurrencyRate } from '~/logic/currencyValues/store/actions/setCurrencyRate'

View File

@ -3,13 +3,11 @@ import { List } from 'immutable'
import { batch } from 'react-redux' import { batch } from 'react-redux'
import type { Dispatch as ReduxDispatch } from 'redux' import type { Dispatch as ReduxDispatch } from 'redux'
import fetchCurrencyRate from '~/logic/currencyValues/store/actions/fetchCurrencyRate'
import { setCurrencyBalances } from '~/logic/currencyValues/store/actions/setCurrencyBalances' import { setCurrencyBalances } from '~/logic/currencyValues/store/actions/setCurrencyBalances'
import { setCurrencyRate } from '~/logic/currencyValues/store/actions/setCurrencyRate' import { setCurrencyRate } from '~/logic/currencyValues/store/actions/setCurrencyRate'
import { setSelectedCurrency } from '~/logic/currencyValues/store/actions/setSelectedCurrency' import { setSelectedCurrency } from '~/logic/currencyValues/store/actions/setSelectedCurrency'
import { AVAILABLE_CURRENCIES } from '~/logic/currencyValues/store/model/currencyValues' import { AVAILABLE_CURRENCIES } from '~/logic/currencyValues/store/model/currencyValues'
import { loadCurrencyValues } from '~/logic/currencyValues/store/utils/currencyValuesStorage' import { loadCurrencyValues } from '~/logic/currencyValues/store/utils/currencyValuesStorage'
import fetchSafeTokens from '~/logic/tokens/store/actions/fetchSafeTokens'
import type { GlobalState } from '~/store' import type { GlobalState } from '~/store'
export const fetchCurrencyValues = (safeAddress: string) => async (dispatch: ReduxDispatch<GlobalState>) => { export const fetchCurrencyValues = (safeAddress: string) => async (dispatch: ReduxDispatch<GlobalState>) => {
@ -27,12 +25,15 @@ export const fetchCurrencyValues = (safeAddress: string) => async (dispatch: Red
Object.entries(storedCurrencies).forEach((kv) => { Object.entries(storedCurrencies).forEach((kv) => {
const safeAddr = kv[0] const safeAddr = kv[0]
const value = kv[1] const value = kv[1]
if (!Object.keys(value).length) {
return
}
const { currencyRate, selectedCurrency } = value const { currencyRate, selectedCurrency } = value
batch(() => { batch(() => {
dispatch(setSelectedCurrency(safeAddr, selectedCurrency)) dispatch(setSelectedCurrency(safeAddr, selectedCurrency))
dispatch(setCurrencyRate(safeAddr, currencyRate)) dispatch(setCurrencyRate(safeAddr, currencyRate))
dispatch(fetchCurrencyRate(safeAddr, selectedCurrency))
dispatch(fetchSafeTokens(safeAddress))
}) })
}) })
} catch (err) { } catch (err) {