|
12 | 12 | workersBody, |
13 | 13 | peeringSync: document.getElementById('peering-sync'), |
14 | 14 | peeringBody: document.getElementById('peering-body'), |
| 15 | + peeringInvoicesSync: document.getElementById('peering-invoices-sync'), |
| 16 | + peeringInvoicesBody: document.getElementById('peering-invoices-body'), |
| 17 | + peeringBudgetsBody: document.getElementById('peering-budgets-body'), |
15 | 18 | nip05Error: document.getElementById('ops-nip05-error'), |
16 | 19 | nip05Domain: document.getElementById('ops-nip05-domain'), |
17 | 20 | nip05Verified: document.getElementById('ops-nip05-verified'), |
|
152 | 155 | } |
153 | 156 | } |
154 | 157 |
|
155 | | - const renderPeering = (rows) => { |
156 | | - if (!Array.isArray(rows) || !rows.length) { |
| 158 | + const peeringInvoiceBadge = (status) => { |
| 159 | + const degraded = status === 'held' || status === 'failed' || status === 'rejected' |
| 160 | + return `<span class="status-badge${degraded ? ' status-degraded' : ''}"><span class="status-led" aria-hidden="true"></span>${escapeHtml(status)}</span>` |
| 161 | + } |
| 162 | + |
| 163 | + const renderPeeringInvoices = (invoices) => { |
| 164 | + if (!Array.isArray(invoices) || !invoices.length) { |
| 165 | + elements.peeringInvoicesBody.innerHTML = |
| 166 | + '<tr><td colspan="6" class="admin-muted small">No buyer invoices yet.</td></tr>' |
| 167 | + return |
| 168 | + } |
| 169 | + |
| 170 | + elements.peeringInvoicesBody.innerHTML = invoices |
| 171 | + .map((invoice) => { |
| 172 | + const pending = invoice.status === 'held' || invoice.status === 'failed' |
| 173 | + const actions = pending |
| 174 | + ? `<button type="button" class="btn btn-console btn-sm me-1" data-peering-invoice-action="approve" data-payment-hash="${escapeAttr(invoice.paymentHash)}">Approve</button> |
| 175 | + <button type="button" class="btn btn-console btn-sm" data-peering-invoice-action="reject" data-payment-hash="${escapeAttr(invoice.paymentHash)}">Reject</button>` |
| 176 | + : '' |
| 177 | + const title = [invoice.peerPubkey, invoice.reason || '', invoice.expiresAt || ''].filter(Boolean).join(' · ') |
| 178 | + return `<tr> |
| 179 | + <td><code class="small" title="${escapeAttr(title)}">${escapeHtml(shortPubkey(invoice.peerPubkey))}</code></td> |
| 180 | + <td class="small">${escapeHtml(Math.round(Number(BigInt(invoice.amountMsats) / 1000n)))} sats</td> |
| 181 | + <td>${peeringInvoiceBadge(invoice.status)}</td> |
| 182 | + <td class="small">${escapeHtml(invoice.reason || '—')}</td> |
| 183 | + <td class="small">${escapeHtml(formatTime(invoice.createdAt))}</td> |
| 184 | + <td>${actions}</td> |
| 185 | + </tr>` |
| 186 | + }) |
| 187 | + .join('') |
| 188 | + } |
| 189 | + |
| 190 | + const renderPeeringBudgets = (budgets) => { |
| 191 | + if (!Array.isArray(budgets) || !budgets.length) { |
| 192 | + elements.peeringBudgetsBody.innerHTML = |
| 193 | + '<tr><td colspan="5" class="admin-muted small">No buyer budgets configured.</td></tr>' |
| 194 | + return |
| 195 | + } |
| 196 | + |
| 197 | + elements.peeringBudgetsBody.innerHTML = budgets |
| 198 | + .map((budget) => { |
| 199 | + const label = budget.scope === 'global' ? 'All peers' : shortPubkey(budget.peerPubkey) |
| 200 | + const title = budget.scope === 'global' ? 'global cap' : budget.peerPubkey |
| 201 | + return `<tr> |
| 202 | + <td class="small" title="${escapeAttr(title)}">${escapeHtml(label)}</td> |
| 203 | + <td class="small">${escapeHtml(formatTime(budget.periodStart))} → ${escapeHtml(formatTime(budget.periodEnd))}</td> |
| 204 | + <td class="small">${escapeHtml(Math.round(Number(BigInt(budget.spentMsats) / 1000n)))} sats</td> |
| 205 | + <td class="small">${escapeHtml(Math.round(Number(BigInt(budget.remainingMsats) / 1000n)))} sats</td> |
| 206 | + <td class="small">${escapeHtml(budget.received)} / ${escapeHtml(budget.paid)} / ${escapeHtml(budget.held)}</td> |
| 207 | + </tr>` |
| 208 | + }) |
| 209 | + .join('') |
| 210 | + } |
| 211 | + |
| 212 | + const renderPeering = (rows) => { if (!Array.isArray(rows) || !rows.length) { |
157 | 213 | elements.peeringBody.innerHTML = |
158 | 214 | '<tr><td colspan="10" class="admin-muted small">No peering peers configured.</td></tr>' |
159 | 215 | return |
|
291 | 347 | } |
292 | 348 | const payload = await response.json() |
293 | 349 | renderPeering(payload.peers) |
| 350 | + renderPeeringInvoices(payload.invoices) |
| 351 | + renderPeeringBudgets(payload.budgets) |
294 | 352 | if (elements.peeringSync) { |
295 | 353 | elements.peeringSync.innerHTML = `<span class="prompt-char">></span> peers: updated ${formatTime(new Date().toISOString())}` |
296 | 354 | } |
| 355 | + if (elements.peeringInvoicesSync) { |
| 356 | + elements.peeringInvoicesSync.innerHTML = `<span class="prompt-char">></span> buyer invoices: updated ${formatTime(new Date().toISOString())}` |
| 357 | + } |
297 | 358 | } |
298 | 359 |
|
299 | 360 | const buildNip05Query = () => { |
|
375 | 436 | await loadNip05() |
376 | 437 | } |
377 | 438 |
|
| 439 | + const decidePeeringInvoice = async (paymentHash, action) => { |
| 440 | + const response = await adminFetch('/peering/invoices/decision', { |
| 441 | + method: 'POST', |
| 442 | + headers: { 'content-type': 'application/json' }, |
| 443 | + body: JSON.stringify({ paymentHash, action }), |
| 444 | + }) |
| 445 | + const payload = await response.json().catch(() => ({})) |
| 446 | + if (!response.ok) { |
| 447 | + if (elements.peeringInvoicesSync) { |
| 448 | + elements.peeringInvoicesSync.innerHTML = `<span class="prompt-char">></span><span class="text-danger"> invoice: ${escapeHtml(payload.error || 'decision failed')}</span>` |
| 449 | + } |
| 450 | + return |
| 451 | + } |
| 452 | + await loadPeering() |
| 453 | + } |
| 454 | + |
378 | 455 | const refreshAll = async () => { |
379 | 456 | const results = await Promise.allSettled([loadWorkers(), loadPeering(), loadNip05()]) |
380 | 457 |
|
|
431 | 508 | void reverify(pubkey) |
432 | 509 | }) |
433 | 510 |
|
| 511 | + elements.peeringInvoicesBody?.addEventListener('click', (event) => { |
| 512 | + const target = event.target |
| 513 | + if (!(target instanceof HTMLElement)) { |
| 514 | + return |
| 515 | + } |
| 516 | + const action = target.getAttribute('data-peering-invoice-action') |
| 517 | + const paymentHash = target.getAttribute('data-payment-hash') |
| 518 | + if (!action || !paymentHash) { |
| 519 | + return |
| 520 | + } |
| 521 | + void decidePeeringInvoice(paymentHash, action) |
| 522 | + }) |
| 523 | + |
434 | 524 | window.__ADMIN_OPS__ = { |
435 | 525 | load: () => { |
436 | 526 | nip05Offset = 0 |
|
0 commit comments