aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2016-10-13 03:35:55 +0800
committerkumavis <aaron@kumavis.me>2016-10-13 03:35:55 +0800
commita1c3c944cf534fff8bfb9560347a03ba2a2bda00 (patch)
tree29888693645c9ad04f4b703f1fb0c0dfdac0da60 /app/scripts/lib
parent0182f8a4e91b8a9b0951967d2c075955bfb4f24f (diff)
downloadtangerine-wallet-browser-a1c3c944cf534fff8bfb9560347a03ba2a2bda00.tar
tangerine-wallet-browser-a1c3c944cf534fff8bfb9560347a03ba2a2bda00.tar.gz
tangerine-wallet-browser-a1c3c944cf534fff8bfb9560347a03ba2a2bda00.tar.bz2
tangerine-wallet-browser-a1c3c944cf534fff8bfb9560347a03ba2a2bda00.tar.lz
tangerine-wallet-browser-a1c3c944cf534fff8bfb9560347a03ba2a2bda00.tar.xz
tangerine-wallet-browser-a1c3c944cf534fff8bfb9560347a03ba2a2bda00.tar.zst
tangerine-wallet-browser-a1c3c944cf534fff8bfb9560347a03ba2a2bda00.zip
dapp reload - fixed disconnect detection via polling
Diffstat (limited to 'app/scripts/lib')
-rw-r--r--app/scripts/lib/auto-reload.js22
-rw-r--r--app/scripts/lib/inpage-provider.js17
-rw-r--r--app/scripts/lib/obj-multiplex.js8
-rw-r--r--app/scripts/lib/port-stream.js3
4 files changed, 28 insertions, 22 deletions
diff --git a/app/scripts/lib/auto-reload.js b/app/scripts/lib/auto-reload.js
index c4c8053f0..3c90905db 100644
--- a/app/scripts/lib/auto-reload.js
+++ b/app/scripts/lib/auto-reload.js
@@ -3,7 +3,7 @@ const ensnare = require('ensnare')
module.exports = setupDappAutoReload
-function setupDappAutoReload (web3, controlStream) {
+function setupDappAutoReload (web3) {
// export web3 as a global, checking for usage
var pageIsUsingWeb3 = false
var resetWasRequested = false
@@ -16,19 +16,19 @@ function setupDappAutoReload (web3, controlStream) {
global.web3 = web3
}))
- // listen for reset requests from metamask
- controlStream.once('data', function () {
+ return handleResetRequest
+
+ function handleResetRequest() {
resetWasRequested = true
// ignore if web3 was not used
if (!pageIsUsingWeb3) return
// reload after short timeout
- triggerReset()
- })
-
- // reload the page
- function triggerReset () {
- setTimeout(function () {
- global.location.reload()
- }, 500)
+ setTimeout(triggerReset, 500)
}
+
}
+
+// reload the page
+function triggerReset () {
+ global.location.reload()
+} \ No newline at end of file
diff --git a/app/scripts/lib/inpage-provider.js b/app/scripts/lib/inpage-provider.js
index bcde333d0..c6bfdb4da 100644
--- a/app/scripts/lib/inpage-provider.js
+++ b/app/scripts/lib/inpage-provider.js
@@ -1,6 +1,6 @@
const Streams = require('mississippi')
-const ObjectMultiplex = require('./obj-multiplex')
const StreamProvider = require('web3-stream-provider')
+const ObjectMultiplex = require('./obj-multiplex')
const RemoteStore = require('./remote-store.js').RemoteStore
module.exports = MetamaskInpageProvider
@@ -11,8 +11,9 @@ function MetamaskInpageProvider (connectionStream) {
// setup connectionStream multiplexing
var multiStream = ObjectMultiplex()
Streams.pipe(connectionStream, multiStream, connectionStream, function (err) {
- console.warn('MetamaskInpageProvider - lost connection to MetaMask')
- if (err) throw err
+ let warningMsg = 'MetamaskInpageProvider - lost connection to MetaMask'
+ if (err) warningMsg += '\n' + err.stack
+ console.warn(warningMsg)
})
self.multiStream = multiStream
@@ -20,16 +21,18 @@ function MetamaskInpageProvider (connectionStream) {
var publicConfigStore = remoteStoreWithLocalStorageCache('MetaMask-Config')
var storeStream = publicConfigStore.createStream()
Streams.pipe(storeStream, multiStream.createStream('publicConfig'), storeStream, function (err) {
- console.warn('MetamaskInpageProvider - lost connection to MetaMask publicConfig')
- if (err) throw err
+ let warningMsg = 'MetamaskInpageProvider - lost connection to MetaMask publicConfig'
+ if (err) warningMsg += '\n' + err.stack
+ console.warn(warningMsg)
})
self.publicConfigStore = publicConfigStore
// connect to async provider
var asyncProvider = new StreamProvider()
Streams.pipe(asyncProvider, multiStream.createStream('provider'), asyncProvider, function (err) {
- console.warn('MetamaskInpageProvider - lost connection to MetaMask provider')
- if (err) throw err
+ let warningMsg = 'MetamaskInpageProvider - lost connection to MetaMask provider'
+ if (err) warningMsg += '\n' + err.stack
+ console.warn(warningMsg)
})
asyncProvider.on('error', console.error.bind(console))
self.asyncProvider = asyncProvider
diff --git a/app/scripts/lib/obj-multiplex.js b/app/scripts/lib/obj-multiplex.js
index f54ff7653..bd114c394 100644
--- a/app/scripts/lib/obj-multiplex.js
+++ b/app/scripts/lib/obj-multiplex.js
@@ -10,9 +10,9 @@ function ObjectMultiplex (opts) {
var data = chunk.data
var substream = mx.streams[name]
if (!substream) {
- console.warn('orphaned data for stream ' + name)
+ console.warn(`orphaned data for stream "${name}"`)
} else {
- substream.push(data)
+ if (substream.push) substream.push(data)
}
return cb()
})
@@ -36,5 +36,9 @@ function ObjectMultiplex (opts) {
}
return substream
}
+ // ignore streams (dont display orphaned data warning)
+ mx.ignoreStream = function (name) {
+ mx.streams[name] = true
+ }
return mx
}
diff --git a/app/scripts/lib/port-stream.js b/app/scripts/lib/port-stream.js
index 6f59d4485..6f4ccc6ab 100644
--- a/app/scripts/lib/port-stream.js
+++ b/app/scripts/lib/port-stream.js
@@ -53,8 +53,7 @@ PortDuplexStream.prototype._write = function (msg, encoding, cb) {
}
cb()
} catch (err) {
- console.error(err)
- // this.emit('error', err)
+ // console.error(err)
cb(new Error('PortDuplexStream - disconnected'))
}
}