88 AccordionItem ,
99 AccordionTrigger ,
1010} from "@/components/ui/accordion" ;
11- import { Alert , AlertTitle } from "@/components/ui/alert" ;
11+ import { Alert , AlertDescription , AlertTitle } from "@/components/ui/alert" ;
1212import { Button } from "@/components/ui/button" ;
1313import {
1414 Form ,
@@ -38,6 +38,7 @@ import {
3838} from "react" ;
3939import { useFieldArray , useForm } from "react-hook-form" ;
4040import {
41+ NATIVE_TOKEN_ADDRESS ,
4142 type PreparedTransaction ,
4243 ZERO_ADDRESS ,
4344 getContract ,
@@ -64,12 +65,15 @@ export type ClaimConditionValue = {
6465 auxData : string ;
6566} ;
6667
68+ const positiveIntegerRegex = / ^ [ 0 - 9 ] \d * $ / ;
69+
6770function ClaimableModule ( props : ModuleInstanceProps ) {
6871 const { contract, ownerAccount } = props ;
6972 const account = useActiveAccount ( ) ;
7073 const [ tokenId , setTokenId ] = useState < string > ( "" ) ;
7174
7275 const isErc721 = props . contractInfo . name === "ClaimableERC721" ;
76+ const isValidTokenId = positiveIntegerRegex . test ( tokenId ) ;
7377
7478 const primarySaleRecipientQuery = useReadContract (
7579 isErc721 ? ClaimableERC721 . getSaleConfig : ClaimableERC1155 . getSaleConfig ,
@@ -83,14 +87,24 @@ function ClaimableModule(props: ModuleInstanceProps) {
8387 ? ClaimableERC721 . getClaimCondition
8488 : ClaimableERC1155 . getClaimCondition ,
8589 {
86- tokenId : BigInt ( tokenId ) ,
90+ tokenId : positiveIntegerRegex . test ( tokenId ) ? BigInt ( tokenId ) : 0n ,
8791 contract : contract ,
8892 queryOptions : {
89- enabled : isErc721 || ! ! tokenId ,
93+ enabled : isErc721 || ( ! ! tokenId && isValidTokenId ) ,
9094 } ,
9195 } ,
9296 ) ;
9397
98+ const noClaimConditionSet =
99+ claimConditionQuery . data ?. availableSupply === 0n &&
100+ claimConditionQuery . data ?. allowlistMerkleRoot ===
101+ "0x0000000000000000000000000000000000000000000000000000000000000000" &&
102+ claimConditionQuery . data ?. pricePerUnit === 0n &&
103+ claimConditionQuery . data ?. currency === ZERO_ADDRESS &&
104+ claimConditionQuery . data ?. maxMintPerWallet === 0n &&
105+ claimConditionQuery . data ?. startTimestamp === 0 &&
106+ claimConditionQuery . data ?. endTimestamp === 0 ;
107+
94108 const currencyContract = getContract ( {
95109 address : claimConditionQuery . data ?. currency || "" ,
96110 chain : props . contract . chain ,
@@ -229,6 +243,8 @@ function ClaimableModule(props: ModuleInstanceProps) {
229243 isErc721 = { isErc721 }
230244 contractChainId = { props . contract . chain . id }
231245 setTokenId = { setTokenId }
246+ isValidTokenId = { isValidTokenId }
247+ noClaimConditionSet = { noClaimConditionSet }
232248 mintSection = { {
233249 mint,
234250 } }
@@ -242,6 +258,8 @@ export function ClaimableModuleUI(
242258 isErc721 : boolean ;
243259 contractChainId : number ;
244260 setTokenId : Dispatch < SetStateAction < string > > ;
261+ isValidTokenId : boolean ;
262+ noClaimConditionSet : boolean ;
245263 primarySaleRecipientSection : {
246264 setPrimarySaleRecipient : (
247265 values : PrimarySaleRecipientFormValues ,
@@ -300,7 +318,12 @@ export function ClaimableModuleUI(
300318 < Input onChange = { ( e ) => props . setTokenId ( e . target . value ) } />
301319 </ div >
302320
303- { ! props . claimConditionSection . tokenId && (
321+ { ! (
322+ props . claimConditionSection . tokenId &&
323+ positiveIntegerRegex . test (
324+ props . claimConditionSection . tokenId ,
325+ )
326+ ) && (
304327 < Alert variant = "warning" >
305328 < CircleAlertIcon className = "size-5 max-sm:hidden" />
306329 < AlertTitle className = "max-sm:!pl-0" >
@@ -313,7 +336,8 @@ export function ClaimableModuleUI(
313336
314337 < div className = "h-6" />
315338
316- { props . claimConditionSection . data &&
339+ { props . isValidTokenId &&
340+ props . claimConditionSection . data &&
317341 ! props . claimConditionSection . isLoading && (
318342 < ClaimConditionSection
319343 isOwnerAccount = { props . isOwnerAccount }
@@ -323,15 +347,17 @@ export function ClaimableModuleUI(
323347 update = { props . claimConditionSection . setClaimCondition }
324348 isErc721 = { props . isErc721 }
325349 chainId = { props . contractChainId }
350+ noClaimConditionSet = { props . noClaimConditionSet }
326351 tokenDecimals = {
327352 props . claimConditionSection . data ?. tokenDecimals
328353 }
329354 tokenId = { props . claimConditionSection . tokenId }
330355 />
331356 ) }
332- { props . claimConditionSection . isLoading && (
333- < Skeleton className = "h-[350px]" />
334- ) }
357+ { props . isValidTokenId &&
358+ props . claimConditionSection . isLoading && (
359+ < Skeleton className = "h-[350px]" />
360+ ) }
335361 </ AccordionContent >
336362 </ AccordionItem >
337363
@@ -407,6 +433,7 @@ function ClaimConditionSection(props: {
407433 chainId : number ;
408434 tokenDecimals ?: number ;
409435 tokenId : string ;
436+ noClaimConditionSet : boolean ;
410437} ) {
411438 const { idToChain } = useAllChainsData ( ) ;
412439 const chain = idToChain . get ( props . chainId ) ;
@@ -418,14 +445,12 @@ function ClaimConditionSection(props: {
418445 tokenId,
419446 currencyAddress :
420447 claimCondition ?. currency === ZERO_ADDRESS
421- ? ""
448+ ? NATIVE_TOKEN_ADDRESS // default to the native token address
422449 : claimCondition ?. currency ,
423- pricePerToken :
424- claimCondition ?. pricePerUnit &&
425- claimCondition ?. currency !== ZERO_ADDRESS &&
426- props . tokenDecimals
427- ? Number ( toTokens ( claimCondition ?. pricePerUnit , props . tokenDecimals ) )
428- : 0 ,
450+ // default case is zero state, so 0 // 10 ** 18 still results in 0
451+ pricePerToken : Number (
452+ toTokens ( claimCondition ?. pricePerUnit , props . tokenDecimals || 18 ) ,
453+ ) ,
429454 maxClaimableSupply :
430455 claimCondition ?. availableSupply . toString ( ) === "0" ||
431456 claimCondition ?. availableSupply . toString ( ) === MAX_UINT_256
@@ -475,6 +500,17 @@ function ClaimConditionSection(props: {
475500
476501 return (
477502 < div className = "flex flex-col gap-6" >
503+ { props . noClaimConditionSet && (
504+ < Alert variant = "warning" >
505+ < CircleAlertIcon className = "size-5 max-sm:hidden" />
506+ < AlertTitle > No Claim Condition Set</ AlertTitle >
507+ < AlertDescription >
508+ You have not set a claim condition for this token. You can set a
509+ claim condition by clicking the "Set Claim Condition" button.
510+ </ AlertDescription >
511+ </ Alert >
512+ ) }
513+
478514 < Form { ...form } >
479515 < form onSubmit = { form . handleSubmit ( onSubmit ) } >
480516 < div className = "flex flex-col gap-6" >
0 commit comments