Skip to content

Commit

Permalink
Change transaction type for send with approve transaction (#17777)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpuri authored Feb 16, 2023
1 parent 74ef8e4 commit 41e2c2b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
7 changes: 6 additions & 1 deletion shared/modules/transaction.utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
25 changes: 25 additions & 0 deletions shared/modules/transaction.utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
});
});
});
});

0 comments on commit 41e2c2b

Please sign in to comment.