Address code review: tighten bip110 key matching, fix redundant condition, extract shared badge config, add CSS classes

This commit is contained in:
copilot-swe-agent[bot]
2026-06-04 19:46:40 +00:00
committed by GitHub
parent df08a7c413
commit 69b84153b4
5 changed files with 38 additions and 72 deletions
+6 -4
View File
@@ -2436,8 +2436,10 @@ def _get_bip110_status() -> dict:
deployments = deploy_info.get("deployments", {}) deployments = deploy_info.get("deployments", {})
if isinstance(deployments, dict): if isinstance(deployments, dict):
for key, entry in deployments.items(): for key, entry in deployments.items():
# Generic scan: match key containing "bip110" or "110" # Generic scan: match key that contains "bip110" (case-insensitive).
if not ("bip110" in key.lower() or "110" in key.lower()): # Deliberately not matching bare "110" to avoid false positives on
# unrelated deployments whose names happen to include that digit sequence.
if "bip110" not in key.lower():
continue continue
if not isinstance(entry, dict): if not isinstance(entry, dict):
continue continue
@@ -2460,7 +2462,7 @@ def _get_bip110_status() -> dict:
if status in ("started", "defined"): if status in ("started", "defined"):
# Check whether the node is currently signaling this period # Check whether the node is currently signaling this period
stats = bip9.get("statistics") or bip8.get("statistics") or {} stats = bip9.get("statistics") or bip8.get("statistics") or {}
signaling = bool(stats.get("signaling", False)) if stats else False signaling = bool(stats.get("signaling", False))
if signaling: if signaling:
return {"supported": True, "signaling": True, "state": "signaling", "source": "getdeploymentinfo"} return {"supported": True, "signaling": True, "state": "signaling", "source": "getdeploymentinfo"}
return {"supported": True, "signaling": False, "state": "not_signaling", "source": "getdeploymentinfo"} return {"supported": True, "signaling": False, "state": "not_signaling", "source": "getdeploymentinfo"}
@@ -2474,7 +2476,7 @@ def _get_bip110_status() -> dict:
if net_info is not None: if net_info is not None:
subversion = net_info.get("subversion", "") or "" subversion = net_info.get("subversion", "") or ""
sv_lower = subversion.lower() sv_lower = subversion.lower()
if "bip110" in sv_lower or "uasf-bip110" in sv_lower or "uasf" in sv_lower: if "bip110" in sv_lower or "uasf-bip110" in sv_lower:
return {"supported": True, "signaling": True, "state": "signaling", "source": "subversion"} return {"supported": True, "signaling": True, "state": "signaling", "source": "subversion"}
# Node is reachable via RPC but no BIP-110 marker found anywhere # Node is reachable via RPC but no BIP-110 marker found anywhere
return {"supported": False, "signaling": False, "state": "unsupported", "source": "subversion"} return {"supported": False, "signaling": False, "state": "unsupported", "source": "subversion"}
@@ -206,6 +206,18 @@
border: 1px solid var(--border-color); border: 1px solid var(--border-color);
} }
.bip110-status-row {
display: flex;
align-items: center;
gap: 8px;
flex-wrap: wrap;
}
.bip110-source-label {
color: var(--text-dim);
font-size: 0.75rem;
}
/* ── Service detail modal sections ───────────────────────────────── */ /* ── Service detail modal sections ───────────────────────────────── */
.svc-detail-section { .svc-detail-section {
@@ -60,3 +60,17 @@ async function apiFetch(path, options) {
} }
return res.json(); 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) { if (icon === 'bip110' && data.bip110) {
var bip110 = data.bip110; var bip110 = data.bip110;
var bip110State = bip110.state || 'unknown'; var bip110State = bip110.state || 'unknown';
var bip110BadgeCls, bip110Label, bip110Tooltip; var bip110Cfg = BIP110_BADGE_CONFIG[bip110State] || BIP110_BADGE_CONFIG.unknown;
switch (bip110State) { var bip110Source = bip110.source ? ' <span class="bip110-source-label">(source: ' + escHtml(bip110.source) + ')</span>' : '';
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>' : '';
html += '<div class="svc-detail-section">' + html += '<div class="svc-detail-section">' +
'<div class="svc-detail-section-title">BIP-110 Deployment Status</div>' + '<div class="svc-detail-section-title">BIP-110 Deployment Status</div>' +
'<div style="display:flex;align-items:center;gap:8px;flex-wrap:wrap;">' + '<div class="bip110-status-row">' +
'<span class="tile-bip110-badge ' + bip110BadgeCls + '" title="' + escHtml(bip110Tooltip) + '">' + escHtml(bip110Label) + '</span>' + '<span class="tile-bip110-badge ' + bip110Cfg.cls + '" title="' + escHtml(bip110Cfg.title) + '">' + escHtml(bip110Cfg.label) + '</span>' +
bip110Source + bip110Source +
'</div>' + '</div>' +
'</div>'; '</div>';
+2 -33
View File
@@ -9,39 +9,8 @@ var _btcSyncPrev = {};
function _renderBip110Badge(bip110) { function _renderBip110Badge(bip110) {
if (!bip110) return ''; if (!bip110) return '';
var state = bip110.state || 'unknown'; var state = bip110.state || 'unknown';
var label, cls, title; var cfg = BIP110_BADGE_CONFIG[state] || BIP110_BADGE_CONFIG.unknown;
switch (state) { return '<div class="tile-bip110-badge ' + cfg.cls + '" title="' + escHtml(cfg.title) + '">' + escHtml(cfg.label) + '</div>';
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>';
} }
// ── Render: initial build ───────────────────────────────────────── // ── Render: initial build ─────────────────────────────────────────