Fix confirmed transaction time (#12633)

feature/default_network_editable
igorms-cons 3 years ago committed by GitHub
parent 5205f02de6
commit 981db6e0ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      app/scripts/controllers/transactions/index.js
  2. 1
      app/scripts/controllers/transactions/lib/tx-state-history-helpers.js
  3. 15
      app/scripts/controllers/transactions/pending-tx-tracker.js
  4. 13
      ui/components/app/transaction-activity-log/transaction-activity-log.util.js

@ -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);

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

@ -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) {

@ -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;
}

Loading…
Cancel
Save