22 type BaseTransactionOptions ,
33 type ThirdwebClient ,
44 toTokens ,
5+ toUnits ,
56} from "thirdweb" ;
67import type { OverrideEntry } from "thirdweb/dist/types/utils/extensions/drops/types" ;
78import type { Prettify } from "thirdweb/dist/types/utils/type-utils" ;
@@ -42,6 +43,7 @@ type CombinedClaimCondition = Prettify<
4243type Options =
4344 | {
4445 type : "erc20" ;
46+ decimals ?: number ;
4547 }
4648 | {
4749 type : "erc721" ;
@@ -91,12 +93,18 @@ export async function getClaimPhasesInLegacyFormat(
9193 startTime : new Date ( Number ( condition . startTimestamp * 1000n ) ) ,
9294 currencyAddress : condition . currency ,
9395 price : condition . pricePerToken ,
94- maxClaimableSupply : toUnlimited ( condition . maxClaimableSupply ) ,
96+ maxClaimableSupply : toUnlimited (
97+ condition . maxClaimableSupply ,
98+ options . type === "erc20" ? currencyMetadata . decimals : undefined ,
99+ ) ,
95100 currencyMetadata,
96101 currentMintSupply : (
97102 condition . maxClaimableSupply - condition . supplyClaimed
98103 ) . toString ( ) ,
99- maxClaimablePerWallet : toUnlimited ( condition . quantityLimitPerWallet ) ,
104+ maxClaimablePerWallet : toUnlimited (
105+ condition . quantityLimitPerWallet ,
106+ options . type === "erc20" ? currencyMetadata . decimals : undefined ,
107+ ) ,
100108 merkleRootHash : condition . merkleRoot ,
101109 metadata,
102110 snapshot,
@@ -114,8 +122,14 @@ export function setClaimPhasesTx(
114122 const phases = rawPhases . map ( ( phase ) => {
115123 return {
116124 startTime : toDate ( phase . startTime ) ,
117- maxClaimableSupply : toBigInt ( phase . maxClaimableSupply ) ,
118- maxClaimablePerWallet : toBigInt ( phase . maxClaimablePerWallet ) ,
125+ maxClaimableSupply : toBigInt (
126+ phase . maxClaimableSupply ,
127+ baseOptions . type === "erc20" ? baseOptions . decimals : undefined ,
128+ ) ,
129+ maxClaimablePerWallet : toBigInt (
130+ phase . maxClaimablePerWallet ,
131+ baseOptions . type === "erc20" ? baseOptions . decimals : undefined ,
132+ ) ,
119133 merkleRootHash : phase . merkleRootHash as string | undefined ,
120134 overrideList : phase . snapshot ?. length
121135 ? snapshotToOverrides ( phase . snapshot )
@@ -175,18 +189,35 @@ function toDate(timestamp: number | Date | undefined) {
175189 }
176190 return new Date ( timestamp ) ;
177191}
178- function toBigInt ( value : string | number | undefined ) {
192+ function toBigInt (
193+ value : string | number | undefined ,
194+ decimals ?: number ,
195+ ) : bigint | undefined {
179196 if ( value === undefined ) {
180197 return undefined ;
181198 }
182199 if ( value === "unlimited" ) {
183200 return maxUint256 ;
184201 }
202+ // The ERC20Claim condition extension in v5 does not convert to wei for us
203+ // so we have to, manually
204+ if ( decimals ) {
205+ return toUnits ( value . toString ( ) , decimals ) ;
206+ }
207+
208+ // Will cause issue if trying to convert a non-integer string or number
209+ // thankfully the decimals logic above prevents it
185210 return BigInt ( value ) ;
186211}
187212
188- function toUnlimited ( value : bigint ) {
189- return value === maxUint256 ? "unlimited" : value . toString ( ) ;
213+ function toUnlimited ( value : bigint , decimals ?: number ) {
214+ if ( value === maxUint256 ) {
215+ return "unlimited" ;
216+ }
217+ if ( decimals ) {
218+ return toTokens ( value , decimals ) ;
219+ }
220+ return value . toString ( ) ;
190221}
191222
192223async function fetchSnapshot (
0 commit comments