diff --git a/frontend/components/post/NewPost.tsx b/frontend/components/post/NewPost.tsx index ccda9fd..2fc6f8e 100644 --- a/frontend/components/post/NewPost.tsx +++ b/frontend/components/post/NewPost.tsx @@ -11,6 +11,9 @@ import UserInfo from "../user/UserInfo"; import PostForm from "./PostForm"; import { POST_TITLES } from "@/utils/constants"; import Modal from "../Modal"; +import SismoConnect from "../user/SismoConnect"; +import { sendTx } from "@/utils/sendTx"; +import toast from "react-hot-toast"; export default function NewPost({ web3StorageAccessToken, @@ -25,18 +28,16 @@ export default function NewPost({ const { address } = useAccount(); const { data: isVerified, refetch: refetchVerified } = useIsVerified(address); const [type, setType] = useState(undefined); - const [needVerify, setNeedVerify] = useState(false) const selectType = (selected: PostType) => { setType(selected); - if ((isVerified as number) < 2) { - setNeedVerify(true) - } } let title; - if (needVerify) { - title = isVerified == 0 ? 'Please verify you are a project owner first' : 'Please wait to be verified' + if (isVerified == 0) { + title = 'Please verify you are a project owner first' + } else if (isVerified == 1) { + title = 'Please verify you starred ShuaJJ/Cryptopia repo via Sismo Connect to finish verification' } else if (type) { title = POST_TITLES[type] ?? 'Please upload a cool image and enter the content'; } else { @@ -62,23 +63,44 @@ export default function NewPost({ const userProps = { ...props, contract: userContract, refetch }; const postProps = { ...props, contract: postContract, type: type ?? 'announcement', refetch: refetchPosts }; + const verifySismo = async (response: string) => { + if (!walletClient || !publicClient || !address || !userContract) { + toast.error('Please make sure you are connected', { position: 'top-center' }) + return; + } + + const verified = await sendTx( + 'Verify Github Star', + address, + userContract, + 'verifySismoConnectResponse', + publicClient, + walletClient, + addRecentTransaction, + [response] + ); + + if (verified) { + refetch(); + } + } + const modalBody = () => { - if (needVerify && isVerified == 0) { + if (isVerified == 0) { return - }else if (!needVerify && type) { + } else if (isVerified == 1) { + return + } else if (type) { return - } else if (!type) { - return } - return null; + return } return ( { setType(undefined); - setNeedVerify(false); setShow(false); }}> {type && ( @@ -86,7 +108,6 @@ export default function NewPost({ className="absolute left-3 top-3 inline-block p-4" onClick={() => { setType(undefined); - setNeedVerify(false); }} > back diff --git a/frontend/components/user/SismoConnect.tsx b/frontend/components/user/SismoConnect.tsx index 41918a0..a03e5bd 100644 --- a/frontend/components/user/SismoConnect.tsx +++ b/frontend/components/user/SismoConnect.tsx @@ -1,63 +1,25 @@ -// Next.js https://nextjs.org/docs/getting-started/installation -// in src/page.tsx "use client"; import { SismoConnectButton, AuthType, - SismoConnectResponse, - ClaimType, } from "@sismo-core/sismo-connect-react"; -export default function Home() { +export default function SismoConnect({callback}: {callback: (response: string) => void}) { return ( { - const res = await fetch("/api/verify", { - method: "POST", - body: JSON.stringify(response), - }); - console.log(await res.json()); + signature={{ message: "I starred the project repo" }} + onResponseBytes={async (response: string) => { + callback(response); }} - // reponse in bytes to call a contract - // onResponseBytes={async (response: string) => { - // console.log(response); - // }} /> ); } \ No newline at end of file diff --git a/frontend/components/user/UserInfo.tsx b/frontend/components/user/UserInfo.tsx index ed1202c..a7c5f1f 100644 --- a/frontend/components/user/UserInfo.tsx +++ b/frontend/components/user/UserInfo.tsx @@ -224,7 +224,7 @@ export default function UserInfo({ onClick={createPost} loading={loading} > - Submit for verification + Next )