diff --git a/docs/pages/guides/components/create-wallet-button.mdx b/docs/pages/guides/components/create-wallet-button.mdx new file mode 100644 index 0000000..1585a68 --- /dev/null +++ b/docs/pages/guides/components/create-wallet-button.mdx @@ -0,0 +1,228 @@ +# Add a Create Wallet button to your app + +## With wagmi + +:::code-group + +```tsx [CreateWalletButton.tsx] +import React, { useCallback } from "react"; +import { useConnect } from "wagmi"; +import { CoinbaseWalletLogo } from "./CoinbaseWalletLogo"; + +const buttonStyles = { + background: "transparent", + border: "1px solid transparent", + display: "flex", + alignItems: "center", + fontFamily: "Arial, sans-serif", + fontWeight: "bold", + fontSize: 18, + backgroundColor: "#0052FF", + padding: "7px 14px", + borderRadius: 10, +}; + +export function WagmiCreateWalletButton() { + const { connectors, connect, data } = useConnect(); + + const connectCoinbaseWallet = useCallback(() => { + const coinbaseWalletConnector = connectors.find( + (connector) => connector.id === "coinbaseWalletSDK" + ); + if (coinbaseWalletConnector) { + connect({ connector: coinbaseWalletConnector }); + } + }, [connectors, connect]); + return ( + + ); +} +``` + +```tsx twoslash [CoinbaseWalletLogo.tsx] +import React from "react"; + +const defaultContainerStyles = { + paddingRight: 10, + paddingTop: 2, +}; + +export function CoinbaseWalletLogo({ + size = 25, + containerStyles = defaultContainerStyles, +}) { + return ( +
+ + + + +
+ ); +} +``` + +```ts twoslash [wagmi.ts] +import { http, createConfig } from "wagmi"; +import { baseSepolia } from "wagmi/chains"; +import { coinbaseWallet } from "wagmi/connectors"; + +export const config = createConfig({ + chains: [baseSepolia], + connectors: [ + coinbaseWallet({ + appName: "Create Wagmi", + appChainIds: [baseSepolia.id], + }), + ], + transports: { + [baseSepolia.id]: http(), + }, +}); + +declare module "wagmi" { + interface Register { + config: typeof config; + } +} +``` + +::: + +### Notes + +- For more detail, view the [`useConnect` documentation](https://wagmi.sh/react/api/hooks/useConnect). +- Upon successful connection, account information can be accessed via [data](https://wagmi.sh/react/api/hooks/useConnect#data) +returned from `useConnect`, or via [`useAccount`](https://wagmi.sh/react/api/hooks/useAccount). + +## Without wagmi + +:::code-group + +```tsx [CreateWalletButton.tsx] +import { CoinbaseWalletSDK } from "@coinbase/wallet-sdk"; +import { CoinbaseWalletLogo } from "./CoinbaseWalletLogo"; + +const buttonStyles = { + background: "transparent", + border: "1px solid transparent", + display: "flex", + alignItems: "center", + fontFamily: "Arial, sans-serif", + fontWeight: "bold", + fontSize: 18, + backgroundColor: "#0052FF", + padding: "7px 14px", + borderRadius: 10, +}; + +const sdk = new CoinbaseWalletSDK({ + appName: "My Dapp", + appLogoUrl: "https://example.com/logo.png", + appChainIds: [84532], +}); + +const provider = sdk.makeWeb3Provider(); + +interface CreateWalletButtonProps { + handleSuccess: (res: any) => void; + handleError: (error: any) => void; +} + +export function CreateWalletButton({ + handleSuccess, + handleError, +}: CreateWalletButtonProps) { + const connectToSmartWallet = async () => { + try { + const [address] = await provider.request({ + method: "eth_requestAccounts", + }); + handleSuccess(address); + } catch (error) { + handleError(error); + } + }; + return ( + + ); +} +``` + +```tsx twoslash [CoinbaseWalletLogo.tsx] +import React from "react"; + +const defaultContainerStyles = { + paddingRight: 10, + paddingTop: 2, +}; + +export function CoinbaseWalletLogo({ + size = 25, + containerStyles = defaultContainerStyles, +}) { + return ( +
+ + + + +
+ ); +} +``` + +```ts twoslash [wagmi.ts] +import { http, createConfig } from "wagmi"; +import { baseSepolia } from "wagmi/chains"; +import { coinbaseWallet } from "wagmi/connectors"; + +export const config = createConfig({ + chains: [baseSepolia], + connectors: [ + coinbaseWallet({ + appName: "Create Wagmi", + appChainIds: [baseSepolia.id], + }), + ], + transports: { + [baseSepolia.id]: http(), + }, +}); + +declare module "wagmi" { + interface Register { + config: typeof config; + } +} +``` + +::: diff --git a/docs/pages/guides/create-wallet-button.mdx b/docs/pages/guides/create-wallet-button.mdx deleted file mode 100644 index 966ac75..0000000 --- a/docs/pages/guides/create-wallet-button.mdx +++ /dev/null @@ -1,46 +0,0 @@ -# Add a Create a Wallet button to your appChainIds - -## With wagmi - -```tsx -import { useConnect } from "wagmi"; - -export function WagmiCreateWalletButton() { - const { connectors, connect } = useConnect(); - - return ; -} -``` - -Upon successful connection, access account information via the [`useAccount`](https://wagmi.sh/react/api/hooks/useAccount) hook. - -## Without wagmi - -```tsx -import { CoinbaseWalletSDK } from "@coinbase/wallet-sdk"; - -const sdk = new CoinbaseWalletSDK({ - appName: "My Dapp", - appLogoUrl: "https://example.com/logo.png", - appChainIds: [84532], -}); - -const provider = sdk.makeWeb3Provider(); - -interface CreateWalletButtonProps { - handleSuccess: (res: any) => void; - handleError: (error: any) => void; -} - -export function CreateWalletButton({ handleSuccess, handleError }: CreateWalletButtonProps) { - const connectToSmartWallet = async () => { - try { - const [address] = await provider.request({ method: "eth_requestAccounts" }); - handleSuccess(address); - } catch (error) { - handleError(error); - } - }; - return ; -} -``` diff --git a/vocs.config.ts b/vocs.config.ts index 5f398e8..2e64f0f 100644 --- a/vocs.config.ts +++ b/vocs.config.ts @@ -62,8 +62,13 @@ export default defineConfig({ link: "/guides/update-existing-app", }, { - text: "Add Create Wallet Button", - link: "/guides/create-wallet-button", + text: "Components", + items: [ + { + text: "Create Wallet button", + link: "/guides/components/create-wallet-button", + }, + ], }, { text: "Signature Verification",