mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Merge pull request #1598 from MetaMask/txRetry
put tx resubmission on the block event
This commit is contained in:
commit
dd7e11d196
@ -9,7 +9,6 @@ const createId = require('../lib/random-id')
|
|||||||
const denodeify = require('denodeify')
|
const denodeify = require('denodeify')
|
||||||
|
|
||||||
const RETRY_LIMIT = 200
|
const RETRY_LIMIT = 200
|
||||||
const RESUBMIT_INTERVAL = 10000 // Ten seconds
|
|
||||||
|
|
||||||
module.exports = class TransactionController extends EventEmitter {
|
module.exports = class TransactionController extends EventEmitter {
|
||||||
constructor (opts) {
|
constructor (opts) {
|
||||||
@ -26,6 +25,7 @@ module.exports = class TransactionController extends EventEmitter {
|
|||||||
this.query = opts.ethQuery
|
this.query = opts.ethQuery
|
||||||
this.txProviderUtils = new TxProviderUtil(this.query)
|
this.txProviderUtils = new TxProviderUtil(this.query)
|
||||||
this.blockTracker.on('block', this.checkForTxInBlock.bind(this))
|
this.blockTracker.on('block', this.checkForTxInBlock.bind(this))
|
||||||
|
this.blockTracker.on('block', this.resubmitPendingTxs.bind(this))
|
||||||
this.signEthTx = opts.signTransaction
|
this.signEthTx = opts.signTransaction
|
||||||
this.nonceLock = Semaphore(1)
|
this.nonceLock = Semaphore(1)
|
||||||
|
|
||||||
@ -34,8 +34,6 @@ module.exports = class TransactionController extends EventEmitter {
|
|||||||
this.store.subscribe(() => this._updateMemstore())
|
this.store.subscribe(() => this._updateMemstore())
|
||||||
this.networkStore.subscribe(() => this._updateMemstore())
|
this.networkStore.subscribe(() => this._updateMemstore())
|
||||||
this.preferencesStore.subscribe(() => this._updateMemstore())
|
this.preferencesStore.subscribe(() => this._updateMemstore())
|
||||||
|
|
||||||
this.continuallyResubmitPendingTxs()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getState () {
|
getState () {
|
||||||
@ -409,18 +407,15 @@ module.exports = class TransactionController extends EventEmitter {
|
|||||||
this.memStore.updateState({ unapprovedTxs, selectedAddressTxList })
|
this.memStore.updateState({ unapprovedTxs, selectedAddressTxList })
|
||||||
}
|
}
|
||||||
|
|
||||||
continuallyResubmitPendingTxs () {
|
resubmitPendingTxs () {
|
||||||
const pending = this.getTxsByMetaData('status', 'submitted')
|
const pending = this.getTxsByMetaData('status', 'submitted')
|
||||||
|
// only try resubmitting if their are transactions to resubmit
|
||||||
|
if (!pending.length) return
|
||||||
const resubmit = denodeify(this.resubmitTx.bind(this))
|
const resubmit = denodeify(this.resubmitTx.bind(this))
|
||||||
Promise.all(pending.map(txMeta => resubmit(txMeta)))
|
Promise.all(pending.map(txMeta => resubmit(txMeta)))
|
||||||
.catch((reason) => {
|
.catch((reason) => {
|
||||||
log.info('Problem resubmitting tx', reason)
|
log.info('Problem resubmitting tx', reason)
|
||||||
})
|
})
|
||||||
.then(() => {
|
|
||||||
global.setTimeout(() => {
|
|
||||||
this.continuallyResubmitPendingTxs()
|
|
||||||
}, RESUBMIT_INTERVAL)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resubmitTx (txMeta, cb) {
|
resubmitTx (txMeta, cb) {
|
||||||
|
Loading…
Reference in New Issue
Block a user