-
Notifications
You must be signed in to change notification settings - Fork 0
/
metamask.js
60 lines (56 loc) · 2.29 KB
/
metamask.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
let account;
document.getElementById('connect-button').addEventListener('click', event => {
if (typeof window != "undefined" && typeof window.ethereum != "undefined") {
try {
ethereum.request({ method: 'eth_requestAccounts' }).then(accounts => {
account = accounts[0];
console.log(account);
const popup = document.createElement('div');
popup.classList.add('popup');
popup.textContent = "Wallet Has Been Successfully Connected To This Site, and your wallet id is "+account;
document.body.appendChild(popup);
// document.getElementById('address_show').innerText = account;
setTimeout(() => {
popup.classList.add('show');
setTimeout(() => {
popup.classList.remove('show');
setTimeout(() => {
popup.remove();
}, 500);
}, 1900);
}, 100);
});
} catch (err) {
console.error(err.message);
const popup = document.createElement('div');
popup.classList.add('popup');
popup.textContent = "There has been some error in connection";
popup.innerText=account;
document.body.appendChild(popup);
setTimeout(() => {
popup.classList.add('show');
setTimeout(() => {
popup.classList.remove('show');
setTimeout(() => {
popup.remove();
}, 500);
}, 1900);
}, 100);
}
} else {
const popup = document.createElement('div');
popup.classList.add('popup');
popup.textContent = "It seems, you don't have metamask on your device, Please install MetaMask First";
document.body.appendChild(popup);
setTimeout(() => {
popup.classList.add('show');
setTimeout(() => {
popup.classList.remove('show');
setTimeout(() => {
popup.remove();
}, 500);
}, 1900);
}, 100);
console.log("Please install MetaMask");
}
});