mirror of
https://github.com/status-im/safe-react.git
synced 2025-01-12 19:14:08 +00:00
(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:
parent
eab0e73ac6
commit
b04ec4337b
@ -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()
|
||||
|
@ -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)
|
||||
|
@ -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<AxiosResponse<BalanceEndpoint[]>> => {
|
||||
@ -24,5 +26,3 @@ const fetchTokenCurrenciesBalances = (
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export default fetchTokenCurrenciesBalances
|
||||
|
@ -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,
|
||||
}),
|
||||
)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user