diff --git a/packages/web-app/components/agreementCreate/AgreementCreationPreview.tsx b/packages/web-app/components/agreementCreate/AgreementCreationPreview.tsx index 631f0c3f..a13d22b3 100644 --- a/packages/web-app/components/agreementCreate/AgreementCreationPreview.tsx +++ b/packages/web-app/components/agreementCreate/AgreementCreationPreview.tsx @@ -73,6 +73,7 @@ export const AgreementCreationPreview: React.FC = const { put } = await preparePutToIPFS(metadata); const cid = await put(); + console.log(cid); const metadataURI = `ipfs://${cid}`; create({ diff --git a/packages/web-app/components/dispute/ResolutionForm.tsx b/packages/web-app/components/dispute/ResolutionForm.tsx index 206d1b07..017aa08f 100644 --- a/packages/web-app/components/dispute/ResolutionForm.tsx +++ b/packages/web-app/components/dispute/ResolutionForm.tsx @@ -33,7 +33,8 @@ export const ResolutionForm = () => { const submit = async () => { const metadata = generateResolutionMetadata(settlement ?? []); - const { put, cid } = await preparePutToIPFS(metadata); + const { put } = await preparePutToIPFS(metadata); + const cid = await put(); const metadataURI = `ipfs://${cid}`; const data = arbitratorInterface.encodeFunctionData("submitResolution", [ diff --git a/packages/web-app/components/layout/Layout.tsx b/packages/web-app/components/layout/Layout.tsx index 5a2a1ae6..11d957f2 100644 --- a/packages/web-app/components/layout/Layout.tsx +++ b/packages/web-app/components/layout/Layout.tsx @@ -1,6 +1,6 @@ import React, { ReactNode } from "react"; import { TopBar } from "./TopBar"; -import { Footer } from "@nation3/ui-components" +import { Footer } from "@nation3/ui-components"; export interface LayoutProps { children: ReactNode; diff --git a/packages/web-app/components/layout/TopBar.tsx b/packages/web-app/components/layout/TopBar.tsx index d2b2363b..0986052d 100644 --- a/packages/web-app/components/layout/TopBar.tsx +++ b/packages/web-app/components/layout/TopBar.tsx @@ -68,4 +68,4 @@ export const TopBar = () => { ); -}; \ No newline at end of file +}; diff --git a/packages/web-app/lib/ipfs.tsx b/packages/web-app/lib/ipfs.tsx index 776a2ca5..61df6a0e 100644 --- a/packages/web-app/lib/ipfs.tsx +++ b/packages/web-app/lib/ipfs.tsx @@ -1,43 +1,16 @@ -import { Web3Storage } from "web3.storage"; -import { pack } from "ipfs-car/pack"; -import { CarReader } from "@ipld/car"; - +import { NFTStorage, Blob } from "nft.storage"; const ipfsGateway = "https://w3s.link/ipfs"; - export const IPFSUriToUrl = (uri: string) => { return `${ipfsGateway}/${uri.split("ipfs://").pop()}`; }; - -export const client = () => { - const token = process.env.IPFS_API_TOKEN || process.env.NEXT_PUBLIC_IPFS_API_TOKEN; - if (!token) { - throw new Error("IPFS API token not found"); - } - return new Web3Storage({ token }); -}; - -const objectToFile = (obj: object, filename: string) => { - const blob = new Blob([JSON.stringify(obj)], { type: "application/json" }); - - return new File([blob], filename); -}; - -const stringToFile = (str: string, filename: string) => { - return new File([Buffer.from(str)], filename); -}; +const client = new NFTStorage({ + token: process.env.NEXT_PUBLIC_NFTSTORAGE_KEY || "", +}); export const preparePutToIPFS = async (data: string | object, filename?: string) => { - const file = - typeof data === "string" - ? stringToFile(data, filename || "file.md") - : objectToFile(data, "data.json"); - const { root, out } = await pack({ input: [file], wrapWithDirectory: false }); - const cid = root.toString(); - + const d = new Blob([JSON.stringify(data)]); const put = async () => { - const car = await CarReader.fromIterable(out); - return client().putCar(car); + return await client.storeBlob(d); }; - - return { cid, put }; + return { put }; }; diff --git a/packages/web-app/package.json b/packages/web-app/package.json index a067254c..f9520c0b 100644 --- a/packages/web-app/package.json +++ b/packages/web-app/package.json @@ -49,7 +49,8 @@ "sharp": "^0.31.3", "tippy.js": "^6.3.7", "wagmi": "^0.6.7", - "web3.storage": "^4.4.0" + "web3.storage": "^4.4.0", + "nft.storage": "^6.3.0" }, "devDependencies": { "@types/crypto-js": "^4.1.1", diff --git a/yarn.lock b/yarn.lock index 351e956c..74ab47ba 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1852,7 +1852,7 @@ multiformats "^9.5.4" varint "^6.0.0" -"@ipld/dag-cbor@^6.0.3": +"@ipld/dag-cbor@^6.0.13", "@ipld/dag-cbor@^6.0.3": version "6.0.15" resolved "https://registry.yarnpkg.com/@ipld/dag-cbor/-/dag-cbor-6.0.15.tgz#aebe7a26c391cae98c32faedb681b1519e3d2372" integrity sha512-Vm3VTSTwlmGV92a3C5aeY+r2A18zbH2amehNhsX8PBa3muXICaWrN8Uri85A5hLH7D7ElhE8PdjxD6kNqUmTZA== @@ -4828,6 +4828,13 @@ data-uri-to-buffer "^3.0.1" mrmime "^1.0.0" +"@web-std/file@^3.0.0": + version "3.0.3" + resolved "https://registry.yarnpkg.com/@web-std/file/-/file-3.0.3.tgz#a29b9164d34155a126d1ab2af5e5867e83c8b098" + integrity sha512-X7YYyvEERBbaDfJeC9lBKC5Q5lIEWYCP1SNftJNwNH/VbFhdHm+3neKOQP+kWEYJmosbDFq+NEUG7+XIvet/Jw== + dependencies: + "@web-std/blob" "^3.0.3" + "@web-std/file@^3.0.2": version "3.0.2" resolved "https://registry.yarnpkg.com/@web-std/file/-/file-3.0.2.tgz#b84cc9ed754608b18dcf78ac62c40dbcc6a94692" @@ -4835,6 +4842,13 @@ dependencies: "@web-std/blob" "^3.0.3" +"@web-std/form-data@^3.0.0": + version "3.1.0" + resolved "https://registry.yarnpkg.com/@web-std/form-data/-/form-data-3.1.0.tgz#573b40f6296e8bdba31f1bbf2db398f104ef4831" + integrity sha512-WkOrB8rnc2hEK2iVhDl9TFiPMptmxJA1HaIzSdc2/qk3XS4Ny4cCt6/V36U3XmoYKz0Md2YyK2uOZecoZWPAcA== + dependencies: + web-encoding "1.1.5" + "@web-std/form-data@^3.0.2": version "3.0.2" resolved "https://registry.yarnpkg.com/@web-std/form-data/-/form-data-3.0.2.tgz#c71d9def6a593138ea92fe3d1ffbce19f43e869c" @@ -10955,6 +10969,33 @@ ipaddr.js@1.9.1: resolved "https://registry.yarnpkg.com/ipaddr.js/-/ipaddr.js-1.9.1.tgz#bff38543eeb8984825079ff3a2a8e6cbd46781b3" integrity sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g== +ipfs-car@^0.6.2: + version "0.6.2" + resolved "https://registry.yarnpkg.com/ipfs-car/-/ipfs-car-0.6.2.tgz#ec645cebe29056344abb3545e4e2e99788a4405c" + integrity sha512-tliuakkKKtCa4TTnFT3zJKjq/aD8EGKX8Y0ybCyrAW0fo/n2koZpxiLjBvtTs47Rqyji6ggXo+atPbJJ60hJmg== + dependencies: + "@ipld/car" "^3.2.3" + "@web-std/blob" "^3.0.1" + bl "^5.0.0" + blockstore-core "^1.0.2" + browser-readablestream-to-it "^1.0.2" + idb-keyval "^6.0.3" + interface-blockstore "^2.0.2" + ipfs-core-types "^0.8.3" + ipfs-core-utils "^0.12.1" + ipfs-unixfs-exporter "^7.0.4" + ipfs-unixfs-importer "^9.0.4" + ipfs-utils "^9.0.2" + it-all "^1.0.5" + it-last "^1.0.5" + it-pipe "^1.1.0" + meow "^9.0.0" + move-file "^2.1.0" + multiformats "^9.6.3" + stream-to-it "^0.2.3" + streaming-iterables "^6.0.0" + uint8arrays "^3.0.0" + ipfs-car@^0.7.0: version "0.7.0" resolved "https://registry.yarnpkg.com/ipfs-car/-/ipfs-car-0.7.0.tgz#72955d2b6904e87edfa17bbe5c00c1b3fcb79bb9" @@ -13532,7 +13573,7 @@ multiaddr@^10.0.0: uint8arrays "^3.0.0" varint "^6.0.0" -multiformats@^9.0.4, multiformats@^9.4.13, multiformats@^9.4.2, multiformats@^9.4.5, multiformats@^9.4.7, multiformats@^9.5.4, multiformats@^9.6.3: +multiformats@^9.0.4, multiformats@^9.4.13, multiformats@^9.4.2, multiformats@^9.4.5, multiformats@^9.4.7, multiformats@^9.5.4, multiformats@^9.6.3, multiformats@^9.6.4: version "9.9.0" resolved "https://registry.yarnpkg.com/multiformats/-/multiformats-9.9.0.tgz#c68354e7d21037a8f1f8833c8ccd68618e8f1d37" integrity sha512-HoMUjhH9T8DDBNT+6xzkrd9ga/XiBI4xLr58LJACwK6G3HTOPeMz4nB4KJs33L2BelrIJa7P0VuNaVF3hMYfjg== @@ -13668,6 +13709,25 @@ next@latest: "@next/swc-win32-ia32-msvc" "13.3.4" "@next/swc-win32-x64-msvc" "13.3.4" +nft.storage@^6.3.0: + version "6.4.1" + resolved "https://registry.yarnpkg.com/nft.storage/-/nft.storage-6.4.1.tgz#262faa3ba67970cbdd48480aa048d96671c6ccb4" + integrity sha512-UwZ+QgDCr58X+vHN4BydqdB89M8Vaza+vkWR9RatC3rXuDfIyYE5T7oOV53tbiuhA8x5Yi56tlG3NI8wLfOO1A== + dependencies: + "@ipld/car" "^3.2.3" + "@ipld/dag-cbor" "^6.0.13" + "@web-std/blob" "^3.0.1" + "@web-std/fetch" "^3.0.3" + "@web-std/file" "^3.0.0" + "@web-std/form-data" "^3.0.0" + carbites "^1.0.6" + ipfs-car "^0.6.2" + it-pipe "^1.1.0" + multiformats "^9.6.4" + p-retry "^4.6.1" + streaming-iterables "^6.0.0" + throttled-queue "^2.1.2" + nice-try@^1.0.4: version "1.0.5" resolved "https://registry.yarnpkg.com/nice-try/-/nice-try-1.0.5.tgz#a3378a7696ce7d223e88fc9b764bd7ef1089e366" @@ -14253,7 +14313,7 @@ p-queue@^6.6.2: eventemitter3 "^4.0.4" p-timeout "^3.2.0" -p-retry@^4.5.0: +p-retry@^4.5.0, p-retry@^4.6.1: version "4.6.2" resolved "https://registry.npmjs.org/p-retry/-/p-retry-4.6.2.tgz" integrity sha512-312Id396EbJdvRONlngUx0NydfrIQ5lsYu0znKVUzVvArzEIt08V1qhtyESbGVd1FGX7UKtiFp5uwKZdM8wIuQ==