Skip to content

Commit

Permalink
WIP: fix mint function
Browse files Browse the repository at this point in the history
  • Loading branch information
PerminovEugene committed Oct 16, 2024
1 parent d994d27 commit 4d99ffe
Show file tree
Hide file tree
Showing 11 changed files with 350 additions and 253 deletions.
3 changes: 1 addition & 2 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"dependencies": {
"@metamask/sdk-react": "^0.26.5",
"@nft-open-marketplace/interface": "^0.1.3",
"@nft-open-marketplace/interface": "^0.2.0",
"ethers": "^6.13.1",
"next": "14.2.4",
"react": "^18",
Expand All @@ -19,7 +19,6 @@
"react-icons": "^5.3.0"
},
"devDependencies": {
"@nft-open-marketplace/interface": "^0.2.0",
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
Expand Down
13 changes: 8 additions & 5 deletions packages/ui/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import "./globals.css";
import Header from "@/components/header/header.component";
import Footer from "@/components/footer/footer.component";
import MetaMaskProviderWrapper from "@/providers/metamask.provider";
import { EthereumProvider } from "@/providers/etherium.provider";

const inter = Inter({ subsets: ["latin"] });

Expand All @@ -20,11 +21,13 @@ export default function RootLayout({
return (
<html lang="en">
<MetaMaskProviderWrapper>
<body className={inter.className}>
<Header />
{children}
<Footer />
</body>
<EthereumProvider>
<body className={inter.className}>
<Header />
{children}
<Footer />
</body>
</EthereumProvider>
</MetaMaskProviderWrapper>
</html>
);
Expand Down
41 changes: 17 additions & 24 deletions packages/ui/src/app/mint/hooks/use-handle-submit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { mint } from "@/components/etherium/nft/mint";
import { useRef, useState } from "react";
import { MintFormValues } from "../page";

type UploadParams = {
type PinFileBody = {
file: File;
data: {
name: string;
Expand All @@ -18,26 +18,17 @@ type UploadParams = {
};
};

async function uploadFile({
file,
data,
}: // name,
// description,
// externalUrl,
// backgroundColor,
// animationUrl,
// youtubeUrl,
// attributes,
UploadParams) {
type PinFileResponse = {
IpfsHash: string;
PinSize: number;
Timestamp: string;
isDuplicate: boolean;
};

async function uploadFile({ file, data }: PinFileBody) {
const formData = new FormData();
formData.append("file", file);
formData.append("data", JSON.stringify(data));
// formData.append("description", description);
// externalUrl && formData.append("externalUrl", externalUrl);
// backgroundColor && formData.append("backgroundColor", backgroundColor);
// animationUrl && formData.append("animationUrl", animationUrl);
// youtubeUrl && formData.append("youtubeUrl", youtubeUrl);
// attributes && formData.append("attributes", JSON.stringify(attributes));

try {
const response = await fetch("http://localhost:8080/ipfs/upload", {
Expand All @@ -46,15 +37,14 @@ UploadParams) {
});

if (response.ok) {
const data = await response.json();
alert("IPFS Pinning successfull");
const data: PinFileResponse = await response.json();
return data;
} else {
alert("IPFS pinning error");
throw new Error("Ipfs pinning error", { cause: response });
}
} catch (error) {
alert("NETWORK ERROR");
console.error("Сетевая ошибка:", error);
alert("Ipfs pinning network error");
throw new Error("Ipfs pinning network error", { cause: error });
}
}

Expand Down Expand Up @@ -89,9 +79,12 @@ export const useHandleSubmit = () => {
},
});
try {
await mint(uploadResult.tokenURI);
console.log("mint");
await mint(uploadResult?.IpfsHash);
} catch (error: unknown) {
console.log(error);
await deleteFile();
throw new Error("Mint error", { cause: error });
}
};

Expand Down
Loading

0 comments on commit 4d99ffe

Please sign in to comment.