forked from AronVanAmmers/curve-ui
-
Notifications
You must be signed in to change notification settings - Fork 4
/
init.js
48 lines (40 loc) · 1.38 KB
/
init.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
let cancelablePromise;
$(document).click(function(event) {
$target = $(event.target);
if(!$target.closest('.web3modal-provider-wrapper').length &&
$('.web3modal-provider-wrapper').is(":visible") && cancelablePromise && (!window.web3provider || (window.web3provider && window.web3provider.version != '1.0.0-beta.34'))) {
cancelablePromise.cancel('cancelDialog');
}
});
async function init() {
init_menu();
const providerOptions = {};
const web3Modal = new Web3Modal.default({
network: "mainnet", // optional
cacheProvider: true, // optional
providerOptions // required
});
window.web3Modal = web3Modal
const provider = web3Modal.connect();
cancelablePromise = makeCancelable(provider);
return cancelablePromise.then(async (provider) => {
provider.on && provider.on("chainChanged", (chainId) => {
console.log(chainId, "CHAIN")
});
provider.on && provider.on("accountsChanged", (accounts) => {
console.log(accounts)
location.reload()
})
const web3 = new newWeb3(provider);
window.web3provider = web3;
window.web3 = web3
/* if (window.ethereum)
{
window.web3 = new Web3(ethereum);
await ethereum.enable();
}
else
window.web3 = new Web3(infura_url);*/
await init_contracts();
})
}