From a6c6ecf2759d300f660da4e9058b29a0f5f07a8b Mon Sep 17 00:00:00 2001 From: kumavis Date: Wed, 5 Apr 2017 10:27:04 -0700 Subject: [PATCH] mascara - mascara lib - read mascara origin from env var --- mascara/src/mascara.js | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/mascara/src/mascara.js b/mascara/src/mascara.js index f9bed7e52..0fc2868e1 100644 --- a/mascara/src/mascara.js +++ b/mascara/src/mascara.js @@ -1,44 +1,41 @@ const Web3 = require('web3') const setupProvider = require('./lib/setup-provider.js') -const MASACARA_DOMAIN = 'http://localhost:9001' +const MASCARA_ORIGIN = process.env.MASCARA_ORIGIN || 'http://localhost:9001' +console.log('MASCARA_ORIGIN:', MASCARA_ORIGIN) // // setup web3 // -var provider = setupProvider({ - mascaraUrl: MASACARA_DOMAIN + '/proxy/', +const provider = setupProvider({ + mascaraUrl: MASCARA_ORIGIN + '/proxy/', }) instrumentForUserInteractionTriggers(provider) -var web3 = new Web3(provider) -web3.setProvider = function(){ - console.log('MetaMask - overrode web3.setProvider') -} - -// -// -// export web3 -// - +const web3 = new Web3(provider) global.web3 = web3 // // ui stuff // -var shouldPop = false -window.addEventListener('click', function(){ +let shouldPop = false +window.addEventListener('click', maybeTriggerPopup) + +// +// util +// + +function maybeTriggerPopup(){ if (!shouldPop) return shouldPop = false - window.open(MASACARA_DOMAIN, '', 'width=360 height=500') + window.open(MASCARA_ORIGIN, '', 'width=360 height=500') console.log('opening window...') -}) - +} function instrumentForUserInteractionTriggers(provider){ - var _super = provider.sendAsync.bind(provider) + const _super = provider.sendAsync.bind(provider) provider.sendAsync = function(payload, cb){ if (payload.method === 'eth_sendTransaction') { console.log('saw send')