added refresh interval to Bitcoin Price

This commit is contained in:
0ceanSlim 2023-08-01 16:21:35 -04:00
parent a3a60d2c1d
commit 3dd177f0f3

View File

@ -1,4 +1,5 @@
// Fetch the Bitcoin price from the CoinGecko API
// Function to fetch and update the Bitcoin price
function updateBitcoinPrice() {
fetch('https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd')
.then(response => response.json())
.then(data => {
@ -22,3 +23,13 @@ fetch('https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=u
dollarsToSatsElement.textContent = `$1.00 = ${sats.toFixed(0)} sats`; // Display the result
})
.catch(error => console.error(error));
}
// Function to refresh the Bitcoin price every 30 seconds
function refreshBitcoinPrice() {
updateBitcoinPrice(); // Call the function immediately to display the price on page load
setInterval(updateBitcoinPrice, 10000); // Call the function every 30 seconds (30,000 milliseconds)
}
// Call the function to refresh the Bitcoin price
refreshBitcoinPrice();