Add env toggles to show/hide perp and options hedge plan tabs.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-19 00:43:04 +08:00
parent 9e1343981d
commit f21e4d1166
10 changed files with 109 additions and 6 deletions
+33 -4
View File
@@ -5,9 +5,22 @@
const root = document.getElementById("hedge-plan-root");
if (!root) return;
function flagOn(attr) {
return root.getAttribute(attr) !== "0";
}
const showPerp = flagOn("data-show-perp");
const showOo = flagOn("data-show-oo");
function pickDefaultTab() {
if (showPerp) return "perp_options";
if (showOo) return "options_options";
return "active";
}
const state = {
tab: "perp_options",
mode: "perp_options",
tab: pickDefaultTab(),
mode: showPerp ? "perp_options" : showOo ? "options_options" : "perp_options",
underlying: root.getAttribute("data-default-underly") || "ETH",
moneyFilter: "all",
chain: null,
@@ -103,7 +116,10 @@
}
function syncTabUI() {
const tab = state.tab || "perp_options";
let tab = state.tab || pickDefaultTab();
if (tab === "perp_options" && !showPerp) tab = pickDefaultTab();
if (tab === "options_options" && !showOo) tab = pickDefaultTab();
state.tab = tab;
document.querySelectorAll(".hp-tab").forEach(function (b) {
const on = b.getAttribute("data-tab") === tab;
b.classList.toggle("active", on);
@@ -120,6 +136,16 @@
if (tab === "perp_options" || tab === "options_options") {
state.mode = tab;
}
const hint = $("hp-acct-hint");
if (hint) {
if (tab === "options_options") {
hint.textContent = "期期双腿→期权账户";
} else if (tab === "perp_options") {
hint.textContent = "永续腿→合约账户 · 期权腿→期权账户";
} else {
hint.textContent = "进行中/历史含永期与期期;显示开关只影响新建测算 Tab";
}
}
}
function setGateLine(gates) {
@@ -716,7 +742,10 @@
function bind() {
document.querySelectorAll(".hp-tab").forEach(function (b) {
b.addEventListener("click", function () {
state.tab = b.getAttribute("data-tab") || "perp_options";
const next = b.getAttribute("data-tab") || pickDefaultTab();
if (next === "perp_options" && !showPerp) return;
if (next === "options_options" && !showOo) return;
state.tab = next;
syncTabUI();
if (state.tab === "perp_options" || state.tab === "options_options") {
void loadGates();