Skip to content

Commit 37d836f

Browse files
authored
Merge pull request #819 from MetaMask/i791-FixLosingConnection
Increment tx ids to avoid collisions
2 parents b0ccde6 + 8eb91e8 commit 37d836f

File tree

4 files changed

+13
-11
lines changed

4 files changed

+13
-11
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Current Master
44

5+
- Fix bug that would cause MetaMask to occasionally lose its StreamProvider connection and drop requests.
6+
57
## 2.13.8 2016-11-16
68

79
- Show a warning when a transaction fails during simulation.

app/scripts/lib/idStore.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const EthQuery = require('eth-query')
77
const KeyStore = require('eth-lightwallet').keystore
88
const clone = require('clone')
99
const extend = require('xtend')
10-
const createId = require('web3-provider-engine/util/random-id')
10+
const createId = require('./random-id')
1111
const ethBinToOps = require('eth-bin-to-ops')
1212
const autoFaucet = require('./auto-faucet')
1313
const messageManager = require('./message-manager')

app/scripts/lib/inpage-provider.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const Streams = require('mississippi')
22
const StreamProvider = require('web3-stream-provider')
33
const ObjectMultiplex = require('./obj-multiplex')
44
const RemoteStore = require('./remote-store.js').RemoteStore
5+
const createRandomId = require('./random-id')
56

67
module.exports = MetamaskInpageProvider
78

@@ -119,16 +120,6 @@ function remoteStoreWithLocalStorageCache (storageKey) {
119120
return store
120121
}
121122

122-
function createRandomId(){
123-
const extraDigits = 3
124-
// 13 time digits
125-
const datePart = new Date().getTime() * Math.pow(10, extraDigits)
126-
// 3 random digits
127-
const extraPart = Math.floor(Math.random() * Math.pow(10, extraDigits))
128-
// 16 digits
129-
return datePart + extraPart
130-
}
131-
132123
function eachJsonMessage(payload, transformFn){
133124
if (Array.isArray(payload)) {
134125
return payload.map(transformFn)

app/scripts/lib/random-id.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const MAX = 1000000000
2+
3+
let idCounter = Math.round( Math.random() * MAX )
4+
function createRandomId() {
5+
idCounter = idCounter % MAX
6+
return idCounter++
7+
}
8+
9+
module.exports = createRandomId

0 commit comments

Comments
 (0)