diff options
author | Kevin Serrano <kevgagser@gmail.com> | 2016-08-24 05:51:09 +0800 |
---|---|---|
committer | Kevin Serrano <kevgagser@gmail.com> | 2016-08-24 05:51:09 +0800 |
commit | 4bceda37a8dfa414d4e5ff2b315b9968120d0d37 (patch) | |
tree | 4ed708d8f1db35b5373389b7c005ff2b9bfc4807 /app/scripts/lib/inpage-provider.js | |
parent | 00e8db31cebaf7af42660e828cc912b2b6af5b5d (diff) | |
parent | 9dad3a5917308cb6d9ee56aa183298b8eaad1c5f (diff) | |
download | tangerine-wallet-browser-4bceda37a8dfa414d4e5ff2b315b9968120d0d37.tar tangerine-wallet-browser-4bceda37a8dfa414d4e5ff2b315b9968120d0d37.tar.gz tangerine-wallet-browser-4bceda37a8dfa414d4e5ff2b315b9968120d0d37.tar.bz2 tangerine-wallet-browser-4bceda37a8dfa414d4e5ff2b315b9968120d0d37.tar.lz tangerine-wallet-browser-4bceda37a8dfa414d4e5ff2b315b9968120d0d37.tar.xz tangerine-wallet-browser-4bceda37a8dfa414d4e5ff2b315b9968120d0d37.tar.zst tangerine-wallet-browser-4bceda37a8dfa414d4e5ff2b315b9968120d0d37.zip |
Merge branch 'master' into fox-sub
Diffstat (limited to 'app/scripts/lib/inpage-provider.js')
-rw-r--r-- | app/scripts/lib/inpage-provider.js | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/app/scripts/lib/inpage-provider.js b/app/scripts/lib/inpage-provider.js index b3ed3d9e2..65354cd3d 100644 --- a/app/scripts/lib/inpage-provider.js +++ b/app/scripts/lib/inpage-provider.js @@ -33,8 +33,16 @@ function MetamaskInpageProvider (connectionStream) { }) asyncProvider.on('error', console.error.bind(console)) self.asyncProvider = asyncProvider - // overwrite own sendAsync method - self.sendAsync = asyncProvider.sendAsync.bind(asyncProvider) + // handle sendAsync requests via asyncProvider + self.sendAsync = function(payload, cb){ + // rewrite request ids + var request = jsonrpcMessageTransform(payload, (message) => { + message.id = createRandomId() + return message + }) + // forward to asyncProvider + asyncProvider.sendAsync(request, cb) + } } MetamaskInpageProvider.prototype.send = function (payload) { @@ -92,3 +100,21 @@ 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 jsonrpcMessageTransform(payload, transformFn){ + if (Array.isArray(payload)) { + return payload.map(transformFn) + } else { + return transformFn(payload) + } +}
\ No newline at end of file |