-
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 #5 from KibokoDao-Africa/alex
Alex
- Loading branch information
Showing
5 changed files
with
142 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export const MARKETPLACE_ADDRESS = "0xBE3e0d39d350b41b5B6a4Bff4D4606F73849b01A"; | ||
export const MARKETPLACE_ADDRESS = "0x42Ca855E799a2891182c1859f78FFadE939f869C"; | ||
|
||
export const NFT_COLLECTION_ADDRESS = | ||
"0x717F9d7605b0669f1c81e71385763634a556faC9"; | ||
"0x744AA400cbb2D215d37642d510194e7418b180bC"; |
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,97 @@ | ||
import React, { useState, useCallback } from "react"; | ||
import { | ||
useAddress, | ||
useContract, | ||
useContractWrite, | ||
useStorageUpload, | ||
} from "@thirdweb-dev/react"; | ||
import { Box, Button, CircularProgress, TextField } from "@mui/material"; | ||
import { CustomTextField } from "./CustomeTextBox"; | ||
|
||
const Mint = () => { | ||
const address = useAddress(); | ||
const [amount, setAmount] = useState(1); | ||
// State to store generated random IDs | ||
const [tokenIds, setTokenIds] = useState(4); | ||
const [imageFile, setImageFile] = useState(null); // Added state for image file | ||
const { mutateAsync: upload } = useStorageUpload(); | ||
const { contract } = useContract( | ||
"0x717F9d7605b0669f1c81e71385763634a556faC9" | ||
); | ||
const { mutateAsync: mintTo, isLoading } = useContractWrite( | ||
contract, | ||
"mintTo" | ||
); | ||
|
||
const handleImageChange = (e) => { | ||
const file = e.target.files[0]; | ||
setImageFile(file); | ||
}; | ||
|
||
const mintNft = useCallback(async () => { | ||
try { | ||
if (!imageFile) { | ||
console.error("Please select an image file"); | ||
return; | ||
} | ||
|
||
// Upload the image file to IPFS | ||
const uris = await upload({ data: [imageFile] }); | ||
if (typeof uris !== "string") { | ||
console.error("Invalid IPFS CID"); | ||
return; | ||
} | ||
|
||
// Mint an NFT with the given IPFS CID | ||
const data = await mintTo({ args: [address, tokenIds, uris, amount] }); | ||
|
||
console.info("contract call successs", data); | ||
} catch (err) { | ||
console.error("contract call failure", err); | ||
} | ||
}, [address, amount, imageFile, mintTo, tokenIds, upload]); | ||
|
||
return ( | ||
<div> | ||
<Box> | ||
<CustomTextField | ||
value={amount} | ||
onChange={(e) => setAmount(Number(e.target.value))} | ||
sx={{ mt: "7%" }} | ||
fullWidth | ||
size="small" | ||
label="amount" | ||
inputProps={{ | ||
sx: { | ||
"&::placeholder": { | ||
color: "#fff", | ||
}, | ||
color: "#fff", | ||
backgroundColor: "grey", | ||
borderRadius: "12px", | ||
}, | ||
}} | ||
/> | ||
<input type="file" accept="image/*" onChange={handleImageChange} /> | ||
|
||
<Button | ||
sx={{ | ||
mt: "7%", | ||
background: "#0fe9ef", | ||
borderRadius: "15px", | ||
"&:hover": { background: "#0fe9ef" }, | ||
textTransform: "capitalize", | ||
width: "100%", | ||
whiteSpace: "nowrap", | ||
}} | ||
onClick={mintNft} | ||
disabled={isLoading} | ||
> | ||
Mint/Create Tickets {isLoading && <CircularProgress size={20} />} | ||
</Button> | ||
</Box> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Mint; |
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