알림목록 전략지표 없음 문제 수정
This commit is contained in:
@@ -9,22 +9,24 @@ import {
|
||||
resolveNotificationStrategy,
|
||||
normalizeStrategyId,
|
||||
} from '../utils/resolveNotificationStrategy';
|
||||
import { hydrateStrategyDto, normalizeMarketCode } from '../utils/strategyHydrate';
|
||||
import {
|
||||
fetchLiveSnapshot,
|
||||
type VirtualIndicatorSnapshot,
|
||||
} from './useVirtualIndicatorSnapshots';
|
||||
|
||||
const MAX_EMPTY_RETRIES = 10;
|
||||
const MAX_EMPTY_RETRIES = 15;
|
||||
|
||||
function staticFallback(
|
||||
market: string,
|
||||
strategyId: number,
|
||||
strategy: StrategyDto,
|
||||
): VirtualIndicatorSnapshot | undefined {
|
||||
const baseRows = extractVirtualConditions(strategy);
|
||||
const hydrated = hydrateStrategyDto(strategy);
|
||||
const baseRows = extractVirtualConditions(hydrated);
|
||||
if (baseRows.length === 0) return undefined;
|
||||
return {
|
||||
market,
|
||||
market: normalizeMarketCode(market),
|
||||
strategyId,
|
||||
timeframe: [...new Set(baseRows.map(r => r.timeframe))].join(', '),
|
||||
rows: baseRows.map(r => normalizeConditionRow({ ...r, currentValue: null, satisfied: null })),
|
||||
@@ -49,6 +51,7 @@ export function useTradeNotificationSignalSnapshot(
|
||||
const refreshInFlightRef = useRef(false);
|
||||
const resolvedStrategyRef = useRef<StrategyDto | undefined>();
|
||||
const effectiveStrategyIdRef = useRef<number | null>(null);
|
||||
const normalizedMarket = normalizeMarketCode(market);
|
||||
|
||||
const refresh = useCallback(async () => {
|
||||
const rawId = normalizeStrategyId(strategyId);
|
||||
@@ -65,14 +68,19 @@ export function useTradeNotificationSignalSnapshot(
|
||||
setLoading(true);
|
||||
|
||||
try {
|
||||
let effectiveStrategy = strategy ?? resolvedStrategyRef.current;
|
||||
let effectiveStrategy = strategy ? hydrateStrategyDto(strategy) : resolvedStrategyRef.current;
|
||||
let effectiveId = effectiveStrategy?.id ?? effectiveStrategyIdRef.current ?? rawId;
|
||||
|
||||
if (!effectiveStrategy || effectiveStrategy.id !== rawId) {
|
||||
const needsResolve = !effectiveStrategy
|
||||
|| extractVirtualConditions(effectiveStrategy).length === 0
|
||||
|| effectiveStrategy.id !== rawId;
|
||||
|
||||
if (needsResolve) {
|
||||
const resolved = await resolveNotificationStrategy(
|
||||
rawId,
|
||||
strategyName,
|
||||
prefetchedStrategies,
|
||||
normalizedMarket,
|
||||
);
|
||||
if (gen !== genRef.current) return;
|
||||
if (resolved.strategy) {
|
||||
@@ -86,11 +94,17 @@ export function useTradeNotificationSignalSnapshot(
|
||||
}
|
||||
|
||||
const pinFirst = emptyRetryRef.current === 0;
|
||||
let snap = await fetchLiveSnapshot(market, effectiveId, effectiveStrategy, pinFirst);
|
||||
let snap = await fetchLiveSnapshot(
|
||||
normalizedMarket,
|
||||
effectiveId,
|
||||
effectiveStrategy,
|
||||
pinFirst,
|
||||
{ readOnlyPin: true },
|
||||
);
|
||||
if (gen !== genRef.current) return;
|
||||
|
||||
if (!snap && effectiveStrategy) {
|
||||
snap = staticFallback(market, effectiveId, effectiveStrategy) ?? null;
|
||||
if ((!snap || snap.rows.length === 0) && effectiveStrategy) {
|
||||
snap = staticFallback(normalizedMarket, effectiveId, effectiveStrategy) ?? snap;
|
||||
}
|
||||
|
||||
if (snap && snap.rows.length > 0) {
|
||||
@@ -108,7 +122,15 @@ export function useTradeNotificationSignalSnapshot(
|
||||
} finally {
|
||||
refreshInFlightRef.current = false;
|
||||
}
|
||||
}, [market, strategyId, strategy, strategyName, enabled, prefetchedStrategies]);
|
||||
}, [
|
||||
market,
|
||||
normalizedMarket,
|
||||
strategyId,
|
||||
strategy,
|
||||
strategyName,
|
||||
enabled,
|
||||
prefetchedStrategies,
|
||||
]);
|
||||
|
||||
useEffect(() => {
|
||||
const rawId = normalizeStrategyId(strategyId);
|
||||
@@ -121,7 +143,7 @@ export function useTradeNotificationSignalSnapshot(
|
||||
return;
|
||||
}
|
||||
emptyRetryRef.current = 0;
|
||||
resolvedStrategyRef.current = strategy;
|
||||
resolvedStrategyRef.current = strategy ? hydrateStrategyDto(strategy) : undefined;
|
||||
effectiveStrategyIdRef.current = strategy?.id ?? rawId;
|
||||
setLoading(true);
|
||||
void refresh();
|
||||
|
||||
Reference in New Issue
Block a user