From 4847632f686ae863891228f36d90c3b701bc4ee0 Mon Sep 17 00:00:00 2001 From: aki-0517 Date: Fri, 6 Dec 2024 00:18:05 +0900 Subject: [PATCH] =?UTF-8?q?=E3=81=A4=E3=81=AA=E3=81=8E=E8=BE=BC=E3=81=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nextjs/app/enterpreneur/form/fieldSet.tsx | 146 ++++++++++++------ .../hooks/scaffold-eth/useERC721Mintbatch.ts | 2 + 2 files changed, 101 insertions(+), 47 deletions(-) diff --git a/packages/nextjs/app/enterpreneur/form/fieldSet.tsx b/packages/nextjs/app/enterpreneur/form/fieldSet.tsx index 22b17f9..a033eec 100644 --- a/packages/nextjs/app/enterpreneur/form/fieldSet.tsx +++ b/packages/nextjs/app/enterpreneur/form/fieldSet.tsx @@ -7,12 +7,15 @@ import Grid from "@mui/material/Grid"; import Radio from "@mui/material/Radio"; import RadioGroup from "@mui/material/RadioGroup"; import TextField from "@mui/material/TextField"; +import { useERC721MintBatch } from "~~/hooks/scaffold-eth/useERC721Mintbatch"; +import { useAccount } from "wagmi"; type FiledSetProps = { title: string; }; export const FiledSet: FC = ({ title }) => { + const { address } = useAccount(); const [amount, setAmount] = useState(""); const [startDate, setStartDate] = useState(""); const [endDate, setEndDate] = useState(""); @@ -20,54 +23,103 @@ export const FiledSet: FC = ({ title }) => { const [details, setDetails] = useState(""); const [storeName, setStoreName] = useState(""); + const { mintBatch, isMinting } = useERC721MintBatch(); + + const handleMint = async () => { + if (!address) { + console.error("ウォレットが接続されていません。"); + return; + } + + try { + const numberOfTokens = 1n; + const issueDate = BigInt(Math.floor(new Date(startDate).getTime() / 1000)); + const expiryDate = BigInt(Math.floor(new Date(endDate).getTime() / 1000)); + const amountBigInt = BigInt(amount); + + await mintBatch( + address, + numberOfTokens, + title, + issueDate, + amountBigInt, + expiryDate, + usage === "店舗名入力" ? storeName : usage + ); + } catch (error) { + console.error("ミント中にエラーが発生しました:", error); + } + }; + return ( - <> - - - setAmount(e.target.value)} sx={{ mb: 2 }} /> - - - setStartDate(e.target.value)} - /> - - - setEndDate(e.target.value)} - /> - + + + setAmount(e.target.value)} + sx={{ mb: 2 }} + /> + + + setStartDate(e.target.value)} + /> + + + setEndDate(e.target.value)} + /> - setUsage(e.target.value)} sx={{ mt: 2, mb: 2 }}> - } label="会社全体" /> - - } label="店舗名入力" /> - setStoreName(e.target.value)} sx={{ ml: 2 }} /> - - - setDetails(e.target.value)} - sx={{ mb: 2 }} - /> - - - - + + setUsage(e.target.value)} + sx={{ mt: 2, mb: 2 }} + > + } label="会社全体" /> + + } label="店舗名入力" /> + setStoreName(e.target.value)} + sx={{ ml: 2 }} + /> + + + setDetails(e.target.value)} + sx={{ mb: 2 }} + /> + + + ); }; diff --git a/packages/nextjs/hooks/scaffold-eth/useERC721Mintbatch.ts b/packages/nextjs/hooks/scaffold-eth/useERC721Mintbatch.ts index 68f926f..beea3f9 100644 --- a/packages/nextjs/hooks/scaffold-eth/useERC721Mintbatch.ts +++ b/packages/nextjs/hooks/scaffold-eth/useERC721Mintbatch.ts @@ -1,3 +1,5 @@ +"use client"; + import { useState } from "react"; import { useScaffoldWriteContract } from "~~/hooks/scaffold-eth";