From 580fa89d1b2712788d35a38f6ae61241ed6c1a8f Mon Sep 17 00:00:00 2001 From: aki-0517 Date: Thu, 5 Dec 2024 19:53:46 +0900 Subject: [PATCH 1/2] add scaffold --- .../hooks/scaffold-eth/useERC721List.ts | 27 ++++++++++++ .../hooks/scaffold-eth/useERC721Mintbatch.ts | 44 +++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 packages/nextjs/hooks/scaffold-eth/useERC721List.ts create mode 100644 packages/nextjs/hooks/scaffold-eth/useERC721Mintbatch.ts diff --git a/packages/nextjs/hooks/scaffold-eth/useERC721List.ts b/packages/nextjs/hooks/scaffold-eth/useERC721List.ts new file mode 100644 index 0000000..5ee1f2f --- /dev/null +++ b/packages/nextjs/hooks/scaffold-eth/useERC721List.ts @@ -0,0 +1,27 @@ +'use client'; + +import { useScaffoldReadContract } from './useScaffoldReadContract'; +import { BigNumber } from 'ethers'; + +interface Voucher { + title: string; + issueDate: BigNumber; + amount: BigNumber; + expiryDate: BigNumber; + usageScope: string; +} + +export const useERC721List = ( ownerAddress: string) => { + + // Fetch the list of vouchers owned by the specified address + const { data: vouchers } = useScaffoldReadContract({ + contractName: "ExpirableERC721", + functionName: "listVouchers", + args: [ownerAddress], + }); + + + return { + vouchers: vouchers as Voucher[] | undefined, + }; +}; diff --git a/packages/nextjs/hooks/scaffold-eth/useERC721Mintbatch.ts b/packages/nextjs/hooks/scaffold-eth/useERC721Mintbatch.ts new file mode 100644 index 0000000..68f926f --- /dev/null +++ b/packages/nextjs/hooks/scaffold-eth/useERC721Mintbatch.ts @@ -0,0 +1,44 @@ +import { useState } from "react"; +import { useScaffoldWriteContract } from "~~/hooks/scaffold-eth"; + +/** + * Custom hook to interact with the mintBatch function of the ExpirableERC721 contract. + */ +export const useERC721MintBatch = () => { + const [isMinting, setIsMinting] = useState(false); + const { writeContractAsync } = useScaffoldWriteContract("ExpirableERC721"); + + /** + * Function to mint a batch of ERC721 tokens. + * @param to Address to mint the tokens to. + * @param numberOfTokens Number of tokens to mint. + * @param title Title of the voucher. + * @param issueDate Issue date of the voucher. + * @param amount Amount associated with the voucher. + * @param expiryDate Expiry date of the voucher. + * @param usageScope Usage scope of the voucher. + */ + const mintBatch = async ( + to: string, + numberOfTokens: bigint, + title: string, + issueDate: bigint, + amount: bigint, + expiryDate: bigint, + usageScope: string + ) => { + setIsMinting(true); + try { + await writeContractAsync({ + functionName: "mintBatch", + args: [to, numberOfTokens, title, issueDate, amount, expiryDate, usageScope], + }); + } catch (error) { + console.error("Error minting batch:", error); + } finally { + setIsMinting(false); + } + }; + + return { mintBatch, isMinting }; +}; From 68281a9b49969ebe5d04264a087dcd1dd3e020ea Mon Sep 17 00:00:00 2001 From: aki-0517 Date: Fri, 6 Dec 2024 00:01:07 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=E3=81=A4=E3=81=AA=E3=81=8E=E8=BE=BC?= =?UTF-8?q?=E3=81=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/nextjs/app/user/list/page.tsx | 52 ++++++++++---------------- packages/nextjs/components/Header.tsx | 9 +---- packages/nextjs/public/logo.svg | 34 ++++++++++++----- 3 files changed, 46 insertions(+), 49 deletions(-) diff --git a/packages/nextjs/app/user/list/page.tsx b/packages/nextjs/app/user/list/page.tsx index 8336700..effee4a 100644 --- a/packages/nextjs/app/user/list/page.tsx +++ b/packages/nextjs/app/user/list/page.tsx @@ -1,37 +1,25 @@ -import type { NextPage } from "next"; -import { CardList } from "~~/components/CardList"; +'use client'; + +import type { NextPage } from 'next'; +import { useAccount } from 'wagmi'; +import { CardList } from '~~/components/CardList'; +import { useERC721List } from '~~/hooks/scaffold-eth/useERC721List'; const UserListPage: NextPage = () => { - const cards = [ - { - title: "引換券", - issueDate: "2024.12.05", - amount: 7000, - expiryDate: "2025.06.30", - usageScope: "店舗全体", - }, - { - title: "引換券", - issueDate: "2024.12.05", - amount: 7000, - expiryDate: "2025.06.30", - usageScope: "店舗全体", - }, - { - title: "引換券", - issueDate: "2024.12.05", - amount: 7000, - expiryDate: "2025.06.30", - usageScope: "店舗全体", - }, - { - title: "引換券", - issueDate: "2024.12.05", - amount: 7000, - expiryDate: "2025.06.30", - usageScope: "店舗全体", - }, - ]; + const { address } = useAccount(); + const { vouchers } = useERC721List(address || ''); + + const cards = vouchers?.map((voucher) => { + const amount = voucher.amount; + return { + title: voucher.title, + issueDate: voucher.issueDate.toString(), + amount: Number(amount), + expiryDate: voucher.expiryDate.toString(), + usageScope: voucher.usageScope, + }; + }) || []; + return ; }; diff --git a/packages/nextjs/components/Header.tsx b/packages/nextjs/components/Header.tsx index 91b2765..6b27ce3 100644 --- a/packages/nextjs/components/Header.tsx +++ b/packages/nextjs/components/Header.tsx @@ -90,17 +90,10 @@ export const Header = () => { )} -
+
SE2 logo
-
- Scaffold-ETH - Ethereum dev stack -
- {/*
    - -
*/}
diff --git a/packages/nextjs/public/logo.svg b/packages/nextjs/public/logo.svg index 93e4b40..7521d84 100644 --- a/packages/nextjs/public/logo.svg +++ b/packages/nextjs/public/logo.svg @@ -1,10 +1,26 @@ - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + +