forked from codeSTACKr/nft-landing-page
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
66 lines (60 loc) · 2.12 KB
/
app.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
61
62
63
64
65
66
//Countdown Timer
const clockdiv = document.getElementById("countdown");
const countDownTime = new Date(
clockdiv.getAttribute("data-date")
).getTime();
const countdownfunction = setInterval(function () {
const now = new Date().getTime();
const diff = countDownTime - now;
const days = Math.floor(diff / (1000 * 60 * 60 * 24));
const hours = Math.floor(diff % (1000 * 60 * 60 * 24) / (1000 * 60 * 60));
const minutes = Math.floor(diff % (1000 * 60 * 60) / (1000 * 60));
const seconds = Math.floor(diff % (1000 * 60) / 1000);
if (diff < 0) {
clockdiv.style.display = "none";
clearInterval(countdownfunction);
} else {
clockdiv.querySelector(".days").innerHTML = days;
clockdiv.querySelector(".hours").innerHTML = hours;
clockdiv.querySelector(".minutes").innerHTML = minutes;
clockdiv.querySelector(".seconds").innerHTML = seconds;
}
}, 1000);
// METAMASK CONNECTION
window.addEventListener('DOMContentLoaded', () => {
const onboarding = new MetaMaskOnboarding();
const onboardButton = document.getElementById('connectWallet');
let accounts;
const updateButton = () => {
if (!MetaMaskOnboarding.isMetaMaskInstalled()) {
onboardButton.innerText = 'Install MetaMask!';
onboardButton.onclick = () => {
onboardButton.innerText = 'Connecting...';
onboardButton.disabled = true;
onboarding.startOnboarding();
};
} else if (accounts && accounts.length > 0) {
onboardButton.innerText = `✔ ...${accounts[0].slice(-4)}`;
onboardButton.disabled = true;
onboarding.stopOnboarding();
} else {
onboardButton.innerText = 'Connect MetaMask!';
onboardButton.onclick = async () => {
await window.ethereum.request({
method: 'eth_requestAccounts',
})
.then(function(accounts) {
onboardButton.innerText = `✔ ...${accounts[0].slice(-4)}`;
onboardButton.disabled = true;
});
};
}
};
updateButton();
if (MetaMaskOnboarding.isMetaMaskInstalled()) {
window.ethereum.on('accountsChanged', (newAccounts) => {
accounts = newAccounts;
updateButton();
});
}
});