@@ -374,22 +374,6 @@ export default class TransactionController extends EventEmitter {
374374 return transactions [ txId ] ;
375375 }
376376
377- /**
378- * @param {string } txHash - transaction hash
379- * @returns {TransactionMeta } the txMeta who matches the given hash if none found
380- * for the network returns undefined
381- */
382- _getTransactionByHash ( txHash ) {
383- const { transactions } = this . store . getState ( ) ;
384- const txByHash = Object . values ( transactions ) . filter ( ( tx ) => {
385- if ( tx . hash && txHash && tx . hash === txHash ) {
386- return tx ;
387- }
388- return undefined ;
389- } ) ;
390- return txByHash [ 0 ] ;
391- }
392-
393377 /**
394378 * @param {number } txId
395379 * @returns {boolean }
@@ -1857,6 +1841,7 @@ export default class TransactionController extends EventEmitter {
18571841 return ;
18581842 }
18591843 otherTxMeta . replacedBy = txMeta . hash ;
1844+ otherTxMeta . replacedById = txMeta . id ;
18601845 this . txStateManager . updateTransaction (
18611846 txMeta ,
18621847 'transactions/pending-tx-tracker#event: tx:confirmed reference to confirmed txHash with same nonce' ,
@@ -2011,7 +1996,7 @@ export default class TransactionController extends EventEmitter {
20111996 } ,
20121997 defaultGasEstimates,
20131998 originalType,
2014- replacedBy ,
1999+ replacedById ,
20152000 metamaskNetworkId : network ,
20162001 } = txMeta ;
20172002 const { transactions } = this . store . getState ( ) ;
@@ -2115,15 +2100,21 @@ export default class TransactionController extends EventEmitter {
21152100 transactionContractMethod = transactions [ id ] ?. contractMethodName ;
21162101 }
21172102
2118- const replacedTxMeta = this . _getTransactionByHash ( replacedBy ) ;
2103+ const replacedTxMeta = this . _getTransaction ( replacedById ) ;
2104+
2105+ const TRANSACTION_REPLACEMENT_METHODS = {
2106+ RETRY : TRANSACTION_TYPES . RETRY ,
2107+ CANCEL : TRANSACTION_TYPES . CANCEL ,
2108+ SAME_NONCE : 'other' ,
2109+ } ;
21192110
21202111 let transactionReplaced ;
21212112 if ( extraParams ?. dropped ) {
2122- transactionReplaced = TRANSACTION_TYPES . OTHER ;
2113+ transactionReplaced = TRANSACTION_REPLACEMENT_METHODS . SAME_NONCE ;
21232114 if ( replacedTxMeta ?. type === TRANSACTION_TYPES . CANCEL ) {
2124- transactionReplaced = TRANSACTION_TYPES . CANCEL ;
2115+ transactionReplaced = TRANSACTION_REPLACEMENT_METHODS . CANCEL ;
21252116 } else if ( replacedTxMeta ?. type === TRANSACTION_TYPES . RETRY ) {
2126- transactionReplaced = TRANSACTION_TYPES . RETRY ;
2117+ transactionReplaced = TRANSACTION_REPLACEMENT_METHODS . RETRY ;
21272118 }
21282119 }
21292120
0 commit comments