feat(symbol-page): intraday short-term returns + hline storage-failure guard
- IntradayReturns: 10분/30분/1시간/3시간/시가대비 mini cards for 1D mode
(PeriodReturns labels lie when interval is 10m; swap them out by isIntraday)
- addLine/removeLine/clearLines now return previous state when localStorage
write fails — UI no longer diverges from storage in locked-storage env
addresses reviewer 318eae6 non-blocking caveat about write-failure divergence
This commit is contained in:
@@ -87,18 +87,21 @@ export function addLine(code: string, price: number): HLine[] {
|
||||
// 같은 가격이 이미 있으면 중복 추가 안 함 — 라인이 안 보일 뿐 헷갈림 유발.
|
||||
if (cur.some((l) => nearlyEqual(l.price, price))) return cur;
|
||||
const next = [...cur, { id: newId(), price, createdAt: new Date().toISOString() }];
|
||||
writeRaw(code, next);
|
||||
// 저장 실패 시 이전 상태 반환 — UI 가 보여주는 라인과 스토리지가 어긋나
|
||||
// 새로고침 후 사라지는 혼란을 막음 (시크릿 탭/스토리지 잠금 환경 대비).
|
||||
if (!writeRaw(code, next)) return cur;
|
||||
return next.slice(0, HLINE_MAX);
|
||||
}
|
||||
|
||||
export function removeLine(code: string, id: string): HLine[] {
|
||||
const cur = readLines(code);
|
||||
const next = cur.filter((l) => l.id !== id);
|
||||
writeRaw(code, next);
|
||||
// 삭제 저장 실패 시 이전 상태 유지 — UI 에서 사라졌다가 새로고침에 부활하면 더 혼란.
|
||||
if (!writeRaw(code, next)) return cur;
|
||||
return next;
|
||||
}
|
||||
|
||||
export function clearLines(code: string): HLine[] {
|
||||
writeRaw(code, []);
|
||||
if (!writeRaw(code, [])) return readLines(code);
|
||||
return [];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user