mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Fix confirmed transaction time (#12633)
This commit is contained in:
parent
5205f02de6
commit
981db6e0ea
@ -977,7 +977,7 @@ export default class TransactionController extends EventEmitter {
|
|||||||
* @param {number} txId - The tx's ID
|
* @param {number} txId - The tx's ID
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
async confirmTransaction(txId, txReceipt, baseFeePerGas) {
|
async confirmTransaction(txId, txReceipt, baseFeePerGas, blockTimestamp) {
|
||||||
// get the txReceipt before marking the transaction confirmed
|
// get the txReceipt before marking the transaction confirmed
|
||||||
// to ensure the receipt is gotten before the ui revives the tx
|
// to ensure the receipt is gotten before the ui revives the tx
|
||||||
const txMeta = this.txStateManager.getTransaction(txId);
|
const txMeta = this.txStateManager.getTransaction(txId);
|
||||||
@ -1002,6 +1002,9 @@ export default class TransactionController extends EventEmitter {
|
|||||||
if (baseFeePerGas) {
|
if (baseFeePerGas) {
|
||||||
txMeta.baseFeePerGas = baseFeePerGas;
|
txMeta.baseFeePerGas = baseFeePerGas;
|
||||||
}
|
}
|
||||||
|
if (blockTimestamp) {
|
||||||
|
txMeta.blockTimestamp = blockTimestamp;
|
||||||
|
}
|
||||||
|
|
||||||
this.txStateManager.setTxStatusConfirmed(txId);
|
this.txStateManager.setTxStatusConfirmed(txId);
|
||||||
this._markNonceDuplicatesDropped(txId);
|
this._markNonceDuplicatesDropped(txId);
|
||||||
@ -1183,8 +1186,13 @@ export default class TransactionController extends EventEmitter {
|
|||||||
});
|
});
|
||||||
this.pendingTxTracker.on(
|
this.pendingTxTracker.on(
|
||||||
'tx:confirmed',
|
'tx:confirmed',
|
||||||
(txId, transactionReceipt, baseFeePerGas) =>
|
(txId, transactionReceipt, baseFeePerGas, blockTimestamp) =>
|
||||||
this.confirmTransaction(txId, transactionReceipt, baseFeePerGas),
|
this.confirmTransaction(
|
||||||
|
txId,
|
||||||
|
transactionReceipt,
|
||||||
|
baseFeePerGas,
|
||||||
|
blockTimestamp,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
this.pendingTxTracker.on('tx:dropped', (txId) => {
|
this.pendingTxTracker.on('tx:dropped', (txId) => {
|
||||||
this._dropTransaction(txId);
|
this._dropTransaction(txId);
|
||||||
|
@ -38,7 +38,6 @@ export function generateHistoryEntry(previousState, newState, note) {
|
|||||||
if (note) {
|
if (note) {
|
||||||
entry[0].note = note;
|
entry[0].note = note;
|
||||||
}
|
}
|
||||||
|
|
||||||
entry[0].timestamp = Date.now();
|
entry[0].timestamp = Date.now();
|
||||||
}
|
}
|
||||||
return entry;
|
return entry;
|
||||||
|
@ -164,6 +164,7 @@ export default class PendingTransactionTracker extends EventEmitter {
|
|||||||
* @emits tx:warning
|
* @emits tx:warning
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
|
|
||||||
async _checkPendingTx(txMeta) {
|
async _checkPendingTx(txMeta) {
|
||||||
const txHash = txMeta.hash;
|
const txHash = txMeta.hash;
|
||||||
const txId = txMeta.id;
|
const txId = txMeta.id;
|
||||||
@ -193,11 +194,21 @@ export default class PendingTransactionTracker extends EventEmitter {
|
|||||||
try {
|
try {
|
||||||
const transactionReceipt = await this.query.getTransactionReceipt(txHash);
|
const transactionReceipt = await this.query.getTransactionReceipt(txHash);
|
||||||
if (transactionReceipt?.blockNumber) {
|
if (transactionReceipt?.blockNumber) {
|
||||||
const { baseFeePerGas } = await this.query.getBlockByHash(
|
const {
|
||||||
|
baseFeePerGas,
|
||||||
|
timestamp: blockTimestamp,
|
||||||
|
} = await this.query.getBlockByHash(
|
||||||
transactionReceipt?.blockHash,
|
transactionReceipt?.blockHash,
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
this.emit('tx:confirmed', txId, transactionReceipt, baseFeePerGas);
|
|
||||||
|
this.emit(
|
||||||
|
'tx:confirmed',
|
||||||
|
txId,
|
||||||
|
transactionReceipt,
|
||||||
|
baseFeePerGas,
|
||||||
|
blockTimestamp,
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -24,6 +24,7 @@ const STATUS_PATH = '/status';
|
|||||||
const GAS_PRICE_PATH = '/txParams/gasPrice';
|
const GAS_PRICE_PATH = '/txParams/gasPrice';
|
||||||
const GAS_LIMIT_PATH = '/txParams/gas';
|
const GAS_LIMIT_PATH = '/txParams/gas';
|
||||||
const ESTIMATE_BASE_FEE_PATH = '/estimatedBaseFee';
|
const ESTIMATE_BASE_FEE_PATH = '/estimatedBaseFee';
|
||||||
|
const BLOCKTIMESTAMP = '/blockTimestamp';
|
||||||
|
|
||||||
// op constants
|
// op constants
|
||||||
const REPLACE_OP = 'replace';
|
const REPLACE_OP = 'replace';
|
||||||
@ -32,6 +33,7 @@ const eventPathsHash = {
|
|||||||
[STATUS_PATH]: true,
|
[STATUS_PATH]: true,
|
||||||
[GAS_PRICE_PATH]: true,
|
[GAS_PRICE_PATH]: true,
|
||||||
[GAS_LIMIT_PATH]: true,
|
[GAS_LIMIT_PATH]: true,
|
||||||
|
[BLOCKTIMESTAMP]: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
const statusHash = {
|
const statusHash = {
|
||||||
@ -144,7 +146,6 @@ export function getActivities(transaction, isFirstTransaction = false) {
|
|||||||
eventKey = TRANSACTION_CANCEL_SUCCESS_EVENT;
|
eventKey = TRANSACTION_CANCEL_SUCCESS_EVENT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
events.push({
|
events.push({
|
||||||
id,
|
id,
|
||||||
hash,
|
hash,
|
||||||
@ -155,7 +156,6 @@ export function getActivities(transaction, isFirstTransaction = false) {
|
|||||||
value: gasFee,
|
value: gasFee,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,7 +189,16 @@ export function getActivities(transaction, isFirstTransaction = false) {
|
|||||||
gasPrice: cachedGasPrice,
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user