@tonconnect/ui 2.0.0-beta.3 → 2.0.0-beta.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/README.md +68 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -103,38 +103,95 @@ or
|
|
|
103
103
|
const walletsList = await TonConnectUI.getWallets();
|
|
104
104
|
```
|
|
105
105
|
|
|
106
|
-
##
|
|
106
|
+
## Open connect modal
|
|
107
107
|
"TonConnect UI connect button" (which is added at `buttonRootId`) automatically handles clicks and calls connect.
|
|
108
108
|
But you are still able to open "connect modal" programmatically, e.g. after click on your custom connect button.
|
|
109
109
|
|
|
110
110
|
```ts
|
|
111
|
-
|
|
111
|
+
await tonConnectUI.openModal();
|
|
112
112
|
```
|
|
113
113
|
|
|
114
|
-
|
|
114
|
+
This method opens the modal window and returns a promise that resolves after the modal window is opened.
|
|
115
|
+
|
|
116
|
+
If there is an error while modal opening, `TonConnectUIError` or `TonConnectError` will be thrown depends on situation.
|
|
117
|
+
|
|
118
|
+
## Close connect modal
|
|
119
|
+
|
|
120
|
+
```ts
|
|
121
|
+
tonConnectUI.closeModal();
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
This method closes the modal window.
|
|
125
|
+
|
|
126
|
+
## Get current modal state
|
|
127
|
+
|
|
128
|
+
This getter returns the current state of the modal window. The state will be an object with `status` and `closeReason` properties. The `status` can be either 'opened' or 'closed'. If the modal is closed, you can check the `closeReason` to find out the reason of closing.
|
|
129
|
+
|
|
130
|
+
```ts
|
|
131
|
+
const currentModalState = tonConnectUI.modalState;
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Subscribe to the modal window state changes
|
|
135
|
+
To subscribe to the changes of the modal window state, you can use the `onModalStateChange` method. It returns a function which has to be called to unsubscribe.
|
|
136
|
+
|
|
137
|
+
```js
|
|
138
|
+
const unsubscribeModal = tonConnectUI.onModalStateChange(
|
|
139
|
+
(state: WalletsModalState) => {
|
|
140
|
+
// update state/reactive variables to show updates in the ui
|
|
141
|
+
// state.status will be 'opened' or 'closed'
|
|
142
|
+
// if state.status is 'closed', you can check state.closeReason to find out the reason
|
|
143
|
+
}
|
|
144
|
+
);
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Call `unsubscribeModal()` later to save resources when you don't need to listen for updates anymore.
|
|
148
|
+
|
|
149
|
+
## Wallets Modal Control
|
|
150
|
+
|
|
151
|
+
The `tonConnectUI` provides methods for managing the modal window, such as `openModal()`, `closeModal()` and other, which are designed for ease of use and cover most use cases.
|
|
152
|
+
|
|
153
|
+
```typescript
|
|
154
|
+
const { modal } = tonConnectUI;
|
|
155
|
+
|
|
156
|
+
// Open and close the modal
|
|
157
|
+
await modal.open();
|
|
158
|
+
modal.close();
|
|
159
|
+
|
|
160
|
+
// Get the current modal state
|
|
161
|
+
const currentState = modal.state;
|
|
162
|
+
|
|
163
|
+
// Subscribe and unsubscribe to modal state changes
|
|
164
|
+
const unsubscribe = modal.onStateChange(state => { /* ... */ });
|
|
165
|
+
unsubscribe();
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
While `tonConnectUI` internally delegates these calls to the `modal`, it is recommended to use the `tonConnectUI` methods for a more straightforward and consistent experience. The `modal` is exposed in case you need direct access to the modal window's state and behavior, but this should generally be avoided unless necessary.
|
|
115
169
|
|
|
116
170
|
## Get current connected Wallet and WalletInfo
|
|
117
171
|
You can use special getters to read current connection state. Note that this getter only represents current value, so they are not reactive.
|
|
118
|
-
To react and handle wallet changes use `onStatusChange`
|
|
172
|
+
To react and handle wallet changes use `onStatusChange` method.
|
|
119
173
|
|
|
120
174
|
```ts
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
175
|
+
const currentWallet = tonConnectUI.wallet;
|
|
176
|
+
const currentWalletInfo = tonConnectUI.walletInfo;
|
|
177
|
+
const currentAccount = tonConnectUI.account;
|
|
178
|
+
const currentIsConnectedStatus = tonConnectUI.connected;
|
|
125
179
|
```
|
|
126
180
|
|
|
127
181
|
## Subscribe to the connection status changes
|
|
128
|
-
|
|
182
|
+
|
|
183
|
+
To subscribe to the changes of the connection status, you can use the `onStatusChange` method. It returns a function which has to be called to unsubscribe.
|
|
184
|
+
|
|
185
|
+
```ts
|
|
129
186
|
const unsubscribe = tonConnectUI.onStatusChange(
|
|
130
187
|
walletAndwalletInfo => {
|
|
131
188
|
// update state/reactive variables to show updates in the ui
|
|
132
189
|
}
|
|
133
190
|
);
|
|
134
|
-
|
|
135
|
-
// call `unsubscribe()` later to save resources when you don't need to listen for updates anymore.
|
|
136
191
|
```
|
|
137
192
|
|
|
193
|
+
Call `unsubscribe()` later to save resources when you don't need to listen for updates anymore.
|
|
194
|
+
|
|
138
195
|
## Disconnect wallet
|
|
139
196
|
Call to disconnect the wallet.
|
|
140
197
|
|