aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfrankiebee <frankie.diamond@gmail.com>2017-06-15 11:17:59 +0800
committerfrankiebee <frankie.diamond@gmail.com>2017-06-15 11:17:59 +0800
commita10740af7e35aa60e0445598403e6bda22382c2f (patch)
tree6cf284f709933bc2fe290cd494cfa813992faa5a
parent1a4f982739a09a4fd757b5f45fcaeef1a93dd4a3 (diff)
downloadtangerine-wallet-browser-a10740af7e35aa60e0445598403e6bda22382c2f.tar
tangerine-wallet-browser-a10740af7e35aa60e0445598403e6bda22382c2f.tar.gz
tangerine-wallet-browser-a10740af7e35aa60e0445598403e6bda22382c2f.tar.bz2
tangerine-wallet-browser-a10740af7e35aa60e0445598403e6bda22382c2f.tar.lz
tangerine-wallet-browser-a10740af7e35aa60e0445598403e6bda22382c2f.tar.xz
tangerine-wallet-browser-a10740af7e35aa60e0445598403e6bda22382c2f.tar.zst
tangerine-wallet-browser-a10740af7e35aa60e0445598403e6bda22382c2f.zip
add a check for weather a tx is included in a block when jumping blocks
-rw-r--r--app/scripts/controllers/transactions.js41
-rw-r--r--test/unit/tx-controller-test.js1
2 files changed, 42 insertions, 0 deletions
diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js
index 2db8041eb..41f651458 100644
--- a/app/scripts/controllers/transactions.js
+++ b/app/scripts/controllers/transactions.js
@@ -26,6 +26,7 @@ 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))
+ this.provider._blockTracker.on('sync', this.queryPendingTxs.bind(this))
this.signEthTx = opts.signTransaction
this.nonceLock = Semaphore(1)
@@ -369,6 +370,15 @@ module.exports = class TransactionController extends EventEmitter {
})
}
+ queryPendingTxs ({oldBlock, newBlock}) {
+ if (!oldBlock) {
+ this._checkPendingTxs()
+ return
+ }
+ 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
@@ -443,6 +453,37 @@ module.exports = class TransactionController extends EventEmitter {
this.txProviderUtils.publishTransaction(rawTx, cb)
}
+ _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)
+ }
+ })
+ })
+ }
+
}
diff --git a/test/unit/tx-controller-test.js b/test/unit/tx-controller-test.js
index f0d8a706e..0d35cd62c 100644
--- a/test/unit/tx-controller-test.js
+++ b/test/unit/tx-controller-test.js
@@ -19,6 +19,7 @@ describe('Transaction Controller', function () {
txController = new TransactionController({
networkStore: new ObservableStore(currentNetworkId),
txHistoryLimit: 10,
+ provider: { _blockTracker: new EventEmitter()},
blockTracker: new EventEmitter(),
ethQuery: new EthQuery(new EventEmitter()),
signTransaction: (ethTx) => new Promise((resolve) => {