forked from StellarSplit/StellarSplit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsession.ts
More file actions
53 lines (45 loc) · 1.68 KB
/
Copy pathsession.ts
File metadata and controls
53 lines (45 loc) · 1.68 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { sessionStore, SessionKey } from "./sessionStore";
export interface StoredParticipantIdentity {
name: string;
email?: string;
walletAddress?: string;
}
const PARTICIPANT_DIRECTORY_KEY = 'participant-directory';
export function getStoredActiveUserId(): string | null {
return sessionStore.getItem<string>(SessionKey.ACTIVE_USER_ID);
}
export function setStoredActiveUserId(userId: string | null): void {
if (!userId) {
sessionStore.removeItem(SessionKey.ACTIVE_USER_ID);
} else {
sessionStore.setItem(SessionKey.ACTIVE_USER_ID, userId);
}
}
export function getStoredAuthToken(): string | null {
return sessionStore.getItem<string>(SessionKey.AUTH_TOKEN);
}
export function setStoredAuthToken(token: string | null): void {
if (!token) {
sessionStore.removeItem(SessionKey.AUTH_TOKEN);
} else {
sessionStore.setItem(SessionKey.AUTH_TOKEN, token);
}
}
// Keep the participant directory for now, but move it to sessionStore if needed later
export function storeSplitParticipantDirectory(
splitId: string,
identities: Record<string, StoredParticipantIdentity>,
): void {
const currentDirectory = sessionStore.getItem<Record<string, Record<string, StoredParticipantIdentity>>>(PARTICIPANT_DIRECTORY_KEY) || {};
currentDirectory[splitId] = {
...(currentDirectory[splitId] ?? {}),
...identities,
};
sessionStore.setItem(PARTICIPANT_DIRECTORY_KEY, currentDirectory);
}
export function getStoredSplitParticipantDirectory(
splitId: string,
): Record<string, StoredParticipantIdentity> {
const directory = sessionStore.getItem<Record<string, Record<string, StoredParticipantIdentity>>>(PARTICIPANT_DIRECTORY_KEY) || {};
return directory[splitId] ?? {};
}