@@ -8,8 +8,12 @@ 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" ;
1213import 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" ;
1317import { PlusIcon } from "lucide-react" ;
1418import { useState } from "react" ;
1519import 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+
2632export 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