11"use client" ;
22
3+ import { Button } from "@/components/ui/button" ;
34import { useApiKeys , useCreateApiKey } from "@3rdweb-sdk/react/hooks/useApi" ;
4- import { Flex , FormControl , Input , Link , Select } from "@chakra-ui/react" ;
5+ import { Flex , FormControl , Input , Select } from "@chakra-ui/react" ;
6+ import CreateAPIKeyDialog from "components/settings/ApiKeys/Create" ;
57import { useTrack } from "hooks/analytics/useTrack" ;
68import { useAllChainsData } from "hooks/chains/allChains" ;
79import { useClipboard } from "hooks/useClipboard" ;
8- import { useTxNotifications } from "hooks/useTxNotifications" ;
910import { CheckIcon , CopyIcon } from "lucide-react" ;
10- import { useMemo } from "react" ;
11+ import Link from "next/link" ;
12+ import { usePathname } from "next/navigation" ;
13+ import { useMemo , useState } from "react" ;
1114import { useForm } from "react-hook-form" ;
1215import type { StoredChain } from "stores/chainStores" ;
1316import type { ThirdwebContract } from "thirdweb" ;
1417import type { ChainMetadata } from "thirdweb/chains" ;
18+ import { useActiveAccount } from "thirdweb/react" ;
1519import {
16- Button ,
1720 Card ,
1821 CodeBlock ,
1922 FormHelperText ,
@@ -211,10 +214,6 @@ export const EmbedSetup: React.FC<EmbedSetupProps> = ({
211214
212215 const apiKeys = useApiKeys ( ) ;
213216 const createKeyMutation = useCreateApiKey ( ) ;
214- const { onSuccess, onError } = useTxNotifications (
215- "API key created" ,
216- "Failed to create API key" ,
217- ) ;
218217
219218 const validApiKey = ( apiKeys . data || [ ] ) . find (
220219 ( apiKey ) =>
@@ -298,14 +297,35 @@ export const EmbedSetup: React.FC<EmbedSetupProps> = ({
298297 ) ;
299298
300299 const { hasCopied, onCopy } = useClipboard ( embedCode , 3000 ) ;
300+ const [ showCreateAPIKeyModal , setShowCreateAPIKeyModal ] = useState ( false ) ;
301+ const activeAccount = useActiveAccount ( ) ;
302+ const pathname = usePathname ( ) ;
301303
302304 return (
303305 < Flex gap = { 8 } direction = "column" >
306+ < CreateAPIKeyDialog
307+ wording = "api-key"
308+ prefill = { {
309+ name : "Embed API Key" ,
310+ domains : "embed.ipfscdn.io" ,
311+ } }
312+ open = { showCreateAPIKeyModal }
313+ onOpenChange = { setShowCreateAPIKeyModal }
314+ onCreateAndComplete = { ( ) => {
315+ trackEvent ( {
316+ category : "api-keys" ,
317+ action : "create" ,
318+ label : "success" ,
319+ fromEmbed : true ,
320+ } ) ;
321+ apiKeys . refetch ( ) ;
322+ } }
323+ />
324+
304325 < Flex gap = { 8 } direction = { { base : "column" , md : "row" } } >
305- < Card className = "flex w-full flex-col gap-2 md:w-1/2" >
306- < Heading size = "title.sm" mb = { 4 } >
307- Configuration
308- </ Heading >
326+ < Card className = "flex w-full flex-col gap-5 md:w-1/2" >
327+ < Heading size = "title.sm" > Configuration</ Heading >
328+
309329 { ercOrMarketplace === "marketplace" ? (
310330 < FormControl >
311331 < FormLabel > Listing ID</ FormLabel >
@@ -315,6 +335,7 @@ export const EmbedSetup: React.FC<EmbedSetupProps> = ({
315335 </ FormHelperText >
316336 </ FormControl >
317337 ) : null }
338+
318339 { ercOrMarketplace === "marketplace-v3" ? (
319340 < FormControl >
320341 < FormLabel > Listing type</ FormLabel >
@@ -327,6 +348,7 @@ export const EmbedSetup: React.FC<EmbedSetupProps> = ({
327348 </ FormHelperText >
328349 </ FormControl >
329350 ) : null }
351+
330352 { ercOrMarketplace === "marketplace-v3" &&
331353 watch ( "listingType" ) === "direct-listing" ? (
332354 < FormControl >
@@ -337,6 +359,7 @@ export const EmbedSetup: React.FC<EmbedSetupProps> = ({
337359 </ FormHelperText >
338360 </ FormControl >
339361 ) : null }
362+
340363 { ercOrMarketplace === "marketplace-v3" &&
341364 watch ( "listingType" ) === "english-auction" ? (
342365 < FormControl >
@@ -347,6 +370,7 @@ export const EmbedSetup: React.FC<EmbedSetupProps> = ({
347370 </ FormHelperText >
348371 </ FormControl >
349372 ) : null }
373+
350374 { ercOrMarketplace === "erc1155" ? (
351375 < FormControl >
352376 < FormLabel > Token ID</ FormLabel >
@@ -356,21 +380,28 @@ export const EmbedSetup: React.FC<EmbedSetupProps> = ({
356380 </ FormHelperText >
357381 </ FormControl >
358382 ) : null }
383+
359384 < FormControl >
360385 < FormLabel > Client ID</ FormLabel >
361- { validApiKey ? (
386+ { ! activeAccount ? (
387+ < Button asChild className = "w-full" >
388+ < Link
389+ href = { `/login${
390+ pathname ? `?next=${ encodeURIComponent ( pathname ) } ` : ""
391+ } `}
392+ >
393+ Sign in to create a client ID
394+ </ Link >
395+ </ Button >
396+ ) : validApiKey ? (
362397 < Input
363398 readOnly
364399 disabled
365400 value = { `${ validApiKey ?. name } - ${ validApiKey ?. key } ` }
366401 />
367402 ) : (
368403 < Button
369- bgColor = "bgBlack"
370- color = "bgWhite"
371- _hover = { {
372- opacity : 0.8 ,
373- } }
404+ className = "w-full"
374405 onClick = { ( ) => {
375406 trackEvent ( {
376407 category : "api-keys" ,
@@ -379,44 +410,7 @@ export const EmbedSetup: React.FC<EmbedSetupProps> = ({
379410 fromEmbed : true ,
380411 } ) ;
381412
382- createKeyMutation . mutate (
383- {
384- name : "Embed API key" ,
385- domains : [ "embed.ipfscdn.io" ] ,
386- services : [
387- {
388- name : "rpc" ,
389- targetAddresses : [ "*" ] ,
390- } ,
391- {
392- name : "storage" ,
393- targetAddresses : [ "*" ] ,
394- actions : [ "read" ] ,
395- } ,
396- ] ,
397- } ,
398- {
399- onSuccess : ( ) => {
400- onSuccess ( ) ;
401- trackEvent ( {
402- category : "api-keys" ,
403- action : "create" ,
404- label : "success" ,
405- fromEmbed : true ,
406- } ) ;
407- } ,
408- onError : ( err ) => {
409- onError ( err ) ;
410- trackEvent ( {
411- category : "api-keys" ,
412- action : "create" ,
413- label : "error" ,
414- error : err ,
415- fromEmbed : true ,
416- } ) ;
417- } ,
418- } ,
419- ) ;
413+ setShowCreateAPIKeyModal ( true ) ;
420414 } }
421415 disabled = { createKeyMutation . isPending }
422416 >
@@ -428,14 +422,15 @@ export const EmbedSetup: React.FC<EmbedSetupProps> = ({
428422 You need a client ID to use embeds.{ " " }
429423 < Link
430424 href = "https://portal.thirdweb.com/account/api-keys"
431- color = "primary.500 "
432- isExternal
425+ className = "text-link-foreground hover:text-foreground "
426+ target = "_blank"
433427 >
434428 Learn more
435429 </ Link >
436430 .
437431 </ FormHelperText >
438432 </ FormControl >
433+
439434 < FormControl >
440435 < FormLabel > RPC Url</ FormLabel >
441436 < Input type = "url" { ...register ( "rpcUrl" ) } />
@@ -477,15 +472,16 @@ export const EmbedSetup: React.FC<EmbedSetupProps> = ({
477472 A relayer can be used to make the transaction gasless for the
478473 end user.{ " " }
479474 < Link
480- isExternal
481- color = "blue.500 "
475+ target = "_blank"
476+ className = "text-link-foreground hover:text-foreground "
482477 href = "https://blog.thirdweb.com/guides/setup-gasless-transactions"
483478 >
484479 Learn more
485480 </ Link >
486481 </ FormHelperText >
487482 </ FormControl >
488483 ) }
484+
489485 < FormControl >
490486 < Heading size = "title.sm" my = { 4 } >
491487 Customization
@@ -501,6 +497,7 @@ export const EmbedSetup: React.FC<EmbedSetupProps> = ({
501497 on the user system's preferences.
502498 </ FormHelperText >
503499 </ FormControl >
500+
504501 < FormControl >
505502 < FormLabel > Primary Color</ FormLabel >
506503 < Select { ...register ( "primaryColor" ) } >
@@ -517,6 +514,7 @@ export const EmbedSetup: React.FC<EmbedSetupProps> = ({
517514 Used for the main actions button backgrounds.
518515 </ FormHelperText >
519516 </ FormControl >
517+
520518 { ercOrMarketplace === "marketplace" ||
521519 ercOrMarketplace === "marketplace-v3" ? (
522520 < FormControl >
@@ -535,6 +533,7 @@ export const EmbedSetup: React.FC<EmbedSetupProps> = ({
535533 </ FormControl >
536534 ) : null }
537535 </ Card >
536+
538537 < Card className = "flex w-full flex-col gap-2 md:w-1/2" >
539538 < Heading size = "title.sm" > Embed Code</ Heading >
540539 < CodeBlock
@@ -545,8 +544,7 @@ export const EmbedSetup: React.FC<EmbedSetupProps> = ({
545544 language = "markup"
546545 />
547546 < Button
548- colorScheme = "purple"
549- w = "auto"
547+ className = "w-auto gap-2"
550548 variant = "outline"
551549 onClick = { ( ) => {
552550 onCopy ( ) ;
@@ -558,14 +556,12 @@ export const EmbedSetup: React.FC<EmbedSetupProps> = ({
558556 chainId,
559557 } ) ;
560558 } }
561- leftIcon = {
562- hasCopied ? (
563- < CheckIcon className = "size-4" />
564- ) : (
565- < CopyIcon className = "size-4" />
566- )
567- }
568559 >
560+ { hasCopied ? (
561+ < CheckIcon className = "size-4" />
562+ ) : (
563+ < CopyIcon className = "size-4" />
564+ ) }
569565 { hasCopied ? "Copied!" : "Copy to clipboard" }
570566 </ Button >
571567 </ Card >
0 commit comments