Skip to content

Commit 9042cb3

Browse files
committed
updated claim conditinos
1 parent 4487295 commit 9042cb3

File tree

2 files changed

+35
-14
lines changed

2 files changed

+35
-14
lines changed

apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/modules/components/Claimable.tsx

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,18 @@ function ClaimableModule(props: ModuleInstanceProps) {
128128
claimConditionQuery.data &&
129129
claimConditionQuery.data?.currency !== ZERO_ADDRESS;
130130

131-
const tokenDecimalsQuery = useReadContract(decimals, {
131+
const currencyDecimalsQuery = useReadContract(decimals, {
132132
contract: currencyContract,
133133
queryOptions: {
134134
enabled: shouldFetchTokenDecimals,
135135
},
136136
});
137+
const tokenDecimalsQuery = useReadContract(decimals, {
138+
contract: contract,
139+
queryOptions: {
140+
enabled: props.contractInfo.name === "ClaimableERC20",
141+
},
142+
});
137143

138144
const mint = useCallback(
139145
async (values: MintFormValues) => {
@@ -258,17 +264,18 @@ function ClaimableModule(props: ModuleInstanceProps) {
258264
// claim conditions data is present
259265
claimConditionQuery.data &&
260266
// token decimals is fetched if it should be fetched
261-
(shouldFetchTokenDecimals ? tokenDecimalsQuery.isFetched : true)
267+
(shouldFetchTokenDecimals ? currencyDecimalsQuery.isFetched : true)
262268
? {
263269
claimCondition: claimConditionQuery.data,
270+
currencyDecimals: currencyDecimalsQuery.data,
264271
tokenDecimals: tokenDecimalsQuery.data,
265272
}
266273
: undefined,
267274
setClaimCondition,
268275
tokenId,
269276
isLoading:
270277
claimConditionQuery.isLoading ||
271-
(!!shouldFetchTokenDecimals && tokenDecimalsQuery.isLoading),
278+
(!!shouldFetchTokenDecimals && currencyDecimalsQuery.isLoading),
272279
}}
273280
isOwnerAccount={!!ownerAccount}
274281
name={props.contractInfo.name}
@@ -310,6 +317,7 @@ export function ClaimableModuleUI(
310317
data:
311318
| {
312319
claimCondition: ClaimConditionValue;
320+
currencyDecimals: number | undefined;
313321
tokenDecimals: number | undefined;
314322
}
315323
| undefined;
@@ -358,9 +366,8 @@ export function ClaimableModuleUI(
358366

359367
<div className="h-6" />
360368

361-
{props.isValidTokenId &&
362-
props.claimConditionSection.data &&
363-
!props.claimConditionSection.isLoading && (
369+
{props.name !== "ClaimableERC1155" || props.isValidTokenId ? (
370+
props.claimConditionSection.data ? (
364371
<ClaimConditionSection
365372
isOwnerAccount={props.isOwnerAccount}
366373
claimCondition={
@@ -370,16 +377,18 @@ export function ClaimableModuleUI(
370377
name={props.name}
371378
chainId={props.contractChainId}
372379
noClaimConditionSet={props.noClaimConditionSet}
380+
currencyDecimals={
381+
props.claimConditionSection.data?.currencyDecimals
382+
}
373383
tokenDecimals={
374384
props.claimConditionSection.data?.tokenDecimals
375385
}
376386
tokenId={props.claimConditionSection.tokenId}
377387
/>
378-
)}
379-
{props.isValidTokenId &&
380-
props.claimConditionSection.isLoading && (
388+
) : (
381389
<Skeleton className="h-[350px]" />
382-
)}
390+
)
391+
) : null}
383392
</AccordionContent>
384393
</AccordionItem>
385394

@@ -453,7 +462,8 @@ function ClaimConditionSection(props: {
453462
isOwnerAccount: boolean;
454463
name: string;
455464
chainId: number;
456-
tokenDecimals?: number;
465+
currencyDecimals?: number;
466+
tokenDecimals?: number | undefined;
457467
tokenId: string;
458468
noClaimConditionSet: boolean;
459469
}) {
@@ -473,18 +483,28 @@ function ClaimConditionSection(props: {
473483
: claimCondition?.currency,
474484
// default case is zero state, so 0 // 10 ** 18 still results in 0
475485
pricePerToken: Number(
476-
toTokens(claimCondition?.pricePerUnit, props.tokenDecimals || 18),
486+
toTokens(claimCondition?.pricePerUnit, props.currencyDecimals || 18),
477487
),
478488
maxClaimableSupply:
479489
claimCondition?.availableSupply.toString() === "0" ||
480490
claimCondition?.availableSupply.toString() === MAX_UINT_256
481491
? ""
482-
: claimCondition?.availableSupply.toString() || "",
492+
: props.name === "ClaimableERC20"
493+
? toTokens(
494+
claimCondition?.availableSupply,
495+
props.tokenDecimals || 18,
496+
)
497+
: claimCondition?.availableSupply.toString() || "",
483498
maxClaimablePerWallet:
484499
claimCondition?.maxMintPerWallet.toString() === "0" ||
485500
claimCondition?.maxMintPerWallet.toString() === MAX_UINT_256
486501
? ""
487-
: claimCondition?.maxMintPerWallet.toString() || "",
502+
: props.name === "ClaimableERC20"
503+
? toTokens(
504+
claimCondition?.maxMintPerWallet,
505+
props.tokenDecimals || 18,
506+
)
507+
: claimCondition?.maxMintPerWallet.toString() || "",
488508
startTime: claimCondition?.startTimestamp
489509
? fromUnixTime(claimCondition?.startTimestamp)
490510
: defaultStartDate,

apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/modules/components/claimable.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ function Component() {
176176
? undefined
177177
: {
178178
claimCondition,
179+
currencyDecimals: 18,
179180
tokenDecimals: 18,
180181
},
181182
isLoading: false,

0 commit comments

Comments
 (0)