Skip to content

Commit 1c9525d

Browse files
committed
Adding a replacedById key that records the internal metamask id of the tx that replaced it and delete getTransactionByHash method
1 parent 87d80ca commit 1c9525d

File tree

3 files changed

+12
-42
lines changed

3 files changed

+12
-42
lines changed

app/scripts/controllers/transactions/index.js

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -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

app/scripts/controllers/transactions/tx-state-manager.js

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -297,22 +297,6 @@ export default class TransactionStateManager extends EventEmitter {
297297
return transactions[txId];
298298
}
299299

300-
/**
301-
* @param {string} txHash - transaction hash
302-
* @returns {TransactionMeta} the txMeta who matches the given hash if none found
303-
* for the network returns undefined
304-
*/
305-
getTransactionByHash(txHash) {
306-
const { transactions } = this.store.getState();
307-
const txByHash = Object.values(transactions).filter((tx) => {
308-
if (txHash && tx.hash && tx.hash === txHash) {
309-
return tx;
310-
}
311-
return undefined;
312-
});
313-
return txByHash[0];
314-
}
315-
316300
/**
317301
* updates the txMeta in the list and adds a history entry
318302
*

shared/constants/transaction.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ import { MESSAGE_TYPE } from './app';
3737
* resubmitting the same transaction with a higher gas fee. This type is also used
3838
* to speed up pending transactions. This is accomplished by creating a new tx with
3939
* the same nonce and higher gas fees.
40-
* @property {'other'} OTHER - First we must to turn on Customize transaction nonce in
41-
* Settings tab, then we want to send a tx. In confirmation screen we set Max base fee
42-
* and Priority fee to be lower, then save that changes and confirm a tx. This is accomplished
43-
* by creating a new tx with the same nonce while pending transaction.
4440
*/
4541

4642
/**
@@ -62,7 +58,6 @@ export const TRANSACTION_TYPES = {
6258
INCOMING: 'incoming',
6359
PERSONAL_SIGN: MESSAGE_TYPE.PERSONAL_SIGN,
6460
RETRY: 'retry',
65-
OTHER: 'other',
6661
SIGN: MESSAGE_TYPE.ETH_SIGN,
6762
SIGN_TYPED_DATA: MESSAGE_TYPE.ETH_SIGN_TYPED_DATA,
6863
SIMPLE_SEND: 'simpleSend',

0 commit comments

Comments
 (0)