├── .eslintrc.cjs ├── .github └── workflows │ └── main.yml ├── .gitignore ├── .prettierrc ├── CHANGELOG.md ├── LICENSE ├── OFFICIAL_SYNC.md ├── README.md ├── index.html ├── package.json ├── postcss.config.cjs ├── public └── official_sync_process_flowchart.png ├── rollup.config.mjs ├── scripts ├── switch-cli.mjs └── utils.mjs ├── src ├── components │ ├── TonConnectButton.vue │ └── index.ts ├── errors │ ├── index.ts │ ├── ton-connect-provider-not-set.error.ts │ └── ton-connect-ui-vue.error.ts ├── hooks │ ├── index.ts │ ├── useIsConnectionRestored.ts │ ├── useTonAddress.ts │ ├── useTonConnectModal.ts │ ├── useTonConnectUI.ts │ └── useTonWallet.ts ├── index.ts ├── library.ts ├── plugin.ts ├── shims-vue.d.ts ├── types.ts └── utils │ ├── UIProvider.ts │ ├── errors.ts │ └── web.ts ├── tsconfig.json ├── tsconfig.node.json ├── vite.config.ts └── yarn.lock /.eslintrc.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | parser: "vue-eslint-parser", 3 | extends: [ 4 | "plugin:vue/recommended", 5 | "plugin:@typescript-eslint/recommended", 6 | "prettier", 7 | ], 8 | parserOptions: { 9 | parser: "@typescript-eslint/parser", 10 | sourceType: "module", 11 | ecmaVersion: "latest", 12 | ecmaFeatures: { 13 | jsx: true, 14 | }, 15 | }, 16 | plugins: ["vue", "@typescript-eslint", "unused-imports"], 17 | rules: { 18 | "import/extensions": ["off"], 19 | "@typescript-eslint/explicit-function-return-type": [ 20 | "error", 21 | { 22 | allowExpressions: true, 23 | allowTypedFunctionExpressions: true, 24 | allowConciseArrowFunctionExpressionsStartingWithVoid: true, 25 | allowDirectConstAssertionInArrowFunctions: true, 26 | }, 27 | ], 28 | "unused-imports/no-unused-vars": [ 29 | "error", 30 | { 31 | vars: "all", 32 | varsIgnorePattern: "^_", 33 | args: "after-used", 34 | argsIgnorePattern: "^_", 35 | }, 36 | ], 37 | "@typescript-eslint/no-explicit-any": "error", 38 | "quotes": ["error", "single"], 39 | }, 40 | }; 41 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: Build and publish 2 | 3 | on: 4 | push: 5 | branches: [ "main" ] 6 | 7 | jobs: 8 | build: 9 | runs-on: ubuntu-latest 10 | 11 | steps: 12 | - uses: actions/checkout@v3 13 | 14 | - name: Read .nvmrc 15 | run: echo "NVMRC=$(cat .nvmrc)" >> $GITHUB_ENV 16 | 17 | - name: Set up Node.js 18 | uses: actions/setup-node@v2 19 | with: 20 | node-version: '${{ env.NVMRC }}' 21 | 22 | - name: Set up NPM token 1 23 | run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc 24 | 25 | - name: Install dependencies 26 | run: yarn install 27 | 28 | - name: Build project 29 | run: yarn build 30 | 31 | - name: Verify NPM token with multiple commands 1 32 | run: | 33 | echo "Running npm whoami..." 34 | npm whoami 35 | echo "Running npm ping..." 36 | npm ping 37 | echo "Running npm publish --dry-run..." 38 | npm publish --dry-run 39 | env: 40 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} 41 | 42 | - name: Publish package 43 | env: 44 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} 45 | run: npm publish 46 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | /lib 4 | 5 | 6 | # local env files 7 | .env.local 8 | .env.*.local 9 | 10 | # Log files 11 | npm-debug.log* 12 | yarn-debug.log* 13 | yarn-error.log* 14 | pnpm-debug.log* 15 | 16 | # Editor directories and files 17 | .idea 18 | .vscode 19 | *.suo 20 | *.ntvs* 21 | *.njsproj 22 | *.sln 23 | *.sw? 24 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true 3 | } -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. 4 | 5 | ## 2.1.0 (2024-11-04) 6 | 7 | 8 | ### Features 9 | 10 | * add TonConnectUIPlugin ([af7c4d2](https://github.com/TownSquareXYZ/tonconnect-ui-vue/commit/af7c4d24f825d36c453ccb694ba0dbddacb755f1)) 11 | * add TypeScript type definitions ([4cd5796](https://github.com/TownSquareXYZ/tonconnect-ui-vue/commit/4cd5796829a1e44d5266f0161c4853d792de1ecb)) 12 | * use Symble key in provide / inject ([e3f5115](https://github.com/TownSquareXYZ/tonconnect-ui-vue/commit/e3f51155999d2699170a416909ed01db6c7b0dc2)) 13 | 14 | 15 | ### Bug Fixes 16 | 17 | * add vue-demi to external dependencies ([e83b1bd](https://github.com/TownSquareXYZ/tonconnect-ui-vue/commit/e83b1bd91e1f9aa404098de90d394548f6821bdf)) 18 | * resolve issues with Vue 2.7 integration ([263dd91](https://github.com/TownSquareXYZ/tonconnect-ui-vue/commit/263dd917c77c3007c878eaef4882ea159b501619)) 19 | * update injections components & watch options change ([e1f8be8](https://github.com/TownSquareXYZ/tonconnect-ui-vue/commit/e1f8be88dffabaa7c0a81ffe961b3c56ce66cc96)) 20 | * useTonConnectUI().tonConnectUI is not typed ([2449bd8](https://github.com/TownSquareXYZ/tonconnect-ui-vue/commit/2449bd8027c235818f085bdce608edc9ba5ee3d6)) 21 | 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2024 Townsquare Labs 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | Portions of this software are based on the work of Original Software Project: 204 | Copyright 2022 tonkeeper 205 | -------------------------------------------------------------------------------- /OFFICIAL_SYNC.md: -------------------------------------------------------------------------------- 1 | # Sync with Official Releases 2 | 3 | We are committed to providing our users with a reliable and continuously optimized Kit, so we will keep in close sync with the official release, and whenever a new official version is released, we will quickly update it to ensure that our Kit will always include the latest features, fixes, and improvements. Additionally, we conduct regular compatibility tests and performance optimizations based on the official release cadence to ensure you get the best experience possible. Whether it's the introduction of new features or security enhancements, you can rest assured that you can rely on us to stay consistent and on the cutting edge with the official release. 4 | 5 | ## process description 6 | 7 | 1. get the latest npm version to compare 8 | 9 | 2. if inconsistent, select the latest tag with version number to compare and get the patch file 10 | a. get all tags 11 | b. select the tags to compare 12 | c. get the patch file 13 | 14 | 3. parse patch and compare tonconnect react update content 15 | 16 | 4. if only package.json version and tonconnect ui version have changed 17 | 18 | 5. pull our package file and update these fields 19 | a. pull the latest code 20 | b. update package.json 21 | 22 | 6. create a new branch and commit the changes 23 | 24 | 7. merge the branch into main 25 | 26 | 8. trigger github action to automatically update log and publish to npm 27 | 28 | 9. after successful merge, remove the created branch 29 | 30 | 10. if the patch contains more than just version updates, create an issue to be notified 31 | a. if the patch contains other significant changes, create an issue on github to be notified about the updates 32 | 33 | 11. if any request fails after step 3, create an issue, making sure there is only one issue per problem 34 | 35 | 36 | ![Official_Sync_Process_Flowchart_image](./public/official_sync_process_flowchart.png) 37 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TON Connect UI Vue 2 | 3 | TonConnect UI Vue is a Vue UI kit for TonConnect SDK. Use it to connect your app to TON wallets via TonConnect protocol in Vue apps. 4 | 5 | If you don't use Vue for your app, take a look at [TonConnect UI](https://github.com/ton-connect/sdk/tree/main/packages/ui) and [TonConnect UI React](https://github.com/ton-connect/sdk/tree/main/packages/ui-react). 6 | 7 | If you want to use TonConnect on the server side, you should use the [TonConnect SDK](https://github.com/ton-connect/sdk/tree/main/packages/sdk). 8 | 9 | You can find more details and the protocol specification in the [docs](https://docs.ton.org/develop/dapps/ton-connect/overview). 10 | 11 | --- 12 | ## Features 13 | - **TonConnect UI Integration**: Vue components and hooks for TON wallet connections. 14 | - **Cross-version Compatibility**: Fully supports **Vue 2.7+** and **Vue 3** through `vue-demi`. 15 | - **TypeScript Support**: Complete type definitions for enhanced development experience. 16 | - **Flexible Configuration**: Extensive options for customizing behavior and appearance. 17 | --- 18 | 19 | # Getting started 20 | 21 | [Latest API documentation](https://ton-connect.github.io/sdk/modules/_tonconnect_ui-vue.html) 22 | 23 | # Getting started 24 | 25 | ## Installation with npm 26 | `npm i @townsquarelabs/ui-vue` 27 | ## Installation with yarn 28 | `yarn add @townsquarelabs/ui-vue` 29 | 30 | # Sync with Official Releases 31 | This [OFFICIAL_SYNC.md](./OFFICIAL_SYNC.md) file describes how we synchronize with the official. 32 | 33 | # Usage 34 | 35 | 36 | ## Use TonConnectUIPlugin 37 | 38 | Use TonConnectUIPlugin before mounting the app. You can specify UI options using plugin options. 39 | // todo 40 | 41 | 42 | For Vue@2.7: 43 | ```ts 44 | import Vue from 'vue' 45 | import { TonConnectUIPlugin } from '@townsquarelabs/ui-vue' 46 | 47 | import App from './App.vue' 48 | 49 | Vue.use(TonConnectUIPlugin, { 50 | manifestUrl: "https:///tonconnect-manifest.json" 51 | }); 52 | 53 | new Vue({ 54 | render: (h) => h(App) 55 | }).$mount('#app') 56 | ``` 57 | 58 | For Vue@3: 59 | ```ts 60 | import { createApp } from 'vue' 61 | import { TonConnectUIPlugin } from '@townsquarelabs/ui-vue' 62 | 63 | import App from './App.vue' 64 | 65 | const app = createApp(App) 66 | app 67 | .use(TonConnectUIPlugin,{ manifestUrl: "https:///tonconnect-manifest.json" }) 68 | .mount('#app') 69 | ``` 70 | 71 | ## Add TonConnect Button 72 | TonConnect Button is universal UI component for initializing connection. After wallet is connected it transforms to a wallet menu. 73 | It is recommended to place it in the top right corner of your app. 74 | 75 | ```vue 76 | 82 | 83 | 92 | ``` 93 | 94 | You can add `buttonRootId` props to the button as well. 95 | `` 96 | 97 | 98 | ## Use TonConnect UI hooks 99 | 100 | ### useTonAddress 101 | Use it to get user's current ton wallet address. Pass boolean parameter isUserFriendly to choose format of the address. If wallet is not connected hook will return empty string. 102 | 103 | ```vue 104 | 110 | 111 | 126 | ``` 127 | 128 | ### useTonWallet 129 | Use it to get user's current ton wallet. If wallet is not connected hook will return null. 130 | 131 | See all wallet's properties 132 | // todo 133 | 134 | 135 | 136 | ```vue 137 | 143 | 144 | 158 | ``` 159 | 160 | ### useTonConnectModal 161 | 162 | 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. 163 | 164 | ```vue 165 | 172 | 173 | 183 | ``` 184 | 185 | ### useTonConnectUI 186 | Use it to get access to the `TonConnectUI` instance and UI options updating function. 187 | 188 | [See more about TonConnectUI instance methods](https://github.com/ton-connect/sdk/tree/main/packages/ui#send-transaction) 189 | 190 | [See more about setOptions function](https://github.com/ton-connect/sdk/tree/main/packages/ui#change-options-if-needed) 191 | 192 | 193 | ```vue 194 | 206 | 207 | 243 | ``` 244 | 245 | or 246 | 247 | ```vue 248 | 252 | ``` 253 | 254 | ### useIsConnectionRestored 255 | Indicates current status of the connection restoring process. 256 | You can use it to detect when connection restoring process if finished. 257 | 258 | ```vue 259 | 265 | 266 | 277 | ``` 278 | 279 | ## Add connect request parameters (ton_proof) 280 | Use `tonConnectUI.setConnectRequestParameters` function to pass your connect request parameters. 281 | 282 | This function takes one parameter: 283 | 284 | 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. 285 | ```ts 286 | import { ref } from 'vue'; 287 | import { useTonConnectUI } from '@townsquarelabs/ui-vue'; 288 | 289 | const {tonConnectUI} = useTonConnectUI(); 290 | 291 | tonConnectUI.setConnectRequestParameters({ 292 | state: 'loading' 293 | }); 294 | ``` 295 | 296 | or 297 | 298 | Set state to 'ready' and define `tonProof` value. Passed parameter will be applied to the connect request (QR and universal link). 299 | ```ts 300 | import { ref } from 'vue'; 301 | import { useTonConnectUI } from '@townsquarelabs/ui-vue'; 302 | 303 | const {tonConnectUI} = useTonConnectUI(); 304 | 305 | tonConnectUI.setConnectRequestParameters({ 306 | state: 'ready', 307 | value: { 308 | tonProof: '' 309 | } 310 | }); 311 | ``` 312 | 313 | or 314 | 315 | 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. 316 | ```ts 317 | import { ref } from 'vue'; 318 | import { useTonConnectUI } from '@townsquarelabs/ui-vue'; 319 | 320 | const {tonConnectUI} = useTonConnectUI(); 321 | 322 | tonConnectUI.setConnectRequestParameters(null); 323 | ``` 324 | 325 | 326 | 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). 327 | 328 | 329 | ```ts 330 | import { ref } from 'vue'; 331 | import { useTonConnectUI } from '@townsquarelabs/ui-vue'; 332 | 333 | const { tonConnectUI } = useTonConnectUI(); 334 | 335 | // enable ui loader 336 | tonConnectUI.setConnectRequestParameters({ state: 'loading' }); 337 | 338 | // fetch you tonProofPayload from the backend 339 | const tonProofPayload: string | null = await fetchTonProofPayloadFromBackend(); 340 | 341 | if (!tonProofPayload) { 342 | // remove loader, connect request will be without any additional parameters 343 | tonConnectUI.setConnectRequestParameters(null); 344 | } else { 345 | // add tonProof to the connect request 346 | tonConnectUI.setConnectRequestParameters({ 347 | state: "ready", 348 | value: { tonProof: tonProofPayload } 349 | }); 350 | } 351 | 352 | ``` 353 | 354 | 355 | You can find `ton_proof` result in the `wallet` object when wallet will be connected: 356 | 357 | ```ts 358 | import { ref, onMounted } from 'vue'; 359 | import { useTonConnectUI } from '@townsquarelabs/ui-vue'; 360 | 361 | const { tonConnectUI } = useTonConnectUI(); 362 | 363 | onMounted(() => 364 | tonConnectUI.onStatusChange(wallet => { 365 | if (wallet.connectItems?.tonProof && 'proof' in wallet.connectItems.tonProof) { 366 | checkProofInYourBackend(wallet.connectItems.tonProof.proof, wallet.account); 367 | } 368 | })); 369 | ``` 370 | 371 | # Troubleshooting 372 | 373 | ## Animations not working 374 | 375 | 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. 376 | 377 | ### Using npm 378 | 379 | To install the polyfill, run the following command: 380 | 381 | ```shell 382 | npm install web-animations-js 383 | ``` 384 | 385 | Then, import the polyfill in your project: 386 | 387 | ```typescript 388 | import 'web-animations-js'; 389 | ``` 390 | 391 | ### Using CDN 392 | 393 | Alternatively, you can include the polyfill via CDN by adding the following script tag to your HTML: 394 | 395 | ```html 396 | 397 | ``` 398 | 399 | Both methods will provide a fallback implementation of the Web Animations API and should resolve the animation issues you are facing. 400 | 401 | # Sync with Official Releases 402 | 403 | We are committed to providing our users with a reliable and continuously optimized Kit, so we will keep in close sync with the official release, and whenever a new official version is released, we will quickly update it to ensure that our Kit will always include the latest features, fixes, and improvements. Additionally, we conduct regular compatibility tests and performance optimizations based on the official release cadence to ensure you get the best experience possible. Whether it's the introduction of new features or security enhancements, you can rest assured that you can rely on us to stay consistent and on the cutting edge with the official release. 404 | 405 | ## process description 406 | 407 | 1. get the latest npm version to compare 408 | 409 | 2. if inconsistent, select the latest tag with version number to compare and get the patch file 410 | a. get all tags 411 | b. select the tags to compare 412 | c. get the patch file 413 | 414 | 3. parse patch and compare tonconnect react update content 415 | 416 | 4. if only package.json version and tonconnect ui version have changed 417 | 418 | 5. pull our package file and update these fields 419 | a. pull the latest code 420 | b. update package.json 421 | 422 | 6. create a new branch and commit the changes 423 | 424 | 7. merge the branch into main 425 | 426 | 8. trigger github action to automatically update log and publish to npm 427 | 428 | 9. after successful merge, remove the created branch 429 | 430 | 10. if the patch contains more than just version updates, create an issue to be notified 431 | a. if the patch contains other significant changes, create an issue on github to be notified about the updates 432 | 433 | 11. if any request fails after step 3, create an issue, making sure there is only one issue per problem 434 | 435 | 436 | ![Official_Sync_Process_Flowchart_image](./public/official_sync_process_flowchart.png) 437 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Vite + Vue + TS 8 | 9 | 10 |
11 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@townsquarelabs/ui-vue", 3 | "private": false, 4 | "version": "2.0.11-beta.0", 5 | "type": "module", 6 | "scripts": { 7 | "dev": "vite", 8 | "build": "npx vue-demi-switch 3 && vite build", 9 | "build:lib": "yarn build:lib:3 && yarn build:lib:2.7", 10 | "build:lib:2.7": "npx vue-demi-switch 2 && vite build", 11 | "build:lib:3": "npx vue-demi-switch 3 && vite build", 12 | "preview": "vite preview", 13 | "lint-fix": "eslint --fix --ext .ts,.vue src", 14 | "lint": "eslint", 15 | "prepare": "husky", 16 | "security-audit": "npm audit && npm outdated", 17 | "release": "standard-version" 18 | }, 19 | "publishConfig": { 20 | "access": "public" 21 | }, 22 | "description": "TonConnect UI Vue is a Vue UI kit for TonConnect SDK. Use it to connect your app to TON wallets via TonConnect protocol in Vue apps.", 23 | "repository": { 24 | "type": "git", 25 | "url": "git+https://github.com/TownSquareXYZ/tonconnect-ui-vue.git" 26 | }, 27 | "keywords": [ 28 | "ton", 29 | "townsquarexyz", 30 | "TON", 31 | "Wallet", 32 | "ton-connect", 33 | "tonconnect", 34 | "Connect", 35 | "Tonkeeper", 36 | "sdk", 37 | "UI", 38 | "Vue" 39 | ], 40 | "author": "", 41 | "license": "Apache-2.0", 42 | "bugs": { 43 | "url": "https://github.com/TownSquareXYZ/tonconnect-ui-vue/issues" 44 | }, 45 | "homepage": "https://github.com/TownSquareXYZ/tonconnect-ui-vue#readme", 46 | "files": [ 47 | "lib", 48 | "scripts" 49 | ], 50 | "main": "./lib/index.cjs", 51 | "module": "./lib/index.mjs", 52 | "types": "./lib/index.d.ts", 53 | "exports": { 54 | ".": { 55 | "types": "./lib/index.d.ts", 56 | "require": "./lib/index.cjs", 57 | "import": "./lib/index.mjs", 58 | "default": "./lib/index.cjs" 59 | } 60 | }, 61 | "peerDependencies": { 62 | "@vue/composition-api": "^1.0.0-rc.1", 63 | "vue": "^2.7.0 || >=3.0.0", 64 | "vue-demi": "^0.14.8" 65 | }, 66 | "dependencies": { 67 | "@tonconnect/ui": "2.0.10-beta.0" 68 | }, 69 | "devDependencies": { 70 | "@types/node": "^18.19.7", 71 | "@typescript-eslint/eslint-plugin": "^5.62.0", 72 | "@typescript-eslint/parser": "^5.62.0", 73 | "@vitejs/plugin-legacy": "^5.2.0", 74 | "@vitejs/plugin-vue": "^5.0.5", 75 | "@vitejs/plugin-vue2": "^2.3.1", 76 | "@vue-macros/volar": "^0.18.16", 77 | "@vue/composition-api": "^1.7.2", 78 | "autoprefixer": "^10.4.16", 79 | "eslint": "^8.56.0", 80 | "eslint-config-prettier": "^9.1.0", 81 | "eslint-plugin-prettier": "^5.2.1", 82 | "eslint-plugin-unused-imports": "^4.1.4", 83 | "eslint-plugin-vue": "^9.20.1", 84 | "husky": "^9.0.11", 85 | "lint-staged": "^15.2.2", 86 | "prettier": "^3.3.3", 87 | "standard-version": "^9.5.0", 88 | "typescript": "^4.9.5", 89 | "unplugin-vue-components": "^0.27.4", 90 | "unplugin-vue-define-options": "^1.5.1", 91 | "vite": "^5.0.11", 92 | "vite-plugin-dts": "^4.2.1", 93 | "vitest": "latest", 94 | "vue": "^2.7.16", 95 | "vue-demi": "^0.14.10", 96 | "vue-eslint-parser": "^9.4.0", 97 | "vue-tsc": "^0.39.5" 98 | }, 99 | "lint-staged": { 100 | "*.{vue,ts,tsx}": [ 101 | "eslint --ext .ts,.vue src", 102 | "prettier --write" 103 | ] 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /postcss.config.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: { 3 | autoprefixer: {}, 4 | }, 5 | } 6 | -------------------------------------------------------------------------------- /public/official_sync_process_flowchart.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TownSquareXYZ/tonconnect-ui-vue/ff8cbb66aa30b7c29ac1a1f76c96ebef91700ff3/public/official_sync_process_flowchart.png -------------------------------------------------------------------------------- /rollup.config.mjs: -------------------------------------------------------------------------------- 1 | import vue from '@vitejs/plugin-vue2' 2 | import typescript from '@rollup/plugin-typescript'; 3 | 4 | const config = [ 5 | { 6 | input: "./src/index.ts", 7 | output: [{ file: "lib/index.d.ts", format: "es" }], 8 | plugins: [ 9 | vue(), 10 | typescript({ 11 | tsconfig: path.resolve(__dirname, 'tsconfig.json'), 12 | // Ensure declaration files are generated 13 | declaration: true, 14 | declarationMap: true, 15 | }), 16 | ], 17 | }, 18 | ]; 19 | 20 | export default config; -------------------------------------------------------------------------------- /scripts/switch-cli.mjs: -------------------------------------------------------------------------------- 1 | import { switchVersion } from './utils.mjs' 2 | 3 | const version = process.argv[2] 4 | switchVersion(version) -------------------------------------------------------------------------------- /scripts/utils.mjs: -------------------------------------------------------------------------------- 1 | import path from 'path' 2 | import fs from 'fs' 3 | import { fileURLToPath } from 'url' 4 | const __filename = fileURLToPath(import.meta.url) 5 | const __dirname = path.dirname(__filename) 6 | 7 | function switchVersion(version) { 8 | const src = getLibDir(version) 9 | const dest = path.join(src, '..') 10 | console.log(`[frontend-shared] switch lib to vue version ${version}`) 11 | copyDir(src, dest) 12 | } 13 | 14 | function getLibDir(version) { 15 | const dirname = String(version).startsWith('2') ? 'vue2' : 'vue3' 16 | return path.join(__dirname, `../lib/${dirname}`) 17 | } 18 | 19 | function copyDir(src, dest) { 20 | console.log(`copying from ${src} to ${dest}`) 21 | // unlink for pnpm, #92 22 | try { 23 | fs.unlinkSync(dest) 24 | } catch (error) {} 25 | try { 26 | copyRecursiveSync(src, dest) 27 | } catch (error) { 28 | console.error(error) 29 | } 30 | } 31 | 32 | function copyRecursiveSync(src, dest) { 33 | const exists = fs.existsSync(src) 34 | const stats = exists && fs.statSync(src) 35 | const isDirectory = stats && stats.isDirectory() 36 | if (isDirectory) { 37 | !fs.existsSync(dest) && fs.mkdirSync(dest) 38 | fs.readdirSync(src).forEach((childItemName) => { 39 | copyRecursiveSync(path.join(src, childItemName), path.join(dest, childItemName)) 40 | }) 41 | } else { 42 | fs.copyFileSync(src, dest) 43 | } 44 | } 45 | 46 | export { getLibDir, copyDir, switchVersion } -------------------------------------------------------------------------------- /src/components/TonConnectButton.vue: -------------------------------------------------------------------------------- 1 | 44 | -------------------------------------------------------------------------------- /src/components/index.ts: -------------------------------------------------------------------------------- 1 | export { default as TonConnectButton } from './TonConnectButton.vue'; 2 | -------------------------------------------------------------------------------- /src/errors/index.ts: -------------------------------------------------------------------------------- 1 | export { TonConnectProviderNotSetError } from './ton-connect-provider-not-set.error'; 2 | export { TonConnectUIVueError } from './ton-connect-ui-vue.error'; 3 | -------------------------------------------------------------------------------- /src/errors/ton-connect-provider-not-set.error.ts: -------------------------------------------------------------------------------- 1 | import { TonConnectUIVueError } from './ton-connect-ui-vue.error'; 2 | 3 | /** 4 | * Thrown when either not added to the top of the tags tree, 5 | * either there is an attempt using TonConnect UI hook or inside 6 | */ 7 | export class TonConnectProviderNotSetError extends TonConnectUIVueError { 8 | constructor(...args: ConstructorParameters) { 9 | super(...args); 10 | 11 | Object.setPrototypeOf(this, TonConnectProviderNotSetError.prototype); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/errors/ton-connect-ui-vue.error.ts: -------------------------------------------------------------------------------- 1 | import { TonConnectUIError } from '@tonconnect/ui'; 2 | 3 | /** 4 | * Base class for TonConnectUIReact errors. You can check if the error was triggered by the @tonconnect/ui-react using `err instanceof TonConnectUIReactError`. 5 | */ 6 | export class TonConnectUIVueError extends TonConnectUIError { 7 | constructor(...args: ConstructorParameters) { 8 | super(...args); 9 | 10 | Object.setPrototypeOf(this, TonConnectUIVueError.prototype); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/hooks/index.ts: -------------------------------------------------------------------------------- 1 | export { useTonAddress } from './useTonAddress'; 2 | export { useTonConnectModal } from './useTonConnectModal'; 3 | export { useTonConnectUI } from './useTonConnectUI'; 4 | export { useTonWallet } from './useTonWallet'; 5 | export { useIsConnectionRestored } from './useIsConnectionRestored'; 6 | -------------------------------------------------------------------------------- /src/hooks/useIsConnectionRestored.ts: -------------------------------------------------------------------------------- 1 | import { ref, onMounted, Ref } from 'vue-demi'; 2 | import { useTonConnectUI } from './useTonConnectUI'; 3 | 4 | export function useIsConnectionRestored(): Ref { 5 | const restored = ref(false); 6 | const { tonConnectUI } = useTonConnectUI(); 7 | 8 | onMounted(() => { 9 | if (tonConnectUI?.closeModal) { 10 | tonConnectUI.connectionRestored.then(() => { 11 | restored.value = true; 12 | }); 13 | } 14 | }); 15 | 16 | return restored; 17 | } 18 | -------------------------------------------------------------------------------- /src/hooks/useTonAddress.ts: -------------------------------------------------------------------------------- 1 | import { computed, ComputedRef } from 'vue-demi'; 2 | import { CHAIN, toUserFriendlyAddress } from '@tonconnect/ui'; 3 | import { useTonWallet } from './useTonWallet'; 4 | 5 | export function useTonAddress(userFriendly = true): ComputedRef { 6 | const wallet = useTonWallet(); 7 | 8 | const tonAddress = computed(() => { 9 | if (wallet.value) { 10 | return userFriendly 11 | ? toUserFriendlyAddress( 12 | wallet.value.account.address, 13 | wallet.value.account.chain === CHAIN.TESTNET, 14 | ) 15 | : wallet.value.account.address; 16 | } else { 17 | return ''; 18 | } 19 | }); 20 | 21 | return tonAddress; 22 | } 23 | -------------------------------------------------------------------------------- /src/hooks/useTonConnectModal.ts: -------------------------------------------------------------------------------- 1 | import { ref, onMounted, Ref } from 'vue-demi'; 2 | import { useTonConnectUI } from './useTonConnectUI'; 3 | import { WalletsModalState } from '@tonconnect/ui'; 4 | 5 | export function useTonConnectModal(): { 6 | state: Ref; 7 | open: () => void; 8 | close: () => void; 9 | } { 10 | const { tonConnectUI } = useTonConnectUI(); 11 | const state = ref( 12 | tonConnectUI?.modal.state || null, 13 | ); 14 | 15 | onMounted(() => { 16 | if (tonConnectUI) { 17 | state.value = tonConnectUI.modal.state; 18 | 19 | tonConnectUI.onModalStateChange((value: WalletsModalState) => { 20 | state.value = value; 21 | }); 22 | } 23 | }); 24 | 25 | return { 26 | state: state, 27 | open: () => tonConnectUI?.modal.open(), 28 | close: () => tonConnectUI?.modal.close(), 29 | }; 30 | } 31 | -------------------------------------------------------------------------------- /src/hooks/useTonConnectUI.ts: -------------------------------------------------------------------------------- 1 | import { DefineComponent, getCurrentInstance, isVue2 } from 'vue-demi'; 2 | import { TonConnectUI, TonConnectUiOptions } from '@tonconnect/ui'; 3 | import { checkProvider } from '../utils/errors'; 4 | import { isServerSide } from '../utils/web'; 5 | 6 | type CustomInstance = DefineComponent & { 7 | proxy?: { 8 | $tonConnectUI?: TonConnectUI; 9 | }; 10 | appContext?: { 11 | app: { 12 | config: { 13 | globalProperties: { 14 | $tonConnectUI?: TonConnectUI; 15 | }; 16 | }; 17 | }; 18 | }; 19 | }; 20 | 21 | export function useTonConnectUI(): { 22 | tonConnectUI: TonConnectUI | null; 23 | setOptions: (options: TonConnectUiOptions) => void; 24 | error?: string; 25 | } { 26 | if (isServerSide()) { 27 | return { 28 | tonConnectUI: null as TonConnectUI | null, 29 | setOptions: () => { 30 | // empty 31 | }, 32 | }; 33 | } 34 | 35 | const instance = getCurrentInstance() as CustomInstance | null; 36 | 37 | if (!instance) { 38 | return { 39 | tonConnectUI: null, 40 | setOptions: () => { 41 | // empty 42 | }, 43 | error: 'Vue instance not found', 44 | }; 45 | } 46 | 47 | const tonConnectUI: TonConnectUI | null = isVue2 48 | ? (instance.proxy?.$tonConnectUI ?? null) 49 | : (instance.appContext?.app?.config?.globalProperties?.$tonConnectUI ?? 50 | null); 51 | 52 | if (!tonConnectUI) { 53 | throw new Error('TonConnect is not available'); 54 | } 55 | 56 | checkProvider(tonConnectUI); 57 | 58 | // 明确返回类型为 void 59 | const setOptions = (options: TonConnectUiOptions): void => { 60 | tonConnectUI.uiOptions = options; 61 | }; 62 | 63 | return { 64 | tonConnectUI, 65 | setOptions, 66 | }; 67 | } 68 | -------------------------------------------------------------------------------- /src/hooks/useTonWallet.ts: -------------------------------------------------------------------------------- 1 | import { ref, onMounted, onUnmounted, Ref } from 'vue-demi'; 2 | import { 3 | ConnectedWallet, 4 | Wallet, 5 | WalletInfoWithOpenMethod, 6 | } from '@tonconnect/ui'; 7 | import { useTonConnectUI } from './useTonConnectUI'; 8 | 9 | // Custom type to make properties mutable 10 | type Mutable = { 11 | -readonly [P in keyof T]: T[P]; 12 | }; 13 | 14 | function isWallet( 15 | value: unknown, 16 | ): value is Wallet | (Wallet & WalletInfoWithOpenMethod) { 17 | return ( 18 | value !== null && 19 | typeof value === 'object' && 20 | 'device' in value && 21 | 'provider' in value && 22 | 'account' in value 23 | ); 24 | } 25 | 26 | export function useTonWallet(): Ref< 27 | Wallet | (Wallet & WalletInfoWithOpenMethod) | null 28 | > { 29 | const { tonConnectUI } = useTonConnectUI(); 30 | const wallet = ref(null); 31 | 32 | const updateWallet = (value: ConnectedWallet | null): void => { 33 | if (isWallet(value)) { 34 | wallet.value = value as Mutable< 35 | Wallet | (Wallet & WalletInfoWithOpenMethod) 36 | >; 37 | } else { 38 | wallet.value = null; 39 | } 40 | }; 41 | 42 | const subscribeToWalletChanges = (): void => { 43 | if (!tonConnectUI) return; 44 | 45 | if (isWallet(tonConnectUI.wallet)) { 46 | wallet.value = tonConnectUI.wallet as Mutable< 47 | Wallet | (Wallet & WalletInfoWithOpenMethod) 48 | >; 49 | } 50 | 51 | const unsubscribe = tonConnectUI.onStatusChange(updateWallet); 52 | onUnmounted(unsubscribe); 53 | }; 54 | 55 | onMounted(subscribeToWalletChanges); 56 | 57 | return wallet; 58 | } 59 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | export * from '@tonconnect/ui'; 2 | export * from './library'; 3 | export * from './plugin'; 4 | export * from './types'; 5 | -------------------------------------------------------------------------------- /src/library.ts: -------------------------------------------------------------------------------- 1 | export * from './components'; 2 | export * from './errors'; 3 | export * from './hooks'; 4 | -------------------------------------------------------------------------------- /src/plugin.ts: -------------------------------------------------------------------------------- 1 | import { isVue2, shallowRef, PluginObject } from 'vue-demi'; 2 | import { TonConnectUI } from '@tonconnect/ui'; 3 | import { isClientSide } from './utils/web'; 4 | import { TonConnectUIProviderProps } from './types'; 5 | 6 | export const TonConnectUIPlugin: PluginObject = { 7 | install(app, options) { 8 | const tonConnectUI = shallowRef(null); 9 | 10 | // Initialize TonConnectUI if on client side 11 | if (isClientSide() && !tonConnectUI.value) { 12 | tonConnectUI.value = new TonConnectUI(options || {}); 13 | } 14 | 15 | if (isVue2) { 16 | app.prototype.$tonConnectUI = tonConnectUI.value; 17 | } else { 18 | // @ts-expect-error: TypeScript does not recognize the globalProperties property in Vue 3 19 | app.config.globalProperties.$tonConnectUI = tonConnectUI.value; 20 | } 21 | }, 22 | }; 23 | -------------------------------------------------------------------------------- /src/shims-vue.d.ts: -------------------------------------------------------------------------------- 1 | declare module '*.vue' { 2 | import Vue from 'vue'; 3 | const component: Vue & { [key: string]: unknown }; 4 | export default component; 5 | } 6 | -------------------------------------------------------------------------------- /src/types.ts: -------------------------------------------------------------------------------- 1 | import { 2 | ActionConfiguration, 3 | Locales, 4 | UIPreferences, 5 | WalletsListConfiguration, 6 | } from '@tonconnect/ui'; 7 | import type { ITonConnect } from '@tonconnect/ui'; 8 | 9 | export type TonConnectUIProviderProps = Partial & 10 | Partial< 11 | | TonConnectUIProviderPropsWithManifest 12 | | TonConnectUIProviderPropsWithConnector 13 | >; 14 | 15 | export interface TonConnectUIProviderPropsWithManifest { 16 | /** 17 | * Url to the [manifest]{@link https://github.com/ton-connect/docs/blob/main/requests-responses.md#app-manifest} with the Dapp metadata that will be displayed in the user's wallet. 18 | * If not passed, manifest from `${window.location.origin}/tonconnect-manifest.json` will be taken. 19 | */ 20 | manifestUrl: string; 21 | } 22 | 23 | export interface TonConnectUIProviderPropsWithConnector { 24 | /** 25 | * TonConnect instance. Can be helpful if you use custom ITonConnect implementation, or use both of @tonconnect/sdk and @tonconnect/ui in your app. 26 | */ 27 | connector: ITonConnect; 28 | } 29 | 30 | export interface TonConnectUIProviderPropsBase { 31 | /** 32 | * Try to restore existing session and reconnect to the corresponding wallet. 33 | * @default true. 34 | */ 35 | restoreConnection: boolean; 36 | 37 | /** 38 | * Language for the phrases it the UI elements. 39 | * @default system 40 | */ 41 | language: Locales; 42 | 43 | /** 44 | * HTML element id to attach the modal window element. If not passed, `div#tc-widget-root` in the end of the will be added and used. 45 | * @default `div#tc-widget-root`. 46 | */ 47 | widgetRootId: string; 48 | 49 | /** 50 | * UI elements configuration. 51 | */ 52 | uiPreferences?: UIPreferences; 53 | 54 | /** 55 | * Configuration for the wallets list in the connect wallet modal. 56 | */ 57 | walletsListConfiguration?: WalletsListConfiguration; 58 | 59 | /** 60 | * Configuration for action-period (e.g. sendTransaction) UI elements: modals and notifications and wallet behaviour (return strategy). 61 | */ 62 | actionsConfiguration?: ActionConfiguration; 63 | 64 | /** 65 | * Specifies whether the Android back button should be used to close modals and notifications on Android devices. 66 | * @default true 67 | */ 68 | enableAndroidBackHandler?: boolean; 69 | } 70 | -------------------------------------------------------------------------------- /src/utils/UIProvider.ts: -------------------------------------------------------------------------------- 1 | import { 2 | ActionConfiguration, 3 | Locales, 4 | UIPreferences, 5 | WalletsListConfiguration, 6 | } from '@tonconnect/ui'; 7 | import type { ITonConnect } from '@tonconnect/ui'; 8 | 9 | export type TonConnectUIProviderProps = Partial & 10 | Partial< 11 | | TonConnectUIProviderPropsWithManifest 12 | | TonConnectUIProviderPropsWithConnector 13 | >; 14 | 15 | export interface TonConnectUIProviderPropsWithManifest { 16 | /** 17 | * Url to the [manifest]{@link https://github.com/ton-connect/docs/blob/main/requests-responses.md#app-manifest} with the Dapp metadata that will be displayed in the user's wallet. 18 | * If not passed, manifest from `${window.location.origin}/tonconnect-manifest.json` will be taken. 19 | */ 20 | manifestUrl: string; 21 | } 22 | 23 | export interface TonConnectUIProviderPropsWithConnector { 24 | /** 25 | * TonConnect instance. Can be helpful if you use custom ITonConnect implementation, or use both of @tonconnect/sdk and @tonconnect/ui in your app. 26 | */ 27 | connector: ITonConnect; 28 | } 29 | 30 | export interface TonConnectUIProviderPropsBase { 31 | /** 32 | * Try to restore existing session and reconnect to the corresponding wallet. 33 | * @default true. 34 | */ 35 | restoreConnection: boolean; 36 | 37 | /** 38 | * Language for the phrases it the UI elements. 39 | * @default system 40 | */ 41 | language: Locales; 42 | 43 | /** 44 | * HTML element id to attach the modal window element. If not passed, `div#tc-widget-root` in the end of the will be added and used. 45 | * @default `div#tc-widget-root`. 46 | */ 47 | widgetRootId: string; 48 | 49 | /** 50 | * UI elements configuration. 51 | */ 52 | uiPreferences?: UIPreferences; 53 | 54 | /** 55 | * Configuration for the wallets list in the connect wallet modal. 56 | */ 57 | walletsListConfiguration?: WalletsListConfiguration; 58 | 59 | /** 60 | * Configuration for action-period (e.g. sendTransaction) UI elements: modals and notifications and wallet behaviour (return strategy). 61 | */ 62 | actionsConfiguration?: ActionConfiguration; 63 | 64 | /** 65 | * Specifies whether the Android back button should be used to close modals and notifications on Android devices. 66 | * @default true 67 | */ 68 | enableAndroidBackHandler?: boolean; 69 | } 70 | -------------------------------------------------------------------------------- /src/utils/errors.ts: -------------------------------------------------------------------------------- 1 | import { TonConnectUI } from '@tonconnect/ui'; 2 | import { TonConnectProviderNotSetError } from '../errors/ton-connect-provider-not-set.error'; 3 | 4 | export function checkProvider( 5 | provider: TonConnectUI | null, 6 | ): provider is TonConnectUI { 7 | if (!provider) { 8 | throw new TonConnectProviderNotSetError( 9 | 'You should add on the top of the app to use TonConnect', 10 | ); 11 | } 12 | 13 | return true; 14 | } 15 | -------------------------------------------------------------------------------- /src/utils/web.ts: -------------------------------------------------------------------------------- 1 | export function isClientSide(): boolean { 2 | return typeof window !== 'undefined'; 3 | } 4 | 5 | export function isServerSide(): boolean { 6 | return !isClientSide(); 7 | } 8 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "esnext", 4 | "module": "esnext", 5 | "moduleResolution": "node", 6 | "strict": true, 7 | "noLib": false, 8 | "forceConsistentCasingInFileNames": true, 9 | "allowSyntheticDefaultImports": true, 10 | "strictFunctionTypes": false, 11 | "jsx": "preserve", 12 | "baseUrl": ".", 13 | "allowJs": true, 14 | "sourceMap": true, 15 | "esModuleInterop": true, 16 | "resolveJsonModule": true, 17 | "noUnusedLocals": true, 18 | "noUnusedParameters": true, 19 | "experimentalDecorators": true, 20 | "lib": ["dom", "esnext"], 21 | "noImplicitAny": false, 22 | "skipLibCheck": true, 23 | "typeRoots": ["./node_modules/@types/", "./types", "./node_modules"], 24 | "types": ["vite/client", "node", "unplugin-vue-define-options/macros-global"], 25 | "removeComments": true, 26 | "paths": { 27 | "/@/*": ["src/*"] 28 | }, 29 | }, 30 | "include": [ 31 | // "tests/**/*.ts", 32 | "src/**/*.ts", 33 | "src/**/*.d.ts", 34 | "src/**/*.tsx", 35 | "src/**/*.vue", 36 | // "types/**/*.d.ts", 37 | // "types/**/*.ts", 38 | // "vite.config.ts" 39 | ], 40 | "exclude": ["node_modules", "dist", "**/*.js"] 41 | } 42 | -------------------------------------------------------------------------------- /tsconfig.node.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "composite": true, 4 | "module": "ESNext", 5 | "moduleResolution": "Node", 6 | "allowSyntheticDefaultImports": true 7 | }, 8 | "include": ["vite.config.ts"] 9 | } 10 | -------------------------------------------------------------------------------- /vite.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from "vite"; 2 | import vue2 from "@vitejs/plugin-vue2"; 3 | import vue3 from "@vitejs/plugin-vue"; 4 | import path from "path"; 5 | import dts from "vite-plugin-dts"; 6 | import { isVue2 } from "vue-demi"; 7 | import * as compiler from "@vue/compiler-sfc"; 8 | 9 | export default defineConfig({ 10 | plugins: [ 11 | isVue2 12 | ? vue2() 13 | : vue3({ 14 | compiler: compiler as any, 15 | }), 16 | dts({ 17 | insertTypesEntry: true, 18 | }), 19 | ], 20 | optimizeDeps: { 21 | exclude: ["csstype", "vue-demi"], 22 | }, 23 | build: { 24 | target: "es2018", 25 | outDir: 'lib', 26 | emptyOutDir: true, 27 | minify: false, 28 | sourcemap: false, 29 | lib: { 30 | formats: ["es", "cjs"], 31 | entry: path.resolve("src/index.ts"), 32 | name: "@townsquarelabs/ui-vue", 33 | fileName: (format) => { 34 | switch (format) { 35 | case "es": 36 | return "index.mjs"; 37 | case "cjs": 38 | return "index.cjs"; 39 | default: 40 | throw new Error("Unknown format"); 41 | } 42 | }, 43 | }, 44 | rollupOptions: { 45 | external: ["vue", "@tonconnect/ui", "vue-demi"], 46 | output: { 47 | globals: { 48 | vue: "Vue", 49 | "@tonconnect/ui": "TON_CONNECT_UI", 50 | "vue-demi": "VueDemi", 51 | }, 52 | }, 53 | }, 54 | }, 55 | }); 56 | --------------------------------------------------------------------------------