Skip to content

Commit 7819e1e

Browse files
committed
[Dashboard] Add a form to let user manually input data for Marketplace listings (#5654)
## Problem solved Short description of the bug fixed or feature added <!-- start pr-codex --> --- ## PR-Codex overview This PR enhances the `CreateListingButton` and `CreateListingsForm` components by adding support for multiple listing modes (automatic and manual) and improving NFT validation logic, ensuring users can list NFTs more effectively based on the selected mode. ### Detailed summary - Introduced `LISTING_MODES` for "Select NFT" and "Manual" modes. - Added logic to toggle between automatic and manual listing modes. - Enhanced NFT validation for manual mode, including contract address and token ID checks. - Updated NFT approval checks based on listing mode. - Modified form controls and error handling for improved user experience. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent 6994310 commit 7819e1e

File tree

2 files changed

+294
-144
lines changed

2 files changed

+294
-144
lines changed

apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/(marketplace)/components/list-button.tsx

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ import {
88
SheetTitle,
99
SheetTrigger,
1010
} from "@/components/ui/sheet";
11+
import { TabButtons } from "@/components/ui/tabs";
1112
import { ListerOnly } from "@3rdweb-sdk/react/components/roles/lister-only";
1213
import type { Account } from "@3rdweb-sdk/react/hooks/useApi";
14+
import { isAlchemySupported } from "lib/wallet/nfts/alchemy";
15+
import { isMoralisSupported } from "lib/wallet/nfts/moralis";
16+
import { isSimpleHashSupported } from "lib/wallet/nfts/simpleHash";
1317
import { PlusIcon } from "lucide-react";
1418
import { useState } from "react";
1519
import type { ThirdwebContract } from "thirdweb";
@@ -23,6 +27,8 @@ interface CreateListingButtonProps {
2327
twAccount: Account | undefined;
2428
}
2529

30+
const LISTING_MODES = ["Select NFT", "Manual"] as const;
31+
2632
export const CreateListingButton: React.FC<CreateListingButtonProps> = ({
2733
createText = "Create",
2834
type,
@@ -32,7 +38,13 @@ export const CreateListingButton: React.FC<CreateListingButtonProps> = ({
3238
}) => {
3339
const address = useActiveAccount()?.address;
3440
const [open, setOpen] = useState(false);
35-
41+
const [listingMode, setListingMode] =
42+
useState<(typeof LISTING_MODES)[number]>("Select NFT");
43+
const isSupportedChain =
44+
contract.chain.id &&
45+
(isSimpleHashSupported(contract.chain.id) ||
46+
isAlchemySupported(contract.chain.id) ||
47+
isMoralisSupported(contract.chain.id));
3648
return (
3749
<ListerOnly contract={contract}>
3850
<Sheet open={open} onOpenChange={setOpen}>
@@ -43,15 +55,47 @@ export const CreateListingButton: React.FC<CreateListingButtonProps> = ({
4355
</SheetTrigger>
4456
<SheetContent className="w-full overflow-y-auto sm:min-w-[540px] lg:min-w-[700px]">
4557
<SheetHeader>
46-
<SheetTitle className="mb-5 text-left">{createText}</SheetTitle>
58+
<SheetTitle className="mb-3 text-left">{createText}</SheetTitle>
4759
</SheetHeader>
48-
<CreateListingsForm
49-
twAccount={twAccount}
50-
contract={contract}
51-
type={type}
52-
actionText={createText}
53-
setOpen={setOpen}
54-
/>
60+
{/*
61+
If the chain is not supported by the indexer providers
62+
we don't show the tabs, we only show the Manual input form.
63+
Otherwise we show both */}
64+
{isSupportedChain ? (
65+
<>
66+
<TabButtons
67+
tabs={LISTING_MODES.map((mode) => ({
68+
name: mode,
69+
isActive: mode === listingMode,
70+
onClick: () => setListingMode(mode),
71+
isEnabled: true,
72+
}))}
73+
tabClassName="text-sm gap-2 !text-sm"
74+
tabContainerClassName="gap-0.5"
75+
/>
76+
<div className="mt-5">
77+
<CreateListingsForm
78+
twAccount={twAccount}
79+
contract={contract}
80+
type={type}
81+
actionText={createText}
82+
setOpen={setOpen}
83+
mode={listingMode === "Select NFT" ? "automatic" : "manual"}
84+
/>
85+
</div>
86+
</>
87+
) : (
88+
<div className="mt-5">
89+
<CreateListingsForm
90+
twAccount={twAccount}
91+
contract={contract}
92+
type={type}
93+
actionText={createText}
94+
setOpen={setOpen}
95+
mode="manual"
96+
/>
97+
</div>
98+
)}
5599
</SheetContent>
56100
</Sheet>
57101
</ListerOnly>

0 commit comments

Comments
 (0)