This repository has been archived by the owner on Jul 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
90 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title>Swiss Hacks 2024</title> | ||
<style> | ||
</style> | ||
</head> | ||
<body> | ||
<h1 id="title">New Transaction</h1> | ||
<form id="transactionForm"> | ||
<label for="fromIban">Sender IBAN:</label> | ||
<input type="text" id="fromIban" name="fromIban" required><br><br> | ||
<label for="toIban">Recipient IBAN:</label> | ||
<input type="text" id="toIban" name="toIban" required><br><br> | ||
<label for="amount">Amount:</label> | ||
<input type="number" id="amount" name="amount" required><br><br> | ||
<button type="submit">Submit</button> | ||
</form> | ||
<div id="responseContainer"></div> | ||
</body> | ||
<script> | ||
document.getElementById("transactionForm").addEventListener("submit", function (event) { | ||
event.preventDefault(); // Prevent default form submission | ||
|
||
const fromIban = document.getElementById("fromIban").value; | ||
const toIban = document.getElementById("toIban").value; | ||
const amount = document.getElementById("amount").value; | ||
|
||
const data = { | ||
fromIban, | ||
toIban, | ||
amount | ||
}; | ||
|
||
fetch("/transactions/transfer", { | ||
method: "POST", | ||
headers: { | ||
"accept": "application/json", | ||
"Content-Type": "application/json" | ||
}, | ||
body: JSON.stringify(data) | ||
}) | ||
.then(response => { | ||
if (response.ok) { | ||
response.json().then(jsonBody => { | ||
const title = document.getElementById("title"); | ||
title.textContent = "Transfer successful!"; | ||
|
||
const container = document.getElementById("responseContainer"); | ||
container.innerHTML = ` | ||
<p>Transaction <i>${jsonBody.transactionId}</i> successfully executed.</p> | ||
<a href="/"> | ||
<button type="button">Back</button> | ||
</a>`; | ||
|
||
document.getElementById("transactionForm").remove(); | ||
}); | ||
} else { | ||
const error = document.createElement("p"); | ||
error.textContent = "Transfer of funds failed: " + response.statusText + " (" + response.status + "). Please check your input and try again." | ||
error.style.color = "red"; | ||
|
||
const container = document.getElementById("responseContainer"); | ||
container.innerHTML = ""; | ||
container.appendChild(error); | ||
} | ||
}); | ||
}); | ||
|
||
const urlParams = new URLSearchParams(window.location.search); | ||
|
||
if (urlParams.has('fromIban')) { | ||
const fromIbanInput = document.getElementById('fromIban'); | ||
fromIbanInput.value = urlParams.get('fromIban'); | ||
} | ||
</script> | ||
</html> |