Skip to content

Commit bea430c

Browse files
committed
implemented functionality of Claimable
1 parent 0269675 commit bea430c

File tree

3 files changed

+566
-21
lines changed

3 files changed

+566
-21
lines changed

apps/dashboard/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"private": true,
55
"scripts": {
66
"preinstall": "npx only-allow pnpm",
7-
"dev": "next dev --turbo",
7+
"dev": "next dev",
88
"build": "next build",
99
"start": "next start",
1010
"format": "biome format ./src --write",

apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/modules/components/Mintable.tsx

Lines changed: 50 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
} from "@/components/ui/accordion";
99
import { Alert, AlertTitle } from "@/components/ui/alert";
1010
import { Button } from "@/components/ui/button";
11+
import { Checkbox, CheckboxWithLabel } from "@/components/ui/checkbox";
1112
import {
1213
Form,
1314
FormControl,
@@ -28,7 +29,7 @@ import { CircleAlertIcon } from "lucide-react";
2829
import { useCallback } from "react";
2930
import { useForm } from "react-hook-form";
3031
import { toast } from "sonner";
31-
import { sendAndConfirmTransaction } from "thirdweb";
32+
import { PreparedTransaction, sendAndConfirmTransaction } from "thirdweb";
3233
import { isAddress } from "thirdweb";
3334
import { MintableERC721, MintableERC1155 } from "thirdweb/modules";
3435
import { useReadContract } from "thirdweb/react";
@@ -46,7 +47,8 @@ export type UpdateFormValues = {
4647

4748
// TODO - add form validation with zod schema for mint form
4849

49-
export type MintFormValues = NFTMetadataInputLimited & {
50+
export type MintFormValues = NFTMetadat||aInputLimited & {
51+
useNextTokenId: boolean;
5052
recipient: string;
5153
amount: number;
5254
supply: number;
@@ -79,20 +81,25 @@ function MintableModule(props: ModuleInstanceProps) {
7981
if (!ownerAccount) {
8082
throw new Error("Not an owner account");
8183
}
82-
83-
const mintTx = isErc721
84-
? MintableERC721.mintWithRole({
84+
85+
let mintTx: PreparedTransaction;
86+
if (isErc721) {
87+
mintTx = MintableERC721.mintWithRole({
8588
contract,
8689
to: values.recipient,
8790
nfts: [nft],
8891
})
89-
: MintableERC1155.mintWithRole({
92+
} else if (values.useNextTokenId || values.tokenId) {
93+
mintTx = MintableERC1155.mintWithRole({
9094
contract,
9195
to: values.recipient,
9296
amount: BigInt(values.amount),
93-
tokenId: values.tokenId ? BigInt(values.tokenId) : undefined,
97+
tokenId: values.useNextTokenId ? undefined : BigInt(values.tokenId),
9498
nft,
9599
});
100+
} else {
101+
throw new Error("Invalid token ID");
102+
}
96103

97104
await sendAndConfirmTransaction({
98105
account: ownerAccount,
@@ -292,6 +299,7 @@ function MintNFTSection(props: {
292299
}) {
293300
const form = useForm<MintFormValues>({
294301
values: {
302+
useNextTokenId: false,
295303
supply: 1,
296304
customImage: "",
297305
customAnimationUrl: "",
@@ -313,6 +321,8 @@ function MintNFTSection(props: {
313321
});
314322
};
315323

324+
const useNextTokenId = form.watch("useNextTokenId");
325+
316326
return (
317327
<Form {...form}>
318328
<form onSubmit={form.handleSubmit(onSubmit)}>
@@ -426,19 +436,39 @@ function MintNFTSection(props: {
426436
/>
427437
)}
428438

429-
{!props.isErc721 && !props.isSequentialTokenIdInstalled && (
430-
<FormField
431-
control={form.control}
432-
name="tokenId"
433-
render={({ field }) => (
434-
<FormItem className="flex-1">
435-
<FormLabel>Token ID</FormLabel>
436-
<FormControl>
437-
<Input {...field} />
438-
</FormControl>
439-
</FormItem>
440-
)}
441-
/>
439+
{!props.isErc721 && (
440+
<div className="relative flex-1">
441+
<FormField
442+
control={form.control}
443+
name="tokenId"
444+
render={({ field }) => (
445+
<FormItem className="flex-1">
446+
<FormLabel>Token ID</FormLabel>
447+
<FormControl>
448+
<Input {...field} disabled={useNextTokenId} />
449+
</FormControl>
450+
</FormItem>
451+
)}
452+
/>
453+
454+
<FormField
455+
control={form.control}
456+
name="useNextTokenId"
457+
render={({ field }) => (
458+
<FormItem className="absolute top-0 right-0 flex items-center gap-2">
459+
<CheckboxWithLabel>
460+
<Checkbox
461+
className="mt-0"
462+
checked={field.value}
463+
onCheckedChange={field.onChange}
464+
/>
465+
Use next token ID
466+
</CheckboxWithLabel>
467+
<FormMessage />
468+
</FormItem>
469+
)}
470+
/>
471+
</div>
442472
)}
443473
</div>
444474

0 commit comments

Comments
 (0)