From 46c227881a4c23bedb9c1918a4f5e593f31da195 Mon Sep 17 00:00:00 2001 From: Mikhail Mikheev Date: Fri, 26 Jun 2020 13:22:34 +0400 Subject: [PATCH 1/3] hardcode ens contract address to isERC721Transaction function, fallback to 18/unknown in methods fetching token decimals --- src/logic/tokens/utils/tokenHelpers.ts | 43 +++++++++++++------ .../transactions/utils/transactionHelpers.ts | 16 +++++-- 2 files changed, 42 insertions(+), 17 deletions(-) diff --git a/src/logic/tokens/utils/tokenHelpers.ts b/src/logic/tokens/utils/tokenHelpers.ts index eab9ec7e..202d000b 100644 --- a/src/logic/tokens/utils/tokenHelpers.ts +++ b/src/logic/tokens/utils/tokenHelpers.ts @@ -26,7 +26,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 +45,51 @@ 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 => { - const ERC721token = await getERC721TokenContract() - const tokenInstance = await ERC721token.at(contractAddress) - return tokenInstance.symbol() + let tokenSymbol = 'UNKNOWN' + try { + const ERC721token = await getERC721TokenContract() + const tokenInstance = await ERC721token.at(contractAddress) + 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..99817565 100644 --- a/src/routes/safe/store/actions/transactions/utils/transactionHelpers.ts +++ b/src/routes/safe/store/actions/transactions/utils/transactionHelpers.ts @@ -253,7 +253,17 @@ 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' + if (isSendERC20Tx) { + const { decimals, symbol } = await getERC20DecimalsAndSymbol(tx.to) + tokenDecimals = decimals + tokenSymbol = symbol + } else if (isSendERC721Tx) { + const { symbol } = await getERC721Symbol(tx.to) + tokenSymbol = symbol + } const txToStore = makeTransaction({ baseGas: tx.baseGas, @@ -263,7 +273,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 +296,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(), }) From 728bcc3f8e29d51780e4b9c911f1b7b762f41956 Mon Sep 17 00:00:00 2001 From: Mikhail Mikheev Date: Fri, 26 Jun 2020 13:34:12 +0400 Subject: [PATCH 2/3] fix catching errors during retrieving token symbols/decimals --- src/config/development-mainnet.ts | 12 ++++----- src/logic/tokens/utils/tokenHelpers.ts | 25 ++++++++----------- .../transactions/utils/transactionHelpers.ts | 17 +++++++------ 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/config/development-mainnet.ts b/src/config/development-mainnet.ts index a26a7075..d24d20e1 100644 --- a/src/config/development-mainnet.ts +++ b/src/config/development-mainnet.ts @@ -1,11 +1,11 @@ // -import devConfig from './development' +import prodConfig from './production' import { TX_SERVICE_HOST, RELAY_API_URL } from 'src/config/names' -const devMainnetConfig = { - ...devConfig, - [TX_SERVICE_HOST]: 'https://safe-transaction.mainnet.staging.gnosisdev.com/api/v1/', - [RELAY_API_URL]: 'https://safe-relay.mainnet.staging.gnosisdev.com/api/v1/', +const prodMainnetConfig = { + ...prodConfig, + [TX_SERVICE_HOST]: 'https://safe-transaction.mainnet.gnosis.io/api/v1/', + [RELAY_API_URL]: 'https://safe-relay.gnosis.io/api/v1/', } -export default devMainnetConfig +export default prodMainnetConfig diff --git a/src/logic/tokens/utils/tokenHelpers.ts b/src/logic/tokens/utils/tokenHelpers.ts index 202d000b..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 { @@ -55,19 +54,17 @@ export const isSendERC721Transaction = (tx: any, txCode: string, knownTokens: an ) } -export const getERC721Symbol = memoize( - async (contractAddress: string): Promise => { - let tokenSymbol = 'UNKNOWN' - try { - const ERC721token = await getERC721TokenContract() - const tokenInstance = await ERC721token.at(contractAddress) - tokenSymbol = tokenInstance.symbol() - } catch (err) { - console.error(`Failed to retrieve token symbol for ERC721 token ${contractAddress}`) - } - return tokenSymbol - }, -) +export const getERC721Symbol = async (contractAddress: string): Promise => { + let tokenSymbol = 'UNKNOWN' + try { + const ERC721token = await getERC721TokenContract() + const tokenInstance = await ERC721token.at(contractAddress) + tokenSymbol = tokenInstance.symbol() + } catch (err) { + console.error(`Failed to retrieve token symbol for ERC721 token ${contractAddress}`) + } + return tokenSymbol +} export const getERC20DecimalsAndSymbol = async ( tokenAddress: string, diff --git a/src/routes/safe/store/actions/transactions/utils/transactionHelpers.ts b/src/routes/safe/store/actions/transactions/utils/transactionHelpers.ts index 99817565..ba8de692 100644 --- a/src/routes/safe/store/actions/transactions/utils/transactionHelpers.ts +++ b/src/routes/safe/store/actions/transactions/utils/transactionHelpers.ts @@ -256,13 +256,16 @@ export const buildTx = async ({ let tokenDecimals = 18 let tokenSymbol = 'ETH' - if (isSendERC20Tx) { - const { decimals, symbol } = await getERC20DecimalsAndSymbol(tx.to) - tokenDecimals = decimals - tokenSymbol = symbol - } else if (isSendERC721Tx) { - const { symbol } = await getERC721Symbol(tx.to) - tokenSymbol = symbol + 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({ From 00843b5c6603751801f05c762b893e691930d4ed Mon Sep 17 00:00:00 2001 From: Mikhail Mikheev Date: Fri, 26 Jun 2020 13:36:43 +0400 Subject: [PATCH 3/3] Fix dev mainnet config --- src/config/development-mainnet.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/config/development-mainnet.ts b/src/config/development-mainnet.ts index d24d20e1..a26a7075 100644 --- a/src/config/development-mainnet.ts +++ b/src/config/development-mainnet.ts @@ -1,11 +1,11 @@ // -import prodConfig from './production' +import devConfig from './development' import { TX_SERVICE_HOST, RELAY_API_URL } from 'src/config/names' -const prodMainnetConfig = { - ...prodConfig, - [TX_SERVICE_HOST]: 'https://safe-transaction.mainnet.gnosis.io/api/v1/', - [RELAY_API_URL]: 'https://safe-relay.gnosis.io/api/v1/', +const devMainnetConfig = { + ...devConfig, + [TX_SERVICE_HOST]: 'https://safe-transaction.mainnet.staging.gnosisdev.com/api/v1/', + [RELAY_API_URL]: 'https://safe-relay.mainnet.staging.gnosisdev.com/api/v1/', } -export default prodMainnetConfig +export default devMainnetConfig