Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
kien-ngo committed Dec 11, 2024
1 parent f25d1d8 commit 1427f09
Show file tree
Hide file tree
Showing 2 changed files with 288 additions and 143 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import {
SheetTitle,
SheetTrigger,
} from "@/components/ui/sheet";
import { TabButtons } from "@/components/ui/tabs";
import { ListerOnly } from "@3rdweb-sdk/react/components/roles/lister-only";
import { isAlchemySupported } from "lib/wallet/nfts/alchemy";
import { isMoralisSupported } from "lib/wallet/nfts/moralis";
import { isSimpleHashSupported } from "lib/wallet/nfts/simpleHash";
import { PlusIcon } from "lucide-react";
import { useState } from "react";
import type { ThirdwebContract } from "thirdweb";
Expand All @@ -21,6 +25,8 @@ interface CreateListingButtonProps {
type?: "direct-listings" | "english-auctions";
}

const LISTING_MODES = ["Select NFT", "Manual"] as const;

export const CreateListingButton: React.FC<CreateListingButtonProps> = ({
createText = "Create",
type,
Expand All @@ -29,7 +35,13 @@ export const CreateListingButton: React.FC<CreateListingButtonProps> = ({
}) => {
const address = useActiveAccount()?.address;
const [open, setOpen] = useState(false);

const [listingMode, setListingMode] =
useState<(typeof LISTING_MODES)[number]>("Select NFT");
const isSupportedChain =
contract.chain.id &&
(isSimpleHashSupported(contract.chain.id) ||
isAlchemySupported(contract.chain.id) ||
isMoralisSupported(contract.chain.id));
return (
<ListerOnly contract={contract}>
<Sheet open={open} onOpenChange={setOpen}>
Expand All @@ -40,14 +52,45 @@ export const CreateListingButton: React.FC<CreateListingButtonProps> = ({
</SheetTrigger>
<SheetContent className="w-full overflow-y-auto sm:min-w-[540px] lg:min-w-[700px]">
<SheetHeader>
<SheetTitle className="mb-5 text-left">{createText}</SheetTitle>
<SheetTitle className="mb-3 text-left">{createText}</SheetTitle>
</SheetHeader>
<CreateListingsForm
contract={contract}
type={type}
actionText={createText}
setOpen={setOpen}
/>
{/*
If the chain is not supported by the indexer providers
we don't show the tabs, we only show the Manual input form.
Otherwise we show both */}
{isSupportedChain ? (
<>
<TabButtons
tabs={LISTING_MODES.map((mode) => ({
name: mode,
isActive: mode === listingMode,
onClick: () => setListingMode(mode),
isEnabled: true,
}))}
tabClassName="text-sm gap-2 !text-sm"
tabContainerClassName="gap-0.5"
/>
<div className="mt-5">
<CreateListingsForm
contract={contract}
type={type}
actionText={createText}
setOpen={setOpen}
mode={listingMode === "Select NFT" ? "automatic" : "manual"}
/>
</div>
</>
) : (
<div className="mt-5">
<CreateListingsForm
contract={contract}
type={type}
actionText={createText}
setOpen={setOpen}
mode="manual"
/>
</div>
)}
</SheetContent>
</Sheet>
</ListerOnly>
Expand Down
Loading

0 comments on commit 1427f09

Please sign in to comment.