1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-22 17:33:23 +01:00

Change transaction type for send with approve transaction (#17777)

This commit is contained in:
Jyoti Puri 2023-02-16 20:22:59 +05:30 committed by GitHub
parent 74ef8e4fa4
commit 41e2c2beff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 1 deletions

View File

@ -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 {

View File

@ -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',
});
});
});
});