From 41e2c2beff61be7cbb79086068258e22762e54a5 Mon Sep 17 00:00:00 2001 From: Jyoti Puri Date: Thu, 16 Feb 2023 20:22:59 +0530 Subject: [PATCH] Change transaction type for send with approve transaction (#17777) --- shared/modules/transaction.utils.js | 7 ++++++- shared/modules/transaction.utils.test.js | 25 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/shared/modules/transaction.utils.js b/shared/modules/transaction.utils.js index 44337a6d8..70f6064ca 100644 --- a/shared/modules/transaction.utils.js +++ b/shared/modules/transaction.utils.js @@ -184,8 +184,13 @@ 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 + data && tokenMethodName && !isSendWithApprove ? tokenMethodName : TransactionType.contractInteraction; } else { diff --git a/shared/modules/transaction.utils.test.js b/shared/modules/transaction.utils.test.js index 49248c995..4c01f6089 100644 --- a/shared/modules/transaction.utils.test.js +++ b/shared/modules/transaction.utils.test.js @@ -306,5 +306,30 @@ describe('Transaction.utils', function () { getCodeResponse: '0x0a', }); }); + + it('should return contractInteraction for send with approve', async function () { + const _providerResultStub = { + // 1 gwei + eth_gasPrice: '0x0de0b6b3a7640000', + // by default, all accounts are external accounts (not contracts) + eth_getCode: '0xa', + }; + const _provider = createTestProviderTools({ + scaffold: _providerResultStub, + }).provider; + + const result = await determineTransactionType( + { + to: '0x9e673399f795D01116e9A8B2dD2F156705131ee9', + value: '0x5af3107a4000', + data: '0x095ea7b30000000000000000000000002f318C334780961FB129D2a6c30D0763d9a5C9700000000000000000000000000000000000000000000000000000000000000005', + }, + new EthQuery(_provider), + ); + expect(result).toMatchObject({ + type: TransactionType.contractInteraction, + getCodeResponse: '0x0a', + }); + }); }); });