feat: enhance iframe communication and caching mechanisms
Some checks failed
lotteryfront CI / build (push) Has been cancelled
Some checks failed
lotteryfront CI / build (push) Has been cancelled
- Improved the entry lifecycle management to prevent duplicate token requests and ensure smooth transitions. - Updated the `resolvePostMessageTargetOrigin` function to return null when no allowed origins are present, enhancing security. - Cached runtime origins to optimize performance and reduce unnecessary API calls. - Added a new error message for frozen lottery wallets in the player notifications.
This commit is contained in:
@@ -10,7 +10,15 @@ type RuntimeOriginsEnvelope = {
|
||||
};
|
||||
};
|
||||
|
||||
const RUNTIME_ORIGINS_TTL_MS = 60_000;
|
||||
let cachedRuntimeOrigins: string[] | null = null;
|
||||
let cachedAt = 0;
|
||||
|
||||
async function loadRuntimeOrigins(): Promise<string[]> {
|
||||
if (cachedRuntimeOrigins !== null && Date.now() - cachedAt < RUNTIME_ORIGINS_TTL_MS) {
|
||||
return cachedRuntimeOrigins;
|
||||
}
|
||||
|
||||
try {
|
||||
const url = `${lotteryApiOrigin()}/api/v1/integration/runtime-origins`;
|
||||
const response = await fetch(url, {
|
||||
@@ -25,9 +33,12 @@ async function loadRuntimeOrigins(): Promise<string[]> {
|
||||
|
||||
if (!Array.isArray(origins)) return [];
|
||||
|
||||
return origins.filter((origin): origin is string => typeof origin === "string");
|
||||
cachedRuntimeOrigins = origins.filter((origin): origin is string => typeof origin === "string");
|
||||
cachedAt = Date.now();
|
||||
|
||||
return cachedRuntimeOrigins;
|
||||
} catch {
|
||||
return [];
|
||||
return cachedRuntimeOrigins ?? [];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user