(Fix) Wrong value for ERC-20 tokens transfers (#679)

The fix attempts to properly differentiate an ERC-721 from an ERC-20 token transaction by identifying if it's a `transfer` transaction looking for a `decimals` method in its code. It the later is not found, then it's considered an ERC-721.

fixes #678
This commit is contained in:
Fernando 2020-03-20 12:46:12 -03:00 committed by GitHub
parent 29fbe383f8
commit c4cc79c682
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 4 deletions

View File

@ -6,6 +6,9 @@ import { type Token, makeToken } from '~/logic/tokens/store/model/token'
import { getWeb3 } from '~/logic/wallets/getWeb3'
export const ETH_ADDRESS = '0x000'
export const SAFE_TRANSFER_FROM_WITHOUT_DATA_HASH = '0x42842e0e'
export const DECIMALS_METHOD_HASH = '313ce567'
export const isEther = (symbol: string) => symbol === 'ETH'
export const getEthAsToken = (balance: string) => {

View File

@ -32,6 +32,7 @@ import {
} from '~/logic/tokens/store/actions/fetchTokens'
import { type Token } from '~/logic/tokens/store/model/token'
import { formatAmount } from '~/logic/tokens/utils/formatAmount'
import { SAFE_TRANSFER_FROM_WITHOUT_DATA_HASH } from '~/logic/tokens/utils/tokenHelpers'
import { getWeb3 } from '~/logic/wallets/getWeb3'
import SafeInfo from '~/routes/safe/components/Balances/SendModal/SafeInfo'
import { setImageToPlaceholder } from '~/routes/safe/components/Balances/utils'
@ -42,8 +43,6 @@ import { textShortener } from '~/utils/strings'
const useStyles = makeStyles(styles)
const SAFE_TRANSFER_FROM_WITHOUT_DATA_HASH = '0x42842e0e'
type Props = {
onClose: () => void,
onPrev: () => void,

View File

@ -13,7 +13,13 @@ import { type TxServiceType, buildTxServiceUrl } from '~/logic/safe/transactions
import { getLocalSafe } from '~/logic/safe/utils'
import { getHumanFriendlyToken } from '~/logic/tokens/store/actions/fetchTokens'
import { ALTERNATIVE_TOKEN_ABI } from '~/logic/tokens/utils/alternativeAbi'
import { isMultisendTransaction, isTokenTransfer, isUpgradeTransaction } from '~/logic/tokens/utils/tokenHelpers'
import {
DECIMALS_METHOD_HASH,
SAFE_TRANSFER_FROM_WITHOUT_DATA_HASH,
isMultisendTransaction,
isTokenTransfer,
isUpgradeTransaction,
} from '~/logic/tokens/utils/tokenHelpers'
import { ZERO_ADDRESS, sameAddress } from '~/logic/wallets/ethAddresses'
import { EMPTY_DATA } from '~/logic/wallets/ethTransactions'
import { getWeb3 } from '~/logic/wallets/getWeb3'
@ -93,7 +99,8 @@ export const buildTransactionFrom = async (safeAddress: string, tx: TxServiceMod
const cancellationTx = sameAddress(tx.to, safeAddress) && Number(tx.value) === 0 && !tx.data
const code = tx.to ? await web3.eth.getCode(tx.to) : ''
const isERC721Token =
code.includes('42842e0e') || (isTokenTransfer(tx.data, Number(tx.value)) && code.includes('06fdde03'))
code.includes(SAFE_TRANSFER_FROM_WITHOUT_DATA_HASH) ||
(isTokenTransfer(tx.data, Number(tx.value)) && !code.includes(DECIMALS_METHOD_HASH))
const isSendTokenTx = !isERC721Token && isTokenTransfer(tx.data, Number(tx.value))
const isMultiSendTx = isMultisendTransaction(tx.data, Number(tx.value))
const isUpgradeTx = isMultiSendTx && isUpgradeTransaction(tx.data)