修复币本位顶栏改动导致 Gate/Binance 顶栏 UndefinedError 500

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-08-20 14:56:30 +08:00
parent 87910ed71a
commit b0c331aa26
5 changed files with 22 additions and 8 deletions
+9
View File
@@ -220,10 +220,19 @@ def pwa_app_name(exchange_key: str) -> str:
def embed_context_extras(exchange_key: str) -> dict:
# 顶栏共享模板调用 trading_account_label / options_funding_label;
# 须注入三所,否则 Gate/Binance 渲染会 UndefinedError → HTTP 500.
from lib.instance.instance_embed_context_lib import (
options_funding_label,
trading_account_label,
)
return {
"order_rule_tips_tpl": order_rule_tips_template(exchange_key),
"include_transfer_block": include_transfer_block(exchange_key),
"ui_open_guard_enabled": ui_open_guard_enabled(exchange_key),
"ui_orphan_recovery_enabled": ui_orphan_recovery_enabled(exchange_key),
"pwa_app_name": pwa_app_name(exchange_key),
"options_funding_label": options_funding_label,
"trading_account_label": trading_account_label,
}
@@ -1143,7 +1143,8 @@ function formatOptionsFundingLabel(usdc, usdt, eth, marginMode, underly) {
return `${n.toFixed(2)} USDC`;
}
function formatTradingAccountLabel(usdt, eth, btc, marginMode) {
const mode = String(marginMode || "coin").toLowerCase();
// 缺省按 usdc(xx.xxU):Gate/Binance 快照无 options_margin_mode;OKX 会显式下发.
const mode = String(marginMode || "usdc").toLowerCase();
if (mode !== "coin") {
if (usdt === null || usdt === undefined || usdt === "") return "—";
const n = Number(usdt);
@@ -1203,7 +1204,7 @@ function accountSnapshotFundingMissing(data){
let accountSnapshotRetryCount = 0;
function applyAccountSnapshot(data){
if(!data || typeof data !== "object") return;
const coinMode = String(data.options_margin_mode || "coin").toLowerCase() === "coin";
const coinMode = String(data.options_margin_mode || "").toLowerCase() === "coin";
if(typeof data.show_perp_funds !== "undefined"){
applyPerpFundsVisibility(data.show_perp_funds !== false || coinMode);
} else if (coinMode) {
+3 -2
View File
@@ -1624,7 +1624,8 @@ function formatOptionsFundingLabel(usdc, usdt, eth, marginMode, underly) {
return `${n.toFixed(2)} USDC`;
}
function formatTradingAccountLabel(usdt, eth, btc, marginMode) {
const mode = String(marginMode || "coin").toLowerCase();
// 缺省按 usdc(xx.xxU):Gate/Binance 快照无 options_margin_mode;OKX 会显式下发.
const mode = String(marginMode || "usdc").toLowerCase();
if (mode !== "coin") {
if (usdt == null || usdt === "") return "—";
const n = Number(usdt);
@@ -1684,7 +1685,7 @@ function accountSnapshotFundingMissing(data){
let accountSnapshotRetryCount = 0;
function applyAccountSnapshot(data){
if(!data || typeof data !== "object") return;
const coinMode = String(data.options_margin_mode || "coin").toLowerCase() === "coin";
const coinMode = String(data.options_margin_mode || "").toLowerCase() === "coin";
if(typeof data.show_perp_funds !== "undefined"){
applyPerpFundsVisibility(data.show_perp_funds !== false || coinMode);
} else if (coinMode) {
@@ -38,11 +38,12 @@
{% include 'instance_header_stats.html' %}
</div>
<div class="instance-header-phone-strip instance-phone-only" aria-label="手机资金摘要">
{% set _coin_margin = (options_margin_mode|default('coin')) == 'coin' %}
{% set _coin_margin = (options_enabled|default(false)) and (options_margin_mode|default('coin')) == 'coin' %}
{% set _show_perp = (show_perp_funds|default(true)) or _coin_margin %}
{% set _trading_margin_mode = 'coin' if _coin_margin else 'usdc' %}
<span class="inst-phone-chip"{% if not _show_perp %} style="display:none"{% endif %} data-perp-funds="1">
<em>交易</em>
<b data-funds-field="current-capital">{{ trading_account_label(current_capital, options_trading_eth, options_trading_btc, margin_mode=options_margin_mode|default('coin')) }}</b>
<b data-funds-field="current-capital">{{ trading_account_label(current_capital, options_trading_eth, options_trading_btc, margin_mode=_trading_margin_mode) }}</b>
</span>
<span class="inst-phone-chip"{% if not _show_perp %} style="display:none"{% endif %} data-perp-funds="1">
<em>资金</em>
@@ -1,6 +1,8 @@
{# 资金与统计条(顶栏 / 系统设置共用,单行展示) #}
{% set _coin_margin = (options_margin_mode|default('coin')) == 'coin' %}
{# 币本位顶栏仅 OKX 期权开启时生效;Gate/Binance 保持原 xx.xxU #}
{% set _coin_margin = (options_enabled|default(false)) and (options_margin_mode|default('coin')) == 'coin' %}
{% set _show_perp = (show_perp_funds|default(true)) or _coin_margin %}
{% set _trading_margin_mode = 'coin' if _coin_margin else 'usdc' %}
<div class="instance-header-stats{% if options_enabled %} instance-header-stats--options{% endif %}">
<div class="stat-strip-item stat-strip-item--primary">
<div class="label">交易所</div>
@@ -32,7 +34,7 @@
</div>
<div class="stat-strip-item"{% if not _show_perp %} style="display:none"{% endif %} data-perp-funds="1">
<div class="label">交易账户</div>
<div class="value" id="current-capital" data-funds-field="current-capital">{{ trading_account_label(current_capital, options_trading_eth, options_trading_btc, margin_mode=options_margin_mode|default('coin')) }}</div>
<div class="value" id="current-capital" data-funds-field="current-capital">{{ trading_account_label(current_capital, options_trading_eth, options_trading_btc, margin_mode=_trading_margin_mode) }}</div>
</div>
{% if options_enabled and not _coin_margin %}
<div class="stat-strip-item" data-options-funds="1">