Skip to content

Commit b663959

Browse files
committed
[Update] Refactor claim conditions detection and NFT page handling (#4379)
<!-- start pr-codex --> ## PR-Codex overview The focus of this PR is to update the NFT overview page to include an `isErc721` flag and adjust features detection in NFT drawer tabs. ### Detailed summary - Added `isErc721` flag to NFT overview page props - Adjusted features detection in NFT drawer tabs for ERC20 - Refactored feature detection in contract route configuration > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent ad61b64 commit b663959

File tree

3 files changed

+33
-27
lines changed

3 files changed

+33
-27
lines changed

apps/dashboard/src/contract-ui/hooks/useRouteConfig.tsx

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { useContract } from "@thirdweb-dev/react";
22
import { extensionDetectedState } from "components/buttons/ExtensionDetectButton";
33
import { useEns } from "components/contract-components/hooks";
4-
import { detectFeatures } from "components/contract-components/utils";
54
import { ContractOverviewPage } from "contract-ui/tabs/overview/page";
65
import type { EnhancedRoute } from "contract-ui/types/types";
76
import dynamic from "next/dynamic";
@@ -210,29 +209,32 @@ export function useContractRouteConfig(
210209
],
211210
});
212211

213-
const hasNewClaimConditions = detectFeatures(contractQuery.contract, [
214-
// erc721
215-
"ERC721ClaimConditionsV2",
216-
"ERC721ClaimPhasesV2",
217-
// erc1155
218-
"ERC1155ClaimConditionsV2",
219-
"ERC1155ClaimPhasesV2",
220-
// erc20
221-
"ERC20ClaimConditionsV2",
222-
"ERC20ClaimPhasesV2",
223-
]);
212+
const hasNewClaimConditions = extensionDetectedState({
213+
contractQuery,
214+
feature: [
215+
// erc721
216+
"ERC721ClaimConditionsV2",
217+
"ERC721ClaimPhasesV2",
218+
// erc1155
219+
"ERC1155ClaimConditionsV2",
220+
"ERC1155ClaimPhasesV2",
221+
// erc20
222+
"ERC20ClaimConditionsV2",
223+
"ERC20ClaimPhasesV2",
224+
],
225+
});
224226

225-
const hasMultiPhaseClaimConditions = detectFeatures(
226-
contractQuery.contract,
227-
[
227+
const hasMultiPhaseClaimConditions = extensionDetectedState({
228+
contractQuery,
229+
feature: [
228230
// erc721
229231
"ERC721ClaimPhasesV2",
230232
// erc1155
231233
"ERC1155ClaimPhasesV2",
232234
// erc20
233235
"ERC20ClaimPhasesV2",
234236
],
235-
);
237+
});
236238

237239
return {
238240
claimconditionExtensionDetection,
@@ -354,7 +356,12 @@ export function useContractRouteConfig(
354356
: isERC721Query.isLoading || isERC1155Query.isLoading
355357
? "loading"
356358
: "disabled",
357-
component: () => <LazyContractNFTPage contract={contract} />,
359+
component: () => (
360+
<LazyContractNFTPage
361+
contract={contract}
362+
isErc721={isERC721Query.data || false}
363+
/>
364+
),
358365
},
359366
{
360367
title: "Tokens",
@@ -420,8 +427,10 @@ export function useContractRouteConfig(
420427
contractData.claimconditionExtensionDetection
421428
}
422429
isERC20={isERC20}
423-
hasNewClaimConditions={contractData.hasNewClaimConditions}
424-
isMultiPhase={contractData.hasMultiPhaseClaimConditions}
430+
hasNewClaimConditions={
431+
contractData.hasNewClaimConditions === "enabled"
432+
}
433+
isMultiPhase={contractData.hasMultiPhaseClaimConditions === "enabled"}
425434
/>
426435
),
427436
},

apps/dashboard/src/contract-ui/tabs/nfts/page.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { TokenIdPage } from "./components/token-id";
1717

1818
interface NftOverviewPageProps {
1919
contract: ThirdwebContract;
20+
isErc721: boolean;
2021
}
2122

2223
function isOnlyNumbers(str: string) {
@@ -25,11 +26,11 @@ function isOnlyNumbers(str: string) {
2526

2627
export const ContractNFTPage: React.FC<NftOverviewPageProps> = ({
2728
contract,
29+
isErc721,
2830
}) => {
2931
const contractQuery = useContract(contract.address);
3032
const router = useRouter();
3133
const tokenId = router.query?.paths?.[2];
32-
const isErc721 = detectFeatures(contractQuery?.contract, ["ERC721"]);
3334

3435
if (tokenId && isOnlyNumbers(tokenId)) {
3536
return (

apps/dashboard/src/core-ui/nft-drawer/useNftDrawerTabs.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,6 @@ export function useNFTDrawerTabs({
8181
// erc1155
8282
"ERC1155ClaimConditionsV2",
8383
"ERC1155ClaimPhasesV2",
84-
// erc20
85-
"ERC20ClaimConditionsV2",
86-
"ERC20ClaimPhasesV2",
8784
]),
8885
[oldContract],
8986
);
@@ -94,18 +91,17 @@ export function useNFTDrawerTabs({
9491
"ERC721ClaimPhasesV2",
9592
// erc1155
9693
"ERC1155ClaimPhasesV2",
97-
// erc20
98-
"ERC20ClaimPhasesV2",
9994
]),
10095
[oldContract],
10196
);
10297
const contractInfo = useMemo(() => {
10398
return {
10499
hasNewClaimConditions,
105-
isErc20: detectFeatures(oldContract, ["ERC20"]),
100+
// it cannot be erc20 since were in the NFT DRAWER TABS!
101+
isErc20: false,
106102
isMultiPhase: hasMultiPhaseClaimConditions,
107103
};
108-
}, [oldContract, hasNewClaimConditions, hasMultiPhaseClaimConditions]);
104+
}, [hasNewClaimConditions, hasMultiPhaseClaimConditions]);
109105

110106
return useMemo(() => {
111107
const isMintable = detectFeatures(oldContract, ["ERC1155Mintable"]);

0 commit comments

Comments
 (0)