Address code review: tighten bip110 key matching, fix redundant condition, extract shared badge config, add CSS classes
This commit is contained in:
committed by
GitHub
parent
df08a7c413
commit
69b84153b4
@@ -60,3 +60,17 @@ async function apiFetch(path, options) {
|
||||
}
|
||||
return res.json();
|
||||
}
|
||||
|
||||
|
||||
// ── BIP-110 badge state config ────────────────────────────────────
|
||||
// Shared lookup used by tiles.js and service-detail.js.
|
||||
// Keys match the "state" values returned by /api/bitcoin/bip110.
|
||||
|
||||
var BIP110_BADGE_CONFIG = {
|
||||
active: { cls: 'tile-bip110-badge--active', label: 'BIP\u2011110: Active \u2713', title: 'BIP-110 is active on this node' },
|
||||
locked_in: { cls: 'tile-bip110-badge--locked_in', label: 'BIP\u2011110: Locked In', title: 'BIP-110 is locked in and will activate shortly' },
|
||||
signaling: { cls: 'tile-bip110-badge--signaling', label: 'BIP\u2011110: Signaling', title: 'Node is signaling readiness for BIP-110' },
|
||||
not_signaling: { cls: 'tile-bip110-badge--not_signaling',label: 'BIP\u2011110: Not Signaling', title: 'Node supports BIP-110 but is not signaling this period' },
|
||||
unsupported: { cls: 'tile-bip110-badge--unsupported', label: 'BIP\u2011110: Not Supported', title: 'This node build does not include BIP-110' },
|
||||
unknown: { cls: 'tile-bip110-badge--unknown', label: 'BIP\u2011110: \u2014', title: 'Status unavailable (node syncing or RPC not ready)' }
|
||||
};
|
||||
|
||||
@@ -111,43 +111,12 @@ async function openServiceDetailModal(unit, name, icon) {
|
||||
if (icon === 'bip110' && data.bip110) {
|
||||
var bip110 = data.bip110;
|
||||
var bip110State = bip110.state || 'unknown';
|
||||
var bip110BadgeCls, bip110Label, bip110Tooltip;
|
||||
switch (bip110State) {
|
||||
case 'active':
|
||||
bip110BadgeCls = 'tile-bip110-badge--active';
|
||||
bip110Label = 'BIP\u2011110: Active \u2713';
|
||||
bip110Tooltip = 'BIP-110 is active on this node';
|
||||
break;
|
||||
case 'locked_in':
|
||||
bip110BadgeCls = 'tile-bip110-badge--locked_in';
|
||||
bip110Label = 'BIP\u2011110: Locked In';
|
||||
bip110Tooltip = 'BIP-110 is locked in and will activate shortly';
|
||||
break;
|
||||
case 'signaling':
|
||||
bip110BadgeCls = 'tile-bip110-badge--signaling';
|
||||
bip110Label = 'BIP\u2011110: Signaling';
|
||||
bip110Tooltip = 'Node is signaling readiness for BIP-110';
|
||||
break;
|
||||
case 'not_signaling':
|
||||
bip110BadgeCls = 'tile-bip110-badge--not_signaling';
|
||||
bip110Label = 'BIP\u2011110: Not Signaling';
|
||||
bip110Tooltip = 'Node supports BIP-110 but is not signaling this period';
|
||||
break;
|
||||
case 'unsupported':
|
||||
bip110BadgeCls = 'tile-bip110-badge--unsupported';
|
||||
bip110Label = 'BIP\u2011110: Not Supported';
|
||||
bip110Tooltip = 'This node build does not include BIP-110';
|
||||
break;
|
||||
default:
|
||||
bip110BadgeCls = 'tile-bip110-badge--unknown';
|
||||
bip110Label = 'BIP\u2011110: \u2014';
|
||||
bip110Tooltip = 'Status unavailable (node syncing or RPC not ready)';
|
||||
}
|
||||
var bip110Source = bip110.source ? ' <span style="color:var(--text-dim);font-size:0.75rem;">(source: ' + escHtml(bip110.source) + ')</span>' : '';
|
||||
var bip110Cfg = BIP110_BADGE_CONFIG[bip110State] || BIP110_BADGE_CONFIG.unknown;
|
||||
var bip110Source = bip110.source ? ' <span class="bip110-source-label">(source: ' + escHtml(bip110.source) + ')</span>' : '';
|
||||
html += '<div class="svc-detail-section">' +
|
||||
'<div class="svc-detail-section-title">BIP-110 Deployment Status</div>' +
|
||||
'<div style="display:flex;align-items:center;gap:8px;flex-wrap:wrap;">' +
|
||||
'<span class="tile-bip110-badge ' + bip110BadgeCls + '" title="' + escHtml(bip110Tooltip) + '">' + escHtml(bip110Label) + '</span>' +
|
||||
'<div class="bip110-status-row">' +
|
||||
'<span class="tile-bip110-badge ' + bip110Cfg.cls + '" title="' + escHtml(bip110Cfg.title) + '">' + escHtml(bip110Cfg.label) + '</span>' +
|
||||
bip110Source +
|
||||
'</div>' +
|
||||
'</div>';
|
||||
|
||||
@@ -9,39 +9,8 @@ var _btcSyncPrev = {};
|
||||
function _renderBip110Badge(bip110) {
|
||||
if (!bip110) return '';
|
||||
var state = bip110.state || 'unknown';
|
||||
var label, cls, title;
|
||||
switch (state) {
|
||||
case 'active':
|
||||
label = 'BIP\u2011110: Active \u2713';
|
||||
cls = 'tile-bip110-badge--active';
|
||||
title = 'BIP-110 is active on this node';
|
||||
break;
|
||||
case 'locked_in':
|
||||
label = 'BIP\u2011110: Locked In';
|
||||
cls = 'tile-bip110-badge--locked_in';
|
||||
title = 'BIP-110 is locked in and will activate shortly';
|
||||
break;
|
||||
case 'signaling':
|
||||
label = 'BIP\u2011110: Signaling';
|
||||
cls = 'tile-bip110-badge--signaling';
|
||||
title = 'Node is signaling readiness for BIP-110';
|
||||
break;
|
||||
case 'not_signaling':
|
||||
label = 'BIP\u2011110: Not Signaling';
|
||||
cls = 'tile-bip110-badge--not_signaling';
|
||||
title = 'Node supports BIP-110 but is not signaling this period';
|
||||
break;
|
||||
case 'unsupported':
|
||||
label = 'BIP\u2011110: Not Supported';
|
||||
cls = 'tile-bip110-badge--unsupported';
|
||||
title = 'This node build does not include BIP-110';
|
||||
break;
|
||||
default:
|
||||
label = 'BIP\u2011110: \u2014';
|
||||
cls = 'tile-bip110-badge--unknown';
|
||||
title = 'Status unavailable (node syncing or RPC not ready)';
|
||||
}
|
||||
return '<div class="tile-bip110-badge ' + cls + '" title="' + escHtml(title) + '">' + escHtml(label) + '</div>';
|
||||
var cfg = BIP110_BADGE_CONFIG[state] || BIP110_BADGE_CONFIG.unknown;
|
||||
return '<div class="tile-bip110-badge ' + cfg.cls + '" title="' + escHtml(cfg.title) + '">' + escHtml(cfg.label) + '</div>';
|
||||
}
|
||||
|
||||
// ── Render: initial build ─────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user