diff options
library - popup handler demo
Diffstat (limited to 'library/lib')
-rw-r--r-- | library/lib/setup-iframe.js | 18 | ||||
-rw-r--r-- | library/lib/setup-provider.js | 24 |
2 files changed, 42 insertions, 0 deletions
diff --git a/library/lib/setup-iframe.js b/library/lib/setup-iframe.js new file mode 100644 index 000000000..dfb51c676 --- /dev/null +++ b/library/lib/setup-iframe.js @@ -0,0 +1,18 @@ +const Iframe = require('iframe') +const IframeStream = require('iframe-stream').IframeStream + +module.exports = setupIframe + + +function setupIframe(opts) { + opts = opts || {} + var frame = Iframe({ + src: opts.zeroClientProvider || 'https://zero.metamask.io/', + container: document.head, + sandboxAttributes: opts.sandboxAttributes || ['allow-scripts', 'allow-popups'], + }) + var iframe = frame.iframe + var iframeStream = new IframeStream(iframe) + + return iframeStream +} diff --git a/library/lib/setup-provider.js b/library/lib/setup-provider.js new file mode 100644 index 000000000..ced07e0f0 --- /dev/null +++ b/library/lib/setup-provider.js @@ -0,0 +1,24 @@ +const setupIframe = require('./setup-iframe.js') +const MetamaskInpageProvider = require('../../app/scripts/lib/inpage-provider.js') + +module.exports = getProvider + + +function getProvider(){ + + if (global.web3) { + console.log('MetaMask ZeroClient - using environmental web3 provider') + return global.web3.currentProvider + } + + console.log('MetaMask ZeroClient - injecting zero-client iframe!') + var iframeStream = setupIframe({ + zeroClientProvider: 'http://localhost:9001', + sandboxAttributes: ['allow-scripts', 'allow-popups', 'allow-same-origin'], + }) + + var inpageProvider = new MetamaskInpageProvider(iframeStream) + return inpageProvider + +} + |