Skip to content

Commit 96373be

Browse files
mithatakbulutgithub-actions[bot]bunnybones1RichardIralamreg-17
authored
Refactor useBuyModal documentation (#149)
* Refactor useBuyModal documentation to enhance clarity and usability. Updated title and description, added detailed usage examples, and improved parameter and return type sections for better understanding of the hook's functionality. * chore(i18n): update translations [en] Sync file structure, format locales. Branch: 149/merge * remove unused prop `onBuyAtFloorPrice` * chore(i18n): update translations [en] Sync file structure, format locales. Branch: 149/merge * fix sidekick docker command (#150) * fix sidekick docker command * chore(i18n): update translations [en] Sync file structure, format locales. Branch: 150/merge --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> * Add Shops docs (#143) * Add Shops docs * chore(i18n): update translations [en] Sync file structure, format locales. Branch: 143/merge * Update shop docs assets * chore(i18n): update translations [en] Sync file structure, format locales. Branch: 143/merge * Minor update * chore(i18n): update translations [en] Sync file structure, format locales. Branch: 143/merge * Apply fixes * chore(i18n): update translations [en] Sync file structure, format locales. Branch: 143/merge * Remove ERC-721 contracts reference in docs * Update ERC-1155 sale creation steps * chore(i18n): update translations [en] Sync file structure, format locales. Branch: 143/merge * Update --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Max Reg <[email protected]> * Marketplace sdk overview and getting started (#148) * Revise Marketplace SDK overview content * Enhance Getting Started guide for Marketplace SDK * Reorganize the documentation structure for the Marketplace SDK, creating distinct groups for "Marketplace SDK", "Hooks", and "Marketplace Actions". * chore(i18n): update translations [en] Sync file structure, format locales. Branch: 148/merge * Update description in Getting Started guide for Marketplace SDK to focus on installation, configuration, and the make offer feature. * chore(i18n): update translations [en] Sync file structure, format locales. Branch: 148/merge * Enhance Getting Started guide for Marketplace SDK by adding a new section for SDK configuration, including instructions for creating a configuration file and replacing placeholder values with actual project credentials. Additionally, clarify the default behavior of the `shadowDom` setting in the SDK configuration. * chore(i18n): update translations [en] Sync file structure, format locales. Branch: 148/merge * rename NFTCard to CollectibleCard * refactor line: Optimized data fetching with React Query and Wagmi * chore(i18n): update translations [en] Sync file structure, format locales. Branch: 148/merge * showcase `useMarketplaceConfig` and get contract address, chain id from its data. use them in useCollectible params * chore(i18n): update translations [en] Sync file structure, format locales. Branch: 148/merge * remove shadowDom note. it should be mentioned in another page clearly and with examples * add width and height to image * Enhance CollectibleCard component with loading and error states * improve clarity and type safety by extracting collection properties. * chore(i18n): update translations [en] Sync file structure, format locales. Branch: 148/merge * Refactor getting started guide to replace ConnectButton with CollectibleCard component. * Update SDK overview link to point to the marketplace SDK documentation. * chore(i18n): update translations [en] Sync file structure, format locales. Branch: 148/merge --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> * use tabs for market and shop purchase examples * chore(i18n): update translations [en] Sync file structure, format locales. Branch: 149/merge * Add new hooks and update documentation for marketplace SDK and add link to them as reference in useBuyModal * chore(i18n): update translations [en] Sync file structure, format locales. Branch: 149/merge * rename "NFT purchases" to "collectible purchases" * chore(i18n): update translations [en] Sync file structure, format locales. Branch: 149/merge --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Tomasz Dysinski <[email protected]> Co-authored-by: RichardIrala <[email protected]> Co-authored-by: Max Reg <[email protected]>
1 parent ba05888 commit 96373be

File tree

25 files changed

+2252
-158
lines changed

25 files changed

+2252
-158
lines changed

docs.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,13 @@
144144
"group": "Payment Rails",
145145
"pages": [
146146
"solutions/monetization-overview",
147+
{
148+
"group": "Shop",
149+
"pages": [
150+
"solutions/shop/overview",
151+
"solutions/shop/guide"
152+
]
153+
},
147154
{
148155
"group": "White-label Marketplace",
149156
"pages": [
@@ -276,10 +283,10 @@
276283
"group": "Hooks",
277284
"pages": [
278285
{
279-
"group": "Marketplace Actions",
286+
"group": "Actions",
280287
"pages": [
281-
"sdk/marketplace-sdk/hooks/marketplace-actions/useCreateListingModal",
282288
"sdk/marketplace-sdk/hooks/marketplace-actions/useBuyModal",
289+
"sdk/marketplace-sdk/hooks/marketplace-actions/useCreateListingModal",
283290
"sdk/marketplace-sdk/hooks/marketplace-actions/useMakeOfferModal",
284291
"sdk/marketplace-sdk/hooks/marketplace-actions/useSellModal",
285292
"sdk/marketplace-sdk/hooks/marketplace-actions/useCancelOrder"
@@ -290,6 +297,8 @@
290297
"pages": [
291298
"sdk/marketplace-sdk/hooks/marketplace-data/overview",
292299
"sdk/marketplace-sdk/hooks/marketplace-data/useCountOfCollectables",
300+
"sdk/marketplace-sdk/hooks/marketplace-data/useLowestListing",
301+
"sdk/marketplace-sdk/hooks/marketplace-data/useListPrimarySaleItems",
293302
"sdk/marketplace-sdk/hooks/marketplace-data/useListCollectibles",
294303
"sdk/marketplace-sdk/hooks/marketplace-data/useListCollectiblesPaginated",
295304
"sdk/marketplace-sdk/hooks/marketplace-data/useMarketplaceConfig",
Lines changed: 254 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,264 @@
11
---
22
title: useBuyModal
3-
description: El hook useBuyModal permite a los usuarios comprar un NFT que está listado en el Marketplace. Se encarga del proceso de compra y la ejecución de la transacción.
3+
description: Hook para gestionar la interfaz del modal de compra de coleccionables
44
sidebarTitle: useBuyModal
55
---
66

7-
```ts
8-
import { useBuyModal } from "@0xsequence/marketplace-sdk/react";
7+
## Importar
98

10-
## Into your React component:
11-
12-
const { show: showBuyModal } = useBuyModal({
13-
onSuccess(hash) {
14-
console.log("Buy transaction sent with hash: ", hash);
15-
},
16-
onError,
17-
});
18-
19-
const onClickBuy = () => {
20-
showBuyModal({
21-
chainId,
22-
collectionAddress,
23-
tokenId,
24-
order,
25-
});
26-
};
27-
28-
return <button onClick={onClickBuy}>Buy</button>
9+
```tsx
10+
import { useBuyModal } from "@0xsequence/marketplace-sdk/react";
2911
```
3012

31-
<ResponseField name="useBuyModal">
32-
<ResponseField name="* params" />
33-
34-
<Expandable>
35-
```ts
36-
interface useBuyModal {
37-
onSuccess?: ({ hash, orderId }: {
38-
hash?: Hash;
39-
orderId?: string;
40-
}) => void;
41-
onError?: (error: Error) => void;
13+
## Uso
14+
15+
### Examples
16+
17+
<Tabs>
18+
<Tab title="Compra en el mercado">
19+
Ejemplo de cómo implementar una compra en el mercado (ventas secundarias) usando el hook `useBuyModal`:
20+
21+
<Note>
22+
Este ejemplo utiliza el hook [`useLowestListing`](/sdk/marketplace-sdk/hooks/marketplace-data/useLowestListing) de marketplace-sdk. Si no existe un lowestListing con los parámetros indicados, significa que no hay un orderId disponible y, por lo tanto, el artículo no se puede comprar.
23+
</Note>
24+
25+
```tsx
26+
27+
import type { MarketplaceKind } from "@0xsequence/marketplace-sdk";
28+
import {
29+
useBuyModal,
30+
useLowestListing,
31+
} from "@0xsequence/marketplace-sdk/react";
32+
import type { Address } from "viem";
33+
34+
export default function MarketPurchaseExample() {
35+
const {
36+
data: lowestListing,
37+
isLoading: isLoadingLowestListing,
38+
isError: isErrorLowestListing,
39+
} = useLowestListing({
40+
collectionAddress: "0x1234567890123456789012345678901234567890" as Address // Replace with your collection address
41+
chainId: 1 // Replace with your chain id
42+
tokenId: "1", // Replace with your token id
43+
});
44+
const chainId = lowestListing?.chainId as number;
45+
const collectionAddress = lowestListing?.collectionContractAddress as Address;
46+
const tokenId = lowestListing?.tokenId as string;
47+
const orderId = lowestListing?.orderId as string;
48+
const marketplace = lowestListing?.marketplace as MarketplaceKind;
49+
const priceUSDFormatted = lowestListing?.priceUSDFormatted as string;
50+
51+
const { show: showMarketModal } = useBuyModal({
52+
onSuccess: ({ hash, orderId }) => {
53+
console.log("Market purchase successful", { hash, orderId });
54+
},
55+
onError: (error) => {
56+
console.error("Market purchase failed:", error.message);
57+
},
58+
});
59+
60+
const handleMarketBuy = () => {
61+
if (!lowestListing || isLoadingLowestListing) return;
62+
63+
showMarketModal({
64+
chainId,
65+
collectionAddress,
66+
collectibleId: tokenId,
67+
orderId,
68+
marketplace,
69+
});
70+
71+
};
72+
73+
return (
74+
<div style={{ padding: "20px" }}>
75+
<h3>Market Purchase</h3>
76+
77+
<p>Price: ${priceUSDFormatted}</p>
78+
79+
<button
80+
onClick={handleMarketBuy}
81+
disabled={isLoadingLowestListing || isErrorLowestListing}
82+
>
83+
Buy from Market
84+
</button>
85+
</div>
86+
87+
);
88+
}
89+
90+
```
91+
</Tab>
92+
93+
<Tab title="Compra en la tienda">
94+
Ejemplo de cómo implementar una compra en la tienda (ventas primarias) usando el hook `useBuyModal`:
95+
96+
<Note>
97+
Este ejemplo utiliza el hook [`useListPrimarySaleItems`](/sdk/marketplace-sdk/hooks/marketplace-data/useListPrimarySaleItems) de marketplace-sdk. El hook obtiene los artículos de venta primaria de un contrato específico. Si no existe un primarySaleItem con los parámetros indicados o si el suministro es 0, el artículo no se puede comprar.
98+
</Note>
99+
100+
```tsx
101+
102+
import {
103+
useBuyModal,
104+
useListPrimarySaleItems,
105+
} from '@0xsequence/marketplace-sdk/react';
106+
import type { Address } from 'viem';
107+
108+
export default function ShopPurchaseExample() {
109+
// Example values - replace with your own
110+
const chainId = 1; // Ethereum mainnet
111+
const saleContractAddress =
112+
'0x1234567890123456789012345678901234567890' as Address;
113+
const collectionAddress =
114+
'0x0987654321098765432109876543210987654321' as Address;
115+
const tokenId = '1';
116+
117+
const { show: showBuyModal } = useBuyModal({
118+
onSuccess: ({ hash }) => {
119+
console.log('Shop purchase successful', { hash });
120+
},
121+
onError: (error) => {
122+
console.error('Shop purchase failed:', error.message);
123+
},
124+
});
125+
126+
// Fetch primary sale items - replace parameters with your own
127+
const { data: primarySaleItems } = useListPrimarySaleItems({
128+
chainId: chainId,
129+
primarySaleContractAddress: saleContractAddress,
130+
filter: {
131+
includeEmpty: true,
132+
},
133+
});
134+
135+
const primarySaleItem =
136+
primarySaleItems?.pages[0]?.primarySaleItems[0]?.primarySaleItem;
137+
138+
const handleShopBuy = () => {
139+
if (!primarySaleItem) return;
140+
141+
showBuyModal({
142+
chainId: chainId,
143+
collectionAddress: collectionAddress,
144+
salesContractAddress: saleContractAddress,
145+
marketplaceType: 'shop',
146+
quantityDecimals: 0,
147+
quantityRemaining: Number(primarySaleItem.supply),
148+
items: [
149+
{
150+
tokenId: tokenId,
151+
quantity: '1',
152+
},
153+
],
154+
salePrice: {
155+
amount: primarySaleItem.priceAmount ?? '0',
156+
currencyAddress: (primarySaleItem.currencyAddress as Address) ?? '0x',
157+
},
158+
});
159+
160+
};
161+
162+
return (
163+
<div>
164+
<p>Available: {primarySaleItem?.supply ?? 0}</p>
165+
<button
166+
onClick={handleShopBuy}
167+
disabled={!primarySaleItem || Number(primarySaleItem.supply) === 0} >
168+
Buy from Shop
169+
</button>
170+
</div>
171+
);
42172
}
173+
43174
```
44-
</Expandable>
45-
46-
<ResponseField name="* return properties" />
47-
48-
<Expandable>
49-
<ResponseField name="show" type="(args: ShowBuyModalArgs) => void">
50-
```ts
51-
interface ShowBuyModalArgs {
52-
chainId: string;
53-
collectionAddress: Hex;
54-
tokenId: string;
55-
order: Order;
56-
}
57-
```
58-
</ResponseField>
59-
60-
<ResponseField name="close" type="() => void" />
61-
</Expandable>
62-
</ResponseField>
175+
</Tab>
176+
</Tabs>
177+
178+
## Parámetros
179+
El hook acepta un objeto opcional `callbacks` con las siguientes propiedades:
180+
181+
```tsx
182+
interface ModalCallbacks {
183+
onSuccess?: ({ hash, orderId }: { hash?: Hash; orderId?: string }) => void;
184+
onError?: (error: Error) => void;
185+
successActionButtons?: Array<{ label: string; action: () => void }>;
186+
}
187+
```
188+
189+
| Parámetro | Type | Description |
190+
| -------------------------------- | ---------------------------------------------------------------- | ---------------------------------------------------------------------------------- |
191+
| `callbacks.onSuccess` | `({ hash, orderId }: { hash?: Hash; orderId?: string }) => void` | Función de callback opcional que se llama cuando la compra es exitosa |
192+
| `callbacks.onError` | `(error: Error) => void` | Función de callback opcional que se llama cuando ocurre un error durante la compra |
193+
| `callbacks.successActionButtons` | `Array<{ label: string; action: () => void }>` | Arreglo opcional de botones de acción para mostrar en caso de éxito |
194+
195+
## Tipo de retorno
196+
El hook retorna un objeto con los siguientes métodos:
197+
198+
```tsx
199+
{
200+
show: (args: BuyModalProps) => void
201+
close: () => void
202+
}
203+
```
204+
205+
### Métodos
206+
207+
#### show
208+
`(args: BuyModalProps) => void`
209+
210+
Abre el modal de compra con los parámetros especificados. `BuyModalProps` puede ser `ShopBuyModalProps` o `MarketplaceBuyModalProps` dependiendo del tipo de compra.
211+
212+
Para compras en el mercado (ventas secundarias):
213+
214+
```tsx
215+
interface MarketplaceBuyModalProps extends BuyModalBaseProps {
216+
marketplaceType?: "market";
217+
collectibleId: string;
218+
marketplace: MarketplaceKind;
219+
orderId: string;
220+
}
221+
```
222+
223+
Para compras en la tienda (ventas primarias):
224+
225+
```tsx
226+
interface ShopBuyModalProps extends BuyModalBaseProps {
227+
marketplaceType: "shop";
228+
salesContractAddress: Address;
229+
items: Array<Partial<CheckoutOptionsItem> & { tokenId?: string }>;
230+
quantityDecimals: number;
231+
quantityRemaining: number;
232+
salePrice: {
233+
amount: string;
234+
currencyAddress: Address;
235+
};
236+
unlimitedSupply?: boolean;
237+
}
238+
```
239+
240+
Ambos tipos extienden de `BuyModalBaseProps`:
241+
242+
```tsx
243+
interface BuyModalBaseProps {
244+
chainId: number;
245+
collectionAddress: Address;
246+
skipNativeBalanceCheck?: boolean;
247+
nativeTokenAddress?: Address;
248+
marketplaceType?: MarketplaceType;
249+
customCreditCardProviderCallback?: (buyStep: Step) => void;
250+
successActionButtons?: Array<{ label: string; action: () => void }>;
251+
}
252+
```
253+
254+
#### close
255+
`() => void`
256+
257+
Cierra el modal de compra.
258+
259+
## Notas
260+
El hook `useBuyModal` ofrece una forma práctica de gestionar la interfaz del modal de compra de coleccionables. Se encarga de:
261+
- Abrir y cerrar el modal
262+
- Gestionar el estado del flujo de compra
263+
- Manejo de errores y callbacks de éxito
264+
- Soporte tanto para ventas primarias como secundarias

0 commit comments

Comments
 (0)