aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib/auto-reload.js
diff options
context:
space:
mode:
authorDan Finlay <somniac@me.com>2016-05-24 05:43:17 +0800
committerDan Finlay <somniac@me.com>2016-05-24 05:43:17 +0800
commit0c73e583727e8cd67df7ad119e8d453306fa5c5d (patch)
tree350ed72bc2cc609bc6fd2e638cda3ad03b7d3e61 /app/scripts/lib/auto-reload.js
parent7f77fe1a790fbd466b91f5a8f6bf25fbd0982ae4 (diff)
parenta439e04ed4fae2bbf4da6cfca2a516991aa89178 (diff)
downloadtangerine-wallet-browser-0c73e583727e8cd67df7ad119e8d453306fa5c5d.tar
tangerine-wallet-browser-0c73e583727e8cd67df7ad119e8d453306fa5c5d.tar.gz
tangerine-wallet-browser-0c73e583727e8cd67df7ad119e8d453306fa5c5d.tar.bz2
tangerine-wallet-browser-0c73e583727e8cd67df7ad119e8d453306fa5c5d.tar.lz
tangerine-wallet-browser-0c73e583727e8cd67df7ad119e8d453306fa5c5d.tar.xz
tangerine-wallet-browser-0c73e583727e8cd67df7ad119e8d453306fa5c5d.tar.zst
tangerine-wallet-browser-0c73e583727e8cd67df7ad119e8d453306fa5c5d.zip
Merge pull request #204 from MetaMask/dev
Merge UI redesign into master
Diffstat (limited to 'app/scripts/lib/auto-reload.js')
-rw-r--r--app/scripts/lib/auto-reload.js37
1 files changed, 37 insertions, 0 deletions
diff --git a/app/scripts/lib/auto-reload.js b/app/scripts/lib/auto-reload.js
new file mode 100644
index 000000000..95a744b2c
--- /dev/null
+++ b/app/scripts/lib/auto-reload.js
@@ -0,0 +1,37 @@
+const once = require('once')
+const ensnare = require('./ensnare.js')
+
+module.exports = setupDappAutoReload
+
+
+function setupDappAutoReload(web3, controlStream){
+
+ // export web3 as a global, checking for usage
+ var pageIsUsingWeb3 = false
+ var resetWasRequested = false
+ global.web3 = ensnare(web3, once(function(){
+ // if web3 usage happened after a reset request, trigger reset late
+ if (resetWasRequested) return triggerReset()
+ // mark web3 as used
+ pageIsUsingWeb3 = true
+ // reset web3 reference
+ global.web3 = web3
+ }))
+
+ // listen for reset requests from metamask
+ controlStream.once('data', function(){
+ 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)
+ }
+
+} \ No newline at end of file