@@ -29,7 +29,13 @@ import { useTxNotifications } from "hooks/useTxNotifications";
2929import { CircleAlertIcon , PlusIcon , Trash2Icon } from "lucide-react" ;
3030import { useCallback } from "react" ;
3131import { useFieldArray , useForm } from "react-hook-form" ;
32- import { type PreparedTransaction , sendAndConfirmTransaction } from "thirdweb" ;
32+ import {
33+ type PreparedTransaction ,
34+ getContract ,
35+ sendAndConfirmTransaction ,
36+ toTokens ,
37+ } from "thirdweb" ;
38+ import { decimals } from "thirdweb/extensions/erc20" ;
3339import { ClaimableERC721 , ClaimableERC1155 } from "thirdweb/modules" ;
3440import { useActiveAccount , useReadContract } from "thirdweb/react" ;
3541import { z } from "zod" ;
@@ -66,6 +72,23 @@ function ClaimableModule(props: ModuleInstanceProps) {
6672 } ,
6773 ) ;
6874
75+ const currencyContract = getContract ( {
76+ address : claimConditionQuery . data ?. currency || "" ,
77+ chain : props . contract . chain ,
78+ client : props . contract . client ,
79+ } ) ;
80+
81+ const tokenDecimals = useReadContract ( decimals , {
82+ contract : currencyContract ,
83+ queryOptions : {
84+ enabled :
85+ claimConditionQuery . data &&
86+ claimConditionQuery . data ?. currency !==
87+ "0x0000000000000000000000000000000000000000" ,
88+ } ,
89+ } ) ;
90+ const tokenDecimalsData = tokenDecimals . data ?? 0 ;
91+
6992 const isErc721 = props . contractInfo . name === "ClaimableERC721" ;
7093
7194 const mint = useCallback (
@@ -160,7 +183,12 @@ function ClaimableModule(props: ModuleInstanceProps) {
160183 < ClaimableModuleUI
161184 { ...props }
162185 isPendingPrimarySaleRecipient = { primarySaleRecipientQuery . isPending }
163- isPendingClaimCondition = { claimConditionQuery . isPending }
186+ isPendingClaimCondition = {
187+ claimConditionQuery . isPending ||
188+ ( claimConditionQuery . data ?. currency !==
189+ "0x0000000000000000000000000000000000000000" &&
190+ tokenDecimals . isPending )
191+ }
164192 primarySaleRecipient = { primarySaleRecipientQuery . data }
165193 claimCondition = { claimConditionQuery . data }
166194 setClaimCondition = { setClaimCondition }
@@ -169,6 +197,7 @@ function ClaimableModule(props: ModuleInstanceProps) {
169197 isOwnerAccount = { ! ! ownerAccount }
170198 isErc721 = { isErc721 }
171199 chainId = { props . contract . chain . id }
200+ tokenDecimals = { tokenDecimalsData }
172201 />
173202 ) ;
174203}
@@ -187,6 +216,7 @@ export function ClaimableModuleUI(
187216 mint : ( values : MintFormValues ) => Promise < void > ;
188217 isErc721 : boolean ;
189218 chainId : number ;
219+ tokenDecimals : number ;
190220 } ,
191221) {
192222 return (
@@ -218,6 +248,7 @@ export function ClaimableModuleUI(
218248 update = { props . setClaimCondition }
219249 isErc721 = { props . isErc721 }
220250 chainId = { props . chainId }
251+ tokenDecimals = { props . tokenDecimals }
221252 />
222253 ) : (
223254 < Skeleton className = "h-[74px]" />
@@ -285,6 +316,8 @@ export type ClaimConditionFormValues = z.infer<typeof claimConditionFormSchema>;
285316
286317// perform this outside else it forces too many re-renders
287318const now = Date . now ( ) / 1000 ;
319+ const MAX_UINT_256 =
320+ "115792089237316195423570985008687907853269984665640564039457584007913129639935" ;
288321
289322function ClaimConditionSection ( props : {
290323 primarySaleRecipient : string | undefined ;
@@ -293,26 +326,35 @@ function ClaimConditionSection(props: {
293326 isOwnerAccount : boolean ;
294327 isErc721 : boolean ;
295328 chainId : number ;
329+ tokenDecimals : number ;
296330} ) {
297331 const { idToChain } = useAllChainsData ( ) ;
298332 const chain = idToChain . get ( props . chainId ) ;
299333
300334 const form = useForm < ClaimConditionFormValues > ( {
301335 resolver : zodResolver ( claimConditionFormSchema ) ,
302336 values : {
303- // TODO: parse units based on the currency decimals
304- pricePerToken : props . claimCondition ?. pricePerUnit ? 0 : 0 ,
305337 currencyAddress :
306338 props . claimCondition ?. currency ===
307339 "0x0000000000000000000000000000000000000000"
308340 ? ""
309341 : props . claimCondition ?. currency ,
342+ pricePerToken :
343+ props . claimCondition ?. pricePerUnit &&
344+ props . claimCondition ?. currency !==
345+ "0x0000000000000000000000000000000000000000"
346+ ? Number (
347+ toTokens ( props . claimCondition ?. pricePerUnit , props . tokenDecimals ) ,
348+ )
349+ : 0 ,
310350 maxClaimableSupply :
311- props . claimCondition ?. availableSupply . toString ( ) === "0"
351+ props . claimCondition ?. availableSupply . toString ( ) === "0" ||
352+ props . claimCondition ?. availableSupply . toString ( ) === MAX_UINT_256
312353 ? ""
313354 : props . claimCondition ?. availableSupply . toString ( ) || "" ,
314355 maxClaimablePerWallet :
315- props . claimCondition ?. maxMintPerWallet . toString ( ) === "0"
356+ props . claimCondition ?. maxMintPerWallet . toString ( ) === "0" ||
357+ props . claimCondition ?. maxMintPerWallet . toString ( ) === MAX_UINT_256
316358 ? ""
317359 : props . claimCondition ?. maxMintPerWallet . toString ( ) || "" ,
318360 startTime : new Date ( ( props . claimCondition ?. startTimestamp || now ) * 1000 ) ,
0 commit comments