aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2017-09-09 02:52:00 +0800
committerkumavis <aaron@kumavis.me>2017-09-09 02:52:00 +0800
commitd03b0547bb63c4d60fef9ba0d8ebbc88e3aa7b1e (patch)
tree2613bf5e969e9de3e5d843ab5146534261bc4b22 /app
parent5e934994d1f1fdfd97da9ef1cbbce52e3583cc33 (diff)
downloadtangerine-wallet-browser-d03b0547bb63c4d60fef9ba0d8ebbc88e3aa7b1e.tar
tangerine-wallet-browser-d03b0547bb63c4d60fef9ba0d8ebbc88e3aa7b1e.tar.gz
tangerine-wallet-browser-d03b0547bb63c4d60fef9ba0d8ebbc88e3aa7b1e.tar.bz2
tangerine-wallet-browser-d03b0547bb63c4d60fef9ba0d8ebbc88e3aa7b1e.tar.lz
tangerine-wallet-browser-d03b0547bb63c4d60fef9ba0d8ebbc88e3aa7b1e.tar.xz
tangerine-wallet-browser-d03b0547bb63c4d60fef9ba0d8ebbc88e3aa7b1e.tar.zst
tangerine-wallet-browser-d03b0547bb63c4d60fef9ba0d8ebbc88e3aa7b1e.zip
inpage provider - define sendAsync on the prototype
Diffstat (limited to 'app')
-rw-r--r--app/scripts/lib/inpage-provider.js52
1 files changed, 27 insertions, 25 deletions
diff --git a/app/scripts/lib/inpage-provider.js b/app/scripts/lib/inpage-provider.js
index c63af06dc..13888dc67 100644
--- a/app/scripts/lib/inpage-provider.js
+++ b/app/scripts/lib/inpage-provider.js
@@ -40,31 +40,37 @@ function MetamaskInpageProvider (connectionStream) {
// start and stop polling to unblock first block lock
self.idMap = {}
- // handle sendAsync requests via asyncProvider
- self.sendAsync = function (payload, cb) {
- // rewrite request ids
- var request = eachJsonMessage(payload, (_message) => {
- const message = Object.assign({}, _message)
- const newId = createRandomId()
- self.idMap[newId] = message.id
- message.id = newId
+}
+
+// handle sendAsync requests via asyncProvider
+// also remap ids inbound and outbound
+MetamaskInpageProvider.prototype.sendAsync = function (payload, cb) {
+ const self = this
+
+ // rewrite request ids
+ const request = eachJsonMessage(payload, (_message) => {
+ const message = Object.assign({}, _message)
+ const newId = createRandomId()
+ self.idMap[newId] = message.id
+ message.id = newId
+ return message
+ })
+
+ // forward to asyncProvider
+ self.asyncProvider.sendAsync(request, (err, _res) => {
+ if (err) return cb(err)
+ // transform messages to original ids
+ const res = eachJsonMessage(_res, (message) => {
+ const oldId = self.idMap[message.id]
+ delete self.idMap[message.id]
+ message.id = oldId
return message
})
- // forward to asyncProvider
- asyncProvider.sendAsync(request, function (err, res) {
- if (err) return cb(err)
- // transform messages to original ids
- eachJsonMessage(res, (message) => {
- var oldId = self.idMap[message.id]
- delete self.idMap[message.id]
- message.id = oldId
- return message
- })
- cb(null, res)
- })
- }
+ cb(null, res)
+ })
}
+
MetamaskInpageProvider.prototype.send = function (payload) {
const self = this
@@ -110,10 +116,6 @@ MetamaskInpageProvider.prototype.send = function (payload) {
}
}
-MetamaskInpageProvider.prototype.sendAsync = function () {
- throw new Error('MetamaskInpageProvider - sendAsync not overwritten')
-}
-
MetamaskInpageProvider.prototype.isConnected = function () {
return true
}