@@ -46,7 +46,11 @@ import {
4646 toTokens ,
4747} from "thirdweb" ;
4848import { decimals } from "thirdweb/extensions/erc20" ;
49- import { ClaimableERC721 , ClaimableERC1155 } from "thirdweb/modules" ;
49+ import {
50+ ClaimableERC20 ,
51+ ClaimableERC721 ,
52+ ClaimableERC1155 ,
53+ } from "thirdweb/modules" ;
5054import { useActiveAccount , useReadContract } from "thirdweb/react" ;
5155import { z } from "zod" ;
5256import { 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) {
257286export 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
783811function 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