Add fix to swap symbol and name for sidechains

This commit is contained in:
Daniel Sanchez 2021-03-30 10:01:36 +02:00
parent 15d98e2d84
commit 45d8157f90
1 changed files with 23 additions and 2 deletions

View File

@ -1,9 +1,11 @@
import axios from 'axios'
import { getSafeClientGatewayBaseUrl } from 'src/config'
import { getSafeClientGatewayBaseUrl, getNetworkInfo } from 'src/config'
import { TokenProps } from 'src/logic/tokens/store/model/token'
import { checksumAddress } from 'src/utils/checksumAddress'
import { ZERO_ADDRESS, sameAddress } from 'src/logic/wallets/ethAddresses'
export type TokenBalance = {
tokenInfo: TokenProps
balance: string
@ -33,5 +35,24 @@ export const fetchTokenCurrenciesBalances = async ({
checksumAddress(safeAddress),
)}/balances/${selectedCurrency}/?trusted=${trustedTokens}&exclude_spam=${excludeSpamTokens}`
return axios.get(url).then(({ data }) => data)
return axios.get(url).then(({ data }) => {
// Currently the client-gateway is not returning the balance using network token symbol and name
// FIXME remove this logic and return data directly once this is fixed
const { nativeCoin } = getNetworkInfo()
if (data.items && data.items.length) {
data.items = data.items.map((element) => {
const { tokenInfo } = element
if (sameAddress(ZERO_ADDRESS, tokenInfo.address)) {
// If it's native coin we swap symbol and name
tokenInfo.symbol = nativeCoin.symbol
tokenInfo.name = nativeCoin.name
}
return element
})
}
return data
})
}