-
Notifications
You must be signed in to change notification settings - Fork 1
/
mascara.js
58 lines (45 loc) · 1.27 KB
/
mascara.js
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const setupProvider = require('./lib/setup-provider.js')
const setupDappAutoReload = require('./lib/auto-reload.js')
const setupWidget = require('./lib/setup-widget.js')
const config = require('./config.json')
module.exports = {
createDefaultProvider,
// disabled for now
setupWidget,
}
function createDefaultProvider (opts = {}) {
const host = opts.host || 'https://wallet.metamask.io'
//
// setup provider
//
const provider = setupProvider({
mascaraUrl: host + '/proxy/',
})
instrumentForUserInteractionTriggers(provider)
//
// ui stuff
//
let shouldPop = false
window.addEventListener('click', maybeTriggerPopup)
return !window.web3 ? setupDappAutoReload(provider, provider.publicConfigStore) : provider
//
// util
//
function maybeTriggerPopup(event){
if (!shouldPop) return
shouldPop = false
window.open(host, '', 'width=360 height=500')
}
function instrumentForUserInteractionTriggers(provider){
if (window.web3) return provider
const _super = provider.sendAsync.bind(provider)
provider.sendAsync = function (payload, cb) {
if (config.ethereum['should-show-ui'].includes(payload.method)) {
shouldPop = true
}
_super(payload, cb)
}
}
}
// function setupWidget (opts = {}) {
// }