Skip to content

Commit

Permalink
docs: add documentation for <ConnectWallet />'s onConnect handler (
Browse files Browse the repository at this point in the history
  • Loading branch information
dschlabach authored Nov 1, 2024
1 parent 0fcf2b3 commit d47723a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
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)](https://docs.login.xyz/general-information/siwe-overview) with OnchainKit, you can use the `onConnect` prop in the `<ConnectWallet />` component. This will trigger the SIWE prompt when the user connects their wallet.

```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

0 comments on commit d47723a

Please sign in to comment.