Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/transaction-controller/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ jest.mock('@metamask/eth-query', () =>
gasUsed: '0x5208',
status: '0x1',
transactionIndex: 1337,
blockHash: '1337',
},
{
transactionHash: '1111',
Expand All @@ -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);
},
};
}),
);
Expand Down Expand Up @@ -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);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
46 changes: 24 additions & 22 deletions packages/transaction-controller/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
| ({
Expand All @@ -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;
};
Expand Down