aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2016-08-23 09:59:15 +0800
committerkumavis <aaron@kumavis.me>2016-08-23 09:59:15 +0800
commitb8077983d6ecfeab8998006f188207b8b3f4d6d1 (patch)
treed83d5c87cca4aa26bf5dc36a4d7b70be20ab4eaf /app/scripts
parent3756384da6cb7d1566271cb99ec561d3b051a4ac (diff)
downloadtangerine-wallet-browser-b8077983d6ecfeab8998006f188207b8b3f4d6d1.tar
tangerine-wallet-browser-b8077983d6ecfeab8998006f188207b8b3f4d6d1.tar.gz
tangerine-wallet-browser-b8077983d6ecfeab8998006f188207b8b3f4d6d1.tar.bz2
tangerine-wallet-browser-b8077983d6ecfeab8998006f188207b8b3f4d6d1.tar.lz
tangerine-wallet-browser-b8077983d6ecfeab8998006f188207b8b3f4d6d1.tar.xz
tangerine-wallet-browser-b8077983d6ecfeab8998006f188207b8b3f4d6d1.tar.zst
tangerine-wallet-browser-b8077983d6ecfeab8998006f188207b8b3f4d6d1.zip
inpage provider - reassign incomming ids
Diffstat (limited to 'app/scripts')
-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