Skip to content

Commit 9c73d62

Browse files
committed
updated to use contractInfo name
1 parent e87eb2f commit 9c73d62

File tree

6 files changed

+172
-90
lines changed

6 files changed

+172
-90
lines changed

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ import { CircleAlertIcon } from "lucide-react";
2424
import { useCallback } from "react";
2525
import { useForm } from "react-hook-form";
2626
import { sendAndConfirmTransaction } from "thirdweb";
27-
import { BatchMetadataERC721, BatchMetadataERC1155 } from "thirdweb/modules";
27+
import {
28+
BatchMetadataERC20,
29+
BatchMetadataERC721,
30+
BatchMetadataERC1155,
31+
} from "thirdweb/modules";
2832
import { parseAttributes } from "utils/parseAttributes";
2933
import { z } from "zod";
3034
import { fileBufferOrStringSchema } from "../zod-schemas";
@@ -66,18 +70,19 @@ export type UploadMetadataFormValues = z.infer<typeof uploadMetadataFormSchema>;
6670
function BatchMetadataModule(props: ModuleInstanceProps) {
6771
const { contract, ownerAccount } = props;
6872

69-
const isErc721 = props.contractInfo.name === "BatchMetadataERC721";
70-
7173
const uploadMetadata = useCallback(
7274
async (values: UploadMetadataFormValues) => {
7375
if (!ownerAccount) {
7476
throw new Error("Not an owner account");
7577
}
7678

7779
const nft = parseAttributes(values);
78-
const uploadMetadata = isErc721
79-
? BatchMetadataERC721.uploadMetadata
80-
: BatchMetadataERC1155.uploadMetadata;
80+
const uploadMetadata =
81+
props.contractInfo.name === "BatchMetadataERC721"
82+
? BatchMetadataERC721.uploadMetadata
83+
: props.contractInfo.name === "BatchMetadataERC20"
84+
? BatchMetadataERC20.uploadMetadata
85+
: BatchMetadataERC1155.uploadMetadata;
8186
const uploadMetadataTx = uploadMetadata({
8287
contract,
8388
metadatas: [nft],
@@ -88,7 +93,7 @@ function BatchMetadataModule(props: ModuleInstanceProps) {
8893
transaction: uploadMetadataTx,
8994
});
9095
},
91-
[contract, ownerAccount, isErc721],
96+
[contract, ownerAccount, props.contractInfo.name],
9297
);
9398

9499
return (

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

Lines changed: 56 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ import {
4646
toTokens,
4747
} from "thirdweb";
4848
import { decimals } from "thirdweb/extensions/erc20";
49-
import { ClaimableERC721, ClaimableERC1155 } from "thirdweb/modules";
49+
import {
50+
ClaimableERC20,
51+
ClaimableERC721,
52+
ClaimableERC1155,
53+
} from "thirdweb/modules";
5054
import { useActiveAccount, useReadContract } from "thirdweb/react";
5155
import { z } from "zod";
5256
import { addressSchema } from "../zod-schemas";
@@ -72,26 +76,34 @@ function ClaimableModule(props: ModuleInstanceProps) {
7276
const account = useActiveAccount();
7377
const [tokenId, setTokenId] = useState<string>("");
7478

75-
const isErc721 = props.contractInfo.name === "ClaimableERC721";
76-
const isErc20 = props.contractInfo.name === "ClaimableERC20";
7779
const isValidTokenId = positiveIntegerRegex.test(tokenId);
7880

7981
const primarySaleRecipientQuery = useReadContract(
80-
isErc721 ? ClaimableERC721.getSaleConfig : ClaimableERC1155.getSaleConfig,
82+
props.contractInfo.name === "ClaimableERC721"
83+
? ClaimableERC721.getSaleConfig
84+
: props.contractInfo.name === "ClaimableERC20"
85+
? ClaimableERC20.getSaleConfig
86+
: ClaimableERC1155.getSaleConfig,
8187
{
8288
contract: contract,
8389
},
8490
);
8591

8692
const claimConditionQuery = useReadContract(
87-
isErc721
93+
props.contractInfo.name === "ClaimableERC721"
8894
? ClaimableERC721.getClaimCondition
89-
: ClaimableERC1155.getClaimCondition,
95+
: props.contractInfo.name === "ClaimableERC20"
96+
? ClaimableERC20.getClaimCondition
97+
: ClaimableERC1155.getClaimCondition,
9098
{
9199
tokenId: positiveIntegerRegex.test(tokenId) ? BigInt(tokenId) : 0n,
92100
contract: contract,
93101
queryOptions: {
94-
enabled: isErc721 || (!!tokenId && isValidTokenId),
102+
enabled:
103+
["ClaimableERC721", "ClaimableERC20"].includes(
104+
props.contractInfo.name,
105+
) ||
106+
(!!tokenId && isValidTokenId),
95107
},
96108
},
97109
);
@@ -130,12 +142,18 @@ function ClaimableModule(props: ModuleInstanceProps) {
130142
}
131143

132144
let mintTx: PreparedTransaction;
133-
if (isErc721) {
145+
if (props.contractInfo.name === "ClaimableERC721") {
134146
mintTx = ClaimableERC721.mint({
135147
contract,
136148
to: values.recipient,
137149
quantity: values.quantity,
138150
});
151+
} else if (props.contractInfo.name === "ClaimableERC20") {
152+
mintTx = ClaimableERC20.mint({
153+
contract,
154+
to: values.recipient,
155+
quantity: values.quantity,
156+
});
139157
} else if (values.tokenId) {
140158
mintTx = ClaimableERC1155.mint({
141159
contract,
@@ -152,7 +170,7 @@ function ClaimableModule(props: ModuleInstanceProps) {
152170
transaction: mintTx,
153171
});
154172
},
155-
[contract, account, isErc721],
173+
[contract, account, props.contractInfo.name],
156174
);
157175

158176
const setClaimCondition = useCallback(
@@ -162,7 +180,7 @@ function ClaimableModule(props: ModuleInstanceProps) {
162180
}
163181

164182
let setClaimConditionTx: PreparedTransaction;
165-
if (isErc721) {
183+
if (props.contractInfo.name === "ClaimableERC721") {
166184
setClaimConditionTx = ClaimableERC721.setClaimCondition({
167185
...values,
168186
contract,
@@ -171,6 +189,15 @@ function ClaimableModule(props: ModuleInstanceProps) {
171189
? values.allowList.map(({ address }) => address)
172190
: undefined,
173191
});
192+
} else if (props.contractInfo.name === "ClaimableERC20") {
193+
setClaimConditionTx = ClaimableERC20.setClaimCondition({
194+
...values,
195+
contract,
196+
allowList:
197+
values.allowList && values.allowList.length > 0
198+
? values.allowList.map(({ address }) => address)
199+
: undefined,
200+
});
174201
} else if (values.tokenId) {
175202
setClaimConditionTx = ClaimableERC1155.setClaimCondition({
176203
...values,
@@ -190,17 +217,20 @@ function ClaimableModule(props: ModuleInstanceProps) {
190217
transaction: setClaimConditionTx,
191218
});
192219
},
193-
[contract, ownerAccount, isErc721],
220+
[contract, ownerAccount, props.contractInfo.name],
194221
);
195222

196223
const setPrimarySaleRecipient = useCallback(
197224
async (values: PrimarySaleRecipientFormValues) => {
198225
if (!ownerAccount) {
199226
throw new Error("Not an owner account");
200227
}
201-
const setSaleConfig = isErc721
202-
? ClaimableERC721.setSaleConfig
203-
: ClaimableERC1155.setSaleConfig;
228+
const setSaleConfig =
229+
props.contractInfo.name === "ClaimableERC721"
230+
? ClaimableERC721.setSaleConfig
231+
: props.contractInfo.name === "ClaimableERC20"
232+
? ClaimableERC20.setSaleConfig
233+
: ClaimableERC1155.setSaleConfig;
204234
const setSaleConfigTx = setSaleConfig({
205235
contract: contract,
206236
primarySaleRecipient: values.primarySaleRecipient,
@@ -211,7 +241,7 @@ function ClaimableModule(props: ModuleInstanceProps) {
211241
transaction: setSaleConfigTx,
212242
});
213243
},
214-
[contract, ownerAccount, isErc721],
244+
[contract, ownerAccount, props.contractInfo.name],
215245
);
216246

217247
return (
@@ -241,8 +271,7 @@ function ClaimableModule(props: ModuleInstanceProps) {
241271
(!!shouldFetchTokenDecimals && tokenDecimalsQuery.isLoading),
242272
}}
243273
isOwnerAccount={!!ownerAccount}
244-
isErc721={isErc721}
245-
isErc20={isErc20}
274+
name={props.contractInfo.name}
246275
contractChainId={props.contract.chain.id}
247276
setTokenId={setTokenId}
248277
isValidTokenId={isValidTokenId}
@@ -257,8 +286,7 @@ function ClaimableModule(props: ModuleInstanceProps) {
257286
export function ClaimableModuleUI(
258287
props: Omit<ModuleCardUIProps, "children" | "updateButton"> & {
259288
isOwnerAccount: boolean;
260-
isErc721: boolean;
261-
isErc20: boolean;
289+
name: string;
262290
contractChainId: number;
263291
setTokenId: Dispatch<SetStateAction<string>>;
264292
isValidTokenId: boolean;
@@ -298,12 +326,12 @@ export function ClaimableModuleUI(
298326
<Accordion type="single" collapsible className="-mx-1">
299327
<AccordionItem value="metadata" className="border-none">
300328
<AccordionTrigger className="border-border border-t px-1">
301-
Mint {props.isErc20 ? "Token" : "NFT"}
329+
Mint {props.name === "ClaimableERC20" ? "Token" : "NFT"}
302330
</AccordionTrigger>
303331
<AccordionContent className="px-1">
304332
<MintNFTSection
305333
mint={props.mintSection.mint}
306-
isErc721={props.isErc721}
334+
name={props.name}
307335
contractChainId={props.contractChainId}
308336
/>
309337
</AccordionContent>
@@ -314,7 +342,7 @@ export function ClaimableModuleUI(
314342
Claim Conditions
315343
</AccordionTrigger>
316344
<AccordionContent className="px-1">
317-
{!props.isErc721 && (
345+
{props.name === "ClaimableERC1155" && (
318346
<div className="flex flex-col gap-6">
319347
<div className="flex-1 space-y-1">
320348
<Label>Token ID</Label>
@@ -339,7 +367,7 @@ export function ClaimableModuleUI(
339367
props.claimConditionSection.data.claimCondition
340368
}
341369
update={props.claimConditionSection.setClaimCondition}
342-
isErc721={props.isErc721}
370+
name={props.name}
343371
chainId={props.contractChainId}
344372
noClaimConditionSet={props.noClaimConditionSet}
345373
tokenDecimals={
@@ -423,7 +451,7 @@ function ClaimConditionSection(props: {
423451
claimCondition: ClaimConditionValue;
424452
update: (values: ClaimConditionFormValues) => Promise<void>;
425453
isOwnerAccount: boolean;
426-
isErc721: boolean;
454+
name: string;
427455
chainId: number;
428456
tokenDecimals?: number;
429457
tokenId: string;
@@ -487,7 +515,7 @@ function ClaimConditionSection(props: {
487515

488516
const onSubmit = async () => {
489517
const values = form.getValues();
490-
if (!props.isErc721 && !values.tokenId) {
518+
if (props.name === "ClaimableERC1155" && !values.tokenId) {
491519
form.setError("tokenId", { message: "Token ID is required" });
492520
return;
493521
}
@@ -782,7 +810,7 @@ export type MintFormValues = z.infer<typeof mintFormSchema>;
782810

783811
function MintNFTSection(props: {
784812
mint: (values: MintFormValues) => Promise<void>;
785-
isErc721: boolean;
813+
name: string;
786814
contractChainId: number;
787815
}) {
788816
const form = useForm<MintFormValues>({
@@ -808,7 +836,7 @@ function MintNFTSection(props: {
808836

809837
const onSubmit = async () => {
810838
const values = form.getValues();
811-
if (!props.isErc721 && !values.tokenId) {
839+
if (props.name === "ClaimableERC1155" && !values.tokenId) {
812840
form.setError("tokenId", { message: "Token ID is required" });
813841
return;
814842
}
@@ -847,7 +875,7 @@ function MintNFTSection(props: {
847875
)}
848876
/>
849877

850-
{!props.isErc721 && (
878+
{props.name === "ClaimableERC1155" && (
851879
<FormField
852880
control={form.control}
853881
name="tokenId"

0 commit comments

Comments
 (0)