@tonconnect/ui 0.0.10 → 0.0.11

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 CHANGED
@@ -434,3 +434,43 @@ const customWallet: UIWallet = {
434
434
  ```
435
435
 
436
436
  [See all available options](https://ton-connect.github.io/sdk/types/_tonconnect_ui.WalletsListConfiguration.html)
437
+
438
+
439
+ ## Add connect request parameters (ton_proof)
440
+ Pass `getConnectParameters` async function to the `TonConnectUI` constructor. This callback will be called after `connectWallet` method call or `Connect Button` click before wallets list render.
441
+
442
+ In other words, if `getConnectParameters` is passed, there will be a following steps:
443
+ 1. User clicks to the 'Connect Wallet' button, or `connectWallet` method is called
444
+ 2. Wallets modal opens
445
+ 3. Loader renders in the center of the modal
446
+ 4. TonConnectUI calls `getConnectParameters` and waits while it resolves
447
+ 5. Wallets list renders in the center of the modal
448
+
449
+ Note that there is no any caching for `getConnectParameters` -- every time wallets modal opens there will be the 5 steps above.
450
+
451
+ 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.
452
+
453
+ ```ts
454
+ const tonProofPayloadPromise = getTonProofFromYourBackend(); // will be executed during app initialization
455
+ // don't forget to manage to refetch payload from your backend if needed
456
+
457
+ const tonConnectUI = new TonConnectUI({
458
+ manifestUrl: 'https://<YOUR_APP_URL>/tonconnect-manifest.json',
459
+ buttonRootId: '<YOUR_CONNECT_BUTTON_ANCHOR_ID>',
460
+ getConnectParameters: async () => {
461
+ const tonProof = await tonProofPayloadPromise; // will be executed every time when wallets modal is opened. It is recommended to make an http-request in advance
462
+ return {
463
+ tonProof
464
+ };
465
+ }
466
+ });
467
+ ```
468
+
469
+ You can find `ton_proof` result in the `wallet` object when wallet will be connected:
470
+ ```ts
471
+ tonConnectUI.onStatusChange(wallet => {
472
+ if (wallet && wallet.connectItems?.tonProof && 'proof' in wallet.connectItems.tonProof) {
473
+ checkProofInYourBackend(wallet.connectItems.tonProof.proof);
474
+ }
475
+ });
476
+ ```