Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
kien-ngo committed Oct 30, 2024
1 parent 519349b commit 2a27e74
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -107,15 +108,41 @@ export async function getClaimPhasesInLegacyFormat(

type PhaseInput = z.input<typeof LegacyClaimConditionInputSchema>;

export function setClaimPhasesTx(
export async function setClaimPhasesTx(
baseOptions: BaseTransactionOptions<Options>,
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ export const ClaimConditionsForm: React.FC<ClaimConditionsFormProps> = ({
});

try {
const tx = setClaimPhasesTx(
const tx = await setClaimPhasesTx(
{
contract,
...(isErc20
Expand Down

0 comments on commit 2a27e74

Please sign in to comment.