diff --git a/src/logic/tokens/utils/tokenHelpers.ts b/src/logic/tokens/utils/tokenHelpers.ts index eab9ec7e..4fab2c79 100644 --- a/src/logic/tokens/utils/tokenHelpers.ts +++ b/src/logic/tokens/utils/tokenHelpers.ts @@ -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 => { +export const isAddressAToken = async (tokenAddress: string): Promise => { // 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 => { +export const getERC721Symbol = async (contractAddress: string): Promise => { + 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 ( diff --git a/src/routes/safe/store/actions/transactions/utils/transactionHelpers.ts b/src/routes/safe/store/actions/transactions/utils/transactionHelpers.ts index b5b7db88..ba8de692 100644 --- a/src/routes/safe/store/actions/transactions/utils/transactionHelpers.ts +++ b/src/routes/safe/store/actions/transactions/utils/transactionHelpers.ts @@ -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(), })