aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2018-05-24 13:34:00 +0800
committerkumavis <aaron@kumavis.me>2018-05-24 13:34:00 +0800
commitdc96b1eb935e59b12bcdc00fc68058684a376bd8 (patch)
tree48e7489cfb99a3cccef02b93139f7fccd144c9b0 /app
parent90327195986c953df40a10a6556ad9f133165712 (diff)
parent3d8f41e912535240b85c18e7d6bf6431f1339524 (diff)
downloadtangerine-wallet-browser-dc96b1eb935e59b12bcdc00fc68058684a376bd8.tar
tangerine-wallet-browser-dc96b1eb935e59b12bcdc00fc68058684a376bd8.tar.gz
tangerine-wallet-browser-dc96b1eb935e59b12bcdc00fc68058684a376bd8.tar.bz2
tangerine-wallet-browser-dc96b1eb935e59b12bcdc00fc68058684a376bd8.tar.lz
tangerine-wallet-browser-dc96b1eb935e59b12bcdc00fc68058684a376bd8.tar.xz
tangerine-wallet-browser-dc96b1eb935e59b12bcdc00fc68058684a376bd8.tar.zst
tangerine-wallet-browser-dc96b1eb935e59b12bcdc00fc68058684a376bd8.zip
Merge branch 'network-remove-provider-engine' of github.com:MetaMask/metamask-extension into network-remove-provider-engine
Diffstat (limited to 'app')
-rw-r--r--app/scripts/controllers/transactions/index.js8
-rw-r--r--app/scripts/controllers/transactions/pending-tx-tracker.js25
2 files changed, 24 insertions, 9 deletions
diff --git a/app/scripts/controllers/transactions/index.js b/app/scripts/controllers/transactions/index.js
index 128f5b86f..7cb8af3a8 100644
--- a/app/scripts/controllers/transactions/index.js
+++ b/app/scripts/controllers/transactions/index.js
@@ -57,6 +57,7 @@ class TransactionController extends EventEmitter {
initState: opts.initState,
txHistoryLimit: opts.txHistoryLimit,
getNetwork: this.getNetwork.bind(this),
+ confirmTransaction: this.confirmTransaction.bind(this),
})
this._onBootCleanUp()
@@ -301,6 +302,11 @@ class TransactionController extends EventEmitter {
this.txStateManager.setTxStatusSubmitted(txId)
}
+ confirmTransaction (txId) {
+ this.txStateManager.setTxStatusConfirmed(txId)
+ this._markNonceDuplicatesDropped(txId)
+ }
+
/**
Convenience method for the ui thats sets the transaction to rejected
@param txId {number} - the tx's Id
@@ -381,8 +387,6 @@ class TransactionController extends EventEmitter {
this.pendingTxTracker.on('tx:warning', (txMeta) => {
this.txStateManager.updateTx(txMeta, 'transactions/pending-tx-tracker#event: tx:warning')
})
- this.pendingTxTracker.on('tx:confirmed', (txId) => this.txStateManager.setTxStatusConfirmed(txId))
- this.pendingTxTracker.on('tx:confirmed', (txId) => this._markNonceDuplicatesDropped(txId))
this.pendingTxTracker.on('tx:failed', this.txStateManager.setTxStatusFailed.bind(this.txStateManager))
this.pendingTxTracker.on('tx:block-update', (txMeta, latestBlockNumber) => {
if (!txMeta.firstRetryBlockNumber) {
diff --git a/app/scripts/controllers/transactions/pending-tx-tracker.js b/app/scripts/controllers/transactions/pending-tx-tracker.js
index 6e2fcb40b..bd26a72d9 100644
--- a/app/scripts/controllers/transactions/pending-tx-tracker.js
+++ b/app/scripts/controllers/transactions/pending-tx-tracker.js
@@ -27,6 +27,7 @@ class PendingTransactionTracker extends EventEmitter {
this.getPendingTransactions = config.getPendingTransactions
this.getCompletedTransactions = config.getCompletedTransactions
this.publishTransaction = config.publishTransaction
+ this.confirmTransaction = config.confirmTransaction
this._checkPendingTxs()
}
@@ -37,7 +38,8 @@ class PendingTransactionTracker extends EventEmitter {
@emits tx:confirmed
@emits tx:failed
*/
- checkForTxInBlock (block) {
+ async checkForTxInBlock (blockNumber) {
+ const block = await this._getBlock(blockNumber)
const signedTxList = this.getPendingTransactions()
if (!signedTxList.length) return
signedTxList.forEach((txMeta) => {
@@ -51,9 +53,12 @@ class PendingTransactionTracker extends EventEmitter {
return
}
+ if (!block.transactions.length) return
- block.transactions.forEach((tx) => {
- if (tx.hash === txHash) this.emit('tx:confirmed', txId)
+ block.transactions.forEach((hash) => {
+ if (hash === txHash) {
+ this.confirmTransaction(txId)
+ }
})
})
}
@@ -70,7 +75,7 @@ class PendingTransactionTracker extends EventEmitter {
return
}
// if we synced by more than one block, check for missed pending transactions
- const diff = Number.parseInt(newBlock.number, 16) - Number.parseInt(oldBlock.number, 16)
+ const diff = Number.parseInt(newBlock, 16) - Number.parseInt(oldBlock, 16)
if (diff > 1) this._checkPendingTxs()
}
@@ -79,11 +84,11 @@ class PendingTransactionTracker extends EventEmitter {
@param block {object} - a block object
@emits tx:warning
*/
- resubmitPendingTxs (block) {
+ resubmitPendingTxs (blockNumber) {
const pending = this.getPendingTransactions()
// only try resubmitting if their are transactions to resubmit
if (!pending.length) return
- pending.forEach((txMeta) => this._resubmitTx(txMeta, block.number).catch((err) => {
+ pending.forEach((txMeta) => this._resubmitTx(txMeta, blockNumber).catch((err) => {
/*
Dont marked as failed if the error is a "known" transaction warning
"there is already a transaction with the same sender-nonce
@@ -179,7 +184,7 @@ class PendingTransactionTracker extends EventEmitter {
txParams = await this.query.getTransactionByHash(txHash)
if (!txParams) return
if (txParams.blockNumber) {
- this.emit('tx:confirmed', txId)
+ this.confirmTransaction(txId)
}
} catch (err) {
txMeta.warning = {
@@ -206,11 +211,17 @@ class PendingTransactionTracker extends EventEmitter {
nonceGlobalLock.releaseLock()
}
+ async _getBlock (blockNumber) {
+ return await this.query.getBlockByNumber(blockNumber, false)
+ }
+
/**
checks to see if a confirmed txMeta has the same nonce
@param txMeta {Object} - txMeta object
@returns {boolean}
*/
+
+
async _checkIfNonceIsTaken (txMeta) {
const address = txMeta.txParams.from
const completed = this.getCompletedTransactions(address)