forked from TrustUp-app/TrustUp-Frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUser.ts
More file actions
63 lines (60 loc) · 1.96 KB
/
Copy pathUser.ts
File metadata and controls
63 lines (60 loc) · 1.96 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
54
55
56
57
58
59
60
61
62
63
/**
* UI / app model for the authenticated user profile.
* Mapped from `GET /users/me` (and optional related endpoints).
*/
export interface UserProfile {
id: string;
displayName: string;
username: string;
/** Avatar image URL. Absent when the user has no photo (fall back to initials). */
avatarUrl?: string | null;
/** Full Stellar wallet address (starts with `G`). */
walletAddress: string;
/** Reputation score in the 0–100 range. */
reputationScore: number;
/** Total number of loans the user has taken. */
totalLoans: number;
/** Total amount deposited by the user, in the platform's base currency. */
totalDeposited: number;
/** ISO date string of when the user joined. */
memberSince: string;
}
/**
* Raw payload fields commonly returned by `GET /users/me`.
* Supports both the documented API shape and a flatter UI-oriented shape.
*/
export interface UserMeApiResponse {
id?: string;
wallet?: string;
walletAddress?: string;
name?: string;
displayName?: string;
username?: string;
avatar?: string | null;
avatarUrl?: string | null;
reputationScore?: number;
totalLoans?: number;
totalDeposited?: number;
memberSince?: string;
createdAt?: string;
}
/**
* Maps a `GET /users/me` payload into the app's {@link UserProfile} model.
*/
export const mapUserMeToProfile = (raw: UserMeApiResponse): UserProfile => {
const displayName = raw.displayName ?? raw.name ?? '';
const walletAddress = raw.walletAddress ?? raw.wallet ?? '';
const username =
raw.username ?? (walletAddress ? walletAddress.slice(0, 8).toLowerCase() : 'user');
return {
id: raw.id ?? walletAddress ?? 'unknown',
displayName: displayName || username,
username,
avatarUrl: raw.avatarUrl ?? raw.avatar ?? null,
walletAddress,
reputationScore: raw.reputationScore ?? 0,
totalLoans: raw.totalLoans ?? 0,
totalDeposited: raw.totalDeposited ?? 0,
memberSince: raw.memberSince ?? raw.createdAt ?? new Date().toISOString(),
};
};