From 09db7d732150b0327232cb255241e659ffbde7b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Mart=C3=ADnez?= Date: Thu, 19 Sep 2019 01:45:17 +0200 Subject: [PATCH 1/2] Refactor isTokenTransfer --- src/logic/tokens/utils/tokenHelpers.js | 2 ++ src/routes/safe/store/actions/fetchTransactions.js | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/logic/tokens/utils/tokenHelpers.js b/src/logic/tokens/utils/tokenHelpers.js index b97b8b6d..1fac59f9 100644 --- a/src/logic/tokens/utils/tokenHelpers.js +++ b/src/logic/tokens/utils/tokenHelpers.js @@ -48,3 +48,5 @@ export const isAddressAToken = async (tokenAddress: string) => { return call !== '0x' } + +export const isTokenTransfer = async (data: string, value: number) => data.substring(0, 10) === '0xa9059cbb' && value === 0 diff --git a/src/routes/safe/store/actions/fetchTransactions.js b/src/routes/safe/store/actions/fetchTransactions.js index 72f5e3d9..cc14513d 100644 --- a/src/routes/safe/store/actions/fetchTransactions.js +++ b/src/routes/safe/store/actions/fetchTransactions.js @@ -13,7 +13,7 @@ import { getWeb3 } from '~/logic/wallets/getWeb3' import { EMPTY_DATA } from '~/logic/wallets/ethTransactions' import { addTransactions } from './addTransactions' import { getHumanFriendlyToken } from '~/logic/tokens/store/actions/fetchTokens' -import { isAddressAToken } from '~/logic/tokens/utils/tokenHelpers' +import { isTokenTransfer } from '~/logic/tokens/utils/tokenHelpers' import { TX_TYPE_EXECUTION } from '~/logic/safe/transactions/send' import { decodeParamsFromSafeMethod } from '~/logic/contracts/methodIds' @@ -60,7 +60,7 @@ export const buildTransactionFrom = async ( const modifySettingsTx = tx.to === safeAddress && Number(tx.value) === 0 && !!tx.data const cancellationTx = tx.to === safeAddress && Number(tx.value) === 0 && !tx.data const customTx = tx.to !== safeAddress && !!tx.data - const isTokenTransfer = await isAddressAToken(tx.to) + const isSendTokenTx = await isTokenTransfer(tx.data, tx.value) let executionTxHash const executionTx = confirmations.find((conf) => conf.type === TX_TYPE_EXECUTION) @@ -71,7 +71,7 @@ export const buildTransactionFrom = async ( let symbol = 'ETH' let decodedParams - if (isTokenTransfer) { + if (isSendTokenTx) { const tokenContract = await getHumanFriendlyToken() const tokenInstance = await tokenContract.at(tx.to) symbol = await tokenInstance.symbol() From 05939222c53a717aaf6573a28570dde7e457bb48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Mart=C3=ADnez?= Date: Thu, 19 Sep 2019 11:33:35 +0200 Subject: [PATCH 2/2] Fix isSendTokenTx --- src/routes/safe/store/actions/fetchTransactions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/safe/store/actions/fetchTransactions.js b/src/routes/safe/store/actions/fetchTransactions.js index cc14513d..a56949a3 100644 --- a/src/routes/safe/store/actions/fetchTransactions.js +++ b/src/routes/safe/store/actions/fetchTransactions.js @@ -100,7 +100,7 @@ export const buildTransactionFrom = async ( executionDate: tx.executionDate, executionTxHash, safeTxHash: tx.safeTxHash, - isTokenTransfer, + isTokenTransfer: isSendTokenTx, decodedParams, modifySettingsTx, customTx,