Replace old random-id code with incrementing id generator

feature/default_network_editable
Dan Finlay 8 years ago
parent 161ff62fdc
commit f229d32442
  1. 3
      app/scripts/keyring-controller.js
  2. 11
      app/scripts/lib/inpage-provider.js
  3. 9
      app/scripts/lib/random-id.js

@ -7,7 +7,6 @@ const ethBinToOps = require('eth-bin-to-ops')
const EthQuery = require('eth-query') const EthQuery = require('eth-query')
const BN = ethUtil.BN const BN = ethUtil.BN
const Transaction = require('ethereumjs-tx') const Transaction = require('ethereumjs-tx')
const createId = require('web3-provider-engine/util/random-id')
const autoFaucet = require('./lib/auto-faucet') const autoFaucet = require('./lib/auto-faucet')
const bip39 = require('bip39') const bip39 = require('bip39')
@ -22,6 +21,8 @@ const keyringTypes = [
HdKeyring, HdKeyring,
] ]
const createId = require('./lib/random-id')
module.exports = class KeyringController extends EventEmitter { module.exports = class KeyringController extends EventEmitter {
constructor (opts) { constructor (opts) {

@ -2,6 +2,7 @@ const Streams = require('mississippi')
const StreamProvider = require('web3-stream-provider') const StreamProvider = require('web3-stream-provider')
const ObjectMultiplex = require('./obj-multiplex') const ObjectMultiplex = require('./obj-multiplex')
const RemoteStore = require('./remote-store.js').RemoteStore const RemoteStore = require('./remote-store.js').RemoteStore
const createRandomId = require('./random-id')
module.exports = MetamaskInpageProvider module.exports = MetamaskInpageProvider
@ -119,16 +120,6 @@ function remoteStoreWithLocalStorageCache (storageKey) {
return store return store
} }
function createRandomId(){
const extraDigits = 3
// 13 time digits
const datePart = new Date().getTime() * Math.pow(10, extraDigits)
// 3 random digits
const extraPart = Math.floor(Math.random() * Math.pow(10, extraDigits))
// 16 digits
return datePart + extraPart
}
function eachJsonMessage(payload, transformFn){ function eachJsonMessage(payload, transformFn){
if (Array.isArray(payload)) { if (Array.isArray(payload)) {
return payload.map(transformFn) return payload.map(transformFn)

@ -0,0 +1,9 @@
const MAX = 1000000000
let idCounter = Math.round( Math.random() * MAX )
function createRandomId() {
idCounter = idCounter % MAX
return idCounter++
}
module.exports = createRandomId
Loading…
Cancel
Save