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 first challenge progress #1075

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
2 changes: 1 addition & 1 deletion flow.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
},
"deployments": {
"testnet": {
"goldstar": ["GoldStar"]
"goldstar": ["GoldStar", "NoopChallenge"]
}
}
}
25 changes: 24 additions & 1 deletion src/config/fcl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as fcl from '@onflow/fcl';
import config from '@generated/docusaurus.config';
import flowJSON from '../../flow.json';

const flowNetwork = config.customFields?.flowNetwork;
const flowNetwork = (config.customFields?.flowNetwork as string) || 'testnet';

console.log('Dapp running on network:', flowNetwork);

Expand All @@ -25,4 +25,27 @@ export function configureFCL(): void {
});
}

/**
* Get the contract address for a given contract name from the flow.json file
* @param contractName
* @returns Contract address
*/
export function getContractAddress(contractName: string): string {
const deploymentAccount = Object.entries(
flowJSON.deployments[flowNetwork],
).find(([_, c]) => (c as string[]).includes(contractName))?.[0];

if (deploymentAccount) {
return flowJSON.accounts[deploymentAccount].address;
}

const externalAddress =
flowJSON.contracts[contractName]?.aliases[flowNetwork];
if (externalAddress) {
return externalAddress;
}

throw new Error(`Contract address not found for ${contractName}`);
}

configureFCL();
10 changes: 9 additions & 1 deletion src/hooks/use-progress.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { SocialType } from '../types/gold-star';
import { ChallengeContractName } from '../utils/constants';
import { getChallengeIdentifier } from '../utils/flow';
import { useCurrentUser } from './use-current-user';
import { useProfile } from './use-profile';

Expand Down Expand Up @@ -30,10 +32,16 @@ export function useProgress() {
},
] as ProgressItem[];

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

const challengeItems = [
{
label: 'Complete first challenge',
completed: false,
completed:
profile &&
profile.submissions?.[
getChallengeIdentifier(ChallengeContractName.NOOP_CHALLENGE)
]?.completed,
},
] as ProgressItem[];

Expand Down
4 changes: 4 additions & 0 deletions src/utils/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,7 @@ export const HIGHLIGHT_LANGUAGES = [
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',
}
19 changes: 19 additions & 0 deletions src/utils/flow.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import * as fcl from '@onflow/fcl';
import { ChallengeContractName } from './constants';
import { getContractAddress } from '../config/fcl';

export function typeIdentifier(
address: string,
contractName: string,
type?: string,
): string {
return `A.${fcl.sansPrefix(address)}.${contractName}${
type ? `.${type}` : ''
}`;
}

export function getChallengeIdentifier(
contractName: ChallengeContractName,
): string {
return typeIdentifier(getContractAddress(contractName), contractName);
}