From 9b33329887b2c08e687650879d973ee1b8ee0f25 Mon Sep 17 00:00:00 2001
From: thekiba
Date: Sat, 21 Oct 2023 01:00:04 +0400
Subject: [PATCH 09/17] chore(ui): release version 2.0.0-beta.3
---
packages/ui/CHANGELOG.md | 23 +++++++++++++++++++++++
packages/ui/package.json | 2 +-
2 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/packages/ui/CHANGELOG.md b/packages/ui/CHANGELOG.md
index 01ae31cc..c7f1703a 100644
--- a/packages/ui/CHANGELOG.md
+++ b/packages/ui/CHANGELOG.md
@@ -1,5 +1,28 @@
# Changelog @tonconnect/ui
+# [2.0.0-beta.3](https://github.com/ton-connect/sdk/compare/ui-2.0.0-beta.2...ui-2.0.0-beta.3) (2023-10-20)
+
+
+### Bug Fixes
+
+* **ui:** implement back button handler for modal popup on Android devices ([ff83611](https://github.com/ton-connect/sdk/commit/ff8361138dac5efb1086ab5791e0700e67190491)), closes [#70](https://github.com/ton-connect/sdk/issues/70)
+* **ui:** prevent reappearing of success tooltip on re-render ([17bbc9a](https://github.com/ton-connect/sdk/commit/17bbc9a66eb01aad10dcc9bd91ba25696c652ba8))
+* **ui:** resolve illegal constructor error in safari ([512678f](https://github.com/ton-connect/sdk/commit/512678ff25ae877a7a2f608e8d8c06fda5dcbd21)), closes [#87](https://github.com/ton-connect/sdk/issues/87)
+* **ui:** resolve premature promise resolution and unhandled popup closing scenarios ([5e7b825](https://github.com/ton-connect/sdk/commit/5e7b825b809856f6bd3dff969464beeb9d372a08)), closes [#67](https://github.com/ton-connect/sdk/issues/67) [#68](https://github.com/ton-connect/sdk/issues/68)
+
+
+### Features
+
+* **ui:** introduce modal, fix promise handling, and refactor internal classes ([ac803aa](https://github.com/ton-connect/sdk/commit/ac803aa7bec56f6358071a906879d814eb485c8d))
+* **ui:** refactor wallet modal interfaces and expose them publicly ([5618a0a](https://github.com/ton-connect/sdk/commit/5618a0ae945b2aad50cb994d4cad8371f029bf65))
+
+
+### BREAKING CHANGES
+
+* **ui:** The method tonConnectUI.connectWallet() is now deprecated and will be removed in subsequent versions. Use tonConnectUI.openModal() instead.
+
+
+
# [2.0.0-beta.2](https://github.com/ton-connect/sdk/compare/ui-2.0.0-beta.1...ui-2.0.0-beta.2) (2023-09-15)
diff --git a/packages/ui/package.json b/packages/ui/package.json
index 67576ee2..2f8b4f03 100644
--- a/packages/ui/package.json
+++ b/packages/ui/package.json
@@ -1,6 +1,6 @@
{
"name": "@tonconnect/ui",
- "version": "2.0.0-beta.2",
+ "version": "2.0.0-beta.3",
"scripts": {
"start": "vite --host",
"dev": "vite",
From cd15215080a83f41f38151c5c929718349d5fbd0 Mon Sep 17 00:00:00 2001
From: thekiba
Date: Sat, 21 Oct 2023 01:20:01 +0400
Subject: [PATCH 10/17] chore(ui-react): update @tonconnect/ui to ^2.0.0-beta.3
---
packages/ui-react/package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/packages/ui-react/package.json b/packages/ui-react/package.json
index 0fa2612e..5fb06666 100644
--- a/packages/ui-react/package.json
+++ b/packages/ui-react/package.json
@@ -52,7 +52,7 @@
"vite-plugin-dts": "^1.7.1"
},
"dependencies": {
- "@tonconnect/ui": "^2.0.0-beta.2"
+ "@tonconnect/ui": "^2.0.0-beta.3"
},
"peerDependencies": {
"react": ">=17.0.0",
From 79206bba72f985d9afb60562b3a0bbddb775915d Mon Sep 17 00:00:00 2001
From: thekiba
Date: Sat, 21 Oct 2023 01:21:27 +0400
Subject: [PATCH 11/17] chore(ui-react): release version 2.0.0-beta.3
---
packages/ui-react/CHANGELOG.md | 9 +++++++++
packages/ui-react/package.json | 2 +-
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/packages/ui-react/CHANGELOG.md b/packages/ui-react/CHANGELOG.md
index c4ce3ee2..df2a17a8 100644
--- a/packages/ui-react/CHANGELOG.md
+++ b/packages/ui-react/CHANGELOG.md
@@ -1,5 +1,14 @@
# Changelog @tonconnect/ui-react
+# [2.0.0-beta.3](https://github.com/ton-connect/sdk/compare/ui-react-2.0.0-beta.2...ui-react-2.0.0-beta.3) (2023-10-20)
+
+
+### Features
+
+* **ui-react:** add useTonConnectModal() hook for modal management ([d1e2381](https://github.com/ton-connect/sdk/commit/d1e238154694d142bae67b21bfc81deb30647d49))
+
+
+
# [2.0.0-beta.2](https://github.com/ton-connect/sdk/compare/ui-react-2.0.0-beta.1...ui-react-2.0.0-beta.2) (2023-09-15)
diff --git a/packages/ui-react/package.json b/packages/ui-react/package.json
index 5fb06666..8734a591 100644
--- a/packages/ui-react/package.json
+++ b/packages/ui-react/package.json
@@ -1,6 +1,6 @@
{
"name": "@tonconnect/ui-react",
- "version": "2.0.0-beta.2",
+ "version": "2.0.0-beta.3",
"scripts": {
"dev": "vite",
"build": "tsc && vite build"
From 0ce0228b23cb0568e97f147ea27976f87ff97fc7 Mon Sep 17 00:00:00 2001
From: thekiba
Date: Wed, 25 Oct 2023 18:36:45 +0400
Subject: [PATCH 12/17] docs(sdk): update README.md
---
packages/sdk/README.md | 41 +++++++++++++++++++++++------------------
1 file changed, 23 insertions(+), 18 deletions(-)
diff --git a/packages/sdk/README.md b/packages/sdk/README.md
index ce24cd2b..bb11d779 100644
--- a/packages/sdk/README.md
+++ b/packages/sdk/README.md
@@ -59,7 +59,9 @@ Make sure that manifest is available to GET by its URL.
If your manifest placed not in the root of your app, you can specify its path:
```ts
- const connector = new TonConnect({ manifestUrl: 'https://myApp.com/assets/tonconnect-manifest.json' });
+const connector = new TonConnect({
+ manifestUrl: 'https://myApp.com/assets/tonconnect-manifest.json'
+});
```
## Subscribe to the connection status changes
@@ -273,29 +275,32 @@ To authorize user in your backend with TonConnect you can use following schema:
1. Fetch auth payload from your backend. It might be any random value. Backend must save information that this payload was sent to the client to check payload correctness later.
2. Connect to the wallet when user clicks to the connection button:
```ts
- connector.connect(walletConnectionSource, { tonProof: "" });
+connector.connect(
+ walletConnectionSource,
+ { tonProof: "" }
+);
```
Note that you can use `tonProof` only with `connector.connect()` method. This feature is not available in `connector.restoreConnection()`.
3. Read a signed result after user approves connection:
```ts
connector.onStatusChange(wallet => {
- if (!wallet) {
- return;
- }
-
- const tonProof = wallet.connectItems?.tonProof;
-
- if (tonProof) {
- if ('proof' in tonProof) {
- // send proof to your backend
- // e.g. myBackendCheckProof(tonProof.proof, wallet.account);
- return;
- }
-
- console.error(tonProof.error);
- }
- });
+ if (!wallet) {
+ return;
+ }
+
+ const tonProof = wallet.connectItems?.tonProof;
+
+ if (tonProof) {
+ if ('proof' in tonProof) {
+ // send proof to your backend
+ // e.g. myBackendCheckProof(tonProof.proof, wallet.account);
+ return;
+ }
+
+ console.error(tonProof.error);
+ }
+});
```
4. Send proof and user's account data to your backend. Backend should check the proof correctness and check that payload inside the proof was generated before. After all checks backend should return an auth token to the client. Notice that `Account` contains the `walletStateInit` property which can be helpful for your backend to get user's public key if user's wallet contract doesn't support corresponding get method.
5. Client saves the auth token in the `localStorage` and use it to access to auth-required endpoints. Client should delete the token when user disconnects the wallet.
From 0544eaf8d9fb159bff0dce8ac872400ea5e5d60a Mon Sep 17 00:00:00 2001
From: thekiba
Date: Wed, 25 Oct 2023 18:39:17 +0400
Subject: [PATCH 13/17] docs(ui): update README.md
---
packages/ui/README.md | 79 +++++++++++++++++++++++++++++++++++++------
1 file changed, 68 insertions(+), 11 deletions(-)
diff --git a/packages/ui/README.md b/packages/ui/README.md
index fc855b46..6a19466a 100644
--- a/packages/ui/README.md
+++ b/packages/ui/README.md
@@ -103,38 +103,95 @@ or
const walletsList = await TonConnectUI.getWallets();
```
-## Call connect
+## Open connect modal
"TonConnect UI connect button" (which is added at `buttonRootId`) automatically handles clicks and calls connect.
But you are still able to open "connect modal" programmatically, e.g. after click on your custom connect button.
```ts
-const connectedWallet = await tonConnectUI.connectWallet();
+await tonConnectUI.openModal();
```
-If there is an error while wallet connecting, `TonConnectUIError` or `TonConnectError` will be thrown depends on situation.
+This method opens the modal window and returns a promise that resolves after the modal window is opened.
+
+If there is an error while modal opening, `TonConnectUIError` or `TonConnectError` will be thrown depends on situation.
+
+## Close connect modal
+
+```ts
+tonConnectUI.closeModal();
+```
+
+This method closes the modal window.
+
+## Get current modal state
+
+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.
+
+```ts
+const currentModalState = tonConnectUI.modalState;
+```
+
+## Subscribe to the modal window state changes
+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.
+
+```js
+const unsubscribeModal = tonConnectUI.onModalStateChange(
+ (state: WalletsModalState) => {
+ // update state/reactive variables to show updates in the ui
+ // state.status will be 'opened' or 'closed'
+ // if state.status is 'closed', you can check state.closeReason to find out the reason
+ }
+);
+```
+
+Call `unsubscribeModal()` later to save resources when you don't need to listen for updates anymore.
+
+## Wallets Modal Control
+
+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.
+
+```typescript
+const { modal } = tonConnectUI;
+
+// Open and close the modal
+await modal.open();
+modal.close();
+
+// Get the current modal state
+const currentState = modal.state;
+
+// Subscribe and unsubscribe to modal state changes
+const unsubscribe = modal.onStateChange(state => { /* ... */ });
+unsubscribe();
+```
+
+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.
## Get current connected Wallet and WalletInfo
You can use special getters to read current connection state. Note that this getter only represents current value, so they are not reactive.
-To react and handle wallet changes use `onStatusChange` mathod.
+To react and handle wallet changes use `onStatusChange` method.
```ts
- const currentWallet = tonConnectUI.wallet;
- const currentWalletInfo = tonConnectUI.walletInfo;
- const currentAccount = tonConnectUI.account;
- const currentIsConnectedStatus = tonConnectUI.connected;
+const currentWallet = tonConnectUI.wallet;
+const currentWalletInfo = tonConnectUI.walletInfo;
+const currentAccount = tonConnectUI.account;
+const currentIsConnectedStatus = tonConnectUI.connected;
```
## Subscribe to the connection status changes
-```js
+
+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.
+
+```ts
const unsubscribe = tonConnectUI.onStatusChange(
walletAndwalletInfo => {
// update state/reactive variables to show updates in the ui
}
);
-
-// call `unsubscribe()` later to save resources when you don't need to listen for updates anymore.
```
+Call `unsubscribe()` later to save resources when you don't need to listen for updates anymore.
+
## Disconnect wallet
Call to disconnect the wallet.
From 31ba6d21c3bc0e2b1815321db6eefa8356ff3703 Mon Sep 17 00:00:00 2001
From: thekiba
Date: Wed, 25 Oct 2023 18:40:34 +0400
Subject: [PATCH 14/17] chore(ui): release version 2.0.0-beta.4
---
packages/ui/CHANGELOG.md | 4 ++++
packages/ui/package.json | 2 +-
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/packages/ui/CHANGELOG.md b/packages/ui/CHANGELOG.md
index c7f1703a..aea5a918 100644
--- a/packages/ui/CHANGELOG.md
+++ b/packages/ui/CHANGELOG.md
@@ -1,5 +1,9 @@
# Changelog @tonconnect/ui
+# [2.0.0-beta.4](https://github.com/ton-connect/sdk/compare/ui-2.0.0-beta.3...ui-2.0.0-beta.4) (2023-10-25)
+
+
+
# [2.0.0-beta.3](https://github.com/ton-connect/sdk/compare/ui-2.0.0-beta.2...ui-2.0.0-beta.3) (2023-10-20)
diff --git a/packages/ui/package.json b/packages/ui/package.json
index 2f8b4f03..7cc7de29 100644
--- a/packages/ui/package.json
+++ b/packages/ui/package.json
@@ -1,6 +1,6 @@
{
"name": "@tonconnect/ui",
- "version": "2.0.0-beta.3",
+ "version": "2.0.0-beta.4",
"scripts": {
"start": "vite --host",
"dev": "vite",
From 9dc59340a71113f1a4e1588dfe3290d92b7469fa Mon Sep 17 00:00:00 2001
From: thekiba
Date: Wed, 25 Oct 2023 18:43:21 +0400
Subject: [PATCH 15/17] docs(ui-react): update README.md
---
packages/ui-react/README.md | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/packages/ui-react/README.md b/packages/ui-react/README.md
index 6ee1b955..41b5592d 100644
--- a/packages/ui-react/README.md
+++ b/packages/ui-react/README.md
@@ -107,6 +107,26 @@ export const Wallet = () => {
};
```
+### useTonConnectModal
+
+Use this hook to access the functions for opening and closing the modal window. The hook returns an object with the current modal state and methods to open and close the modal.
+
+```tsx
+import { useTonConnectModal } from '@tonconnect/ui-react';
+
+export const ModalControl = () => {
+ const { state, open, close } = useTonConnectModal();
+
+ return (
+