var ids; var onSale; var inMarket; var inOffers; $(document).ready( async () => {//when page is loaded, get latest instance of blockchain await connectWallet(); await onlyOwnerAccess(); ids = await getBirdsOfOwner(); onSale = await getBirdsOnSale(); inMarket = onSale.filter(x => !ids.includes(x));//offers of other users inMarket = inMarket.filter(x => !["0"].includes(x));//remove Bird0 inOffers = onSale.filter(x => ids.includes(x));//user's offers await buildOffers(inOffers);//build offers await buildMarket(inMarket);//build market activateMouseListeners(); }); async function appendBirdToMarket(dna, id) { var price = await getPrice(id); marketBox(price, id); renderBird(`#BirdBox${id}`, birdDna(dna), id); }; async function appendBirdToOffers(dna, id) { var price = await getPrice(id); offerBox(price, id); renderBird(`#BirdBox${id}`, birdDna(dna), id); }; function marketBox(price, id) {//used for offers of other users var boxDiv = `

ID: ` + id + `
GEN:

MUM:
DAD:

DNA:
ASKING PRICE: ` + price + ` ETH
` $('.marketOffers').append(boxDiv); }; function offerBox(price, id) {//used for offers of current user var boxDiv = `

ID: ` + id + `
GEN:

MUM:
DAD:

DNA:
ASKING PRICE: ` + price + ` ETH
` $('.myOffers').append(boxDiv); }; //Listener for eye animation function activateMouseListeners() { $('.CatalogBox').on("mousemove", () => { var eyeballs = $('.eyesFollow'); document.onmousemove = function(event) { var x = event.clientX * 65 / window.innerWidth + "%"; var y = event.clientY * 65 / window.innerHeight + "%"; for (let i = 0; i < eyeballs.length; i++) { eyeballs[i].style.left = x; eyeballs[i].style.top = y; }; }; }); }; //Listeners for buttons async function activateBuyButtonListeners() { if(await checkPause()) { $(`[id^='buyButton']`).hide(); } else { $(`[id^='buyButton']`).show(); $(`[id^='buyButton']`).on("click", async function() { await initializeMarketplace(); //make sure marketplace contract is approved as operator for user var id = $(this).attr("id").substring(9);//extract bird ID from HTML var price = await getPrice(id); $(`#buyButton${id}`).hide(); await buyBird(price, id); $(`#BirdBox${id}`).remove();//remove bird from DOM }); }; }; function activateCancelButtonListeners() { $(`[id^='cancelButton']`).on("click", async function() { await initializeMarketplace(); //make sure marketplace contract is approved as operator for user var id = $(this).attr("id").substring(12);//extract bird ID from HTML $(`#cancelButton${id}`).hide(); await removeOffer(id); $(`#BirdBox${id}`).remove();//remove bird from DOM }); };