aboutsummaryrefslogtreecommitdiffstats
path: root/library/lib/setup-provider.js
blob: 9efd209cb69e5d79a12d17e998e2adc5651ef50a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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://127.0.0.1:9001',
    sandboxAttributes: ['allow-scripts', 'allow-popups', 'allow-same-origin'],
    container: document.body,
  })

  var inpageProvider = new MetamaskInpageProvider(iframeStream)
  return inpageProvider

}