28 lines
No EOL
1.1 KiB
JavaScript
28 lines
No EOL
1.1 KiB
JavaScript
const token = docCookies.getItem("token");
|
|
const notificationElement = document.getElementById("notification");
|
|
const balanceElement = document.getElementById("balance");
|
|
|
|
window.addEventListener("load", async function () {
|
|
balanceElement.innerText = await getBalance(token);
|
|
});
|
|
|
|
document.getElementById("delete-form").addEventListener("submit", async (e) => {
|
|
e.preventDefault();
|
|
const id = document.getElementById("id").value;
|
|
const infoResult = await chequeInfo(id);
|
|
if (infoResult !== undefined) {
|
|
const coinsLeft = infoResult['amount'] * infoResult['count'];
|
|
const deleteResult = await deleteCheque(token, id);
|
|
if (deleteResult !== undefined) {
|
|
notificationElement.innerText = `+${coinsLeft} coins`;
|
|
notificationElement.style.color = "green";
|
|
balanceElement.innerText = deleteResult;
|
|
} else {
|
|
notificationElement.innerText = "You do not own this cheque.";
|
|
notificationElement.style.color = "red";
|
|
}
|
|
} else {
|
|
notificationElement.innerText = "Incorrect ID!";
|
|
notificationElement.style.color = "red";
|
|
}
|
|
}); |