forked from Scaffold-Stark/scaffold-stark-2
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c97f571
commit d9ab9e2
Showing
37 changed files
with
3,111 additions
and
330 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ yarn-error.log* | |
|
||
# local env files | ||
.env*.local | ||
.env | ||
|
||
# vercel | ||
.vercel | ||
|
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,12 @@ | ||
import { ipfsClient } from "~~/utils/simpleNFT/ipfs"; | ||
|
||
export async function POST(request: Request) { | ||
try { | ||
const body = await request.json(); | ||
const res = await ipfsClient.add(JSON.stringify(body)); | ||
return Response.json(res); | ||
} catch (error) { | ||
console.log("Error adding to ipfs", error); | ||
return Response.json({ error: "Error adding to ipfs" }); | ||
} | ||
} |
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,12 @@ | ||
import { getNFTMetadataFromIPFS } from "~~/utils/simpleNFT/ipfs"; | ||
|
||
export async function POST(request: Request) { | ||
try { | ||
const { ipfsHash } = await request.json(); | ||
const res = await getNFTMetadataFromIPFS(ipfsHash); | ||
return Response.json(res); | ||
} catch (error) { | ||
console.log("Error getting metadata from ipfs", error); | ||
return Response.json({ error: "Error getting metadata from ipfs" }); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,84 @@ | ||
"use client"; | ||
|
||
import { lazy, useEffect, useState } from "react"; | ||
import type { NextPage } from "next"; | ||
import { notification } from "~~/utils/scaffold-stark/notification"; | ||
import { getMetadataFromIPFS } from "~~/utils/simpleNFT/ipfs-fetch"; | ||
|
||
const LazyReactJson = lazy(() => import("react-json-view")); | ||
|
||
const IpfsDownload: NextPage = () => { | ||
const [yourJSON, setYourJSON] = useState({}); | ||
const [ipfsPath, setIpfsPath] = useState(""); | ||
const [loading, setLoading] = useState(false); | ||
const [mounted, setMounted] = useState(false); | ||
useEffect(() => { | ||
setMounted(true); | ||
}, []); | ||
|
||
const handleIpfsDownload = async () => { | ||
setLoading(true); | ||
const notificationId = notification.loading("Getting data from IPFS"); | ||
try { | ||
const metaData = await getMetadataFromIPFS(ipfsPath); | ||
notification.remove(notificationId); | ||
notification.success("Downloaded from IPFS"); | ||
|
||
setYourJSON(metaData); | ||
} catch (error) { | ||
notification.remove(notificationId); | ||
notification.error("Error downloading from IPFS"); | ||
console.log(error); | ||
} finally { | ||
setLoading(false); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
<div className="flex items-center flex-col flex-grow pt-10"> | ||
<h1 className="text-center mb-4"> | ||
<span className="block text-4xl font-bold">Download from IPFS</span> | ||
</h1> | ||
<div | ||
className={`flex border-2 border-accent/95 bg-base-200 rounded-full text-accent w-96`} | ||
> | ||
<input | ||
className="input input-ghost focus:outline-none focus:bg-transparent focus:text-secondary-content h-[2.2rem] min-h-[2.2rem] px-4 border w-full font-medium placeholder:text-accent/50 text-secondary-content/75" | ||
placeholder="IPFS CID" | ||
value={ipfsPath} | ||
onChange={(e) => setIpfsPath(e.target.value)} | ||
autoComplete="off" | ||
/> | ||
</div> | ||
<button | ||
className={`btn btn-secondary text-white my-6 ${loading ? "loading" : ""}`} | ||
disabled={loading} | ||
onClick={handleIpfsDownload} | ||
> | ||
Download from IPFS | ||
</button> | ||
|
||
{mounted && ( | ||
<LazyReactJson | ||
style={{ padding: "1rem", borderRadius: "0.75rem" }} | ||
src={yourJSON} | ||
theme="solarized" | ||
enableClipboard={false} | ||
onEdit={(edit) => { | ||
setYourJSON(edit.updated_src); | ||
}} | ||
onAdd={(add) => { | ||
setYourJSON(add.updated_src); | ||
}} | ||
onDelete={(del) => { | ||
setYourJSON(del.updated_src); | ||
}} | ||
/> | ||
)} | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
export default IpfsDownload; |
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,85 @@ | ||
"use client"; | ||
|
||
import { lazy, useEffect, useState } from "react"; | ||
import type { NextPage } from "next"; | ||
import { notification } from "~~/utils/scaffold-stark/notification"; | ||
import { addToIPFS } from "~~/utils/simpleNFT/ipfs-fetch"; | ||
import nftsMetadata from "~~/utils/simpleNFT/nftsMetadata"; | ||
|
||
const LazyReactJson = lazy(() => import("react-json-view")); | ||
|
||
const IpfsUpload: NextPage = () => { | ||
const [yourJSON, setYourJSON] = useState<object>(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 ( | ||
<> | ||
<div className="flex items-center flex-col flex-grow pt-10"> | ||
<h1 className="text-center mb-4"> | ||
<span className="block text-4xl font-bold">Upload to IPFS</span> | ||
</h1> | ||
|
||
{mounted && ( | ||
<LazyReactJson | ||
style={{ padding: "1rem", borderRadius: "0.75rem" }} | ||
src={yourJSON} | ||
theme="solarized" | ||
enableClipboard={false} | ||
onEdit={(edit) => { | ||
setYourJSON(edit.updated_src); | ||
}} | ||
onAdd={(add) => { | ||
setYourJSON(add.updated_src); | ||
}} | ||
onDelete={(del) => { | ||
setYourJSON(del.updated_src); | ||
}} | ||
/> | ||
)} | ||
<button | ||
className={`btn btn-secondary text-white my-4 ${loading ? "loading" : ""}`} | ||
disabled={loading} | ||
onClick={handleIpfsUpload} | ||
> | ||
Upload to IPFS | ||
</button> | ||
{uploadedIpfsPath && ( | ||
<div className="mt-4"> | ||
<a | ||
href={`https://ipfs.io/ipfs/${uploadedIpfsPath}`} | ||
target="_blank" | ||
rel="noreferrer" | ||
> | ||
{`https://ipfs.io/ipfs/${uploadedIpfsPath}`} | ||
</a> | ||
</div> | ||
)} | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
export default IpfsUpload; |
Oops, something went wrong.