-
Notifications
You must be signed in to change notification settings - Fork 0
/
profiles.ts
105 lines (93 loc) · 2.77 KB
/
profiles.ts
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import { readHandler } from 'api';
import { PROCESSES } from 'helpers/config';
import { ProfileHeaderType, RegistryProfileType } from 'helpers/types';
export async function getProfileById(args: { profileId: string }): Promise<ProfileHeaderType | null> {
const emptyProfile = {
id: args.profileId,
walletAddress: null,
displayName: null,
username: null,
bio: null,
avatar: null,
banner: null,
};
try {
const fetchedProfile = await readHandler({
processId: args.profileId,
action: 'Info',
data: null,
});
if (fetchedProfile) {
return {
id: args.profileId,
walletAddress: fetchedProfile.Owner || null,
displayName: fetchedProfile.Profile.DisplayName || null,
username: fetchedProfile.Profile.Username || null,
bio: fetchedProfile.Profile.Bio || null,
avatar: fetchedProfile.Profile.Avatar || null,
banner: fetchedProfile.Profile.Banner || null,
};
} else return emptyProfile;
} catch (e: any) {
throw new Error(e);
}
}
export async function getProfileByWalletAddress(args: { address: string }): Promise<ProfileHeaderType | null> {
const emptyProfile = {
id: null,
walletAddress: args.address,
displayName: null,
username: null,
bio: null,
avatar: null,
banner: null,
};
try {
const profileLookup = await readHandler({
processId: PROCESSES.profileRegistry,
action: 'Get-Profiles-By-Address',
data: { Address: args.address },
});
let activeProfileId: string;
if (profileLookup && profileLookup.length > 0 && profileLookup[0].ProfileId) {
activeProfileId = profileLookup[0].ProfileId;
}
if (activeProfileId) {
const fetchedProfile = await readHandler({
processId: activeProfileId,
action: 'Info',
data: null,
});
if (fetchedProfile) {
return {
id: activeProfileId,
walletAddress: args.address,
displayName: fetchedProfile.Profile.DisplayName || null,
username: fetchedProfile.Profile.Username || null,
bio: fetchedProfile.Profile.Bio || null,
avatar: fetchedProfile.Profile.Avatar || null,
banner: fetchedProfile.Profile.Banner || null,
};
} else return emptyProfile;
} else return emptyProfile;
} catch (e: any) {
throw new Error(e);
}
}
export async function getRegistryProfiles(args: { profileIds: string[] }): Promise<RegistryProfileType[]> {
try {
const metadataLookup = await readHandler({
processId: PROCESSES.profileRegistry,
action: 'Get-Metadata-By-ProfileIds',
data: { ProfileIds: args.profileIds },
});
if (metadataLookup && metadataLookup.length) {
return metadataLookup.map((profile: { ProfileId: string; Username: string; Avatar: string }) => {
return { id: profile.ProfileId, username: profile.Username, avatar: profile.Avatar };
});
}
return [];
} catch (e: any) {
throw new Error(e);
}
}