use createXhrWithFormKey in the lottery

remotes/1693176582716663532/tmp_refs/heads/watchparty
justcool393 2022-10-14 05:43:23 -07:00
parent bb9ab04a90
commit 6efb9b41b4
3 changed files with 6 additions and 14 deletions

View File

@ -297,8 +297,6 @@ document.onpaste = function(event) {
}
function handle_action(type, cid, thing) {
const btns = document.getElementsByClassName(`action-${cid}`)
for (const btn of btns)
{

View File

@ -74,13 +74,11 @@ function postPostToastNonShopActions(t, url, button1, button2, className) {
}
}
function createXhrWithFormKey(url, method="POST", form=null) {
function createXhrWithFormKey(url, method="POST", form=new FormData()) {
const xhr = new XMLHttpRequest();
xhr.open(method, url);
xhr.setRequestHeader('xhr', 'xhr');
if (!form) {
form = new FormData();
}
if (!form) form = new FormData();
form.append("formkey", formkey());
return [xhr, form]; // hacky but less stupid than what we were doing before
}

View File

@ -77,16 +77,12 @@ function endLotterySession() {
// Composed
function handleLotteryRequest(uri, method, callback = () => {}) {
const xhr = new XMLHttpRequest();
const url = `/lottery/${uri}`;
xhr.open(method, url);
xhr.onload = handleLotteryResponse.bind(null, xhr, method, callback);
const form = new FormData();
form.append("formkey", formkey());
form.append("quantity", purchaseQuantity)
xhr.send(form);
form.append("quantity", purchaseQuantity);
const xhr = createXhrWithFormKey(`/lottery/${uri}`, method, form);
xhr[0].onload = handleLotteryResponse.bind(null, xhr[0], method, callback);
xhr[0].send(xhr[1]);
}
function handleLotteryResponse(xhr, method, callback) {