Add explorer link to block details modal

This update introduces a new feature in `blocks.js` that adds an "Explorer Link" to view block details on the mempool.space website. The link is styled for visibility and includes an external link indicator. Additional comments were added for clarity, and minor adjustments were made to the existing code structure, ensuring the overall functionality of the block details modal remains intact.
This commit is contained in:
DJObleezy 2025-04-15 21:24:21 -07:00
parent 1eb17aed80
commit 1dec2ba35b

View File

@ -1,4 +1,4 @@
"use strict"; "use strict";
// Global variables // Global variables
let currentStartHeight = null; let currentStartHeight = null;
@ -476,23 +476,23 @@ function addNavigationControls(blocks) {
function showBlockDetails(block) { function showBlockDetails(block) {
const modal = $("#block-modal"); const modal = $("#block-modal");
const blockDetails = $("#block-details"); const blockDetails = $("#block-details");
// Clear the details // Clear the details
blockDetails.empty(); blockDetails.empty();
// Format the timestamp // Format the timestamp
const timestamp = formatTimestamp(block.timestamp); const timestamp = formatTimestamp(block.timestamp);
// Create the block header section // Create the block header section
const headerSection = $("<div>", { const headerSection = $("<div>", {
class: "block-detail-section" class: "block-detail-section"
}); });
headerSection.append($("<div>", { headerSection.append($("<div>", {
class: "block-detail-title", class: "block-detail-title",
text: "Block #" + block.height text: "Block #" + block.height
})); }));
// Add block hash // Add block hash
const hashItem = $("<div>", { const hashItem = $("<div>", {
class: "block-detail-item" class: "block-detail-item"
@ -506,7 +506,43 @@ function showBlockDetails(block) {
text: block.id text: block.id
})); }));
headerSection.append(hashItem); headerSection.append(hashItem);
// Add mempool.space link
const linkItem = $("<div>", {
class: "block-detail-item"
});
linkItem.append($("<div>", {
class: "block-detail-label",
text: "Explorer Link"
}));
const mempoolLink = $("<a>", {
href: `${mempoolBaseUrl}/block/${block.id}`,
target: "_blank",
class: "mempool-link",
text: "View on mempool.space",
css: {
color: "#f7931a",
textDecoration: "none"
}
});
// Add icon or indicator that it's an external link
mempoolLink.append($("<span>", {
html: " ↗",
css: {
fontSize: "14px"
}
}));
const linkContainer = $("<div>", {
class: "block-detail-value"
});
linkContainer.append(mempoolLink);
linkItem.append(linkContainer);
headerSection.append(linkItem);
// Add timestamp // Add timestamp
const timeItem = $("<div>", { const timeItem = $("<div>", {
class: "block-detail-item" class: "block-detail-item"
@ -520,7 +556,7 @@ function showBlockDetails(block) {
text: timestamp text: timestamp
})); }));
headerSection.append(timeItem); headerSection.append(timeItem);
// Add merkle root // Add merkle root
const merkleItem = $("<div>", { const merkleItem = $("<div>", {
class: "block-detail-item" class: "block-detail-item"
@ -534,7 +570,7 @@ function showBlockDetails(block) {
text: block.merkle_root text: block.merkle_root
})); }));
headerSection.append(merkleItem); headerSection.append(merkleItem);
// Add previous block hash // Add previous block hash
const prevHashItem = $("<div>", { const prevHashItem = $("<div>", {
class: "block-detail-item" class: "block-detail-item"
@ -548,19 +584,20 @@ function showBlockDetails(block) {
text: block.previousblockhash text: block.previousblockhash
})); }));
headerSection.append(prevHashItem); headerSection.append(prevHashItem);
blockDetails.append(headerSection); blockDetails.append(headerSection);
// Rest of the function remains unchanged
// Create the mining section // Create the mining section
const miningSection = $("<div>", { const miningSection = $("<div>", {
class: "block-detail-section" class: "block-detail-section"
}); });
miningSection.append($("<div>", { miningSection.append($("<div>", {
class: "block-detail-title", class: "block-detail-title",
text: "Mining Details" text: "Mining Details"
})); }));
// Add miner/pool // Add miner/pool
const minerItem = $("<div>", { const minerItem = $("<div>", {
class: "block-detail-item" class: "block-detail-item"
@ -575,7 +612,7 @@ function showBlockDetails(block) {
text: poolName text: poolName
})); }));
miningSection.append(minerItem); miningSection.append(minerItem);
// Add difficulty // Add difficulty
const difficultyItem = $("<div>", { const difficultyItem = $("<div>", {
class: "block-detail-item" class: "block-detail-item"
@ -589,7 +626,7 @@ function showBlockDetails(block) {
text: numberWithCommas(Math.round(block.difficulty)) text: numberWithCommas(Math.round(block.difficulty))
})); }));
miningSection.append(difficultyItem); miningSection.append(difficultyItem);
// Add nonce // Add nonce
const nonceItem = $("<div>", { const nonceItem = $("<div>", {
class: "block-detail-item" class: "block-detail-item"
@ -603,7 +640,7 @@ function showBlockDetails(block) {
text: numberWithCommas(block.nonce) text: numberWithCommas(block.nonce)
})); }));
miningSection.append(nonceItem); miningSection.append(nonceItem);
// Add bits // Add bits
const bitsItem = $("<div>", { const bitsItem = $("<div>", {
class: "block-detail-item" class: "block-detail-item"
@ -617,7 +654,7 @@ function showBlockDetails(block) {
text: block.bits text: block.bits
})); }));
miningSection.append(bitsItem); miningSection.append(bitsItem);
// Add version // Add version
const versionItem = $("<div>", { const versionItem = $("<div>", {
class: "block-detail-item" class: "block-detail-item"
@ -631,19 +668,19 @@ function showBlockDetails(block) {
text: "0x" + block.version.toString(16) text: "0x" + block.version.toString(16)
})); }));
miningSection.append(versionItem); miningSection.append(versionItem);
blockDetails.append(miningSection); blockDetails.append(miningSection);
// Create the transaction section // Create the transaction section
const txSection = $("<div>", { const txSection = $("<div>", {
class: "block-detail-section" class: "block-detail-section"
}); });
txSection.append($("<div>", { txSection.append($("<div>", {
class: "block-detail-title", class: "block-detail-title",
text: "Transaction Details" text: "Transaction Details"
})); }));
// Add transaction count // Add transaction count
const txCountItem = $("<div>", { const txCountItem = $("<div>", {
class: "block-detail-item" class: "block-detail-item"
@ -657,7 +694,7 @@ function showBlockDetails(block) {
text: numberWithCommas(block.tx_count) text: numberWithCommas(block.tx_count)
})); }));
txSection.append(txCountItem); txSection.append(txCountItem);
// Add size // Add size
const sizeItem = $("<div>", { const sizeItem = $("<div>", {
class: "block-detail-item" class: "block-detail-item"
@ -671,7 +708,7 @@ function showBlockDetails(block) {
text: formatFileSize(block.size) text: formatFileSize(block.size)
})); }));
txSection.append(sizeItem); txSection.append(sizeItem);
// Add weight // Add weight
const weightItem = $("<div>", { const weightItem = $("<div>", {
class: "block-detail-item" class: "block-detail-item"
@ -685,20 +722,20 @@ function showBlockDetails(block) {
text: numberWithCommas(block.weight) + " WU" text: numberWithCommas(block.weight) + " WU"
})); }));
txSection.append(weightItem); txSection.append(weightItem);
blockDetails.append(txSection); blockDetails.append(txSection);
// Create the fee section if available // Create the fee section if available
if (block.extras) { if (block.extras) {
const feeSection = $("<div>", { const feeSection = $("<div>", {
class: "block-detail-section" class: "block-detail-section"
}); });
feeSection.append($("<div>", { feeSection.append($("<div>", {
class: "block-detail-title", class: "block-detail-title",
text: "Fee Details" text: "Fee Details"
})); }));
// Add total fees // Add total fees
const totalFeesItem = $("<div>", { const totalFeesItem = $("<div>", {
class: "block-detail-item" class: "block-detail-item"
@ -713,7 +750,7 @@ function showBlockDetails(block) {
text: totalFees + " BTC" text: totalFees + " BTC"
})); }));
feeSection.append(totalFeesItem); feeSection.append(totalFeesItem);
// Add reward // Add reward
const rewardItem = $("<div>", { const rewardItem = $("<div>", {
class: "block-detail-item" class: "block-detail-item"
@ -728,7 +765,7 @@ function showBlockDetails(block) {
text: reward + " BTC" text: reward + " BTC"
})); }));
feeSection.append(rewardItem); feeSection.append(rewardItem);
// Add median fee // Add median fee
const medianFeeItem = $("<div>", { const medianFeeItem = $("<div>", {
class: "block-detail-item" class: "block-detail-item"
@ -742,7 +779,7 @@ function showBlockDetails(block) {
text: block.extras.medianFee + " sat/vB" text: block.extras.medianFee + " sat/vB"
})); }));
feeSection.append(medianFeeItem); feeSection.append(medianFeeItem);
// Add average fee // Add average fee
const avgFeeItem = $("<div>", { const avgFeeItem = $("<div>", {
class: "block-detail-item" class: "block-detail-item"
@ -756,7 +793,7 @@ function showBlockDetails(block) {
text: numberWithCommas(block.extras.avgFee) + " sat" text: numberWithCommas(block.extras.avgFee) + " sat"
})); }));
feeSection.append(avgFeeItem); feeSection.append(avgFeeItem);
// Add average fee rate // Add average fee rate
const avgFeeRateItem = $("<div>", { const avgFeeRateItem = $("<div>", {
class: "block-detail-item" class: "block-detail-item"
@ -770,48 +807,48 @@ function showBlockDetails(block) {
text: block.extras.avgFeeRate + " sat/vB" text: block.extras.avgFeeRate + " sat/vB"
})); }));
feeSection.append(avgFeeRateItem); feeSection.append(avgFeeRateItem);
// Add fee range with visual representation // Add fee range with visual representation
if (block.extras.feeRange && block.extras.feeRange.length > 0) { if (block.extras.feeRange && block.extras.feeRange.length > 0) {
const feeRangeItem = $("<div>", { const feeRangeItem = $("<div>", {
class: "block-detail-item transaction-data" class: "block-detail-item transaction-data"
}); });
feeRangeItem.append($("<div>", { feeRangeItem.append($("<div>", {
class: "block-detail-label", class: "block-detail-label",
text: "Fee Rate Percentiles (sat/vB)" text: "Fee Rate Percentiles (sat/vB)"
})); }));
const feeRangeText = $("<div>", { const feeRangeText = $("<div>", {
class: "block-detail-value", class: "block-detail-value",
text: block.extras.feeRange.join(", ") text: block.extras.feeRange.join(", ")
}); });
feeRangeItem.append(feeRangeText); feeRangeItem.append(feeRangeText);
// Add visual fee bar // Add visual fee bar
const feeBarContainer = $("<div>", { const feeBarContainer = $("<div>", {
class: "fee-bar-container" class: "fee-bar-container"
}); });
const feeBar = $("<div>", { const feeBar = $("<div>", {
class: "fee-bar" class: "fee-bar"
}); });
feeBarContainer.append(feeBar); feeBarContainer.append(feeBar);
feeRangeItem.append(feeBarContainer); feeRangeItem.append(feeBarContainer);
// Animate the fee bar // Animate the fee bar
setTimeout(() => { setTimeout(() => {
feeBar.css("width", "100%"); feeBar.css("width", "100%");
}, 100); }, 100);
feeSection.append(feeRangeItem); feeSection.append(feeRangeItem);
} }
blockDetails.append(feeSection); blockDetails.append(feeSection);
} }
// Show the modal // Show the modal
modal.css("display", "block"); modal.css("display", "block");
} }