forked from Prompt-Hash-Stellar/prompt-hash
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprofileStorage.ts
More file actions
27 lines (25 loc) · 881 Bytes
/
Copy pathprofileStorage.ts
File metadata and controls
27 lines (25 loc) · 881 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const AVATAR_STORAGE_KEY = "ph_user_avatars";
export function getProfileAvatarUrl(address: string): string | null {
if (typeof window === "undefined") return null;
try {
const raw = localStorage.getItem(AVATAR_STORAGE_KEY);
if (!raw) return null;
const map = JSON.parse(raw);
return map[address] || null;
} catch {
return null;
}
}
export function saveProfileAvatarUrl(address: string, url: string) {
if (typeof window === "undefined") return;
try {
const raw = localStorage.getItem(AVATAR_STORAGE_KEY);
const map = raw ? JSON.parse(raw) : {};
map[address] = url;
localStorage.setItem(AVATAR_STORAGE_KEY, JSON.stringify(map));
// Dispatch a custom event to notify components across the app to re-render
window.dispatchEvent(new Event("avatar_updated"));
} catch (e) {
console.error("Failed to save avatar", e);
}
}