Skip to content

Commit 78758dc

Browse files
chore(runway): cherry-pick fix: Fallback to regular transaction submit for legacy transactions (#16172)
- fix: Fallback to regular transaction submit for legacy transactions (#15881)
1 parent 6dd1355 commit 78758dc

4 files changed

Lines changed: 87 additions & 3 deletions

File tree

app/util/smart-transactions/smart-publish-hook.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
TransactionController,
1010
TransactionMeta,
1111
WalletDevice,
12+
TransactionEnvelopeType,
1213
} from '@metamask/transaction-controller';
1314
import SmartTransactionsController from '@metamask/smart-transactions-controller';
1415
import {
@@ -235,6 +236,23 @@ describe('submitSmartTransactionHook', () => {
235236
});
236237
});
237238

239+
it('falls back to regular transaction submit if it is a legacy transaction', async () => {
240+
withRequest(async ({ request }) => {
241+
// Modify transaction to be a legacy transaction with explicit type
242+
request.transactionMeta.txParams = {
243+
...request.transactionMeta.txParams,
244+
type: TransactionEnvelopeType.legacy,
245+
gasPrice: '0x77359400',
246+
};
247+
// Remove EIP-1559 specific fields if they exist
248+
delete request.transactionMeta.txParams.maxFeePerGas;
249+
delete request.transactionMeta.txParams.maxPriorityFeePerGas;
250+
251+
const result = await submitSmartTransactionHook(request);
252+
expect(result).toEqual({ transactionHash: undefined });
253+
});
254+
});
255+
238256
it('returns a txHash asap if the feature flag requires it', async () => {
239257
withRequest(async ({ request }) => {
240258
request.featureFlags.smartTransactions.mobileReturnTxHashAsap = true;

app/util/smart-transactions/smart-publish-hook.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {
22
TransactionParams,
33
TransactionController,
44
TransactionMeta,
5-
type PublishBatchHookTransaction
5+
type PublishBatchHookTransaction,
66
} from '@metamask/transaction-controller';
77
import SmartTransactionsController, {
88
SmartTransactionsControllerSmartTransactionEvent,
@@ -27,6 +27,7 @@ import { RAMPS_SEND } from '../../components/UI/Ramp/constants';
2727
import { Messenger } from '@metamask/base-controller';
2828
import { addSwapsTransaction } from '../swaps/swaps-transactions';
2929
import { Hex } from '@metamask/utils';
30+
import { isLegacyTransaction } from '../transactions';
3031

3132
export type AllowedActions = never;
3233

@@ -176,7 +177,8 @@ class SmartTransactionHook {
176177
const useRegularTransactionSubmit = { transactionHash: undefined };
177178
if (
178179
!this.#shouldUseSmartTransaction ||
179-
this.#transactionMeta.origin === RAMPS_SEND
180+
this.#transactionMeta.origin === RAMPS_SEND ||
181+
isLegacyTransaction(this.#transactionMeta)
180182
) {
181183
return useRegularTransactionSubmit;
182184
}

app/util/transactions/index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
import {
1313
isEIP1559Transaction,
1414
TransactionType,
15+
TransactionEnvelopeType,
1516
} from '@metamask/transaction-controller';
1617
import { swapsUtils } from '@metamask/swaps-controller';
1718
import Engine from '../../core/Engine';
@@ -170,6 +171,17 @@ const actionKeys = {
170171
),
171172
};
172173

174+
/**
175+
* Checks if a transaction is a legacy transaction by examining its type.
176+
* Legacy transactions are identified by the TransactionEnvelopeType.legacy type.
177+
*
178+
* @param {object} transactionMeta - The transaction metadata to check
179+
* @returns {boolean} true if the transaction is a legacy transaction, false otherwise
180+
*/
181+
export function isLegacyTransaction(transactionMeta) {
182+
return transactionMeta?.txParams?.type === TransactionEnvelopeType.legacy;
183+
}
184+
173185
/**
174186
* Generates transfer data for specified method
175187
*

app/util/transactions/index.test.ts

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@ import {
3939
TOKEN_METHOD_APPROVE,
4040
getTransactionReviewActionKey,
4141
getTransactionById,
42+
isLegacyTransaction
4243
} from '.';
4344
import Engine from '../../core/Engine';
4445
import { strings } from '../../../locales/i18n';
45-
import { TransactionType } from '@metamask/transaction-controller';
46+
import { TransactionType, TransactionEnvelopeType, TransactionMeta } from '@metamask/transaction-controller';
4647
import { Provider } from '@metamask/network-controller';
4748
import 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

Comments
 (0)