diff --git a/src/logic/currencyValues/__tests__/fetchSafeTokens.test.ts b/src/logic/currencyValues/__tests__/fetchSafeTokens.test.ts index 32bf362f..618cd12c 100644 --- a/src/logic/currencyValues/__tests__/fetchSafeTokens.test.ts +++ b/src/logic/currencyValues/__tests__/fetchSafeTokens.test.ts @@ -1,5 +1,5 @@ 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 { getTxServiceHost } from 'src/config' @@ -19,23 +19,25 @@ describe('fetchTokenCurrenciesBalances', () => { // given const expectedResult = [ { - balance: '849890000000000000', - balanceUsd: '337.2449', - token: null, tokenAddress: null, - usdConversion: '396.81', + token: null, + balance: '849890000000000000', + fiatBalance: '337.2449', + fiatConversion: '396.81', + fiatCode: 'USD', }, { - balance: '24698677800000000000', - balanceUsd: '29.3432', + tokenAddress: '0x5592EC0cfb4dbc12D3aB100b257153436a1f0FEa', token: { name: 'Dai', symbol: 'DAI', decimals: 18, logoUri: 'https://gnosis-safe-token-logos.s3.amazonaws.com/0x5592EC0cfb4dbc12D3aB100b257153436a1f0FEa.png', }, - tokenAddress: '0x5592EC0cfb4dbc12D3aB100b257153436a1f0FEa', - usdConversion: '1.188', + balance: '24698677800000000000', + fiatBalance: '29.3432', + fiatConversion: '1.188', + fiatCode: 'USD', }, ] const apiUrl = getTxServiceHost() diff --git a/src/logic/currencyValues/api/fetchCurrenciesRates.ts b/src/logic/currencyValues/api/fetchCurrenciesRates.ts index 00e2c48a..b39a5b74 100644 --- a/src/logic/currencyValues/api/fetchCurrenciesRates.ts +++ b/src/logic/currencyValues/api/fetchCurrenciesRates.ts @@ -2,7 +2,7 @@ import axios from 'axios' import { getExchangeRatesUrl } from 'src/config' import { AVAILABLE_CURRENCIES } from '../store/model/currencyValues' -import fetchTokenCurrenciesBalances from './fetchTokenCurrenciesBalances' +import { fetchTokenCurrenciesBalances } from './fetchTokenCurrenciesBalances' import BigNumber from 'bignumber.js' const fetchCurrenciesRates = async ( @@ -16,7 +16,7 @@ const fetchCurrenciesRates = async ( try { const result = await fetchTokenCurrenciesBalances(safeAddress) 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) { console.error('Fetching ETH data from the relayer errored', error) diff --git a/src/logic/currencyValues/api/fetchTokenCurrenciesBalances.ts b/src/logic/currencyValues/api/fetchTokenCurrenciesBalances.ts index c2804708..7e27cf2d 100644 --- a/src/logic/currencyValues/api/fetchTokenCurrenciesBalances.ts +++ b/src/logic/currencyValues/api/fetchTokenCurrenciesBalances.ts @@ -2,16 +2,18 @@ import axios, { AxiosResponse } from 'axios' import { getTxServiceHost } from 'src/config' import { TokenProps } from 'src/logic/tokens/store/model/token' +import { AVAILABLE_CURRENCIES } from '../store/model/currencyValues' export type BalanceEndpoint = { - balance: string - balanceUsd: string tokenAddress: string token?: TokenProps - usdConversion: string + balance: string + fiatBalance: string + fiatConversion: string + fiatCode: AVAILABLE_CURRENCIES } -const fetchTokenCurrenciesBalances = ( +export const fetchTokenCurrenciesBalances = ( safeAddress: string, excludeSpamTokens = true, ): Promise> => { @@ -24,5 +26,3 @@ const fetchTokenCurrenciesBalances = ( }, }) } - -export default fetchTokenCurrenciesBalances diff --git a/src/logic/tokens/store/actions/fetchSafeTokens.ts b/src/logic/tokens/store/actions/fetchSafeTokens.ts index 608256c6..55eca9e5 100644 --- a/src/logic/tokens/store/actions/fetchSafeTokens.ts +++ b/src/logic/tokens/store/actions/fetchSafeTokens.ts @@ -3,15 +3,12 @@ import { List, Map } from 'immutable' import { batch } from 'react-redux' import { Dispatch } from 'redux' -import fetchTokenCurrenciesBalances, { +import { + fetchTokenCurrenciesBalances, BalanceEndpoint, } from 'src/logic/currencyValues/api/fetchTokenCurrenciesBalances' import { setCurrencyBalances } from 'src/logic/currencyValues/store/actions/setCurrencyBalances' -import { - AVAILABLE_CURRENCIES, - CurrencyRateValueRecord, - makeBalanceCurrency, -} from 'src/logic/currencyValues/store/model/currencyValues' +import { CurrencyRateValueRecord, makeBalanceCurrency } from 'src/logic/currencyValues/store/model/currencyValues' import addTokens from 'src/logic/tokens/store/actions/saveTokens' import { makeToken, Token } from 'src/logic/tokens/store/model/token' import { TokenState } from 'src/logic/tokens/store/reducer/tokens' @@ -43,7 +40,7 @@ interface ExtractedData { const extractDataFromResult = (currentTokens: TokenState) => ( acc: ExtractedData, - { balance, balanceUsd, token, tokenAddress }: BalanceEndpoint, + { balance, fiatBalance, fiatCode, token, tokenAddress }: BalanceEndpoint, ): ExtractedData => { if (tokenAddress === null) { acc.ethBalance = humanReadableValue(balance, 18) @@ -57,10 +54,10 @@ const extractDataFromResult = (currentTokens: TokenState) => ( acc.currencyList = acc.currencyList.push( makeBalanceCurrency({ - currencyName: balanceUsd ? AVAILABLE_CURRENCIES.USD : undefined, + currencyName: fiatCode, tokenAddress, - balanceInBaseCurrency: balanceUsd, - balanceInSelectedCurrency: balanceUsd, + balanceInBaseCurrency: fiatBalance, + balanceInSelectedCurrency: fiatBalance, }), )