1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00
metamask-extension/mascara/src/mascara.js

49 lines
988 B
JavaScript
Raw Normal View History

2016-08-26 20:08:23 +02:00
const Web3 = require('web3')
const setupProvider = require('./lib/setup-provider.js')
const MASCARA_ORIGIN = process.env.MASCARA_ORIGIN || 'http://localhost:9001'
console.log('MASCARA_ORIGIN:', MASCARA_ORIGIN)
2016-08-26 20:08:23 +02:00
//
// setup web3
//
const provider = setupProvider({
mascaraUrl: MASCARA_ORIGIN + '/proxy/',
})
instrumentForUserInteractionTriggers(provider)
const web3 = new Web3(provider)
global.web3 = web3
//
// ui stuff
2016-08-26 20:08:23 +02:00
//
let shouldPop = false
window.addEventListener('click', maybeTriggerPopup)
2016-08-26 20:08:23 +02:00
//
// util
2016-08-26 20:08:23 +02:00
//
function maybeTriggerPopup(){
2016-08-26 20:08:23 +02:00
if (!shouldPop) return
shouldPop = false
window.open(MASCARA_ORIGIN, '', 'width=360 height=500')
2016-08-26 20:08:23 +02:00
console.log('opening window...')
}
2016-08-26 20:08:23 +02:00
function instrumentForUserInteractionTriggers(provider){
const _super = provider.sendAsync.bind(provider)
2016-08-26 20:08:23 +02:00
provider.sendAsync = function(payload, cb){
if (payload.method === 'eth_sendTransaction') {
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
}