const token = docCookies.getItem("token"); const notificationElement = document.getElementById("notification"); const balanceElement = document.getElementById("balance"); let balance; window.addEventListener("load", async function () { refreshBalance(await getBalance(token)); }); function refreshBalance(from) { balance = from; balanceElement.innerText = balance; } document.getElementById("create-form").addEventListener("submit", async (e) => { e.preventDefault(); const act = parseInt(document.getElementById("act").value); if (act <= 0) { notificationElement.innerText = "Activation amount cannot be lower than 0!"; notificationElement.style.color = "red"; return; } const amount = parseInt(document.getElementById("amount").value); const bottleneck = Math.floor(balance / act); if (amount <= 0 || amount > bottleneck) { notificationElement.innerText = `Incorrect coin amount. (1-${bottleneck} allowed)`; notificationElement.style.color = "red"; return; } const createResult = await createCheque(token, amount, act); if (createResult['status']) { notificationElement.innerHTML = `Cheque has been created. `; notificationElement.style.color = "green"; refreshBalance(createResult['balance']); } else { notificationElement.innerText = "Incorrect ID!"; notificationElement.style.color = "red"; } });