(Feature) - Update balance endpoint parameter usage (#1482)

* Replaces old balanceUsd with fiatBalance and fiatCode on BalanceEndpoint API

* Update balance endpoint tests

Co-authored-by: Fernando <fernando.greco@gmail.com>
Co-authored-by: Daniel Sanchez <daniel.sanchez@gnosis.pm>
This commit is contained in:
Agustin Pane 2020-10-15 14:43:18 -03:00 committed by GitHub
parent eab0e73ac6
commit b04ec4337b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 27 deletions

View File

@ -1,5 +1,5 @@
import { aNewStore } from 'src/store' import { aNewStore } from 'src/store'
import fetchTokenCurrenciesBalances from 'src/logic/currencyValues/api/fetchTokenCurrenciesBalances' import { fetchTokenCurrenciesBalances } from 'src/logic/currencyValues/api/fetchTokenCurrenciesBalances'
import axios from 'axios' import axios from 'axios'
import { getTxServiceHost } from 'src/config' import { getTxServiceHost } from 'src/config'
@ -19,23 +19,25 @@ describe('fetchTokenCurrenciesBalances', () => {
// given // given
const expectedResult = [ const expectedResult = [
{ {
balance: '849890000000000000',
balanceUsd: '337.2449',
token: null,
tokenAddress: null, tokenAddress: null,
usdConversion: '396.81', token: null,
balance: '849890000000000000',
fiatBalance: '337.2449',
fiatConversion: '396.81',
fiatCode: 'USD',
}, },
{ {
balance: '24698677800000000000', tokenAddress: '0x5592EC0cfb4dbc12D3aB100b257153436a1f0FEa',
balanceUsd: '29.3432',
token: { token: {
name: 'Dai', name: 'Dai',
symbol: 'DAI', symbol: 'DAI',
decimals: 18, decimals: 18,
logoUri: 'https://gnosis-safe-token-logos.s3.amazonaws.com/0x5592EC0cfb4dbc12D3aB100b257153436a1f0FEa.png', logoUri: 'https://gnosis-safe-token-logos.s3.amazonaws.com/0x5592EC0cfb4dbc12D3aB100b257153436a1f0FEa.png',
}, },
tokenAddress: '0x5592EC0cfb4dbc12D3aB100b257153436a1f0FEa', balance: '24698677800000000000',
usdConversion: '1.188', fiatBalance: '29.3432',
fiatConversion: '1.188',
fiatCode: 'USD',
}, },
] ]
const apiUrl = getTxServiceHost() const apiUrl = getTxServiceHost()

View File

@ -2,7 +2,7 @@ import axios from 'axios'
import { getExchangeRatesUrl } from 'src/config' import { getExchangeRatesUrl } from 'src/config'
import { AVAILABLE_CURRENCIES } from '../store/model/currencyValues' import { AVAILABLE_CURRENCIES } from '../store/model/currencyValues'
import fetchTokenCurrenciesBalances from './fetchTokenCurrenciesBalances' import { fetchTokenCurrenciesBalances } from './fetchTokenCurrenciesBalances'
import BigNumber from 'bignumber.js' import BigNumber from 'bignumber.js'
const fetchCurrenciesRates = async ( const fetchCurrenciesRates = async (
@ -16,7 +16,7 @@ const fetchCurrenciesRates = async (
try { try {
const result = await fetchTokenCurrenciesBalances(safeAddress) const result = await fetchTokenCurrenciesBalances(safeAddress)
if (result?.data?.length) { if (result?.data?.length) {
rate = new BigNumber(1).div(result.data[0].usdConversion).toNumber() rate = new BigNumber(1).div(result.data[0].fiatConversion).toNumber()
} }
} catch (error) { } catch (error) {
console.error('Fetching ETH data from the relayer errored', error) console.error('Fetching ETH data from the relayer errored', error)

View File

@ -2,16 +2,18 @@ import axios, { AxiosResponse } from 'axios'
import { getTxServiceHost } from 'src/config' import { getTxServiceHost } from 'src/config'
import { TokenProps } from 'src/logic/tokens/store/model/token' import { TokenProps } from 'src/logic/tokens/store/model/token'
import { AVAILABLE_CURRENCIES } from '../store/model/currencyValues'
export type BalanceEndpoint = { export type BalanceEndpoint = {
balance: string
balanceUsd: string
tokenAddress: string tokenAddress: string
token?: TokenProps token?: TokenProps
usdConversion: string balance: string
fiatBalance: string
fiatConversion: string
fiatCode: AVAILABLE_CURRENCIES
} }
const fetchTokenCurrenciesBalances = ( export const fetchTokenCurrenciesBalances = (
safeAddress: string, safeAddress: string,
excludeSpamTokens = true, excludeSpamTokens = true,
): Promise<AxiosResponse<BalanceEndpoint[]>> => { ): Promise<AxiosResponse<BalanceEndpoint[]>> => {
@ -24,5 +26,3 @@ const fetchTokenCurrenciesBalances = (
}, },
}) })
} }
export default fetchTokenCurrenciesBalances

View File

@ -3,15 +3,12 @@ import { List, Map } from 'immutable'
import { batch } from 'react-redux' import { batch } from 'react-redux'
import { Dispatch } from 'redux' import { Dispatch } from 'redux'
import fetchTokenCurrenciesBalances, { import {
fetchTokenCurrenciesBalances,
BalanceEndpoint, BalanceEndpoint,
} from 'src/logic/currencyValues/api/fetchTokenCurrenciesBalances' } from 'src/logic/currencyValues/api/fetchTokenCurrenciesBalances'
import { setCurrencyBalances } from 'src/logic/currencyValues/store/actions/setCurrencyBalances' import { setCurrencyBalances } from 'src/logic/currencyValues/store/actions/setCurrencyBalances'
import { import { CurrencyRateValueRecord, makeBalanceCurrency } from 'src/logic/currencyValues/store/model/currencyValues'
AVAILABLE_CURRENCIES,
CurrencyRateValueRecord,
makeBalanceCurrency,
} from 'src/logic/currencyValues/store/model/currencyValues'
import addTokens from 'src/logic/tokens/store/actions/saveTokens' import addTokens from 'src/logic/tokens/store/actions/saveTokens'
import { makeToken, Token } from 'src/logic/tokens/store/model/token' import { makeToken, Token } from 'src/logic/tokens/store/model/token'
import { TokenState } from 'src/logic/tokens/store/reducer/tokens' import { TokenState } from 'src/logic/tokens/store/reducer/tokens'
@ -43,7 +40,7 @@ interface ExtractedData {
const extractDataFromResult = (currentTokens: TokenState) => ( const extractDataFromResult = (currentTokens: TokenState) => (
acc: ExtractedData, acc: ExtractedData,
{ balance, balanceUsd, token, tokenAddress }: BalanceEndpoint, { balance, fiatBalance, fiatCode, token, tokenAddress }: BalanceEndpoint,
): ExtractedData => { ): ExtractedData => {
if (tokenAddress === null) { if (tokenAddress === null) {
acc.ethBalance = humanReadableValue(balance, 18) acc.ethBalance = humanReadableValue(balance, 18)
@ -57,10 +54,10 @@ const extractDataFromResult = (currentTokens: TokenState) => (
acc.currencyList = acc.currencyList.push( acc.currencyList = acc.currencyList.push(
makeBalanceCurrency({ makeBalanceCurrency({
currencyName: balanceUsd ? AVAILABLE_CURRENCIES.USD : undefined, currencyName: fiatCode,
tokenAddress, tokenAddress,
balanceInBaseCurrency: balanceUsd, balanceInBaseCurrency: fiatBalance,
balanceInSelectedCurrency: balanceUsd, balanceInSelectedCurrency: fiatBalance,
}), }),
) )