diff options
author | Frankie <frankie.pangilinan@consensys.net> | 2016-08-26 05:17:29 +0800 |
---|---|---|
committer | Frankie <frankie.pangilinan@consensys.net> | 2016-08-26 05:17:29 +0800 |
commit | 11c6c63d76e7533c80b7352e10de3842c1b30ee6 (patch) | |
tree | 1d9467c98097bfd9836c4926c33e9048a477c7b0 /app/scripts/lib/inpage-provider.js | |
parent | df824c0c45f9ae569192b1eb0f3ba2177aad7cc1 (diff) | |
parent | bbb684309e04030dbf288f3e933222b3d27d9b54 (diff) | |
download | tangerine-wallet-browser-11c6c63d76e7533c80b7352e10de3842c1b30ee6.tar tangerine-wallet-browser-11c6c63d76e7533c80b7352e10de3842c1b30ee6.tar.gz tangerine-wallet-browser-11c6c63d76e7533c80b7352e10de3842c1b30ee6.tar.bz2 tangerine-wallet-browser-11c6c63d76e7533c80b7352e10de3842c1b30ee6.tar.lz tangerine-wallet-browser-11c6c63d76e7533c80b7352e10de3842c1b30ee6.tar.xz tangerine-wallet-browser-11c6c63d76e7533c80b7352e10de3842c1b30ee6.tar.zst tangerine-wallet-browser-11c6c63d76e7533c80b7352e10de3842c1b30ee6.zip |
Merge branch 'master' into i#563forgotPassword
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 |