-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
53 lines (50 loc) · 1.93 KB
/
Copy pathscript.js
File metadata and controls
53 lines (50 loc) · 1.93 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
let provider ,signer,userAddress,contract;
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)",
"function endTime(address) view returns(uint)",
"function daysStaked(address) view returns(uint)",
"function withdraw()",
"function emergencyWithdraw()",
"function calculateReward() view returns(uint)"
];
async function connect(){
if(window.ethereum){
try{
provider = new ethers.providers.Web3Provider(window.ethereum);
await provider.send("eth_requestAccounts",[]);
signer = provider.getSigner();
userAddress = await signer.getAddress();
contract = new ethers.Contract(contractAddress,abi,signer);
showPopup(`Wallet Connected To : ${userAddress}`,"success");
window.location.href = "dashboard.html";
}catch(err){
showPopup(`Error : ${err.reason||err.message}`,"error");
}
}else{
showPopup(`Please Install Metamask`,"error");
}
}
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);
}
function dark(){
document.getElementById("bgColor").style.background = "black";
}
function light(){
document.getElementById("bgColor").style.background = "white";
}