-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add WebSocket logic to fetch real-time mempool data for fee rates and…
… block height; display updates in footer with periodic reconnection every minute for refreshed data.
- Loading branch information
1 parent
36ef185
commit ea425f6
Showing
9 changed files
with
277 additions
and
60 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
<link rel="stylesheet" href="styles.css"> | ||
<link rel="stylesheet" href="converter.css"> | ||
<link href="https://cdn.lineicons.com/3.0/lineicons.css" rel="stylesheet"> | ||
|
||
|
||
<title>Hi Satoshi</title> | ||
</head> | ||
|
@@ -56,23 +57,41 @@ <h4>Select a Currency</h4> | |
</div> | ||
</div> | ||
|
||
|
||
|
||
<!-- ---------------------------------------------------------------------- --> | ||
<!-- Footer with Email and Lightning Icon --> | ||
<footer class="footer"> | ||
<a href="mailto:one@satoshi.si?subject=mail to one Satoshi from satoshi.si" target="_blank"> | ||
[email protected] | ||
</a> | ||
<!-- Lightning Icon --> | ||
<i class="lni lni-bolt-alt" onclick="openQRCodeModal()" title="Support me with a sat or two!"></i> | ||
<!-- Footer with Email, Lightning Icon, Block Height, and Fee Rate --> | ||
<footer class="footer"> | ||
<!-- Email Link --> | ||
<a href="mailto:one@satoshi.si?subject=mail to one Satoshi from satoshi.si" target="_blank"> | ||
[email protected] | ||
</a> | ||
|
||
<!-- Block Height Display (Left Side) --> | ||
<span id="block-height" title="Block Height" onclick="openMempoolTinyDataModal()"> | ||
</span> | ||
|
||
<!-- Fee Rate Display (Right Side) --> | ||
<span id="fee-rate" title="Network fee rate" onclick="openMempoolTinyDataModal()"> | ||
</span> | ||
|
||
<!-- Lightning Icon --> | ||
<i class="lni lni-bolt-alt" onclick="openQRCodeModal()" title="Support me with a sat or two!"></i> | ||
</footer> | ||
|
||
<!-- modal for Mempool Tiny Data Modal --> | ||
<div id="mempoolTinyDataModal" class="description-modal"> | ||
<div class="modal-content"> | ||
<span class="close-button" onclick="closeMempoolTinyDataModal()">×</span> | ||
<h2>This section is still under development...</h2> | ||
<!-- Content for mempool data goes here --> | ||
</div> | ||
</div> | ||
|
||
|
||
<!-- Modal for QR Code donation --> | ||
<div id="qrCodeModal" class="description-modal"> | ||
<div class="modal-content"> | ||
<span class="close-icon" onclick="closeQRCodeModal()">×</span> | ||
<h4 id="gratitudeHeader">If you like what you see, consider contributing a few sats. Thanks!</h4> | ||
<h4 id="gratitudeHeader">If you find this website valuable, consider contributing a sat or two. Thank you.</h4> | ||
<div class="qr-code-container"> | ||
<!-- Lightning QR Code --> | ||
<div class="qr-code-wrapper"> | ||
|
@@ -116,6 +135,7 @@ <h6>The G.D.P.R. (Greatly Demanding Privacy Rules) requires us to share this wit | |
|
||
<script src="coockieConsent.js"></script> | ||
<script src="copyonclick.js"></script> | ||
<script src="mempoolWebSocket.js"></script> | ||
<script src="converter.js"></script> | ||
<script src="index.js"></script> | ||
<script src="burgerMenu.js"></script> | ||
|
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 |
---|---|---|
|
@@ -49,20 +49,41 @@ | |
</defs> | ||
</svg> | ||
|
||
<!-- Footer with Email and Lightning Icon --> | ||
<footer class="footer"> | ||
<a href="mailto:one@satoshi.si?subject=mail to one Satoshi from satoshi.si" target="_blank"> | ||
[email protected] | ||
</a> | ||
<!-- Lightning Icon --> | ||
<i class="lni lni-bolt-alt" onclick="openQRCodeModal()" title="Support me with a sat or two!"></i> | ||
<!-- ---------------------------------------------------------------------- --> | ||
<!-- Footer with Email, Lightning Icon, Block Height, and Fee Rate --> | ||
<footer class="footer"> | ||
<!-- Email Link --> | ||
<a href="mailto:one@satoshi.si?subject=mail to one Satoshi from satoshi.si" target="_blank"> | ||
[email protected] | ||
</a> | ||
|
||
<!-- Block Height Display (Left Side) --> | ||
<span id="block-height" title="Block Height" onclick="openMempoolTinyDataModal()"> | ||
</span> | ||
|
||
<!-- Fee Rate Display (Right Side) --> | ||
<span id="fee-rate" title="Network fee rate" onclick="openMempoolTinyDataModal()"> | ||
</span> | ||
|
||
<!-- Lightning Icon --> | ||
<i class="lni lni-bolt-alt" onclick="openQRCodeModal()" title="Support me with a sat or two!"></i> | ||
</footer> | ||
|
||
<!-- modal for Mempool Tiny Data Modal --> | ||
<div id="mempoolTinyDataModal" class="description-modal"> | ||
<div class="modal-content"> | ||
<span class="close-button" onclick="closeMempoolTinyDataModal()">×</span> | ||
<h2>This section is still under development...</h2> | ||
<!-- Content for mempool data goes here --> | ||
</div> | ||
</div> | ||
|
||
|
||
<!-- Modal for QR Code donation --> | ||
<div id="qrCodeModal" class="description-modal"> | ||
<div class="modal-content"> | ||
<span class="close-icon" onclick="closeQRCodeModal()">×</span> | ||
<h4 id="gratitudeHeader">If you like what you see, consider contributing a few sats. Thanks!</h4> | ||
<h4 id="gratitudeHeader">If you find this website valuable, consider contributing a sat or two. Thank you.</h4> | ||
<div class="qr-code-container"> | ||
<!-- Lightning QR Code --> | ||
<div class="qr-code-wrapper"> | ||
|
@@ -107,6 +128,7 @@ <h6>The G.D.P.R. (Greatly Demanding Privacy Rules) requires us to share this wit | |
|
||
<script src="coockieConsent.js"></script> | ||
<script src="copyonclick.js"></script> | ||
<script src="mempoolWebSocket.js"></script> | ||
<script src="text.js"></script> | ||
<script src="index.js"></script> | ||
<script src="burgerMenu.js"></script> | ||
|
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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Function to establish WebSocket connection and listen for fee rate updates | ||
function connectToMempoolAPI() { | ||
const ws = new WebSocket('wss://mempool.space/api/v1/ws'); | ||
|
||
ws.onopen = () => { | ||
console.log('WebSocket connection established'); | ||
// Subscribe to 'stats' and 'blocks' channels to receive mempool statistics and block info | ||
ws.send(JSON.stringify({ | ||
"action": "init", | ||
"channels": ["stats", "blocks"] | ||
})); | ||
}; | ||
|
||
ws.onmessage = (event) => { | ||
const data = JSON.parse(event.data); | ||
|
||
// Log the received data to check its structure | ||
console.log('Received data:', data); | ||
|
||
// Extract the half-hour fee rate from the 'fees' object | ||
if (data.fees && data.fees.halfHourFee) { | ||
const feeRate = data.fees.halfHourFee; | ||
document.getElementById('fee-rate').textContent = feeRate + ' sat/vB'; | ||
} else { | ||
console.log('Fee rate data not available in the received payload.'); | ||
} | ||
|
||
// Extract the last block height from the 'blocks' object | ||
if (data.blocks && data.blocks.length > 0) { | ||
const lastBlockHeight = data.blocks[0].height; | ||
document.getElementById('block-height').textContent = '' + lastBlockHeight; | ||
} else { | ||
console.log('Block height data not available in the received payload.'); | ||
} | ||
}; | ||
|
||
ws.onerror = (error) => { | ||
console.error('WebSocket error:', error); | ||
}; | ||
|
||
ws.onclose = () => { | ||
console.log('WebSocket connection closed'); | ||
// Attempt to reconnect after a 15-second delay | ||
setTimeout(connectToMempoolAPI, 60000); | ||
}; | ||
} | ||
|
||
// Call the function to establish connection on page load | ||
connectToMempoolAPI(); | ||
|
||
// Function to open the fee rate modal | ||
function openFeeRateModal() { | ||
// Logic to open the modal window displaying more fee rate information | ||
const mempoolModal = document.getElementById('mempoolTinyDataModal'); | ||
if (mempoolModal) { | ||
mempoolModal.classList.add('active'); | ||
document.body.classList.add('modal-open'); | ||
} else { | ||
console.error('Mempool Tiny Data Modal not found!'); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -122,20 +122,41 @@ | |
</div> | ||
</div> | ||
|
||
<!-- Footer with Email and Lightning Icon --> | ||
<footer class="footer"> | ||
<a href="mailto:one@satoshi.si?subject=mail to one Satoshi from satoshi.si" target="_blank"> | ||
[email protected] | ||
</a> | ||
<!-- Lightning Icon --> | ||
<i class="lni lni-bolt-alt" onclick="openQRCodeModal()" title="Support me with a sat or two!"></i> | ||
</footer> | ||
<!-- ---------------------------------------------------------------------- --> | ||
<!-- Footer with Email, Lightning Icon, Block Height, and Fee Rate --> | ||
<footer class="footer"> | ||
<!-- Email Link --> | ||
<a href="mailto:one@satoshi.si?subject=mail to one Satoshi from satoshi.si" target="_blank"> | ||
[email protected] | ||
</a> | ||
|
||
<!-- Block Height Display (Left Side) --> | ||
<span id="block-height" title="Block Height" onclick="openMempoolTinyDataModal()"> | ||
</span> | ||
|
||
<!-- Fee Rate Display (Right Side) --> | ||
<span id="fee-rate" title="Network fee rate" onclick="openMempoolTinyDataModal()"> | ||
</span> | ||
|
||
<!-- Lightning Icon --> | ||
<i class="lni lni-bolt-alt" onclick="openQRCodeModal()" title="Support me with a sat or two!"></i> | ||
</footer> | ||
|
||
<!-- modal for Mempool Tiny Data Modal --> | ||
<div id="mempoolTinyDataModal" class="description-modal"> | ||
<div class="modal-content"> | ||
<span class="close-button" onclick="closeMempoolTinyDataModal()">×</span> | ||
<h2>This section is still under development...</h2> | ||
<!-- Content for mempool data goes here --> | ||
</div> | ||
</div> | ||
|
||
|
||
<!-- Modal for QR Code donation --> | ||
<div id="qrCodeModal" class="description-modal"> | ||
<div class="modal-content"> | ||
<span class="close-icon" onclick="closeQRCodeModal()">×</span> | ||
<h4 id="gratitudeHeader">If you like what you see, consider contributing a few sats. Thanks!</h4> | ||
<h4 id="gratitudeHeader">If you find this website valuable, consider contributing a sat or two. Thank you.</h4> | ||
<div class="qr-code-container"> | ||
<!-- Lightning QR Code --> | ||
<div class="qr-code-wrapper"> | ||
|
@@ -178,6 +199,7 @@ <h6>The G.D.P.R. (Greatly Demanding Privacy Rules) requires us to share this wit | |
|
||
<script src="coockieConsent.js"></script> | ||
<script src="copyonclick.js"></script> | ||
<script src="mempoolWebSocket.js"></script> | ||
<script src="burgerMenu.js"></script> | ||
<script src="index.js"></script> | ||
<script src="nip05.js"></script> | ||
|
Oops, something went wrong.