mirror of
https://github.com/chillpadclub/bedolaga-cabinet.git
synced 2026-07-28 09:33:46 +00:00
- Fix stale initData comparison in clearStaleSessionIfNeeded that destroyed valid refresh tokens on mobile WebView reopens - Restrict X-Telegram-Init-Data header to auth endpoints only - Close Mini App on auth retry to force fresh initData from Telegram - Merge Connection page error/not-configured states for better UX - Remove unnecessary comments across 40+ files (section dividers, restating comments, noise catch block comments) - Configure ESLint allowEmptyCatch to properly handle intentional empty catch blocks (62 warnings resolved)
60 lines
1.6 KiB
TypeScript
60 lines
1.6 KiB
TypeScript
const STORAGE_KEY = 'topup_pending_payment';
|
|
const MAX_AGE_MS = 30 * 60 * 1000; // 30 minutes
|
|
|
|
export interface TopUpPendingInfo {
|
|
amount_kopeks: number;
|
|
method_id: string;
|
|
method_name: string;
|
|
payment_id: string;
|
|
created_at: number; // Date.now()
|
|
}
|
|
|
|
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
return typeof value === 'object' && value !== null;
|
|
}
|
|
|
|
export function saveTopUpPendingInfo(info: TopUpPendingInfo) {
|
|
try {
|
|
sessionStorage.setItem(STORAGE_KEY, JSON.stringify(info));
|
|
} catch {}
|
|
}
|
|
|
|
export function loadTopUpPendingInfo(): TopUpPendingInfo | null {
|
|
try {
|
|
const raw = sessionStorage.getItem(STORAGE_KEY);
|
|
if (!raw) return null;
|
|
const parsed: unknown = JSON.parse(raw);
|
|
if (
|
|
!isRecord(parsed) ||
|
|
typeof parsed.amount_kopeks !== 'number' ||
|
|
typeof parsed.method_id !== 'string' ||
|
|
typeof parsed.method_name !== 'string' ||
|
|
typeof parsed.payment_id !== 'string' ||
|
|
typeof parsed.created_at !== 'number' ||
|
|
parsed.amount_kopeks <= 0
|
|
) {
|
|
return null;
|
|
}
|
|
// Discard stale entries
|
|
if (Date.now() - (parsed.created_at as number) > MAX_AGE_MS) {
|
|
clearTopUpPendingInfo();
|
|
return null;
|
|
}
|
|
return {
|
|
amount_kopeks: parsed.amount_kopeks as number,
|
|
method_id: parsed.method_id as string,
|
|
method_name: parsed.method_name as string,
|
|
payment_id: parsed.payment_id as string,
|
|
created_at: parsed.created_at as number,
|
|
};
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
export function clearTopUpPendingInfo() {
|
|
try {
|
|
sessionStorage.removeItem(STORAGE_KEY);
|
|
} catch {}
|
|
}
|