aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrankie <frankie.diamond@gmail.com>2017-07-27 02:56:13 +0800
committerGitHub <noreply@github.com>2017-07-27 02:56:13 +0800
commitf23efec3e3d9f42484f633ba0444db350875f898 (patch)
treea951967d7c5760ec2e66cb358fdf1b3c065cf1c9
parent0deb617d8f879b9a05c4581f16f5790cafa9789a (diff)
parent55a55141d08f7827cb23f4213a6d88351803fbff (diff)
downloadtangerine-wallet-browser-f23efec3e3d9f42484f633ba0444db350875f898.tar.gz
tangerine-wallet-browser-f23efec3e3d9f42484f633ba0444db350875f898.tar.zst
tangerine-wallet-browser-f23efec3e3d9f42484f633ba0444db350875f898.zip
Merge pull request #1830 from MetaMask/providerProxyFix
NonceTracker - Provider proxy fix
-rw-r--r--app/scripts/controllers/transactions.js1
-rw-r--r--app/scripts/lib/nonce-tracker.js17
-rw-r--r--test/unit/nonce-tracker-test.js8
3 files changed, 17 insertions, 9 deletions
diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js
index 8f53ffa8c..f71659042 100644
--- a/app/scripts/controllers/transactions.js
+++ b/app/scripts/controllers/transactions.js
@@ -24,7 +24,6 @@ module.exports = class TransactionController extends EventEmitter {
this.blockTracker = opts.blockTracker
this.nonceTracker = new NonceTracker({
provider: this.provider,
- blockTracker: this.provider._blockTracker,
getPendingTransactions: (address) => {
return this.getFilteredTxList({
from: address,
diff --git a/app/scripts/lib/nonce-tracker.js b/app/scripts/lib/nonce-tracker.js
index c0746bd87..8328e81ec 100644
--- a/app/scripts/lib/nonce-tracker.js
+++ b/app/scripts/lib/nonce-tracker.js
@@ -4,8 +4,8 @@ const Mutex = require('await-semaphore').Mutex
class NonceTracker {
- constructor ({ blockTracker, provider, getPendingTransactions }) {
- this.blockTracker = blockTracker
+ constructor ({ provider, getPendingTransactions }) {
+ this.provider = provider
this.ethQuery = new EthQuery(provider)
this.getPendingTransactions = getPendingTransactions
this.lockMap = {}
@@ -39,16 +39,17 @@ class NonceTracker {
assert(Number.isInteger(nextNonce), `nonce-tracker - nextNonce is not an integer - got: (${typeof nextNonce}) "${nextNonce}"`)
// collect the numbers used to calculate the nonce for debugging
const blockNumber = currentBlock.number
- const nonceDetails = { blockNumber, baseCount, pendingCount }
+ const nonceDetails = { blockNumber, baseCount, baseCountHex, pendingCount }
// return nonce and release cb
return { nextNonce, nonceDetails, releaseLock }
}
async _getCurrentBlock () {
- const currentBlock = this.blockTracker.getCurrentBlock()
+ const blockTracker = this._getBlockTracker()
+ const currentBlock = blockTracker.getCurrentBlock()
if (currentBlock) return currentBlock
return await Promise((reject, resolve) => {
- this.blockTracker.once('latest', resolve)
+ blockTracker.once('latest', resolve)
})
}
@@ -82,6 +83,12 @@ class NonceTracker {
return mutex
}
+ // this is a hotfix for the fact that the blockTracker will
+ // change when the network changes
+ _getBlockTracker () {
+ return this.provider._blockTracker
+ }
+
}
module.exports = NonceTracker
diff --git a/test/unit/nonce-tracker-test.js b/test/unit/nonce-tracker-test.js
index 16cd6d008..b0283e159 100644
--- a/test/unit/nonce-tracker-test.js
+++ b/test/unit/nonce-tracker-test.js
@@ -18,11 +18,13 @@ describe('Nonce Tracker', function () {
getPendingTransactions = () => pendingTxs
- provider = { sendAsync: (_, cb) => { cb(undefined, {result: '0x0'}) } }
- nonceTracker = new NonceTracker({
- blockTracker: {
+ provider = {
+ sendAsync: (_, cb) => { cb(undefined, {result: '0x0'}) },
+ _blockTracker: {
getCurrentBlock: () => '0x11b568',
},
+ }
+ nonceTracker = new NonceTracker({
provider,
getPendingTransactions,
})