@tonconnect/ui-react 1.0.0-beta.2 → 1.0.0-beta.3

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 (2) hide show
  1. package/README.md +58 -26
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,7 +1,5 @@
1
1
  # TON Connect UI React
2
2
 
3
- ⚠️ **API is work in progress right now. Don't use this package in production.**
4
-
5
3
  TonConnect UI React is a React UI kit for TonConnect SDK. Use it to connect your app to TON wallets via TonConnect protocol in React apps.
6
4
 
7
5
  If you don't use React for your app, take a look at [TonConnect UI](https://github.com/ton-connect/sdk/tree/main/packages/ui).
@@ -25,7 +23,7 @@ You can find more details and the protocol specification in the [docs](https://g
25
23
 
26
24
  ## Add TonConnectUIProvider
27
25
  Add TonConnectUIProvider to the root of the app. You can specify UI options using props.
28
- [See all available options](TODO)
26
+ [See all available options](https://ton-connect.github.io/sdk/types/_tonconnect_ui_react.TonConnectUIProviderProps.html)
29
27
 
30
28
  All TonConnect UI hooks calls and `<TonConnectButton />` component must be placed inside `<TonConnectUIProvider>`.
31
29
 
@@ -164,35 +162,69 @@ export const EntrypointPage = () => {
164
162
  ```
165
163
 
166
164
  ## Add connect request parameters (ton_proof)
167
- Pass `getConnectParameters` async function to the `TonConnectUIProvider`. This callback will be called after `connectWallet` method call or `Connect Button` click before wallets list render.
165
+ Use `tonConnectUI.setConnectRequestParameters` function to pass your connect request parameters.
168
166
 
169
- In other words, if `getConnectParameters` is passed, there will be following steps:
170
- 1. User clicks to the 'Connect Wallet' button, or `connectWallet` method is called
171
- 2. Wallets modal opens
172
- 3. Loader renders in the center of the modal
173
- 4. TonConnectUI calls `getConnectParameters` and waits while it resolves
174
- 5. Wallets list renders in the center of the modal
167
+ This function takes one parameter:
175
168
 
176
- Note that there is no any caching for `getConnectParameters` -- every time wallets modal opens there will be the 5 steps above.
169
+ Set state to 'loading' while you are waiting for the response from your backend. If user opens connect wallet modal at this moment, he will see a loader.
170
+ ```ts
171
+ const [tonConnectUI] = useTonConnectUI();
177
172
 
178
- If you have to make a http-request to your backend it this case, it is better to do it after app initialization (if possible) and return (probably completed) promise from the `getConnectParameters` to reduce loading time for the user.
173
+ tonConnectUI.setConnectRequestParameters({
174
+ state: 'loading'
175
+ });
176
+ ```
179
177
 
180
- ```tsx
181
- const tonProofPayloadPromise = getTonProofFromYourBackend(); // will be executed during app initialization
182
- // don't forget to manage to refetch payload from your backend if needed
183
- <TonConnectUIProvider
184
- manifestUrl="https://<YOUR_APP_URL>/tonconnect-manifest.json"
185
- getConnectParameters={async () => {
186
- const tonProof = await tonProofPayloadPromise; // will be executed every time when wallets modal is opened. It is recommended to make an http-request in advance
187
- return {
188
- tonProof
189
- };
190
- }}
191
- >
192
- { /* Your app */ }
193
- </TonConnectUIProvider>
178
+ or
179
+
180
+ Set state to 'ready' and define `tonProof` value. Passed parameter will be applied to the connect request (QR and universal link).
181
+ ```ts
182
+ const [tonConnectUI] = useTonConnectUI();
183
+
184
+ tonConnectUI.setConnectRequestParameters({
185
+ state: 'ready',
186
+ value: {
187
+ tonProof: '<your-proof-payload>'
188
+ }
189
+ });
194
190
  ```
195
191
 
192
+ or
193
+
194
+ Remove loader if it was enabled via `state: 'loading'` (e.g. you received an error instead of a response from your backend). Connect request will be created without any additional parameters.
195
+ ```ts
196
+ const [tonConnectUI] = useTonConnectUI();
197
+
198
+ tonConnectUI.setConnectRequestParameters(null);
199
+ ```
200
+
201
+
202
+ You can call `tonConnectUI.setConnectRequestParameters` multiple times if your tonProof payload has bounded lifetime (e.g. you can refresh connect request parameters every 10 minutes).
203
+
204
+
205
+ ```ts
206
+ const [tonConnectUI] = useTonConnectUI();
207
+
208
+ // enable ui loader
209
+ tonConnectUI.setConnectRequestParameters({ state: 'loading' });
210
+
211
+ // fetch you tonProofPayload from the backend
212
+ const tonProofPayload: string | null = await fetchTonProofPayloadFromBackend();
213
+
214
+ if (!tonProofPayload) {
215
+ // remove loader, connect request will be without any additional parameters
216
+ tonConnectUI.setConnectRequestParameters(null);
217
+ } else {
218
+ // add tonProof to the connect request
219
+ tonConnectUI.setConnectRequestParameters({
220
+ state: "ready",
221
+ value: { tonProof: tonProofPayload }
222
+ });
223
+ }
224
+
225
+ ```
226
+
227
+
196
228
  You can find `ton_proof` result in the `wallet` object when wallet will be connected:
197
229
 
198
230
  ```ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tonconnect/ui-react",
3
- "version": "1.0.0-beta.2",
3
+ "version": "1.0.0-beta.3",
4
4
  "scripts": {
5
5
  "dev": "vite",
6
6
  "build": "tsc && vite build"