diff --git a/shared/modules/transaction.utils.js b/shared/modules/transaction.utils.js index 70f6064ca..b07d1f869 100644 --- a/shared/modules/transaction.utils.js +++ b/shared/modules/transaction.utils.js @@ -176,6 +176,8 @@ export async function determineTransactionType(txParams, query) { contractCode = resultCode; if (isContractAddress) { + const hasValue = txParams.value && txParams.value !== '0x0'; + const tokenMethodName = [ TransactionType.tokenMethodApprove, TransactionType.tokenMethodSetApprovalForAll, @@ -184,13 +186,8 @@ export async function determineTransactionType(txParams, query) { TransactionType.tokenMethodSafeTransferFrom, ].find((methodName) => isEqualCaseInsensitive(methodName, name)); - const isSendWithApprove = - txParams.value && - txParams.value !== '0x0' && - tokenMethodName === TransactionType.tokenMethodApprove; - result = - data && tokenMethodName && !isSendWithApprove + data && tokenMethodName && !hasValue ? tokenMethodName : TransactionType.contractInteraction; } else { diff --git a/shared/modules/transaction.utils.test.js b/shared/modules/transaction.utils.test.js index 4c01f6089..615fda2e3 100644 --- a/shared/modules/transaction.utils.test.js +++ b/shared/modules/transaction.utils.test.js @@ -135,7 +135,7 @@ describe('Transaction.utils', function () { }); }); - it('should return a token transfer type when the recipient is a contract and data is for the respective method call', async function () { + it('should return a token transfer type when the recipient is a contract, there is no value passed, and data is for the respective method call', async function () { const _providerResultStub = { // 1 gwei eth_gasPrice: '0x0de0b6b3a7640000', @@ -159,6 +159,48 @@ describe('Transaction.utils', function () { }); }); + it( + 'should NOT return a token transfer type and instead return contract interaction' + + ' when the recipient is a contract, the data matches the respective method call, but there is a value passed', + async function () { + const _providerResultStub = { + // 1 gwei + eth_gasPrice: '0x0de0b6b3a7640000', + // by default, all accounts are external accounts (not contracts) + eth_getCode: '0xab', + }; + const _provider = createTestProviderTools({ + scaffold: _providerResultStub, + }).provider; + + const resultWithEmptyValue = await determineTransactionType( + { + value: '0x0', + to: '0x9e673399f795D01116e9A8B2dD2F156705131ee9', + data: '0xa9059cbb0000000000000000000000002f318C334780961FB129D2a6c30D0763d9a5C970000000000000000000000000000000000000000000000000000000000000000a', + }, + new EthQuery(_provider), + ); + expect(resultWithEmptyValue).toMatchObject({ + type: TransactionType.tokenMethodTransfer, + getCodeResponse: '0xab', + }); + + const resultWithValue = await determineTransactionType( + { + value: '0x12345', + to: '0x9e673399f795D01116e9A8B2dD2F156705131ee9', + data: '0xa9059cbb0000000000000000000000002f318C334780961FB129D2a6c30D0763d9a5C970000000000000000000000000000000000000000000000000000000000000000a', + }, + new EthQuery(_provider), + ); + expect(resultWithValue).toMatchObject({ + type: TransactionType.contractInteraction, + getCodeResponse: '0xab', + }); + }, + ); + it('should NOT return a token transfer type when the recipient is not a contract but the data matches the respective method call', async function () { const _providerResultStub = { // 1 gwei