From d8f14b3ce6d594c5b7fb1146e6fc990e597e726b Mon Sep 17 00:00:00 2001 From: osmannyildiz Date: Sun, 17 Dec 2023 07:58:57 +0300 Subject: [PATCH] up --- src/app/kurslar/[courseSlug]/ogren/page.jsx | 23 +++++++++++++++++++-- src/components/DTLDisplay.jsx | 5 +++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/app/kurslar/[courseSlug]/ogren/page.jsx b/src/app/kurslar/[courseSlug]/ogren/page.jsx index fb9f3a7..01fffc7 100644 --- a/src/app/kurslar/[courseSlug]/ogren/page.jsx +++ b/src/app/kurslar/[courseSlug]/ogren/page.jsx @@ -1,5 +1,8 @@ "use client"; +import { DTLToken } from "@/contracts"; +import { COURSES } from "@/mockData"; import { useState } from "react"; +import { useContractWrite, usePrepareContractWrite } from "wagmi"; import styles from "./page.module.css"; const Step = ({ label }) => { @@ -13,7 +16,22 @@ const Step = ({ label }) => { ); }; -const Home = () => { +const LearnPage = ({ params }) => { + const course = COURSES.find((c) => c.slug === params.courseSlug); + + const { config: finishCourseConfig } = usePrepareContractWrite({ + address: DTLToken.address, + abi: DTLToken.abi, + functionName: "finishCourse", + args: [ + course.id, + "Osman Nuri Yıldız", + "Akıllı Kontrat Güvenliği", + "Atıl Samancıoğlu", + ], + }); + const finishCourse = useContractWrite(finishCourseConfig); + return (
@@ -47,6 +65,7 @@ const Home = () => { marginRight: "auto", display: "block", }} + onClick={() => finishCourse.write?.()} > Sertifikayı Al @@ -55,4 +74,4 @@ const Home = () => { ); }; -export default Home; +export default LearnPage; diff --git a/src/components/DTLDisplay.jsx b/src/components/DTLDisplay.jsx index ca95a2e..f4a4140 100644 --- a/src/components/DTLDisplay.jsx +++ b/src/components/DTLDisplay.jsx @@ -37,6 +37,11 @@ export default function DTLDisplay() { }); const approveMax = useContractWrite(approveMaxConfig); + useEffect(() => { + const interval = setInterval(() => getMyBalance.refetch(), 2000); + return () => clearInterval(interval); + }, []); + useEffect(() => { if (address) { getMyBalance.refetch();