@@ -39,10 +39,11 @@ import {
3939 TOKEN_METHOD_APPROVE ,
4040 getTransactionReviewActionKey ,
4141 getTransactionById ,
42+ isLegacyTransaction
4243} from '.' ;
4344import Engine from '../../core/Engine' ;
4445import { strings } from '../../../locales/i18n' ;
45- import { TransactionType } from '@metamask/transaction-controller' ;
46+ import { TransactionType , TransactionEnvelopeType , TransactionMeta } from '@metamask/transaction-controller' ;
4647import { Provider } from '@metamask/network-controller' ;
4748import BigNumber from 'bignumber.js' ;
4849
@@ -1256,3 +1257,54 @@ describe('Transactions utils :: getTransactionById', () => {
12561257 expect ( result ) . toBeUndefined ( ) ;
12571258 } ) ;
12581259} ) ;
1260+
1261+ describe ( 'Transactions utils :: isLegacyTransaction' , ( ) => {
1262+ it ( 'returns true for a transaction with legacy type' , ( ) => {
1263+ const transactionMeta = {
1264+ txParams : {
1265+ type : TransactionEnvelopeType . legacy ,
1266+ from : '0x123' ,
1267+ to : '0x456' ,
1268+ gasPrice : '0x77359400' ,
1269+ } ,
1270+ } ;
1271+
1272+ expect ( isLegacyTransaction ( transactionMeta ) ) . toBe ( true ) ;
1273+ } ) ;
1274+
1275+ it ( 'returns false for an EIP-1559 transaction' , ( ) => {
1276+ const transactionMeta = {
1277+ txParams : {
1278+ type : TransactionEnvelopeType . feeMarket ,
1279+ from : '0x123' ,
1280+ to : '0x456' ,
1281+ maxFeePerGas : '0x77359400' ,
1282+ maxPriorityFeePerGas : '0x1' ,
1283+ } ,
1284+ } ;
1285+
1286+ expect ( isLegacyTransaction ( transactionMeta ) ) . toBe ( false ) ;
1287+ } ) ;
1288+
1289+ it ( 'returns false for a transaction without type field' , ( ) => {
1290+ const transactionMeta = {
1291+ txParams : {
1292+ from : '0x123' ,
1293+ to : '0x456' ,
1294+ gasPrice : '0x77359400' ,
1295+ } ,
1296+ } ;
1297+
1298+ expect ( isLegacyTransaction ( transactionMeta ) ) . toBe ( false ) ;
1299+ } ) ;
1300+
1301+ it ( 'returns false for undefined transactionMeta' , ( ) => {
1302+ // @ts -expect-error Testing undefined input
1303+ expect ( isLegacyTransaction ( undefined ) ) . toBe ( false ) ;
1304+ } ) ;
1305+
1306+ it ( 'returns false for transactionMeta without txParams' , ( ) => {
1307+ const transactionMeta = { } ;
1308+ expect ( isLegacyTransaction ( transactionMeta as Partial < TransactionMeta > ) ) . toBe ( false ) ;
1309+ } ) ;
1310+ } ) ;
0 commit comments