mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 09:57:02 +01:00
fix: prevent cancel and speedup transactions to call accept approval (#18846)
This commit is contained in:
parent
b5a11857c4
commit
cbcb46f704
@ -1248,7 +1248,9 @@ export default class TransactionController extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.addTransaction(newTxMeta);
|
this.addTransaction(newTxMeta);
|
||||||
await this.approveTransaction(newTxMeta.id, actionId);
|
await this.approveTransaction(newTxMeta.id, actionId, {
|
||||||
|
hasApprovalRequest: false,
|
||||||
|
});
|
||||||
return newTxMeta;
|
return newTxMeta;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1306,7 +1308,9 @@ export default class TransactionController extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.addTransaction(newTxMeta);
|
this.addTransaction(newTxMeta);
|
||||||
await this.approveTransaction(newTxMeta.id, actionId);
|
await this.approveTransaction(newTxMeta.id, actionId, {
|
||||||
|
hasApprovalRequest: false,
|
||||||
|
});
|
||||||
return newTxMeta;
|
return newTxMeta;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1345,8 +1349,10 @@ export default class TransactionController extends EventEmitter {
|
|||||||
*
|
*
|
||||||
* @param {number} txId - the tx's Id
|
* @param {number} txId - the tx's Id
|
||||||
* @param {string} actionId - actionId passed from UI
|
* @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.
|
// TODO: Move this safety out of this function.
|
||||||
// Since this transaction is async,
|
// Since this transaction is async,
|
||||||
// we need to keep track of what is currently being signed,
|
// we need to keep track of what is currently being signed,
|
||||||
@ -1361,7 +1367,9 @@ export default class TransactionController extends EventEmitter {
|
|||||||
try {
|
try {
|
||||||
// approve
|
// approve
|
||||||
this.txStateManager.setTxStatusApproved(txId);
|
this.txStateManager.setTxStatusApproved(txId);
|
||||||
this._acceptApproval(txMeta);
|
if (hasApprovalRequest) {
|
||||||
|
this._acceptApproval(txMeta);
|
||||||
|
}
|
||||||
// get next nonce
|
// get next nonce
|
||||||
const fromAddress = txMeta.txParams.from;
|
const fromAddress = txMeta.txParams.from;
|
||||||
// wait for a nonce
|
// wait for a nonce
|
||||||
|
@ -608,6 +608,8 @@ describe('Transaction Controller', function () {
|
|||||||
cancelTxMeta.id,
|
cancelTxMeta.id,
|
||||||
);
|
);
|
||||||
assert.deepEqual(cancelTxMeta, memTxMeta);
|
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 () {
|
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,
|
type: TransactionType.retry,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
assert.equal(messengerMock.call.callCount, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call this.approveTransaction with the id of the returned tx', async function () {
|
it('should call this.approveTransaction with the id of the returned tx', async function () {
|
||||||
|
Loading…
Reference in New Issue
Block a user