diff options
Diffstat (limited to 'app/scripts')
-rw-r--r-- | app/scripts/keyring-controller.js | 3 | ||||
-rw-r--r-- | app/scripts/lib/inpage-provider.js | 13 | ||||
-rw-r--r-- | app/scripts/lib/random-id.js | 9 |
3 files changed, 13 insertions, 12 deletions
diff --git a/app/scripts/keyring-controller.js b/app/scripts/keyring-controller.js index 8ceb2b1ce..10d686e23 100644 --- a/app/scripts/keyring-controller.js +++ b/app/scripts/keyring-controller.js @@ -6,7 +6,6 @@ const bip39 = require('bip39') const Transaction = require('ethereumjs-tx') const EventEmitter = require('events').EventEmitter -const createId = require('web3-provider-engine/util/random-id') const normalize = require('./lib/sig-util').normalize const encryptor = require('./lib/encryptor') const messageManager = require('./lib/message-manager') @@ -22,6 +21,8 @@ const keyringTypes = [ HdKeyring, ] +const createId = require('./lib/random-id') + module.exports = class KeyringController extends EventEmitter { constructor (opts) { diff --git a/app/scripts/lib/inpage-provider.js b/app/scripts/lib/inpage-provider.js index 6795f2bd4..c9d617996 100644 --- a/app/scripts/lib/inpage-provider.js +++ b/app/scripts/lib/inpage-provider.js @@ -2,6 +2,7 @@ const Streams = require('mississippi') const StreamProvider = require('web3-stream-provider') const ObjectMultiplex = require('./obj-multiplex') const RemoteStore = require('./remote-store.js').RemoteStore +const createRandomId = require('./random-id') module.exports = MetamaskInpageProvider @@ -119,17 +120,7 @@ function remoteStoreWithLocalStorageCache (storageKey) { 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)) { return payload.map(transformFn) } else { diff --git a/app/scripts/lib/random-id.js b/app/scripts/lib/random-id.js new file mode 100644 index 000000000..3c5ae5600 --- /dev/null +++ b/app/scripts/lib/random-id.js @@ -0,0 +1,9 @@ +const MAX = 1000000000 + +let idCounter = Math.round( Math.random() * MAX ) +function createRandomId() { + idCounter = idCounter % MAX + return idCounter++ +} + +module.exports = createRandomId |