fix: заменить crypto.randomUUID() на fallback для HTTP без TLS

crypto.randomUUID() доступен только в secure context (HTTPS/localhost),
из-за чего при открытии приложения по обычному HTTP падал TypeError
при добавлении сплитов транзакции.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01769tkxLJooEWNjx3xc9aCv
This commit is contained in:
ZProger
2026-09-10 19:17:20 +03:00
parent aac72f36f2
commit cd2e4ae9f9

View File

@@ -41,8 +41,19 @@ interface SplitRowState {
note: string;
}
// crypto.randomUUID() only exists in secure contexts (HTTPS/localhost) — on plain
// HTTP (e.g. accessing the app by LAN IP) it's undefined and throws a TypeError.
// This key is only a local React list key, never sent to the backend, so a
// Math.random()-based fallback is fine when the Web Crypto API isn't available.
function generateRowKey(): string {
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
return crypto.randomUUID();
}
return `split-${Date.now()}-${Math.random().toString(36).slice(2, 10)}`;
}
function emptySplitRow(): SplitRowState {
return { key: crypto.randomUUID(), category_id: "", amount: "", note: "" };
return { key: generateRowKey(), category_id: "", amount: "", note: "" };
}
// Cents, not floats — a plain Number sum of "0.10" + "0.20" style amounts can