Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hook up NoopChallenge button #1081

Merged
merged 4 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/cadence/scripts/GetProfile.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ access(all) struct Profile {
access(all) var referralSource: String?
access(all) var deployedContracts: {Address: [String]}
access(all) var socials: {String: String}
access(all) var submissions: {Type: Submission}
access(all) var submissions: {String: Submission}

init(ref: &GoldStar.Profile) {
let submissions: {Type: Submission} = {}
let submissions: {String: Submission} = {}
for challengeType in ref.submissions.submissions.keys {
submissions[challengeType] = Submission(ref: ref.submissions.submissions[challengeType]!)
submissions[challengeType.identifier] = Submission(ref: ref.submissions.submissions[challengeType]!)
}

let deployedContracts: {Address: [String]} = {}
Expand Down
16 changes: 11 additions & 5 deletions src/components/ProgressModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Button } from '@site/src/ui/design-system/src/lib/Components/Button';
import { useProgress } from '../hooks/use-progress';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faBrain } from '@fortawesome/free-solid-svg-icons';
import { submitNoopChallenge } from '../utils/gold-star';

interface ProgressModalProps {
isOpen: boolean;
Expand All @@ -29,8 +30,8 @@ const ProgressModal: React.FC<ProgressModalProps> = ({
setChallengeModalOpen(false);
};

const completeChallenge = () => {
console.log('Challenge Completed!');
const completeChallenge = async () => {
await submitNoopChallenge();
closeChallengeModal();
};

Expand Down Expand Up @@ -73,12 +74,17 @@ const ProgressModal: React.FC<ProgressModalProps> = ({
<Modal
isOpen={challengeModalOpen}
onClose={closeChallengeModal}
title='Challenge Details'
title="Challenge Details"
>
<div className="space-y-4 text-center">
<FontAwesomeIcon icon={faBrain} size="5x" className="text-green-500" />
<FontAwesomeIcon
icon={faBrain}
size="5x"
className="text-green-500"
/>
<p className="text-lg text-gray-700 mt-4">
By completing this challenge, you are declaring your intent to learn Flow and explore its capabilities.
By completing this challenge, you are declaring your intent to
learn Flow and explore its capabilities.
</p>
<Button
size="lg"
Expand Down
6 changes: 2 additions & 4 deletions src/hooks/use-progress.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SocialType } from '../types/gold-star';
import { ChallengeContractName } from '../utils/constants';
import { GOLD_STAR_CHALLENGES } from '../utils/constants';
import { getChallengeIdentifier } from '../utils/flow';
import { useCurrentUser } from './use-current-user';
import { useProfile } from './use-profile';
Expand Down Expand Up @@ -32,15 +32,13 @@ export function useProgress() {
},
] as ProgressItem[];

console.log(getChallengeIdentifier(ChallengeContractName.NOOP_CHALLENGE));

const challengeItems = [
{
label: 'Complete first challenge',
completed:
profile &&
profile.submissions?.[
getChallengeIdentifier(ChallengeContractName.NOOP_CHALLENGE)
getChallengeIdentifier(GOLD_STAR_CHALLENGES.NOOP_CHALLENGE)
]?.completed,
},
] as ProgressItem[];
Expand Down
5 changes: 5 additions & 0 deletions src/types/gold-star.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,8 @@ export interface ChallengeResponse {
export enum SocialType {
GITHUB = 'github',
}

export interface Challenge {
contractName: string;
resourceIdentifier: string;
}
9 changes: 6 additions & 3 deletions src/utils/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ export const DISCORD_URL = 'https://discord.gg/flow';
export const DISCORD_ANNOUNCEMENTS_CHANNEL_ID = '621529603718119424';
export const DISCORD_DEV_UPDATES_CHANNEL_ID = '811693600403357706';

export enum ChallengeContractName {
NOOP_CHALLENGE = 'NoopChallenge',
}
export const GOLD_STAR_CHALLENGES = {
NOOP_CHALLENGE: {
contractName: 'NoopChallenge',
resourceIdentifier: 'Challenge',
},
};
12 changes: 7 additions & 5 deletions src/utils/flow.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as fcl from '@onflow/fcl';
import { ChallengeContractName } from './constants';
import { getContractAddress } from '../config/fcl';
import { Challenge } from '../types/gold-star';

export function typeIdentifier(
address: string,
Expand All @@ -12,8 +12,10 @@ export function typeIdentifier(
}`;
}

export function getChallengeIdentifier(
contractName: ChallengeContractName,
): string {
return typeIdentifier(getContractAddress(contractName), contractName);
export function getChallengeIdentifier(challenge: Challenge): string {
return typeIdentifier(
getContractAddress(challenge.contractName),
challenge.contractName,
challenge.resourceIdentifier,
);
}
11 changes: 11 additions & 0 deletions src/utils/gold-star.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import GetChallenges from '../cadence/scripts/GetChallenges.cdc';
import GetProfile from '../cadence/scripts/GetProfile.cdc';
import CreateProfile from '../cadence/transactions/GoldStar/CreateProfile.cdc';
import UpdateProfile from '../cadence/transactions/GoldStar/UpdateProfile.cdc';
import Evaluate from '../cadence/transactions/NoopChallenge/Evaluate.cdc';

import * as fcl from '@onflow/fcl';
import {
Expand Down Expand Up @@ -111,3 +112,13 @@ export const setProfile = async (profile: ProfileSettings) => {
],
});
};

/**
* Submit a noop challenge
* @returns The transaction ID
*/
export const submitNoopChallenge = async () => {
return await fcl.mutate({
cadence: Evaluate,
});
};
Loading