-
Notifications
You must be signed in to change notification settings - Fork 111
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
106 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,66 @@ | ||
const balances = { | ||
{% for token, value in balances.items() %} | ||
"{{ token }}": {{ value }}, | ||
{% endfor %} | ||
}; | ||
console.log("JavaScript is loaded"); | ||
alert("JavaScript is working!"); | ||
|
||
// Update max balance based on the selected token | ||
function updateMaxBalance() { | ||
const selectedToken = document.getElementById('token').value; | ||
const maxBalance = balances[selectedToken] || 0; | ||
document.getElementById('amount').setAttribute('max', maxBalance); | ||
} | ||
|
||
function validateAmount() { | ||
const selectedToken = document.getElementById('token').value; | ||
const enteredAmount = parseFloat(document.getElementById('amount').value); | ||
const maxBalance = balances[selectedToken] || 0; | ||
// Validate the entered amount | ||
// function validateAmount() { | ||
// const selectedToken = document.getElementById("token").value; | ||
// const enteredAmount = parseFloat(document.getElementById("amount").value); | ||
// const maxBalance = balances[selectedToken] || 0; | ||
// | ||
// if (enteredAmount > maxBalance) { | ||
// document.getElementById("balance-warning").style.display = "block"; | ||
// return false; | ||
// } else { | ||
// document.getElementById("balance-warning").style.display = "none"; | ||
// return true; | ||
// } | ||
// } | ||
|
||
if (enteredAmount > maxBalance) { | ||
document.getElementById('balance-warning').style.display = 'block'; | ||
return false; | ||
} else { | ||
document.getElementById('balance-warning').style.display = 'none'; | ||
return true; | ||
} | ||
} | ||
document.addEventListener("DOMContentLoaded", function () { | ||
console.log("DOM Content Loaded"); | ||
|
||
// Attach change event to token select dropdown | ||
// document.getElementById("token").addEventListener("change", updateMaxBalance); | ||
|
||
// Attach click event to submit button | ||
document.getElementById("submit-btn").onclick = async function () { | ||
console.log("Submit button clicked"); | ||
|
||
// Get form values | ||
const token = document.getElementById("token").value; | ||
const amount = document.getElementById("amount").value; | ||
const multiplier = document.getElementById("multiplier").value; | ||
|
||
console.log("Form Values:", { token, amount, multiplier }); | ||
|
||
try { | ||
const response = await fetch(`/transaction-data?token=${token}&amount=${amount}&multiplier=${multiplier}`, { | ||
method: "GET", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
}); | ||
|
||
if (!response.ok) { | ||
const errorData = await response.json(); | ||
throw new Error(`Failed to fetch transaction data: ${errorData.message || "Unknown error"}`); | ||
} | ||
|
||
const transactionData = await response.json(); | ||
console.log("Transaction data received:", transactionData); | ||
|
||
// Implement sendTransaction here | ||
await sendTransaction(transactionData); | ||
} catch (error) { | ||
console.error("Error while submitting form:", error.message); | ||
alert(`Failed to submit the form and fetch transaction data: ${error.message}`); | ||
} | ||
}; | ||
}); |
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