From 17182fdb84699babb52d5be89ffedee4bf91427f Mon Sep 17 00:00:00 2001 From: Leonardo Zizzamia Date: Wed, 18 Sep 2024 16:34:52 +0800 Subject: [PATCH] docs: wallet story time (#1276) --- site/docs/components/WalletComponents.tsx | 2 +- site/docs/pages/transaction/transaction.mdx | 2 +- site/docs/pages/wallet/wallet.mdx | 222 +++++++++++++------- 3 files changed, 144 insertions(+), 82 deletions(-) diff --git a/site/docs/components/WalletComponents.tsx b/site/docs/components/WalletComponents.tsx index 30eb9d07ae..0a9fbed540 100644 --- a/site/docs/components/WalletComponents.tsx +++ b/site/docs/components/WalletComponents.tsx @@ -9,7 +9,7 @@ type WalletComponentsReact = { export default function WalletComponents({ children }: WalletComponentsReact) { return ( -
{children}
+
{children}
); } diff --git a/site/docs/pages/transaction/transaction.mdx b/site/docs/pages/transaction/transaction.mdx index 8f1e933f96..e5ca314414 100644 --- a/site/docs/pages/transaction/transaction.mdx +++ b/site/docs/pages/transaction/transaction.mdx @@ -297,7 +297,7 @@ The components are designed to work together hierarchically. For each component, - `` - Displays the label text in the transaction toast notification. - `` - Provides additional actions within the transaction toast notification. -## Props +## Component types - [`TransactionButtonReact`](/transaction/types#transactionbuttonreact) - [`TransactionError`](/transaction/types#transactionerror) diff --git a/site/docs/pages/wallet/wallet.mdx b/site/docs/pages/wallet/wallet.mdx index 7c9cec1071..416920775e 100644 --- a/site/docs/pages/wallet/wallet.mdx +++ b/site/docs/pages/wallet/wallet.mdx @@ -1,12 +1,15 @@ --- title: ยท OnchainKit -description: Wallet components & utilities +description: The `` components provides an interface for users to connect their Smart Wallet with their identity information like Basename and ETH balance. --- import { ConnectWallet, + ConnectWalletText, Wallet, WalletDropdown, + WalletDropdownBasename, + WalletDropdownFundLink, WalletDropdownLink, WalletDropdownDisconnect, } from '@coinbase/onchainkit/wallet'; @@ -23,16 +26,64 @@ import WalletComponents from '../../components/WalletComponents'; # `` -The Wallet components provide a comprehensive interface for users to connect their Smart Wallet, view their identity information, and manage their wallet connection. Before using them, ensure you've completed all Getting Started steps. +The `` components provides an interface for users to connect their +Smart Wallet with their identity information like Basename and ETH balance. -## Usage +It features built-in polished user experiences for both web and mobile web, +making it incredibly easy to enhance with drop-in components. + +Before using them, ensure you've completed all [Getting Started steps](/getting-started). + +## Walkthrough + +::::steps + +### Set up your wallet connections + +Kick off your wallet connection setup by configuring the `wagmi` provider. + +And make sure to update the `appName` as that will be displayed to +the user when they connect their wallet. + +```tsx twoslash +import { ReactNode } from 'react'; +import { WagmiProvider, createConfig, http } from 'wagmi'; +import { baseSepolia } from 'wagmi/chains'; +import { coinbaseWallet } from 'wagmi/connectors'; + +const wagmiConfig = createConfig({ + chains: [baseSepolia], + connectors: [ + coinbaseWallet({ + appName: 'onchainkit', + }), + ], + ssr: true, + transports: { + [baseSepolia.id]: http(), + }, +}); + +function App({ children }: { children: ReactNode }) { + return {children}; +} +``` + +### Drop in the `` components + +Experience the magic by simply dropping in the `` component +and watch it seamlessly come to life. +
+Additionally, you can see the [``](/identity/identity) components +like [``](/identity/avatar), [``](/identity/name), +and [`
`](/identity/address) are used in a composable way. +Explore their documentation pages to discover various customization options. ```tsx twoslash import { // [!code focus] ConnectWallet, // [!code focus] Wallet, // [!code focus] WalletDropdown, // [!code focus] - WalletDropdownLink, // [!code focus] WalletDropdownDisconnect, // [!code focus] } from '@coinbase/onchainkit/wallet'; // [!code focus] import { @@ -40,7 +91,6 @@ import { Avatar, Name, Identity, - EthBalance, } from '@coinbase/onchainkit/identity'; import { color } from '@coinbase/onchainkit/theme'; @@ -57,11 +107,7 @@ export function WalletComponents() {
- - // [!code focus] - Wallet // [!code focus] - // [!code focus] // [!code focus] // [!code focus] // [!code focus] @@ -81,26 +127,30 @@ export function WalletComponents() {
- - - Wallet - -### Override styles +### Drop in pre-made wallet components -You can override component styles using `className`. +Expand the user experience with pre-made components like [``](/wallet/wallet-dropdown-link), +[``](/wallet/wallet-dropdown-basename), + [``](/wallet/wallet-dropdown-fund-link), + or ``, to help you build a seamless wallet experience for your users. +
+The `` is highly versatile and will likely be your go-to choice +for adding more links to the dropdown, connecting your users to various pages of your onchain app. ```tsx twoslash import { ConnectWallet, Wallet, WalletDropdown, - WalletDropdownLink, + WalletDropdownBasename, // [!code focus] + WalletDropdownFundLink, // [!code focus] + WalletDropdownLink, // [!code focus] WalletDropdownDisconnect, } from '@coinbase/onchainkit/wallet'; import { @@ -108,139 +158,147 @@ import { Avatar, Name, Identity, - EthBalance, + EthBalance, // [!code focus] } from '@coinbase/onchainkit/identity'; -import { color } from '@coinbase/onchainkit/theme'; -// ---cut-before--- + // omitted for brevity - + - +
- + // [!code focus] - - Wallet - - + // [!code focus] + // [!code focus] + Wallet // [!code focus] + // [!code focus] + // [!code focus] + ``` - + - + - +
+ Wallet - + + -### Override text +### Customize Connect button text and style + +Each OnchainKit component offers the flexibility to customize `className` +and adjust the style of the React components it represents. -You can override component text using `text`. +Customize the connect wallet text by using directly the `` component. ```tsx twoslash import { ConnectWallet, + ConnectWalletText, Wallet, + WalletDropdown, + WalletDropdownLink, + WalletDropdownDisconnect, } from '@coinbase/onchainkit/wallet'; import { + Address, Avatar, Name, + Identity, + EthBalance, } from '@coinbase/onchainkit/identity'; +import { color } from '@coinbase/onchainkit/theme'; // ---cut-before--- // omitted for brevity - // [!code focus] - - + // [!code focus] + Log In // [!code focus] + // [!code focus] + // [!code focus] + + + + +
+ + + + Wallet + + // [!code focus] + ``` - + + Log In - + - +
- + Wallet - + -## Required providers - -If you are using any of the provided components, you will need to install -and configure `wagmi` and wrap your app in ``. - -```tsx twoslash -import { ReactNode } from 'react'; -import { WagmiProvider, createConfig, http } from 'wagmi'; -import { baseSepolia } from 'wagmi/chains'; -import { coinbaseWallet } from 'wagmi/connectors'; - -const wagmiConfig = createConfig({ - chains: [baseSepolia], - connectors: [ - coinbaseWallet({ - appName: 'onchainkit', - }), - ], - ssr: true, - transports: { - [baseSepolia.id]: http(), - }, -}); - -function App({ children }: { children: ReactNode }) { - return {children}; -} -``` - -## Use wallet aggregator +### Use RainbowKit for wallet aggregation You can expand the wallet connection options by using the `withWalletAggregator` prop in the `` component. This will present users with a list of recommended and other wallets to choose from. @@ -271,7 +329,7 @@ import { // omitted for brevity - + // [!code focus] @@ -364,7 +422,7 @@ export default OnchainProviders; ::: -
+
@@ -389,6 +447,8 @@ export default OnchainProviders;
+:::: + ## Components The components are designed to work together hierarchically. For each component, ensure the following: @@ -409,9 +469,11 @@ Additional components for customizing the wallet interface include: - `
` - Shows the user's wallet address. - `` - Displays the user's ETH balance. -The Wallet component automatically handles the wallet connection state and updates the UI accordingly. You need to wrap your application or relevant part of it with these components to provide a complete wallet interaction experience. +The Wallet component automatically handles the wallet connection state and updates the UI accordingly. +You need to wrap your application or relevant part of it with these components +to provide a complete wallet interaction experience. -## Props +## Component types - [`WalletReact`](/wallet/types#walletreact) - [`ConnectWalletReact`](/wallet/types#connectwalletreact)