"use client"; import { lazy, useEffect, useState } from "react"; import type { NextPage } from "next"; import { notification } from "~~/utils/scaffold-eth"; import { addToIPFS } from "~~/utils/tokenization/ipfs-fetch"; import nftsMetadata from "~~/utils/tokenization/nftsMetadata"; const LazyReactJson = lazy(() => import("react-json-view")); const IpfsUpload: NextPage = () => { const [yourJSON, setYourJSON] = useState(nftsMetadata[0]); const [loading, setLoading] = useState(false); const [uploadedIpfsPath, setUploadedIpfsPath] = useState(""); const [mounted, setMounted] = useState(false); useEffect(() => { setMounted(true); }, []); const handleIpfsUpload = async () => { setLoading(true); const notificationId = notification.loading("Uploading to IPFS..."); try { const uploadedItem = await addToIPFS(yourJSON); notification.remove(notificationId); notification.success("Uploaded to IPFS"); setUploadedIpfsPath(uploadedItem.path); } catch (error) { notification.remove(notificationId); notification.error("Error uploading to IPFS"); console.log(error); } finally { setLoading(false); } }; return ( <>

Upload to IPFS

{mounted && ( { setYourJSON(edit.updated_src); }} onAdd={add => { setYourJSON(add.updated_src); }} onDelete={del => { setYourJSON(del.updated_src); }} /> )} {uploadedIpfsPath && (
{`https://ipfs.io/ipfs/${uploadedIpfsPath}`}
)}
); }; export default IpfsUpload;