diff options
author | Frankie <frankie.diamond@gmail.com> | 2017-06-17 07:54:32 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-17 07:54:32 +0800 |
commit | 7ec7e1226691474ea200ccf867f7a7d1f0c1086a (patch) | |
tree | dabfd728e64ded6fcea6b7c2fcaa4ac7c726e591 /app/scripts | |
parent | 42f3ccd9dc91dde7c82aecaf2eb22625a9ef2172 (diff) | |
parent | ac728189e15b9963ab8e3bd03847e4ca2b3043fb (diff) | |
download | tangerine-wallet-browser-7ec7e1226691474ea200ccf867f7a7d1f0c1086a.tar tangerine-wallet-browser-7ec7e1226691474ea200ccf867f7a7d1f0c1086a.tar.gz tangerine-wallet-browser-7ec7e1226691474ea200ccf867f7a7d1f0c1086a.tar.bz2 tangerine-wallet-browser-7ec7e1226691474ea200ccf867f7a7d1f0c1086a.tar.lz tangerine-wallet-browser-7ec7e1226691474ea200ccf867f7a7d1f0c1086a.tar.xz tangerine-wallet-browser-7ec7e1226691474ea200ccf867f7a7d1f0c1086a.tar.zst tangerine-wallet-browser-7ec7e1226691474ea200ccf867f7a7d1f0c1086a.zip |
Merge pull request #1607 from MetaMask/i1567-FixInaccurateError
Do not mark slowly mined txs as failed.
Diffstat (limited to 'app/scripts')
-rw-r--r-- | app/scripts/controllers/transactions.js | 36 | ||||
-rw-r--r-- | app/scripts/metamask-controller.js | 1 |
2 files changed, 18 insertions, 19 deletions
diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js index d56a81150..d9d9849b1 100644 --- a/app/scripts/controllers/transactions.js +++ b/app/scripts/controllers/transactions.js @@ -25,11 +25,11 @@ module.exports = class TransactionController extends EventEmitter { this.query = opts.ethQuery this.txProviderUtils = new TxProviderUtil(this.query) this.blockTracker.on('rawBlock', this.checkForTxInBlock.bind(this)) - this.blockTracker.on('block', this.resubmitPendingTxs.bind(this)) + this.blockTracker.on('latest', this.resubmitPendingTxs.bind(this)) this.blockTracker.on('sync', this.queryPendingTxs.bind(this)) this.signEthTx = opts.signTransaction this.nonceLock = Semaphore(1) - + this.ethStore = opts.ethStore // memstore is computed from a few different stores this._updateMemstore() this.store.subscribe(() => this._updateMemstore()) @@ -413,33 +413,31 @@ module.exports = class TransactionController extends EventEmitter { 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))) .catch((reason) => { log.info('Problem resubmitting tx', reason) }) } - resubmitTx (txMeta, cb) { - // Increment a try counter. - if (!('retryCount' in txMeta)) { - txMeta.retryCount = 0 - } + _resubmitTx (txMeta, cb) { + const address = txMeta.txParams.from + const balance = this.ethStore.getState().accounts[address].balance + const nonce = Number.parseInt(this.ethStore.getState().accounts[address].nonce) + const txNonce = Number.parseInt(txMeta.txParams.nonce) + const gtBalance = Number.parseInt(txMeta.txParams.value) > Number.parseInt(balance) + if (!('retryCount' in txMeta)) txMeta.retryCount = 0 + // if the value of the transaction is greater then the balance + // or the nonce of the transaction is lower then the accounts nonce + // dont resubmit the tx + if (gtBalance || txNonce < nonce) return cb() // Only auto-submit already-signed txs: - if (!('rawTx' in txMeta)) { - return cb() - } + if (!('rawTx' in txMeta)) return cb() - if (txMeta.retryCount > RETRY_LIMIT) { - txMeta.err = { - isWarning: true, - message: 'Gave up submitting tx.', - } - this.updateTx(txMeta) - return log.error(txMeta.err.message) - } + if (txMeta.retryCount > RETRY_LIMIT) return + // Increment a try counter. txMeta.retryCount++ const rawTx = txMeta.rawTx this.txProviderUtils.publishTransaction(rawTx, cb) diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index d745d29dc..de9a15924 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -102,6 +102,7 @@ module.exports = class MetamaskController extends EventEmitter { provider: this.provider, blockTracker: this.provider, ethQuery: this.ethQuery, + ethStore: this.ethStore, }) // notices |