diff --git a/packages/transaction-controller/src/types.ts b/packages/transaction-controller/src/types.ts index 5cf4544d57c..e6a29685607 100644 --- a/packages/transaction-controller/src/types.ts +++ b/packages/transaction-controller/src/types.ts @@ -430,6 +430,12 @@ export interface TransactionParams { * Value associated with this transaction. */ value?: string; + + /** + * Type of transaction. + * 0x0 indicates a legacy transaction. + */ + type?: string; } /** diff --git a/packages/transaction-controller/src/utils.test.ts b/packages/transaction-controller/src/utils.test.ts index d0932826a18..d54d47ddc8d 100644 --- a/packages/transaction-controller/src/utils.test.ts +++ b/packages/transaction-controller/src/utils.test.ts @@ -19,8 +19,8 @@ describe('utils', () => { jest.clearAllMocks(); }); - it('normalizeTxParams', () => { - const normalized = util.normalizeTxParams({ + describe('normalizeTxParams', () => { + const commonInput = { data: 'data', from: 'FROM', gas: 'gas', @@ -31,18 +31,43 @@ describe('utils', () => { maxFeePerGas: 'maxFeePerGas', maxPriorityFeePerGas: 'maxPriorityFeePerGas', estimatedBaseFee: 'estimatedBaseFee', + }; + + it('normalizeTransaction', () => { + const normalized = util.normalizeTxParams({ + ...commonInput, + }); + expect(normalized).toStrictEqual({ + data: '0xdata', + from: '0xfrom', + gas: '0xgas', + gasPrice: '0xgasPrice', + nonce: '0xnonce', + to: '0xto', + value: '0xvalue', + maxFeePerGas: '0xmaxFeePerGas', + maxPriorityFeePerGas: '0xmaxPriorityFeePerGas', + estimatedBaseFee: '0xestimatedBaseFee', + }); }); - expect(normalized).toStrictEqual({ - data: '0xdata', - from: '0xfrom', - gas: '0xgas', - gasPrice: '0xgasPrice', - nonce: '0xnonce', - to: '0xto', - value: '0xvalue', - maxFeePerGas: '0xmaxFeePerGas', - maxPriorityFeePerGas: '0xmaxPriorityFeePerGas', - estimatedBaseFee: '0xestimatedBaseFee', + it('normalizeTransaction if type is zero', () => { + const normalized = util.normalizeTxParams({ + ...commonInput, + type: '0x0', + }); + expect(normalized).toStrictEqual({ + data: '0xdata', + from: '0xfrom', + gas: '0xgas', + gasPrice: '0xgasPrice', + nonce: '0xnonce', + to: '0xto', + value: '0xvalue', + maxFeePerGas: '0xmaxFeePerGas', + maxPriorityFeePerGas: '0xmaxPriorityFeePerGas', + estimatedBaseFee: '0xestimatedBaseFee', + type: '0x0', + }); }); }); diff --git a/packages/transaction-controller/src/utils.ts b/packages/transaction-controller/src/utils.ts index 7bab7d91e44..13dd009818d 100644 --- a/packages/transaction-controller/src/utils.ts +++ b/packages/transaction-controller/src/utils.ts @@ -28,6 +28,7 @@ const NORMALIZERS: { [param in keyof TransactionParams]: any } = { addHexPrefix(maxPriorityFeePerGas), estimatedBaseFee: (maxPriorityFeePerGas: string) => addHexPrefix(maxPriorityFeePerGas), + type: (type: string) => (type === '0x0' ? '0x0' : undefined), }; /**