aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2017-08-24 11:31:03 +0800
committerDan Finlay <dan@danfinlay.com>2017-08-24 11:43:47 +0800
commit855f4eeacbcf7b3e056cf7956edea2c84fa256d5 (patch)
tree4e9abd4ec6dd2de2822ea5490789c6a92003c89d /app/scripts
parent04d40b114dd12237710f605fe2f0a5f2c337d2cb (diff)
downloadtangerine-wallet-browser-855f4eeacbcf7b3e056cf7956edea2c84fa256d5.tar
tangerine-wallet-browser-855f4eeacbcf7b3e056cf7956edea2c84fa256d5.tar.gz
tangerine-wallet-browser-855f4eeacbcf7b3e056cf7956edea2c84fa256d5.tar.bz2
tangerine-wallet-browser-855f4eeacbcf7b3e056cf7956edea2c84fa256d5.tar.lz
tangerine-wallet-browser-855f4eeacbcf7b3e056cf7956edea2c84fa256d5.tar.xz
tangerine-wallet-browser-855f4eeacbcf7b3e056cf7956edea2c84fa256d5.tar.zst
tangerine-wallet-browser-855f4eeacbcf7b3e056cf7956edea2c84fa256d5.zip
Pass nonce tests
Diffstat (limited to 'app/scripts')
-rw-r--r--app/scripts/lib/nonce-tracker.js15
1 files changed, 7 insertions, 8 deletions
diff --git a/app/scripts/lib/nonce-tracker.js b/app/scripts/lib/nonce-tracker.js
index 6fcd716f2..8c2568c3f 100644
--- a/app/scripts/lib/nonce-tracker.js
+++ b/app/scripts/lib/nonce-tracker.js
@@ -30,10 +30,12 @@ class NonceTracker {
const nonceDetails = {}
const networkNonceResult = await this._getNetworkNextNonce(address)
const highestLocallyConfirmed = this._getHighestLocallyConfirmed(address)
+ const nextNetworkNonce = networkNonceResult.nonce
+ const highestLocalNonce = highestLocallyConfirmed
+ const highestSuggested = Math.max(nextNetworkNonce, highestLocalNonce)
- const highestConfirmed = Math.max(networkNonceResult.nonce, highestLocallyConfirmed)
const pendingTxs = this.getPendingTransactions(address)
- const localNonceResult = this._getHighestContinuousFrom(pendingTxs, highestConfirmed) || 0
+ const localNonceResult = this._getHighestContinuousFrom(pendingTxs, highestSuggested) || 0
nonceDetails.local = localNonceResult.details
nonceDetails.network = networkNonceResult.details
@@ -90,7 +92,7 @@ class NonceTracker {
_getHighestLocallyConfirmed (address) {
const confirmedTransactions = this.getConfirmedTransactions(address)
const highest = this._getHighestNonce(confirmedTransactions)
- return highest
+ return Number.isInteger(highest) ? highest + 1 : 0
}
_reduceTxListToUniqueNonces (txList) {
@@ -116,14 +118,11 @@ class NonceTracker {
const nonces = txList.map((txMeta) => parseInt(txMeta.txParams.nonce, 16))
let highest = startPoint
- while (nonces.includes(highest + 1)) {
+ while (nonces.includes(highest)) {
highest++
}
- const haveHighestNonce = Number.isInteger(highest) && highest > 0
- const nonce = haveHighestNonce ? highest + 1 : 0
-
- return { name: 'local', nonce }
+ return { name: 'local', nonce: highest, details: { startPoint, highest } }
}
// this is a hotfix for the fact that the blockTracker will