Skip to content

[TOOL-4972] Dashboard: Add field to configure admins in NFT asset creation #7542

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion apps/dashboard/src/@/analytics/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,11 @@ export function reportAssetCreationFailed(
properties: { contractType: AssetContractType; error: string } & (
| {
assetType: "nft";
step: "deploy-contract" | "mint-nfts" | "set-claim-conditions";
step:
| "deploy-contract"
| "mint-nfts"
| "set-claim-conditions"
| "set-admins";
}
| {
assetType: "coin";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function SocialUrlsFieldset<T extends WithSocialUrls>(props: {
<h2 className="mb-2 font-medium text-sm">Social URLs</h2>

{fields.length > 0 && (
<div className="mb-5 space-y-4">
<div className="mb-4 space-y-3">
{fields.map((field, index) => (
<div
className="flex gap-3 max-sm:mb-6 max-sm:border-b max-sm:border-dashed max-sm:pb-6"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
"use client";

import { PlusIcon, Trash2Icon } from "lucide-react";
import { type UseFormReturn, useFieldArray } from "react-hook-form";
import { useActiveAccount } from "thirdweb/react";
import { Button } from "@/components/ui/button";
import {
FormControl,
FormField,
FormItem,
FormMessage,
} from "@/components/ui/form";
import { Input } from "@/components/ui/input";

type WithAdmins = {
admins: {
address: string;
}[];
};

export function AdminAddressesFieldset<T extends WithAdmins>(props: {
form: UseFormReturn<T>;
}) {
// T contains all properties of WithAdmins, so this is ok
const form = props.form as unknown as UseFormReturn<WithAdmins>;
const account = useActiveAccount();

const { fields, append, remove } = useFieldArray({
control: form.control,
name: "admins",
});

const handleAddAddress = () => {
append({ address: "" });
};

const handleRemoveAddress = (index: number) => {
const field = fields[index];
if (field?.address === account?.address) {
return; // Don't allow removing the connected address
}
remove(index);
};

return (
<div className="border-t border-dashed px-4 py-6 lg:px-6">
<div className="mb-3">
<h2 className="mb-1 font-medium text-sm">Admins</h2>
<p className="text-sm text-muted-foreground">
These wallets will have authority on the token
</p>
</div>

{fields.length > 0 && (
<div className="mb-4 space-y-3">
{fields.map((field, index) => (
<div
className="flex gap-3 max-sm:mb-6 max-sm:border-b max-sm:border-dashed max-sm:pb-6"
key={field.id}
>
<div className="flex flex-1 flex-col gap-3 lg:flex-row">
<FormField
control={form.control}
name={`admins.${index}.address`}
render={({ field }) => (
<FormItem className="flex-1">
<FormControl>
<Input
{...field}
aria-label="Admin Address"
disabled={field.value === account?.address}
placeholder="0x..."
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
</div>

<Button
className="rounded-full"
disabled={field.address === account?.address}
onClick={() => handleRemoveAddress(index)}
size="icon"
type="button"
variant="outline"
>
<Trash2Icon className="h-4 w-4" />
<span className="sr-only">Remove</span>
</Button>
</div>
))}
</div>
)}

<Button
className="h-auto gap-1.5 rounded-full px-3 py-1.5 text-xs"
onClick={handleAddAddress}
size="sm"
type="button"
variant="outline"
>
<PlusIcon className="size-3.5" />
Add Admin
</Button>

{form.watch("admins").length === 0 && (
<p className="text-sm text-destructive mt-2">
At least one admin address is required
</p>
)}
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@ export const socialUrlsSchema = z.array(
}),
);

export const addressArraySchema = z.array(
z.object({
address: z.string().refine(
(value) => {
if (isAddress(value)) {
return true;
}
return false;
},
{
message: "Invalid address",
},
),
}),
);

export const addressSchema = z.string().refine(
(value) => {
if (isAddress(value)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { isAddress } from "thirdweb";
import * as z from "zod";
import { socialUrlsSchema } from "../../_common/schema";
import {
addressArraySchema,
addressSchema,
socialUrlsSchema,
} from "../../_common/schema";
import type { NFTMetadataWithPrice } from "../upload-nfts/batch-upload/process-files";

export const nftCollectionInfoFormSchema = z.object({
admins: addressArraySchema.refine((addresses) => addresses.length > 0, {
message: "At least one admin is required",
}),
chain: z.string().min(1, "Chain is required"),
description: z.string().optional(),
image: z.instanceof(File).optional(),
Expand All @@ -12,14 +18,6 @@ export const nftCollectionInfoFormSchema = z.object({
symbol: z.string(),
});

const addressSchema = z.string().refine((value) => {
if (isAddress(value)) {
return true;
}

return false;
});

export const nftSalesSettingsFormSchema = z.object({
primarySaleRecipient: addressSchema,
royaltyBps: z.coerce.number().min(0).max(10000),
Expand All @@ -37,6 +35,14 @@ export type CreateNFTCollectionAllValues = {
};

export type CreateNFTCollectionFunctions = {
setAdmins: (values: {
contractAddress: string;
contractType: "DropERC721" | "DropERC1155";
admins: {
address: string;
}[];
chain: string;
}) => Promise<void>;
erc721: {
deployContract: (values: CreateNFTCollectionAllValues) => Promise<{
contractAddress: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { SingleNetworkSelector } from "@/components/blocks/NetworkSelectors";
import { Form } from "@/components/ui/form";
import { Input } from "@/components/ui/input";
import { Textarea } from "@/components/ui/textarea";
import { AdminAddressesFieldset } from "../../_common/admin-addresses-fieldset";
import { SocialUrlsFieldset } from "../../_common/SocialUrls";
import { StepCard } from "../../_common/step-card";
import type { NFTCollectionInfoFormValues } from "../_common/form";
Expand Down Expand Up @@ -126,6 +127,8 @@ export function NFTCollectionInfoFieldset(props: {
</div>

<SocialUrlsFieldset form={form} />

<AdminAddressesFieldset form={form} />
</StepCard>
</form>
</Form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
NATIVE_TOKEN_ADDRESS,
type ThirdwebClient,
} from "thirdweb";
import { useActiveAccount } from "thirdweb/react";
import { useActiveAccount, useActiveWalletChain } from "thirdweb/react";
import { reportAssetCreationStepConfigured } from "@/analytics/report";
import type { Team } from "@/api/team";
import {
Expand Down Expand Up @@ -163,11 +163,16 @@ export function CreateNFTPageUI(props: {
}

function useNFTCollectionInfoForm() {
const chain = useActiveWalletChain();
const account = useActiveAccount();
return useForm<NFTCollectionInfoFormValues>({
resolver: zodResolver(nftCollectionInfoFormSchema),
reValidateMode: "onChange",
values: {
chain: "1",
defaultValues: {
admins: [
{
address: account?.address || "",
},
],
chain: chain?.id.toString() || "1",
description: "",
image: undefined,
name: "",
Expand All @@ -183,5 +188,7 @@ function useNFTCollectionInfoForm() {
],
symbol: "",
},
resolver: zodResolver(nftCollectionInfoFormSchema),
reValidateMode: "onChange",
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
lazyMint as lazyMint1155,
setClaimConditions as setClaimConditions1155,
} from "thirdweb/extensions/erc1155";
import { grantRole } from "thirdweb/extensions/permissions";
import { useActiveAccount } from "thirdweb/react";
import { maxUint256 } from "thirdweb/utils";
import { revalidatePathAction } from "@/actions/revalidate";
Expand Down Expand Up @@ -332,6 +333,60 @@ export function CreateNFTPage(props: {
}
}

async function handleSetAdmins(params: {
contractAddress: string;
contractType: "DropERC721" | "DropERC1155";
admins: {
address: string;
}[];
chain: string;
}) {
const { contract, activeAccount } = getContractAndAccount({
chain: params.chain,
});

// remove the current account from the list - its already an admin, don't have to add it again
const adminsToAdd = params.admins.filter(
(admin) => admin.address !== activeAccount.address,
);

const encodedTxs = await Promise.all(
adminsToAdd.map((admin) => {
const tx = grantRole({
contract,
role: "admin",
targetAccountAddress: admin.address,
});

return encode(tx);
}),
);

const tx = multicall({
contract,
data: encodedTxs,
});

try {
await sendAndConfirmTransaction({
account: activeAccount,
transaction: tx,
});
} catch (e) {
const errorMessage = parseError(e);
console.error(errorMessage);

reportAssetCreationFailed({
assetType: "nft",
contractType: params.contractType,
error: errorMessage,
step: "set-admins",
});

throw e;
}
}

return (
<CreateNFTPageUI
{...props}
Expand All @@ -349,7 +404,6 @@ export function CreateNFTPage(props: {
formValues,
});
},

setClaimConditions: async (formValues) => {
return handleSetClaimConditionsERC721({
formValues,
Expand All @@ -373,6 +427,7 @@ export function CreateNFTPage(props: {
return handleSetClaimConditionsERC1155(params);
},
},
setAdmins: handleSetAdmins,
}}
onLaunchSuccess={() => {
revalidatePathAction(
Expand Down
Loading
Loading