1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-22 19:26:13 +02:00

Fix confirmed transaction time (#12633)

This commit is contained in:
igorms-cons 2021-12-07 19:16:40 +01:00 committed by GitHub
parent 5205f02de6
commit 981db6e0ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 8 deletions

View File

@ -977,7 +977,7 @@ export default class TransactionController extends EventEmitter {
* @param {number} txId - The tx's ID
* @returns {Promise<void>}
*/
async confirmTransaction(txId, txReceipt, baseFeePerGas) {
async confirmTransaction(txId, txReceipt, baseFeePerGas, blockTimestamp) {
// get the txReceipt before marking the transaction confirmed
// to ensure the receipt is gotten before the ui revives the tx
const txMeta = this.txStateManager.getTransaction(txId);
@ -1002,6 +1002,9 @@ export default class TransactionController extends EventEmitter {
if (baseFeePerGas) {
txMeta.baseFeePerGas = baseFeePerGas;
}
if (blockTimestamp) {
txMeta.blockTimestamp = blockTimestamp;
}
this.txStateManager.setTxStatusConfirmed(txId);
this._markNonceDuplicatesDropped(txId);
@ -1183,8 +1186,13 @@ export default class TransactionController extends EventEmitter {
});
this.pendingTxTracker.on(
'tx:confirmed',
(txId, transactionReceipt, baseFeePerGas) =>
this.confirmTransaction(txId, transactionReceipt, baseFeePerGas),
(txId, transactionReceipt, baseFeePerGas, blockTimestamp) =>
this.confirmTransaction(
txId,
transactionReceipt,
baseFeePerGas,
blockTimestamp,
),
);
this.pendingTxTracker.on('tx:dropped', (txId) => {
this._dropTransaction(txId);

View File

@ -38,7 +38,6 @@ export function generateHistoryEntry(previousState, newState, note) {
if (note) {
entry[0].note = note;
}
entry[0].timestamp = Date.now();
}
return entry;

View File

@ -164,6 +164,7 @@ export default class PendingTransactionTracker extends EventEmitter {
* @emits tx:warning
* @private
*/
async _checkPendingTx(txMeta) {
const txHash = txMeta.hash;
const txId = txMeta.id;
@ -193,11 +194,21 @@ export default class PendingTransactionTracker extends EventEmitter {
try {
const transactionReceipt = await this.query.getTransactionReceipt(txHash);
if (transactionReceipt?.blockNumber) {
const { baseFeePerGas } = await this.query.getBlockByHash(
const {
baseFeePerGas,
timestamp: blockTimestamp,
} = await this.query.getBlockByHash(
transactionReceipt?.blockHash,
false,
);
this.emit('tx:confirmed', txId, transactionReceipt, baseFeePerGas);
this.emit(
'tx:confirmed',
txId,
transactionReceipt,
baseFeePerGas,
blockTimestamp,
);
return;
}
} catch (err) {

View File

@ -24,6 +24,7 @@ const STATUS_PATH = '/status';
const GAS_PRICE_PATH = '/txParams/gasPrice';
const GAS_LIMIT_PATH = '/txParams/gas';
const ESTIMATE_BASE_FEE_PATH = '/estimatedBaseFee';
const BLOCKTIMESTAMP = '/blockTimestamp';
// op constants
const REPLACE_OP = 'replace';
@ -32,6 +33,7 @@ const eventPathsHash = {
[STATUS_PATH]: true,
[GAS_PRICE_PATH]: true,
[GAS_LIMIT_PATH]: true,
[BLOCKTIMESTAMP]: true,
};
const statusHash = {
@ -144,7 +146,6 @@ export function getActivities(transaction, isFirstTransaction = false) {
eventKey = TRANSACTION_CANCEL_SUCCESS_EVENT;
}
}
events.push({
id,
hash,
@ -155,7 +156,6 @@ export function getActivities(transaction, isFirstTransaction = false) {
value: gasFee,
});
}
break;
}
@ -189,7 +189,16 @@ export function getActivities(transaction, isFirstTransaction = false) {
gasPrice: cachedGasPrice,
});
}
break;
}
case BLOCKTIMESTAMP: {
const filteredAcc = acc.find(
(ac) => ac.eventKey === TRANSACTION_CONFIRMED_EVENT,
);
filteredAcc.timestamp = new Date(
parseInt(entry.value, 16) * 1000,
).getTime();
break;
}