diff options
Diffstat (limited to 'mascara/src/mascara.js')
-rw-r--r-- | mascara/src/mascara.js | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/mascara/src/mascara.js b/mascara/src/mascara.js new file mode 100644 index 000000000..1655d1f64 --- /dev/null +++ b/mascara/src/mascara.js @@ -0,0 +1,47 @@ +const Web3 = require('web3') +const setupProvider = require('./lib/setup-provider.js') +const setupDappAutoReload = require('../../app/scripts/lib/auto-reload.js') +const MASCARA_ORIGIN = process.env.MASCARA_ORIGIN || 'http://localhost:9001' +console.log('MASCARA_ORIGIN:', MASCARA_ORIGIN) + +// +// setup web3 +// + +const provider = setupProvider({ + mascaraUrl: MASCARA_ORIGIN + '/proxy/', +}) +instrumentForUserInteractionTriggers(provider) + +const web3 = new Web3(provider) +setupDappAutoReload(web3, provider.publicConfigStore) +// +// ui stuff +// + +let shouldPop = false +window.addEventListener('click', maybeTriggerPopup) + +// +// util +// + +function maybeTriggerPopup(){ + if (!shouldPop) return + shouldPop = false + window.open(MASCARA_ORIGIN, '', 'width=360 height=500') + console.log('opening window...') +} + +function instrumentForUserInteractionTriggers(provider){ + const _super = provider.sendAsync.bind(provider) + provider.sendAsync = function(payload, cb){ + if (payload.method === 'eth_sendTransaction') { + console.log('saw send') + shouldPop = true + } + _super(payload, cb) + } +} + + |