feat: count down in realtime

This commit is contained in:
nate 2026-03-25 23:05:12 +04:00
parent ad798d0bbf
commit 3a3499cd8b
1 changed files with 12 additions and 1 deletions

View File

@ -216,7 +216,7 @@
<span class="w-1.5 h-1.5 rounded-full <%= inv.status === 'underpaid' ? 'bg-yellow-500' : 'bg-blue-500' %> animate-pulse"></span>
<span class="text-xs <%= inv.status === 'underpaid' ? 'text-yellow-400' : 'text-gray-400' %>"><%= inv.status === 'underpaid' ? 'Underpaid, send the rest' : 'Waiting for payment' %></span>
</div>
<span class="text-xs text-gray-500 font-mono"><%= mins %>:<%= String(secs).padStart(2, '0') %></span>
<span id="timer" class="text-xs text-gray-500 font-mono" data-expires="<%= expiresAt.toISOString() %>"><%= mins %>:<%= String(secs).padStart(2, '0') %></span>
</div>
<% } else if (inv.status === 'confirming') { %>
@ -265,6 +265,17 @@
<script>
// Countdown timer
const timerEl = document.getElementById('timer');
if (timerEl) {
const expires = new Date(timerEl.dataset.expires).getTime();
setInterval(() => {
const left = Math.max(0, Math.floor((expires - Date.now()) / 1000));
timerEl.textContent = Math.floor(left / 60) + ':' + String(left % 60).padStart(2, '0');
if (left <= 0) location.reload();
}, 1000);
}
// Copy address
function copyAddr() {
const addr = document.getElementById('pay-address');