|
2 | 2 | type BaseTransactionOptions, |
3 | 3 | type ThirdwebClient, |
4 | 4 | toTokens, |
| 5 | + toUnits, |
5 | 6 | } from "thirdweb"; |
6 | 7 | import type { OverrideEntry } from "thirdweb/dist/types/utils/extensions/drops/types"; |
7 | 8 | import type { Prettify } from "thirdweb/dist/types/utils/type-utils"; |
@@ -107,15 +108,41 @@ export async function getClaimPhasesInLegacyFormat( |
107 | 108 |
|
108 | 109 | type PhaseInput = z.input<typeof LegacyClaimConditionInputSchema>; |
109 | 110 |
|
110 | | -export function setClaimPhasesTx( |
| 111 | +export async function setClaimPhasesTx( |
111 | 112 | baseOptions: BaseTransactionOptions<Options>, |
112 | 113 | rawPhases: PhaseInput[], |
113 | 114 | ) { |
| 115 | + const tokenDecimals = |
| 116 | + baseOptions.type === "erc20" |
| 117 | + ? await ERC20Ext.decimals({ |
| 118 | + contract: baseOptions.contract, |
| 119 | + }).catch(() => 0) |
| 120 | + : 0; |
114 | 121 | 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 | + } |
115 | 136 | return { |
116 | 137 | 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), |
119 | 146 | merkleRootHash: phase.merkleRootHash as string | undefined, |
120 | 147 | overrideList: phase.snapshot?.length |
121 | 148 | ? snapshotToOverrides(phase.snapshot) |
|
0 commit comments