Skip to content

Commit 22927c0

Browse files
committed
Update
1 parent 519349b commit 22927c0

File tree

4 files changed

+71
-8
lines changed

4 files changed

+71
-8
lines changed

apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/_components/claim-conditions/claim-conditions-form/hooks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ function toDate(timestamp: number | Date | undefined) {
175175
}
176176
return new Date(timestamp);
177177
}
178-
function toBigInt(value: string | number | undefined) {
178+
export function toBigInt(value: string | number | undefined) {
179179
if (value === undefined) {
180180
return undefined;
181181
}

apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/_components/claim-conditions/claim-conditions-form/index.tsx

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ import {
2626
useFieldArray,
2727
useForm,
2828
} from "react-hook-form";
29+
import { toast } from "sonner";
2930
import {
3031
NATIVE_TOKEN_ADDRESS,
3132
type ThirdwebContract,
3233
ZERO_ADDRESS,
34+
toUnits,
3335
} from "thirdweb";
3436
import { decimals } from "thirdweb/extensions/erc20";
3537
import {
@@ -48,7 +50,11 @@ import {
4850
} from "../legacy-zod-schema";
4951
import { ResetClaimEligibility } from "../reset-claim-eligibility";
5052
import { SnapshotUpload } from "../snapshot-upload";
51-
import { getClaimPhasesInLegacyFormat, setClaimPhasesTx } from "./hooks";
53+
import {
54+
getClaimPhasesInLegacyFormat,
55+
setClaimPhasesTx,
56+
toBigInt,
57+
} from "./hooks";
5258
import { ClaimConditionsPhase } from "./phase";
5359

5460
type ClaimConditionDashboardInput = ClaimConditionInput & {
@@ -355,6 +361,31 @@ export const ClaimConditionsForm: React.FC<ClaimConditionsFormProps> = ({
355361
});
356362

357363
try {
364+
if (isErc20 && !tokenDecimalsData) {
365+
return toast.error("Could not fetch token metadata");
366+
}
367+
368+
// For ERC20 claim condition, we need to convert `maxClaimableSupply` and `maxClaimbablePerWallet` to wei
369+
const phases = isErc20
370+
? d.phases.map((item) => {
371+
item.maxClaimableSupply =
372+
item.maxClaimableSupply !== undefined
373+
? toUnits(
374+
String(toBigInt(item.maxClaimableSupply)).toString(),
375+
tokenDecimalsData,
376+
).toString()
377+
: undefined;
378+
item.maxClaimablePerWallet =
379+
item.maxClaimablePerWallet !== undefined
380+
? toUnits(
381+
String(toBigInt(item.maxClaimablePerWallet)),
382+
tokenDecimalsData,
383+
).toString()
384+
: undefined;
385+
return item;
386+
})
387+
: d.phases;
388+
358389
const tx = setClaimPhasesTx(
359390
{
360391
contract,
@@ -364,7 +395,7 @@ export const ClaimConditionsForm: React.FC<ClaimConditionsFormProps> = ({
364395
? { type: "erc721" }
365396
: { type: "erc1155", tokenId: BigInt(tokenId || 0) }),
366397
},
367-
d.phases,
398+
phases,
368399
);
369400
await sendTx.mutateAsync(tx);
370401
trackEvent({
@@ -630,7 +661,10 @@ export const ClaimConditionsForm: React.FC<ClaimConditionsFormProps> = ({
630661
colorScheme="primary"
631662
txChainID={contract.chain.id}
632663
transactionCount={1}
633-
isDisabled={claimConditionsQuery.isPending}
664+
isDisabled={
665+
claimConditionsQuery.isPending ||
666+
(isErc20 && tokenDecimals.isPending)
667+
}
634668
type="submit"
635669
isLoading={sendTx.isPending}
636670
loadingText="Saving..."

apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/_components/claim-conditions/claim-conditions-form/phase.tsx

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { AdminOnly } from "@3rdweb-sdk/react/components/roles/admin-only";
22
import { Flex, SimpleGrid } from "@chakra-ui/react";
33
import { ChevronDownIcon, ChevronUpIcon, XIcon } from "lucide-react";
4-
import type { ThirdwebContract } from "thirdweb";
4+
import { type ThirdwebContract, toTokens } from "thirdweb";
5+
import { maxUint256 } from "thirdweb/utils";
56
import { Badge, Button, Card, Heading, Text } from "tw-components";
67
import { ClaimConditionTypeData, useClaimConditionsFormContext } from ".";
78
import { PricePreview } from "../price-preview";
@@ -34,6 +35,7 @@ export const ClaimConditionsPhase: React.FC<ClaimConditionsPhaseProps> = ({
3435
isActive,
3536
isMultiPhase,
3637
phaseIndex,
38+
tokenDecimals,
3739
} = useClaimConditionsFormContext();
3840

3941
const toggleEditing = () => {
@@ -102,7 +104,18 @@ export const ClaimConditionsPhase: React.FC<ClaimConditionsPhaseProps> = ({
102104
<Text fontWeight="bold">
103105
{isErc20 ? "Tokens" : "NFTs"} to drop
104106
</Text>
105-
<Text textTransform="capitalize">{field.maxClaimableSupply}</Text>
107+
<Text textTransform="capitalize">
108+
{field.maxClaimableSupply === "unlimited"
109+
? "Unlimited"
110+
: isErc20 && field.maxClaimableSupply
111+
? BigInt(field.maxClaimableSupply) === maxUint256
112+
? "Unlimited"
113+
: toTokens(
114+
BigInt(field.maxClaimableSupply),
115+
tokenDecimals,
116+
)
117+
: field.maxClaimableSupply}
118+
</Text>
106119
</div>
107120
<PricePreview
108121
price={field.price}
@@ -117,7 +130,16 @@ export const ClaimConditionsPhase: React.FC<ClaimConditionsPhaseProps> = ({
117130
<Text>Unlimited</Text>
118131
) : (
119132
<Text textTransform="capitalize">
120-
{field.maxClaimablePerWallet}
133+
{field.maxClaimablePerWallet === "unlimited"
134+
? "Unlimited"
135+
: isErc20 && field.maxClaimablePerWallet
136+
? BigInt(field.maxClaimablePerWallet) === maxUint256
137+
? "Unlimited"
138+
: toTokens(
139+
BigInt(field.maxClaimablePerWallet),
140+
tokenDecimals,
141+
)
142+
: field.maxClaimablePerWallet}
121143
</Text>
122144
)}
123145
</div>

apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/_components/claim-conditions/quantity-input-with-unlimited.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
InputRightElement,
66
} from "@chakra-ui/react";
77
import { useEffect, useState } from "react";
8+
import { toTokens } from "thirdweb";
89
import { Button } from "tw-components";
910

1011
interface QuantityInputWithUnlimitedProps
@@ -60,7 +61,13 @@ export const QuantityInputWithUnlimited: React.FC<
6061
if (value === "unlimited") {
6162
setStringValue("unlimited");
6263
} else if (!Number.isNaN(Number(value))) {
63-
setStringValue(Number(Number(value).toFixed(decimals)).toString());
64+
if (decimals) {
65+
setStringValue(toTokens(BigInt(value), decimals));
66+
} else {
67+
setStringValue(
68+
Number(Number(value).toFixed(decimals)).toString(),
69+
);
70+
}
6471
} else {
6572
setStringValue("0");
6673
}

0 commit comments

Comments
 (0)