From ffd581a10529ac9d801204e57a97fb96c5eaa4ec Mon Sep 17 00:00:00 2001 From: vivekjain23 <165671934+vivekjain23@users.noreply.github.com> Date: Thu, 16 Jan 2025 11:19:23 +0530 Subject: [PATCH] feat(docs): mint ctf completion nft (#4521) * Mint CTF completion NFT --- .../developer/iota-move-ctf/challenge_1.mdx | 2 +- .../developer/iota-move-ctf/challenge_2.mdx | 2 +- .../developer/iota-move-ctf/challenge_3.mdx | 2 +- .../developer/iota-move-ctf/challenge_4.mdx | 2 +- .../developer/iota-move-ctf/challenge_5.mdx | 2 +- .../developer/iota-move-ctf/challenge_6.mdx | 2 +- .../developer/iota-move-ctf/challenge_7.mdx | 2 +- .../developer/iota-move-ctf/challenge_8.mdx | 2 +- docs/site/src/components/CTF/ctf-verifier.tsx | 76 ++++++++++++------- docs/site/src/components/CTF/popup.tsx | 17 ++++- docs/site/src/utils/ctf-utils.ts | 4 +- 11 files changed, 73 insertions(+), 40 deletions(-) diff --git a/docs/content/developer/iota-move-ctf/challenge_1.mdx b/docs/content/developer/iota-move-ctf/challenge_1.mdx index 074825eb770..141a2791a6e 100644 --- a/docs/content/developer/iota-move-ctf/challenge_1.mdx +++ b/docs/content/developer/iota-move-ctf/challenge_1.mdx @@ -35,4 +35,4 @@ Good luck in capturing your first flag! - \ No newline at end of file + \ No newline at end of file diff --git a/docs/content/developer/iota-move-ctf/challenge_2.mdx b/docs/content/developer/iota-move-ctf/challenge_2.mdx index b00a5bd9983..046822df864 100644 --- a/docs/content/developer/iota-move-ctf/challenge_2.mdx +++ b/docs/content/developer/iota-move-ctf/challenge_2.mdx @@ -42,4 +42,4 @@ Good luck in capturing your second flag! - \ No newline at end of file + \ No newline at end of file diff --git a/docs/content/developer/iota-move-ctf/challenge_3.mdx b/docs/content/developer/iota-move-ctf/challenge_3.mdx index 172ca441ff7..5627115e415 100644 --- a/docs/content/developer/iota-move-ctf/challenge_3.mdx +++ b/docs/content/developer/iota-move-ctf/challenge_3.mdx @@ -45,4 +45,4 @@ Good luck in capturing your third flag! - \ No newline at end of file + \ No newline at end of file diff --git a/docs/content/developer/iota-move-ctf/challenge_4.mdx b/docs/content/developer/iota-move-ctf/challenge_4.mdx index 511a948e5cc..66fe23e263c 100644 --- a/docs/content/developer/iota-move-ctf/challenge_4.mdx +++ b/docs/content/developer/iota-move-ctf/challenge_4.mdx @@ -46,4 +46,4 @@ Good luck in capturing your fourth flag! Under `Deployed Contract Addresses`, you can find the addresses of the package as well as the `Vault`. Carefully check what the constraints are for the `get_flag` function to work, as it has some assertions that need to be met. ::: - \ No newline at end of file + \ No newline at end of file diff --git a/docs/content/developer/iota-move-ctf/challenge_5.mdx b/docs/content/developer/iota-move-ctf/challenge_5.mdx index 5404f6f582f..bfe79236979 100644 --- a/docs/content/developer/iota-move-ctf/challenge_5.mdx +++ b/docs/content/developer/iota-move-ctf/challenge_5.mdx @@ -36,4 +36,4 @@ After taking a look at the challenge's usage of [bcs::to_bytes](../../references Good luck in capturing your fifth flag! - \ No newline at end of file + \ No newline at end of file diff --git a/docs/content/developer/iota-move-ctf/challenge_6.mdx b/docs/content/developer/iota-move-ctf/challenge_6.mdx index ffade8fdfe7..2c8d253a92c 100644 --- a/docs/content/developer/iota-move-ctf/challenge_6.mdx +++ b/docs/content/developer/iota-move-ctf/challenge_6.mdx @@ -44,4 +44,4 @@ Good luck in capturing your sixth flag! Make sure you recycle enough pizza boxes! ::: - \ No newline at end of file + \ No newline at end of file diff --git a/docs/content/developer/iota-move-ctf/challenge_7.mdx b/docs/content/developer/iota-move-ctf/challenge_7.mdx index a6ba9de785a..62b2900bbd4 100644 --- a/docs/content/developer/iota-move-ctf/challenge_7.mdx +++ b/docs/content/developer/iota-move-ctf/challenge_7.mdx @@ -35,4 +35,4 @@ Good luck in capturing your seventh flag! - \ No newline at end of file + \ No newline at end of file diff --git a/docs/content/developer/iota-move-ctf/challenge_8.mdx b/docs/content/developer/iota-move-ctf/challenge_8.mdx index d8015702836..0417f08574a 100644 --- a/docs/content/developer/iota-move-ctf/challenge_8.mdx +++ b/docs/content/developer/iota-move-ctf/challenge_8.mdx @@ -53,4 +53,4 @@ The DEX programmer pulled an all-nighter before writing the flash loan mechanism - \ No newline at end of file + \ No newline at end of file diff --git a/docs/site/src/components/CTF/ctf-verifier.tsx b/docs/site/src/components/CTF/ctf-verifier.tsx index 0ba79670930..3f0c0140d04 100644 --- a/docs/site/src/components/CTF/ctf-verifier.tsx +++ b/docs/site/src/components/CTF/ctf-verifier.tsx @@ -1,48 +1,64 @@ import React, { useState, useMemo } from 'react'; import { IotaClientProvider, + useSignAndExecuteTransaction, WalletProvider, } from '@iota/dapp-kit'; import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; -import { getFullnodeUrl, IotaClient } from '@iota/iota-sdk/client'; +import { getFullnodeUrl } from '@iota/iota-sdk/client'; import clsx from 'clsx'; +import { useConnectWallet, useWallets } from '@iota/dapp-kit'; +import Popup from './popup'; +import { handleChallengeSubmit } from "../../utils/ctf-utils" -// Define props interface interface ChallengeVerifierProps { - expectedObjectType: string; // Prop for the expected Object Type + expectedObjectType: string; + nftName: string; + challengeNumber: string } -// Define network configurations const NETWORKS = { testnet: { url: getFullnodeUrl('testnet') }, }; -// Main ChallengeVerifier component -const ChallengeVerifier: React.FC = ({ expectedObjectType }) => { +const ChallengeVerifier: React.FC = ({ + expectedObjectType, + nftName, + challengeNumber, +}) => { const [inputText, setInputText] = useState(''); const [coins, setCoins] = useState(null); + const [showPopup, setShowPopup] = useState(false); const [loading, setLoading] = useState(false); - const [error, setError] = useState(''); + const [error, setError] = useState<{ + status: 'success' | 'error'; + description: string; + title: string; + }>({ + status: 'success', + description: '', + title: '', + }); + const wallets = useWallets(); + const { mutate } = useConnectWallet(); + const { mutate: signAndExecuteTransaction} = useSignAndExecuteTransaction(); + const [digest,setDigest] = useState(''); const handleSubmit = async () => { - setLoading(true); - setError(''); - setCoins(null); - - try { - const client = new IotaClient({ url: NETWORKS.testnet.url }); - const result = await client.getObject({ id: inputText, options: { showType: true } }); - - const message = result.data.type === expectedObjectType - ? 'Congratulations! You have successfully completed this level!' - : 'Invalid Flag Object Id. Please try again.'; - - setCoins(message); - } catch (err: any) { - setError(err.message || 'An error occurred. Please try again.'); - } finally { - setLoading(false); - } + await handleChallengeSubmit({ + inputText, + expectedObjectType, + nftName, + challengeNumber, + wallets, + mutate, + signAndExecuteTransaction, + setLoading, + setCoins, + setError, + setShowPopup, + setDigest + }); }; return ( @@ -57,7 +73,7 @@ const ChallengeVerifier: React.FC = ({ expectedObjectTyp placeholder="Enter Flag Object Id" className="input-field" /> - {

{error}

} + {

{error.description}

}