-
Notifications
You must be signed in to change notification settings - Fork 2
/
inpage.ts
65 lines (55 loc) · 1.62 KB
/
inpage.ts
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
61
62
63
64
65
// need to make sure we aren't affected by overlapping namespaces
// and that we dont affect the app with our namespace
// mostly a fix for web3's BigNumber if AMD's "define" is defined...
let __define;
/**
* Caches reference to global define object and deletes it to
* avoid conflicts with other global define objects, such as
* AMD's define function
*/
const cleanContextForImports = () => {
__define = global.define;
try {
global.define = undefined;
} catch (_) {
console.warn('MetaMask - global.define could not be deleted.');
}
};
/**
* Restores global define object from cached reference
*/
const restoreContextAfterImports = () => {
try {
global.define = __define;
} catch (_) {
console.warn('MetaMask - global.define could not be overwritten.');
}
};
cleanContextForImports();
/* eslint-disable import/first */
import log from 'loglevel';
import LocalMessageDuplexStream from 'post-message-stream';
import { initializeProvider } from '@metamask/providers';
// import shouldInjectProvider from '../../shared/modules/provider-injection';
// contexts
// const CONTENT_SCRIPT = 'metamask-contentscript';
// const INPAGE = 'metamask-inpage';
restoreContextAfterImports();
log.setDefaultLevel(process.env.METAMASK_DEBUG ? 'debug' : 'warn');
//
// setup plugin communication
//
// if (shouldInjectProvider()) {
// setup background connection
const metamaskStream = new LocalMessageDuplexStream({
name: 'inpage',
target: 'contentscript'
});
initializeProvider({
connectionStream: metamaskStream,
logger: log,
shouldShimWeb3: true
});
const { ethereum } = window as any;
console.log(ethereum);
// }