@mysten/dapp-kit 1.0.5 → 1.0.6
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 +12 -0
- package/dist/components/AccountDropdownMenu.css.d.ts +7 -0
- package/dist/components/AccountDropdownMenu.css.d.ts.map +1 -0
- package/dist/components/AccountDropdownMenu.d.ts +11 -0
- package/dist/components/AccountDropdownMenu.d.ts.map +1 -0
- package/dist/components/ConnectButton.d.ts +10 -0
- package/dist/components/ConnectButton.d.ts.map +1 -0
- package/dist/components/SuiClientProvider.d.ts +26 -0
- package/dist/components/SuiClientProvider.d.ts.map +1 -0
- package/dist/components/WalletProvider.d.ts +27 -0
- package/dist/components/WalletProvider.d.ts.map +1 -0
- package/dist/components/connect-modal/ConnectModal.css.d.ts +12 -0
- package/dist/components/connect-modal/ConnectModal.css.d.ts.map +1 -0
- package/dist/components/connect-modal/ConnectModal.d.ts +24 -0
- package/dist/components/connect-modal/ConnectModal.d.ts.map +1 -0
- package/dist/components/connect-modal/InfoSection.css.d.ts +2 -0
- package/dist/components/connect-modal/InfoSection.css.d.ts.map +1 -0
- package/dist/components/connect-modal/InfoSection.d.ts +7 -0
- package/dist/components/connect-modal/InfoSection.d.ts.map +1 -0
- package/dist/components/connect-modal/views/ConnectionStatus.css.d.ts +6 -0
- package/dist/components/connect-modal/views/ConnectionStatus.css.d.ts.map +1 -0
- package/dist/components/connect-modal/views/ConnectionStatus.d.ts +9 -0
- package/dist/components/connect-modal/views/ConnectionStatus.d.ts.map +1 -0
- package/dist/components/connect-modal/views/GettingStarted.css.d.ts +4 -0
- package/dist/components/connect-modal/views/GettingStarted.css.d.ts.map +1 -0
- package/dist/components/connect-modal/views/GettingStarted.d.ts +2 -0
- package/dist/components/connect-modal/views/GettingStarted.d.ts.map +1 -0
- package/dist/components/connect-modal/views/WhatIsAWallet.css.d.ts +3 -0
- package/dist/components/connect-modal/views/WhatIsAWallet.css.d.ts.map +1 -0
- package/dist/components/connect-modal/views/WhatIsAWallet.d.ts +2 -0
- package/dist/components/connect-modal/views/WhatIsAWallet.d.ts.map +1 -0
- package/dist/components/connect-modal/wallet-list/WalletList.css.d.ts +2 -0
- package/dist/components/connect-modal/wallet-list/WalletList.css.d.ts.map +1 -0
- package/dist/components/connect-modal/wallet-list/WalletList.d.ts +10 -0
- package/dist/components/connect-modal/wallet-list/WalletList.d.ts.map +1 -0
- package/dist/components/connect-modal/wallet-list/WalletListItem.css.d.ts +5 -0
- package/dist/components/connect-modal/wallet-list/WalletListItem.css.d.ts.map +1 -0
- package/dist/components/connect-modal/wallet-list/WalletListItem.d.ts +10 -0
- package/dist/components/connect-modal/wallet-list/WalletListItem.d.ts.map +1 -0
- package/dist/components/icons/BackIcon.d.ts +3 -0
- package/dist/components/icons/BackIcon.d.ts.map +1 -0
- package/dist/components/icons/CheckIcon.d.ts +3 -0
- package/dist/components/icons/CheckIcon.d.ts.map +1 -0
- package/dist/components/icons/ChevronIcon.d.ts +3 -0
- package/dist/components/icons/ChevronIcon.d.ts.map +1 -0
- package/dist/components/icons/CloseIcon.d.ts +3 -0
- package/dist/components/icons/CloseIcon.d.ts.map +1 -0
- package/dist/components/styling/InjectedThemeStyles.d.ts +7 -0
- package/dist/components/styling/InjectedThemeStyles.d.ts.map +1 -0
- package/dist/components/styling/StyleMarker.css.d.ts +2 -0
- package/dist/components/styling/StyleMarker.css.d.ts.map +1 -0
- package/dist/components/styling/StyleMarker.d.ts +3 -0
- package/dist/components/styling/StyleMarker.d.ts.map +1 -0
- package/dist/components/ui/Button.css.d.ts +34 -0
- package/dist/components/ui/Button.css.d.ts.map +1 -0
- package/dist/components/ui/Button.d.ts +9 -0
- package/dist/components/ui/Button.d.ts.map +1 -0
- package/dist/components/ui/Heading.css.d.ts +34 -0
- package/dist/components/ui/Heading.css.d.ts.map +1 -0
- package/dist/components/ui/Heading.d.ts +13 -0
- package/dist/components/ui/Heading.d.ts.map +1 -0
- package/dist/components/ui/IconButton.css.d.ts +2 -0
- package/dist/components/ui/IconButton.css.d.ts.map +1 -0
- package/dist/components/ui/IconButton.d.ts +7 -0
- package/dist/components/ui/IconButton.d.ts.map +1 -0
- package/dist/components/ui/Text.css.d.ts +34 -0
- package/dist/components/ui/Text.css.d.ts.map +1 -0
- package/dist/components/ui/Text.d.ts +13 -0
- package/dist/components/ui/Text.d.ts.map +1 -0
- package/dist/constants/styleDataAttribute.d.ts +6 -0
- package/dist/constants/styleDataAttribute.d.ts.map +1 -0
- package/dist/constants/walletDefaults.d.ts +7 -0
- package/dist/constants/walletDefaults.d.ts.map +1 -0
- package/dist/constants/walletMutationKeys.d.ts +14 -0
- package/dist/constants/walletMutationKeys.d.ts.map +1 -0
- package/dist/contexts/walletContext.d.ts +14 -0
- package/dist/contexts/walletContext.d.ts.map +1 -0
- package/dist/errors/walletErrors.d.ts +23 -0
- package/dist/errors/walletErrors.d.ts.map +1 -0
- package/dist/hooks/networkConfig.d.ts +11 -0
- package/dist/hooks/networkConfig.d.ts.map +1 -0
- package/dist/hooks/useResolveSuiNSNames.d.ts +4 -0
- package/dist/hooks/useResolveSuiNSNames.d.ts.map +1 -0
- package/dist/hooks/useSuiClient.d.ts +4 -0
- package/dist/hooks/useSuiClient.d.ts.map +1 -0
- package/dist/hooks/useSuiClientInfiniteQuery.d.ts +26 -0
- package/dist/hooks/useSuiClientInfiniteQuery.d.ts.map +1 -0
- package/dist/hooks/useSuiClientMutation.d.ts +5 -0
- package/dist/hooks/useSuiClientMutation.d.ts.map +1 -0
- package/dist/hooks/useSuiClientQueries.d.ts +28 -0
- package/dist/hooks/useSuiClientQueries.d.ts.map +1 -0
- package/dist/hooks/useSuiClientQuery.d.ts +39 -0
- package/dist/hooks/useSuiClientQuery.d.ts.map +1 -0
- package/dist/hooks/wallet/useAccounts.d.ts +6 -0
- package/dist/hooks/wallet/useAccounts.d.ts.map +1 -0
- package/dist/hooks/wallet/useAutoConnectWallet.d.ts +2 -0
- package/dist/hooks/wallet/useAutoConnectWallet.d.ts.map +1 -0
- package/dist/hooks/wallet/useConnectWallet.d.ts +16 -0
- package/dist/hooks/wallet/useConnectWallet.d.ts.map +1 -0
- package/dist/hooks/wallet/useCurrentAccount.d.ts +6 -0
- package/dist/hooks/wallet/useCurrentAccount.d.ts.map +1 -0
- package/dist/hooks/wallet/useCurrentWallet.d.ts +26 -0
- package/dist/hooks/wallet/useCurrentWallet.d.ts.map +1 -0
- package/dist/hooks/wallet/useDisconnectWallet.d.ts +10 -0
- package/dist/hooks/wallet/useDisconnectWallet.d.ts.map +1 -0
- package/dist/hooks/wallet/useSignAndExecuteTransaction.d.ts +30 -0
- package/dist/hooks/wallet/useSignAndExecuteTransaction.d.ts.map +1 -0
- package/dist/hooks/wallet/useSignPersonalMessage.d.ts +14 -0
- package/dist/hooks/wallet/useSignPersonalMessage.d.ts.map +1 -0
- package/dist/hooks/wallet/useSignTransaction.d.ts +18 -0
- package/dist/hooks/wallet/useSignTransaction.d.ts.map +1 -0
- package/dist/hooks/wallet/useSlushWallet.d.ts +6 -0
- package/dist/hooks/wallet/useSlushWallet.d.ts.map +1 -0
- package/dist/hooks/wallet/useSwitchAccount.d.ts +15 -0
- package/dist/hooks/wallet/useSwitchAccount.d.ts.map +1 -0
- package/dist/hooks/wallet/useUnsafeBurnerWallet.d.ts +2 -0
- package/dist/hooks/wallet/useUnsafeBurnerWallet.d.ts.map +1 -0
- package/dist/hooks/wallet/useWalletPropertiesChanged.d.ts +5 -0
- package/dist/hooks/wallet/useWalletPropertiesChanged.d.ts.map +1 -0
- package/dist/hooks/wallet/useWalletStore.d.ts +3 -0
- package/dist/hooks/wallet/useWalletStore.d.ts.map +1 -0
- package/dist/hooks/wallet/useWallets.d.ts +5 -0
- package/dist/hooks/wallet/useWallets.d.ts.map +1 -0
- package/dist/hooks/wallet/useWalletsChanged.d.ts +6 -0
- package/dist/hooks/wallet/useWalletsChanged.d.ts.map +1 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/themes/lightTheme.d.ts +3 -0
- package/dist/themes/lightTheme.d.ts.map +1 -0
- package/dist/themes/themeContract.d.ts +141 -0
- package/dist/themes/themeContract.d.ts.map +1 -0
- package/dist/types/utilityTypes.d.ts +2 -0
- package/dist/types/utilityTypes.d.ts.map +1 -0
- package/dist/types.d.ts +3 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/assertUnreachable.d.ts +5 -0
- package/dist/utils/assertUnreachable.d.ts.map +1 -0
- package/dist/utils/stateStorage.d.ts +3 -0
- package/dist/utils/stateStorage.d.ts.map +1 -0
- package/dist/utils/walletUtils.d.ts +4 -0
- package/dist/utils/walletUtils.d.ts.map +1 -0
- package/dist/walletStore.d.ts +45 -0
- package/dist/walletStore.d.ts.map +1 -0
- package/docs/index.md +93 -0
- package/docs/llms-index.md +22 -0
- package/docs/rpc-hooks.md +166 -0
- package/docs/slush.md +29 -0
- package/docs/sui-client-provider.md +196 -0
- package/docs/themes.md +117 -0
- package/docs/wallet-components/ConnectButton.md +22 -0
- package/docs/wallet-components/ConnectModal.md +67 -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 +38 -0
- package/package.json +5 -5
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
# SuiClientProvider
|
|
2
|
+
|
|
3
|
+
> React provider for managing the active SuiJsonRpcClient in legacy dApp Kit.
|
|
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
|
+
|
|
18
|
+
// Config options for the networks you want to connect to
|
|
19
|
+
const { networkConfig } = createNetworkConfig({
|
|
20
|
+
localnet: { url: getJsonRpcFullnodeUrl('localnet') },
|
|
21
|
+
mainnet: { url: getJsonRpcFullnodeUrl('mainnet') },
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
function App() {
|
|
25
|
+
return (
|
|
26
|
+
<SuiClientProvider networks={networkConfig} defaultNetwork="localnet">
|
|
27
|
+
<YourApp />
|
|
28
|
+
</SuiClientProvider>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Props
|
|
34
|
+
|
|
35
|
+
- `networks`: A map of networks you can use. The keys are the network names, and the values can be
|
|
36
|
+
either a configuration object (`SuiClientOptions`) or a `SuiJsonRpcClient` instance.
|
|
37
|
+
- `defaultNetwork`: The name of the network to use by default when using the `SuiClientProvider` as
|
|
38
|
+
an uncontrolled component.
|
|
39
|
+
- `network`: The name of the network to use when using the `SuiClientProvider` as a controlled
|
|
40
|
+
component.
|
|
41
|
+
- `onNetworkChange`: A callback when the active network changes.
|
|
42
|
+
- `createClient`: A callback when a new `SuiJsonRpcClient` is created (for example, when the active
|
|
43
|
+
network changes). It receives the network name and configuration object as arguments, returning a
|
|
44
|
+
`SuiJsonRpcClient` instance.
|
|
45
|
+
|
|
46
|
+
## Controlled component
|
|
47
|
+
|
|
48
|
+
The following example demonstrates a `SuiClientProvider` used as a controlled component.
|
|
49
|
+
|
|
50
|
+
```tsx
|
|
51
|
+
|
|
52
|
+
// Config options for the networks you want to connect to
|
|
53
|
+
const { networkConfig } = createNetworkConfig({
|
|
54
|
+
localnet: { url: getJsonRpcFullnodeUrl('localnet') },
|
|
55
|
+
mainnet: { url: getJsonRpcFullnodeUrl('mainnet') },
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
function App() {
|
|
59
|
+
const [activeNetwork, setActiveNetwork] = useState('localnet' as keyof typeof networks);
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<SuiClientProvider
|
|
63
|
+
networks={networkConfig}
|
|
64
|
+
network={activeNetwork}
|
|
65
|
+
onNetworkChange={(network) => {
|
|
66
|
+
setActiveNetwork(network);
|
|
67
|
+
}}
|
|
68
|
+
>
|
|
69
|
+
<YourApp />
|
|
70
|
+
</SuiClientProvider>
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## `SuiJsonRpcClient` customization
|
|
76
|
+
|
|
77
|
+
The following example demonstrates how to create a custom `SuiJsonRpcClient`.
|
|
78
|
+
|
|
79
|
+
```tsx
|
|
80
|
+
|
|
81
|
+
// Config options for the networks you want to connect to
|
|
82
|
+
const networks = {
|
|
83
|
+
localnet: { url: getJsonRpcFullnodeUrl('localnet') },
|
|
84
|
+
mainnet: { url: getJsonRpcFullnodeUrl('mainnet') },
|
|
85
|
+
} satisfies Record<string, SuiClientOptions>;
|
|
86
|
+
|
|
87
|
+
function App() {
|
|
88
|
+
return (
|
|
89
|
+
<SuiClientProvider
|
|
90
|
+
networks={networks}
|
|
91
|
+
defaultNetwork="localnet"
|
|
92
|
+
createClient={(network, config) => {
|
|
93
|
+
return new SuiJsonRpcClient({
|
|
94
|
+
transport: new SuiHTTPTransport({
|
|
95
|
+
url: 'https://api.safecoin.org',
|
|
96
|
+
rpc: {
|
|
97
|
+
headers: {
|
|
98
|
+
Authorization: 'xyz',
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
}),
|
|
102
|
+
});
|
|
103
|
+
}}
|
|
104
|
+
>
|
|
105
|
+
<YourApp />
|
|
106
|
+
</SuiClientProvider>
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Using the `SuiJsonRpcClient` from the provider
|
|
112
|
+
|
|
113
|
+
To use the `SuiJsonRpcClient` from the provider, import the `useSuiClient` function from the
|
|
114
|
+
`@mysten/dapp-kit` module.
|
|
115
|
+
|
|
116
|
+
```tsx
|
|
117
|
+
|
|
118
|
+
function MyComponent() {
|
|
119
|
+
const client = useSuiClient();
|
|
120
|
+
|
|
121
|
+
// use the client
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Creating a network selector
|
|
126
|
+
|
|
127
|
+
The dApp Kit doesn't provide its own network switcher, but you can use the `useSuiClientContext`
|
|
128
|
+
hook to get the list of networks and set the active one:
|
|
129
|
+
|
|
130
|
+
```tsx
|
|
131
|
+
function NetworkSelector() {
|
|
132
|
+
const ctx = useSuiClientContext();
|
|
133
|
+
|
|
134
|
+
return (
|
|
135
|
+
<div>
|
|
136
|
+
{Object.keys(ctx.networks).map((network) => (
|
|
137
|
+
<button key={network} onClick={() => ctx.selectNetwork(network)}>
|
|
138
|
+
{`select ${network}`}
|
|
139
|
+
</button>
|
|
140
|
+
))}
|
|
141
|
+
</div>
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## Using network specific configuration
|
|
147
|
+
|
|
148
|
+
If your app runs on multiple networks, the IDs for packages and other configurations might change,
|
|
149
|
+
depending on which network you're using. You can use `createNetworkConfig` to create per-network
|
|
150
|
+
configurations that your components can access.
|
|
151
|
+
|
|
152
|
+
The `createNetworkConfig` function returns the provided configuration, along with hooks you can use
|
|
153
|
+
to get the variables defined in your configuration.
|
|
154
|
+
|
|
155
|
+
- `useNetworkConfig` returns the full network configuration object
|
|
156
|
+
- `useNetworkVariables` returns the full variables object from the network configuration
|
|
157
|
+
- `useNetworkVariable` returns a specific variable from the network configuration
|
|
158
|
+
|
|
159
|
+
```tsx
|
|
160
|
+
|
|
161
|
+
// Config options for the networks you want to connect to
|
|
162
|
+
const { networkConfig, useNetworkVariable } = createNetworkConfig({
|
|
163
|
+
localnet: {
|
|
164
|
+
url: getJsonRpcFullnodeUrl('localnet'),
|
|
165
|
+
variables: {
|
|
166
|
+
myMovePackageId: '0x123',
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
mainnet: {
|
|
170
|
+
url: getJsonRpcFullnodeUrl('mainnet'),
|
|
171
|
+
variables: {
|
|
172
|
+
myMovePackageId: '0x456',
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
const queryClient = new QueryClient();
|
|
178
|
+
|
|
179
|
+
function App() {
|
|
180
|
+
return (
|
|
181
|
+
<QueryClientProvider client={queryClient}>
|
|
182
|
+
<SuiClientProvider networks={networkConfig} defaultNetwork="localnet">
|
|
183
|
+
<WalletProvider>
|
|
184
|
+
<YourApp />
|
|
185
|
+
</WalletProvider>
|
|
186
|
+
</SuiClientProvider>
|
|
187
|
+
</QueryClientProvider>
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function YourApp() {
|
|
192
|
+
const id = useNetworkVariable('myMovePackageId');
|
|
193
|
+
|
|
194
|
+
return <div>Package ID: {id}</div>;
|
|
195
|
+
}
|
|
196
|
+
```
|
package/docs/themes.md
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# Themes
|
|
2
|
+
|
|
3
|
+
> Theming API for customizing the appearance of legacy 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
|
+
|
|
9
|
+
const App = () => {
|
|
10
|
+
return (
|
|
11
|
+
<WalletProvider theme={lightTheme}>
|
|
12
|
+
<YourApp />
|
|
13
|
+
</WalletProvider>
|
|
14
|
+
);
|
|
15
|
+
};
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Dynamic themes
|
|
19
|
+
|
|
20
|
+
To dynamically change the theme, you can provide multiple themes to the `WalletProvider` component:
|
|
21
|
+
|
|
22
|
+
```tsx
|
|
23
|
+
|
|
24
|
+
const App = () => {
|
|
25
|
+
return (
|
|
26
|
+
<WalletProvider
|
|
27
|
+
theme={[
|
|
28
|
+
{
|
|
29
|
+
// default to light theme
|
|
30
|
+
variables: lightTheme,
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
// Adds theme inside a media query
|
|
34
|
+
mediaQuery: '(prefers-color-scheme: dark)',
|
|
35
|
+
variables: darkTheme,
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
// prefixes the theme styles with the given selector
|
|
39
|
+
// this allows controlling the theme by adding a class to the body
|
|
40
|
+
selector: '.pink-theme',
|
|
41
|
+
variables: pinkTheme,
|
|
42
|
+
},
|
|
43
|
+
]}
|
|
44
|
+
>
|
|
45
|
+
<YourApp />
|
|
46
|
+
</WalletProvider>
|
|
47
|
+
);
|
|
48
|
+
};
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Theme variables
|
|
52
|
+
|
|
53
|
+
To define a custom theme, implement the `ThemeVars` interface with CSS variable values for your
|
|
54
|
+
theme:
|
|
55
|
+
|
|
56
|
+
```tsx
|
|
57
|
+
|
|
58
|
+
// Light theme copied from dapp-kit
|
|
59
|
+
|
|
60
|
+
blurs: {
|
|
61
|
+
modalOverlay: 'blur(0)',
|
|
62
|
+
},
|
|
63
|
+
backgroundColors: {
|
|
64
|
+
primaryButton: '#F6F7F9',
|
|
65
|
+
primaryButtonHover: '#F0F2F5',
|
|
66
|
+
outlineButtonHover: '#F4F4F5',
|
|
67
|
+
modalOverlay: 'rgba(24 36 53 / 20%)',
|
|
68
|
+
modalPrimary: 'white',
|
|
69
|
+
modalSecondary: '#F7F8F8',
|
|
70
|
+
iconButton: 'transparent',
|
|
71
|
+
iconButtonHover: '#F0F1F2',
|
|
72
|
+
dropdownMenu: '#FFFFFF',
|
|
73
|
+
dropdownMenuSeparator: '#F3F6F8',
|
|
74
|
+
walletItemSelected: 'white',
|
|
75
|
+
walletItemHover: '#3C424226',
|
|
76
|
+
},
|
|
77
|
+
borderColors: {
|
|
78
|
+
outlineButton: '#E4E4E7',
|
|
79
|
+
},
|
|
80
|
+
colors: {
|
|
81
|
+
primaryButton: '#373737',
|
|
82
|
+
outlineButton: '#373737',
|
|
83
|
+
iconButton: '#000000',
|
|
84
|
+
body: '#182435',
|
|
85
|
+
bodyMuted: '#767A81',
|
|
86
|
+
bodyDanger: '#FF794B',
|
|
87
|
+
},
|
|
88
|
+
radii: {
|
|
89
|
+
small: '6px',
|
|
90
|
+
medium: '8px',
|
|
91
|
+
large: '12px',
|
|
92
|
+
xlarge: '16px',
|
|
93
|
+
},
|
|
94
|
+
shadows: {
|
|
95
|
+
primaryButton: '0px 4px 12px rgba(0, 0, 0, 0.1)',
|
|
96
|
+
walletItemSelected: '0px 2px 6px rgba(0, 0, 0, 0.05)',
|
|
97
|
+
},
|
|
98
|
+
fontWeights: {
|
|
99
|
+
normal: '400',
|
|
100
|
+
medium: '500',
|
|
101
|
+
bold: '600',
|
|
102
|
+
},
|
|
103
|
+
fontSizes: {
|
|
104
|
+
small: '14px',
|
|
105
|
+
medium: '16px',
|
|
106
|
+
large: '18px',
|
|
107
|
+
xlarge: '20px',
|
|
108
|
+
},
|
|
109
|
+
typography: {
|
|
110
|
+
fontFamily:
|
|
111
|
+
'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"',
|
|
112
|
+
fontStyle: 'normal',
|
|
113
|
+
lineHeight: '1.3',
|
|
114
|
+
letterSpacing: '1',
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
```
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# ConnectButton
|
|
2
|
+
|
|
3
|
+
> Legacy React button component for connecting and disconnecting a Sui wallet.
|
|
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.
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# ConnectModal
|
|
2
|
+
|
|
3
|
+
> Legacy React modal component that guides users through connecting their wallet.
|
|
4
|
+
|
|
5
|
+
ControlledConnectModalExample,
|
|
6
|
+
UncontrolledConnectModalExample,
|
|
7
|
+
} from '../../../../examples/wallet-components-client';
|
|
8
|
+
|
|
9
|
+
The `ConnectModal` component opens a modal that guides the user through connecting their wallet to
|
|
10
|
+
the app.
|
|
11
|
+
|
|
12
|
+
## Controlled example
|
|
13
|
+
|
|
14
|
+
```tsx
|
|
15
|
+
|
|
16
|
+
const currentAccount = useCurrentAccount();
|
|
17
|
+
const [open, setOpen] = useState(false);
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<ConnectModal
|
|
21
|
+
trigger={
|
|
22
|
+
<button disabled={!!currentAccount}> {currentAccount ? 'Connected' : 'Connect'}</button>
|
|
23
|
+
}
|
|
24
|
+
open={open}
|
|
25
|
+
onOpenChange={(isOpen) => setOpen(isOpen)}
|
|
26
|
+
/>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Click **Connect** to connect your wallet and see the previous code in action:
|
|
32
|
+
|
|
33
|
+
## Uncontrolled example
|
|
34
|
+
|
|
35
|
+
```tsx
|
|
36
|
+
|
|
37
|
+
const currentAccount = useCurrentAccount();
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<ConnectModal
|
|
41
|
+
trigger={
|
|
42
|
+
<button disabled={!!currentAccount}> {currentAccount ? 'Connected' : 'Connect'}</button>
|
|
43
|
+
}
|
|
44
|
+
/>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Click **Connect** to connect your wallet and see the previous code in action:
|
|
50
|
+
|
|
51
|
+
## Controlled props
|
|
52
|
+
|
|
53
|
+
- `open`: The controlled open state of the dialog.
|
|
54
|
+
- `onOpenChange`: Event handler called when the open state of the dialog changes.
|
|
55
|
+
- `trigger`: The trigger button that opens the dialog.
|
|
56
|
+
- `walletFilter`: A filter function that receives a wallet instance, and returns a boolean
|
|
57
|
+
indicating whether the wallet should be displayed in the wallet list. By default, all wallets are
|
|
58
|
+
displayed.
|
|
59
|
+
|
|
60
|
+
## Uncontrolled props
|
|
61
|
+
|
|
62
|
+
- `defaultOpen`: The open state of the dialog when it is initially rendered. Use when you do not
|
|
63
|
+
need to control its open state.
|
|
64
|
+
- `trigger`: The trigger button that opens the dialog.
|
|
65
|
+
- `walletFilter`: A filter function that receives a wallet instance, and returns a boolean
|
|
66
|
+
indicating whether the wallet should be displayed in the wallet list. By default, all wallets are
|
|
67
|
+
displayed.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# useAccounts
|
|
2
|
+
|
|
3
|
+
> Legacy React hook to list connected wallet accounts authorized by the app.
|
|
4
|
+
|
|
5
|
+
The `useAccounts` hook retrieves a list of connected accounts the app authorizes.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
|
|
9
|
+
function MyComponent() {
|
|
10
|
+
const accounts = useAccounts();
|
|
11
|
+
|
|
12
|
+
return (
|
|
13
|
+
<div>
|
|
14
|
+
<ConnectButton />
|
|
15
|
+
<h2>Available accounts:</h2>
|
|
16
|
+
{accounts.length === 0 && <div>No accounts detected</div>}
|
|
17
|
+
<ul>
|
|
18
|
+
{accounts.map((account) => (
|
|
19
|
+
<li key={account.address}>- {account.address}</li>
|
|
20
|
+
))}
|
|
21
|
+
</ul>
|
|
22
|
+
</div>
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Example
|
|
28
|
+
|
|
29
|
+
## Account properties
|
|
30
|
+
|
|
31
|
+
- `address`: The address of the account, corresponding with a public key.
|
|
32
|
+
- `publicKey`: The public key of the account, represented as a `Uint8Array`.
|
|
33
|
+
- `chains`: The chains the account supports.
|
|
34
|
+
- `features`: The features the account supports.
|
|
35
|
+
- `label`: An optional user-friendly descriptive label or name for the account.
|
|
36
|
+
- `icon`: An optional user-friendly icon for the account.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# useAutoConnectWallet
|
|
2
|
+
|
|
3
|
+
> Legacy React hook to check the auto-connection status for the last connected wallet.
|
|
4
|
+
|
|
5
|
+
The `useAutoConnectWallet` hook retrieves the status for the initial wallet auto-connection process.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
|
|
9
|
+
function MyComponent() {
|
|
10
|
+
const autoConnectionStatus = useAutoConnectWallet();
|
|
11
|
+
|
|
12
|
+
return (
|
|
13
|
+
<div>
|
|
14
|
+
<ConnectButton />
|
|
15
|
+
<div>Auto-connection status: {autoConnectionStatus}</div>
|
|
16
|
+
</div>
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Example
|
|
22
|
+
|
|
23
|
+
## Auto-connection status properties
|
|
24
|
+
|
|
25
|
+
- `disabled`: When the auto-connection functionality is disabled.
|
|
26
|
+
- `idle`: When the initial auto-connection attempt hasn't been made yet.
|
|
27
|
+
- `attempted`: When an auto-connection attempt has been made. This means either that there is no
|
|
28
|
+
previously connected wallet, the previously connected wallet was not found, or that it has
|
|
29
|
+
successfully connected to a wallet.
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# useConnectWallet
|
|
2
|
+
|
|
3
|
+
> Legacy React mutation hook to establish a connection with a specific wallet.
|
|
4
|
+
|
|
5
|
+
The `useConnectWallet` hook is a mutation hook for establishing a connection to a specific wallet.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
|
|
9
|
+
function MyComponent() {
|
|
10
|
+
const wallets = useWallets();
|
|
11
|
+
const { mutate: connect } = useConnectWallet();
|
|
12
|
+
|
|
13
|
+
return (
|
|
14
|
+
<div style={{ padding: 20 }}>
|
|
15
|
+
<ConnectButton />
|
|
16
|
+
<ul>
|
|
17
|
+
{wallets.map((wallet) => (
|
|
18
|
+
<li key={wallet.name}>
|
|
19
|
+
<button
|
|
20
|
+
onClick={() => {
|
|
21
|
+
connect(
|
|
22
|
+
{ wallet },
|
|
23
|
+
{
|
|
24
|
+
onSuccess: () => console.log('connected'),
|
|
25
|
+
},
|
|
26
|
+
);
|
|
27
|
+
}}
|
|
28
|
+
>
|
|
29
|
+
Connect to {wallet.name}
|
|
30
|
+
</button>
|
|
31
|
+
</li>
|
|
32
|
+
))}
|
|
33
|
+
</ul>
|
|
34
|
+
</div>
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Example
|
|
40
|
+
|
|
41
|
+
## Connect arguments
|
|
42
|
+
|
|
43
|
+
- `args`: Arguments passed to the `connect` function of the wallet.
|
|
44
|
+
- `wallet`: The wallet to connect to.
|
|
45
|
+
- `accountAddress`: (optional) The address in the wallet to connect to.
|
|
46
|
+
|
|
47
|
+
- `options`: Options passed the `useMutation` hook from
|
|
48
|
+
[@tanstack/react-query](https://tanstack.com/query/latest/docs/react/guides/mutations).
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# useCurrentAccount
|
|
2
|
+
|
|
3
|
+
> Legacy React hook to get the currently selected wallet account.
|
|
4
|
+
|
|
5
|
+
The `useCurrentAccount` hook retrieves the wallet account that is currently selected, if one exists.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
|
|
9
|
+
function MyComponent() {
|
|
10
|
+
const account = useCurrentAccount();
|
|
11
|
+
|
|
12
|
+
return (
|
|
13
|
+
<div>
|
|
14
|
+
<ConnectButton />
|
|
15
|
+
{!account && <div>No account connected</div>}
|
|
16
|
+
{account && (
|
|
17
|
+
<div>
|
|
18
|
+
<h2>Current account:</h2>
|
|
19
|
+
<div>Address: {account.address}</div>
|
|
20
|
+
</div>
|
|
21
|
+
)}
|
|
22
|
+
</div>
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Example
|
|
28
|
+
|
|
29
|
+
## Account properties
|
|
30
|
+
|
|
31
|
+
- `address`: The address of the account, corresponding with a public key.
|
|
32
|
+
- `publicKey`: The public key of the account, represented as a `Uint8Array`.
|
|
33
|
+
- `chains`: The chains the account supports.
|
|
34
|
+
- `features`: The features the account supports.
|
|
35
|
+
- `label`: An optional user-friendly descriptive label or name for the account.
|
|
36
|
+
- `icon`: An optional user-friendly icon for the account.
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# useCurrentWallet
|
|
2
|
+
|
|
3
|
+
> Legacy React hook to get the currently connected wallet and connection status.
|
|
4
|
+
|
|
5
|
+
The `useCurrentWallet` hook retrieves the wallet that is currently connected to the app, if one
|
|
6
|
+
exists.
|
|
7
|
+
|
|
8
|
+
```ts
|
|
9
|
+
|
|
10
|
+
function MyComponent() {
|
|
11
|
+
const { currentWallet, connectionStatus } = useCurrentWallet();
|
|
12
|
+
|
|
13
|
+
return (
|
|
14
|
+
<div>
|
|
15
|
+
<ConnectButton />
|
|
16
|
+
{connectionStatus === 'connected' ? (
|
|
17
|
+
<div>
|
|
18
|
+
<h2>Current wallet:</h2>
|
|
19
|
+
<div>Name: {currentWallet.name}</div>
|
|
20
|
+
<div>
|
|
21
|
+
Accounts:
|
|
22
|
+
<ul>
|
|
23
|
+
{currentWallet.accounts.map((account) => (
|
|
24
|
+
<li key={account.address}>- {account.address}</li>
|
|
25
|
+
))}
|
|
26
|
+
</ul>
|
|
27
|
+
</div>
|
|
28
|
+
</div>
|
|
29
|
+
) : (
|
|
30
|
+
<div>Connection status: {connectionStatus}</div>
|
|
31
|
+
)}
|
|
32
|
+
</div>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Example
|
|
38
|
+
|
|
39
|
+
## Wallet properties
|
|
40
|
+
|
|
41
|
+
- `name`: The name of the wallet.
|
|
42
|
+
- `version`: The version of the wallet as a string.
|
|
43
|
+
- `icon`: A data URL of the wallet icon as an SVG.
|
|
44
|
+
- `accounts`: An array of accounts that are available in the wallet.
|
|
45
|
+
- `features`: An object with all the
|
|
46
|
+
[`wallet-standard`](https://github.com/wallet-standard/wallet-standard) features implemented by
|
|
47
|
+
the wallet.
|
|
48
|
+
- `chains`: An array of chain identifiers that the wallet supports.
|
|
49
|
+
|
|
50
|
+
## Connection status properties
|
|
51
|
+
|
|
52
|
+
- `connectionStatus`
|
|
53
|
+
- `disconnected`: When no wallet is connected to the app.
|
|
54
|
+
- `connecting`: When a wallet connection attempt is in progress.
|
|
55
|
+
- `connected`: When a wallet is connected to the app.
|
|
56
|
+
|
|
57
|
+
- `isDisconnected`: A derived boolean from the status variable above, provided for convenience.
|
|
58
|
+
- `isConnecting`: A derived boolean from the status variable above, provided for convenience.
|
|
59
|
+
- `isConnected`: A derived boolean from the status variable above, provided for convenience.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# useDisconnectWallet
|
|
2
|
+
|
|
3
|
+
> Legacy React mutation hook to disconnect from the currently connected wallet.
|
|
4
|
+
|
|
5
|
+
The `useDisconnectWallet` hook is a mutation hook for disconnecting from an active wallet
|
|
6
|
+
connection, if currently connected.
|
|
7
|
+
|
|
8
|
+
```ts
|
|
9
|
+
|
|
10
|
+
function MyComponent() {
|
|
11
|
+
const { mutate: disconnect } = useDisconnectWallet();
|
|
12
|
+
return (
|
|
13
|
+
<div>
|
|
14
|
+
<ConnectButton />
|
|
15
|
+
|
|
16
|
+
<button onClick={() => disconnect()}>Disconnect</button>
|
|
17
|
+
</div>
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Example
|
|
23
|
+
|
|
24
|
+
## Arguments
|
|
25
|
+
|
|
26
|
+
There are no arguments for `useDisconnectWallet`.
|