mirror of
https://github.com/Retropex/custom-ocean.xyz-dashboard.git
synced 2025-05-28 12:42:30 +02:00
Update blocks.js
This commit is contained in:
parent
495e272843
commit
8d40fb83a8
@ -209,9 +209,9 @@ function loadBlocksFromHeight(height) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function to load the latest blocks
|
// Function to load the latest blocks and return a promise with the latest block height
|
||||||
function loadLatestBlocks() {
|
function loadLatestBlocks() {
|
||||||
if (isLoading) return;
|
if (isLoading) return Promise.resolve(null);
|
||||||
|
|
||||||
isLoading = true;
|
isLoading = true;
|
||||||
|
|
||||||
@ -219,7 +219,7 @@ function loadLatestBlocks() {
|
|||||||
$("#blocks-grid").html('<div class="loader"><span class="loader-text">Loading latest blocks<span class="terminal-cursor"></span></span></div>');
|
$("#blocks-grid").html('<div class="loader"><span class="loader-text">Loading latest blocks<span class="terminal-cursor"></span></span></div>');
|
||||||
|
|
||||||
// Fetch the latest blocks from the API
|
// Fetch the latest blocks from the API
|
||||||
$.ajax({
|
return $.ajax({
|
||||||
url: `${mempoolBaseUrl}/api/v1/blocks`,
|
url: `${mempoolBaseUrl}/api/v1/blocks`,
|
||||||
method: "GET",
|
method: "GET",
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
@ -250,9 +250,23 @@ function loadLatestBlocks() {
|
|||||||
complete: function () {
|
complete: function () {
|
||||||
isLoading = false;
|
isLoading = false;
|
||||||
}
|
}
|
||||||
});
|
}).then(data => data.length > 0 ? data[0].height : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Refresh blocks page every 60 seconds if there are new blocks
|
||||||
|
setInterval(function () {
|
||||||
|
console.log("Checking for new blocks at " + new Date().toLocaleTimeString());
|
||||||
|
loadLatestBlocks().then(latestHeight => {
|
||||||
|
if (latestHeight && latestHeight > currentStartHeight) {
|
||||||
|
console.log("New blocks detected, refreshing the page");
|
||||||
|
location.reload();
|
||||||
|
} else {
|
||||||
|
console.log("No new blocks detected");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, 60000);
|
||||||
|
|
||||||
|
|
||||||
// Function to update the latest block stats section
|
// Function to update the latest block stats section
|
||||||
function updateLatestBlockStats(block) {
|
function updateLatestBlockStats(block) {
|
||||||
if (!block) return;
|
if (!block) return;
|
||||||
|
Loading…
Reference in New Issue
Block a user