fix(hedge): equal-height right shell card with strategy status

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-08-09 10:02:59 +08:00
parent eca6d091e9
commit 425fc701bc
3 changed files with 175 additions and 53 deletions
+67 -4
View File
@@ -421,6 +421,62 @@
}
}
function isPoOptionPrimaryPlan(p) {
if (!p || p.plan_type !== "perp_options") return false;
return p.option_primary == 1 || p.option_primary === true || Number(p.option_primary) === 1;
}
function setPoStrategyStatus(kind, planId) {
const el = $("hp-po-strategy-status");
if (!el) return;
el.classList.remove("is-watching", "is-holding", "is-idle");
if (!isOptionPrimary()) {
el.textContent = "";
return;
}
const idPart = planId ? " #" + planId : "";
if (kind === "watching") {
el.textContent = "盯盘中" + idPart;
el.classList.add("is-watching");
} else if (kind === "holding") {
el.textContent = "持仓中" + idPart;
el.classList.add("is-holding");
} else {
el.textContent = "未启动";
el.classList.add("is-idle");
}
}
async function refreshPoStrategyStatus() {
const el = $("hp-po-strategy-status");
if (!el) return;
if (!isOptionPrimary()) {
setPoStrategyStatus("", null);
return;
}
try {
const d = await apiJson("/api/hedge-plan/active");
const uly = (state.underlying || "ETH").toUpperCase();
const rows = (d.plans || []).filter(function (p) {
return isPoOptionPrimaryPlan(p) && String(p.underlying || "").toUpperCase() === uly;
});
if (!rows.length) {
setPoStrategyStatus("idle", null);
return;
}
rows.sort(function (a, b) {
return Number(b.id || 0) - Number(a.id || 0);
});
const p = rows[0];
const st = String(p.status || "");
if (st === "watching") setPoStrategyStatus("watching", p.id);
else if (st === "active" || st === "opening" || st === "partial") setPoStrategyStatus("holding", p.id);
else setPoStrategyStatus("idle", null);
} catch (e) {
/* ignore status refresh errors */
}
}
function syncOoRecommendUI() {
const cur = state.ooRecommend || "";
document.querySelectorAll(".hp-oo-recommend-btn").forEach(function (b) {
@@ -1747,6 +1803,7 @@
syncTabUI();
if (state.tab === "perp_options" || state.tab === "options_options") {
void loadGates();
if (state.tab === "perp_options") void refreshPoStrategyStatus();
} else if (state.tab === "active") {
void loadActivePlans();
} else if (state.tab === "history") {
@@ -2167,6 +2224,7 @@
void loadActivePlans();
void loadHistory();
void loadGates();
void refreshPoStrategyStatus();
} catch (e) {
alert(e.message || String(e));
}
@@ -2531,10 +2589,9 @@
body: JSON.stringify(body),
});
setGateLine(d.gates);
setPoStrategyStatus("watching", d.plan_id || null);
alert((d.msg || "已启动盯盘") + (d.plan_id ? "\n计划 #" + d.plan_id : ""));
state.tab = "active";
syncTabUI();
void loadActivePlans();
void refreshPoStrategyStatus();
void loadGates();
} catch (e) {
alert(e.message || String(e));
@@ -2688,6 +2745,7 @@
const tbody = $("hp-strike-tbody");
if (tbody) tbody.innerHTML = '<tr><td colspan="6" class="err">' + (e.message || e) + "</td></tr>";
}
if (state.tab === "perp_options") void refreshPoStrategyStatus();
}
syncTabUI();
@@ -2702,5 +2760,10 @@
updateOoBudgetLine(null);
bind();
syncOptionPrimaryUI();
void refreshAll();
void refreshAll().then(function () {
void refreshPoStrategyStatus();
});
setInterval(function () {
if (state.tab === "perp_options" && isOptionPrimary()) void refreshPoStrategyStatus();
}, 15000);
})();