(Fix) #1587 - Ens mislabeled as eth (#1601)

* Fix fetch symbol for incoming txs

* Fix getting symbol promise from erc721

* Adda ens contract addresses for different networks
This commit is contained in:
Agustin Pane 2020-11-16 11:20:07 -03:00 committed by GitHub
parent 3c795462b7
commit 9f1dc37bbb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 10 deletions

View File

@ -1,4 +1,4 @@
import { getNetworkId } from 'src/config'
import { getNetworkId, getNetworkInfo } from 'src/config'
import { ETHEREUM_NETWORK } from 'src/config/networks/network.d'
import { nftAssetsListAddressesSelector } from 'src/logic/collectibles/store/selectors'
import { TxServiceModel } from 'src/logic/safe/store/actions/transactions/fetchTransactions/loadOutgoingTransactions'
@ -18,6 +18,14 @@ export const CK_ADDRESS = {
[ETHEREUM_NETWORK.RINKEBY]: '0x16baf0de678e52367adc69fd067e5edd1d33e3bf',
}
// Note: xDAI ENS is missing, once we have it we need to add it here
const ENS_CONTRACT_ADDRESS = {
[ETHEREUM_NETWORK.MAINNET]: '0x57f1887a8BF19b14fC0dF6Fd9B2acc9Af147eA85',
[ETHEREUM_NETWORK.RINKEBY]: '0x57f1887a8BF19b14fC0dF6Fd9B2acc9Af147eA85',
[ETHEREUM_NETWORK.ENERGY_WEB_CHAIN]: '0x0A6d64413c07E10E890220BBE1c49170080C6Ca0',
[ETHEREUM_NETWORK.VOLTA]: '0xd7CeF70Ba7efc2035256d828d5287e2D285CD1ac',
}
// safeTransferFrom(address,address,uint256)
export const SAFE_TRANSFER_FROM_WITHOUT_DATA_HASH = '42842e0e'
@ -50,12 +58,11 @@ export const getERC721Symbol = async (contractAddress: string): Promise<string>
try {
const ERC721token = await getERC721TokenContract()
const tokenInstance = await ERC721token.at(contractAddress)
tokenSymbol = tokenInstance.symbol()
tokenSymbol = await tokenInstance.symbol()
} catch (err) {
// If the contract address is an ENS token contract, we know that the ERC721 standard is not proper implemented
// The method symbol() is missing
const ENS_TOKEN_CONTRACT = '0x57f1887a8BF19b14fC0dF6Fd9B2acc9Af147eA85'
if (sameAddress(contractAddress, ENS_TOKEN_CONTRACT)) {
if (isENSContract(contractAddress)) {
return 'ENS'
}
console.error(`Failed to retrieve token symbol for ERC721 token ${contractAddress}`)
@ -64,6 +71,11 @@ export const getERC721Symbol = async (contractAddress: string): Promise<string>
return tokenSymbol
}
export const isENSContract = (contractAddress: string): boolean => {
const { id } = getNetworkInfo()
return sameAddress(contractAddress, ENS_CONTRACT_ADDRESS[id])
}
/**
* Verifies if the provided contract is a valid ERC721
* @param {string} contractAddress

View File

@ -10,6 +10,7 @@ import { web3ReadOnly } from 'src/logic/wallets/getWeb3'
import { makeIncomingTransaction } from 'src/logic/safe/store/models/incomingTransaction'
import fetchTransactions from 'src/logic/safe/store/actions/transactions/fetchTransactions/fetchTransactions'
import { TransactionTypes } from 'src/logic/safe/store/models/types/transaction'
import { isENSContract } from 'src/logic/collectibles/utils'
export type IncomingTxServiceModel = {
blockNumber: number
@ -76,12 +77,18 @@ const batchIncomingTxsTokenDataRequest = (txs: IncomingTxServiceModel[]) => {
batch.execute()
return Promise.all(whenTxsValues).then((txsValues) =>
txsValues.map(([tx, symbol, decimals, ethTx, ethTxReceipt]) => [
tx,
symbol ? symbol : nativeCoin.symbol,
decimals ? decimals : nativeCoin.decimals,
new bn(ethTx?.gasPrice ?? 0).times(ethTxReceipt?.gasUsed ?? 0),
]),
txsValues.map(([tx, symbolFetched, decimals, ethTx, ethTxReceipt]) => {
let symbol = symbolFetched
if (!symbolFetched) {
symbol = isENSContract(tx.tokenAddress) ? 'ENS' : nativeCoin.symbol
}
return [
tx,
symbol,
decimals ? decimals : nativeCoin.decimals,
new bn(ethTx?.gasPrice ?? 0).times(ethTxReceipt?.gasUsed ?? 0),
]
}),
)
}