mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Autofill gasPrice for retry attempts with either the recommended gasprice or a %10 bump (#5786)
* transactions - autofill gasPrice for retry attempts with either the recomened gasprice or a %10 bump * lint
This commit is contained in:
parent
97c1e6bcc1
commit
8198ec9ae1
@ -229,7 +229,16 @@ class TransactionController extends EventEmitter {
|
||||
|
||||
async retryTransaction (originalTxId) {
|
||||
const originalTxMeta = this.txStateManager.getTx(originalTxId)
|
||||
const { txParams } = originalTxMeta
|
||||
const lastGasPrice = originalTxMeta.txParams.gasPrice
|
||||
const suggestedGasPriceBN = new ethUtil.BN(ethUtil.stripHexPrefix(this.getGasPrice()), 16)
|
||||
const lastGasPriceBN = new ethUtil.BN(ethUtil.stripHexPrefix(lastGasPrice), 16)
|
||||
// essentially lastGasPrice * 1.1 but
|
||||
// dont trust decimals so a round about way of doing that
|
||||
const lastGasPriceBNBumped = lastGasPriceBN.mul(new ethUtil.BN(110, 10)).div(new ethUtil.BN(100, 10))
|
||||
// transactions that are being retried require a >=%10 bump or the clients will throw an error
|
||||
txParams.gasPrice = suggestedGasPriceBN.gt(lastGasPriceBNBumped) ? `0x${suggestedGasPriceBN.toString(16)}` : `0x${lastGasPriceBNBumped.toString(16)}`
|
||||
|
||||
const txMeta = this.txStateManager.generateTxMeta({
|
||||
txParams: originalTxMeta.txParams,
|
||||
lastGasPrice,
|
||||
|
@ -28,6 +28,7 @@ describe('Transaction Controller', function () {
|
||||
blockTrackerStub.getLatestBlock = noop
|
||||
txController = new TransactionController({
|
||||
provider,
|
||||
getGasPrice: function () { return '0xee6b2800' },
|
||||
networkStore: new ObservableStore(currentNetworkId),
|
||||
txHistoryLimit: 10,
|
||||
blockTracker: blockTrackerStub,
|
||||
@ -415,8 +416,9 @@ describe('Transaction Controller', function () {
|
||||
})
|
||||
|
||||
describe('#retryTransaction', function () {
|
||||
it('should create a new txMeta with the same txParams as the original one', function (done) {
|
||||
it('should create a new txMeta with the same txParams as the original one but with a higher gasPrice', function (done) {
|
||||
const txParams = {
|
||||
gasPrice: '0xee6b2800',
|
||||
nonce: '0x00',
|
||||
from: '0xB09d8505E1F4EF1CeA089D47094f5DD3464083d4',
|
||||
to: '0xB09d8505E1F4EF1CeA089D47094f5DD3464083d4',
|
||||
@ -427,6 +429,7 @@ describe('Transaction Controller', function () {
|
||||
])
|
||||
txController.retryTransaction(1)
|
||||
.then((txMeta) => {
|
||||
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')
|
||||
|
Loading…
Reference in New Issue
Block a user