@@ -28,7 +28,6 @@ import { addDays, fromUnixTime } from "date-fns";
2828import { useAllChainsData } from "hooks/chains/allChains" ;
2929import { useTxNotifications } from "hooks/useTxNotifications" ;
3030import { CircleAlertIcon , PlusIcon , Trash2Icon } from "lucide-react" ;
31- import { useEffect } from "react" ;
3231import { useCallback } from "react" ;
3332import { useFieldArray , useForm } from "react-hook-form" ;
3433import {
@@ -59,15 +58,6 @@ export type ClaimConditionValue = {
5958 auxData : string ;
6059} ;
6160
62- // TODO - for erc1155 have a UI something like this:
63- // - show one input initially - user enters tokenId
64- // - fetch the claim conditions for that tokenId and show the entire claim condition form with those values if they exist, or show empty form state if they don't exist
65-
66- // TODO - don't compare with ZERO_ADDRESS we are not getting ZERO_ADDRESS as currency address and instead getting 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE, (checksummed NATIVE_TOKEN_ADDRESS)
67-
68- // TODO - fix Currency selector not showing the selected currency
69- //
70-
7161type ClaimCondition = {
7262 availableSupply : bigint ;
7363 allowlistMerkleRoot : `0x${string } `;
@@ -403,39 +393,56 @@ function ClaimConditionSection(props: {
403393 const chain = idToChain . get ( props . chainId ) ;
404394 const { claimCondition } = props ;
405395
396+ const tokenIdForm = useForm < { tokenId : string } > ( {
397+ defaultValues : {
398+ tokenId : "" ,
399+ } ,
400+ } ) ;
401+
402+ const tokenId = tokenIdForm . watch ( "tokenId" ) ;
403+
404+ const claimConditionErc1155Query = useQuery ( {
405+ queryKey : [ "claimConditionErc1155" , props . chainId , tokenId ] ,
406+ queryFn : ( ) => props . getClaimConditionErc1155 ( tokenId ) ,
407+ enabled : ! props . isErc721 && Number ( tokenId ) > 0 ,
408+ } ) ;
409+
410+ const conditions = props . isErc721
411+ ? claimCondition
412+ : claimConditionErc1155Query . data ;
413+
406414 const form = useForm < ClaimConditionFormValues > ( {
407415 resolver : zodResolver ( claimConditionFormSchema ) ,
408416 values : {
409- tokenId : "" ,
417+ tokenId,
410418 currencyAddress :
411- claimCondition ?. currency === ZERO_ADDRESS
412- ? ""
413- : claimCondition ?. currency ,
419+ conditions ?. currency === ZERO_ADDRESS ? "" : conditions ?. currency ,
414420 pricePerToken :
415- claimCondition ?. pricePerUnit &&
416- claimCondition ?. currency !== ZERO_ADDRESS &&
421+ conditions ?. pricePerUnit &&
422+ conditions ?. currency !== ZERO_ADDRESS &&
417423 props . tokenDecimals
418- ? Number ( toTokens ( claimCondition ?. pricePerUnit , props . tokenDecimals ) )
424+ ? Number ( toTokens ( conditions ?. pricePerUnit , props . tokenDecimals ) )
419425 : 0 ,
420426 maxClaimableSupply :
421- claimCondition ?. availableSupply . toString ( ) === "0" ||
422- claimCondition ?. availableSupply . toString ( ) === MAX_UINT_256
427+ conditions ?. availableSupply . toString ( ) === "0" ||
428+ conditions ?. availableSupply . toString ( ) === MAX_UINT_256
423429 ? ""
424- : claimCondition ?. availableSupply . toString ( ) || "" ,
430+ : conditions ?. availableSupply . toString ( ) || "" ,
425431 maxClaimablePerWallet :
426- claimCondition ?. maxMintPerWallet . toString ( ) === "0" ||
427- claimCondition ?. maxMintPerWallet . toString ( ) === MAX_UINT_256
432+ conditions ?. maxMintPerWallet . toString ( ) === "0" ||
433+ conditions ?. maxMintPerWallet . toString ( ) === MAX_UINT_256
428434 ? ""
429- : claimCondition ?. maxMintPerWallet . toString ( ) || "" ,
430- startTime : claimCondition ?. startTimestamp
431- ? fromUnixTime ( claimCondition ?. startTimestamp )
435+ : conditions ?. maxMintPerWallet . toString ( ) || "" ,
436+ startTime : conditions ?. startTimestamp
437+ ? fromUnixTime ( conditions ?. startTimestamp )
432438 : defaultStartDate ,
433- endTime : claimCondition ?. endTimestamp
434- ? fromUnixTime ( claimCondition ?. endTimestamp )
439+ endTime : conditions ?. endTimestamp
440+ ? fromUnixTime ( conditions ?. endTimestamp )
435441 : defaultEndDate ,
436442 allowList : [ ] ,
437443 } ,
438444 } ) ;
445+
439446 const allowListFields = useFieldArray ( {
440447 control : form . control ,
441448 name : "allowList" ,
@@ -463,68 +470,13 @@ function ClaimConditionSection(props: {
463470 updateMutation . mutateAsync ( values ) ;
464471 } ;
465472
466- const tokenId = form . watch ( "tokenId" ) ;
467-
468- const claimConditionErc1155Query = useQuery ( {
469- queryKey : [ "claimConditionErc1155" , props . chainId , tokenId ] ,
470- queryFn : ( ) => props . getClaimConditionErc1155 ( tokenId ) ,
471- enabled : ! props . isErc721 && Number ( tokenId ) > 0 ,
472- } ) ;
473-
474- useEffect ( ( ) => {
475- if ( claimConditionErc1155Query . data ) {
476- form . reset ( {
477- tokenId,
478- currencyAddress :
479- claimConditionErc1155Query . data . currency === ZERO_ADDRESS
480- ? ""
481- : claimConditionErc1155Query . data . currency ,
482- pricePerToken :
483- claimConditionErc1155Query . data . pricePerUnit &&
484- claimConditionErc1155Query . data . currency !== ZERO_ADDRESS &&
485- props . tokenDecimals
486- ? Number (
487- toTokens (
488- claimConditionErc1155Query . data . pricePerUnit ,
489- props . tokenDecimals ,
490- ) ,
491- )
492- : 0 ,
493- maxClaimableSupply :
494- claimConditionErc1155Query . data . availableSupply . toString ( ) === "0" ||
495- claimConditionErc1155Query . data . availableSupply . toString ( ) ===
496- MAX_UINT_256
497- ? ""
498- : claimConditionErc1155Query . data . availableSupply . toString ( ) || "" ,
499- maxClaimablePerWallet :
500- claimConditionErc1155Query . data . maxMintPerWallet . toString ( ) === "0" ||
501- claimConditionErc1155Query . data . maxMintPerWallet . toString ( ) ===
502- MAX_UINT_256
503- ? ""
504- : claimConditionErc1155Query . data . maxMintPerWallet . toString ( ) || "" ,
505- startTime : claimConditionErc1155Query . data . startTimestamp
506- ? fromUnixTime ( claimConditionErc1155Query . data . startTimestamp )
507- : defaultStartDate ,
508- endTime : claimConditionErc1155Query . data . endTimestamp
509- ? fromUnixTime ( claimConditionErc1155Query . data . endTimestamp )
510- : defaultEndDate ,
511- allowList : [ ] ,
512- } ) ;
513- }
514- } , [
515- claimConditionErc1155Query . data ,
516- form . reset ,
517- tokenId ,
518- props . tokenDecimals ,
519- ] ) ;
520-
521473 return (
522- < Form { ... form } >
523- < form onSubmit = { form . handleSubmit ( onSubmit ) } >
524- < div className = "flex flex-col gap-6" >
525- { ! props . isErc721 && (
474+ < div className = "flex flex-col gap-6" >
475+ { ! props . isErc721 && (
476+ < Form { ... tokenIdForm } >
477+ < form >
526478 < FormField
527- control = { form . control }
479+ control = { tokenIdForm . control }
528480 name = "tokenId"
529481 render = { ( { field } ) => (
530482 < FormItem className = "flex-1" >
@@ -536,8 +488,12 @@ function ClaimConditionSection(props: {
536488 </ FormItem >
537489 ) }
538490 />
539- ) }
491+ </ form >
492+ </ Form >
493+ ) }
540494
495+ < Form { ...form } >
496+ < form onSubmit = { form . handleSubmit ( onSubmit ) } >
541497 { ! props . isErc721 && ! ( Number ( tokenId ) > 0 ) && (
542498 < Alert variant = "warning" >
543499 < CircleAlertIcon className = "size-5 max-sm:hidden" />
@@ -721,9 +677,9 @@ function ClaimConditionSection(props: {
721677 </ div >
722678 </ >
723679 ) ) }
724- </ div >
725- </ form > { " " }
726- </ Form >
680+ </ form > { " " }
681+ </ Form >
682+ </ div >
727683 ) ;
728684}
729685
0 commit comments