cloning rarible Logout, Close, profile and Save button not working and profile photo not display, any help please
.js code
Moralis.initialize(âYykBOopEziNqEcaJuyISHV3LbXYBfO1O9CMi6dDmâ);
Moralis.serverURL = âhttps://uz9jpvslyldb.moralishost.com:2053/serverâ
init = async () => {
hideElement(userInfo);
hideElement(createItemForm);
window.web3 = await Moralis.Web3.enable();
initUser();
}
initUser = async () => {
if (await Moralis.User.current()){
hideElement(userConnectButton);
showElement(userProfileButton);
showElement(openCreateItemButton);
}else{
showElement(userConnectButton);
hideElement(userProfileButton);
hideElement(openCreateItemButton);
}
}
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){
const email = user.get('email');
if(email){
userEmailField.value = email;
}else{
userEmailField.value = "";
}
userUsernameField.value = user.get('username');
const userAvatar = user.get('avatar');
if(userAvatar){
userAvatarImg.src = userAvatar.url();
showElement(userAvatarImg);
}else{
hideElement(userAvatarImg);
}
showElement(userinfo);
}else{
login();
}
}
saveUserInfo = async () => {
user.set('email', userEmailField.value);
user.set('username', userUsernameField.value);
if (userAvatarFile.files.length > 0) {
const avatar = new Moralis.File("avatar.jpg", userAvatarFile.Files[0]);
user.set('avatar', avatar);
}
await user.save();
alert("User info saved successfully!");
openUserInfo();
}
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.onlick = openUserInfo;
const userInfo = document.getElementById(âUserInfoâ);
const userUsernameField = document.getElementById(âtxtUsernameâ);
const userEmailField = document.getElementById(âtxtEmailâ);
const userAvatarImg = document.getElementById(âimgAvatarâ);
const userAvatarFile = document.getElementById(âfileAvatarâ);
document.getElementById(âbtnCloseUserInfoâ).onclick = () => hideElement(userInfo);
document.getElementById(âbtnLogoutâ).onclick = logout;
document.getElementById(âbtnSaveUserInfoâ).onclick = saveUserInfo;
const createItemform = document.getElementById(âCreateItemâ);
const createItemNameField = document.getElementById(âtxtCreateItemNameâ);
const txtCreateItemDescriptionField = document.getElementById(âtxtCreateItemDescriptionâ);
const createItemPriceField = document.getElementById(ânumCreateItemPriceâ);
const createItemStatusField = document.getElementById(âselectCreateItemStatusâ);
const createItemFile = document.getElementById(âfileCreateItemFileâ);
const openCreateItemButton = document.getElementById(âbtnOpenCreateItemâ);
openCreateItemButton.onclick = () => showElement(createItemForm);
document.getElementById(âbtnCloseCreateItemâ).onclick = () => hideElement(CreateItemForm);
init();
.html
<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>inimitable</title>
<div>
<button id="btnConnect">Connect wallet</button>
<button id="btnUserInfo">profile</button>
<button id="btnOpenCreateItem">Create</button>
</div>
<div id="userInfo">
<h4>User Profile</h4>
<input type="text" id="txtUsername" required placeholder="Enter username">
<input type="text" id="txtEmail" placeholder="Enter email">
<small>Optional</small>
<img width="50" height="50" src="" id="imgAvatar" alt="">
<label for="fileAvatar">select Avatar</label>
<input type="file" id="fileAvatar">
<button id="btnLogout">Log out</button>
<button id="btnCloseUserInfo">Close</button>
<button id="btnSaveUserInfo">Save</button>
</div>
<div id="createItem">
<h4>Create Item</h4>
<input type="text" id="txtCreateItemName" required placeholder="Enter name">
<textarea id="txtCreateItemDescription" cols="30" rows="5" placeholder="Enter description"></textarea>
<input type="number" min="1" id="numCreateItemPrice" placeholder="Enter price"required>
<label for="selectCreateItemStatus">Status</label>
<select id="selectCreateItemStatus">
<option value="0">Not for sale</option>
<option value="1">Instant buy</option>
<option value="2">Accept offers</option>
</select>
<label for="fileCreateItemFile">select file</label>
<input type="file" id="fileCreateItemFile">
<button id="btnCloseCreateItem">Close</button>
<button id="btnCreateItem">Create!</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="main.js"></script>