Skip to content

Commit c86cac4

Browse files
authored
Fix getClaimConditions (#6701)
1 parent af09576 commit c86cac4

File tree

3 files changed

+38
-35
lines changed
  • apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/_components/claim-conditions/claim-conditions-form
  • packages/thirdweb/src/extensions/erc1155/drops/read

3 files changed

+38
-35
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ type Options =
5555
};
5656

5757
export async function getClaimPhasesInLegacyFormat(
58-
options: BaseTransactionOptions<Options>,
58+
options: BaseTransactionOptions<Options> & { isMultiPhase: boolean },
5959
): Promise<CombinedClaimCondition[]> {
6060
const conditions = await (async () => {
6161
switch (options.type) {
@@ -64,7 +64,10 @@ export async function getClaimPhasesInLegacyFormat(
6464
case "erc721":
6565
return ERC721Ext.getClaimConditions(options);
6666
case "erc1155":
67-
return ERC1155Ext.getClaimConditions(options);
67+
return ERC1155Ext.getClaimConditions({
68+
...options,
69+
singlePhaseDrop: !options.isMultiPhase,
70+
});
6871
}
6972
})();
7073

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ export const ClaimConditionsForm: React.FC<ClaimConditionsFormProps> = ({
222222

223223
const claimConditionsQuery = useReadContract(getClaimPhasesInLegacyFormat, {
224224
contract,
225+
isMultiPhase,
225226
...(isErc20
226227
? { type: "erc20", decimals: tokenDecimals.data }
227228
: isErc721

packages/thirdweb/src/extensions/erc1155/drops/read/getClaimConditions.ts

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,36 @@ export type GetClaimConditionsParams = {
2020
* ```
2121
*/
2222
export async function getClaimConditions(
23-
options: BaseTransactionOptions<GetClaimConditionsParams>,
23+
options: BaseTransactionOptions<GetClaimConditionsParams> & {
24+
singlePhaseDrop?: boolean;
25+
},
2426
): Promise<ClaimCondition[]> {
25-
const [multi, single] = await Promise.allSettled([
26-
(async () => {
27+
try {
28+
if (options.singlePhaseDrop) {
29+
return SinglePhase.claimCondition(options).then(
30+
([
31+
startTimestamp,
32+
maxClaimableSupply,
33+
supplyClaimed,
34+
quantityLimitPerWallet,
35+
merkleRoot,
36+
pricePerToken,
37+
currency,
38+
metadata,
39+
]) => [
40+
{
41+
startTimestamp,
42+
maxClaimableSupply,
43+
supplyClaimed,
44+
quantityLimitPerWallet,
45+
merkleRoot,
46+
pricePerToken,
47+
currency,
48+
metadata,
49+
},
50+
],
51+
);
52+
} else {
2753
const [startId, count] = await MultiPhase.claimCondition(options);
2854

2955
const conditionPromises: Array<
@@ -38,37 +64,10 @@ export async function getClaimConditions(
3864
);
3965
}
4066
return Promise.all(conditionPromises);
41-
})(),
42-
SinglePhase.claimCondition(options).then(
43-
([
44-
startTimestamp,
45-
maxClaimableSupply,
46-
supplyClaimed,
47-
quantityLimitPerWallet,
48-
merkleRoot,
49-
pricePerToken,
50-
currency,
51-
metadata,
52-
]) => ({
53-
startTimestamp,
54-
maxClaimableSupply,
55-
supplyClaimed,
56-
quantityLimitPerWallet,
57-
merkleRoot,
58-
pricePerToken,
59-
currency,
60-
metadata,
61-
}),
62-
),
63-
]);
64-
if (multi.status === "fulfilled") {
65-
return multi.value;
67+
}
68+
} catch {
69+
throw new Error("Claim condition not found");
6670
}
67-
if (single.status === "fulfilled") {
68-
return [single.value];
69-
}
70-
71-
throw new Error("Claim condition not found");
7271
}
7372

7473
/**

0 commit comments

Comments
 (0)