From 2a27e74546b5d5d8ad2fb1065e53c52eca59f380 Mon Sep 17 00:00:00 2001 From: Kien Ngo Date: Wed, 30 Oct 2024 23:02:28 +0700 Subject: [PATCH] Update --- .../claim-conditions-form/hooks.ts | 33 +++++++++++++++++-- .../claim-conditions-form/index.tsx | 2 +- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/_components/claim-conditions/claim-conditions-form/hooks.ts b/apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/_components/claim-conditions/claim-conditions-form/hooks.ts index 80c02dd8cfa..a8917cfe112 100644 --- a/apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/_components/claim-conditions/claim-conditions-form/hooks.ts +++ b/apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/_components/claim-conditions/claim-conditions-form/hooks.ts @@ -2,6 +2,7 @@ import { type BaseTransactionOptions, type ThirdwebClient, toTokens, + toUnits, } from "thirdweb"; import type { OverrideEntry } from "thirdweb/dist/types/utils/extensions/drops/types"; import type { Prettify } from "thirdweb/dist/types/utils/type-utils"; @@ -107,15 +108,41 @@ export async function getClaimPhasesInLegacyFormat( type PhaseInput = z.input; -export function setClaimPhasesTx( +export async function setClaimPhasesTx( baseOptions: BaseTransactionOptions, rawPhases: PhaseInput[], ) { + const tokenDecimals = + baseOptions.type === "erc20" + ? await ERC20Ext.decimals({ + contract: baseOptions.contract, + }).catch(() => 0) + : 0; const phases = rawPhases.map((phase) => { + let _maxClaimable = toBigInt(phase.maxClaimableSupply); + if (typeof _maxClaimable === "bigint" && _maxClaimable !== maxUint256) { + _maxClaimable = toUnits(String(_maxClaimable), tokenDecimals); + } + let _maxClaimablePerWallet = toBigInt(phase.maxClaimablePerWallet); + if ( + typeof _maxClaimablePerWallet === "bigint" && + _maxClaimablePerWallet !== maxUint256 + ) { + _maxClaimablePerWallet = toUnits( + String(_maxClaimablePerWallet), + tokenDecimals, + ); + } return { startTime: toDate(phase.startTime), - maxClaimableSupply: toBigInt(phase.maxClaimableSupply), - maxClaimablePerWallet: toBigInt(phase.maxClaimablePerWallet), + maxClaimableSupply: + baseOptions.type === "erc20" + ? _maxClaimable + : toBigInt(phase.maxClaimableSupply), + maxClaimablePerWallet: + baseOptions.type === "erc20" + ? _maxClaimablePerWallet + : toBigInt(phase.maxClaimablePerWallet), merkleRootHash: phase.merkleRootHash as string | undefined, overrideList: phase.snapshot?.length ? snapshotToOverrides(phase.snapshot) diff --git a/apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/_components/claim-conditions/claim-conditions-form/index.tsx b/apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/_components/claim-conditions/claim-conditions-form/index.tsx index 791fc990776..6a4bf173281 100644 --- a/apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/_components/claim-conditions/claim-conditions-form/index.tsx +++ b/apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/_components/claim-conditions/claim-conditions-form/index.tsx @@ -355,7 +355,7 @@ export const ClaimConditionsForm: React.FC = ({ }); try { - const tx = setClaimPhasesTx( + const tx = await setClaimPhasesTx( { contract, ...(isErc20