@tonconnect/ui 2.0.0-beta.4 → 2.0.0-beta.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/README.md CHANGED
@@ -341,31 +341,51 @@ const result = await tonConnectUI.sendTransaction(defaultTx, {
341
341
  });
342
342
  ```
343
343
 
344
- ## Use inside TWA (Telegram web app)
345
- TonConnect UI will work in TWA in the same way as in a regular website!
344
+ ## Use inside TMA (Telegram Mini Apps)
345
+ TonConnect UI will work in TMA in the same way as in a regular website!
346
346
  Basically, no changes are required from the dApp's developers. The only thing you have to set is a dynamic return strategy.
347
347
 
348
- Currently, it is impossible for TWA-wallets to redirect back to previous opened TWA-dApp like native wallet-apps do.
349
- It means, that you need to specify the return strategy as a link to your TWA that will be only applied if the dApp is opened in TWA mode.
348
+ Currently, it is impossible for TMA-wallets to redirect back to previous opened TMA-dApp like native wallet-apps do.
349
+ It means, that you need to specify the return strategy as a link to your TMA that will be only applied if the dApp is opened in TMA mode.
350
350
 
351
351
  ```ts
352
352
  tonConnectUI.uiOptions = {
353
- twaReturnUrl: 'https://t.me/durov'
354
- };
353
+ twaReturnUrl: 'https://t.me/durov'
354
+ };
355
355
  ```
356
356
 
357
- In other words,
357
+ In other words, TonConnect UI will automatically handle the return strategy based on the environment. **The following pseudo-code demonstrates the internal logic of TonConnect UI**:
358
+
359
+ > Please note that you **don't need to add this code to your dApp**. It's just an example of how TonConnect UI processes the return strategy internally.
360
+
358
361
  ```ts
359
- if (isLinkToTelegram()) {
362
+ let finalReturnStrategy;
363
+
364
+ // Determine if the provided link opens Telegram (using protocols tg:// or domain t.me).
365
+ if (isLinkToTelegram('https://example.com')) {
366
+ // In the Telegram Mini Apps environment,
360
367
  if (isInTWA()) {
361
- FINAL_RETURN_STRATEGY = actionsConfiguration.twaReturnUrl || actionsConfiguration.returnStrategy;
362
- } else {
363
- FINAL_RETURN_STRATEGY = 'none';
368
+ // preference is given to 'twaReturnUrl',
369
+ finalReturnStrategy = actionsConfiguration.twaReturnUrl;
370
+
371
+ // but if it's not set, fallback to 'returnStrategy'.
372
+ if (!finalReturnStrategy) {
373
+ finalReturnStrategy = actionsConfiguration.returnStrategy;
374
+ }
364
375
  }
365
- } else {
366
- FINAL_RETURN_STRATEGY = actionsConfiguration.returnStrategy;
376
+ // If not in a TMA environment,
377
+ else {
378
+ // the return strategy is set to 'none'.
379
+ finalReturnStrategy = 'none';
380
+ }
381
+ }
382
+ // When the link does not open Telegram,
383
+ else {
384
+ // use the predefined 'returnStrategy'.
385
+ finalReturnStrategy = actionsConfiguration.returnStrategy;
367
386
  }
368
387
 
388
+ // Now, 'finalReturnStrategy' contains the correct strategy based on the link's destination and the dApp's environment.
369
389
  ```
370
390
 
371
391
  ## Detect end of the connection restoring process
@@ -696,3 +716,72 @@ tonConnectUI.onStatusChange(wallet => {
696
716
  }
697
717
  });
698
718
  ```
719
+
720
+ # Troubleshooting
721
+
722
+ ## Android Back Handler
723
+
724
+ If you encounter any issues with the Android back handler, such as modals not closing properly when the back button is pressed, or conflicts with `history.pushState()` if you are manually handling browser history in your application, you can disable the back handler by setting `enableAndroidBackHandler` to `false`:
725
+
726
+ ```ts
727
+ const tonConnectUI = new TonConnectUI({
728
+ // ...
729
+ enableAndroidBackHandler: false
730
+ });
731
+ ```
732
+
733
+ This will disable the custom back button behavior on Android, and you can then handle the back button press manually in your application.
734
+
735
+ While we do not foresee any problems arising with the Android back handler, but if you find yourself needing to disable it due to an issue, please describe the problem in on [GitHub Issues](https://github.com/ton-connect/sdk/issues), so we can assist you further.
736
+
737
+ ## Animations not working
738
+
739
+ If you are experiencing issues with animations not working in your environment, it might be due to a lack of support for the Web Animations API. To resolve this issue, you can use the `web-animations-js` polyfill.
740
+
741
+ ### Using npm
742
+
743
+ To install the polyfill, run the following command:
744
+
745
+ ```shell
746
+ npm install web-animations-js
747
+ ```
748
+
749
+ Then, import the polyfill in your project:
750
+
751
+ ```typescript
752
+ import 'web-animations-js';
753
+ ```
754
+
755
+ ### Using CDN
756
+
757
+ Alternatively, you can include the polyfill via CDN by adding the following script tag to your HTML:
758
+
759
+ ```html
760
+ <script src="https://www.unpkg.com/web-animations-js@latest/web-animations.min.js"></script>
761
+ ```
762
+
763
+ Both methods will provide a fallback implementation of the Web Animations API and should resolve the animation issues you are facing.
764
+
765
+ ## Warning about 'encoding' module in Next.js
766
+
767
+ If you are using Next.js and see a warning similar to the following:
768
+
769
+ ```
770
+ ⚠ ./node_modules/node-fetch/lib/index.js
771
+ Module not found: Can't resolve 'encoding' in '.../node_modules/node-fetch/lib'
772
+
773
+ Import trace for requested module:
774
+ ./node_modules/node-fetch/lib/index.js
775
+ ./node_modules/@tonconnect/isomorphic-fetch/index.mjs
776
+ ./node_modules/@tonconnect/sdk/lib/esm/index.mjs
777
+ ./node_modules/@tonconnect/ui/lib/esm/index.mjs
778
+ ```
779
+
780
+ Please note that this is just a warning and should not affect the functionality of your application. If you wish to suppress the warning, you have two options:
781
+
782
+ 1. (Recommended) Wait for us to remove the dependency on `@tonconnect/isomorphic-fetch` in future releases. This dependency will be removed when we drop support for Node.js versions below 18.
783
+
784
+ 2. (Optional) Install the `encoding` package, to resolve the warning:
785
+ ```shell
786
+ npm install encoding
787
+ ```