@@ -141,95 +141,67 @@ Vamos a crear una aplicación sencilla en React que permita mostrar e interactua
141
141
```
142
142
</Step >
143
143
144
- <Step title = " Cree el componente Connect Button" >
145
- Cree un nuevo componente ` src/components/ConnectButton.tsx ` para la conexión de wallet:
146
-
147
- ``` tsx
148
- import { useOpenConnectModal } from ' @0xsequence/connect' ;
149
- import { useAccount } from ' wagmi' ;
150
-
151
- export default function ConnectButton() {
152
- const { setOpenConnectModal } = useOpenConnectModal ();
153
- const { address } = useAccount ();
154
-
155
- return (
156
- <button
157
- onClick = { () => setOpenConnectModal (true )}
158
- >
159
- { address ? ` ${address .slice (0 , 6 )}...${address .slice (- 4 )} ` : " Connect Wallet" }
160
- </button >
161
- );
162
- }
163
- ```
164
- </Step >
165
-
166
144
<Step title = " Crear componente de tarjeta de coleccionable" >
167
145
Cree un nuevo componente ` src/components/CollectibleCard.tsx ` para mostrar e interactuar con coleccionables:
168
146
169
147
``` tsx
170
148
import {
171
- useCollectible ,
172
- useMakeOfferModal ,
149
+ useCollectible ,
150
+ useMakeOfferModal ,
151
+ useMarketplaceConfig ,
152
+ useOpenConnectModal ,
173
153
} from " @0xsequence/marketplace-sdk/react" ;
174
154
import type { Address } from " viem" ;
155
+ import { useAccount } from " wagmi" ;
175
156
176
157
export default function CollectibleCard() {
177
- const { data : marketplaceConfig } = useMarketplaceConfig ();
178
- const collection = marketplaceConfig ?.market .collections [0 ]; // First collection setup in Sequence Builder
179
- const chainId = collection ?.chainId as number ;
180
- const collectionAddress = collection ?.itemsAddress as Address ;
181
- const collectibleId = " 0" ;
182
-
183
- const { data : collectible, isLoading : isCollectibleLoading, isError : isCollectibleError } = useCollectible ({
184
- chainId ,
185
- collectionAddress ,
186
- collectibleId ,
187
- });
188
-
189
- const { show } = useMakeOfferModal ();
190
-
191
- if (isCollectibleLoading ){
192
- return <div >Loading collectible...</div >
193
- }
194
-
195
- if (isCollectibleError ){
196
- return <div >Error while fetching collectible</div >
197
- }
198
-
199
- if (! collectible ) {
200
- return <div >No collectible found</div >;
201
- }
202
-
203
- return (
204
- <div >
205
- <img width = { 100 } height = { 100 } src = { collectible ?.image } alt = { collectible ?.name } />
206
-
207
- <h3 >{ collectible ?.name } </h3 >
208
-
209
- <button
210
- onClick = { () => {
211
- show ({
212
- chainId ,
213
- collectionAddress: itemsAddress ,
214
- collectibleId: " 0" ,
215
- });
216
- }}
217
- >
218
- Make Offer
219
- </button >
220
- </div >
221
- );
158
+ const { data : marketplaceConfig, isLoading : isMarketplaceConfigLoading } = useMarketplaceConfig ();
159
+ const { isConnected } = useAccount ()
160
+ const { openConnectModal } = useOpenConnectModal ()
161
+
162
+ const collection = marketplaceConfig ?.market .collections [0 ];
163
+ const chainId = collection ?.chainId as number ;
164
+ const collectionAddress = collection ?.itemsAddress as Address ;
165
+ const collectibleId = " 0" ;
166
+
167
+ const { data : collectible, isLoading : isCollectibleLoading, error : collectibleError } = useCollectible ({
168
+ chainId ,
169
+ collectionAddress ,
170
+ collectibleId ,
171
+ });
172
+
173
+ const { show } = useMakeOfferModal ();
174
+
175
+ if (isMarketplaceConfigLoading || isCollectibleLoading ) return <div >Loading...</div >;
176
+ if (collectibleError ) return <div >Error: { collectibleError .message } </div >;
177
+ if (! collectible ) return <div >No collectible found</div >;
178
+
179
+ return (
180
+ <div >
181
+ <img width = { 200 } height = { 200 } src = { collectible .image } alt = { collectible .name } />
182
+ <h3 >{ collectible .name } </h3 >
183
+ { isConnected ? (
184
+ <button
185
+ onClick = { () => {
186
+ show ({
187
+ chainId ,
188
+ collectionAddress ,
189
+ collectibleId ,
190
+ });
191
+ }}
192
+ >
193
+ Make Offer
194
+ </button >
195
+ ) : (
196
+ <button onClick = { () => openConnectModal ()} >Connect Wallet</button >
197
+ )}
198
+ </div >
199
+ );
222
200
}
223
201
```
224
202
225
203
<Note >
226
- Para obtener la dirección de su colección y el chain ID:
227
-
228
- 1 . Vaya a su marketplace en ` https://sequence.build/project/{YOUR_PROJECT_ID}/marketplace/market ` y copie la dirección de la colección que creó.
229
- 2 . Para el chain ID:
230
- - Si conoce la red donde está desplegada su colección, use ese chain ID
231
- - Si no está seguro, visite [ Sequence Chainlist] ( https://sequence.xyz/chains ) y busque el chain ID donde está desplegada su colección (busque redes con estado "Supported")
232
- 3 . Asegúrese de haber minteado al menos un coleccionable en su colección, luego use el ID de ese coleccionable como ` collectibleId `
204
+ Asegúrese de haber minteado al menos un coleccionable en su colección, luego use el ID de ese coleccionable como ` collectibleId `
233
205
</Note >
234
206
235
207
<Tip >
@@ -241,16 +213,12 @@ Vamos a crear una aplicación sencilla en React que permita mostrar e interactua
241
213
Actualice su ` App.tsx ` para usar los nuevos componentes:
242
214
243
215
``` tsx
244
- import ConnectButton from ' ./components/ConnectButton'
245
- import CollectibleCard from ' ./components/CollectibleCard'
216
+ import NFTCard from " ./nft-card" ;
246
217
247
218
export default function App() {
248
- return (
249
- <div >
250
- <ConnectButton />
251
- <CollectibleCard />
252
- </div >
253
- )
219
+ return (
220
+ <NFTCard />
221
+ );
254
222
}
255
223
```
256
224
</Step >
0 commit comments