Merge pull request #1067 from gnosis/bug/2.3.1-outgoing-transactions-not-showing

Bug: 2.3.1 Outgoing transactions not showing
This commit is contained in:
Mikhail Mikheev 2020-06-26 14:32:58 +04:00 committed by GitHub
commit 941bed1423
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 20 deletions

View File

@ -1,4 +1,3 @@
import memoize from 'lodash.memoize'
import logo from 'src/assets/icons/icon_etherTokens.svg'
import generateBatchRequests from 'src/logic/contracts/generateBatchRequests'
import {
@ -26,7 +25,7 @@ export const getEthAsToken = (balance: string): Token => {
})
}
export const isAddressAToken = async (tokenAddress): Promise<boolean> => {
export const isAddressAToken = async (tokenAddress: string): Promise<boolean> => {
// SECOND APPROACH:
// They both seem to work the same
// const tokenContract = await getStandardTokenContract()
@ -45,36 +44,49 @@ export const isTokenTransfer = (tx: any): boolean => {
}
export const isSendERC721Transaction = (tx: any, txCode: string, knownTokens: any) => {
// "0x57f1887a8BF19b14fC0dF6Fd9B2acc9Af147eA85" - ens token contract, includes safeTransferFrom
// but no proper ERC721 standard implemented
return (
(txCode && txCode.includes(SAFE_TRANSFER_FROM_WITHOUT_DATA_HASH)) ||
(txCode &&
txCode.includes(SAFE_TRANSFER_FROM_WITHOUT_DATA_HASH) &&
tx.to !== '0x57f1887a8BF19b14fC0dF6Fd9B2acc9Af147eA85') ||
(isTokenTransfer(tx) && !knownTokens.get(tx.to))
)
}
export const getERC721Symbol = memoize(
async (contractAddress: string): Promise<string> => {
export const getERC721Symbol = async (contractAddress: string): Promise<string> => {
let tokenSymbol = 'UNKNOWN'
try {
const ERC721token = await getERC721TokenContract()
const tokenInstance = await ERC721token.at(contractAddress)
return tokenInstance.symbol()
},
)
tokenSymbol = tokenInstance.symbol()
} catch (err) {
console.error(`Failed to retrieve token symbol for ERC721 token ${contractAddress}`)
}
return tokenSymbol
}
export const getERC20DecimalsAndSymbol = async (
tokenAddress: string,
): Promise<{ decimals: number; symbol: string }> => {
const tokenInfos = await getTokenInfos(tokenAddress)
const tokenInfo = { decimals: 18, symbol: 'UNKNOWN' }
try {
const storedTokenInfo = await getTokenInfos(tokenAddress)
if (tokenInfos === null) {
const [tokenDecimals, tokenSymbol] = await generateBatchRequests({
abi: ALTERNATIVE_TOKEN_ABI,
address: tokenAddress,
methods: ['decimals', 'symbol'],
})
if (storedTokenInfo === null) {
const [tokenDecimals, tokenSymbol] = await generateBatchRequests({
abi: ALTERNATIVE_TOKEN_ABI,
address: tokenAddress,
methods: ['decimals', 'symbol'],
})
return { decimals: Number(tokenDecimals), symbol: tokenSymbol }
return { decimals: Number(tokenDecimals), symbol: tokenSymbol }
}
} catch (err) {
console.error(`Failed to retrieve token info for ERC20 token ${tokenAddress}`)
}
return { decimals: Number(tokenInfos.decimals), symbol: tokenInfos.symbol }
return tokenInfo
}
export const isSendERC20Transaction = async (

View File

@ -253,7 +253,20 @@ export const buildTx = async ({
const refundParams = await getRefundParams(tx, getERC20DecimalsAndSymbol)
const decodedParams = getDecodedParams(tx)
const confirmations = getConfirmations(tx)
const { decimals = 18, symbol = 'ETH' } = isSendERC20Tx ? await getERC20DecimalsAndSymbol(tx.to) : {}
let tokenDecimals = 18
let tokenSymbol = 'ETH'
try {
if (isSendERC20Tx) {
const { decimals, symbol } = await getERC20DecimalsAndSymbol(tx.to)
tokenDecimals = decimals
tokenSymbol = symbol
} else if (isSendERC721Tx) {
tokenSymbol = await getERC721Symbol(tx.to)
}
} catch (err) {
console.log(`Failed to retrieve token data from ${tx.to}`)
}
const txToStore = makeTransaction({
baseGas: tx.baseGas,
@ -263,7 +276,7 @@ export const buildTx = async ({
creationTx: tx.creationTx,
customTx: isCustomTx,
data: tx.data ? tx.data : EMPTY_DATA,
decimals,
decimals: tokenDecimals,
decodedParams,
executionDate: tx.executionDate,
executionTxHash: tx.transactionHash,
@ -286,7 +299,7 @@ export const buildTx = async ({
safeTxGas: tx.safeTxGas,
safeTxHash: tx.safeTxHash,
submissionDate: tx.submissionDate,
symbol: isSendERC721Tx ? await getERC721Symbol(tx.to) : symbol,
symbol: tokenSymbol,
upgradeTx: isUpgradeTx,
value: tx.value.toString(),
})