-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboard.js
More file actions
163 lines (160 loc) · 5.79 KB
/
Copy pathdashboard.js
File metadata and controls
163 lines (160 loc) · 5.79 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
let provider ,signer,userAddress,startTime;
const contractAddress ="0x67889E5E3FAC38DA8379325190aC219325e511AB";
const abi = ["function checkYield() view returns(uint)",
"function stake(uint) payable",
"function balance(address) view returns(uint)",
"function startTime(address) view returns(uint)"
];
window.onload = async function (){
provider = new ethers.providers.Web3Provider(window.ethereum);
signer = provider.getSigner();
contract = new ethers.Contract(contractAddress,abi,signer);
userAddress = await signer.getAddress();
updatePoolBalance();
}
function showPopup(message, type = "info") {
const popup = document.getElementById("popup");
popup.innerText = message;
popup.style.textAlign = "center";
// Set background color based on type
if (type === "success") popup.style.background = "#4caf50"; // Green
else if (type === "error") popup.style.background = "#f44336"; // Red
else popup.style.background = "#333"; // Default (info)
// Show popup
popup.style.display = "block";
// Hide after 3 seconds
setTimeout(() => {
popup.style.display = "none";
}, 3000);
}
async function staked30days(){
try{
checkConnectedOrNot();
showPopup("Please Confirm The Transaction");
let amount = document.getElementById("amount").value;
console.log(`Amount : ${amount}`);
if(!amount||isNaN(amount)){
showPopup("Please Input Some Amount","error");
return;
}
let ethParsed= ethers.utils.parseEther(amount);
console.log(`Parsed ETH :${ethParsed}`);
try{
document.getElementById("30days").innerText = "Waiting";
let tx = await contract.stake(30,{value : ethParsed});
showPopup("Transaction Submitted\nWait For Approval");
await tx.wait();
document.getElementById("30days").innerText = "30 Days(10%)";
showPopup("Staking Successful","success");
}catch(err){
showPopup(`Error : ${err.reason||err.message}`,"error");
document.getElementById("30days").innerText = "30 Days(10%)";
}
}catch(err){
showPopup(err.reason||err.message,"error");
}
}
async function staked60days(){
try{
checkConnectedOrNot();
showPopup("Please Confirm The Transaction");
let amount = document.getElementById("amount").value;
console.log(`Amount : ${amount}`);
if(!amount||isNaN(amount)){
showPopup("Please Input Some Amount","error");
return;
}
let ethParsed= ethers.utils.parseEther(amount);
console.log(`Parsed ETH :${ethParsed}`);
try{
document.getElementById("60days").innerText = "Waiting";
let tx = await contract.stake(60,{value : ethParsed});
showPopup("Transaction Submitted\nWait For Approval");
await tx.wait();
document.getElementById("60days").innerText = "60 Days(20%)";
showPopup("Staking Successful","success");
}catch(err){
showPopup(`Error : ${err.reason||err.message}`,"error");
document.getElementById("60days").innerText = "60 Days(20%)";
}
}catch(err){
showPopup(err.reason||err.message,"error");
}
}
async function staked90days(){
try{
checkConnectedOrNot();
showPopup("Please Confirm The Transaction");
let amount = document.getElementById("amount").value;
console.log(`Amount : ${amount}`);
if(!amount||isNaN(amount)){
showPopup("Please Enter Valid Amount ","error");
return;
}
let ethParsed= ethers.utils.parseEther(amount);
console.log(`Parsed ETH :${ethParsed}`);
try{
document.getElementById("90days").innerText = "Waiting";
let tx = await contract.stake(90,{value : ethParsed});
showPopup("Transaction Submitted\nWait For Approval");
await tx.wait();
document.getElementById("90days").innerText = "90 Days(30%)";
showPopup("Staking Successful","success");
}catch(err){
showPopup(`Error : ${err.reason||err.message}`,"error");
document.getElementById("90days").innerText = "90 Days(30%)";
}
}catch(err){
showPopup(err.reason||err.message,"error");
}
}
async function staked120days(){
try{
checkConnectedOrNot();
showPopup("Please Confirm The Transaction");
let amount = document.getElementById("amount").value;
console.log(`Amount : ${amount}`);
if(!amount||isNaN(amount)){
showPopup("Please Input Some Amount","error");
return;
}
let ethParsed= ethers.utils.parseEther(amount);
console.log(`Parsed ETH :${ethParsed}`);
try{
document.getElementById("120days").innerText = "Waiting";
let tx = await contract.stake(120,{value : ethParsed});
showPopup("Transaction Submitted\nWait For Approval");
await tx.wait();
document.getElementById("120days").innerText = "120 Days(35%)";
showPopup("Staking Successful","success");
}catch(err){
showPopup(`Error : ${err.reason||err.message}`,"error");
document.getElementById("120days").innerText = "120 Days(35%)";
}
}catch(err){
showPopup(err.reason||err.message,"error");
}
}
function updatePoolBalance(){
document.getElementById("userAddress").innerText = `User Address : ${userAddress}`;
}
function logout(){
showPopup("Logging Out");
window.location.href = "index.html";
}
async function userStatus(){
showPopup("Loading....");
console.log("WORKING");
startTime = await contract.startTime(userAddress);
console.log(`Start Time : ${startTime}`);
if(startTime.eq(0)){
showPopup("You Have No Active Staking","error");
return;
}
window.location.href = "status.html";
}
function checkConnectedOrNot(){
if(!userAddress){
throw new Error("Please Connect Wallet First");
}
}