@@ -26,6 +26,7 @@ import { ToolTipLabel } from "@/components/ui/tooltip";
2626import type { Account } from "@3rdweb-sdk/react/hooks/useApi" ;
2727import { zodResolver } from "@hookform/resolvers/zod" ;
2828import { useMutation } from "@tanstack/react-query" ;
29+ import { useQuery } from "@tanstack/react-query" ;
2930import { TransactionButton } from "components/buttons/TransactionButton" ;
3031import { addDays , fromUnixTime } from "date-fns" ;
3132import { useAllChainsData } from "hooks/chains/allChains" ;
@@ -119,22 +120,39 @@ function ClaimableModule(props: ModuleInstanceProps) {
119120 claimConditionQuery . data ?. startTimestamp === 0 &&
120121 claimConditionQuery . data ?. endTimestamp === 0 ;
121122
122- const currencyContract = getContract ( {
123- address : claimConditionQuery . data ?. currency || "" ,
124- chain : props . contract . chain ,
125- client : props . contract . client ,
126- } ) ;
123+ const claimConditionCurrency = claimConditionQuery . data ?. currency ;
127124
128- const shouldFetchTokenDecimals =
129- claimConditionQuery . data &&
130- claimConditionQuery . data ?. currency !== ZERO_ADDRESS ;
125+ const shouldFetchCurrencyDecimals =
126+ ! ! claimConditionCurrency && claimConditionCurrency !== ZERO_ADDRESS ;
131127
132- const currencyDecimalsQuery = useReadContract ( decimals , {
133- contract : currencyContract ,
134- queryOptions : {
135- enabled : shouldFetchTokenDecimals ,
128+ const currencyDecimalsQuery = useQuery ( {
129+ queryKey : [
130+ "currency-decimals" ,
131+ {
132+ contractAddress : props . contract . address ,
133+ chainId : props . contract . chain . id ,
134+ claimConditionCurrency,
135+ } ,
136+ ] ,
137+ queryFn : async ( ) => {
138+ if ( ! claimConditionCurrency ) {
139+ throw new Error ( ) ;
140+ }
141+ const currencyContract = getContract ( {
142+ address : claimConditionCurrency ,
143+ chain : props . contract . chain ,
144+ client : props . contract . client ,
145+ } ) ;
146+
147+ const decimalsVal = await decimals ( {
148+ contract : currencyContract ,
149+ } ) ;
150+
151+ return decimalsVal ;
136152 } ,
153+ enabled : shouldFetchCurrencyDecimals ,
137154 } ) ;
155+
138156 const tokenDecimalsQuery = useReadContract ( decimals , {
139157 contract : contract ,
140158 queryOptions : {
@@ -265,7 +283,7 @@ function ClaimableModule(props: ModuleInstanceProps) {
265283 // claim conditions data is present
266284 claimConditionQuery . data &&
267285 // token decimals is fetched if it should be fetched
268- ( shouldFetchTokenDecimals ? currencyDecimalsQuery . isFetched : true )
286+ ( shouldFetchCurrencyDecimals ? currencyDecimalsQuery . isFetched : true )
269287 ? {
270288 claimCondition : claimConditionQuery . data ,
271289 currencyDecimals : currencyDecimalsQuery . data ,
@@ -276,7 +294,7 @@ function ClaimableModule(props: ModuleInstanceProps) {
276294 tokenId,
277295 isLoading :
278296 claimConditionQuery . isLoading ||
279- ( ! ! shouldFetchTokenDecimals && currencyDecimalsQuery . isLoading ) ,
297+ ( ! ! shouldFetchCurrencyDecimals && currencyDecimalsQuery . isLoading ) ,
280298 } }
281299 isOwnerAccount = { ! ! ownerAccount }
282300 name = { props . contractInfo . name }
@@ -565,6 +583,7 @@ function ClaimConditionSection(props: {
565583 onClick = { ( ) => setAddClaimConditionButtonClicked ( true ) }
566584 variant = "outline"
567585 className = "w-full"
586+ disabled = { ! props . isOwnerAccount }
568587 >
569588 Add Claim Condition
570589 </ Button >
0 commit comments