Skip to content

Commit

Permalink
Merge pull request #78 from cardano2vn/feat/mint
Browse files Browse the repository at this point in the history
Feat/mint
  • Loading branch information
tidvn authored Nov 9, 2024
2 parents 8072807 + 6b09ab5 commit b3c2d7d
Show file tree
Hide file tree
Showing 14 changed files with 429 additions and 103 deletions.
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"dependencies": {
"@blockfrost/blockfrost-js": "^5.7.0",
"@hookform/resolvers": "^3.9.1",
"@meshsdk/core": "^1.7.12",
"@meshsdk/react": "^1.7.12",
"@meshsdk/core": "^1.7.13",
"@meshsdk/react": "^1.7.13",
"@prisma/client": "^5.22.0",
"@radix-ui/react-alert-dialog": "^1.1.2",
"@radix-ui/react-aspect-ratio": "^1.1.0",
Expand All @@ -27,6 +27,7 @@
"@radix-ui/react-dropdown-menu": "^2.1.2",
"@radix-ui/react-label": "^2.1.0",
"@radix-ui/react-popover": "^1.1.2",
"@radix-ui/react-radio-group": "^1.2.1",
"@radix-ui/react-progress": "^1.1.0",
"@radix-ui/react-scroll-area": "^1.2.0",
"@radix-ui/react-select": "^2.1.2",
Expand All @@ -37,7 +38,7 @@
"@radix-ui/react-toast": "^1.2.2",
"@radix-ui/react-tooltip": "^1.1.3",
"@stepperize/react": "^3.1.1",
"@tanstack/react-query": "^5.59.19",
"@tanstack/react-query": "^5.59.20",
"axios": "^1.7.7",
"buffer": "^6.0.3",
"cbor": "^9.0.2",
Expand All @@ -48,15 +49,15 @@
"framer-motion": "^11.11.11",
"lodash": "^4.17.21",
"lucide-react": "^0.447.0",
"next": "^15.0.2",
"next": "^15.0.3",
"next-auth": "^5.0.0-beta.25",
"prism-react-renderer": "^2.4.0",
"react": "^19.0.0-rc-fb9a90fa48-20240614",
"react-copy-to-clipboard": "^5.1.0",
"react-countup": "^6.5.3",
"react-day-picker": "8.10.1",
"react-dom": "^19.0.0-rc-fb9a90fa48-20240614",
"react-hook-form": "^7.53.1",
"react-hook-form": "^7.53.2",
"react-icons": "^5.3.0",
"react-papaparse": "^4.4.0",
"react-simple-typewriter": "^5.0.1",
Expand All @@ -74,7 +75,7 @@
"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.14.0",
"@jest/globals": "^29.7.0",
"@tanstack/eslint-plugin-query": "^5.59.7",
"@tanstack/eslint-plugin-query": "^5.60.1",
"@types/crypto-js": "^4.2.2",
"@types/dotenv": "^6.1.1",
"@types/jest": "^29.5.14",
Expand Down
144 changes: 144 additions & 0 deletions src/app/(app)/dashboard/mint/one/_components/_mint-step/basic.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
"use client";

import { zodResolver } from "@hookform/resolvers/zod";
import { useForm } from "react-hook-form";
import * as z from "zod";

import { Button } from "@/components/ui/button";
import {
Form,
FormControl,
FormField,
FormItem,
FormLabel,
FormMessage,
} from "@/components/ui/form";
import { Input } from "@/components/ui/input";

import { useMintOneContext } from "../../_context";
import { toast } from "@/hooks/use-toast";

const nftFormSchema = z.object({
assetName: z
.string()
.min(6, {
message: "Name must be at least 6 characters.",
})
.max(30, {
message: "Name must not be longer than 30 characters.",
}),
assetQuantity: z.string().refine(
(val) => {
const parsedValue = parseInt(val, 10);
return !Number.isNaN(parsedValue) && parsedValue > 0;
},
{
message: "Invalid value",
},
),
});

type NftFormValues = z.infer<typeof nftFormSchema>;

export default function BasicStep() {
const { stepper, basicInfoToMint, setBasicInfoToMint } = useMintOneContext();

const defaultValues: Partial<NftFormValues> = {
assetQuantity: basicInfoToMint.quantity,
assetName: basicInfoToMint.assetName,
};

const form = useForm<NftFormValues>({
resolver: zodResolver(nftFormSchema),
defaultValues,
mode: "onChange",
});

async function onSubmit(data: NftFormValues) {
try {
if (!(parseInt(data.assetQuantity || "0", 10) > 0)) {
throw new Error("Invalid quantity");
}
if (data.assetName.length < 2) {
throw new Error("Name must be at least 2 characters.");
}
setBasicInfoToMint({
assetName: data.assetName,
quantity: data.assetQuantity,
});
stepper.next();
} catch (e) {
toast({
title: "Error",
description: e instanceof Error ? e.message : "unknown error",
variant: "destructive",
});
}
}

return (
<Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)}>
<div className="h-full py-8 px-10 m-auto flex flex-col">
<div className="rounded-md border border-dashed">
<div className="space-y-8">
<div className="relative flex-col items-center justify-center">
<div className="lg:p-8">
<div className="mx-auto flex w-full flex-col space-y-6">
<div className="flex flex-col space-y-2 text-left">
<h1 className="text-2xl font-semibold tracking-tight">
Basic Information
</h1>
</div>
<div className="h-full space-y-6">
<div className="h-[29rem] border-none p-0 outline-none gap-2">
<FormField
control={form.control}
name="assetName"
render={({ field }) => (
<FormItem>
<FormLabel>Asset Name</FormLabel>
<FormControl>
<Input placeholder="Enter a Name" {...field} />
</FormControl>

<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="assetQuantity"
render={({ field }) => (
<FormItem>
<FormLabel>Asset Quantity</FormLabel>
<FormControl>
<Input type="number" {...field} />
</FormControl>

<FormMessage />
</FormItem>
)}
/>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div className="flex justify-end gap-4 mt-6">
<Button
variant="secondary"
onClick={stepper.prev}
disabled={stepper.isFirst}
>
Back
</Button>
<Button type="submit">Next</Button>
</div>
</div>
</form>
</Form>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useJsonBuilderStore } from "@/components/common/json-builder/store";
import { Button } from "@/components/ui/button";
import { isEmpty, isNil } from "lodash";

export default function MetadataPage() {
export default function MetadataStep() {
const { stepper, setMetadataToMint } = useMintOneContext();
const { jsonContent } = useJsonBuilderStore();
const handleNext = () => {
Expand All @@ -14,9 +14,11 @@ export default function MetadataPage() {
}
};
return (
<div>
<JsonBuilder />
<div className="flex justify-end gap-4">
<div className="h-full py-8 px-10 m-auto flex flex-col">
<div className="rounded-md border border-dashed">
<JsonBuilder />
</div>
<div className="flex justify-end gap-4 mt-6">
<Button
variant="secondary"
onClick={stepper.prev}
Expand Down
Loading

0 comments on commit b3c2d7d

Please sign in to comment.