ncantu 3e3bfc72d3 Update consolidate button with dynamic info and implement API call
**Motivations:**
- Afficher le nombre d'UTXOs et le montant total concernés par la consolidation
- Rendre le bouton de consolidation plus informatif

**Root causes:**
- Le bouton affichait un texte statique sans information sur ce qui sera consolidé
- Pas de visibilité sur le nombre d'UTXOs et le montant concernés

**Correctifs:**
- Création de la méthode getSmallUtxosInfo() pour obtenir les infos sans consolider
- Ajout de la route GET /api/utxo/small-info pour exposer ces informations

**Evolutions:**
- Bouton de consolidation avec texte dynamique : "Consolider la capacité d'ancrage résiduelle (X UTXOs, Y )"
- Fonction loadSmallUtxosInfo() qui charge les infos depuis l'API
- Bouton désactivé avec message "Aucun UTXO à consolider" si aucun UTXO disponible
- Chargement automatique des infos au chargement de la page et après refresh
- Gestion d'erreur avec message "Erreur de chargement" si l'API échoue

**Pages affectées:**
- signet-dashboard/src/bitcoin-rpc.js: Méthode getSmallUtxosInfo() pour obtenir les infos des petits UTXOs
- signet-dashboard/src/server.js: Route GET /api/utxo/small-info
- signet-dashboard/public/utxo-list.html: Fonction loadSmallUtxosInfo() et mise à jour du bouton avec texte dynamique
2026-01-25 23:39:33 +01:00

799 lines
34 KiB
HTML

<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Liste des UTXO - Bitcoin Ancrage Dashboard</title>
<link rel="stylesheet" href="styles.css">
<style>
.utxo-list-container {
max-width: 1400px;
margin: 0 auto;
padding: 20px;
}
.header-section {
margin-bottom: 30px;
}
.header-section h1 {
margin-bottom: 10px;
}
.header-section .back-link {
display: inline-block;
margin-bottom: 20px;
color: #007bff;
text-decoration: none;
}
.header-section .back-link:hover {
text-decoration: underline;
}
.info-section {
background: #f8f9fa;
padding: 15px;
border-radius: 5px;
margin-bottom: 20px;
}
.info-section p {
margin: 5px 0;
}
.category-section {
margin-bottom: 40px;
}
.category-header {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 15px 20px;
border-radius: 5px 5px 0 0;
margin-bottom: 0;
}
.category-header.bloc-rewards {
background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}
.category-header.ancrages {
background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
}
.category-header.changes {
background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);
}
.category-header.fees {
background: linear-gradient(135deg, #fa709a 0%, #fee140 100%);
}
.category-header h2 {
margin: 0;
font-size: 1.5em;
}
.category-stats {
background: rgba(255, 255, 255, 0.2);
padding: 10px;
margin-top: 10px;
border-radius: 3px;
display: flex;
justify-content: space-between;
flex-wrap: wrap;
}
.category-stats span {
margin-right: 20px;
}
.table-container {
overflow-x: auto;
background: white;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
table {
width: 100%;
border-collapse: collapse;
}
th, td {
padding: 12px;
text-align: left;
border-bottom: 1px solid #ddd;
}
th {
background: #f8f9fa;
color: #333;
font-weight: bold;
position: sticky;
top: 0;
}
tr:hover {
background: #f5f5f5;
}
.txid-cell {
font-family: monospace;
font-size: 0.9em;
}
.txid-link {
color: #007bff;
text-decoration: none;
}
.txid-link:hover {
text-decoration: underline;
}
.address-cell {
font-family: monospace;
font-size: 0.9em;
word-break: break-all;
}
.amount-cell {
text-align: right;
font-weight: bold;
}
.loading {
text-align: center;
padding: 40px;
font-size: 1.2em;
color: #666;
}
.error {
background: #f8d7da;
color: #721c24;
padding: 15px;
border-radius: 5px;
margin: 20px 0;
}
.refresh-button {
background: #28a745;
color: white;
border: none;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
font-size: 1em;
margin-top: 10px;
}
.refresh-button:hover {
background: #218838;
}
.refresh-button:disabled {
background: #6c757d;
cursor: not-allowed;
}
.consolidate-button {
background: #ffc107;
color: #000;
border: none;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
font-size: 1em;
margin-top: 10px;
}
.consolidate-button:hover {
background: #e0a800;
}
.consolidate-button:disabled {
background: #6c757d;
cursor: not-allowed;
}
.sortable-header {
cursor: pointer;
user-select: none;
position: relative;
}
.sortable-header:hover {
background: #e9ecef;
}
.sort-arrow {
display: inline-block;
margin-left: 5px;
font-size: 0.8em;
}
.pagination {
display: flex;
justify-content: center;
align-items: center;
gap: 10px;
margin: 20px 0;
}
.pagination-button {
padding: 8px 16px;
background: #007bff;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
}
.pagination-button:hover:not(:disabled) {
background: #0056b3;
}
.pagination-button:disabled {
background: #6c757d;
cursor: not-allowed;
}
.pagination-info {
font-weight: bold;
}
.total-amount {
font-size: 1.2em;
font-weight: bold;
color: #28a745;
}
.empty-message {
padding: 20px;
text-align: center;
color: #666;
background: #f8f9fa;
border-radius: 0 0 5px 5px;
}
.status-spent {
color: #dc3545;
font-weight: bold;
}
.status-locked {
color: #ffc107;
font-weight: bold;
}
.status-available {
color: #28a745;
font-weight: bold;
}
.navigation-bar {
background: #f8f9fa;
padding: 15px;
border-radius: 5px;
margin-bottom: 20px;
display: flex;
flex-wrap: wrap;
gap: 10px;
justify-content: center;
}
.navigation-bar a {
padding: 10px 20px;
background: white;
color: #007bff;
text-decoration: none;
border-radius: 5px;
border: 2px solid #007bff;
transition: all 0.3s;
font-weight: bold;
}
.navigation-bar a:hover {
background: #007bff;
color: white;
}
.category-section {
scroll-margin-top: 20px;
}
</style>
</head>
<body>
<div class="container">
<div class="utxo-list-container">
<div class="header-section">
<a href="/" class="back-link">← Retour au dashboard</a>
<h1>Liste des UTXO</h1>
<div class="info-section">
<p><strong>Total d'UTXO :</strong> <span id="utxo-count">-</span></p>
<p><strong>Capacité d'ancrage restante :</strong> <span id="available-for-anchor">-</span> ancrages (<span id="confirmed-available-for-anchor">-</span> UTXOs confirmés)</p>
<button class="consolidate-button" id="consolidate-button" onclick="consolidateSmallUtxos()" style="margin-left: 10px; background: #ffc107; color: #000; border: none; padding: 10px 20px; border-radius: 5px; cursor: pointer; font-size: 1em; margin-top: 10px;">Chargement...</button>
<p><strong>Montant total :</strong> <span id="total-amount" class="total-amount">-</span></p>
<p><strong>Dernière mise à jour :</strong> <span id="last-update">-</span></p>
<button class="refresh-button" onclick="loadUtxoList()">Actualiser</button>
<a href="/api/utxo/list.txt" download="utxo_list.txt" style="margin-left: 10px; color: #007bff; text-decoration: none;">📥 Télécharger le fichier texte</a>
</div>
</div>
<div id="navigation" class="navigation-bar" style="display: none;">
<a href="#bloc-rewards">💰 Bloc Rewards</a>
<a href="#ancrages">🔗 Ancrages</a>
<a href="#changes">🔄 Changes</a>
<a href="#fees">💸 Frais</a>
</div>
<div id="content">
<div class="loading">Chargement des UTXO...</div>
</div>
</div>
</div>
<script>
const API_BASE_URL = window.location.origin;
const ITEMS_PER_PAGE = 100;
// État de tri et pagination pour chaque catégorie
const tableState = {};
// Charger la liste au chargement de la page
document.addEventListener('DOMContentLoaded', () => {
loadUtxoList();
loadSmallUtxosInfo();
});
function getSortState(categoryName) {
if (!tableState[categoryName]) {
tableState[categoryName] = {
sortColumn: null,
sortDirection: 'desc',
currentPage: 1,
};
}
return tableState[categoryName];
}
function sortUtxos(utxos, sortColumn, sortDirection) {
const sorted = [...utxos];
sorted.sort((a, b) => {
let aVal, bVal;
if (sortColumn === 'amount') {
aVal = a.amount;
bVal = b.amount;
} else if (sortColumn === 'confirmations') {
aVal = a.confirmations || 0;
bVal = b.confirmations || 0;
} else {
return 0;
}
if (sortDirection === 'asc') {
return aVal - bVal;
} else {
return bVal - aVal;
}
});
return sorted;
}
function getSortArrow(sortColumn, currentSortColumn, sortDirection) {
if (sortColumn !== currentSortColumn) {
return '<span class="sort-arrow">↕</span>';
}
return sortDirection === 'asc'
? '<span class="sort-arrow">↑</span>'
: '<span class="sort-arrow">↓</span>';
}
function renderTable(utxos, categoryName, categoryLabel) {
if (utxos.length === 0) {
return `
<div class="category-section" id="${categoryName}">
<div class="category-header ${categoryName}">
<h2>${categoryLabel}</h2>
<div class="category-stats">
<span><strong>Nombre :</strong> 0</span>
<span><strong>Montant total :</strong> 0 🛡</span>
</div>
</div>
<div class="empty-message">Aucun UTXO dans cette catégorie.</div>
</div>
`;
}
const state = getSortState(categoryName);
// Trier les UTXOs
let sortedUtxos = utxos;
if (state.sortColumn) {
sortedUtxos = sortUtxos(utxos, state.sortColumn, state.sortDirection);
}
// Paginer les UTXOs
const totalPages = Math.ceil(sortedUtxos.length / ITEMS_PER_PAGE);
const startIndex = (state.currentPage - 1) * ITEMS_PER_PAGE;
const endIndex = startIndex + ITEMS_PER_PAGE;
const paginatedUtxos = sortedUtxos.slice(startIndex, endIndex);
const totalAmount = utxos.reduce((sum, utxo) => sum + utxo.amount, 0);
const totalSats = Math.round(totalAmount * 100000000);
const isAnchors = categoryName === 'ancrages';
const isBlocRewards = categoryName === 'bloc-rewards';
const isChanges = categoryName === 'changes';
// Pour les changes, compter les changes d'ancrage
let anchorChangesCount = 0;
let anchorChangesAmount = 0;
if (isChanges) {
const anchorChanges = utxos.filter(utxo => utxo.isAnchorChange);
anchorChangesCount = anchorChanges.length;
anchorChangesAmount = anchorChanges.reduce((sum, utxo) => sum + utxo.amount, 0);
}
let tableHTML = `
<div class="category-section" id="${categoryName}">
<div class="category-header ${categoryName}">
<h2>${categoryLabel}</h2>
<div class="category-stats">
<span><strong>Nombre :</strong> ${utxos.length.toLocaleString('fr-FR')}</span>
<span><strong>Montant total :</strong> ${formatBTC(totalAmount)} (${totalSats.toLocaleString('fr-FR')} ✅)</span>
${isChanges && anchorChangesCount > 0 ? `<span><strong>Changes d'ancrage :</strong> ${anchorChangesCount} (${formatBTC(anchorChangesAmount)})</span>` : ''}
</div>
</div>
<div class="table-container">
<table>
<thead>
<tr>
<th>Transaction ID</th>
<th>Vout</th>
<th>Adresse</th>
`;
if (isAnchors) {
tableHTML += `
<th>Numéro de bloc</th>
<th class="sortable-header" style="text-align: right;" onclick="toggleSort('${categoryName}', 'amount')">Montant (✅)${getSortArrow('amount', state.sortColumn, state.sortDirection)}</th>
<th class="sortable-header" onclick="toggleSort('${categoryName}', 'confirmations')">Confirmations${getSortArrow('confirmations', state.sortColumn, state.sortDirection)}</th>
<th>Statut</th>
`;
} else if (isBlocRewards) {
tableHTML += `
<th class="sortable-header" style="text-align: right;" onclick="toggleSort('${categoryName}', 'amount')">Montant (🛡)${getSortArrow('amount', state.sortColumn, state.sortDirection)}</th>
<th>Date</th>
<th class="sortable-header" onclick="toggleSort('${categoryName}', 'confirmations')">Confirmations${getSortArrow('confirmations', state.sortColumn, state.sortDirection)}</th>
<th>Statut</th>
`;
} else {
// Pour la section changes, ajouter une colonne pour indiquer si c'est un change d'ancrage
if (categoryName === 'changes') {
tableHTML += `
<th class="sortable-header" style="text-align: right;" onclick="toggleSort('${categoryName}', 'amount')">Montant (🛡)${getSortArrow('amount', state.sortColumn, state.sortDirection)}</th>
<th class="sortable-header" style="text-align: right;" onclick="toggleSort('${categoryName}', 'amount')">Montant (✅)${getSortArrow('amount', state.sortColumn, state.sortDirection)}</th>
<th class="sortable-header" onclick="toggleSort('${categoryName}', 'confirmations')">Confirmations${getSortArrow('confirmations', state.sortColumn, state.sortDirection)}</th>
<th>Type</th>
<th>Statut</th>
`;
} else {
tableHTML += `
<th class="sortable-header" style="text-align: right;" onclick="toggleSort('${categoryName}', 'amount')">Montant (🛡)${getSortArrow('amount', state.sortColumn, state.sortDirection)}</th>
<th class="sortable-header" style="text-align: right;" onclick="toggleSort('${categoryName}', 'amount')">Montant (✅)${getSortArrow('amount', state.sortColumn, state.sortDirection)}</th>
<th class="sortable-header" onclick="toggleSort('${categoryName}', 'confirmations')">Confirmations${getSortArrow('confirmations', state.sortColumn, state.sortDirection)}</th>
<th>Statut</th>
`;
}
}
tableHTML += `
</tr>
</thead>
<tbody>
`;
paginatedUtxos.forEach((utxo) => {
const mempoolUrl = 'https://mempool.4nkweb.com/fr';
const txLink = `${mempoolUrl}/tx/${utxo.txid}`;
const amountSats = Math.round(utxo.amount * 100000000);
const amountBTC = Math.round(utxo.amount);
tableHTML += '<tr>';
tableHTML += `<td class="txid-cell"><a href="${txLink}" target="_blank" rel="noopener noreferrer" class="txid-link">${utxo.txid}</a></td>`;
tableHTML += `<td>${utxo.vout}</td>`;
tableHTML += `<td class="address-cell">${utxo.address || '-'}</td>`;
if (isAnchors) {
tableHTML += `<td>${utxo.blockHeight !== null && utxo.blockHeight !== undefined ? utxo.blockHeight.toLocaleString('fr-FR') : '-'}</td>`;
tableHTML += `<td class="amount-cell">${amountSats.toLocaleString('fr-FR')} ✅</td>`;
} else if (isBlocRewards) {
tableHTML += `<td class="amount-cell">${amountBTC.toLocaleString('fr-FR')} 🛡</td>`;
if (utxo.blockTime) {
const date = new Date(utxo.blockTime * 1000);
tableHTML += `<td>${date.toLocaleString('fr-FR', { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit' })}</td>`;
} else {
tableHTML += '<td>-</td>';
}
} else {
tableHTML += `<td class="amount-cell">${amountBTC.toLocaleString('fr-FR')} 🛡</td>`;
tableHTML += `<td class="amount-cell">${amountSats.toLocaleString('fr-FR')} ✅</td>`;
}
tableHTML += `<td>${utxo.confirmations.toLocaleString('fr-FR')}</td>`;
// Colonne Type (uniquement pour les changes)
if (categoryName === 'changes') {
const changeType = utxo.isAnchorChange ? '🔗 Transaction d\'ancrage' : '🔄 Transaction normale';
tableHTML += `<td>${changeType}</td>`;
}
// Colonne Statut
let statusText = '';
let statusClass = '';
if (utxo.isSpentOnchain) {
statusText = 'Dépensé onchain';
statusClass = 'status-spent';
} else if (utxo.isLockedInMutex) {
statusText = 'Verrouillé';
statusClass = 'status-locked';
} else {
statusText = 'Disponible';
statusClass = 'status-available';
}
tableHTML += `<td class="${statusClass}">${statusText}</td>`;
tableHTML += '</tr>';
});
tableHTML += `
</tbody>
</table>
</div>
`;
// Ajouter la pagination
if (totalPages > 1) {
tableHTML += `
<div class="pagination">
<button class="pagination-button" onclick="changePage('${categoryName}', ${state.currentPage - 1})" ${state.currentPage === 1 ? 'disabled' : ''}>← Précédent</button>
<span class="pagination-info">Page ${state.currentPage} / ${totalPages} (${sortedUtxos.length.toLocaleString('fr-FR')} UTXOs)</span>
<button class="pagination-button" onclick="changePage('${categoryName}', ${state.currentPage + 1})" ${state.currentPage === totalPages ? 'disabled' : ''}>Suivant →</button>
</div>
`;
}
tableHTML += `
</div>
`;
return tableHTML;
}
async function loadSmallUtxosInfo() {
const button = document.getElementById('consolidate-button');
if (!button) return;
try {
const response = await fetch(`${API_BASE_URL}/api/utxo/small-info`);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
const count = data.count || 0;
const totalSats = data.totalSats || 0;
if (count > 0) {
button.textContent = `Consolider la capacité d'ancrage résiduelle (${count.toLocaleString('fr-FR')} UTXOs, ${totalSats.toLocaleString('fr-FR')} ✅)`;
button.disabled = false;
} else {
button.textContent = 'Aucun UTXO à consolider';
button.disabled = true;
}
} catch (error) {
console.error('Error loading small UTXOs info:', error);
button.textContent = 'Erreur de chargement';
button.disabled = true;
}
}
async function loadUtxoList() {
const contentDiv = document.getElementById('content');
const refreshButton = document.querySelector('.refresh-button');
refreshButton.disabled = true;
contentDiv.innerHTML = '<div class="loading">Chargement des UTXO...</div>';
// Charger les infos des petits UTXOs en parallèle
loadSmallUtxosInfo();
try {
const response = await fetch(`${API_BASE_URL}/api/utxo/list`);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
const counts = data.counts || {};
const blocRewards = data.blocRewards || [];
const anchors = data.anchors || [];
const changes = data.changes || [];
const fees = data.fees || [];
// Sauvegarder les données pour la pagination
currentUtxosData = { blocRewards, anchors, changes, fees };
document.getElementById('utxo-count').textContent = counts.total.toLocaleString('fr-FR');
document.getElementById('available-for-anchor').textContent = (counts.availableForAnchor || 0).toLocaleString('fr-FR');
document.getElementById('confirmed-available-for-anchor').textContent = (counts.confirmedAvailableForAnchor || 0).toLocaleString('fr-FR');
// Calculer le montant total
const totalAmount = blocRewards.reduce((sum, utxo) => sum + utxo.amount, 0) +
anchors.reduce((sum, utxo) => sum + utxo.amount, 0) +
changes.reduce((sum, utxo) => sum + utxo.amount, 0);
document.getElementById('total-amount').textContent = formatBTC(totalAmount);
updateLastUpdateTime();
// Afficher la barre de navigation
document.getElementById('navigation').style.display = 'flex';
// Afficher les 4 listes
let html = '';
html += renderTable(blocRewards, 'bloc-rewards', '💰 Bloc Rewards (Récompenses de minage)');
html += renderTable(anchors, 'ancrages', '🔗 Ancrages (Transactions d\'ancrage)');
html += renderTable(changes, 'changes', '🔄 Changes (Monnaie de retour)');
html += renderFeesTable(fees, 'fees', '💸 Frais (Transactions d\'ancrage)');
contentDiv.innerHTML = html;
} catch (error) {
console.error('Error loading UTXO list:', error);
contentDiv.innerHTML = `<div class="error">Erreur lors du chargement de la liste des UTXO : ${error.message}</div>`;
} finally {
refreshButton.disabled = false;
// Recharger les infos des petits UTXOs après le chargement de la liste
loadSmallUtxosInfo();
}
}
function formatBTC(btc) {
if (btc === 0) return '0 🛡';
// Arrondir sans décimales
const roundedBTC = Math.round(btc);
if (roundedBTC === 0 && btc > 0) {
// Si arrondi à 0 mais qu'il y a un montant, afficher en sats
const sats = Math.round(btc * 100000000);
return `${sats.toLocaleString('fr-FR')}`;
}
return `${roundedBTC.toLocaleString('fr-FR')} 🛡`;
}
function renderFeesTable(fees, categoryName, categoryLabel) {
if (fees.length === 0) {
return `
<div class="category-section" id="${categoryName}">
<div class="category-header ${categoryName}">
<h2>${categoryLabel}</h2>
<div class="category-stats">
<span><strong>Nombre :</strong> 0</span>
<span><strong>Total des frais :</strong> 0 ✅</span>
</div>
</div>
<div class="empty-message">Aucune transaction avec frais onchain enregistrée.</div>
</div>
`;
}
const state = getSortState(categoryName);
// Paginer les fees
const totalPages = Math.ceil(fees.length / ITEMS_PER_PAGE);
const startIndex = (state.currentPage - 1) * ITEMS_PER_PAGE;
const endIndex = startIndex + ITEMS_PER_PAGE;
const paginatedFees = fees.slice(startIndex, endIndex);
const totalFees = fees.reduce((sum, fee) => sum + fee.fee, 0);
const totalFeesSats = Math.round(totalFees * 100000000);
let tableHTML = `
<div class="category-section" id="${categoryName}">
<div class="category-header ${categoryName}">
<h2>${categoryLabel}</h2>
<div class="category-stats">
<span><strong>Nombre :</strong> ${fees.length.toLocaleString('fr-FR')}</span>
<span><strong>Total des frais :</strong> ${formatBTC(totalFees)} (${totalFeesSats.toLocaleString('fr-FR')} ✅)</span>
</div>
</div>
<div class="table-container">
<table>
<thead>
<tr>
<th>Transaction ID</th>
<th>Frais (BTC)</th>
<th>Frais (✅)</th>
<th>Change Address</th>
<th>Change Amount</th>
<th>Bloc</th>
<th>Date</th>
<th>Confirmations</th>
</tr>
</thead>
<tbody>
`;
paginatedFees.forEach((fee) => {
const mempoolUrl = 'https://mempool.4nkweb.com/fr';
const txLink = `${mempoolUrl}/tx/${fee.txid}`;
const feeSats = fee.fee_sats || Math.round(fee.fee * 100000000);
tableHTML += '<tr>';
tableHTML += `<td class="txid-cell"><a href="${txLink}" target="_blank" rel="noopener noreferrer" class="txid-link">${fee.txid}</a></td>`;
tableHTML += `<td class="amount-cell">${fee.fee.toFixed(8)}</td>`;
tableHTML += `<td class="amount-cell">${feeSats.toLocaleString('fr-FR')} ✅</td>`;
tableHTML += `<td class="address-cell">${fee.changeAddress || '-'}</td>`;
tableHTML += `<td class="amount-cell">${fee.changeAmount ? formatBTC(fee.changeAmount) : '-'}</td>`;
tableHTML += `<td>${fee.blockHeight !== null && fee.blockHeight !== undefined ? fee.blockHeight.toLocaleString('fr-FR') : '-'}</td>`;
if (fee.blockTime) {
const date = new Date(fee.blockTime * 1000);
tableHTML += `<td>${date.toLocaleString('fr-FR', { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit' })}</td>`;
} else {
tableHTML += '<td>-</td>';
}
tableHTML += `<td>${fee.confirmations.toLocaleString('fr-FR')}</td>`;
tableHTML += '</tr>';
});
tableHTML += `
</tbody>
</table>
</div>
</div>
`;
return tableHTML;
}
function updateLastUpdateTime() {
const now = new Date();
document.getElementById('last-update').textContent = now.toLocaleString('fr-FR');
}
function toggleSort(categoryName, column) {
const state = getSortState(categoryName);
if (state.sortColumn === column) {
state.sortDirection = state.sortDirection === 'asc' ? 'desc' : 'asc';
} else {
state.sortColumn = column;
state.sortDirection = 'desc';
}
state.currentPage = 1; // Reset to first page when sorting
loadUtxoList();
}
function changePage(categoryName, page) {
const state = getSortState(categoryName);
let items = [];
if (categoryName === 'fees') {
items = currentUtxosData.fees || [];
} else {
items = getCurrentUtxos(categoryName);
}
const totalPages = Math.ceil(items.length / ITEMS_PER_PAGE);
if (page >= 1 && page <= totalPages) {
state.currentPage = page;
loadUtxoList();
}
}
function getCurrentUtxos(categoryName) {
if (categoryName === 'bloc-rewards') return currentUtxosData.blocRewards || [];
if (categoryName === 'ancrages') return currentUtxosData.anchors || [];
if (categoryName === 'changes') return currentUtxosData.changes || [];
if (categoryName === 'fees') return currentUtxosData.fees || [];
return [];
}
async function consolidateSmallUtxos() {
const button = document.querySelector('.consolidate-button');
const originalText = button.textContent;
button.disabled = true;
button.textContent = '⏳ Consolidation en cours...';
try {
const response = await fetch(`${API_BASE_URL}/api/utxo/consolidate`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
});
if (!response.ok) {
const errorData = await response.json();
throw new Error(errorData.error || `HTTP error! status: ${response.status}`);
}
const result = await response.json();
if (result.success) {
alert(`Consolidation réussie!\n\nTransaction ID: ${result.txid}\nUTXOs consolidés: ${result.inputCount}\nMontant total: ${formatBTC(result.totalInputAmount)}\nChange: ${formatBTC(result.changeAmount)}\nFrais estimés: ${formatBTC(result.estimatedFee)}`);
// Recharger la liste après consolidation
setTimeout(() => {
loadUtxoList();
}, 2000);
} else {
throw new Error(result.error || 'Consolidation échouée');
}
} catch (error) {
console.error('Error consolidating UTXOs:', error);
alert(`Erreur lors de la consolidation: ${error.message}`);
} finally {
button.disabled = false;
button.textContent = originalText;
}
}
</script>
<footer>
<p>Bitcoin Ancrage Dashboard - Équipe 4NK</p>
<a href="https://git.4nkweb.com/4nk/anchorage_layer_simple.git" target="_blank" rel="noopener noreferrer" class="git-link" title="Voir le code source sur Git">
<svg class="git-icon" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" fill="currentColor">
<path d="M23.546 10.93L13.067.452c-.604-.603-1.582-.603-2.188 0L8.708 2.627l2.76 2.76c.645-.215 1.379-.07 1.889.441.516.515.658 1.258.438 1.9l2.658 2.66c.645-.223 1.387-.083 1.9.435.721.72.721 1.884 0 2.604-.719.719-1.881.719-2.6 0-.539-.541-.674-1.337-.404-1.996L12.86 8.955v6.525c.176.086.342.203.488.348.713.721.713 1.883 0 2.6-.719.721-1.884.721-2.599 0-.72-.719-.72-1.879 0-2.598.182-.18.387-.316.605-.406V8.835c-.217-.091-.424-.222-.6-.401-.545-.545-.676-1.342-.396-2.011L7.636 3.7.45 10.881c-.6.605-.6 1.584 0 2.189l10.48 10.477c.604.604 1.582.604 2.186 0l10.43-10.43c.605-.603.605-1.582 0-2.187"/>
</svg>
</a>
</footer>
</body>
</html>