Fix empty dashboard fallback and websocket gating

This commit is contained in:
2026-03-26 12:39:13 +08:00
parent 1f9063edad
commit 86eb8c37a9
2 changed files with 23 additions and 9 deletions

View File

@@ -360,7 +360,7 @@ export default function StatisticsView({ trades, holdings, stats, baseline_vw, e
</div> </div>
{/* Ticker Weights - Compact */} {/* Ticker Weights - Compact */}
{stats.tickerWeights && Object.keys(stats.tickerWeights).length > 0 && ( {effectiveStats?.tickerWeights && Object.keys(effectiveStats.tickerWeights).length > 0 && (
<div style={{ <div style={{
marginTop: 'auto', marginTop: 'auto',
paddingTop: 20, paddingTop: 20,
@@ -382,7 +382,7 @@ export default function StatisticsView({ trades, holdings, stats, baseline_vw, e
gap: 8, gap: 8,
maxHeight: 120 maxHeight: 120
}}> }}>
{Object.entries(stats.tickerWeights).map(([ticker, weight]) => { {Object.entries(effectiveStats.tickerWeights).map(([ticker, weight]) => {
const weightValue = Number(weight); const weightValue = Number(weight);
const isNegative = weightValue < 0; const isNegative = weightValue < 0;
const displayWeight = (weightValue * 100).toFixed(1); const displayWeight = (weightValue * 100).toFixed(1);

View File

@@ -24,13 +24,13 @@ export async function fetchGatewayPort() {
if (data.is_running && data.port) { if (data.is_running && data.port) {
cachedGatewayPort = data.port; cachedGatewayPort = data.port;
cachedWsUrl = data.ws_url; cachedWsUrl = data.ws_url;
return { port: data.port, wsUrl: data.ws_url }; return { status: "running", port: data.port, wsUrl: data.ws_url };
} }
return null; return { status: "stopped", port: data.port || null, wsUrl: data.ws_url || null };
} catch (error) { } catch (error) {
console.warn('[Gateway] Failed to fetch port:', error); console.warn('[Gateway] Failed to fetch port:', error);
return null; return { status: "unavailable", port: null, wsUrl: null };
} }
} }
@@ -86,15 +86,29 @@ export class ReadOnlyClient {
// Resolve WebSocket URL if not set // Resolve WebSocket URL if not set
let targetUrl = this.wsUrl; let targetUrl = this.wsUrl;
if (!targetUrl) { if (!targetUrl) {
// Try to fetch from API first
const gatewayInfo = await fetchGatewayPort(); const gatewayInfo = await fetchGatewayPort();
if (gatewayInfo) { if (gatewayInfo?.status === "running" && gatewayInfo.wsUrl) {
targetUrl = gatewayInfo.wsUrl; targetUrl = gatewayInfo.wsUrl;
console.log(`[WebSocket] Resolved Gateway port: ${gatewayInfo.port}`); console.log(`[WebSocket] Resolved Gateway port: ${gatewayInfo.port}`);
} else { } else if (gatewayInfo?.status === "unavailable") {
// Fallback to default
targetUrl = WS_URL; targetUrl = WS_URL;
console.log(`[WebSocket] Using default URL: ${targetUrl}`); console.log(`[WebSocket] Using default URL: ${targetUrl}`);
} else {
this.isConnecting = false;
this._safeEmit({
type: "system",
content: "运行任务尚未启动,等待数据服务上线..."
});
if (this.shouldReconnect) {
if (this.reconnectTimer) {
clearTimeout(this.reconnectTimer);
}
this.reconnectTimer = setTimeout(() => {
this._connect();
}, this.reconnectDelay);
}
return;
} }
} }