Skip to content

Commit

Permalink
modify javascript
Browse files Browse the repository at this point in the history
  • Loading branch information
jamaltheatlantean committed Mar 29, 2023
1 parent 758691d commit 44d21bf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 27 deletions.
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ <h1>Crypto Tax Calculator</h1>
</select>
<br>
<label for="amount">Amount Purchased (USD):</label>
<input type="number" id="amount" step="any">
<input type="number" id="amount-usd" step="any">
<br>
<label for="sold">Amount Sold (USD):</label>
<input type="number" id="sold" step="any">
<input type="number" id="sold-usd" step="any">
<br>
<label for="purchaseDate">Purchase Date:</label>
<input type="date" id="purchaseDate">
Expand Down
49 changes: 24 additions & 25 deletions script.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
const form = document.querySelector('form');
const resultDiv = document.querySelector('#result');
const form = document.querySelector("form");
const resultDiv = document.querySelector("#result");

form.addEventListener('submit', async (event) => {
form.addEventListener("submit", async (event) => {
event.preventDefault();

const crypto = document.querySelector('#crypto').value;
const amount = document.querySelector('#amount').value;
const amountUsd = document.querySelector('#amount-usd').value;
const sold = document.querySelector('#sold').value;
const soldUsd = document.querySelector('#sold-usd').value;
const purchaseDate = document.querySelector('#purchase-date').value;
const saleDate = document.querySelector('#sale-date').value;

const crypto = document.querySelector("#crypto").value;
const amountUsd = document.querySelector("#amount-usd").value;
const soldUsd = document.querySelector("#sold-usd").value;
const purchaseDate = document.querySelector("#purchaseDate").value;
const saleDate = document.querySelector("#saleDate").value;

// Get the price of the crypto on the purchase date
const purchaseQuery = `
{
Expand All @@ -20,7 +18,7 @@ form.addEventListener('submit', async (event) => {
}
}
`;

const saleQuery = `
{
${crypto}(date: {eq: "${saleDate}"}) {
Expand All @@ -32,28 +30,28 @@ form.addEventListener('submit', async (event) => {
const url = `https://graphql.bitquery.io/`;

const purchaseResponse = await fetch(url, {
method: 'POST',
method: "POST",
headers: {
'Content-Type': 'application/json',
'BITQUERY-API-KEY': 'YOUR_API_KEY' // Will replace with actual API key once i get it
"Content-Type": "application/json",
"X-API-KEY": "BQYgbliUSjLJlBzRVKqe0HNY4vtybLGt", // Will replace with actual API key once i get it
},
body: JSON.stringify({ query: purchaseQuery })
body: JSON.stringify({ query: purchaseQuery }),
});

const saleResponse = await fetch(url, {
method: 'POST',
method: "POST",
headers: {
'Content-Type': 'application/json',
'X-API-KEY': 'YOUR_API_KEY' // Replace with your actual API key
"Content-Type": "application/json",
"X-API-KEY": "BQYgbliUSjLJlBzRVKqe0HNY4vtybLGt", // Replace with your actual API key
},
body: JSON.stringify({ query: saleQuery })
body: JSON.stringify({ query: saleQuery }),
});

const purchaseData = await purchaseResponse.json();
const saleData = await saleResponse.json();

const purchasePrice = purchaseData.data[crypto][0].price;
const salePrice = saleData.data[crypto][0].price;
//const purchasePrice = purchaseData.data[crypto][0].price;
//const salePrice = saleData.data[crypto][0].price;

// Calculate the tax
const purchaseValue = amountUsd;
Expand All @@ -63,12 +61,13 @@ form.addEventListener('submit', async (event) => {
const taxOwed = capitalGain * taxRate;

// Display the result
resultDiv.textContent = `You owe $${taxOwed.toFixed(2)} in taxes on your ${crypto} transaction (purchased on ${purchaseDate} and sold on ${saleDate}).`;

resultDiv.textContent = `You owe $${taxOwed.toFixed(
2
)} in taxes on your ${crypto} transaction (purchased on ${purchaseDate} and sold on ${saleDate}).`;
});

// Retrieve the user's language preference and user agent string
const language = navigator.language;
const userAgent = navigator.userAgent;
console.log(`User language: ${language}`);
console.log(`User agent string: ${userAgent}`);
console.log(`User agent string: ${userAgent}`);

0 comments on commit 44d21bf

Please sign in to comment.