@mysten/dapp-kit 1.0.3 → 1.0.4
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/CHANGELOG.md +11 -0
- package/docs/index.md +91 -0
- package/docs/llms-index.md +27 -0
- package/docs/rpc-hooks.md +161 -0
- package/docs/slush.md +29 -0
- package/docs/sui-client-provider.md +191 -0
- package/docs/themes.md +115 -0
- package/docs/wallet-components/ConnectButton.md +22 -0
- package/docs/wallet-components/ConnectModal.md +66 -0
- package/docs/wallet-hooks/useAccounts.md +36 -0
- package/docs/wallet-hooks/useAutoConnectWallet.md +29 -0
- package/docs/wallet-hooks/useConnectWallet.md +48 -0
- package/docs/wallet-hooks/useCurrentAccount.md +36 -0
- package/docs/wallet-hooks/useCurrentWallet.md +59 -0
- package/docs/wallet-hooks/useDisconnectWallet.md +26 -0
- package/docs/wallet-hooks/useSignAndExecuteTransaction.md +124 -0
- package/docs/wallet-hooks/useSignPersonalMessage.md +59 -0
- package/docs/wallet-hooks/useSignTransaction.md +67 -0
- package/docs/wallet-hooks/useSwitchAccount.md +47 -0
- package/docs/wallet-hooks/useWallets.md +38 -0
- package/docs/wallet-provider.md +37 -0
- package/package.json +6 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# @mysten/dapp-kit
|
|
2
2
|
|
|
3
|
+
## 1.0.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 43e69f8: Add embedded LLM-friendly docs to published packages
|
|
8
|
+
- Updated dependencies [43e69f8]
|
|
9
|
+
- Updated dependencies [e51dc5d]
|
|
10
|
+
- @mysten/slush-wallet@1.0.3
|
|
11
|
+
- @mysten/sui@2.8.0
|
|
12
|
+
- @mysten/wallet-standard@0.20.1
|
|
13
|
+
|
|
3
14
|
## 1.0.3
|
|
4
15
|
|
|
5
16
|
### Patch Changes
|
package/docs/index.md
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# Sui dApp Kit (Legacy)
|
|
2
|
+
|
|
3
|
+
> dApp Kit API reference for @mysten/dapp-kit
|
|
4
|
+
|
|
5
|
+
> **Warning:** **Deprecated - JSON RPC Only**: This legacy version of `@mysten/dapp-kit` only works
|
|
6
|
+
> with the deprecated JSON RPC API and will not be updated to support gRPC or GraphQL. For new
|
|
7
|
+
> projects, use [`@mysten/dapp-kit-core` and `@mysten/dapp-kit-react`](/dapp-kit).
|
|
8
|
+
|
|
9
|
+
The Sui dApp Kit is a set of React components, hooks, and utilities to help you build a dApp for the
|
|
10
|
+
Sui ecosystem. Its hooks and components provide an interface for querying data from the Sui network
|
|
11
|
+
and connecting to Sui wallets.
|
|
12
|
+
|
|
13
|
+
### Core Features
|
|
14
|
+
|
|
15
|
+
Some of the core features of the dApp Kit include:
|
|
16
|
+
|
|
17
|
+
- Query hooks to get the information your dApp needs
|
|
18
|
+
- Automatic wallet state management
|
|
19
|
+
- Support for all Sui wallets
|
|
20
|
+
- Pre-built React components
|
|
21
|
+
- Lower level hooks for custom components
|
|
22
|
+
|
|
23
|
+
## Install
|
|
24
|
+
|
|
25
|
+
To use the Sui dApp Kit in your project, run the following command in your project root:
|
|
26
|
+
|
|
27
|
+
```sh npm2yarn
|
|
28
|
+
npm i --save @mysten/dapp-kit @mysten/sui @tanstack/react-query
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Setting up providers
|
|
32
|
+
|
|
33
|
+
To use the hooks and components in the dApp Kit, wrap your app with the providers shown in the
|
|
34
|
+
following example. The props available on the providers are covered in more detail in their
|
|
35
|
+
respective pages.
|
|
36
|
+
|
|
37
|
+
```tsx
|
|
38
|
+
// Config options for the networks you want to connect to
|
|
39
|
+
const { networkConfig } = createNetworkConfig({
|
|
40
|
+
localnet: { url: getFullnodeUrl('localnet') },
|
|
41
|
+
mainnet: { url: getFullnodeUrl('mainnet') },
|
|
42
|
+
});
|
|
43
|
+
const queryClient = new QueryClient();
|
|
44
|
+
|
|
45
|
+
function App() {
|
|
46
|
+
return (
|
|
47
|
+
<QueryClientProvider client={queryClient}>
|
|
48
|
+
<SuiClientProvider networks={networkConfig} defaultNetwork="localnet">
|
|
49
|
+
<WalletProvider>
|
|
50
|
+
<YourApp />
|
|
51
|
+
</WalletProvider>
|
|
52
|
+
</SuiClientProvider>
|
|
53
|
+
</QueryClientProvider>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Using UI components to connect to a wallet
|
|
59
|
+
|
|
60
|
+
The dApp Kit provides a set of flexible UI components that you can use to connect and manage wallet
|
|
61
|
+
accounts from your dApp. The components are built on top of
|
|
62
|
+
[Radix UI](https://www.radix-ui.com/primitives) and are customizable.
|
|
63
|
+
|
|
64
|
+
To use the provided UI components, import the dApp Kit CSS stylesheet into your dApp. For more
|
|
65
|
+
information regarding customization options, check out the respective documentation pages for the
|
|
66
|
+
components and [themes](/dapp-kit/legacy/themes).
|
|
67
|
+
|
|
68
|
+
```tsx
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Using hooks to make RPC calls
|
|
73
|
+
|
|
74
|
+
The dApp Kit provides a set of hooks for making RPC calls to the Sui blockchain. The hooks are thin
|
|
75
|
+
wrappers around `useQuery` from `@tanstack/react-query`. For more comprehensive documentation on how
|
|
76
|
+
to use these query hooks, check out the
|
|
77
|
+
[react-query documentation](https://tanstack.com/query/latest/docs/react/overview).
|
|
78
|
+
|
|
79
|
+
```tsx
|
|
80
|
+
function MyComponent() {
|
|
81
|
+
const { data, isPending, error, refetch } = useSuiClientQuery('getOwnedObjects', {
|
|
82
|
+
owner: '0x123',
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
if (isPending) {
|
|
86
|
+
return <div>Loading...</div>;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return <pre>{JSON.stringify(data, null, 2)}</pre>;
|
|
90
|
+
}
|
|
91
|
+
```
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# dApp Kit (Legacy)
|
|
2
|
+
|
|
3
|
+
> Build Sui dapps in React with @mysten/dapp-kit
|
|
4
|
+
|
|
5
|
+
- [Sui dApp Kit (Legacy)](./index.md): dApp Kit API reference for @mysten/dapp-kit
|
|
6
|
+
- [SuiClientProvider](./sui-client-provider.md): React provider for Sui client configuration
|
|
7
|
+
- [Rpc Hooks](./rpc-hooks.md): React hooks for Sui RPC queries
|
|
8
|
+
- [WalletProvider](./wallet-provider.md): React provider for wallet connections
|
|
9
|
+
- [ConnectButton](./wallet-components/ConnectButton.md): React connect button component
|
|
10
|
+
- [ConnectModal](./wallet-components/ConnectModal.md): React connect modal component
|
|
11
|
+
- [useAccounts](./wallet-hooks/useAccounts.md): List wallet accounts
|
|
12
|
+
- [useAutoConnectWallet](./wallet-hooks/useAutoConnectWallet.md): Automatically reconnect to the
|
|
13
|
+
last connected wallet
|
|
14
|
+
- [useConnectWallet](./wallet-hooks/useConnectWallet.md): Connect a wallet to the dApp
|
|
15
|
+
- [useCurrentAccount](./wallet-hooks/useCurrentAccount.md): Get the current wallet account
|
|
16
|
+
- [useCurrentWallet](./wallet-hooks/useCurrentWallet.md): Get the current wallet connection
|
|
17
|
+
- [useDisconnectWallet](./wallet-hooks/useDisconnectWallet.md): Disconnect the current wallet
|
|
18
|
+
- [useSignAndExecuteTransaction](./wallet-hooks/useSignAndExecuteTransaction.md): Sign and execute a
|
|
19
|
+
transaction
|
|
20
|
+
- [useSignPersonalMessage](./wallet-hooks/useSignPersonalMessage.md): Sign a personal message with
|
|
21
|
+
the connected wallet
|
|
22
|
+
- [useSignTransaction](./wallet-hooks/useSignTransaction.md): Sign a transaction without executing
|
|
23
|
+
it
|
|
24
|
+
- [useSwitchAccount](./wallet-hooks/useSwitchAccount.md): Switch the active wallet account
|
|
25
|
+
- [useWallets](./wallet-hooks/useWallets.md): List available wallet extensions
|
|
26
|
+
- [Slush Integration](./slush.md): Slush wallet integration for dApp Kit
|
|
27
|
+
- [Themes](./themes.md): theming API for dApp Kit components
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
# Rpc Hooks
|
|
2
|
+
|
|
3
|
+
> React hooks for Sui RPC queries
|
|
4
|
+
|
|
5
|
+
Sui dApp Kit ships with hooks for each of the RPC methods defined in the
|
|
6
|
+
[JSON RPC specification](https://docs.sui.io/sui-api-ref).
|
|
7
|
+
|
|
8
|
+
## useSuiClientQuery
|
|
9
|
+
|
|
10
|
+
Load data from the Sui RPC using the `useSuiClientQuery` hook. This hook is a wrapper around the
|
|
11
|
+
[useQuery](https://tanstack.com/query/latest/docs/react/guides/queries) hook from
|
|
12
|
+
@tanstack/react-query.
|
|
13
|
+
|
|
14
|
+
The hook takes the RPC method name as the first argument and any parameters as the second argument.
|
|
15
|
+
You can pass any additional `useQuery` options as the third argument. You can read the
|
|
16
|
+
[useQuery documentation](https://tanstack.com/query/latest/docs/react/guides/queries) for more
|
|
17
|
+
details on the full set of options available.
|
|
18
|
+
|
|
19
|
+
```tsx
|
|
20
|
+
function MyComponent() {
|
|
21
|
+
const { data, isPending, isError, error, refetch } = useSuiClientQuery(
|
|
22
|
+
'getOwnedObjects',
|
|
23
|
+
{ owner: '0x123' },
|
|
24
|
+
{
|
|
25
|
+
gcTime: 10000,
|
|
26
|
+
},
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
if (isPending) {
|
|
30
|
+
return <div>Loading...</div>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (isError) {
|
|
34
|
+
return <div>Error: {error.message}</div>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return <pre>{JSON.stringify(data, null, 2)}</pre>;
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## useSuiClientQueries
|
|
42
|
+
|
|
43
|
+
You can fetch a variable number of Sui RPC queries using the `useSuiClientQueries` hook. This hook
|
|
44
|
+
is a wrapper around the
|
|
45
|
+
[useQueries](https://tanstack.com/query/latest/docs/react/reference/useQueries) hook from
|
|
46
|
+
@tanstack/react-query.
|
|
47
|
+
|
|
48
|
+
The `queries` value is an array of query option objects identical to the `useSuiClientQuery` hook.
|
|
49
|
+
|
|
50
|
+
The `combine` parameter is optional. Use this parameter to combine the results of the queries into a
|
|
51
|
+
single value. The result is structurally shared to be as referentially stable as possible.
|
|
52
|
+
|
|
53
|
+
```tsx
|
|
54
|
+
function MyComponent() {
|
|
55
|
+
const { data, isPending, isError } = useSuiClientQueries({
|
|
56
|
+
queries: [
|
|
57
|
+
{
|
|
58
|
+
method: 'getAllBalances',
|
|
59
|
+
params: {
|
|
60
|
+
owner: '0x123',
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
method: 'queryTransactionBlocks',
|
|
65
|
+
params: {
|
|
66
|
+
filter: {
|
|
67
|
+
FromAddress: '0x123',
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
combine: (result) => {
|
|
73
|
+
return {
|
|
74
|
+
data: result.map((res) => res.data),
|
|
75
|
+
isSuccess: result.every((res) => res.isSuccess),
|
|
76
|
+
isPending: result.some((res) => res.isPending),
|
|
77
|
+
isError: result.some((res) => res.isError),
|
|
78
|
+
};
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
if (isPending) {
|
|
83
|
+
return <div>Loading...</div>;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (isError) {
|
|
87
|
+
return <div>Fetching Error</div>;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return <pre>{JSON.stringify(data, null, 2)}</pre>;
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## useSuiClientInfiniteQuery
|
|
95
|
+
|
|
96
|
+
For RPC methods that support pagination, dApp Kit also implements a `useSuiClientInfiniteQuery`
|
|
97
|
+
hook. For more details check out the
|
|
98
|
+
[`useInfiniteQuery` documentation](https://tanstack.com/query/latest/docs/react/guides/infinite-queries).
|
|
99
|
+
|
|
100
|
+
```tsx
|
|
101
|
+
function MyComponent() {
|
|
102
|
+
const { data, isPending, isError, error, isFetching, fetchNextPage, hasNextPage } =
|
|
103
|
+
useSuiClientInfiniteQuery('getOwnedObjects', {
|
|
104
|
+
owner: '0x123',
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
if (isPending) {
|
|
108
|
+
return <div>Loading...</div>;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (isError) {
|
|
112
|
+
return <div>Error: {error.message}</div>;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return <pre>{JSON.stringify(data, null, 2)}</pre>;
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## useSuiClientMutation
|
|
120
|
+
|
|
121
|
+
For RPC methods that mutate state, dApp Kit implements a `useSuiClientMutation` hook. Use this hook
|
|
122
|
+
with any RPC method to imperatively call the RPC method. For more details, check out the
|
|
123
|
+
[`useMutation` documentation](https://tanstack.com/query/latest/docs/react/guides/mutations).
|
|
124
|
+
|
|
125
|
+
```tsx
|
|
126
|
+
function MyComponent() {
|
|
127
|
+
const { mutate } = useSuiClientMutation('dryRunTransactionBlock');
|
|
128
|
+
|
|
129
|
+
return (
|
|
130
|
+
<Button
|
|
131
|
+
onClick={() => {
|
|
132
|
+
mutate({
|
|
133
|
+
transactionBlock: tx,
|
|
134
|
+
});
|
|
135
|
+
}}
|
|
136
|
+
>
|
|
137
|
+
Dry run transaction
|
|
138
|
+
</Button>
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## useResolveSuiNSName
|
|
144
|
+
|
|
145
|
+
To get the SuiNS name for a given address, use the `useResolveSuiNSName` hook.
|
|
146
|
+
|
|
147
|
+
```tsx
|
|
148
|
+
function MyComponent() {
|
|
149
|
+
const { data, isPending } = useResolveSuiNSName('0x123');
|
|
150
|
+
|
|
151
|
+
if (isPending) {
|
|
152
|
+
return <div>Loading...</div>;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (data) {
|
|
156
|
+
return <div>Domain name is: {data}</div>;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return <div>Domain name not found</div>;
|
|
160
|
+
}
|
|
161
|
+
```
|
package/docs/slush.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Slush Integration
|
|
2
|
+
|
|
3
|
+
> Slush wallet integration for dApp Kit
|
|
4
|
+
|
|
5
|
+
dApp Kit provides out-of-the-box opt-in support for the [Slush wallet](/slush-wallet/dapp).
|
|
6
|
+
|
|
7
|
+
## Setup
|
|
8
|
+
|
|
9
|
+
To enable support for Slush wallets, pass the `slushWallet` object to the `WalletProvider`
|
|
10
|
+
component. This object has the following properties:
|
|
11
|
+
|
|
12
|
+
- **`name`** - The name of your dApp, shown to the user when connecting to the dApp.
|
|
13
|
+
|
|
14
|
+
```tsx
|
|
15
|
+
function App({ children }) {
|
|
16
|
+
return (
|
|
17
|
+
<WalletProvider
|
|
18
|
+
slushWallet={{
|
|
19
|
+
name: 'Your dApp name',
|
|
20
|
+
}}
|
|
21
|
+
>
|
|
22
|
+
{children}
|
|
23
|
+
</WalletProvider>
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
> Note: In the connect modal, users with the Slush Wallet extension installed will only see the
|
|
29
|
+
> extension. If they don’t have it, the connection will default to the Slush web app.
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
# SuiClientProvider
|
|
2
|
+
|
|
3
|
+
> React provider for Sui client configuration
|
|
4
|
+
|
|
5
|
+
The `SuiClientProvider` manages the active `SuiJsonRpcClient` that hooks and components use in the
|
|
6
|
+
dApp Kit.
|
|
7
|
+
|
|
8
|
+
## Usage
|
|
9
|
+
|
|
10
|
+
Place the `SuiClientProvider` at the root of your app and wrap all components that use the dApp Kit
|
|
11
|
+
hooks.
|
|
12
|
+
|
|
13
|
+
`SuiClientProvider` accepts a list of network configurations to create `SuiJsonRpcClient` instances
|
|
14
|
+
for the currently active network.
|
|
15
|
+
|
|
16
|
+
```tsx
|
|
17
|
+
// Config options for the networks you want to connect to
|
|
18
|
+
const { networkConfig } = createNetworkConfig({
|
|
19
|
+
localnet: { url: getJsonRpcFullnodeUrl('localnet') },
|
|
20
|
+
mainnet: { url: getJsonRpcFullnodeUrl('mainnet') },
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
function App() {
|
|
24
|
+
return (
|
|
25
|
+
<SuiClientProvider networks={networkConfig} defaultNetwork="localnet">
|
|
26
|
+
<YourApp />
|
|
27
|
+
</SuiClientProvider>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Props
|
|
33
|
+
|
|
34
|
+
- `networks`: A map of networks you can use. The keys are the network names, and the values can be
|
|
35
|
+
either a configuration object (`SuiClientOptions`) or a `SuiJsonRpcClient` instance.
|
|
36
|
+
- `defaultNetwork`: The name of the network to use by default when using the `SuiClientProvider` as
|
|
37
|
+
an uncontrolled component.
|
|
38
|
+
- `network`: The name of the network to use when using the `SuiClientProvider` as a controlled
|
|
39
|
+
component.
|
|
40
|
+
- `onNetworkChange`: A callback when the active network changes.
|
|
41
|
+
- `createClient`: A callback when a new `SuiJsonRpcClient` is created (for example, when the active
|
|
42
|
+
network changes). It receives the network name and configuration object as arguments, returning a
|
|
43
|
+
`SuiJsonRpcClient` instance.
|
|
44
|
+
|
|
45
|
+
## Controlled component
|
|
46
|
+
|
|
47
|
+
The following example demonstrates a `SuiClientProvider` used as a controlled component.
|
|
48
|
+
|
|
49
|
+
```tsx
|
|
50
|
+
// Config options for the networks you want to connect to
|
|
51
|
+
const { networkConfig } = createNetworkConfig({
|
|
52
|
+
localnet: { url: getJsonRpcFullnodeUrl('localnet') },
|
|
53
|
+
mainnet: { url: getJsonRpcFullnodeUrl('mainnet') },
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
function App() {
|
|
57
|
+
const [activeNetwork, setActiveNetwork] = useState('localnet' as keyof typeof networks);
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<SuiClientProvider
|
|
61
|
+
networks={networkConfig}
|
|
62
|
+
network={activeNetwork}
|
|
63
|
+
onNetworkChange={(network) => {
|
|
64
|
+
setActiveNetwork(network);
|
|
65
|
+
}}
|
|
66
|
+
>
|
|
67
|
+
<YourApp />
|
|
68
|
+
</SuiClientProvider>
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## SuiJsonRpcClient customization
|
|
74
|
+
|
|
75
|
+
The following example demonstrates how to create a custom `SuiJsonRpcClient`.
|
|
76
|
+
|
|
77
|
+
```tsx
|
|
78
|
+
// Config options for the networks you want to connect to
|
|
79
|
+
const networks = {
|
|
80
|
+
localnet: { url: getJsonRpcFullnodeUrl('localnet') },
|
|
81
|
+
mainnet: { url: getJsonRpcFullnodeUrl('mainnet') },
|
|
82
|
+
} satisfies Record<string, SuiClientOptions>;
|
|
83
|
+
|
|
84
|
+
function App() {
|
|
85
|
+
return (
|
|
86
|
+
<SuiClientProvider
|
|
87
|
+
networks={networks}
|
|
88
|
+
defaultNetwork="localnet"
|
|
89
|
+
createClient={(network, config) => {
|
|
90
|
+
return new SuiJsonRpcClient({
|
|
91
|
+
transport: new SuiHTTPTransport({
|
|
92
|
+
url: 'https://api.safecoin.org',
|
|
93
|
+
rpc: {
|
|
94
|
+
headers: {
|
|
95
|
+
Authorization: 'xyz',
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
}),
|
|
99
|
+
});
|
|
100
|
+
}}
|
|
101
|
+
>
|
|
102
|
+
<YourApp />
|
|
103
|
+
</SuiClientProvider>
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Using the SuiJsonRpcClient from the provider
|
|
109
|
+
|
|
110
|
+
To use the `SuiJsonRpcClient` from the provider, import the `useSuiClient` function from the
|
|
111
|
+
`@mysten/dapp-kit` module.
|
|
112
|
+
|
|
113
|
+
```tsx
|
|
114
|
+
function MyComponent() {
|
|
115
|
+
const client = useSuiClient();
|
|
116
|
+
|
|
117
|
+
// use the client
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Creating a network selector
|
|
122
|
+
|
|
123
|
+
The dApp Kit doesn't provide its own network switcher, but you can use the `useSuiClientContext`
|
|
124
|
+
hook to get the list of networks and set the active one:
|
|
125
|
+
|
|
126
|
+
```tsx
|
|
127
|
+
function NetworkSelector() {
|
|
128
|
+
const ctx = useSuiClientContext();
|
|
129
|
+
|
|
130
|
+
return (
|
|
131
|
+
<div>
|
|
132
|
+
{Object.keys(ctx.networks).map((network) => (
|
|
133
|
+
<button key={network} onClick={() => ctx.selectNetwork(network)}>
|
|
134
|
+
{`select ${network}`}
|
|
135
|
+
</button>
|
|
136
|
+
))}
|
|
137
|
+
</div>
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## Using network specific configuration
|
|
143
|
+
|
|
144
|
+
If your dApp runs on multiple networks, the IDs for packages and other configurations might change,
|
|
145
|
+
depending on which network you're using. You can use `createNetworkConfig` to create per-network
|
|
146
|
+
configurations that your components can access.
|
|
147
|
+
|
|
148
|
+
The `createNetworkConfig` function returns the provided configuration, along with hooks you can use
|
|
149
|
+
to get the variables defined in your configuration.
|
|
150
|
+
|
|
151
|
+
- `useNetworkConfig` returns the full network configuration object
|
|
152
|
+
- `useNetworkVariables` returns the full variables object from the network configuration
|
|
153
|
+
- `useNetworkVariable` returns a specific variable from the network configuration
|
|
154
|
+
|
|
155
|
+
```tsx
|
|
156
|
+
// Config options for the networks you want to connect to
|
|
157
|
+
const { networkConfig, useNetworkVariable } = createNetworkConfig({
|
|
158
|
+
localnet: {
|
|
159
|
+
url: getJsonRpcFullnodeUrl('localnet'),
|
|
160
|
+
variables: {
|
|
161
|
+
myMovePackageId: '0x123',
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
mainnet: {
|
|
165
|
+
url: getJsonRpcFullnodeUrl('mainnet'),
|
|
166
|
+
variables: {
|
|
167
|
+
myMovePackageId: '0x456',
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
const queryClient = new QueryClient();
|
|
173
|
+
|
|
174
|
+
function App() {
|
|
175
|
+
return (
|
|
176
|
+
<QueryClientProvider client={queryClient}>
|
|
177
|
+
<SuiClientProvider networks={networkConfig} defaultNetwork="localnet">
|
|
178
|
+
<WalletProvider>
|
|
179
|
+
<YourApp />
|
|
180
|
+
</WalletProvider>
|
|
181
|
+
</SuiClientProvider>
|
|
182
|
+
</QueryClientProvider>
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function YourApp() {
|
|
187
|
+
const id = useNetworkVariable('myMovePackageId');
|
|
188
|
+
|
|
189
|
+
return <div>Package ID: {id}</div>;
|
|
190
|
+
}
|
|
191
|
+
```
|
package/docs/themes.md
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# Themes
|
|
2
|
+
|
|
3
|
+
> theming API for dApp Kit components
|
|
4
|
+
|
|
5
|
+
You can provide a theme to the `WalletProvider` component to customize the components in dApp Kit.
|
|
6
|
+
|
|
7
|
+
```tsx
|
|
8
|
+
const App = () => {
|
|
9
|
+
return (
|
|
10
|
+
<WalletProvider theme={lightTheme}>
|
|
11
|
+
<YourApp />
|
|
12
|
+
</WalletProvider>
|
|
13
|
+
);
|
|
14
|
+
};
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Dynamic themes
|
|
18
|
+
|
|
19
|
+
To dynamically change the theme, you can provide multiple themes to the `WalletProvider` component:
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
const App = () => {
|
|
23
|
+
return (
|
|
24
|
+
<WalletProvider
|
|
25
|
+
theme={[
|
|
26
|
+
{
|
|
27
|
+
// default to light theme
|
|
28
|
+
variables: lightTheme,
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
// Adds theme inside a media query
|
|
32
|
+
mediaQuery: '(prefers-color-scheme: dark)',
|
|
33
|
+
variables: darkTheme,
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
// prefixes the theme styles with the given selector
|
|
37
|
+
// this allows controlling the theme by adding a class to the body
|
|
38
|
+
selector: '.pink-theme',
|
|
39
|
+
variables: pinkTheme,
|
|
40
|
+
},
|
|
41
|
+
]}
|
|
42
|
+
>
|
|
43
|
+
<YourApp />
|
|
44
|
+
</WalletProvider>
|
|
45
|
+
);
|
|
46
|
+
};
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Theme variables
|
|
50
|
+
|
|
51
|
+
To define a custom theme, implement the `ThemeVars` interface with CSS variable values for your
|
|
52
|
+
theme:
|
|
53
|
+
|
|
54
|
+
```tsx
|
|
55
|
+
|
|
56
|
+
// Light theme copied from dapp-kit
|
|
57
|
+
|
|
58
|
+
blurs: {
|
|
59
|
+
modalOverlay: 'blur(0)',
|
|
60
|
+
},
|
|
61
|
+
backgroundColors: {
|
|
62
|
+
primaryButton: '#F6F7F9',
|
|
63
|
+
primaryButtonHover: '#F0F2F5',
|
|
64
|
+
outlineButtonHover: '#F4F4F5',
|
|
65
|
+
modalOverlay: 'rgba(24 36 53 / 20%)',
|
|
66
|
+
modalPrimary: 'white',
|
|
67
|
+
modalSecondary: '#F7F8F8',
|
|
68
|
+
iconButton: 'transparent',
|
|
69
|
+
iconButtonHover: '#F0F1F2',
|
|
70
|
+
dropdownMenu: '#FFFFFF',
|
|
71
|
+
dropdownMenuSeparator: '#F3F6F8',
|
|
72
|
+
walletItemSelected: 'white',
|
|
73
|
+
walletItemHover: '#3C424226',
|
|
74
|
+
},
|
|
75
|
+
borderColors: {
|
|
76
|
+
outlineButton: '#E4E4E7',
|
|
77
|
+
},
|
|
78
|
+
colors: {
|
|
79
|
+
primaryButton: '#373737',
|
|
80
|
+
outlineButton: '#373737',
|
|
81
|
+
iconButton: '#000000',
|
|
82
|
+
body: '#182435',
|
|
83
|
+
bodyMuted: '#767A81',
|
|
84
|
+
bodyDanger: '#FF794B',
|
|
85
|
+
},
|
|
86
|
+
radii: {
|
|
87
|
+
small: '6px',
|
|
88
|
+
medium: '8px',
|
|
89
|
+
large: '12px',
|
|
90
|
+
xlarge: '16px',
|
|
91
|
+
},
|
|
92
|
+
shadows: {
|
|
93
|
+
primaryButton: '0px 4px 12px rgba(0, 0, 0, 0.1)',
|
|
94
|
+
walletItemSelected: '0px 2px 6px rgba(0, 0, 0, 0.05)',
|
|
95
|
+
},
|
|
96
|
+
fontWeights: {
|
|
97
|
+
normal: '400',
|
|
98
|
+
medium: '500',
|
|
99
|
+
bold: '600',
|
|
100
|
+
},
|
|
101
|
+
fontSizes: {
|
|
102
|
+
small: '14px',
|
|
103
|
+
medium: '16px',
|
|
104
|
+
large: '18px',
|
|
105
|
+
xlarge: '20px',
|
|
106
|
+
},
|
|
107
|
+
typography: {
|
|
108
|
+
fontFamily:
|
|
109
|
+
'ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"',
|
|
110
|
+
fontStyle: 'normal',
|
|
111
|
+
lineHeight: '1.3',
|
|
112
|
+
letterSpacing: '1',
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
```
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# ConnectButton
|
|
2
|
+
|
|
3
|
+
> React connect button component
|
|
4
|
+
|
|
5
|
+
The `ConnectButton` shows the user a button to connect and disconnect a wallet. It automatically
|
|
6
|
+
uses the connected state to show a **connect** or **disconnect** button.
|
|
7
|
+
|
|
8
|
+
```tsx
|
|
9
|
+
|
|
10
|
+
return <ConnectButton />;
|
|
11
|
+
}
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
### Props
|
|
15
|
+
|
|
16
|
+
All props are optional.
|
|
17
|
+
|
|
18
|
+
- `connectText = "Connect Wallet"` - The text that displays in the button when the user is not
|
|
19
|
+
currently connected to a wallet.
|
|
20
|
+
- `walletFilter` - A filter function that receives a wallet instance, and returns a boolean
|
|
21
|
+
indicating whether the wallet should be displayed in the wallet list. By default, all wallets are
|
|
22
|
+
displayed.
|