-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathuse-progress.ts
61 lines (55 loc) · 1.6 KB
/
use-progress.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
import { SocialType } from '../types/gold-star';
import { GOLD_STAR_CHALLENGES } from '../utils/constants';
import { getChallengeIdentifier } from '../utils/flow';
import { useCurrentUser } from './use-current-user';
import { useProfile } from './use-profile';
export interface ProgressItem {
label: string;
completed: boolean;
}
export function useProgress() {
const { user } = useCurrentUser();
const { profile } = useProfile(user.addr);
const profileItems = [
{
label: 'Create your handle',
completed: profile && !!profile.handle,
},
{
label: 'Link your Github profile',
completed: profile && !!profile.socials[SocialType.GITHUB],
},
{
label: 'Share how you discovered Flow',
completed: profile && !!profile.referralSource,
},
{
label: 'Add your contract addresses',
completed:
profile &&
(Object.keys(profile.deployedContracts.cadenceContracts).length > 0 ||
Object.keys(profile.deployedContracts.evmContracts).length > 0),
},
] as ProgressItem[];
const challengeItems = [
{
label: 'Complete your first challenge',
completed:
profile &&
profile.submissions?.[
getChallengeIdentifier(GOLD_STAR_CHALLENGES.NOOP_CHALLENGE)
]?.completed,
},
] as ProgressItem[];
function getProgress() {
const items = [...profileItems, ...challengeItems];
const total = items.length;
const completed = items.filter((item) => item.completed).length;
return completed / total;
}
return {
profileItems,
challengeItems,
getProgress,
};
}