Skip to content

Commit 78924f2

Browse files
committed
cleanup
1 parent 10db1e2 commit 78924f2

File tree

10 files changed

+171
-92
lines changed

10 files changed

+171
-92
lines changed

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

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

5757
export async function getClaimPhasesInLegacyFormat(
58-
options: BaseTransactionOptions<Options> & { isSinglePhase?: boolean },
58+
options: BaseTransactionOptions<Options>,
5959
): Promise<CombinedClaimCondition[]> {
6060
const conditions = await (async () => {
6161
switch (options.type) {
6262
case "erc20":
6363
return ERC20Ext.getClaimConditions(options);
6464
case "erc721":
6565
return ERC721Ext.getClaimConditions(options);
66-
case "erc1155": {
66+
case "erc1155":
6767
return ERC1155Ext.getClaimConditions(options);
68-
}
6968
}
7069
})();
7170

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

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

223223
const claimConditionsQuery = useReadContract(getClaimPhasesInLegacyFormat, {
224224
contract,
225-
isSinglePhase: !isMultiPhase,
226225
...(isErc20
227226
? { type: "erc20", decimals: tokenDecimals.data }
228227
: isErc721
@@ -640,6 +639,7 @@ export const ClaimConditionsForm: React.FC<ClaimConditionsFormProps> = ({
640639
isErc20={isErc20}
641640
contract={contract}
642641
tokenId={tokenId}
642+
isMultiphase={isMultiPhase}
643643
/>
644644
)}
645645
</div>

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ interface ResetClaimEligibilityProps {
1818
contract: ThirdwebContract;
1919
tokenId?: string;
2020
twAccount: Account | undefined;
21+
isMultiphase: boolean;
2122
}
2223

2324
export const ResetClaimEligibility: React.FC<ResetClaimEligibilityProps> = ({
2425
contract,
2526
tokenId,
2627
isErc20,
2728
twAccount,
29+
isMultiphase,
2830
}) => {
2931
const trackEvent = useTrack();
3032

@@ -55,6 +57,7 @@ export const ResetClaimEligibility: React.FC<ResetClaimEligibilityProps> = ({
5557
return ERC1155Ext.resetClaimEligibility({
5658
contract,
5759
tokenId: BigInt(tokenId),
60+
singlePhaseDrop: !isMultiphase,
5861
});
5962
}
6063
// assume erc 721
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[
22
"function claim(address receiver, uint256 tokenId, uint256 quantity, address currency, uint256 pricePerToken, (bytes32[] proof, uint256 quantityLimitPerWallet, uint256 pricePerToken, address currency) allowlistProof, bytes data) payable",
33
"function setClaimConditions(uint256 tokenId, (uint256 startTimestamp, uint256 maxClaimableSupply, uint256 supplyClaimed, uint256 quantityLimitPerWallet, bytes32 merkleRoot, uint256 pricePerToken, address currency, string metadata) phase, bool resetClaimEligibility)",
4-
"function claimCondition(uint256 tokenId) view returns ((uint256 startTimestamp, uint256 maxClaimableSupply, uint256 supplyClaimed, uint256 quantityLimitPerWallet, bytes32 merkleRoot, uint256 pricePerToken, address currency, string metadata) condition)",
4+
"function claimCondition(uint256 tokenId) view returns (uint256 startTimestamp, uint256 maxClaimableSupply, uint256 supplyClaimed, uint256 quantityLimitPerWallet, bytes32 merkleRoot, uint256 pricePerToken, address currency, string metadata)",
55
"event ClaimConditionUpdated(uint256 indexed tokenId, (uint256 startTimestamp, uint256 maxClaimableSupply, uint256 supplyClaimed, uint256 quantityLimitPerWallet, bytes32 merkleRoot, uint256 pricePerToken, address currency, string metadata) condition, bool resetEligibility)",
66
"event TokensClaimed(address indexed claimer, address indexed receiver, uint256 indexed tokenId, uint256 quantityClaimed)"
77
]

packages/thirdweb/src/exports/extensions/erc1155.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ export {
112112
type CanClaimParams,
113113
type CanClaimResult,
114114
} from "../../extensions/erc1155/drops/read/canClaim.js";
115+
export { claimCondition } from "../../extensions/erc1155/__generated__/IDropSinglePhase1155/read/claimCondition.js";
115116

116117
// WRITE
117118
export {

packages/thirdweb/src/extensions/erc1155/__generated__/IDropSinglePhase1155/read/claimCondition.ts

Lines changed: 31 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,43 @@ export type GetActiveClaimConditionParams = GetActiveClaimConditionIdParams;
3030
export async function getActiveClaimCondition(
3131
options: BaseTransactionOptions<GetActiveClaimConditionParams>,
3232
): Promise<ClaimCondition> {
33-
try {
33+
const getActiveClaimConditionMultiPhase = async () => {
3434
const conditionId = await getActiveClaimConditionId(options);
3535
return getClaimConditionById({ ...options, conditionId });
36-
} catch {
37-
// try single phase
38-
try {
39-
return claimCondition({ ...options });
40-
} catch {
41-
throw new Error("Claim condition not found");
42-
}
36+
};
37+
38+
const getActiveClaimConditionSinglePhase = async () => {
39+
const [
40+
startTimestamp,
41+
maxClaimableSupply,
42+
supplyClaimed,
43+
quantityLimitPerWallet,
44+
merkleRoot,
45+
pricePerToken,
46+
currency,
47+
metadata,
48+
] = await claimCondition({ ...options, tokenId: options.tokenId });
49+
return {
50+
startTimestamp,
51+
maxClaimableSupply,
52+
supplyClaimed,
53+
quantityLimitPerWallet,
54+
merkleRoot,
55+
pricePerToken,
56+
currency,
57+
metadata,
58+
};
59+
};
60+
const results = await Promise.allSettled([
61+
getActiveClaimConditionMultiPhase(),
62+
getActiveClaimConditionSinglePhase(),
63+
]);
64+
65+
const condition = results.find((result) => result.status === "fulfilled");
66+
if (condition?.status === "fulfilled") {
67+
return condition.value;
4368
}
69+
throw new Error("Claim condition not found");
4470
}
4571

4672
/**

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

Lines changed: 48 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ import type { BaseTransactionOptions } from "../../../../transaction/types.js";
22
import type { ClaimCondition } from "../../../../utils/extensions/drops/types.js";
33
import * as MultiPhase from "../../__generated__/IDrop1155/read/claimCondition.js";
44
import * as MultiById from "../../__generated__/IDrop1155/read/getClaimConditionById.js";
5-
import {
6-
claimCondition as claimConditionSinglePhase,
7-
isClaimConditionSupported,
8-
} from "../../__generated__/IDropSinglePhase1155/read/claimCondition.js";
5+
import * as SinglePhase from "../../__generated__/IDropSinglePhase1155/read/claimCondition.js";
96

107
export type GetClaimConditionsParams = {
118
tokenId: bigint;
@@ -23,32 +20,55 @@ export type GetClaimConditionsParams = {
2320
* ```
2421
*/
2522
export async function getClaimConditions(
26-
options: BaseTransactionOptions<GetClaimConditionsParams> & {
27-
isSinglePhase?: boolean;
28-
},
23+
options: BaseTransactionOptions<GetClaimConditionsParams>,
2924
): Promise<ClaimCondition[]> {
30-
try {
31-
if (options.isSinglePhase) {
32-
return Promise.all([claimConditionSinglePhase({ ...options })]);
33-
}
25+
const [multi, single] = await Promise.allSettled([
26+
(async () => {
27+
const [startId, count] = await MultiPhase.claimCondition(options);
3428

35-
const [startId, count] = await MultiPhase.claimCondition(options);
36-
37-
const conditionPromises: Array<
38-
ReturnType<typeof MultiById.getClaimConditionById>
39-
> = [];
40-
for (let i = startId; i < startId + count; i++) {
41-
conditionPromises.push(
42-
MultiById.getClaimConditionById({
43-
...options,
44-
conditionId: i,
45-
}),
46-
);
47-
}
48-
return Promise.all(conditionPromises);
49-
} catch {
50-
throw new Error("Claim condition not found");
29+
const conditionPromises: Array<
30+
ReturnType<typeof MultiById.getClaimConditionById>
31+
> = [];
32+
for (let i = startId; i < startId + count; i++) {
33+
conditionPromises.push(
34+
MultiById.getClaimConditionById({
35+
...options,
36+
conditionId: i,
37+
}),
38+
);
39+
}
40+
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;
66+
}
67+
if (single.status === "fulfilled") {
68+
return [single.value];
5169
}
70+
71+
throw new Error("Claim condition not found");
5272
}
5373

5474
/**
@@ -68,6 +88,6 @@ export function isGetClaimConditionsSupported(availableSelectors: string[]) {
6888
return (
6989
(MultiPhase.isClaimConditionSupported(availableSelectors) &&
7090
MultiById.isGetClaimConditionByIdSupported(availableSelectors)) ||
71-
isClaimConditionSupported(availableSelectors)
91+
SinglePhase.isClaimConditionSupported(availableSelectors)
7292
);
7393
}

packages/thirdweb/src/extensions/erc1155/drops/write/resetClaimEligibility.ts

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@ import type { BaseTransactionOptions } from "../../../../transaction/types.js";
33
import type { ClaimCondition } from "../../../../utils/extensions/drops/types.js";
44
import {
55
isSetClaimConditionsSupported,
6-
setClaimConditions,
6+
setClaimConditions as setClaimConditionsMultiPhase,
77
} from "../../__generated__/IDrop1155/write/setClaimConditions.js";
8-
import { isClaimConditionSupported } from "../../__generated__/IDropSinglePhase1155/read/claimCondition.js";
9-
import { isSetClaimConditionsSupported as isSetClaimConditionsSupportedGeneratedSinglePhase } from "../../__generated__/IDropSinglePhase1155/write/setClaimConditions.js";
8+
import {
9+
claimCondition as claimConditionSinglePhase,
10+
isClaimConditionSupported,
11+
} from "../../__generated__/IDropSinglePhase1155/read/claimCondition.js";
12+
import {
13+
isSetClaimConditionsSupported as isSetClaimConditionsSupportedGeneratedSinglePhase,
14+
setClaimConditions as setClaimConditionsSinglePhase,
15+
} from "../../__generated__/IDropSinglePhase1155/write/setClaimConditions.js";
1016
import {
1117
type GetClaimConditionsParams,
1218
getClaimConditions,
@@ -33,10 +39,49 @@ export type ResetClaimEligibilityParams = GetClaimConditionsParams;
3339
* ```
3440
*/
3541
export function resetClaimEligibility(
36-
options: BaseTransactionOptions<ResetClaimEligibilityParams>,
42+
options: BaseTransactionOptions<ResetClaimEligibilityParams> & {
43+
singlePhaseDrop?: boolean;
44+
},
3745
) {
46+
if (options.singlePhaseDrop) {
47+
return setClaimConditionsSinglePhase({
48+
contract: options.contract,
49+
asyncParams: async () => {
50+
// get existing condition
51+
const existingCondition = await claimConditionSinglePhase(options).then(
52+
([
53+
startTimestamp,
54+
maxClaimableSupply,
55+
supplyClaimed,
56+
quantityLimitPerWallet,
57+
merkleRoot,
58+
pricePerToken,
59+
currency,
60+
metadata,
61+
]) => ({
62+
startTimestamp,
63+
maxClaimableSupply,
64+
supplyClaimed,
65+
quantityLimitPerWallet,
66+
merkleRoot,
67+
pricePerToken,
68+
currency,
69+
metadata,
70+
}),
71+
);
72+
73+
// then simply return the exact same ones, but with the resetClaimEligibility flag set to true
74+
return {
75+
tokenId: options.tokenId,
76+
// type is necessary because of viem hex shenanigans (strict vs non-strict `0x` prefix string)
77+
phase: existingCondition,
78+
resetClaimEligibility: true,
79+
};
80+
},
81+
});
82+
}
3883
// download existing conditions
39-
return setClaimConditions({
84+
return setClaimConditionsMultiPhase({
4085
contract: options.contract,
4186
asyncParams: async () => {
4287
// get existing conditions

packages/thirdweb/src/utils/extensions/drops/get-claim-params.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,6 @@ export async function getClaimParams(options: GetClaimParamsOptions) {
5050
const cc: ClaimCondition = await (async () => {
5151
if (options.type === "erc1155") {
5252
// lazy-load the getActiveClaimCondition function
53-
if (options.singlePhaseDrop) {
54-
const { claimCondition } = await import(
55-
"../../../extensions/erc1155/__generated__/IDropSinglePhase1155/read/claimCondition.js"
56-
);
57-
return await claimCondition({
58-
contract: options.contract,
59-
tokenId: options.tokenId,
60-
});
61-
}
6253
const { getActiveClaimCondition } = await import(
6354
"../../../extensions/erc1155/drops/read/getActiveClaimCondition.js"
6455
);

0 commit comments

Comments
 (0)