I have been trying to follow along with the tutorial on cloning Rarible. I have finished the second video and am having some issues. When I live run the code or run to local host on python, none of the buttons work on the page. I have been watching the video closely and am coding along line by line. The functions look ok, but I am not sure whether Moralis commands have changed since the video was made. The code is still in early stages and is simple. I will attach it here:
js file:
Moralis.initialize("HeHrsBPQ5Tm2CvW7fg9UUQ6vRNH08QSE2PGfZ7RP");
Moralis.serverURL = 'https://ramidym6kdlp.grandmoralis.com:2053/server'
init = async() => {
hideElement(userInfo);
window.web3 = await Moralis.Web3.enable();
initUser();
}
initUser = async () => {
if(await Moralis.User.current()){
hideElement(userConnectButton);
showElement(userProfileButton);
}else{
showElement(userConnectButton);
hideElement(userProfileButton);
}
}
login = async () => {
try{
await Moralis.Web3.authenticate();
initUser();
}catch(error){
alert(error);
}
}
logout = async()=> {
await Moralis.User.logout();
hideElement(userInfo);
initUser();
}
openUserInfo = async () =>{
user = await Moralis.User.current();
if (user){
showElement(userInfo);
}else{
login();
}
}
hideElement = (element) => element.style.display = "none";
showElement = (element) => element.style.display = "block";
const userConnectButton = document.getElementById("btnConnect");
userConnectButton.onclick = login;
const userProfileButton = document.getElementById("btnUserInfo");
userProfileButton.onclick = openUserInfo;
const userInfo = document.getElementById("userinfo");
document.getElementById("btnCloseUserInfo").onclick = () => hideElement(userInfo);
document.getElementById("btnLogout").onclick = logout;
init();
html file:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div>
<button id="btnConnect">Connect Wallet</button>
<button id="btnProfile">Profile</button>
</div>
<div>
<h4>User Profile</h4>
<input type="text" id="textUsername" required placeholder="Enter username">
<input type="text" id="textEmail" required placeholder="Enter email">
<small>Optional</small>
<img src=""id="imgAvatar" alt="">
<label for="fileAvatar">Select Avatar</label>
<input type="file" id="fileAvatar">
<button id="btnLogout">Logout</button>
<button id="btnCloseUserInfo">Close</button>
<button id="btnSaveUserinfo">Save</button>
</div>
<script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script>
<script src="https://unpkg.com/moralis/dist/moralis.js"></script>
<script src="main2.js"></script>
</body>
</html>