|
| 1 | +/* eslint-disable @next/next/no-img-element */ |
| 2 | + |
| 3 | +import { GlobeIcon } from "lucide-react"; |
| 4 | +import Image from "next/image"; |
| 5 | +import { getWalletInfo } from "thirdweb/wallets"; |
| 6 | +import { |
| 7 | + Breadcrumb, |
| 8 | + CodeBlock, |
| 9 | + createMetadata, |
| 10 | + DocLink, |
| 11 | + Heading, |
| 12 | + Paragraph, |
| 13 | +} from "@/components/Document"; |
| 14 | +import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; |
| 15 | + |
| 16 | +const walletId = "xyz.abs"; |
| 17 | + |
| 18 | +export async function generateMetadata() { |
| 19 | + const walletMetadata = await getWalletInfo(walletId); |
| 20 | + |
| 21 | + return createMetadata({ |
| 22 | + description: `Connect ${walletMetadata.name} with thirdweb TypeScript SDK`, |
| 23 | + image: { |
| 24 | + icon: "wallets", |
| 25 | + title: walletMetadata.name, |
| 26 | + }, |
| 27 | + title: walletMetadata.name, |
| 28 | + }); |
| 29 | +} |
| 30 | + |
| 31 | +export default async function Page() { |
| 32 | + const [walletMetadata, walletImage] = await Promise.all([ |
| 33 | + getWalletInfo(walletId), |
| 34 | + getWalletInfo(walletId, true), |
| 35 | + ]); |
| 36 | + |
| 37 | + return ( |
| 38 | + <div> |
| 39 | + <Breadcrumb |
| 40 | + crumbs={[ |
| 41 | + { |
| 42 | + href: "/wallets/external-wallets", |
| 43 | + name: "External Wallets", |
| 44 | + }, |
| 45 | + { |
| 46 | + href: `/wallets/external-wallets/${walletId}`, |
| 47 | + name: walletMetadata.name, |
| 48 | + }, |
| 49 | + ]} |
| 50 | + /> |
| 51 | + |
| 52 | + <div className="mb-10 flex items-center gap-3 [&_h1]:m-0"> |
| 53 | + <Image |
| 54 | + alt="" |
| 55 | + className="rounded-lg" |
| 56 | + height={36} |
| 57 | + src={walletImage} |
| 58 | + width={36} |
| 59 | + /> |
| 60 | + <Heading anchorId="title" level={1}> |
| 61 | + {walletMetadata.name} |
| 62 | + </Heading> |
| 63 | + </div> |
| 64 | + |
| 65 | + <DocLink |
| 66 | + className="flex items-center gap-2" |
| 67 | + href={walletMetadata.homepage} |
| 68 | + > |
| 69 | + <GlobeIcon className="size-5" /> |
| 70 | + {walletMetadata.homepage} |
| 71 | + </DocLink> |
| 72 | + |
| 73 | + <Heading anchorId="wallet-id" level={2}> |
| 74 | + Wallet ID |
| 75 | + </Heading> |
| 76 | + |
| 77 | + <CodeBlock code={`"${walletId}"`} lang="ts" /> |
| 78 | + |
| 79 | + <Heading anchorId="connect-wallet" level={2}> |
| 80 | + Installation |
| 81 | + </Heading> |
| 82 | + |
| 83 | + <CodeBlock |
| 84 | + code={`npm i thirdweb @abstract-foundation/agw-react`} |
| 85 | + lang="bash" |
| 86 | + /> |
| 87 | + |
| 88 | + <Heading anchorId="connect-wallet" level={2}> |
| 89 | + Connect Wallet |
| 90 | + </Heading> |
| 91 | + |
| 92 | + <Tabs defaultValue="tab-1"> |
| 93 | + <TabsList> |
| 94 | + <TabsTrigger value="tab-1"> TypeScript </TabsTrigger> |
| 95 | + <TabsTrigger value="tab-2"> React (Custom UI) </TabsTrigger> |
| 96 | + <TabsTrigger value="tab-3"> React (Component) </TabsTrigger> |
| 97 | + </TabsList> |
| 98 | + <TabsContent value="tab-1"> |
| 99 | + <CodeBlock code={injectedSupportedTS()} lang="ts" /> |
| 100 | + </TabsContent> |
| 101 | + <TabsContent value="tab-2"> |
| 102 | + <CodeBlock code={injectedSupportedCodeReact()} lang="ts" /> |
| 103 | + </TabsContent> |
| 104 | + <TabsContent value="tab-3"> |
| 105 | + <Paragraph> |
| 106 | + You can add this wallet in the{" "} |
| 107 | + <DocLink href="/react/v5/ConnectButton" target="_blank"> |
| 108 | + ConnectButton |
| 109 | + </DocLink>{" "} |
| 110 | + or{" "} |
| 111 | + <DocLink href="/react/v5/ConnectEmbed" target="_blank"> |
| 112 | + ConnectEmbed |
| 113 | + </DocLink>{" "} |
| 114 | + component to get a pre-built UI for connecting the wallet.{" "} |
| 115 | + <Heading anchorId="connect-component" level={3}> |
| 116 | + Example |
| 117 | + </Heading>{" "} |
| 118 | + <CodeBlock code={componentCode()} lang="tsx" /> |
| 119 | + </Paragraph> |
| 120 | + </TabsContent> |
| 121 | + </Tabs> |
| 122 | + |
| 123 | + <Heading anchorId="reference" level={2}> |
| 124 | + Reference |
| 125 | + </Heading> |
| 126 | + |
| 127 | + <DocLink href="/references/typescript/v5/AbsWalletCreationOptions"> |
| 128 | + View All Creation Options |
| 129 | + </DocLink> |
| 130 | + </div> |
| 131 | + ); |
| 132 | +} |
| 133 | + |
| 134 | +function injectedSupportedTS() { |
| 135 | + return `\ |
| 136 | +import { createThirdwebClient } from "thirdweb"; |
| 137 | +import { createWallet } from "thirdweb/wallets"; |
| 138 | +import { abstractWallet } from "@abstract-foundation/agw-react/thirdweb"; |
| 139 | +
|
| 140 | +const client = createThirdwebClient({ clientId }); |
| 141 | +
|
| 142 | +const wallet = ${createWallet()}; |
| 143 | +
|
| 144 | +await wallet.connect({ client }); |
| 145 | +`; |
| 146 | +} |
| 147 | + |
| 148 | +function injectedSupportedCodeReact() { |
| 149 | + return `\ |
| 150 | +import { createThirdwebClient } from "thirdweb"; |
| 151 | +import { useConnect } from "thirdweb/react"; |
| 152 | +import { createWallet } from "thirdweb/wallets"; |
| 153 | +import { abstractWallet } from "@abstract-foundation/agw-react/thirdweb"; |
| 154 | +
|
| 155 | +const client = createThirdwebClient({ clientId }); |
| 156 | +const wallet = ${createWallet()}; |
| 157 | +
|
| 158 | +function Example() { |
| 159 | + const { connect, isConnecting, error } = useConnect(); |
| 160 | + return ( |
| 161 | + <button |
| 162 | + onClick={() => { |
| 163 | + // if the wallet extension is installed, connect to it |
| 164 | + connect(async () => { |
| 165 | + await wallet.connect({ client }); |
| 166 | + return wallet; |
| 167 | + }); |
| 168 | + }} |
| 169 | + > |
| 170 | + {isConnecting ? "Connecting..." : "Connect"} |
| 171 | + </button> |
| 172 | + ); |
| 173 | +} |
| 174 | +`; |
| 175 | +} |
| 176 | + |
| 177 | +function componentCode() { |
| 178 | + return `\ |
| 179 | +import { ConnectButton } from "thirdweb/react"; |
| 180 | +import { createWallet } from "thirdweb/wallets"; |
| 181 | +import { abstractWallet } from "@abstract-foundation/agw-react/thirdweb"; |
| 182 | +
|
| 183 | +const wallets = [ |
| 184 | + // Add your wallet in wallet list |
| 185 | + ${createWallet()}, |
| 186 | + // add other wallets... |
| 187 | +]; |
| 188 | +
|
| 189 | +function Example() { |
| 190 | + return ( |
| 191 | + <div> |
| 192 | + {/* Use ConnectButton */} |
| 193 | + <ConnectButton client={client} wallets={wallets} /> |
| 194 | +
|
| 195 | + {/* Or Use ConnectEmbed */} |
| 196 | + <ConnectEmbed client={client} wallets={wallets} /> |
| 197 | + </div> |
| 198 | + ); |
| 199 | +}`; |
| 200 | +} |
| 201 | + |
| 202 | +function createWallet() { |
| 203 | + return `abstractWallet()`; |
| 204 | +} |
0 commit comments