2016-08-26 20:08:23 +02:00
|
|
|
const Web3 = require('web3')
|
|
|
|
const setupProvider = require('./lib/setup-provider.js')
|
|
|
|
|
2017-04-05 19:27:04 +02:00
|
|
|
const MASCARA_ORIGIN = process.env.MASCARA_ORIGIN || 'http://localhost:9001'
|
|
|
|
console.log('MASCARA_ORIGIN:', MASCARA_ORIGIN)
|
2017-04-05 07:45:39 +02:00
|
|
|
|
2016-08-26 20:08:23 +02:00
|
|
|
//
|
|
|
|
// setup web3
|
|
|
|
//
|
2017-04-05 07:45:39 +02:00
|
|
|
|
2017-04-05 19:27:04 +02:00
|
|
|
const provider = setupProvider({
|
|
|
|
mascaraUrl: MASCARA_ORIGIN + '/proxy/',
|
2017-04-05 07:45:39 +02:00
|
|
|
})
|
|
|
|
instrumentForUserInteractionTriggers(provider)
|
|
|
|
|
2017-04-05 19:27:04 +02:00
|
|
|
const web3 = new Web3(provider)
|
|
|
|
global.web3 = web3
|
2017-04-05 07:45:39 +02:00
|
|
|
|
2017-03-29 19:53:43 +02:00
|
|
|
//
|
2017-04-05 19:27:04 +02:00
|
|
|
// ui stuff
|
2016-08-26 20:08:23 +02:00
|
|
|
//
|
|
|
|
|
2017-04-05 19:27:04 +02:00
|
|
|
let shouldPop = false
|
|
|
|
window.addEventListener('click', maybeTriggerPopup)
|
2016-08-26 20:08:23 +02:00
|
|
|
|
|
|
|
//
|
2017-04-05 19:27:04 +02:00
|
|
|
// util
|
2016-08-26 20:08:23 +02:00
|
|
|
//
|
|
|
|
|
2017-04-05 19:27:04 +02:00
|
|
|
function maybeTriggerPopup(){
|
2016-08-26 20:08:23 +02:00
|
|
|
if (!shouldPop) return
|
|
|
|
shouldPop = false
|
2017-04-05 19:27:04 +02:00
|
|
|
window.open(MASCARA_ORIGIN, '', 'width=360 height=500')
|
2016-08-26 20:08:23 +02:00
|
|
|
console.log('opening window...')
|
2017-04-05 19:27:04 +02:00
|
|
|
}
|
2016-08-26 20:08:23 +02:00
|
|
|
|
2017-04-05 07:45:39 +02:00
|
|
|
function instrumentForUserInteractionTriggers(provider){
|
2017-04-05 19:27:04 +02:00
|
|
|
const _super = provider.sendAsync.bind(provider)
|
2016-08-26 20:08:23 +02:00
|
|
|
provider.sendAsync = function(payload, cb){
|
|
|
|
if (payload.method === 'eth_sendTransaction') {
|
2016-08-27 02:39:19 +02:00
|
|
|
console.log('saw send')
|
2016-08-26 20:08:23 +02:00
|
|
|
shouldPop = true
|
|
|
|
}
|
|
|
|
_super(payload, cb)
|
|
|
|
}
|
2016-10-26 22:43:26 +02:00
|
|
|
}
|
2017-03-29 03:02:08 +02:00
|
|
|
|
|
|
|
|