diff options
author | frankiebee <frankie.diamond@gmail.com> | 2017-06-16 05:28:10 +0800 |
---|---|---|
committer | frankiebee <frankie.diamond@gmail.com> | 2017-06-16 05:28:10 +0800 |
commit | f76a555c09ea243865a6e40f140b70da78c23378 (patch) | |
tree | 6bd6ffbe7bca92f04bae9338c7654c2edbcf8805 | |
parent | 2e5deef2b0bdaaa67ee1584da52b7001cc9e849b (diff) | |
parent | 41a1ce037b975e5d69a8bd1f977ec92794621f9b (diff) | |
download | tangerine-wallet-browser-f76a555c09ea243865a6e40f140b70da78c23378.tar tangerine-wallet-browser-f76a555c09ea243865a6e40f140b70da78c23378.tar.gz tangerine-wallet-browser-f76a555c09ea243865a6e40f140b70da78c23378.tar.bz2 tangerine-wallet-browser-f76a555c09ea243865a6e40f140b70da78c23378.tar.lz tangerine-wallet-browser-f76a555c09ea243865a6e40f140b70da78c23378.tar.xz tangerine-wallet-browser-f76a555c09ea243865a6e40f140b70da78c23378.tar.zst tangerine-wallet-browser-f76a555c09ea243865a6e40f140b70da78c23378.zip |
Merge branch 'master' into i1567-FixInaccurateError
-rw-r--r-- | app/scripts/controllers/transactions.js | 68 | ||||
-rw-r--r-- | package.json | 2 | ||||
-rw-r--r-- | test/unit/tx-controller-test.js | 2 |
3 files changed, 54 insertions, 18 deletions
diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js index 58dc8a6ab..f6eb4e4d9 100644 --- a/app/scripts/controllers/transactions.js +++ b/app/scripts/controllers/transactions.js @@ -25,6 +25,8 @@ module.exports = class TransactionController extends EventEmitter { this.query = opts.ethQuery this.txProviderUtils = new TxProviderUtil(this.query) this.blockTracker.on('block', this.checkForTxInBlock.bind(this)) + // provider-engine only exploses the 'block' event, not 'latest' for 'sync' + this.provider._blockTracker.on('sync', this.queryPendingTxs.bind(this)) this.provider._blockTracker.on('latest', this.resubmitPendingTxs.bind(this)) this.signEthTx = opts.signTransaction this.nonceLock = Semaphore(1) @@ -338,12 +340,13 @@ module.exports = class TransactionController extends EventEmitter { // checks if a signed tx is in a block and // if included sets the tx status as 'confirmed' - checkForTxInBlock () { - var signedTxList = this.getFilteredTxList({ status: 'submitted' }) + checkForTxInBlock (block) { + 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', @@ -351,24 +354,24 @@ module.exports = class TransactionController extends EventEmitter { } 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) - } + + block.transactions.forEach((tx) => { + if (tx.hash === txHash) this.setTxStatusConfirmed(txId) }) }) } + 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 @@ -441,6 +444,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) + } + }) + }) + } + } diff --git a/package.json b/package.json index c60aff821..d2fce188a 100644 --- a/package.json +++ b/package.json @@ -123,7 +123,7 @@ "valid-url": "^1.0.9", "vreme": "^3.0.2", "web3": "0.18.2", - "web3-provider-engine": "^12.2.4", + "web3-provider-engine": "^13.0.1", "web3-stream-provider": "^2.0.6", "xtend": "^4.0.1" }, diff --git a/test/unit/tx-controller-test.js b/test/unit/tx-controller-test.js index 702bdd03d..0d35cd62c 100644 --- a/test/unit/tx-controller-test.js +++ b/test/unit/tx-controller-test.js @@ -19,7 +19,7 @@ describe('Transaction Controller', function () { txController = new TransactionController({ networkStore: new ObservableStore(currentNetworkId), txHistoryLimit: 10, - provider: { _blockTracker: new EventEmitter() }, + provider: { _blockTracker: new EventEmitter()}, blockTracker: new EventEmitter(), ethQuery: new EthQuery(new EventEmitter()), signTransaction: (ethTx) => new Promise((resolve) => { |