feat(player): improve wallet activity and session handling
Some checks failed
lotteryfront CI / build (push) Has been cancelled
Some checks failed
lotteryfront CI / build (push) Has been cancelled
This commit is contained in:
@@ -10,17 +10,29 @@ import {
|
||||
import { syncPreferredLanguage } from "@/i18n";
|
||||
|
||||
const I18nHydrationContext = createContext(false);
|
||||
const hydrationListeners = new Set<() => void>();
|
||||
let hydrationReady = false;
|
||||
let hydrationSyncPromise: Promise<void> | null = null;
|
||||
|
||||
function ensurePreferredLanguageSynced(): void {
|
||||
if (hydrationSyncPromise) return;
|
||||
|
||||
hydrationSyncPromise = syncPreferredLanguage()
|
||||
.catch(() => undefined)
|
||||
.then(() => {
|
||||
hydrationReady = true;
|
||||
hydrationListeners.forEach((listener) => listener());
|
||||
});
|
||||
}
|
||||
|
||||
function subscribeI18nHydration(onStoreChange: () => void): () => void {
|
||||
queueMicrotask(() => {
|
||||
syncPreferredLanguage();
|
||||
onStoreChange();
|
||||
});
|
||||
return () => {};
|
||||
hydrationListeners.add(onStoreChange);
|
||||
ensurePreferredLanguageSynced();
|
||||
return () => hydrationListeners.delete(onStoreChange);
|
||||
}
|
||||
|
||||
function getI18nHydratedSnapshot(): boolean {
|
||||
return true;
|
||||
return hydrationReady;
|
||||
}
|
||||
|
||||
function getI18nHydratedServerSnapshot(): boolean {
|
||||
@@ -42,4 +54,4 @@ export function I18nHydrationProvider({ children }: { children: ReactNode }) {
|
||||
|
||||
export function useI18nHydrated(): boolean {
|
||||
return useContext(I18nHydrationContext);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user