From ab5a3cbe6ec13abbd0bcbf34b77eeaec880cd052 Mon Sep 17 00:00:00 2001 From: Jyoti Puri Date: Thu, 16 Feb 2023 12:26:07 +0530 Subject: [PATCH 1/2] Change transaction type for send with approve transaction --- 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 44337a6d8a9a..70f6064ca4e2 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 49248c9957fc..5ecaa601de8e 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: '0x', + }; + const _provider = createTestProviderTools({ + scaffold: _providerResultStub, + }).provider; + + const result = await determineTransactionType( + { + to: '0xabc', + value: '0x5af3107a4000', + data: '0x095ea7b30000000000000000000000002f318c334780961fb129d2a6c30d0763d9a5c9700000000000000000000000000000000000000000000000000000000000011170', + }, + new EthQuery(_provider), + ); + expect(result).toMatchObject({ + type: TransactionType.contractInteraction, + getCodeResponse: null, + }); + }); }); }); From 47c358457e7f202c46d2e078f26ff132eee9d0de Mon Sep 17 00:00:00 2001 From: Jyoti Puri Date: Thu, 16 Feb 2023 16:06:32 +0530 Subject: [PATCH 2/2] Fix build --- shared/modules/transaction.utils.test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/shared/modules/transaction.utils.test.js b/shared/modules/transaction.utils.test.js index 5ecaa601de8e..4c01f6089f30 100644 --- a/shared/modules/transaction.utils.test.js +++ b/shared/modules/transaction.utils.test.js @@ -312,7 +312,7 @@ describe('Transaction.utils', function () { // 1 gwei eth_gasPrice: '0x0de0b6b3a7640000', // by default, all accounts are external accounts (not contracts) - eth_getCode: '0x', + eth_getCode: '0xa', }; const _provider = createTestProviderTools({ scaffold: _providerResultStub, @@ -320,15 +320,15 @@ describe('Transaction.utils', function () { const result = await determineTransactionType( { - to: '0xabc', + to: '0x9e673399f795D01116e9A8B2dD2F156705131ee9', value: '0x5af3107a4000', - data: '0x095ea7b30000000000000000000000002f318c334780961fb129d2a6c30d0763d9a5c9700000000000000000000000000000000000000000000000000000000000011170', + data: '0x095ea7b30000000000000000000000002f318C334780961FB129D2a6c30D0763d9a5C9700000000000000000000000000000000000000000000000000000000000000005', }, new EthQuery(_provider), ); expect(result).toMatchObject({ type: TransactionType.contractInteraction, - getCodeResponse: null, + getCodeResponse: '0x0a', }); }); });