@mysten/dapp-kit-react 1.1.0 → 2.0.1
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.
- package/dist/index.d.mts +22 -40
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2 -55
- package/dist/index.mjs.map +1 -1
- package/dist/ui.d.mts +23 -0
- package/dist/ui.d.mts.map +1 -0
- package/dist/ui.mjs +38 -0
- package/dist/ui.mjs.map +1 -0
- package/dist/useDAppKit-LUp-KcgG.mjs +24 -0
- package/dist/useDAppKit-LUp-KcgG.mjs.map +1 -0
- package/docs/actions/connect-wallet.md +68 -0
- package/docs/actions/disconnect-wallet.md +37 -0
- package/docs/actions/sign-and-execute-transaction.md +95 -0
- package/docs/actions/sign-personal-message.md +57 -0
- package/docs/actions/sign-transaction.md +64 -0
- package/docs/actions/switch-account.md +36 -0
- package/docs/actions/switch-network.md +36 -0
- package/docs/dapp-kit-instance.md +163 -0
- package/docs/getting-started/create-dapp.md +151 -0
- package/docs/getting-started/next-js.md +162 -0
- package/docs/getting-started/react.md +170 -0
- package/docs/getting-started/vue.md +188 -0
- package/docs/index.md +70 -0
- package/docs/llms-index.md +34 -0
- package/docs/react/components/connect-button.md +42 -0
- package/docs/react/components/connect-modal.md +51 -0
- package/docs/react/components/index.md +13 -0
- package/docs/react/dapp-kit-provider.md +86 -0
- package/docs/react/hooks/index.md +25 -0
- package/docs/react/hooks/use-current-account.md +33 -0
- package/docs/react/hooks/use-current-client.md +36 -0
- package/docs/react/hooks/use-current-network.md +28 -0
- package/docs/react/hooks/use-current-wallet.md +36 -0
- package/docs/react/hooks/use-dapp-kit.md +100 -0
- package/docs/react/hooks/use-wallet-connection.md +48 -0
- package/docs/react/hooks/use-wallets.md +33 -0
- package/docs/state.md +168 -0
- package/docs/theming.md +196 -0
- package/docs/web-components/connect-button.md +87 -0
- package/docs/web-components/connect-modal.md +176 -0
- package/package.json +9 -2
- package/src/index.ts +0 -6
- package/src/ui.ts +8 -0
|
@@ -0,0 +1,87 @@
|
|
|
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).
|
|
@@ -0,0 +1,176 @@
|
|
|
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).
|
package/package.json
CHANGED
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
"name": "@mysten/dapp-kit-react",
|
|
3
3
|
"author": "Mysten Labs <build@mystenlabs.com>",
|
|
4
4
|
"description": "React bindings for @mysten/dapp-kit-core",
|
|
5
|
-
"version": "
|
|
5
|
+
"version": "2.0.1",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"files": [
|
|
8
8
|
"LICENSE",
|
|
9
9
|
"README.md",
|
|
10
10
|
"dist",
|
|
11
|
+
"docs",
|
|
11
12
|
"src"
|
|
12
13
|
],
|
|
13
14
|
"type": "module",
|
|
@@ -18,6 +19,11 @@
|
|
|
18
19
|
"types": "./dist/index.d.mts",
|
|
19
20
|
"import": "./dist/index.mjs",
|
|
20
21
|
"default": "./dist/index.mjs"
|
|
22
|
+
},
|
|
23
|
+
"./ui": {
|
|
24
|
+
"types": "./dist/ui.d.mts",
|
|
25
|
+
"import": "./dist/ui.mjs",
|
|
26
|
+
"default": "./dist/ui.mjs"
|
|
21
27
|
}
|
|
22
28
|
},
|
|
23
29
|
"repository": {
|
|
@@ -40,7 +46,7 @@
|
|
|
40
46
|
"@lit/react": "^1.0.8",
|
|
41
47
|
"@nanostores/react": "^1.0.0",
|
|
42
48
|
"nanostores": "^1.1.0",
|
|
43
|
-
"@mysten/dapp-kit-core": "^1.
|
|
49
|
+
"@mysten/dapp-kit-core": "^1.2.0"
|
|
44
50
|
},
|
|
45
51
|
"peerDependencies": {
|
|
46
52
|
"@types/react": ">=17.0.0",
|
|
@@ -49,6 +55,7 @@
|
|
|
49
55
|
"scripts": {
|
|
50
56
|
"clean": "rm -rf tsconfig.tsbuildinfo ./dist",
|
|
51
57
|
"build": "pnpm typecheck && tsdown",
|
|
58
|
+
"build:docs": "tsx ../../../docs/scripts/build-docs.ts",
|
|
52
59
|
"typecheck": "tsc --noEmit",
|
|
53
60
|
"dev": "tsdown --watch",
|
|
54
61
|
"prettier:check": "prettier -c --ignore-unknown .",
|
package/src/index.ts
CHANGED
|
@@ -3,12 +3,6 @@
|
|
|
3
3
|
|
|
4
4
|
export * from '@mysten/dapp-kit-core';
|
|
5
5
|
|
|
6
|
-
export { ConnectButton } from './components/ConnectButton.js';
|
|
7
|
-
export type { ConnectButtonProps } from './components/ConnectButton.js';
|
|
8
|
-
|
|
9
|
-
export { ConnectModal } from './components/ConnectModal.js';
|
|
10
|
-
export type { ConnectModalProps } from './components/ConnectModal.js';
|
|
11
|
-
|
|
12
6
|
export { DAppKitProvider, DAppKitContext } from './components/DAppKitProvider.js';
|
|
13
7
|
export type { DAppKitProviderProps } from './components/DAppKitProvider.js';
|
|
14
8
|
|
package/src/ui.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Copyright (c) Mysten Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
export { ConnectButton } from './components/ConnectButton.js';
|
|
5
|
+
export type { ConnectButtonProps } from './components/ConnectButton.js';
|
|
6
|
+
|
|
7
|
+
export { ConnectModal } from './components/ConnectModal.js';
|
|
8
|
+
export type { ConnectModalProps } from './components/ConnectModal.js';
|