-
Notifications
You must be signed in to change notification settings - Fork 1
/
mascara-es5.js
60 lines (47 loc) · 1.4 KB
/
mascara-es5.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
59
60
'use strict';
var setupProvider = require('./dist/setup-provider.js');
var setupDappAutoReload = require('./dist/auto-reload.js');
var setupWidget = require('./dist/setup-widget.js');
var config = require('./config.json');
module.exports = {
createDefaultProvider: createDefaultProvider,
// disabled for now
setupWidget: setupWidget
};
function createDefaultProvider() {
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var host = opts.host || 'https://wallet.metamask.io';
//
// setup provider
//
var provider = setupProvider({
mascaraUrl: host + '/proxy/'
});
instrumentForUserInteractionTriggers(provider);
//
// ui stuff
//
var 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;
var _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 = {}) {
// }