@mysten/dapp-kit-react 2.0.1 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/dist/index.d.mts +9 -9
  2. package/dist/index.d.mts.map +1 -1
  3. package/dist/ui.d.mts.map +1 -1
  4. package/package.json +3 -5
  5. package/docs/actions/connect-wallet.md +0 -68
  6. package/docs/actions/disconnect-wallet.md +0 -37
  7. package/docs/actions/sign-and-execute-transaction.md +0 -95
  8. package/docs/actions/sign-personal-message.md +0 -57
  9. package/docs/actions/sign-transaction.md +0 -64
  10. package/docs/actions/switch-account.md +0 -36
  11. package/docs/actions/switch-network.md +0 -36
  12. package/docs/dapp-kit-instance.md +0 -163
  13. package/docs/getting-started/create-dapp.md +0 -151
  14. package/docs/getting-started/next-js.md +0 -162
  15. package/docs/getting-started/react.md +0 -170
  16. package/docs/getting-started/vue.md +0 -188
  17. package/docs/index.md +0 -70
  18. package/docs/llms-index.md +0 -34
  19. package/docs/react/components/connect-button.md +0 -42
  20. package/docs/react/components/connect-modal.md +0 -51
  21. package/docs/react/components/index.md +0 -13
  22. package/docs/react/dapp-kit-provider.md +0 -86
  23. package/docs/react/hooks/index.md +0 -25
  24. package/docs/react/hooks/use-current-account.md +0 -33
  25. package/docs/react/hooks/use-current-client.md +0 -36
  26. package/docs/react/hooks/use-current-network.md +0 -28
  27. package/docs/react/hooks/use-current-wallet.md +0 -36
  28. package/docs/react/hooks/use-dapp-kit.md +0 -100
  29. package/docs/react/hooks/use-wallet-connection.md +0 -48
  30. package/docs/react/hooks/use-wallets.md +0 -33
  31. package/docs/state.md +0 -168
  32. package/docs/theming.md +0 -196
  33. package/docs/web-components/connect-button.md +0 -87
  34. package/docs/web-components/connect-modal.md +0 -176
package/docs/state.md DELETED
@@ -1,168 +0,0 @@
1
- # State
2
-
3
- > Access and subscribe to wallet connection state in dApp Kit
4
-
5
- The Sui dApp Kit SDK uses [nanostores](https://github.com/nanostores/nanostores) for state
6
- management, providing a lightweight, framework-agnostic solution that works across React, Vue,
7
- Vanilla JavaScript, and other frameworks.
8
-
9
- ## Available Stores
10
-
11
- The dApp Kit exposes four reactive stores that you can subscribe to:
12
-
13
- - **`$connection`** - Current wallet connection state
14
- - **`$currentNetwork`** - Currently selected network
15
- - **`$currentClient`** - Client instance for the current network
16
- - **`$wallets`** - List of available wallets
17
-
18
- ## Accessing Stores
19
-
20
- All stores are available through the `dAppKit.stores` property:
21
-
22
- ```typescript
23
- const dAppKit = createDAppKit({
24
- /* config */
25
- });
26
-
27
- // Access stores
28
- const connection = dAppKit.stores.$connection.get();
29
- const currentNetwork = dAppKit.stores.$currentNetwork.get();
30
- const client = dAppKit.stores.$currentClient.get();
31
- const wallets = dAppKit.stores.$wallets.get();
32
- ```
33
-
34
- ## Subscribing to State Changes
35
-
36
- Subscribe to any store to react to state changes:
37
-
38
- ```typescript
39
- // Subscribe to connection changes
40
- const unsubscribe = dAppKit.stores.$connection.subscribe((connection) => {
41
- if (connection.isConnected && connection.wallet && connection.account) {
42
- console.log('Connected to:', connection.wallet.name);
43
- console.log('Account:', connection.account.address);
44
- } else {
45
- console.log('Not connected');
46
- }
47
- });
48
-
49
- // Clean up subscription when done
50
- unsubscribe();
51
- ```
52
-
53
- ## Store Details
54
-
55
- ### Connection Store (`$connection`)
56
-
57
- Contains the current wallet connection state with status flags:
58
-
59
- ```typescript
60
- const connection = dAppKit.stores.$connection.get();
61
-
62
- // Connection has these properties:
63
- // - wallet: UiWallet | null
64
- // - account: UiWalletAccount | null
65
- // - status: 'connected' | 'connecting' | 'reconnecting' | 'disconnected'
66
- // - supportedIntents: string[]
67
- // - isConnected: boolean
68
- // - isConnecting: boolean
69
- // - isReconnecting: boolean
70
- // - isDisconnected: boolean
71
- ```
72
-
73
- Example usage:
74
-
75
- ```typescript
76
- const connection = dAppKit.stores.$connection.get();
77
-
78
- if (connection.isConnected && connection.wallet && connection.account) {
79
- console.log('Address:', connection.account.address);
80
- console.log('Wallet:', connection.wallet.name);
81
- console.log('Available accounts:', connection.wallet.accounts);
82
- }
83
- ```
84
-
85
- ### Current Network Store (`$currentNetwork`)
86
-
87
- Contains the currently selected network as a string:
88
-
89
- ```typescript
90
- const currentNetwork = dAppKit.stores.$currentNetwork.get(); // 'mainnet' | 'testnet' | ...
91
-
92
- // Subscribe to network changes
93
- dAppKit.stores.$currentNetwork.subscribe((network) => {
94
- console.log('Switched to network:', network);
95
- });
96
- ```
97
-
98
- Note: This store is read-only. Use `dAppKit.switchNetwork()` to change networks.
99
-
100
- ### Current Client Store (`$currentClient`)
101
-
102
- Contains the SuiClient instance for the current network:
103
-
104
- ```typescript
105
- const client = dAppKit.stores.$currentClient.get();
106
-
107
- // Use the client to query the blockchain
108
- const balance = await client.getBalance({
109
- owner: '0x...',
110
- });
111
- ```
112
-
113
- Note: This store automatically updates when the network changes.
114
-
115
- ### Wallets Store (`$wallets`)
116
-
117
- Contains the list of available wallets:
118
-
119
- ```typescript
120
- const wallets = dAppKit.stores.$wallets.get();
121
-
122
- wallets.forEach((wallet) => {
123
- console.log('Wallet:', wallet.name);
124
- console.log('Icon:', wallet.icon);
125
- });
126
- ```
127
-
128
- ## Subscribing to State Changes
129
-
130
- You can subscribe directly to stores:
131
-
132
- ```typescript
133
- // Subscribe to connection changes
134
- dAppKit.stores.$connection.subscribe((connection) => {
135
- const statusElement = document.getElementById('connection-status');
136
- if (statusElement === null) return;
137
- if (connection.isConnected && connection.account) {
138
- statusElement.textContent = `Connected: ${connection.account.address}`;
139
- } else {
140
- statusElement.textContent = 'Not connected';
141
- }
142
- });
143
-
144
- // Subscribe to network changes
145
- dAppKit.stores.$currentNetwork.subscribe((network) => {
146
- const networkElement = document.getElementById('current-network');
147
- if (networkElement === null) return;
148
- networkElement.textContent = `Network: ${network}`;
149
- });
150
- ```
151
-
152
- ## React
153
-
154
- React users can use the [provided hooks](./react/hooks/use-wallet-connection) instead of direct
155
- store access.
156
-
157
- ## Properties
158
-
159
- Besides stores, some values are available as direct properties:
160
-
161
- ```typescript
162
- // Get available networks (not a store, just a property)
163
- const networks = dAppKit.networks; // ['mainnet', 'testnet', ...]
164
-
165
- // Get client for specific network
166
- const mainnetClient = dAppKit.getClient('mainnet');
167
- const currentClient = dAppKit.getClient(); // Current network's client
168
- ```
package/docs/theming.md DELETED
@@ -1,196 +0,0 @@
1
- # Theming
2
-
3
- > Customize the appearance of dApp Kit UI components
4
-
5
- The dApp Kit web components use a theming system compatible with
6
- [shadcn/ui](https://ui.shadcn.com/docs/theming). Components are customized using CSS custom
7
- properties (CSS variables), allowing you to match them to your application's design system.
8
-
9
- > **Note:** **shadcn/ui Compatibility**: The dApp Kit uses the same CSS custom property naming
10
- > convention as shadcn/ui. If your application already uses shadcn/ui themes, the dApp Kit
11
- > components will automatically inherit your theme. You can also use
12
- > [shadcn/ui's theme builder](https://ui.shadcn.com/themes) to create custom themes.
13
-
14
- ## CSS Custom Properties
15
-
16
- All dApp Kit web components support the following CSS custom properties:
17
-
18
- ### Colors
19
-
20
- These color variables follow the shadcn/ui naming convention. Colors can be defined using any valid
21
- CSS color format (hex, rgb, hsl, oklch, etc.).
22
-
23
- - **`--background`** - Background color of the component. Used as the default background for UI
24
- elements.
25
- - **`--foreground`** - Foreground color of the component. Used as the default text color.
26
- - **`--primary`** - Primary color used for interactive elements such as buttons and links.
27
- - **`--primary-foreground`** - Text or icon color placed on top of primary elements.
28
- - **`--secondary`** - Secondary color used for less prominent interactive elements.
29
- - **`--secondary-foreground`** - Text or icon color placed on top of secondary elements.
30
- - **`--border`** - Border color for UI elements.
31
- - **`--accent`** - Accent color used for highlights and decorative elements.
32
- - **`--accent-foreground`** - Text or icon color placed on top of accent elements.
33
- - **`--muted`** - Background color for subtle or muted UI elements (e.g., placeholders, disabled
34
- states).
35
- - **`--muted-foreground`** - Text or icon color for muted UI elements.
36
- - **`--popover`** - Background color for floating elements such as popovers, dropdowns, or tooltips.
37
- - **`--popover-foreground`** - Text or icon color inside popover elements.
38
- - **`--ring`** - Color used for focus rings (visible focus indicators on interactive elements).
39
-
40
- ### Typography
41
-
42
- - **`--font-sans`** - Font family used for text content.
43
- - **`--font-weight-medium`** - Medium font weight for text (typically used for buttons and
44
- interactive elements).
45
- - **`--font-weight-semibold`** - Semibold font weight for text (typically used for headings or
46
- emphasized text).
47
-
48
- ### Layout
49
-
50
- - **`--radius`** - Border radius used for UI elements.
51
-
52
- ## Usage
53
-
54
- ### Global Theming
55
-
56
- Apply custom properties to affect all dApp Kit components:
57
-
58
- ```css
59
- :root {
60
- --primary: #4f46e5;
61
- --primary-foreground: #ffffff;
62
- --background: #ffffff;
63
- --foreground: #0f172a;
64
- --border: #e2e8f0;
65
- --radius: 0.5rem;
66
- --font-sans: 'Inter', sans-serif;
67
- }
68
- ```
69
-
70
- ### Component-Specific Theming
71
-
72
- Target specific components:
73
-
74
- ```css
75
- mysten-dapp-kit-connect-button {
76
- --primary: #10b981;
77
- --primary-foreground: #ffffff;
78
- --radius: 0.75rem;
79
- }
80
-
81
- mysten-dapp-kit-connect-modal {
82
- --background: #f8fafc;
83
- --popover: #ffffff;
84
- }
85
- ```
86
-
87
- ### Dark Mode
88
-
89
- Implement dark mode by overriding the custom properties:
90
-
91
- ```css
92
- :root {
93
- --background: #ffffff;
94
- --foreground: #0f172a;
95
- --primary: #4f46e5;
96
- --border: #e2e8f0;
97
- }
98
-
99
- @media (prefers-color-scheme: dark) {
100
- :root {
101
- --background: #0f172a;
102
- --foreground: #f1f5f9;
103
- --primary: #818cf8;
104
- --border: #334155;
105
- }
106
- }
107
- ```
108
-
109
- Or use a class-based approach:
110
-
111
- ```css
112
- .light-theme {
113
- --background: #ffffff;
114
- --foreground: #0f172a;
115
- }
116
-
117
- .dark-theme {
118
- --background: #0f172a;
119
- --foreground: #f1f5f9;
120
- }
121
- ```
122
-
123
- ```tsx
124
- <div className={isDark ? 'dark-theme' : 'light-theme'}>
125
- <ConnectButton />
126
- </div>
127
- ```
128
-
129
- ## Example: Complete Theme
130
-
131
- Here's a complete theme example matching a custom design system:
132
-
133
- ```css
134
- :root {
135
- /* Colors */
136
- --background: hsl(0 0% 100%);
137
- --foreground: hsl(222.2 84% 4.9%);
138
- --primary: hsl(221.2 83.2% 53.3%);
139
- --primary-foreground: hsl(210 40% 98%);
140
- --secondary: hsl(210 40% 96.1%);
141
- --secondary-foreground: hsl(222.2 47.4% 11.2%);
142
- --accent: hsl(210 40% 96.1%);
143
- --accent-foreground: hsl(222.2 47.4% 11.2%);
144
- --muted: hsl(210 40% 96.1%);
145
- --muted-foreground: hsl(215.4 16.3% 46.9%);
146
- --border: hsl(214.3 31.8% 91.4%);
147
- --popover: hsl(0 0% 100%);
148
- --popover-foreground: hsl(222.2 84% 4.9%);
149
- --ring: hsl(221.2 83.2% 53.3%);
150
-
151
- /* Typography */
152
- --font-sans:
153
- system-ui, -apple-system, 'Segoe UI', 'Roboto', 'Ubuntu', 'Cantarell', 'Noto Sans', sans-serif;
154
- --font-weight-medium: 500;
155
- --font-weight-semibold: 600;
156
-
157
- /* Layout */
158
- --radius: 0.5rem;
159
- }
160
- ```
161
-
162
- ## Framework Integration
163
-
164
- ### React
165
-
166
- ```tsx
167
-
168
- return <ConnectButton />;
169
- }
170
- ```
171
-
172
- ### Vue
173
-
174
- ```vue
175
- <template>
176
- <mysten-dapp-kit-connect-button :instance="dAppKit" />
177
- </template>
178
-
179
- <style>
180
- @import './theme.css';
181
- </style>
182
- ```
183
-
184
- ### Vanilla JavaScript
185
-
186
- ```html
187
- <!doctype html>
188
- <html>
189
- <head>
190
- <link rel="stylesheet" href="theme.css" />
191
- </head>
192
- <body>
193
- <mysten-dapp-kit-connect-button></mysten-dapp-kit-connect-button>
194
- </body>
195
- </html>
196
- ```
@@ -1,87 +0,0 @@
1
- # Connect Button
2
-
3
- > Framework-agnostic web component for wallet connection
4
-
5
- The `<mysten-dapp-kit-connect-button>` Web Component provides a complete wallet connection UI. It
6
- displays a "Connect Wallet" button when no wallet is connected, and shows the connected account with
7
- a menu when a wallet is active.
8
-
9
- > Auto-connect is enabled by default and will attempt to restore the previous wallet connection on
10
- > page reload. This provides a seamless user experience but can be
11
- > [disabled](../dapp-kit-instance#disabling-auto-connect) if needed.
12
-
13
- ## Basic Usage
14
-
15
- ### Vanilla
16
-
17
- ```html
18
- <mysten-dapp-kit-connect-button></mysten-dapp-kit-connect-button>
19
-
20
- <script>
21
- const button = document.querySelector('mysten-dapp-kit-connect-button');
22
- button!.instance = dAppKit;
23
- </script>
24
- ```
25
-
26
- ### Vue
27
-
28
- ```vue
29
- <script setup></script>
30
-
31
- <template>
32
- <mysten-dapp-kit-connect-button :instance="dAppKit" />
33
- </template>
34
- ```
35
-
36
- ### React
37
-
38
- DApp Kit React bindings provide a [React wrapper](../react/components/connect-button) for the
39
- button.
40
-
41
- ## Features
42
-
43
- The connect button component automatically handles:
44
-
45
- - **Wallet Connection**: Opens a modal to select and connect a wallet
46
- - **Account Display**: Shows the connected account address
47
- - **Account Switching**: Provides a menu to switch between multiple accounts when connected
48
- - **Disconnection**: Includes a disconnect option in the menu
49
-
50
- ## Properties
51
-
52
- - **instance** - The dApp Kit instance
53
- - **modalOptions** (optional) - Configuration options for the connect modal
54
- - `filterFn` - Function to filter available wallets
55
- - `sortFn` - Function to sort available wallets
56
-
57
- ## Custom Button Text
58
-
59
- Use the default slot to customize the button text when not connected:
60
-
61
- ```html
62
- <mysten-dapp-kit-connect-button>
63
- <span>Sign In</span>
64
- </mysten-dapp-kit-connect-button>
65
- ```
66
-
67
- ## Modal Integration
68
-
69
- The connect button automatically manages its own modal. You don't need to add a separate
70
- `<mysten-dapp-kit-connect-modal>` component when using the connect button.
71
-
72
- ## Connected State
73
-
74
- When a wallet is connected, the button transforms into an account menu that displays:
75
-
76
- - Account address (truncated)
77
- - SUI balance
78
- - Network indicator
79
- - Menu options for:
80
- - Switching accounts (if multiple accounts available)
81
- - Managing connection
82
- - Disconnecting
83
-
84
- ## Server-Side Rendering (SSR)
85
-
86
- The `<mysten-dapp-kit-connect-button>` Web Component can be only client-side rendered, as wallets
87
- are detected in the browser. For Next.js guide see [here](../getting-started/next-js).
@@ -1,176 +0,0 @@
1
- # Connect Modal
2
-
3
- > Framework-agnostic web component for wallet selection
4
-
5
- The `<mysten-dapp-kit-connect-modal>` Web Component provides a modal dialog for wallet connection.
6
- While most apps should use the [`Connect Button`](./connect-button) which includes an integrated
7
- modal, the standalone modal is useful for advanced scenarios requiring custom trigger mechanisms.
8
-
9
- ## When to Use
10
-
11
- Use the standalone modal when you need:
12
-
13
- - **Custom trigger elements** - Menu items, keyboard shortcuts, or other non-button triggers
14
- - **Complex UI flows** - Integration into existing navigation or custom wallet management interfaces
15
- - **Programmatic control** - Opening the modal based on application logic or user actions
16
- - **Multiple triggers** - Different parts of your UI that can open the same modal
17
-
18
- For standard wallet connection with a button, use the [Connect Button](./connect-button) component
19
- instead.
20
-
21
- ## Basic Usage
22
-
23
- ### Vanilla
24
-
25
- ```html
26
- <button id="custom-trigger">Open Wallet Selector</button>
27
- <mysten-dapp-kit-connect-modal></mysten-dapp-kit-connect-modal>
28
-
29
- <script>
30
- import { createDAppKit } from '@mysten/dapp-kit-core';
31
- import { SuiGrpcClient } from '@mysten/sui/grpc';
32
-
33
- const GRPC_URLS = {
34
- mainnet: 'https://fullnode.mainnet.sui.io:443',
35
- testnet: 'https://fullnode.testnet.sui.io:443',
36
- };
37
-
38
- const dAppKit = createDAppKit({
39
- enableBurnerWallet: import.meta.env.DEV,
40
- networks: ['mainnet', 'testnet'],
41
- defaultNetwork: 'testnet',
42
- createClient(network) {
43
- return new SuiGrpcClient({ network, baseUrl: GRPC_URLS[network] });
44
- },
45
- });
46
-
47
- const modal = document.querySelector('mysten-dapp-kit-connect-modal');
48
- modal!.instance = dAppKit;
49
-
50
- const trigger = document.getElementById('custom-trigger');
51
- trigger?.addEventListener('click', () => {
52
- modal!.show();
53
- });
54
- </script>
55
- ```
56
-
57
- ### Vue
58
-
59
- ```vue
60
- <script setup lang="ts">
61
- const modalRef = ref();
62
- const isModalOpen = ref(false);
63
-
64
- const openModal = () => {
65
- // Using property binding
66
- isModalOpen.value = true;
67
- // Or using method
68
- modalRef.value.show();
69
- };
70
- </script>
71
-
72
- <template>
73
- <!-- Custom trigger -->
74
- <button @click="openModal">Select Wallet</button>
75
-
76
- <!-- Modal component -->
77
- <mysten-dapp-kit-connect-modal
78
- ref="modalRef"
79
- :instance="dAppKit"
80
- :open="isModalOpen"
81
- @closed="isModalOpen = false"
82
- />
83
- </template>
84
- ```
85
-
86
- ### React
87
-
88
- DApp Kit React bindings provide a [React wrapper](../react/components/connect-modal) for the modal.
89
-
90
- ## Properties
91
-
92
- - **instance** - The dApp Kit instance
93
- - **open** - Boolean to control modal visibility programmatically
94
- - **filterFn** (optional) - Function to filter available wallets
95
- - Type: `(wallet: UiWallet, index: number, array: UiWallet[]) => boolean`
96
- - **sortFn** (optional) - Function to sort available wallets
97
- - Type: `(a: UiWallet, b: UiWallet) => number`
98
-
99
- ## Methods
100
-
101
- ### show()
102
-
103
- Opens the modal programmatically:
104
-
105
- ```js
106
- const modal = document.querySelector('mysten-dapp-kit-connect-modal');
107
- await modal?.show();
108
- ```
109
-
110
- ### close(returnValue: string)
111
-
112
- Closes the modal with an optional return value:
113
-
114
- ```js
115
- const modal = document.querySelector('mysten-dapp-kit-connect-modal');
116
- await modal?.close('user-cancelled');
117
- ```
118
-
119
- ## Events
120
-
121
- The modal fires several events during its lifecycle:
122
-
123
- - **open** - Fired before the modal opens (cancelable)
124
- - **opened** - Fired after the modal has fully opened
125
- - **close** - Fired before the modal closes (cancelable)
126
- - **closed** - Fired after the modal has fully closed
127
- - **cancel** - Fired when clicking backdrop or pressing Escape (cancelable)
128
-
129
- ```js
130
- const modal = document.querySelector('mysten-dapp-kit-connect-modal');
131
-
132
- modal?.addEventListener('open', (event) => {
133
- console.log('Modal is about to open');
134
- // Prevent opening if needed
135
- // event.preventDefault();
136
- });
137
-
138
- modal?.addEventListener('opened', () => {
139
- console.log('Modal is now open');
140
- });
141
-
142
- modal?.addEventListener('closed', () => {
143
- console.log('Modal has closed');
144
- });
145
-
146
- modal?.addEventListener('cancel', (event) => {
147
- console.log('User clicked backdrop or pressed Escape');
148
- });
149
- ```
150
-
151
- ## Examples
152
-
153
- ### Programmatic Control
154
-
155
- ```js
156
- const modal = document.querySelector('mysten-dapp-kit-connect-modal');
157
- modal.instance = dAppKit;
158
-
159
- // Open modal when user tries to perform an action that requires connection
160
- async function performAction() {
161
- const connection = dAppKit.stores.$connection.get();
162
-
163
- if (!connection.account) {
164
- await modal.show();
165
- // Wait for connection or cancellation
166
- return;
167
- }
168
-
169
- // Proceed with action...
170
- }
171
- ```
172
-
173
- ## Server-Side Rendering (SSR)
174
-
175
- The `<mysten-dapp-kit-connect-modal>` Web Component can be only client-side rendered, as wallets are
176
- detected in the browser. For Next.js guide see [here](../getting-started/next-js).