1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 01:39:44 +01:00

fix: prevent cancel and speedup transactions to call accept approval (#18846)

This commit is contained in:
OGPoyraz 2023-05-03 13:07:03 +02:00 committed by PeterYinusa
parent 02b537c0c1
commit e1295e489b
2 changed files with 15 additions and 4 deletions

View File

@ -1248,7 +1248,9 @@ export default class TransactionController extends EventEmitter {
}
this.addTransaction(newTxMeta);
await this.approveTransaction(newTxMeta.id, actionId);
await this.approveTransaction(newTxMeta.id, actionId, {
hasApprovalRequest: false,
});
return newTxMeta;
}
@ -1306,7 +1308,9 @@ export default class TransactionController extends EventEmitter {
}
this.addTransaction(newTxMeta);
await this.approveTransaction(newTxMeta.id, actionId);
await this.approveTransaction(newTxMeta.id, actionId, {
hasApprovalRequest: false,
});
return newTxMeta;
}
@ -1345,8 +1349,10 @@ export default class TransactionController extends EventEmitter {
*
* @param {number} txId - the tx's Id
* @param {string} actionId - actionId passed from UI
* @param opts - options object
* @param opts.hasApprovalRequest - whether the transaction has an approval request
*/
async approveTransaction(txId, actionId) {
async approveTransaction(txId, actionId, { hasApprovalRequest = true } = {}) {
// TODO: Move this safety out of this function.
// Since this transaction is async,
// we need to keep track of what is currently being signed,
@ -1361,7 +1367,9 @@ export default class TransactionController extends EventEmitter {
try {
// approve
this.txStateManager.setTxStatusApproved(txId);
this._acceptApproval(txMeta);
if (hasApprovalRequest) {
this._acceptApproval(txMeta);
}
// get next nonce
const fromAddress = txMeta.txParams.from;
// wait for a nonce

View File

@ -608,6 +608,8 @@ describe('Transaction Controller', function () {
cancelTxMeta.id,
);
assert.deepEqual(cancelTxMeta, memTxMeta);
// One for the initial addUnapprovedTransaction, one for the approval
assert.equal(messengerMock.call.callCount, 2);
});
it('should add only 1 cancel transaction when called twice with same actionId', async function () {
@ -1385,6 +1387,7 @@ describe('Transaction Controller', function () {
type: TransactionType.retry,
},
);
assert.equal(messengerMock.call.callCount, 0);
});
it('should call this.approveTransaction with the id of the returned tx', async function () {