mirror of
https://github.com/Zproger/Aurum.git
synced 2026-10-13 02:56:39 +07:00
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:
@@ -41,8 +41,19 @@ interface SplitRowState {
|
|||||||
note: string;
|
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 {
|
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
|
// Cents, not floats — a plain Number sum of "0.10" + "0.20" style amounts can
|
||||||
|
|||||||
Reference in New Issue
Block a user