Skip to content

Commit 24319f4

Browse files
committed
[TOOL-4175] Dashboard: Add buy listing button in listing drawer in marketplace (#6757)
<!-- ## title your PR with this format: "[SDK/Dashboard/Portal] Feature/Fix: Concise title for the changes" If you did not copy the branch name from Linear, paste the issue tag here (format is TEAM-0000): ## Notes for the reviewer Anything important to call out? Be sure to also clarify these in your comments. ## How to test Unit tests, playground, etc. --> <!-- start pr-codex --> --- ## PR-Codex overview This PR introduces the `BuyDirectListingButton` component into the `ListingDrawer` component, enhancing the marketplace functionality by allowing users to buy listings directly. It also updates documentation and adds error handling for the transaction process. ### Detailed summary - Updated documentation for the `BuyDirectListingButton` to specify `BuyDirectListingButtonProps`. - Imported `BuyDirectListingButton` in `listing-drawer.tsx`. - Implemented the `BuyDirectListingButton` in the `ListingDrawer` component. - Added error and success toast notifications for transaction outcomes. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent f38b262 commit 24319f4

File tree

2 files changed

+24
-10
lines changed
  • apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/(marketplace)/components
  • packages/thirdweb/src/react/web/ui/prebuilt/thirdweb/BuyDirectListingButton

2 files changed

+24
-10
lines changed

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

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ import type {
1010
DirectListing,
1111
EnglishAuction,
1212
} from "thirdweb/extensions/marketplace";
13-
import { useActiveAccount } from "thirdweb/react";
13+
import { BuyDirectListingButton, useActiveAccount } from "thirdweb/react";
1414

1515
import { CodeClient } from "@/components/ui/code/code.client";
1616
import type { Account } from "@3rdweb-sdk/react/hooks/useApi";
17+
import { toast } from "sonner";
1718
import { NFTMediaWithEmptyState } from "tw-components/nft-media";
1819
import { CancelTab } from "./cancel-tab";
1920
import { LISTING_STATUS } from "./types";
@@ -141,11 +142,6 @@ export const ListingDrawer: React.FC<NFTDrawerProps> = ({
141142
</GridItem>
142143
</>
143144
)}
144-
145-
{/*
146-
Todo: Add a Buy button somewhere in this section once the Dashboard is fully migrated to v5 (?)
147-
Kien already shipped a prebuilt component for the Marketplace Buy Button in SDK v5
148-
*/}
149145
</SimpleGrid>
150146
</Card>
151147
{data?.asset.metadata.properties ? (
@@ -168,6 +164,27 @@ export const ListingDrawer: React.FC<NFTDrawerProps> = ({
168164
twAccount={twAccount}
169165
/>
170166
)}
167+
168+
{!isOwner && renderData.status === "ACTIVE" && (
169+
<BuyDirectListingButton
170+
listingId={renderData.id}
171+
contractAddress={renderData.assetContractAddress}
172+
chain={contract.chain}
173+
client={contract.client}
174+
className="w-full"
175+
quantity={1n}
176+
onError={(error) => {
177+
toast.error("Failed to buy listing", {
178+
description: error.message,
179+
});
180+
}}
181+
onTransactionConfirmed={() => {
182+
toast.success("Listing bought successfully");
183+
}}
184+
>
185+
Buy Listing
186+
</BuyDirectListingButton>
187+
)}
171188
</SheetContent>
172189
</Sheet>
173190
);

packages/thirdweb/src/react/web/ui/prebuilt/thirdweb/BuyDirectListingButton/index.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,7 @@ export type BuyDirectListingButtonProps = Omit<
5757
* Since it uses the TransactionButton, it can take in any props that can be passed
5858
* to the [`TransactionButton`](https://portal.thirdweb.com/references/typescript/v5/TransactionButton)
5959
*
60-
*
61-
* @param props
62-
* @returns <TransactionButton />
63-
*
60+
* @param props props of type [BuyDirectListingButtonProps](https://portal.thirdweb.com/references/typescript/v5/BuyDirectListingButtonProps)
6461
* @example
6562
* ```tsx
6663
* import { BuyDirectListingButton } from "thirdweb/react";

0 commit comments

Comments
 (0)