@tonconnect/ui-react 1.0.0-beta.2 → 1.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 +58 -26
- package/lib/components/TonConnectUIProvider.d.ts +1 -1
- package/lib/hooks/useTonWallet.d.ts +1 -2
- package/lib/index.js +109 -15308
- package/lib/index.js.map +1 -1
- package/lib/index.umd.js +152 -15346
- package/lib/index.umd.js.map +1 -1
- package/package.json +4 -7
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](
|
|
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
|
-
|
|
165
|
+
Use `tonConnectUI.setConnectRequestParameters` function to pass your connect request parameters.
|
|
168
166
|
|
|
169
|
-
|
|
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
|
-
|
|
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
|
-
|
|
173
|
+
tonConnectUI.setConnectRequestParameters({
|
|
174
|
+
state: 'loading'
|
|
175
|
+
});
|
|
176
|
+
```
|
|
179
177
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
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
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
2
|
import { ActionConfiguration, Locales, TonConnectUI, UIPreferences, WalletsListConfiguration } from '@tonconnect/ui';
|
|
3
|
-
import type { ITonConnect } from '@tonconnect/
|
|
3
|
+
import type { ITonConnect } from '@tonconnect/ui';
|
|
4
4
|
export declare const TonConnectUIContext: import("react").Context<TonConnectUI | null>;
|
|
5
5
|
export declare type TonConnectUIProviderProps = {
|
|
6
6
|
children: ReactNode;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { Wallet } from '@tonconnect/
|
|
2
|
-
import { WalletInfoWithOpenMethod } from '@tonconnect/ui';
|
|
1
|
+
import { WalletInfoWithOpenMethod, Wallet } from '@tonconnect/ui';
|
|
3
2
|
/**
|
|
4
3
|
* Use it to get user's current ton wallet. If wallet is not connected hook will return null.
|
|
5
4
|
*/
|