Skip to content

Commit c1adba1

Browse files
committed
Update display value
1 parent 519349b commit c1adba1

File tree

4 files changed

+57
-8
lines changed

4 files changed

+57
-8
lines changed

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

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
type BaseTransactionOptions,
33
type ThirdwebClient,
44
toTokens,
5+
toUnits,
56
} from "thirdweb";
67
import type { OverrideEntry } from "thirdweb/dist/types/utils/extensions/drops/types";
78
import type { Prettify } from "thirdweb/dist/types/utils/type-utils";
@@ -107,15 +108,41 @@ export async function getClaimPhasesInLegacyFormat(
107108

108109
type PhaseInput = z.input<typeof LegacyClaimConditionInputSchema>;
109110

110-
export function setClaimPhasesTx(
111+
export async function setClaimPhasesTx(
111112
baseOptions: BaseTransactionOptions<Options>,
112113
rawPhases: PhaseInput[],
113114
) {
115+
const tokenDecimals =
116+
baseOptions.type === "erc20"
117+
? await ERC20Ext.decimals({
118+
contract: baseOptions.contract,
119+
}).catch(() => 0)
120+
: 0;
114121
const phases = rawPhases.map((phase) => {
122+
let _maxClaimable = toBigInt(phase.maxClaimableSupply);
123+
if (typeof _maxClaimable === "bigint" && _maxClaimable !== maxUint256) {
124+
_maxClaimable = toUnits(String(_maxClaimable), tokenDecimals);
125+
}
126+
let _maxClaimablePerWallet = toBigInt(phase.maxClaimablePerWallet);
127+
if (
128+
typeof _maxClaimablePerWallet === "bigint" &&
129+
_maxClaimablePerWallet !== maxUint256
130+
) {
131+
_maxClaimablePerWallet = toUnits(
132+
String(_maxClaimablePerWallet),
133+
tokenDecimals,
134+
);
135+
}
115136
return {
116137
startTime: toDate(phase.startTime),
117-
maxClaimableSupply: toBigInt(phase.maxClaimableSupply),
118-
maxClaimablePerWallet: toBigInt(phase.maxClaimablePerWallet),
138+
maxClaimableSupply:
139+
baseOptions.type === "erc20"
140+
? _maxClaimable
141+
: toBigInt(phase.maxClaimableSupply),
142+
maxClaimablePerWallet:
143+
baseOptions.type === "erc20"
144+
? _maxClaimablePerWallet
145+
: toBigInt(phase.maxClaimablePerWallet),
119146
merkleRootHash: phase.merkleRootHash as string | undefined,
120147
overrideList: phase.snapshot?.length
121148
? snapshotToOverrides(phase.snapshot)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ export const ClaimConditionsForm: React.FC<ClaimConditionsFormProps> = ({
355355
});
356356

357357
try {
358-
const tx = setClaimPhasesTx(
358+
const tx = await setClaimPhasesTx(
359359
{
360360
contract,
361361
...(isErc20

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

Lines changed: 18 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,13 @@ 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+
{isErc20 && field.maxClaimableSupply
109+
? BigInt(field.maxClaimableSupply) === maxUint256
110+
? "Unlimited"
111+
: toTokens(BigInt(field.maxClaimableSupply), tokenDecimals)
112+
: field.maxClaimableSupply}
113+
</Text>
106114
</div>
107115
<PricePreview
108116
price={field.price}
@@ -117,7 +125,14 @@ export const ClaimConditionsPhase: React.FC<ClaimConditionsPhaseProps> = ({
117125
<Text>Unlimited</Text>
118126
) : (
119127
<Text textTransform="capitalize">
120-
{field.maxClaimablePerWallet}
128+
{isErc20 && field.maxClaimablePerWallet
129+
? BigInt(field.maxClaimablePerWallet) === maxUint256
130+
? "Unlimited"
131+
: toTokens(
132+
BigInt(field.maxClaimablePerWallet),
133+
tokenDecimals,
134+
)
135+
: field.maxClaimablePerWallet}
121136
</Text>
122137
)}
123138
</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)