-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from aki-0517/feat/user-list
Feat/user list
- Loading branch information
Showing
5 changed files
with
117 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 }; | ||
}; |
Oops, something went wrong.