mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Delete retryTransaction action and background (#8576)
* delete retryTransaction action and background
This commit is contained in:
parent
0470386326
commit
24cbb6fc66
@ -329,38 +329,6 @@ export default class TransactionController extends EventEmitter {
|
||||
return { gasLimit, simulationFails }
|
||||
}
|
||||
|
||||
/**
|
||||
Creates a new txMeta with the same txParams as the original
|
||||
to allow the user to resign the transaction with a higher gas values
|
||||
@param {number} originalTxId - the id of the txMeta that
|
||||
you want to attempt to retry
|
||||
@param {string} [gasPrice] - Optional gas price to be increased to use as the retry
|
||||
transaction's gas price
|
||||
@returns {txMeta}
|
||||
*/
|
||||
|
||||
async retryTransaction (originalTxId, gasPrice) {
|
||||
const originalTxMeta = this.txStateManager.getTx(originalTxId)
|
||||
const { txParams } = originalTxMeta
|
||||
const lastGasPrice = gasPrice || originalTxMeta.txParams.gasPrice
|
||||
const lastGasPriceBN = new ethUtil.BN(ethUtil.stripHexPrefix(lastGasPrice), 16)
|
||||
// essentially lastGasPrice * 1.1
|
||||
const lastGasPriceBNBumped = lastGasPriceBN
|
||||
.mul(new ethUtil.BN(110, 10))
|
||||
.div(new ethUtil.BN(100, 10))
|
||||
txParams.gasPrice = `0x${lastGasPriceBNBumped.toString(16)}`
|
||||
|
||||
const txMeta = this.txStateManager.generateTxMeta({
|
||||
txParams: originalTxMeta.txParams,
|
||||
lastGasPrice,
|
||||
loadingDefaults: false,
|
||||
type: TRANSACTION_TYPE_RETRY,
|
||||
})
|
||||
this.addTx(txMeta)
|
||||
this.emit('newUnapprovedTx', txMeta)
|
||||
return txMeta
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new approved transaction to attempt to cancel a previously submitted transaction. The
|
||||
* new transaction contains the same nonce as the previous, is a basic ETH transfer of 0x value to
|
||||
|
@ -520,7 +520,6 @@ export default class MetamaskController extends EventEmitter {
|
||||
cancelTransaction: nodeify(txController.cancelTransaction, txController),
|
||||
updateTransaction: nodeify(txController.updateTransaction, txController),
|
||||
updateAndApproveTransaction: nodeify(txController.updateAndApproveTransaction, txController),
|
||||
retryTransaction: nodeify(this.retryTransaction, this),
|
||||
createCancelTransaction: nodeify(this.createCancelTransaction, this),
|
||||
createSpeedUpTransaction: nodeify(this.createSpeedUpTransaction, this),
|
||||
getFilteredTxList: nodeify(txController.getFilteredTxList, txController),
|
||||
@ -1373,18 +1372,6 @@ export default class MetamaskController extends EventEmitter {
|
||||
// END (VAULT / KEYRING RELATED METHODS)
|
||||
//=============================================================================
|
||||
|
||||
/**
|
||||
* Allows a user to try to speed up a transaction by retrying it
|
||||
* with higher gas.
|
||||
*
|
||||
* @param {string} txId - The ID of the transaction to speed up.
|
||||
*/
|
||||
async retryTransaction (txId, gasPrice) {
|
||||
await this.txController.retryTransaction(txId, gasPrice)
|
||||
const state = await this.getState()
|
||||
return state
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows a user to attempt to cancel a previously submitted transaction by creating a new
|
||||
* transaction.
|
||||
|
@ -482,29 +482,6 @@ describe('Transaction Controller', function () {
|
||||
})
|
||||
})
|
||||
|
||||
describe('#retryTransaction', function () {
|
||||
it('should create a new txMeta with the same txParams as the original one but with a higher gasPrice', async function () {
|
||||
const txParams = {
|
||||
gasPrice: '0xee6b2800',
|
||||
nonce: '0x00',
|
||||
from: '0xB09d8505E1F4EF1CeA089D47094f5DD3464083d4',
|
||||
to: '0xB09d8505E1F4EF1CeA089D47094f5DD3464083d4',
|
||||
data: '0x0',
|
||||
}
|
||||
txController.txStateManager._saveTxList([
|
||||
{ id: 1, status: 'submitted', metamaskNetworkId: currentNetworkId, txParams, history: [{}] },
|
||||
])
|
||||
const txMeta = await txController.retryTransaction(1)
|
||||
assert.equal(txMeta.txParams.gasPrice, '0x10642ac00', 'gasPrice should have a %10 gasPrice bump')
|
||||
assert.equal(txMeta.txParams.nonce, txParams.nonce, 'nonce should be the same')
|
||||
assert.equal(txMeta.txParams.from, txParams.from, 'from should be the same')
|
||||
assert.equal(txMeta.txParams.to, txParams.to, 'to should be the same')
|
||||
assert.equal(txMeta.txParams.data, txParams.data, 'data should be the same')
|
||||
assert.ok(('lastGasPrice' in txMeta), 'should have the key `lastGasPrice`')
|
||||
assert.equal(txController.txStateManager.getTxList().length, 2)
|
||||
})
|
||||
})
|
||||
|
||||
describe('#_markNonceDuplicatesDropped', function () {
|
||||
it('should mark all nonce duplicates as dropped without marking the confirmed transaction as dropped', function () {
|
||||
txController.txStateManager._saveTxList([
|
||||
|
@ -1350,29 +1350,6 @@ export function clearPendingTokens () {
|
||||
}
|
||||
}
|
||||
|
||||
export function retryTransaction (txId, gasPrice) {
|
||||
log.debug(`background.retryTransaction`)
|
||||
let newTxId
|
||||
|
||||
return (dispatch) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
background.retryTransaction(txId, gasPrice, (err, newState) => {
|
||||
if (err) {
|
||||
dispatch(displayWarning(err.message))
|
||||
return reject(err)
|
||||
}
|
||||
|
||||
const { currentNetworkTxList } = newState
|
||||
const { id } = currentNetworkTxList[currentNetworkTxList.length - 1]
|
||||
newTxId = id
|
||||
resolve(newState)
|
||||
})
|
||||
})
|
||||
.then((newState) => dispatch(updateMetamaskState(newState)))
|
||||
.then(() => newTxId)
|
||||
}
|
||||
}
|
||||
|
||||
export function createCancelTransaction (txId, customGasPrice) {
|
||||
log.debug('background.cancelTransaction')
|
||||
let newTxId
|
||||
|
Loading…
Reference in New Issue
Block a user