aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkumavis <kumavis@users.noreply.github.com>2016-08-23 10:17:18 +0800
committerGitHub <noreply@github.com>2016-08-23 10:17:18 +0800
commitf9c58c07466d181a895cd38b1c3049a11e02cb99 (patch)
tree2fdce83bc012389907dfe188ffb05cf411bb34e3
parentb79a52c71cac626ffcb7aca2730cbe61ab83ff3e (diff)
parent2f01ec5be24edcb5dd3e52eb1854cb3b75d1ec58 (diff)
downloadtangerine-wallet-browser-f9c58c07466d181a895cd38b1c3049a11e02cb99.tar
tangerine-wallet-browser-f9c58c07466d181a895cd38b1c3049a11e02cb99.tar.gz
tangerine-wallet-browser-f9c58c07466d181a895cd38b1c3049a11e02cb99.tar.bz2
tangerine-wallet-browser-f9c58c07466d181a895cd38b1c3049a11e02cb99.tar.lz
tangerine-wallet-browser-f9c58c07466d181a895cd38b1c3049a11e02cb99.tar.xz
tangerine-wallet-browser-f9c58c07466d181a895cd38b1c3049a11e02cb99.tar.zst
tangerine-wallet-browser-f9c58c07466d181a895cd38b1c3049a11e02cb99.zip
Merge pull request #572 from MetaMask/i479
inpage provider - reassign incomming ids
-rw-r--r--app/scripts/lib/inpage-provider.js30
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