Add persistent onion key backup and restore, improve startup resilience, and flesh out the major site verticals with richer navigation, search coverage, and operator documentation. Made-with: Cursor
39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
const USD_KEY = "cyberlux-usd-store-credit";
|
|
const TX_KEY = "cyberlux-btc-claimed-txids";
|
|
|
|
export function loadUsdStoreCredit(): number {
|
|
if (typeof window === "undefined") return 0;
|
|
try {
|
|
const raw = localStorage.getItem(USD_KEY);
|
|
if (!raw) return 0;
|
|
const n = Number.parseFloat(raw);
|
|
return Number.isFinite(n) ? Math.round(n * 100) / 100 : 0;
|
|
} catch {
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
export function saveUsdStoreCredit(usd: number): void {
|
|
if (typeof window === "undefined") return;
|
|
const safe = Math.max(0, Math.round(usd * 100) / 100);
|
|
localStorage.setItem(USD_KEY, String(safe));
|
|
}
|
|
|
|
export function loadClaimedTxids(): string[] {
|
|
if (typeof window === "undefined") return [];
|
|
try {
|
|
const raw = localStorage.getItem(TX_KEY);
|
|
if (!raw) return [];
|
|
const parsed = JSON.parse(raw) as unknown;
|
|
if (!Array.isArray(parsed)) return [];
|
|
return parsed.map((x) => String(x)).filter((t) => /^[a-fA-F0-9]{64}$/.test(t));
|
|
} catch {
|
|
return [];
|
|
}
|
|
}
|
|
|
|
export function saveClaimedTxids(txids: string[]): void {
|
|
if (typeof window === "undefined") return;
|
|
localStorage.setItem(TX_KEY, JSON.stringify([...new Set(txids)]));
|
|
}
|