aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorkumavis <kumavis@users.noreply.github.com>2017-06-16 05:12:14 +0800
committerGitHub <noreply@github.com>2017-06-16 05:12:14 +0800
commit41a1ce037b975e5d69a8bd1f977ec92794621f9b (patch)
treefb8989c31ab9e607cadb6a1b0ecd6465562e321c /app
parent08b8e89b88678b9fbe2816b0501d700deba8bb97 (diff)
parent27b874f2c48fd1cb9dc0984646cb739173ddaf2c (diff)
downloadtangerine-wallet-browser-41a1ce037b975e5d69a8bd1f977ec92794621f9b.tar
tangerine-wallet-browser-41a1ce037b975e5d69a8bd1f977ec92794621f9b.tar.gz
tangerine-wallet-browser-41a1ce037b975e5d69a8bd1f977ec92794621f9b.tar.bz2
tangerine-wallet-browser-41a1ce037b975e5d69a8bd1f977ec92794621f9b.tar.lz
tangerine-wallet-browser-41a1ce037b975e5d69a8bd1f977ec92794621f9b.tar.xz
tangerine-wallet-browser-41a1ce037b975e5d69a8bd1f977ec92794621f9b.tar.zst
tangerine-wallet-browser-41a1ce037b975e5d69a8bd1f977ec92794621f9b.zip
Merge pull request #1611 from MetaMask/checkTxsOnSync
add a check for weather a tx is included in a block when jumping blocks
Diffstat (limited to 'app')
-rw-r--r--app/scripts/controllers/transactions.js46
1 files changed, 46 insertions, 0 deletions
diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js
index 71f90c2cd..9c20a7f1a 100644
--- a/app/scripts/controllers/transactions.js
+++ b/app/scripts/controllers/transactions.js
@@ -26,6 +26,8 @@ module.exports = class TransactionController extends EventEmitter {
this.txProviderUtils = new TxProviderUtil(this.query)
this.blockTracker.on('block', this.checkForTxInBlock.bind(this))
this.blockTracker.on('block', this.resubmitPendingTxs.bind(this))
+ // provider-engine only exploses the 'block' event, not 'latest' for 'sync'
+ this.provider._blockTracker.on('sync', this.queryPendingTxs.bind(this))
this.signEthTx = opts.signTransaction
this.nonceLock = Semaphore(1)
@@ -359,6 +361,17 @@ module.exports = class TransactionController extends EventEmitter {
})
}
+ queryPendingTxs ({oldBlock, newBlock}) {
+ // check pending transactions on start
+ if (!oldBlock) {
+ this._checkPendingTxs()
+ return
+ }
+ // if we synced by more than one block, check for missed pending transactions
+ const diff = Number.parseInt(newBlock.number) - Number.parseInt(oldBlock.number)
+ if (diff > 1) this._checkPendingTxs()
+ }
+
// PRIVATE METHODS
// Should find the tx in the tx list and
@@ -433,6 +446,39 @@ module.exports = class TransactionController extends EventEmitter {
this.txProviderUtils.publishTransaction(rawTx, cb)
}
+ // checks the network for signed txs and
+ // if confirmed sets the tx status as 'confirmed'
+ _checkPendingTxs () {
+ var signedTxList = this.getFilteredTxList({status: 'submitted'})
+ if (!signedTxList.length) return
+ signedTxList.forEach((txMeta) => {
+ var txHash = txMeta.hash
+ var txId = txMeta.id
+ if (!txHash) {
+ const errReason = {
+ errCode: 'No hash was provided',
+ message: 'We had an error while submitting this transaction, please try again.',
+ }
+ return this.setTxStatusFailed(txId, errReason)
+ }
+ this.query.getTransactionByHash(txHash, (err, txParams) => {
+ if (err || !txParams) {
+ if (!txParams) return
+ txMeta.err = {
+ isWarning: true,
+ errorCode: err,
+ message: 'There was a problem loading this transaction.',
+ }
+ this.updateTx(txMeta)
+ return log.error(err)
+ }
+ if (txParams.blockNumber) {
+ this.setTxStatusConfirmed(txId)
+ }
+ })
+ })
+ }
+
}