diff --git a/flow.json b/flow.json index 695cd04b98..5fe89c976c 100644 --- a/flow.json +++ b/flow.json @@ -114,7 +114,7 @@ }, "deployments": { "testnet": { - "goldstar": ["GoldStar"] + "goldstar": ["GoldStar", "NoopChallenge"] } } } diff --git a/src/config/fcl.ts b/src/config/fcl.ts index 132a2ab6bd..11de1def7d 100644 --- a/src/config/fcl.ts +++ b/src/config/fcl.ts @@ -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); @@ -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(); diff --git a/src/hooks/use-progress.ts b/src/hooks/use-progress.ts index 29b8773a50..109ce202df 100644 --- a/src/hooks/use-progress.ts +++ b/src/hooks/use-progress.ts @@ -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'; @@ -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[]; diff --git a/src/utils/constants.tsx b/src/utils/constants.tsx index a8a001e1af..a2b67a2f96 100644 --- a/src/utils/constants.tsx +++ b/src/utils/constants.tsx @@ -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', +} diff --git a/src/utils/flow.ts b/src/utils/flow.ts new file mode 100644 index 0000000000..f0e7bc7e9e --- /dev/null +++ b/src/utils/flow.ts @@ -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); +}