Skip to content

Commit 32e71c6

Browse files
committed
minor cleanup
1 parent 7fc02a7 commit 32e71c6

File tree

5 files changed

+91
-84
lines changed

5 files changed

+91
-84
lines changed
Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import type { UseFormReturn } from "react-hook-form";
21
import { isAddress } from "thirdweb";
32
import * as z from "zod";
43
import { socialUrlsSchema } from "../../_common/schema";
54
import type { NFTMetadataWithPrice } from "../upload-nfts/batch-upload/process-files";
65

76
export const nftCollectionInfoFormSchema = z.object({
8-
// info fieldset
97
name: z.string().min(1, "Name is required"),
108
symbol: z.string(),
119
chain: z.string().min(1, "Chain is required"),
@@ -14,50 +12,50 @@ export const nftCollectionInfoFormSchema = z.object({
1412
socialUrls: socialUrlsSchema,
1513
});
1614

15+
const addressSchema = z.string().refine((value) => {
16+
if (isAddress(value)) {
17+
return true;
18+
}
19+
20+
return false;
21+
});
22+
23+
export const nftSalesSettingsFormSchema = z.object({
24+
royaltyRecipient: addressSchema,
25+
primarySaleRecipient: addressSchema,
26+
royaltyBps: z.coerce.number().min(0).max(10000),
27+
});
28+
1729
export type NFTCollectionInfoFormValues = z.infer<
1830
typeof nftCollectionInfoFormSchema
1931
>;
20-
export type NFTCollectionInfoForm = UseFormReturn<NFTCollectionInfoFormValues>;
2132

22-
export type CreateNFTFormValues = NFTCollectionInfoFormValues & {
33+
export type CreateNFTCollectionAllValues = {
34+
collectionInfo: NFTCollectionInfoFormValues;
2335
nfts: NFTMetadataWithPrice[];
2436
sales: NFTSalesSettingsFormValues;
2537
};
2638

27-
export type CreateNFTFunctions = {
39+
export type CreateNFTCollectionFunctions = {
2840
erc721: {
29-
deployContract: (values: CreateNFTFormValues) => Promise<{
41+
deployContract: (values: CreateNFTCollectionAllValues) => Promise<{
3042
contractAddress: string;
3143
}>;
32-
setClaimConditions: (values: CreateNFTFormValues) => Promise<void>;
33-
lazyMintNFTs: (values: CreateNFTFormValues) => Promise<void>;
44+
setClaimConditions: (values: CreateNFTCollectionAllValues) => Promise<void>;
45+
lazyMintNFTs: (values: CreateNFTCollectionAllValues) => Promise<void>;
3446
};
3547
erc1155: {
36-
deployContract: (values: CreateNFTFormValues) => Promise<{
48+
deployContract: (values: CreateNFTCollectionAllValues) => Promise<{
3749
contractAddress: string;
3850
}>;
3951
setClaimConditions: (params: {
4052
nftCollectionInfo: NFTCollectionInfoFormValues;
4153
nftBatch: NFTMetadataWithPrice[];
4254
}) => Promise<void>;
43-
lazyMintNFTs: (values: CreateNFTFormValues) => Promise<void>;
55+
lazyMintNFTs: (values: CreateNFTCollectionAllValues) => Promise<void>;
4456
};
4557
};
4658

47-
const addressSchema = z.string().refine((value) => {
48-
if (isAddress(value)) {
49-
return true;
50-
}
51-
52-
return false;
53-
});
54-
55-
export const nftSalesSettingsFormSchema = z.object({
56-
royaltyRecipient: addressSchema,
57-
primarySaleRecipient: addressSchema,
58-
royaltyBps: z.coerce.number().min(0).max(10000),
59-
});
60-
6159
export type NFTSalesSettingsFormValues = z.infer<
6260
typeof nftSalesSettingsFormSchema
6361
>;

apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/(sidebar)/assets/create/nft/collection-info/nft-collection-info-fieldset.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@ import { Input } from "@/components/ui/input";
77
import { Textarea } from "@/components/ui/textarea";
88
import { ClientOnly } from "components/ClientOnly/ClientOnly";
99
import { FileInput } from "components/shared/FileInput";
10+
import type { UseFormReturn } from "react-hook-form";
1011
import type { ThirdwebClient } from "thirdweb";
1112
import { SocialUrlsFieldset } from "../../_common/SocialUrls";
1213
import { StepCard } from "../../_common/step-card";
13-
import type { NFTCollectionInfoForm } from "../_common/form";
14+
import type { NFTCollectionInfoFormValues } from "../_common/form";
1415
import { nftCreationPages } from "../_common/pages";
1516

1617
export function NFTCollectionInfoFieldset(props: {
1718
client: ThirdwebClient;
1819
onNext: () => void;
19-
form: NFTCollectionInfoForm;
20+
form: UseFormReturn<NFTCollectionInfoFormValues>;
2021
onChainUpdated: () => void;
2122
}) {
2223
const { form } = props;

apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/(sidebar)/assets/create/nft/create-nft-page-ui.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
} from "thirdweb";
1111
import { useActiveAccount } from "thirdweb/react";
1212
import {
13-
type CreateNFTFunctions,
13+
type CreateNFTCollectionFunctions,
1414
type NFTCollectionInfoFormValues,
1515
type NFTSalesSettingsFormValues,
1616
nftCollectionInfoFormSchema,
@@ -26,7 +26,7 @@ import { type NFTData, UploadNFTsFieldset } from "./upload-nfts/upload-nfts";
2626
export function CreateNFTPageUI(props: {
2727
accountAddress: string;
2828
client: ThirdwebClient;
29-
createNFTFunctions: CreateNFTFunctions;
29+
createNFTFunctions: CreateNFTCollectionFunctions;
3030
onLaunchSuccess: () => void;
3131
teamSlug: string;
3232
projectSlug: string;
@@ -122,7 +122,7 @@ export function CreateNFTPageUI(props: {
122122
{step === nftCreationPages["launch-nft"] && (
123123
<LaunchNFT
124124
values={{
125-
...nftCollectionInfoForm.watch(),
125+
collectionInfo: nftCollectionInfoForm.watch(),
126126
sales: nftSalesSettingsForm.watch(),
127127
nfts:
128128
nftData.type === "multiple"

apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/(sidebar)/assets/create/nft/create-nft-page.tsx

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { maxUint256 } from "thirdweb/utils";
2525
import { parseError } from "utils/errorParser";
2626
import { useAddContractToProject } from "../../../hooks/project-contracts";
2727
import type {
28-
CreateNFTFormValues,
28+
CreateNFTCollectionAllValues,
2929
NFTCollectionInfoFormValues,
3030
} from "./_common/form";
3131
import {
@@ -77,23 +77,24 @@ export function CreateNFTPage(props: {
7777
}
7878

7979
async function handleContractDeploy(params: {
80-
formValues: CreateNFTFormValues;
80+
values: CreateNFTCollectionAllValues;
8181
ercType: "erc721" | "erc1155";
8282
}) {
83-
const { formValues, ercType } = params;
83+
const { values: formValues, ercType } = params;
84+
const { collectionInfo, sales } = formValues;
8485

8586
if (!activeAccount) {
8687
throw new Error("Wallet is not connected");
8788
}
8889

8990
// eslint-disable-next-line no-restricted-syntax
90-
const chain = defineChain(Number(formValues.chain));
91+
const chain = defineChain(Number(collectionInfo.chain));
9192

9293
trackEvent(
9394
getNFTStepTrackingData({
9495
action: "deploy",
9596
ercType,
96-
chainId: Number(formValues.chain),
97+
chainId: Number(collectionInfo.chain),
9798
status: "attempt",
9899
}),
99100
);
@@ -102,7 +103,7 @@ export function CreateNFTPage(props: {
102103
getNFTDeploymentTrackingData({
103104
ercType,
104105
type: "attempt",
105-
chainId: Number(formValues.chain),
106+
chainId: Number(collectionInfo.chain),
106107
}),
107108
);
108109

@@ -116,14 +117,14 @@ export function CreateNFTPage(props: {
116117
chain: chain,
117118
type: "DropERC721",
118119
params: {
119-
name: formValues.name,
120-
symbol: formValues.symbol,
121-
description: formValues.description,
122-
image: formValues.image,
123-
social_urls: transformSocialUrls(formValues.socialUrls),
124-
saleRecipient: formValues.sales.primarySaleRecipient,
125-
royaltyRecipient: formValues.sales.royaltyRecipient,
126-
royaltyBps: BigInt(formValues.sales.royaltyBps),
120+
name: collectionInfo.name,
121+
symbol: collectionInfo.symbol,
122+
description: collectionInfo.description,
123+
image: collectionInfo.image,
124+
social_urls: transformSocialUrls(collectionInfo.socialUrls),
125+
saleRecipient: sales.primarySaleRecipient,
126+
royaltyRecipient: sales.royaltyRecipient,
127+
royaltyBps: BigInt(sales.royaltyBps),
127128
},
128129
});
129130
} else {
@@ -133,14 +134,14 @@ export function CreateNFTPage(props: {
133134
chain: chain,
134135
type: "DropERC1155",
135136
params: {
136-
name: formValues.name,
137-
symbol: formValues.symbol,
138-
description: formValues.description,
139-
image: formValues.image,
140-
social_urls: transformSocialUrls(formValues.socialUrls),
141-
saleRecipient: formValues.sales.primarySaleRecipient,
142-
royaltyRecipient: formValues.sales.royaltyRecipient,
143-
royaltyBps: BigInt(formValues.sales.royaltyBps),
137+
name: collectionInfo.name,
138+
symbol: collectionInfo.symbol,
139+
description: collectionInfo.description,
140+
image: collectionInfo.image,
141+
social_urls: transformSocialUrls(collectionInfo.socialUrls),
142+
saleRecipient: sales.primarySaleRecipient,
143+
royaltyRecipient: sales.royaltyRecipient,
144+
royaltyBps: BigInt(sales.royaltyBps),
144145
},
145146
});
146147
}
@@ -149,7 +150,7 @@ export function CreateNFTPage(props: {
149150
getNFTStepTrackingData({
150151
action: "deploy",
151152
ercType,
152-
chainId: Number(formValues.chain),
153+
chainId: Number(collectionInfo.chain),
153154
status: "success",
154155
}),
155156
);
@@ -158,7 +159,7 @@ export function CreateNFTPage(props: {
158159
getNFTDeploymentTrackingData({
159160
ercType,
160161
type: "success",
161-
chainId: Number(formValues.chain),
162+
chainId: Number(collectionInfo.chain),
162163
}),
163164
);
164165

@@ -169,7 +170,7 @@ export function CreateNFTPage(props: {
169170
teamId: props.teamId,
170171
projectId: props.projectId,
171172
contractAddress: contractAddress,
172-
chainId: formValues.chain,
173+
chainId: collectionInfo.chain,
173174
deploymentType: "asset",
174175
contractType: ercType === "erc721" ? "DropERC721" : "DropERC1155",
175176
});
@@ -185,7 +186,7 @@ export function CreateNFTPage(props: {
185186
getNFTStepTrackingData({
186187
action: "deploy",
187188
ercType,
188-
chainId: Number(formValues.chain),
189+
chainId: Number(collectionInfo.chain),
189190
status: "error",
190191
errorMessage,
191192
}),
@@ -195,7 +196,7 @@ export function CreateNFTPage(props: {
195196
getNFTDeploymentTrackingData({
196197
ercType,
197198
type: "error",
198-
chainId: Number(formValues.chain),
199+
chainId: Number(collectionInfo.chain),
199200
errorMessage,
200201
}),
201202
);
@@ -205,13 +206,13 @@ export function CreateNFTPage(props: {
205206
}
206207

207208
async function handleLazyMintNFTs(params: {
208-
formValues: CreateNFTFormValues;
209+
formValues: CreateNFTCollectionAllValues;
209210
ercType: "erc721" | "erc1155";
210211
}) {
211212
const { formValues, ercType } = params;
212213

213214
const { contract, activeAccount } = getContractInfo({
214-
chain: formValues.chain,
215+
chain: formValues.collectionInfo.chain,
215216
});
216217

217218
const lazyMintFn = ercType === "erc721" ? lazyMint721 : lazyMint1155;
@@ -225,7 +226,7 @@ export function CreateNFTPage(props: {
225226
getNFTStepTrackingData({
226227
action: "lazy-mint",
227228
ercType,
228-
chainId: Number(formValues.chain),
229+
chainId: Number(formValues.collectionInfo.chain),
229230
status: "attempt",
230231
}),
231232
);
@@ -240,7 +241,7 @@ export function CreateNFTPage(props: {
240241
getNFTStepTrackingData({
241242
action: "lazy-mint",
242243
ercType,
243-
chainId: Number(formValues.chain),
244+
chainId: Number(formValues.collectionInfo.chain),
244245
status: "success",
245246
}),
246247
);
@@ -253,7 +254,7 @@ export function CreateNFTPage(props: {
253254
getNFTStepTrackingData({
254255
action: "lazy-mint",
255256
ercType,
256-
chainId: Number(formValues.chain),
257+
chainId: Number(formValues.collectionInfo.chain),
257258
status: "error",
258259
errorMessage,
259260
}),
@@ -264,11 +265,11 @@ export function CreateNFTPage(props: {
264265
}
265266

266267
async function handleSetClaimConditionsERC721(params: {
267-
formValues: CreateNFTFormValues;
268+
formValues: CreateNFTCollectionAllValues;
268269
}) {
269270
const { formValues } = params;
270271
const { contract, activeAccount } = getContractInfo({
271-
chain: formValues.chain,
272+
chain: formValues.collectionInfo.chain,
272273
});
273274

274275
const firstNFT = formValues.nfts[0];
@@ -296,7 +297,7 @@ export function CreateNFTPage(props: {
296297
getNFTStepTrackingData({
297298
action: "claim-conditions",
298299
ercType: "erc721",
299-
chainId: Number(formValues.chain),
300+
chainId: Number(formValues.collectionInfo.chain),
300301
status: "attempt",
301302
}),
302303
);
@@ -311,7 +312,7 @@ export function CreateNFTPage(props: {
311312
getNFTStepTrackingData({
312313
action: "claim-conditions",
313314
ercType: "erc721",
314-
chainId: Number(formValues.chain),
315+
chainId: Number(formValues.collectionInfo.chain),
315316
status: "success",
316317
}),
317318
);
@@ -324,7 +325,7 @@ export function CreateNFTPage(props: {
324325
getNFTStepTrackingData({
325326
action: "claim-conditions",
326327
ercType: "erc721",
327-
chainId: Number(formValues.chain),
328+
chainId: Number(formValues.collectionInfo.chain),
328329
status: "error",
329330
errorMessage,
330331
}),
@@ -451,7 +452,7 @@ export function CreateNFTPage(props: {
451452
},
452453
deployContract: (formValues) => {
453454
return handleContractDeploy({
454-
formValues,
455+
values: formValues,
455456
ercType: "erc1155",
456457
});
457458
},
@@ -462,7 +463,7 @@ export function CreateNFTPage(props: {
462463
erc721: {
463464
deployContract: (formValues) => {
464465
return handleContractDeploy({
465-
formValues,
466+
values: formValues,
466467
ercType: "erc721",
467468
});
468469
},

0 commit comments

Comments
 (0)