@@ -8,7 +8,11 @@ import {
88 SheetTitle ,
99 SheetTrigger ,
1010} from "@/components/ui/sheet" ;
11+ import { TabButtons } from "@/components/ui/tabs" ;
1112import { ListerOnly } from "@3rdweb-sdk/react/components/roles/lister-only" ;
13+ import { isAlchemySupported } from "lib/wallet/nfts/alchemy" ;
14+ import { isMoralisSupported } from "lib/wallet/nfts/moralis" ;
15+ import { isSimpleHashSupported } from "lib/wallet/nfts/simpleHash" ;
1216import { PlusIcon } from "lucide-react" ;
1317import { useState } from "react" ;
1418import type { ThirdwebContract } from "thirdweb" ;
@@ -21,6 +25,8 @@ interface CreateListingButtonProps {
2125 type ?: "direct-listings" | "english-auctions" ;
2226}
2327
28+ const LISTING_MODES = [ "Select NFT" , "Manual" ] as const ;
29+
2430export const CreateListingButton : React . FC < CreateListingButtonProps > = ( {
2531 createText = "Create" ,
2632 type,
@@ -29,7 +35,13 @@ export const CreateListingButton: React.FC<CreateListingButtonProps> = ({
2935} ) => {
3036 const address = useActiveAccount ( ) ?. address ;
3137 const [ open , setOpen ] = useState ( false ) ;
32-
38+ const [ listingMode , setListingMode ] =
39+ useState < ( typeof LISTING_MODES ) [ number ] > ( "Select NFT" ) ;
40+ const isSupportedChain =
41+ contract . chain . id &&
42+ ( isSimpleHashSupported ( contract . chain . id ) ||
43+ isAlchemySupported ( contract . chain . id ) ||
44+ isMoralisSupported ( contract . chain . id ) ) ;
3345 return (
3446 < ListerOnly contract = { contract } >
3547 < Sheet open = { open } onOpenChange = { setOpen } >
@@ -40,14 +52,45 @@ export const CreateListingButton: React.FC<CreateListingButtonProps> = ({
4052 </ SheetTrigger >
4153 < SheetContent className = "w-full overflow-y-auto sm:min-w-[540px] lg:min-w-[700px]" >
4254 < SheetHeader >
43- < SheetTitle className = "mb-5 text-left" > { createText } </ SheetTitle >
55+ < SheetTitle className = "mb-3 text-left" > { createText } </ SheetTitle >
4456 </ SheetHeader >
45- < CreateListingsForm
46- contract = { contract }
47- type = { type }
48- actionText = { createText }
49- setOpen = { setOpen }
50- />
57+ { /*
58+ If the chain is not supported by the indexer providers
59+ we don't show the tabs, we only show the Manual input form.
60+ Otherwise we show both */ }
61+ { isSupportedChain ? (
62+ < >
63+ < TabButtons
64+ tabs = { LISTING_MODES . map ( ( mode ) => ( {
65+ name : mode ,
66+ isActive : mode === listingMode ,
67+ onClick : ( ) => setListingMode ( mode ) ,
68+ isEnabled : true ,
69+ } ) ) }
70+ tabClassName = "text-sm gap-2 !text-sm"
71+ tabContainerClassName = "gap-0.5"
72+ />
73+ < div className = "mt-5" >
74+ < CreateListingsForm
75+ contract = { contract }
76+ type = { type }
77+ actionText = { createText }
78+ setOpen = { setOpen }
79+ mode = { listingMode === "Select NFT" ? "automatic" : "manual" }
80+ />
81+ </ div >
82+ </ >
83+ ) : (
84+ < div className = "mt-5" >
85+ < CreateListingsForm
86+ contract = { contract }
87+ type = { type }
88+ actionText = { createText }
89+ setOpen = { setOpen }
90+ mode = "manual"
91+ />
92+ </ div >
93+ ) }
5194 </ SheetContent >
5295 </ Sheet >
5396 </ ListerOnly >
0 commit comments