diff --git a/packages/transaction-controller/jest.config.js b/packages/transaction-controller/jest.config.js index ec30bc001e4..85e88d35881 100644 --- a/packages/transaction-controller/jest.config.js +++ b/packages/transaction-controller/jest.config.js @@ -17,7 +17,7 @@ module.exports = merge(baseConfig, { // An object that configures minimum threshold enforcement for coverage results coverageThreshold: { global: { - branches: 84.02, + branches: 83.91, functions: 92.68, lines: 95.35, statements: 95.46, diff --git a/packages/transaction-controller/src/TransactionController.test.ts b/packages/transaction-controller/src/TransactionController.test.ts index 321733851fd..1f4c01245b5 100644 --- a/packages/transaction-controller/src/TransactionController.test.ts +++ b/packages/transaction-controller/src/TransactionController.test.ts @@ -104,6 +104,7 @@ jest.mock('@metamask/eth-query', () => gasUsed: '0x5208', status: '0x1', transactionIndex: 1337, + blockHash: '1337', }, { transactionHash: '1111', @@ -117,6 +118,16 @@ jest.mock('@metamask/eth-query', () => ); callback(undefined, tx); }, + getBlockByHash: (_blockHash: any, callback: any) => { + const blocks: any = [ + { hash: '1337', number: '0x1', baseFeePerGas: '0x14' }, + { hash: '1338', number: '0x2' }, + ]; + const block: any = blocks.find( + (element: any) => element.hash === _blockHash, + ); + callback(undefined, block); + }, }; }), ); @@ -1268,6 +1279,7 @@ describe('TransactionController', () => { const transactionMeta = controller.state.transactions[0]; expect(transactionMeta.verifiedOnBlockchain).toBe(true); expect(transactionMeta.transaction.gasUsed).toBe('0x5208'); + expect(transactionMeta.baseFeePerGas).toBe('0x14'); expect(transactionMeta.txReceipt?.transactionIndex).toBe(1337); }); }); diff --git a/packages/transaction-controller/src/TransactionController.ts b/packages/transaction-controller/src/TransactionController.ts index fa048e2c2d8..f2f4bf387a7 100644 --- a/packages/transaction-controller/src/TransactionController.ts +++ b/packages/transaction-controller/src/TransactionController.ts @@ -1155,9 +1155,14 @@ export class TransactionController extends BaseController< return [meta, false]; } + const txBlock = await query(this.ethQuery, 'getBlockByHash', [ + txReceipt.blockHash, + ]); + meta.verifiedOnBlockchain = true; meta.transaction.gasUsed = txReceipt.gasUsed; meta.txReceipt = txReceipt; + meta.baseFeePerGas = txBlock?.baseFeePerGas; // According to the Web3 docs: // TRUE if the transaction was successful, FALSE if the EVM reverted the transaction. diff --git a/packages/transaction-controller/src/types.ts b/packages/transaction-controller/src/types.ts index 743a97ca852..8b7eb253856 100644 --- a/packages/transaction-controller/src/types.ts +++ b/packages/transaction-controller/src/types.ts @@ -4,19 +4,20 @@ import type { Hex } from '@metamask/utils'; * @type TransactionMeta * * TransactionMeta representation - * @property error - Synthesized error information for failed transactions - * @property id - Generated UUID associated with this transaction - * @property networkID - Network code as per EIP-155 for this transaction - * @property origin - Origin this transaction was sent from - * @property deviceConfirmedOn - string to indicate what device the transaction was confirmed - * @property rawTransaction - Hex representation of the underlying transaction - * @property status - String status of this transaction - * @property time - Timestamp associated with this transaction - * @property toSmartContract - Whether transaction recipient is a smart contract - * @property transaction - Underlying Transaction object - * @property txReceipt - Transaction receipt - * @property transactionHash - Hash of a successful transaction - * @property blockNumber - Number of the block where the transaction has been included + * @property baseFeePerGas - Base fee of the block as a hex value, introduced in EIP-1559. + * @property error - Synthesized error information for failed transactions. + * @property id - Generated UUID associated with this transaction. + * @property networkID - Network code as per EIP-155 for this transaction. + * @property origin - Origin this transaction was sent from. + * @property deviceConfirmedOn - string to indicate what device the transaction was confirmed. + * @property rawTransaction - Hex representation of the underlying transaction. + * @property status - String status of this transaction. + * @property time - Timestamp associated with this transaction. + * @property toSmartContract - Whether transaction recipient is a smart contract. + * @property transaction - Underlying Transaction object. + * @property txReceipt - Transaction receipt. + * @property transactionHash - Hash of a successful transaction. + * @property blockNumber - Number of the block where the transaction has been included. */ export type TransactionMeta = | ({ @@ -25,23 +26,24 @@ export type TransactionMeta = | ({ status: TransactionStatus.failed; error: Error } & TransactionMetaBase); type TransactionMetaBase = { - isTransfer?: boolean; - transferInformation?: { - symbol: string; - contractAddress: string; - decimals: number; - }; + baseFeePerGas?: Hex; + blockNumber?: string; + chainId?: Hex; + deviceConfirmedOn?: WalletDevice; id: string; + isTransfer?: boolean; networkID?: string; - chainId?: Hex; origin?: string; rawTransaction?: string; time: number; toSmartContract?: boolean; transaction: Transaction; transactionHash?: string; - blockNumber?: string; - deviceConfirmedOn?: WalletDevice; + transferInformation?: { + contractAddress: string; + decimals: number; + symbol: string; + }; verifiedOnBlockchain?: boolean; txReceipt?: TransactionReceipt; };