Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add documentation for <ConnectWallet />'s onConnect handler #1555

Merged
merged 8 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions site/docs/pages/wallet/types.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type ConnectWalletReact = {
className?: string; // Optional className override for button element
text?: string; // Optional text override for button. Note: Prefer using `ConnectWalletText` component instead as this will be deprecated in a future version.
withWalletAggregator?: boolean; // Optional flag to enable the wallet aggregator like RainbowKit
onConnect?: () => void; // Optional callback function that is called when the wallet is connected. Can be used to trigger SIWE prompts or other actions.
};
```

Expand Down
33 changes: 32 additions & 1 deletion site/docs/pages/wallet/wallet.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ import {
```

```tsx twoslash [OnchainProviders.tsx]
// @noErrors: 2304 2322 - Cannot find VITE_WALLET_CONNECT_PROJECT_ID, Canoot find name Props
// @noErrors: 2304 2322 - Cannot find VITE_WALLET_CONNECT_PROJECT_ID, Cannot find name Props
'use client';
import type { ReactNode } from 'react';
import { OnchainKitProvider } from '@coinbase/onchainkit';
Expand Down Expand Up @@ -476,6 +476,37 @@ export default OnchainProviders;

::::

## Examples

### With Sign In With Ethereum (SIWE)

To use Sign In With Ethereum (SIWE) with OnchainKit, you can use the `onConnect` prop in the `<ConnectWallet />` component. This will trigger the SIWE prompt when the user connects their wallet.
dschlabach marked this conversation as resolved.
Show resolved Hide resolved

```tsx twoslash
import { ConnectWallet } from '@coinbase/onchainkit/wallet';
import { base } from 'wagmi/chains';
import { createSiweMessage } from 'viem/siwe'
import { useSignMessage } from 'wagmi';

const message = createSiweMessage({
address: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
chainId: base.id,
domain: 'example.com',
nonce: 'foobarbaz',
uri: 'https://example.com/path',
version: '1',
})

export function WalletComponents() {
const { signMessage } = useSignMessage();

return (
<ConnectWallet onConnect={() => {signMessage({ message })}} />
);
}

```

## Components

The components are designed to work together hierarchically. For each component, ensure the following:
Expand Down