├── .changeset └── config.json ├── .editorconfig ├── .eslintignore ├── .eslintrc ├── .gitignore ├── .husky ├── commit-msg └── pre-commit ├── .npmrc ├── .prettierignore ├── .prettierrc.json ├── App.md ├── LICENSE ├── README.md ├── demo.png ├── demos ├── cdn-demo │ ├── .eslintrc │ ├── .gitignore │ ├── .npmrc │ ├── .prettierrc.json │ ├── README.md │ ├── adapters │ │ └── index.html │ ├── bitkeep │ │ └── index.html │ ├── ledger │ │ └── index.html │ ├── metamask │ │ └── index.html │ ├── okxwallet │ │ └── index.html │ ├── package.json │ ├── tokenpocket │ │ └── index.html │ ├── tronlink-evm │ │ └── index.html │ ├── tronlink │ │ └── index.html │ └── walletconnect │ │ └── index.html ├── dev-demo │ ├── .eslintrc │ ├── .gitignore │ ├── .npmrc │ ├── .prettierrc.json │ ├── index.html │ ├── package.json │ ├── scripts │ │ └── ganache.cjs │ ├── src │ │ ├── App.tsx │ │ ├── AppWraper.tsx │ │ ├── BitgetAdapterDemo.tsx │ │ ├── LedgerAdapterDemo.tsx │ │ ├── LedgerDemo │ │ │ ├── ConnectTip.tsx │ │ │ ├── ConnectedSection.tsx │ │ │ ├── CustomConnectWithGetAccounts.tsx │ │ │ ├── CustomConnectWithSelectAccount.tsx │ │ │ ├── SelectAccountSection.tsx │ │ │ └── selectAccount.tsx │ │ ├── Metamask.tsx │ │ ├── OkxWalletAdapterDemo.tsx │ │ ├── ReactHooksDemo.tsx │ │ ├── TokenPocketAdapterDemo.tsx │ │ ├── TronLinkAdapterDemo.tsx │ │ ├── TronLinkEvmDemo.tsx │ │ ├── index.css │ │ ├── main.tsx │ │ ├── theme.ts │ │ ├── tronweb.ts │ │ └── vite-env.d.ts │ ├── tsconfig.json │ ├── tsconfig.node.json │ └── vite.config.ts ├── react-ui │ ├── create-react-app │ │ ├── .gitignore │ │ ├── .npmrc │ │ ├── README.md │ │ ├── config-overrides.js │ │ ├── package.json │ │ ├── public │ │ │ ├── favicon.ico │ │ │ ├── index.html │ │ │ ├── logo192.png │ │ │ ├── logo512.png │ │ │ ├── manifest.json │ │ │ └── robots.txt │ │ ├── src │ │ │ ├── App.css │ │ │ ├── App.test.tsx │ │ │ ├── App.tsx │ │ │ ├── index.css │ │ │ ├── index.tsx │ │ │ ├── logo.svg │ │ │ ├── react-app-env.d.ts │ │ │ ├── reportWebVitals.ts │ │ │ ├── setupTests.ts │ │ │ ├── theme.ts │ │ │ └── tronweb.ts │ │ └── tsconfig.json │ ├── next-app │ │ ├── .eslintrc.json │ │ ├── .gitignore │ │ ├── .npmrc │ │ ├── README.md │ │ ├── next.config.js │ │ ├── package.json │ │ ├── pages │ │ │ ├── _app.tsx │ │ │ ├── api │ │ │ │ ├── hello.ts │ │ │ │ └── tronweb.ts │ │ │ └── index.tsx │ │ ├── public │ │ │ ├── favicon.ico │ │ │ └── vercel.svg │ │ ├── styles │ │ │ ├── Home.module.css │ │ │ └── globals.css │ │ └── tsconfig.json │ └── vite-app │ │ ├── .gitignore │ │ ├── .npmrc │ │ ├── README.md │ │ ├── index.html │ │ ├── package.json │ │ ├── public │ │ └── vite.svg │ │ ├── src │ │ ├── App.tsx │ │ ├── TronLinkAdapter.tsx │ │ ├── assets │ │ │ └── react.svg │ │ ├── index.css │ │ ├── main.tsx │ │ ├── theme.ts │ │ ├── tronweb.ts │ │ └── vite-env.d.ts │ │ ├── tsconfig.json │ │ ├── tsconfig.node.json │ │ └── vite.config.ts └── vue-ui │ └── vite-app │ ├── .gitignore │ ├── README.md │ ├── index.html │ ├── package.json │ ├── public │ └── vite.svg │ ├── src │ ├── App.vue │ ├── assets │ │ └── vue.svg │ ├── components │ │ ├── HooksDemo.vue │ │ └── VueUiDemo.vue │ ├── main.ts │ ├── style.css │ ├── tronweb.ts │ └── vite-env.d.ts │ ├── tsconfig.json │ ├── tsconfig.node.json │ └── vite.config.ts ├── docs ├── action-button.gif ├── index.md ├── wallet-adapter-react-ui.md ├── wallet-adapter-react.md ├── wallet-adapter-vue-ui.md ├── wallet-adapter-vue.md └── wallet-adapters.md ├── package.json ├── packages ├── adapters │ ├── abstract-adapter-evm │ │ ├── LICENSE │ │ ├── README.md │ │ ├── jest.config.js │ │ ├── package.json │ │ ├── src │ │ │ ├── adapter.ts │ │ │ ├── eip1193-provider.ts │ │ │ ├── errors.ts │ │ │ ├── index.ts │ │ │ └── utils.ts │ │ ├── tests │ │ │ └── units │ │ │ │ ├── adapter.test.ts │ │ │ │ ├── errors.test.ts │ │ │ │ └── utils.test.ts │ │ ├── tsconfig.all.json │ │ ├── tsconfig.cjs.json │ │ └── tsconfig.esm.json │ ├── abstract-adapter │ │ ├── LICENSE │ │ ├── README.md │ │ ├── package.json │ │ ├── src │ │ │ ├── adapter.ts │ │ │ ├── errors.ts │ │ │ ├── index.ts │ │ │ ├── types.ts │ │ │ └── utils.ts │ │ ├── tsconfig.all.json │ │ ├── tsconfig.cjs.json │ │ └── tsconfig.esm.json │ ├── adapters │ │ ├── LICENSE │ │ ├── README.md │ │ ├── package.json │ │ ├── src │ │ │ └── index.ts │ │ ├── tsconfig.all.json │ │ ├── tsconfig.cjs.json │ │ └── tsconfig.esm.json │ ├── bitkeep │ │ ├── LICENSE │ │ ├── README.md │ │ ├── jest.config.js │ │ ├── package.json │ │ ├── src │ │ │ ├── adapter.ts │ │ │ ├── index.ts │ │ │ └── utils.ts │ │ ├── tests │ │ │ └── units │ │ │ │ └── adapter.test.ts │ │ ├── tsconfig.all.json │ │ ├── tsconfig.cjs.json │ │ └── tsconfig.esm.json │ ├── ledger │ │ ├── LICENSE │ │ ├── README.md │ │ ├── __mocks__ │ │ │ ├── .eslintrc │ │ │ └── @ledgerhq │ │ │ │ ├── hw-app-trx.js │ │ │ │ └── hw-transport-webhid.js │ │ ├── jest.config.js │ │ ├── package.json │ │ ├── resolver.cjs │ │ ├── src │ │ │ ├── LedgerWallet.ts │ │ │ ├── Modal │ │ │ │ ├── ConfirmContent.tsx │ │ │ │ ├── ConnectingContent.tsx │ │ │ │ ├── LedgerIcon.tsx │ │ │ │ ├── LoadingIcon.tsx │ │ │ │ ├── Modal.tsx │ │ │ │ ├── SelectAccount.tsx │ │ │ │ ├── lang.ts │ │ │ │ ├── openModal.tsx │ │ │ │ └── style.ts │ │ │ ├── __mocks__ │ │ │ │ └── LedgerWallet.ts │ │ │ ├── adapter.ts │ │ │ ├── index.ts │ │ │ └── polyfills │ │ │ │ ├── Buffer.ts │ │ │ │ └── index.ts │ │ ├── test │ │ │ └── units │ │ │ │ ├── LedgerWallet.test.ts │ │ │ │ ├── adapter.test.ts │ │ │ │ └── openModal.test.ts │ │ ├── tsconfig.all.json │ │ ├── tsconfig.cjs.json │ │ ├── tsconfig.esm.json │ │ └── tsconfig.json │ ├── metamask │ │ ├── LICENSE │ │ ├── README.md │ │ ├── jest.config.js │ │ ├── package.json │ │ ├── src │ │ │ ├── adapter.ts │ │ │ ├── index.ts │ │ │ └── utils.ts │ │ ├── tests │ │ │ └── units │ │ │ │ ├── adapter.test.ts │ │ │ │ └── metamask-provider.ts │ │ ├── tsconfig.all.json │ │ ├── tsconfig.cjs.json │ │ └── tsconfig.esm.json │ ├── okxwallet │ │ ├── LICENSE │ │ ├── README.md │ │ ├── jest.config.js │ │ ├── package.json │ │ ├── src │ │ │ ├── adapter.ts │ │ │ ├── index.ts │ │ │ └── utils.ts │ │ ├── tests │ │ │ └── units │ │ │ │ └── adapter.test.ts │ │ ├── tsconfig.all.json │ │ ├── tsconfig.cjs.json │ │ └── tsconfig.esm.json │ ├── tokenpocket │ │ ├── LICENSE │ │ ├── README.md │ │ ├── jest.config.js │ │ ├── package.json │ │ ├── src │ │ │ ├── adapter.ts │ │ │ ├── index.ts │ │ │ └── utils.ts │ │ ├── tests │ │ │ └── units │ │ │ │ └── adapter.test.ts │ │ ├── tsconfig.all.json │ │ ├── tsconfig.cjs.json │ │ └── tsconfig.esm.json │ ├── tronlink-evm │ │ ├── LICENSE │ │ ├── README.md │ │ ├── jest.config.js │ │ ├── package.json │ │ ├── src │ │ │ ├── adapter.ts │ │ │ ├── index.ts │ │ │ └── utils.ts │ │ ├── tests │ │ │ └── units │ │ │ │ └── adapter.test.ts │ │ ├── tsconfig.all.json │ │ ├── tsconfig.cjs.json │ │ └── tsconfig.esm.json │ ├── tronlink │ │ ├── LICENSE │ │ ├── README.md │ │ ├── jest.config.js │ │ ├── package.json │ │ ├── src │ │ │ ├── adapter.ts │ │ │ ├── error.ts │ │ │ ├── index.ts │ │ │ ├── types.ts │ │ │ └── utils.ts │ │ ├── tests │ │ │ └── units │ │ │ │ ├── adapter-mobile.test.ts │ │ │ │ ├── adapter-tron.test.ts │ │ │ │ ├── adapter-tronweb.test.ts │ │ │ │ ├── adapter.test.ts │ │ │ │ ├── mock.ts │ │ │ │ └── utils.ts │ │ ├── tsconfig.all.json │ │ ├── tsconfig.cjs.json │ │ └── tsconfig.esm.json │ └── walletconnect │ │ ├── LICENSE │ │ ├── README.md │ │ ├── package.json │ │ ├── src │ │ ├── adapter.ts │ │ └── index.ts │ │ ├── tsconfig.all.json │ │ ├── tsconfig.cjs.json │ │ └── tsconfig.esm.json ├── react │ ├── react-hooks │ │ ├── LICENSE │ │ ├── README.md │ │ ├── jest.config.js │ │ ├── package.json │ │ ├── src │ │ │ ├── WalletProvider.tsx │ │ │ ├── index.ts │ │ │ ├── useLocalStorage.ts │ │ │ └── useWallet.ts │ │ ├── tests │ │ │ └── units │ │ │ │ ├── useLocalStorage.test.tsx │ │ │ │ └── useWallet.test.tsx │ │ ├── tsconfig.all.json │ │ ├── tsconfig.cjs.json │ │ └── tsconfig.esm.json │ └── react-ui │ │ ├── LICENSE │ │ ├── README.md │ │ ├── action-button.gif │ │ ├── jest.config.js │ │ ├── package.json │ │ ├── src │ │ ├── Button.tsx │ │ ├── Collapse.tsx │ │ ├── Modal │ │ │ ├── ReactPortal.tsx │ │ │ └── WalletSelectModal.tsx │ │ ├── WalletActionButton.tsx │ │ ├── WalletConnectButton.tsx │ │ ├── WalletDisconnectButton.tsx │ │ ├── WalletItem.tsx │ │ ├── WalletModalProvider.tsx │ │ ├── WalletSelectButton.tsx │ │ ├── index.ts │ │ ├── useWalletModal.tsx │ │ └── utils.tsx │ │ ├── style.css │ │ ├── tests │ │ └── units │ │ │ ├── Button.test.tsx │ │ │ ├── MockTronLink.ts │ │ │ ├── WalletActionButton.test.tsx │ │ │ ├── WalletConnectButton.test.tsx │ │ │ ├── WalletDisconnectButton.test.tsx │ │ │ └── WalletSelectButton.test.tsx │ │ ├── tsconfig.all.json │ │ ├── tsconfig.cjs.json │ │ └── tsconfig.esm.json └── vue │ ├── vue-hooks │ ├── LICENSE │ ├── README.md │ ├── package.json │ ├── src │ │ ├── WalletProvider.ts │ │ ├── index.ts │ │ ├── useLocalStorage.ts │ │ └── useWallet.ts │ ├── tests │ │ └── units │ │ │ └── useWallet.test.tsx │ ├── tsconfig.all.json │ ├── tsconfig.cjs.json │ ├── tsconfig.esm.json │ └── vitest.config.ts │ └── vue-ui │ ├── LICENSE │ ├── README.md │ ├── action-button.gif │ ├── babel.config.cjs.json │ ├── babel.config.esm.json │ ├── package.json │ ├── src │ ├── Button.tsx │ ├── Modal │ │ ├── VuePortal.tsx │ │ └── WalletSelectModal.tsx │ ├── WalletActionButton │ │ ├── Collapse.tsx │ │ └── WalletActionButton.tsx │ ├── WalletConnectButton.tsx │ ├── WalletDisconnectButton.tsx │ ├── WalletItem.tsx │ ├── WalletModalProvider.tsx │ ├── WalletSelectButton.tsx │ ├── index.ts │ ├── useWalletModal.tsx │ └── utils.tsx │ ├── style.css │ ├── tests │ └── units │ │ ├── Button.test.tsx │ │ ├── MockTronLink.ts │ │ ├── WalletActionButton.test.tsx │ │ ├── WalletConnectButton.test.tsx │ │ ├── WalletDisconnectButton.test.tsx │ │ └── WalletSelectButton.test.tsx │ ├── tsconfig.all.json │ ├── tsconfig.cjs.json │ ├── tsconfig.esm.json │ ├── tsconfig.json │ └── vite.config.js ├── pnpm-lock.yaml ├── pnpm-workspace.yaml ├── scripts ├── build-umd.js ├── check-dep-version.js └── list-pkg-versions.js ├── tsconfig.all.json ├── tsconfig.base.json ├── tsconfig.cjs.json ├── tsconfig.esm.json ├── tsconfig.json ├── tsconfig.root.json └── tsconfig.tests.json /.changeset/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://unpkg.com/@changesets/config@2.3.0/schema.json", 3 | "changelog": "@changesets/cli/changelog", 4 | "commit": false, 5 | "fixed": [], 6 | "linked": [], 7 | "access": "restricted", 8 | "baseBranch": "main", 9 | "updateInternalDependencies": "patch", 10 | "ignore": [] 11 | } 12 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | indent_style = space 6 | indent_size = 4 7 | end_of_line = lf 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | .github 2 | .next 3 | .parcel-cache 4 | .swc 5 | 6 | docs 7 | lib 8 | build 9 | dist 10 | out 11 | public/ 12 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | "extends": [ 4 | "eslint:recommended", 5 | "plugin:@typescript-eslint/recommended", 6 | "plugin:prettier/recommended", 7 | "plugin:react/recommended", 8 | "plugin:react-hooks/recommended", 9 | "plugin:require-extensions/recommended" 10 | ], 11 | "parser": "@typescript-eslint/parser", 12 | "plugins": ["@typescript-eslint", "prettier", "react", "react-hooks", "require-extensions"], 13 | "settings": { 14 | "react": { 15 | "version": "detect" 16 | } 17 | }, 18 | "rules": { 19 | "@typescript-eslint/ban-ts-comment": "off", 20 | "@typescript-eslint/no-explicit-any": "off", 21 | "@typescript-eslint/no-unused-vars": "warn", 22 | "@typescript-eslint/no-empty-interface": "off", 23 | "@typescript-eslint/consistent-type-imports": "error", 24 | "react/no-unescaped-entities": ["error", { "forbid": [">"] }] 25 | }, 26 | "overrides": [ 27 | { 28 | "files": ["demos/**/*"], 29 | "rules": { 30 | "require-extensions/require-extensions": "off", 31 | "react/react-in-jsx-scope": "off", 32 | "@typescript-eslint/no-unused-vars": "off" 33 | } 34 | }, 35 | { 36 | "files": ["packages/vue/**/*"], 37 | "rules": { 38 | "react-hooks/rules-of-hooks": "off", 39 | "react-hooks/exhaustive-deps": "off", 40 | "react/react-in-jsx-scope": "off", 41 | "react/no-unknown-property": "off" 42 | } 43 | } 44 | ] 45 | } 46 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | .vscode 3 | .DS_Store 4 | 5 | node_modules 6 | 7 | package-lock.json 8 | yarn.lock 9 | 10 | .next 11 | .parcel-cache 12 | .swc 13 | build 14 | lib 15 | dist 16 | out 17 | *.tsbuildinfo 18 | *.log 19 | coverage 20 | -------------------------------------------------------------------------------- /.husky/commit-msg: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | . "$(dirname -- "$0")/_/husky.sh" 3 | 4 | npx --no -- commitlint --edit ${1} 5 | -------------------------------------------------------------------------------- /.husky/pre-commit: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | . "$(dirname -- "$0")/_/husky.sh" 3 | 4 | npx lint-staged 5 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | strict-peer-dependencies=false 2 | # not add workspace: to package.json 3 | save-workspace-protocol=false -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | .github 2 | .next 3 | .parcel-cache 4 | .swc 5 | 6 | docs 7 | lib 8 | build 9 | dist 10 | out 11 | demos/ 12 | -------------------------------------------------------------------------------- /.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "printWidth": 120, 3 | "trailingComma": "es5", 4 | "tabWidth": 4, 5 | "semi": true, 6 | "singleQuote": true 7 | } 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright (c) 2022-Present, tronprotocol 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | -------------------------------------------------------------------------------- /demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tronprotocol/tronwallet-adapter/3b2bdf995a7c3d834a0e3bb5ec71565cd961b2b0/demo.png -------------------------------------------------------------------------------- /demos/cdn-demo/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | // "extends": [], 3 | "parser": "@typescript-eslint/parser", 4 | "env": { 5 | "node": true 6 | }, 7 | "rules": { 8 | "require-extensions/require-extensions": "off" 9 | }, 10 | "overrides": [ 11 | { 12 | "files": "./scripts/*.cjs", 13 | "rules": { 14 | "@typescript-eslint/no-var-requires": "off" 15 | } 16 | } 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /demos/cdn-demo/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | pnpm-debug.log* 8 | lerna-debug.log* 9 | 10 | node_modules 11 | dist 12 | dist-ssr 13 | *.local 14 | 15 | # Editor directories and files 16 | .vscode/* 17 | !.vscode/extensions.json 18 | .idea 19 | .DS_Store 20 | *.suo 21 | *.ntvs* 22 | *.njsproj 23 | *.sln 24 | *.sw? 25 | -------------------------------------------------------------------------------- /demos/cdn-demo/.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false -------------------------------------------------------------------------------- /demos/cdn-demo/.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "printWidth": 180, 3 | "trailingComma": "es5", 4 | "tabWidth": 4, 5 | "semi": true, 6 | "singleQuote": true 7 | } 8 | -------------------------------------------------------------------------------- /demos/cdn-demo/README.md: -------------------------------------------------------------------------------- 1 | # TronWallet CND Demo 2 | This project shows how to use Tronwallet Adapter with vanilla js. 3 | 4 | ## Usage 5 | 1. Installation 6 | First you should install the npm package to use the `umd` format file: 7 | ```bash 8 | npm i @tronweb3/tronwallet-adapters 9 | ``` 10 | 11 | 2. Add script in your HTML file 12 | Put the script in your `head` tag: 13 | ```html 14 | 15 | ``` 16 | 17 | **Note**: You should adjust the relative path according to the position of your HTML file. 18 | 19 | 3. Get specified adapter 20 | ```js 21 | const { TronLinkAdapter, BitKeepAdapter, WalletConnectAdapter, OkxWalletAdapter } = window['@tronweb3/tronwallet-adapters']; 22 | const tronlinkAdapter = new TronLinkAdapter({ 23 | openTronLinkAppOnMobile: true, 24 | openUrlWhenWalletNotFound: false, 25 | checkTimeout: 3000, 26 | }); 27 | ``` 28 | 29 | Please refer [here](https://developers.tron.network/docs/tronwallet-adapter) for more detailed documentation. 30 | 31 | ## WalletConnectAdapter 32 | If you want to use `WalletConnectAdapter`, you should install another dependency in addition: 33 | ```bash 34 | npm i @walletconnect/sign-client 35 | ``` 36 | 37 | And add a script tag for `@walletconnect/sign-client`: 38 | ```diff 39 | + 40 | 41 | ``` -------------------------------------------------------------------------------- /demos/cdn-demo/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cdn-demo", 3 | "private": true, 4 | "version": "0.0.1", 5 | "type": "module", 6 | "scripts": { 7 | "dev": "serve" 8 | }, 9 | "dependencies": { 10 | "@tronweb3/abstract-adapter-evm": "^1.0.1", 11 | "@tronweb3/tronwallet-abstract-adapter": "^1.1.6", 12 | "@tronweb3/tronwallet-adapter-bitkeep": "^1.0.2", 13 | "@tronweb3/tronwallet-adapter-ledger": "^1.1.8", 14 | "@tronweb3/tronwallet-adapter-metamask": "^1.0.1", 15 | "@tronweb3/tronwallet-adapter-okxwallet": "^1.0.2", 16 | "@tronweb3/tronwallet-adapter-tokenpocket": "^1.0.2", 17 | "@tronweb3/tronwallet-adapter-tronlink": "^1.1.9", 18 | "@tronweb3/tronwallet-adapter-tronlink-evm": "^1.0.0", 19 | "@tronweb3/tronwallet-adapter-walletconnect": "^1.0.5", 20 | "@tronweb3/tronwallet-adapters": "^1.1.9", 21 | "@walletconnect/sign-client": "^2.1.4", 22 | "serve": "^14.2.1" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /demos/dev-demo/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | // "extends": [], 3 | "parser": "@typescript-eslint/parser", 4 | "env": { 5 | "node": true 6 | }, 7 | "rules": { 8 | "require-extensions/require-extensions": "off" 9 | }, 10 | "overrides": [ 11 | { 12 | "files": "./scripts/*.cjs", 13 | "rules": { 14 | "@typescript-eslint/no-var-requires": "off" 15 | } 16 | } 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /demos/dev-demo/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | pnpm-debug.log* 8 | lerna-debug.log* 9 | 10 | node_modules 11 | dist 12 | dist-ssr 13 | *.local 14 | 15 | # Editor directories and files 16 | .vscode/* 17 | !.vscode/extensions.json 18 | .idea 19 | .DS_Store 20 | *.suo 21 | *.ntvs* 22 | *.njsproj 23 | *.sln 24 | *.sw? 25 | -------------------------------------------------------------------------------- /demos/dev-demo/.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false -------------------------------------------------------------------------------- /demos/dev-demo/.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "printWidth": 180, 3 | "trailingComma": "es5", 4 | "tabWidth": 4, 5 | "semi": true, 6 | "singleQuote": true 7 | } 8 | -------------------------------------------------------------------------------- /demos/dev-demo/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Vite + React + TS 7 | 8 | 9 |
10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /demos/dev-demo/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dev-demo", 3 | "private": true, 4 | "version": "0.0.1", 5 | "type": "module", 6 | "scripts": { 7 | "dev": "vite", 8 | "build": "tsc && vite build", 9 | "preview": "vite preview", 10 | "ganache": "node scripts/ganache.cjs" 11 | }, 12 | "dependencies": { 13 | "@emotion/react": "^11.10.4", 14 | "@emotion/styled": "^11.10.4", 15 | "@ethersproject/properties": "^5.7.0", 16 | "@ethersproject/strings": "^5.7.0", 17 | "@metamask/eth-sig-util": "^6.0.0", 18 | "@mui/material": "^5.10.10", 19 | "@tronweb3/abstract-adapter-evm": "^1.0.1", 20 | "@tronweb3/tronwallet-abstract-adapter": "^1.1.6", 21 | "@tronweb3/tronwallet-adapter-bitkeep": "^1.0.2", 22 | "@tronweb3/tronwallet-adapter-ledger": "^1.1.8", 23 | "@tronweb3/tronwallet-adapter-metamask": "^1.0.1", 24 | "@tronweb3/tronwallet-adapter-okxwallet": "^1.0.2", 25 | "@tronweb3/tronwallet-adapter-react-hooks": "^1.1.7", 26 | "@tronweb3/tronwallet-adapter-react-ui": "^1.1.8", 27 | "@tronweb3/tronwallet-adapter-tokenpocket": "^1.0.2", 28 | "@tronweb3/tronwallet-adapter-tronlink-evm": "^1.0.0", 29 | "@tronweb3/tronwallet-adapters": "^1.1.9", 30 | "@types/node": "^18.19.0", 31 | "events": "^3.3.0", 32 | "ganache": "^7.9.0", 33 | "lit-html": "^3.0.0", 34 | "react": "^18.2.0", 35 | "react-dom": "^18.2.0", 36 | "tronweb": "~5.1.0", 37 | "vconsole": "^3.15.1" 38 | }, 39 | "devDependencies": { 40 | "@types/react": "^18.0.26", 41 | "@types/react-dom": "^18.0.8", 42 | "@vitejs/plugin-legacy": "^5.4.1", 43 | "@vitejs/plugin-react": "^4.3.1", 44 | "dotenv": "^16.3.1", 45 | "typescript": "^4.6.4", 46 | "vite": "^5.2.11", 47 | "webpack-cli": "^5.0.2" 48 | }, 49 | "overrides": { 50 | "@ledgerhq/errors": "6.10.0", 51 | "@ledgerhq/devices": "6.27.1", 52 | "@ledgerhq/hw-transport": "6.27.1", 53 | "@ledgerhq/hw-transport-webhid": "6.27.1" 54 | }, 55 | "resolutions": { 56 | "@ledgerhq/errors": "6.10.0", 57 | "@ledgerhq/devices": "6.27.1", 58 | "@ledgerhq/hw-transport": "6.27.1", 59 | "@ledgerhq/hw-transport-webhid": "6.27.1" 60 | } 61 | } -------------------------------------------------------------------------------- /demos/dev-demo/scripts/ganache.cjs: -------------------------------------------------------------------------------- 1 | const ganache = require('ganache'); 2 | 3 | require('dotenv').config({}); 4 | 5 | const options = { 6 | fork: process.env.INFURA_PROJECT_ID 7 | ? { url: `https://mainnet.infura.io/v3/${process.env.INFURA_PROJECT_ID}` } 8 | : 'mainnet', 9 | chain: { 10 | // hardfork: 'berlin', 11 | }, 12 | }; 13 | options.wallet = { 14 | mnemonic: 15 | 'shove comic where catch muscle impulse that fork plunge robust noise subject', 16 | }; 17 | const server = ganache.server(options); 18 | const PORT = 8545; 19 | 20 | server.listen(PORT, async (err) => { 21 | if (err) throw err; 22 | 23 | console.log(`ganache listening on port ${PORT}...`); 24 | console.log('accounts created'); 25 | const provider = server.provider; 26 | 27 | if (process.env.MNEMONIC_PHRASE) { 28 | const accounts = await provider.request({ 29 | method: 'eth_accounts', 30 | params: [], 31 | }); 32 | console.log(accounts); 33 | } else { 34 | console.log(`mnemonic used: ${provider.getOptions().wallet?.mnemonic}`); 35 | console.log(provider.getInitialAccounts()); 36 | } 37 | }); 38 | -------------------------------------------------------------------------------- /demos/dev-demo/src/AppWraper.tsx: -------------------------------------------------------------------------------- 1 | import App from './App.js'; 2 | 3 | export function AppWraper() { 4 | return (); 5 | } 6 | -------------------------------------------------------------------------------- /demos/dev-demo/src/LedgerDemo/ConnectTip.tsx: -------------------------------------------------------------------------------- 1 | export function ConnectTip() { 2 | return ( 3 |
4 | Note 5 | 16 |
17 | ); 18 | } 19 | -------------------------------------------------------------------------------- /demos/dev-demo/src/index.css: -------------------------------------------------------------------------------- 1 | button { 2 | text-transform: none !important; 3 | } 4 | -------------------------------------------------------------------------------- /demos/dev-demo/src/main.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | import ReactDOM from 'react-dom/client'; 3 | import App from './App'; 4 | import '@tronweb3/tronwallet-adapter-react-ui/style.css'; 5 | import { WalletProvider } from '@tronweb3/tronwallet-adapter-react-hooks'; 6 | import { WalletModalProvider } from '@tronweb3/tronwallet-adapter-react-ui'; 7 | import { ThemeProvider } from '@mui/material/styles'; 8 | import theme from './theme'; 9 | import VConsole from 'vconsole'; 10 | import './index.css'; 11 | import { AppWraper } from './AppWraper.js'; 12 | const vConsole = new VConsole(); 13 | 14 | ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render( 15 | 16 | 17 | 18 | 19 | 20 | ); 21 | -------------------------------------------------------------------------------- /demos/dev-demo/src/theme.ts: -------------------------------------------------------------------------------- 1 | import { createTheme } from '@mui/material/styles'; 2 | import { red } from '@mui/material/colors'; 3 | 4 | // Create a theme instance. 5 | const theme = createTheme({ 6 | palette: { 7 | primary: { 8 | main: '#556cd6', 9 | }, 10 | secondary: { 11 | main: '#19857b', 12 | }, 13 | error: { 14 | main: red.A400, 15 | }, 16 | }, 17 | components: { 18 | MuiButton: { 19 | styleOverrides: { 20 | root: { 21 | margin: '0 10px' 22 | } 23 | } 24 | } 25 | } 26 | }); 27 | 28 | export default theme; 29 | -------------------------------------------------------------------------------- /demos/dev-demo/src/tronweb.ts: -------------------------------------------------------------------------------- 1 | // @ts-ignore 2 | import TronWeb from 'tronweb'; 3 | 4 | export const tronWeb: any = new TronWeb({ 5 | fullHost: 'https://api.nileex.io', 6 | // fullHost: 'https://api.trongrid.io' 7 | }); 8 | (window as any).tronWeb1 = tronWeb; 9 | -------------------------------------------------------------------------------- /demos/dev-demo/src/vite-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /demos/dev-demo/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ESNext", 4 | "useDefineForClassFields": true, 5 | "lib": ["DOM", "DOM.Iterable", "ESNext"], 6 | "allowJs": false, 7 | "skipLibCheck": true, 8 | "esModuleInterop": false, 9 | "allowSyntheticDefaultImports": true, 10 | "strict": true, 11 | "forceConsistentCasingInFileNames": true, 12 | "module": "ESNext", 13 | "moduleResolution": "Node", 14 | "resolveJsonModule": true, 15 | "isolatedModules": true, 16 | "noEmit": true, 17 | "jsx": "react-jsx", 18 | "types": [ 19 | "@types/node" 20 | ] 21 | }, 22 | "include": ["src"], 23 | "references": [{ "path": "./tsconfig.node.json" }] 24 | } 25 | -------------------------------------------------------------------------------- /demos/dev-demo/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 | -------------------------------------------------------------------------------- /demos/dev-demo/vite.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vite'; 2 | import react from '@vitejs/plugin-react'; 3 | import legacy from '@vitejs/plugin-legacy'; 4 | 5 | // https://vitejs.dev/config/ 6 | export default defineConfig({ 7 | plugins: [ 8 | react(), 9 | legacy({ 10 | targets: ['IE 11'], 11 | }), 12 | ], 13 | resolve: { 14 | alias: { 15 | eventemitter3: 'eventemitter3/umd/eventemitter3.js', 16 | }, 17 | }, 18 | server: { 19 | host: '0.0.0.0', 20 | port: 3003, 21 | https: false 22 | }, 23 | build: { 24 | minify: false, 25 | }, 26 | }); 27 | -------------------------------------------------------------------------------- /demos/react-ui/create-react-app/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /demos/react-ui/create-react-app/.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false -------------------------------------------------------------------------------- /demos/react-ui/create-react-app/README.md: -------------------------------------------------------------------------------- 1 | # Getting Started with Create React App 2 | 3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 4 | 5 | ## Available Scripts 6 | 7 | In the project directory, you can run: 8 | 9 | ### `npm start` 10 | 11 | Runs the app in the development mode.\ 12 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 13 | 14 | The page will reload if you make edits.\ 15 | You will also see any lint errors in the console. 16 | 17 | ### `npm test` 18 | 19 | Launches the test runner in the interactive watch mode.\ 20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 21 | 22 | ### `npm run build` 23 | 24 | Builds the app for production to the `build` folder.\ 25 | It correctly bundles React in production mode and optimizes the build for the best performance. 26 | 27 | The build is minified and the filenames include the hashes.\ 28 | Your app is ready to be deployed! 29 | 30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 31 | 32 | ### `npm run eject` 33 | 34 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 35 | 36 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 37 | 38 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. 39 | 40 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. 41 | 42 | ## Learn More 43 | 44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 45 | 46 | To learn React, check out the [React documentation](https://reactjs.org/). 47 | -------------------------------------------------------------------------------- /demos/react-ui/create-react-app/config-overrides.js: -------------------------------------------------------------------------------- 1 | const webpack = require('webpack'); 2 | 3 | module.exports = function override(config, env) { 4 | console.log('override'); 5 | let loaders = config.resolve; 6 | loaders.fallback = { 7 | 'fs': false, 8 | 'tls': false, 9 | 'net': false, 10 | 'querystring': require.resolve('querystring'), 11 | 'http': require.resolve('stream-http'), 12 | 'https': require.resolve('https-browserify'), 13 | 'zlib': require.resolve('browserify-zlib'), 14 | 'path': require.resolve('path-browserify'), 15 | 'stream': require.resolve('stream-browserify'), 16 | 'crypto': require.resolve('crypto-browserify') 17 | }; 18 | 19 | config.plugins.push( 20 | new webpack.ProvidePlugin({ 21 | process: 'process/browser', 22 | // Buffer: ['buffer', 'Buffer'] 23 | }) 24 | ); 25 | 26 | // config.stats = { ...config.stats, children: true }; 27 | 28 | // react-dnd 29 | config.module.rules.unshift({ 30 | test: /\.m?js$/, 31 | resolve: { 32 | fullySpecified: false // disable the behaviour 33 | } 34 | }); 35 | 36 | // // react-dnd 37 | // config.resolve.alias = { 38 | // ...config.resolve.alias, 39 | // 'react/jsx-runtime.js': 'react/jsx-runtime', 40 | // 'react/jsx-dev-runtime.js': 'react/jsx-dev-runtime' 41 | // }; 42 | 43 | return config; 44 | }; -------------------------------------------------------------------------------- /demos/react-ui/create-react-app/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tronprotocol/tronwallet-adapter/3b2bdf995a7c3d834a0e3bb5ec71565cd961b2b0/demos/react-ui/create-react-app/public/favicon.ico -------------------------------------------------------------------------------- /demos/react-ui/create-react-app/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 14 | 15 | 24 | React App 25 | 26 | 27 | 28 | 29 |
30 | 40 | 41 | -------------------------------------------------------------------------------- /demos/react-ui/create-react-app/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tronprotocol/tronwallet-adapter/3b2bdf995a7c3d834a0e3bb5ec71565cd961b2b0/demos/react-ui/create-react-app/public/logo192.png -------------------------------------------------------------------------------- /demos/react-ui/create-react-app/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tronprotocol/tronwallet-adapter/3b2bdf995a7c3d834a0e3bb5ec71565cd961b2b0/demos/react-ui/create-react-app/public/logo512.png -------------------------------------------------------------------------------- /demos/react-ui/create-react-app/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /demos/react-ui/create-react-app/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /demos/react-ui/create-react-app/src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | height: 40vmin; 7 | pointer-events: none; 8 | } 9 | 10 | @media (prefers-reduced-motion: no-preference) { 11 | .App-logo { 12 | animation: App-logo-spin infinite 20s linear; 13 | } 14 | } 15 | 16 | .App-header { 17 | background-color: #282c34; 18 | min-height: 100vh; 19 | display: flex; 20 | flex-direction: column; 21 | align-items: center; 22 | justify-content: center; 23 | font-size: calc(10px + 2vmin); 24 | color: white; 25 | } 26 | 27 | .App-link { 28 | color: #61dafb; 29 | } 30 | 31 | @keyframes App-logo-spin { 32 | from { 33 | transform: rotate(0deg); 34 | } 35 | to { 36 | transform: rotate(360deg); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /demos/react-ui/create-react-app/src/App.test.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { render, screen } from '@testing-library/react'; 3 | import { App } from './App'; 4 | 5 | test('renders learn react link', () => { 6 | render(); 7 | screen.getByText(/learn react/i); 8 | // expect(linkElement).toBeInTheDocument(); 9 | }); 10 | -------------------------------------------------------------------------------- /demos/react-ui/create-react-app/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | padding: 30px; 3 | margin: 0; 4 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 5 | 'Droid Sans', 'Helvetica Neue', sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', monospace; 12 | } 13 | -------------------------------------------------------------------------------- /demos/react-ui/create-react-app/src/index.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom/client'; 3 | import './index.css'; 4 | import '@tronweb3/tronwallet-adapter-react-ui/style.css'; 5 | import { App } from './App'; 6 | import reportWebVitals from './reportWebVitals'; 7 | import { Toaster } from 'react-hot-toast'; 8 | import { ThemeProvider } from '@mui/material/styles'; 9 | import theme from './theme'; 10 | import vConsole from 'vconsole' 11 | const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement); 12 | new vConsole(); 13 | root.render( 14 | 15 | 16 | 17 | 18 | 19 | 20 | ); 21 | 22 | // If you want to start measuring performance in your app, pass a function 23 | // to log results (for example: reportWebVitals(console.log)) 24 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals 25 | reportWebVitals(); 26 | -------------------------------------------------------------------------------- /demos/react-ui/create-react-app/src/react-app-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /demos/react-ui/create-react-app/src/reportWebVitals.ts: -------------------------------------------------------------------------------- 1 | import { ReportHandler } from 'web-vitals'; 2 | 3 | const reportWebVitals = (onPerfEntry?: ReportHandler) => { 4 | if (onPerfEntry && onPerfEntry instanceof Function) { 5 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { 6 | getCLS(onPerfEntry); 7 | getFID(onPerfEntry); 8 | getFCP(onPerfEntry); 9 | getLCP(onPerfEntry); 10 | getTTFB(onPerfEntry); 11 | }); 12 | } 13 | }; 14 | 15 | export default reportWebVitals; 16 | -------------------------------------------------------------------------------- /demos/react-ui/create-react-app/src/setupTests.ts: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom'; 6 | -------------------------------------------------------------------------------- /demos/react-ui/create-react-app/src/theme.ts: -------------------------------------------------------------------------------- 1 | import { createTheme } from '@mui/material/styles'; 2 | import { red } from '@mui/material/colors'; 3 | 4 | // Create a theme instance. 5 | const theme = createTheme({ 6 | palette: { 7 | primary: { 8 | main: '#556cd6', 9 | }, 10 | secondary: { 11 | main: '#19857b', 12 | }, 13 | error: { 14 | main: red.A400, 15 | }, 16 | }, 17 | }); 18 | 19 | export default theme; 20 | -------------------------------------------------------------------------------- /demos/react-ui/create-react-app/src/tronweb.ts: -------------------------------------------------------------------------------- 1 | // @ts-ignore 2 | import TronWeb from 'tronweb'; 3 | export const tronWeb: any = new TronWeb({ 4 | fullHost: 'https://api.nileex.io', 5 | }); 6 | (window as any).tronWeb1 = tronWeb; 7 | -------------------------------------------------------------------------------- /demos/react-ui/create-react-app/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": ["dom", "dom.iterable", "esnext"], 5 | "allowJs": true, 6 | "skipLibCheck": true, 7 | "esModuleInterop": true, 8 | "allowSyntheticDefaultImports": true, 9 | "strict": false, 10 | "forceConsistentCasingInFileNames": true, 11 | "noFallthroughCasesInSwitch": true, 12 | "module": "esnext", 13 | "moduleResolution": "node", 14 | "resolveJsonModule": true, 15 | "isolatedModules": true, 16 | "noEmit": true, 17 | "jsx": "react-jsx" 18 | }, 19 | "include": ["src"] 20 | } 21 | -------------------------------------------------------------------------------- /demos/react-ui/next-app/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "next/core-web-vitals" 3 | } 4 | -------------------------------------------------------------------------------- /demos/react-ui/next-app/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # next.js 12 | /.next/ 13 | /out/ 14 | 15 | # production 16 | /build 17 | 18 | # misc 19 | .DS_Store 20 | *.pem 21 | 22 | # debug 23 | npm-debug.log* 24 | yarn-debug.log* 25 | yarn-error.log* 26 | .pnpm-debug.log* 27 | 28 | # local env files 29 | .env*.local 30 | 31 | # vercel 32 | .vercel 33 | 34 | # typescript 35 | *.tsbuildinfo 36 | next-env.d.ts 37 | -------------------------------------------------------------------------------- /demos/react-ui/next-app/.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false -------------------------------------------------------------------------------- /demos/react-ui/next-app/README.md: -------------------------------------------------------------------------------- 1 | This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app). 2 | 3 | ## Getting Started 4 | 5 | First, run the development server: 6 | 7 | ```bash 8 | npm run dev 9 | # or 10 | yarn dev 11 | ``` 12 | 13 | Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. 14 | 15 | You can start editing the page by modifying `pages/index.tsx`. The page auto-updates as you edit the file. 16 | 17 | [API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.ts`. 18 | 19 | The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages. 20 | 21 | ## Learn More 22 | 23 | To learn more about Next.js, take a look at the following resources: 24 | 25 | - [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API. 26 | - [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial. 27 | 28 | You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome! 29 | 30 | ## Deploy on Vercel 31 | 32 | The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js. 33 | 34 | Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details. 35 | -------------------------------------------------------------------------------- /demos/react-ui/next-app/next.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('next').NextConfig} */ 2 | const nextConfig = { 3 | reactStrictMode: true, 4 | swcMinify: true, 5 | } 6 | 7 | module.exports = nextConfig 8 | -------------------------------------------------------------------------------- /demos/react-ui/next-app/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-ui-next-app", 3 | "version": "1.0.0", 4 | "private": true, 5 | "scripts": { 6 | "dev": "PORT=5002 next dev", 7 | "build": "next build", 8 | "start": "PORT=5002 next start", 9 | "lint": "next lint" 10 | }, 11 | "dependencies": { 12 | "@emotion/react": "^11.10.4", 13 | "@emotion/styled": "^11.10.4", 14 | "@mui/material": "^5.10.10", 15 | "@tronweb3/tronwallet-abstract-adapter": "^1.1.0", 16 | "@tronweb3/tronwallet-adapter-bitkeep": "^1.0.0", 17 | "@tronweb3/tronwallet-adapter-ledger": "^1.1.1", 18 | "@tronweb3/tronwallet-adapter-react-hooks": "^1.0.0", 19 | "@tronweb3/tronwallet-adapter-react-ui": "^1.1.0", 20 | "@tronweb3/tronwallet-adapter-tokenpocket": "^1.0.0", 21 | "@tronweb3/tronwallet-adapters": "^1.1.1", 22 | "@types/node": "18.11.9", 23 | "eslint": "^8.23.1", 24 | "eslint-config-next": "13.0.5", 25 | "next": "14.2.3", 26 | "react": "^18.2.0", 27 | "react-dom": "^18.2.0", 28 | "react-hot-toast": "^2.4.0", 29 | "tronweb": "^4.4.0", 30 | "tslib": "^2.5.0", 31 | "typescript": "4.9.3" 32 | }, 33 | "devDependencies": { 34 | "@types/react": "18.0.26", 35 | "@types/react-dom": "^18.0.6", 36 | "lokijs": "^1.5.12", 37 | "pino-pretty": "^10.0.0", 38 | "typescript": "^4.6.4" 39 | }, 40 | "overrides": { 41 | "@types/react": "18.0.26", 42 | "@ledgerhq/errors": "6.10.0", 43 | "@ledgerhq/devices": "6.27.1", 44 | "@ledgerhq/hw-transport": "6.27.1", 45 | "@ledgerhq/hw-transport-webhid": "6.27.1" 46 | }, 47 | "resolutions": { 48 | "@types/react": "18.0.26", 49 | "@ledgerhq/errors": "6.10.0", 50 | "@ledgerhq/devices": "6.27.1", 51 | "@ledgerhq/hw-transport": "6.27.1", 52 | "@ledgerhq/hw-transport-webhid": "6.27.1" 53 | } 54 | } -------------------------------------------------------------------------------- /demos/react-ui/next-app/pages/api/hello.ts: -------------------------------------------------------------------------------- 1 | // Next.js API route support: https://nextjs.org/docs/api-routes/introduction 2 | import type { NextApiRequest, NextApiResponse } from 'next'; 3 | 4 | type Data = { 5 | name: string; 6 | }; 7 | 8 | export default function handler(req: NextApiRequest, res: NextApiResponse) { 9 | res.status(200).json({ name: 'John Doe' }); 10 | } 11 | -------------------------------------------------------------------------------- /demos/react-ui/next-app/pages/api/tronweb.ts: -------------------------------------------------------------------------------- 1 | // @ts-ignore 2 | import TronWeb from 'tronweb'; 3 | export const tronWeb: any = new TronWeb({ 4 | fullHost: 'https://api.nileex.io', 5 | }); 6 | if (typeof window !== 'undefined') { 7 | (window as any).tronWeb1 = tronWeb; 8 | } 9 | -------------------------------------------------------------------------------- /demos/react-ui/next-app/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tronprotocol/tronwallet-adapter/3b2bdf995a7c3d834a0e3bb5ec71565cd961b2b0/demos/react-ui/next-app/public/favicon.ico -------------------------------------------------------------------------------- /demos/react-ui/next-app/public/vercel.svg: -------------------------------------------------------------------------------- 1 | 3 | 4 | -------------------------------------------------------------------------------- /demos/react-ui/next-app/styles/globals.css: -------------------------------------------------------------------------------- 1 | html, 2 | body { 3 | padding: 0; 4 | margin: 0; 5 | font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, Ubuntu, Cantarell, Fira Sans, Droid Sans, 6 | Helvetica Neue, sans-serif; 7 | } 8 | 9 | body { 10 | padding: 30px; 11 | } 12 | 13 | a { 14 | color: inherit; 15 | text-decoration: none; 16 | } 17 | 18 | * { 19 | box-sizing: border-box; 20 | } 21 | 22 | -------------------------------------------------------------------------------- /demos/react-ui/next-app/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": ["dom", "dom.iterable", "esnext"], 5 | "allowJs": true, 6 | "skipLibCheck": true, 7 | "strict": true, 8 | "forceConsistentCasingInFileNames": true, 9 | "noEmit": true, 10 | "esModuleInterop": true, 11 | "module": "esnext", 12 | "moduleResolution": "node", 13 | "resolveJsonModule": true, 14 | "isolatedModules": true, 15 | "jsx": "preserve", 16 | "incremental": true 17 | }, 18 | "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"], 19 | "exclude": ["node_modules"] 20 | } 21 | -------------------------------------------------------------------------------- /demos/react-ui/vite-app/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | pnpm-debug.log* 8 | lerna-debug.log* 9 | 10 | node_modules 11 | dist 12 | dist-ssr 13 | *.local 14 | 15 | # Editor directories and files 16 | .vscode/* 17 | !.vscode/extensions.json 18 | .idea 19 | .DS_Store 20 | *.suo 21 | *.ntvs* 22 | *.njsproj 23 | *.sln 24 | *.sw? 25 | -------------------------------------------------------------------------------- /demos/react-ui/vite-app/.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false -------------------------------------------------------------------------------- /demos/react-ui/vite-app/README.md: -------------------------------------------------------------------------------- 1 | # adapter-demo-react 2 | 3 | This is the demo of `@tronweb3/tronwallet-adapter-react-ui`. Please refer the introduction [here](https://github.com/tronprotocol/tronwallet-adapter/blob/main/packages/react/react-ui/README.md). 4 | 5 | ## Start 6 | 7 | ```bash 8 | pnpm install 9 | pnpm dev 10 | ``` 11 | -------------------------------------------------------------------------------- /demos/react-ui/vite-app/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Vite + React + TS 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /demos/react-ui/vite-app/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-ui-vite", 3 | "private": true, 4 | "version": "0.0.1", 5 | "type": "module", 6 | "scripts": { 7 | "dev": "vite", 8 | "start": "vite", 9 | "build": "tsc && vite build", 10 | "preview": "vite preview" 11 | }, 12 | "dependencies": { 13 | "@emotion/react": "^11.10.4", 14 | "@emotion/styled": "^11.10.4", 15 | "@mui/material": "^5.10.10", 16 | "@tronweb3/tronwallet-abstract-adapter": "^1.1.0", 17 | "@tronweb3/tronwallet-adapter-ledger": "^1.1.1", 18 | "@tronweb3/tronwallet-adapter-react-hooks": "^1.0.0", 19 | "@tronweb3/tronwallet-adapter-react-ui": "^1.1.0", 20 | "@tronweb3/tronwallet-adapter-tronlink": "^1.1.9", 21 | "@tronweb3/tronwallet-adapter-walletconnect": "^1.0.0", 22 | "@tronweb3/tronwallet-adapters": "^1.1.1", 23 | "buffer": "^6.0.3", 24 | "events": "^3.3.0", 25 | "react": "^18.2.0", 26 | "react-dom": "^18.2.0", 27 | "react-hot-toast": "^2.4.0", 28 | "tronweb": "^4.4.0", 29 | "vconsole": "^3.15.0" 30 | }, 31 | "devDependencies": { 32 | "@types/react": "^18.0.26", 33 | "@types/react-dom": "^18.0.6", 34 | "@vitejs/plugin-legacy": "^5.4.1", 35 | "@vitejs/plugin-react": "^4.3.1", 36 | "rollup-plugin-polyfill-node": "^0.11.0", 37 | "typescript": "^4.6.4", 38 | "vite": "^5.2.11" 39 | }, 40 | "overrides": { 41 | "@ledgerhq/errors": "6.10.0", 42 | "@ledgerhq/devices": "6.27.1", 43 | "@ledgerhq/hw-transport": "6.27.1", 44 | "@ledgerhq/hw-transport-webhid": "6.27.1" 45 | }, 46 | "resolutions": { 47 | "@ledgerhq/errors": "6.10.0", 48 | "@ledgerhq/devices": "6.27.1", 49 | "@ledgerhq/hw-transport": "6.27.1", 50 | "@ledgerhq/hw-transport-webhid": "6.27.1" 51 | } 52 | } -------------------------------------------------------------------------------- /demos/react-ui/vite-app/public/vite.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /demos/react-ui/vite-app/src/index.css: -------------------------------------------------------------------------------- 1 | #root { 2 | max-width: 1280px; 3 | margin: 0 auto; 4 | text-align: left; 5 | width: 100%; 6 | overflow: auto; 7 | } 8 | :root { 9 | font-family: Inter, Avenir, Helvetica, Arial, sans-serif; 10 | font-size: 16px; 11 | line-height: 24px; 12 | font-weight: 400; 13 | 14 | color-scheme: light; 15 | color: rgba(255, 255, 255, 0.87); 16 | background-color: #242424; 17 | 18 | font-synthesis: none; 19 | text-rendering: optimizeLegibility; 20 | -webkit-font-smoothing: antialiased; 21 | -moz-osx-font-smoothing: grayscale; 22 | -webkit-text-size-adjust: 100%; 23 | } 24 | 25 | a { 26 | font-weight: 500; 27 | color: #646cff; 28 | text-decoration: inherit; 29 | } 30 | a:hover { 31 | color: #535bf2; 32 | } 33 | 34 | body { 35 | padding: 10px; 36 | margin: 0; 37 | display: flex; 38 | min-width: 320px; 39 | min-height: 100vh; 40 | } 41 | 42 | h2 { 43 | margin: 30px 0 10px; 44 | } 45 | 46 | button { 47 | border-radius: 8px; 48 | border: 1px solid transparent; 49 | padding: 0.6em 1.2em; 50 | font-size: 1em; 51 | font-weight: 500; 52 | font-family: inherit; 53 | background-color: #1a1a1a; 54 | cursor: pointer; 55 | transition: border-color 0.25s; 56 | } 57 | button:hover { 58 | border-color: #646cff; 59 | } 60 | button:focus, 61 | button:focus-visible { 62 | outline: 4px auto -webkit-focus-ring-color; 63 | } 64 | 65 | p { 66 | display: flex; 67 | font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; 68 | word-break: break-all; 69 | margin: 10px 0 ; 70 | } 71 | p span:first-of-type { 72 | width: 160px; 73 | } 74 | 75 | :root { 76 | color: #213547; 77 | background-color: #ffffff; 78 | } 79 | a:hover { 80 | color: #747bff; 81 | } 82 | button { 83 | background-color: #f9f9f9; 84 | } 85 | 86 | @media screen and (max-width: 800px) { 87 | p { 88 | display: flex; 89 | flex-direction: column; 90 | } 91 | .adapter-react-button { 92 | font-size: 14px; 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /demos/react-ui/vite-app/src/main.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | import { useWallet } from '@tronweb3/tronwallet-adapter-react-hooks'; 3 | import ReactDOM from 'react-dom/client'; 4 | import '@tronweb3/tronwallet-adapter-react-ui/style.css'; 5 | import './index.css'; 6 | import { Toaster } from 'react-hot-toast'; 7 | import { App } from './App'; 8 | import { ThemeProvider } from '@mui/material/styles'; 9 | import theme from './theme'; 10 | import vConsole from 'vconsole' 11 | new vConsole(); 12 | 13 | ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render( 14 | 15 | 16 | 17 | 18 | 19 | 20 | ); 21 | -------------------------------------------------------------------------------- /demos/react-ui/vite-app/src/theme.ts: -------------------------------------------------------------------------------- 1 | import { createTheme } from '@mui/material/styles'; 2 | import { red } from '@mui/material/colors'; 3 | 4 | // Create a theme instance. 5 | const theme = createTheme({ 6 | palette: { 7 | primary: { 8 | main: '#556cd6', 9 | }, 10 | secondary: { 11 | main: '#19857b', 12 | }, 13 | error: { 14 | main: red.A400, 15 | }, 16 | }, 17 | }); 18 | 19 | export default theme; 20 | -------------------------------------------------------------------------------- /demos/react-ui/vite-app/src/tronweb.ts: -------------------------------------------------------------------------------- 1 | // @ts-ignore 2 | import TronWeb from 'tronweb'; 3 | 4 | export const tronWeb: any = new TronWeb({ 5 | fullHost: 'https://api.nileex.io', 6 | }); 7 | (window as any).tronWeb1 = tronWeb; 8 | 9 | -------------------------------------------------------------------------------- /demos/react-ui/vite-app/src/vite-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /demos/react-ui/vite-app/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ESNext", 4 | "useDefineForClassFields": true, 5 | "lib": ["DOM", "DOM.Iterable", "ESNext"], 6 | "allowJs": false, 7 | "skipLibCheck": true, 8 | "esModuleInterop": false, 9 | "allowSyntheticDefaultImports": true, 10 | "strict": true, 11 | "forceConsistentCasingInFileNames": true, 12 | "module": "ESNext", 13 | "moduleResolution": "Node", 14 | "resolveJsonModule": true, 15 | "isolatedModules": true, 16 | "noEmit": true, 17 | "jsx": "react-jsx" 18 | }, 19 | "include": ["src"], 20 | "references": [{ "path": "./tsconfig.node.json" }] 21 | } 22 | -------------------------------------------------------------------------------- /demos/react-ui/vite-app/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 | -------------------------------------------------------------------------------- /demos/react-ui/vite-app/vite.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vite'; 2 | import react from '@vitejs/plugin-react'; 3 | import legacy from '@vitejs/plugin-legacy'; 4 | 5 | // https://vitejs.dev/config/ 6 | export default defineConfig({ 7 | plugins: [ 8 | react(), 9 | legacy({ 10 | targets: ['>0.3%', 'defaults'], 11 | }), 12 | ], 13 | define: { 14 | global: 'window', 15 | }, 16 | resolve: { 17 | alias: { 18 | eventemitter3: 'eventemitter3/umd/eventemitter3.js', 19 | }, 20 | }, 21 | build: { 22 | // Set false to speed up build process, should change to `true` for production mode. 23 | minify: false, 24 | }, 25 | optimizeDeps: { 26 | // Clear the array to optimize the dependencies 27 | exclude: [ 28 | '@tronweb3/tronwallet-adapters', 29 | '@tronweb3/tronwallet-adapter-tronlink', 30 | '@tronweb3/tronwallet-abstract-adapter', 31 | ], 32 | }, 33 | server: { 34 | host: '0.0.0.0', 35 | port: 5003, 36 | }, 37 | }); 38 | -------------------------------------------------------------------------------- /demos/vue-ui/vite-app/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | pnpm-debug.log* 8 | lerna-debug.log* 9 | 10 | node_modules 11 | dist 12 | dist-ssr 13 | *.local 14 | 15 | # Editor directories and files 16 | .vscode/* 17 | !.vscode/extensions.json 18 | .idea 19 | .DS_Store 20 | *.suo 21 | *.ntvs* 22 | *.njsproj 23 | *.sln 24 | *.sw? 25 | -------------------------------------------------------------------------------- /demos/vue-ui/vite-app/README.md: -------------------------------------------------------------------------------- 1 | # Vue 3 + TypeScript + Vite 2 | 3 | This template should help get you started developing with Vue 3 and TypeScript in Vite. The template uses Vue 3 ` 12 | 13 | 14 | -------------------------------------------------------------------------------- /demos/vue-ui/vite-app/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vite-app", 3 | "private": true, 4 | "version": "0.0.0", 5 | "type": "module", 6 | "scripts": { 7 | "dev": "vite", 8 | "build": "vue-tsc && vite build", 9 | "preview": "vite preview" 10 | }, 11 | "dependencies": { 12 | "@noble/secp256k1": "^2.0.0", 13 | "@tronweb3/tronwallet-abstract-adapter": "^1.1.6", 14 | "@tronweb3/tronwallet-adapter-tronlink": "^1.1.9", 15 | "@tronweb3/tronwallet-adapter-vue-hooks": "^1.0.0", 16 | "@tronweb3/tronwallet-adapter-vue-ui": "^1.0.0", 17 | "@tronweb3/tronwallet-adapters": "^1.2.0", 18 | "element-plus": "^2.4.3", 19 | "tronweb": "5.0.0", 20 | "vue": "^3.3.8" 21 | }, 22 | "devDependencies": { 23 | "@vitejs/plugin-vue": "^4.5.0", 24 | "typescript": "^5.2.2", 25 | "vite": "^5.0.0", 26 | "vue-tsc": "^1.8.22" 27 | }, 28 | "overrides": { 29 | "@ledgerhq/errors": "6.10.0", 30 | "@ledgerhq/devices": "6.27.1", 31 | "@ledgerhq/hw-transport": "6.27.1", 32 | "@ledgerhq/hw-transport-webhid": "6.27.1" 33 | }, 34 | "resolutions": { 35 | "@ledgerhq/errors": "6.10.0", 36 | "@ledgerhq/devices": "6.27.1", 37 | "@ledgerhq/hw-transport": "6.27.1", 38 | "@ledgerhq/hw-transport-webhid": "6.27.1" 39 | } 40 | } -------------------------------------------------------------------------------- /demos/vue-ui/vite-app/public/vite.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /demos/vue-ui/vite-app/src/assets/vue.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /demos/vue-ui/vite-app/src/components/HooksDemo.vue: -------------------------------------------------------------------------------- 1 | 36 | 37 | 50 | 51 | 57 | -------------------------------------------------------------------------------- /demos/vue-ui/vite-app/src/components/VueUiDemo.vue: -------------------------------------------------------------------------------- 1 | 22 | 23 | 35 | · 36 | -------------------------------------------------------------------------------- /demos/vue-ui/vite-app/src/main.ts: -------------------------------------------------------------------------------- 1 | import { createApp } from 'vue'; 2 | import './style.css'; 3 | import App from './App.vue'; 4 | import 'element-plus/dist/index.css'; 5 | import '@tronweb3/tronwallet-adapter-vue-ui/style.css'; 6 | 7 | createApp(App).mount('#app'); 8 | -------------------------------------------------------------------------------- /demos/vue-ui/vite-app/src/style.css: -------------------------------------------------------------------------------- 1 | :root { 2 | font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif; 3 | line-height: 1.5; 4 | font-weight: 400; 5 | 6 | /* color-scheme: light dark; */ 7 | color: rgba(255, 255, 255, 0.87); 8 | /* background-color: #242424; */ 9 | 10 | font-synthesis: none; 11 | text-rendering: optimizeLegibility; 12 | -webkit-font-smoothing: antialiased; 13 | -moz-osx-font-smoothing: grayscale; 14 | } 15 | 16 | a { 17 | font-weight: 500; 18 | color: #646cff; 19 | text-decoration: inherit; 20 | } 21 | a:hover { 22 | color: #535bf2; 23 | } 24 | 25 | body { 26 | margin: 0; 27 | display: flex; 28 | place-items: center; 29 | min-width: 320px; 30 | min-height: 100vh; 31 | } 32 | 33 | h1 { 34 | font-size: 3.2em; 35 | line-height: 1.1; 36 | } 37 | 38 | button { 39 | border-radius: 8px; 40 | border: 1px solid transparent; 41 | padding: 0.6em 1.2em; 42 | font-size: 1em; 43 | font-weight: 500; 44 | font-family: inherit; 45 | background-color: #1a1a1a; 46 | cursor: pointer; 47 | transition: border-color 0.25s; 48 | } 49 | button:hover { 50 | border-color: #646cff; 51 | } 52 | button:focus, 53 | button:focus-visible { 54 | outline: 4px auto -webkit-focus-ring-color; 55 | } 56 | 57 | .card { 58 | padding: 2em; 59 | } 60 | 61 | #app { 62 | max-width: 1280px; 63 | margin: 0 auto; 64 | padding: 2rem; 65 | text-align: center; 66 | } 67 | 68 | 69 | -------------------------------------------------------------------------------- /demos/vue-ui/vite-app/src/tronweb.ts: -------------------------------------------------------------------------------- 1 | // @ts-ignore 2 | import TronWeb from 'tronweb'; 3 | 4 | export const tronWeb: any = new TronWeb({ 5 | fullHost: 'https://api.nileex.io', 6 | // fullHost: 'https://api.trongrid.io' 7 | }); 8 | (window as any).tronWeb1 = tronWeb; 9 | -------------------------------------------------------------------------------- /demos/vue-ui/vite-app/src/vite-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /demos/vue-ui/vite-app/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES2020", 4 | "useDefineForClassFields": true, 5 | "module": "ESNext", 6 | "lib": ["ES2020", "DOM", "DOM.Iterable"], 7 | "skipLibCheck": true, 8 | 9 | /* Bundler mode */ 10 | "moduleResolution": "Node", 11 | "resolveJsonModule": true, 12 | "isolatedModules": true, 13 | "noEmit": true, 14 | "jsx": "preserve", 15 | 16 | /* Linting */ 17 | "strict": true, 18 | "noUnusedLocals": true, 19 | "noUnusedParameters": true, 20 | "noFallthroughCasesInSwitch": true 21 | }, 22 | "include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue"], 23 | "references": [{ "path": "./tsconfig.node.json" }] 24 | } 25 | -------------------------------------------------------------------------------- /demos/vue-ui/vite-app/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 | -------------------------------------------------------------------------------- /demos/vue-ui/vite-app/vite.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vite' 2 | import vue from '@vitejs/plugin-vue' 3 | 4 | // https://vitejs.dev/config/ 5 | export default defineConfig({ 6 | plugins: [vue()], 7 | server: { 8 | host: "0.0.0.0", 9 | // https: true, 10 | port: 5003, 11 | } 12 | }) 13 | -------------------------------------------------------------------------------- /docs/action-button.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tronprotocol/tronwallet-adapter/3b2bdf995a7c3d834a0e3bb5ec71565cd961b2b0/docs/action-button.gif -------------------------------------------------------------------------------- /packages/adapters/abstract-adapter-evm/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright (c) 2022-Present, tronprotocol 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | -------------------------------------------------------------------------------- /packages/adapters/abstract-adapter-evm/jest.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('ts-jest').JestConfigWithTsJest} */ 2 | export default { 3 | preset: 'ts-jest', 4 | testEnvironment: 'jsdom', 5 | transform: { 6 | '\\.tsx?$': [ 7 | 'ts-jest', 8 | { 9 | useESM: true, 10 | }, 11 | ], 12 | }, 13 | moduleNameMapper: { 14 | '(.+)\\.js': '$1', 15 | }, 16 | extensionsToTreatAsEsm: ['.ts'], 17 | }; 18 | -------------------------------------------------------------------------------- /packages/adapters/abstract-adapter-evm/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@tronweb3/abstract-adapter-evm", 3 | "version": "1.0.1", 4 | "description": "Abstract interface definition of Evm Wallet Adapters.", 5 | "author": "tronprotocol", 6 | "repository": { 7 | "type": "git", 8 | "url": "https://github.com/tronprotocol/tronwallet-adapter" 9 | }, 10 | "license": "MIT", 11 | "type": "module", 12 | "sideEffects": false, 13 | "engines": { 14 | "node": ">=16", 15 | "pnpm": ">=7" 16 | }, 17 | "main": "./lib/cjs/index.js", 18 | "module": "./lib/esm/index.js", 19 | "types": "./lib/types/index.d.ts", 20 | "exports": { 21 | "require": "./lib/cjs/index.js", 22 | "import": "./lib/esm/index.js", 23 | "types": "./lib/types/index.d.ts" 24 | }, 25 | "files": [ 26 | "lib", 27 | "src", 28 | "LICENSE" 29 | ], 30 | "publishConfig": { 31 | "access": "public" 32 | }, 33 | "scripts": { 34 | "clean": "shx mkdir -p lib && shx rm -rf lib", 35 | "package": "shx echo '{ \"type\": \"commonjs\" }' > lib/cjs/package.json", 36 | "test": "jest", 37 | "test:coverage": "jest --coverage", 38 | "build:umd": "node ../../../scripts/build-umd.js" 39 | }, 40 | "dependencies": { 41 | "eventemitter3": "^4.0.0", 42 | "jest": "^29.6.2", 43 | "jest-environment-jsdom": "^29.6.2" 44 | }, 45 | "devDependencies": { 46 | "shx": "^0.3.4", 47 | "tronweb": "^4.4.0" 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /packages/adapters/abstract-adapter-evm/src/eip1193-provider.ts: -------------------------------------------------------------------------------- 1 | export interface RequestArguments { 2 | readonly method: string; 3 | readonly params?: readonly unknown[] | object; 4 | } 5 | 6 | export interface ProviderRpcError extends Error { 7 | code: number; 8 | data?: unknown; 9 | } 10 | 11 | export interface ProviderMessage { 12 | readonly type: string; 13 | readonly data: unknown; 14 | } 15 | 16 | export interface ProviderConnectInfo { 17 | readonly chainId: string; 18 | } 19 | export interface ProviderEvents { 20 | /** 21 | * Emitted when wallet is connected to RPC server. 22 | */ 23 | connect(connectInfo: ProviderConnectInfo): void; 24 | /** 25 | * Emitted when wallet is disconnected from RPC server. 26 | */ 27 | disconnect(error: ProviderRpcError): void; 28 | /** 29 | * Emitted when wallet is disconnected from RPC server. 30 | */ 31 | accountsChanged(accounts: string[]): void; 32 | /** 33 | * Emitted when the currently connected chain changes. 34 | */ 35 | chainChanged(chainId: string): void; 36 | } 37 | 38 | export interface EIP1193Provider { 39 | on(event: TEvent, listener: ProviderEvents[TEvent]): this; 40 | removeListener(event: TEvent, listener: ProviderEvents[TEvent]): this; 41 | removeAllListeners(event?: string | symbol): this; 42 | request

(params: { method: string; params?: P }): Promise; 43 | 44 | /** Used to identity wallet */ 45 | isMetaMask: boolean; 46 | } 47 | -------------------------------------------------------------------------------- /packages/adapters/abstract-adapter-evm/src/errors.ts: -------------------------------------------------------------------------------- 1 | export class WalletError extends Error { 2 | error: any; 3 | 4 | constructor(message?: string, error?: any) { 5 | super(message); 6 | this.error = error; 7 | } 8 | } 9 | 10 | /** 11 | * Occurs when wallet is not installed. 12 | */ 13 | export class WalletNotFoundError extends WalletError { 14 | name = 'WalletNotFoundError'; 15 | message = 'The wallet is not found.'; 16 | } 17 | 18 | /** 19 | * Occurs when try to sign but is not connected to wallet. 20 | */ 21 | export class WalletDisconnectedError extends WalletError { 22 | name = 'WalletDisconnectedError'; 23 | message = 'The wallet is disconnected. Please connect the wallet first.'; 24 | } 25 | 26 | /** 27 | * Occurs when try to connect a wallet. 28 | */ 29 | export class WalletConnectionError extends WalletError { 30 | name = 'WalletConnectionError'; 31 | } 32 | -------------------------------------------------------------------------------- /packages/adapters/abstract-adapter-evm/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './adapter.js'; 2 | export * from './errors.js'; 3 | export * from './utils.js'; 4 | export * from './eip1193-provider.js'; 5 | -------------------------------------------------------------------------------- /packages/adapters/abstract-adapter-evm/src/utils.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * check simply if current environment is browser or not 3 | * @returns boolean 4 | */ 5 | export function isInBrowser() { 6 | return typeof window !== 'undefined' && typeof document !== 'undefined' && typeof navigator !== 'undefined'; 7 | } 8 | 9 | /** 10 | * Simplily detect mobile device 11 | */ 12 | export function isInMobileBrowser() { 13 | return ( 14 | typeof navigator !== 'undefined' && 15 | !!navigator.userAgent.match(/Android|webOS|iPhone|iPad|iPod|BlackBerry|Windows Phone/i) 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /packages/adapters/abstract-adapter-evm/tests/units/errors.test.ts: -------------------------------------------------------------------------------- 1 | import { WalletConnectionError, WalletDisconnectedError, WalletNotFoundError } from '../../src/errors.js'; 2 | 3 | describe('errors', () => { 4 | test('WalletError should be exported', () => { 5 | expect(WalletNotFoundError).toBeDefined(); 6 | expect(WalletDisconnectedError).toBeDefined(); 7 | expect(WalletConnectionError).toBeDefined(); 8 | }); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/adapters/abstract-adapter-evm/tests/units/utils.test.ts: -------------------------------------------------------------------------------- 1 | import { isInBrowser, isInMobileBrowser } from '../../src/utils.js'; 2 | 3 | describe('utils', () => { 4 | test('utils function should be exported', () => { 5 | expect(isInBrowser).toBeDefined(); 6 | expect(isInMobileBrowser).toBeDefined(); 7 | }); 8 | }); 9 | -------------------------------------------------------------------------------- /packages/adapters/abstract-adapter-evm/tsconfig.all.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../tsconfig.root.json", 3 | "references": [ 4 | { 5 | "path": "./tsconfig.cjs.json" 6 | }, 7 | { 8 | "path": "./tsconfig.esm.json" 9 | } 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /packages/adapters/abstract-adapter-evm/tsconfig.cjs.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../tsconfig.cjs.json", 3 | "include": ["src"], 4 | "compilerOptions": { 5 | "outDir": "lib/cjs" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /packages/adapters/abstract-adapter-evm/tsconfig.esm.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../tsconfig.esm.json", 3 | "include": ["src"], 4 | "compilerOptions": { 5 | "outDir": "lib/esm", 6 | "declarationDir": "lib/types" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /packages/adapters/abstract-adapter/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright (c) 2022-Present, tronprotocol 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | -------------------------------------------------------------------------------- /packages/adapters/abstract-adapter/README.md: -------------------------------------------------------------------------------- 1 | # `@tronweb3/tronwallet-abstract-adapter` 2 | 3 | This is the abstract interface definition of Tron Wallet Adapters. All wallet adapters implement abstract interface to provide unified interface. Please refer to the introduction [here](https://github.com/tronprotocol/tronwallet-adapter/blob/main/packages/adapters/adapters/README.md) for detailed properties and methods. 4 | -------------------------------------------------------------------------------- /packages/adapters/abstract-adapter/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@tronweb3/tronwallet-abstract-adapter", 3 | "version": "1.1.6", 4 | "description": "Abstract interface definition of Tron Wallet Adapters.", 5 | "author": "tronprotocol", 6 | "repository": { 7 | "type": "git", 8 | "url": "https://github.com/tronprotocol/tronwallet-adapter" 9 | }, 10 | "license": "MIT", 11 | "type": "module", 12 | "sideEffects": false, 13 | "engines": { 14 | "node": ">=16", 15 | "pnpm": ">=7" 16 | }, 17 | "main": "./lib/cjs/index.js", 18 | "module": "./lib/esm/index.js", 19 | "types": "./lib/types/index.d.ts", 20 | "exports": { 21 | "require": "./lib/cjs/index.js", 22 | "import": "./lib/esm/index.js", 23 | "types": "./lib/types/index.d.ts" 24 | }, 25 | "files": [ 26 | "lib", 27 | "src", 28 | "LICENSE" 29 | ], 30 | "publishConfig": { 31 | "access": "public" 32 | }, 33 | "scripts": { 34 | "clean": "shx mkdir -p lib && shx rm -rf lib", 35 | "package": "shx echo '{ \"type\": \"commonjs\" }' > lib/cjs/package.json", 36 | "build:umd": "node ../../../scripts/build-umd.js" 37 | }, 38 | "dependencies": { 39 | "eventemitter3": "^4.0.0" 40 | }, 41 | "devDependencies": { 42 | "shx": "^0.3.4", 43 | "tronweb": "^4.4.0" 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /packages/adapters/abstract-adapter/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './adapter.js'; 2 | export * from './errors.js'; 3 | export * from './types.js'; 4 | export * from './utils.js'; 5 | -------------------------------------------------------------------------------- /packages/adapters/abstract-adapter/src/types.ts: -------------------------------------------------------------------------------- 1 | export enum NetworkType { 2 | Mainnet = 'Mainnet', 3 | Shasta = 'Shasta', 4 | Nile = 'Nile', 5 | /** 6 | * When use custom node 7 | */ 8 | Unknown = 'Unknown', 9 | } 10 | 11 | export enum ChainNetwork { 12 | Mainnet = 'Mainnet', 13 | Shasta = 'Shasta', 14 | Nile = 'Nile', 15 | } 16 | 17 | export type Network = { 18 | networkType: NetworkType; 19 | chainId: string; 20 | fullNode: string; 21 | solidityNode: string; 22 | eventServer: string; 23 | }; 24 | /** 25 | * @deprecated Use Network instead. 26 | */ 27 | export type NetworkNodeConfig = { 28 | chainId: string; 29 | chain: string; 30 | fullNode: string; 31 | solidityNode: string; 32 | eventServer: string; 33 | }; 34 | // types should be defined in @tronweb3/web3.js, such as tronweb 35 | // as no ts in tronweb 36 | // just defined here 37 | export type Contract = { 38 | parameter: { 39 | type_url: string; 40 | value: Record; 41 | }; 42 | type: string; 43 | }; 44 | 45 | export type Transaction = { 46 | visible: boolean; 47 | txID: string; 48 | raw_data: { 49 | contract: Contract[]; 50 | ref_block_bytes: string; 51 | ref_block_hash: string; 52 | expiration: number; 53 | fee_limit: number; 54 | timestamp: number; 55 | }; 56 | raw_data_hex: string; 57 | signature?: string[]; 58 | [key: string]: unknown; 59 | }; 60 | 61 | export type SignedTransaction = Transaction & { signature: string[] }; 62 | -------------------------------------------------------------------------------- /packages/adapters/abstract-adapter/src/utils.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * check simply if current environment is browser or not 3 | * @returns boolean 4 | */ 5 | export function isInBrowser() { 6 | return typeof window !== 'undefined' && typeof document !== 'undefined' && typeof navigator !== 'undefined'; 7 | } 8 | 9 | /** 10 | * 11 | * @param {Function} check funcion to check if wallet is installed. return true if wallet is detected. 12 | * @returns 13 | */ 14 | export function checkAdapterState(check: () => boolean): void { 15 | if (!isInBrowser()) return; 16 | 17 | const disposers: (() => void)[] = []; 18 | 19 | function dispose() { 20 | for (const dispose of disposers) { 21 | dispose(); 22 | } 23 | } 24 | function checkAndDispose() { 25 | if (check()) { 26 | dispose(); 27 | } 28 | } 29 | 30 | const interval = setInterval(checkAndDispose, 500); 31 | disposers.push(() => clearInterval(interval)); 32 | 33 | if (document.readyState === 'loading') { 34 | document.addEventListener('DOMContentLoaded', checkAndDispose, { once: true }); 35 | disposers.push(() => document.removeEventListener('DOMContentLoaded', checkAndDispose)); 36 | } 37 | 38 | if (document.readyState !== 'complete') { 39 | window.addEventListener('load', checkAndDispose, { once: true }); 40 | disposers.push(() => window.removeEventListener('load', checkAndDispose)); 41 | } 42 | checkAndDispose(); 43 | // stop all task after 1min 44 | setTimeout(dispose, 60 * 1000); 45 | } 46 | 47 | /** 48 | * Simplily detect mobile device 49 | */ 50 | export function isInMobileBrowser() { 51 | return ( 52 | typeof navigator !== 'undefined' && 53 | navigator.userAgent.match(/Android|webOS|iPhone|iPad|iPod|BlackBerry|Windows Phone/i) 54 | ); 55 | } 56 | -------------------------------------------------------------------------------- /packages/adapters/abstract-adapter/tsconfig.all.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../tsconfig.root.json", 3 | "references": [ 4 | { 5 | "path": "./tsconfig.cjs.json" 6 | }, 7 | { 8 | "path": "./tsconfig.esm.json" 9 | } 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /packages/adapters/abstract-adapter/tsconfig.cjs.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../tsconfig.cjs.json", 3 | "include": ["src"], 4 | "compilerOptions": { 5 | "outDir": "lib/cjs" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /packages/adapters/abstract-adapter/tsconfig.esm.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../tsconfig.esm.json", 3 | "include": ["src"], 4 | "compilerOptions": { 5 | "outDir": "lib/esm", 6 | "declarationDir": "lib/types" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /packages/adapters/adapters/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright (c) 2022-Present, tronprotocol 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | -------------------------------------------------------------------------------- /packages/adapters/adapters/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@tronweb3/tronwallet-adapters", 3 | "version": "1.2.1", 4 | "description": "Wallet adapters to help developers interact with Tron wallets using consistent API.", 5 | "keywords": [ 6 | "TRON", 7 | "TronWeb", 8 | "adapters" 9 | ], 10 | "author": "tronprotocol", 11 | "repository": { 12 | "type": "git", 13 | "url": "https://github.com/tronprotocol/tronwallet-adapter" 14 | }, 15 | "license": "MIT", 16 | "type": "module", 17 | "sideEffects": false, 18 | "engines": { 19 | "node": ">=16", 20 | "pnpm": ">=7" 21 | }, 22 | "main": "./lib/cjs/index.js", 23 | "module": "./lib/esm/index.js", 24 | "types": "./lib/types/index.d.ts", 25 | "exports": { 26 | "require": "./lib/cjs/index.js", 27 | "import": "./lib/esm/index.js", 28 | "types": "./lib/types/index.d.ts" 29 | }, 30 | "files": [ 31 | "lib", 32 | "src", 33 | "LICENSE" 34 | ], 35 | "publishConfig": { 36 | "access": "public" 37 | }, 38 | "scripts": { 39 | "clean": "shx mkdir -p lib && shx rm -rf lib", 40 | "package": "shx echo '{ \"type\": \"commonjs\" }' > lib/cjs/package.json", 41 | "build:umd": "node ../../../scripts/build-umd.js" 42 | }, 43 | "dependencies": { 44 | "@tronweb3/tronwallet-adapter-bitkeep": "workspace:^", 45 | "@tronweb3/tronwallet-adapter-ledger": "workspace:^", 46 | "@tronweb3/tronwallet-adapter-okxwallet": "workspace:^", 47 | "@tronweb3/tronwallet-adapter-tokenpocket": "workspace:^", 48 | "@tronweb3/tronwallet-adapter-tronlink": "workspace:^", 49 | "@tronweb3/tronwallet-adapter-walletconnect": "workspace:^" 50 | }, 51 | "devDependencies": { 52 | "shx": "^0.3.4" 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /packages/adapters/adapters/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from '@tronweb3/tronwallet-adapter-tronlink'; 2 | export * from '@tronweb3/tronwallet-adapter-walletconnect'; 3 | export * from '@tronweb3/tronwallet-adapter-ledger'; 4 | export * from '@tronweb3/tronwallet-adapter-tokenpocket'; 5 | export * from '@tronweb3/tronwallet-adapter-bitkeep'; 6 | export * from '@tronweb3/tronwallet-adapter-okxwallet'; 7 | -------------------------------------------------------------------------------- /packages/adapters/adapters/tsconfig.all.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../tsconfig.root.json", 3 | "references": [ 4 | { 5 | "path": "../tronlink/tsconfig.all.json" 6 | }, 7 | { 8 | "path": "../walletconnect/tsconfig.all.json" 9 | }, 10 | { 11 | "path": "../ledger/tsconfig.all.json" 12 | }, 13 | { 14 | "path": "../tokenpocket/tsconfig.all.json" 15 | }, 16 | { 17 | "path": "../bitkeep/tsconfig.all.json" 18 | }, 19 | { 20 | "path": "../okxwallet/tsconfig.all.json" 21 | }, 22 | { 23 | "path": "./tsconfig.cjs.json" 24 | }, 25 | { 26 | "path": "./tsconfig.esm.json" 27 | } 28 | ] 29 | } 30 | -------------------------------------------------------------------------------- /packages/adapters/adapters/tsconfig.cjs.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../tsconfig.cjs.json", 3 | "include": ["src"], 4 | "compilerOptions": { 5 | "outDir": "lib/cjs", 6 | "skipLibCheck": true 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /packages/adapters/adapters/tsconfig.esm.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../tsconfig.esm.json", 3 | "include": ["src"], 4 | "compilerOptions": { 5 | "outDir": "lib/esm", 6 | "skipLibCheck": true, 7 | "declarationDir": "lib/types" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /packages/adapters/bitkeep/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright (c) 2022-Present, tronprotocol 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | -------------------------------------------------------------------------------- /packages/adapters/bitkeep/jest.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('ts-jest').JestConfigWithTsJest} */ 2 | export default { 3 | preset: 'ts-jest', 4 | testEnvironment: 'jsdom', 5 | transform: { 6 | '\\.tsx?$': [ 7 | 'ts-jest', 8 | { 9 | useESM: true, 10 | }, 11 | ], 12 | }, 13 | moduleNameMapper: { 14 | '(.+)\\.js': '$1', 15 | }, 16 | extensionsToTreatAsEsm: ['.ts'], 17 | }; 18 | -------------------------------------------------------------------------------- /packages/adapters/bitkeep/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@tronweb3/tronwallet-adapter-bitkeep", 3 | "version": "1.1.1", 4 | "description": "Wallet adapter for Bitget(BitKeep) Wallet extension and app.", 5 | "keywords": [ 6 | "TRON", 7 | "TronWeb", 8 | "BitKeep", 9 | "Bitget" 10 | ], 11 | "author": "tronprotocol", 12 | "repository": { 13 | "type": "git", 14 | "url": "https://github.com/tronprotocol/tronwallet-adapter" 15 | }, 16 | "license": "MIT", 17 | "type": "module", 18 | "sideEffects": false, 19 | "engines": { 20 | "node": ">=16", 21 | "pnpm": ">=7" 22 | }, 23 | "main": "./lib/cjs/index.js", 24 | "module": "./lib/esm/index.js", 25 | "types": "./lib/types/index.d.ts", 26 | "exports": { 27 | "require": "./lib/cjs/index.js", 28 | "import": "./lib/esm/index.js", 29 | "types": "./lib/types/index.d.ts" 30 | }, 31 | "files": [ 32 | "lib", 33 | "src", 34 | "LICENSE" 35 | ], 36 | "publishConfig": { 37 | "access": "public" 38 | }, 39 | "scripts": { 40 | "clean": "shx mkdir -p lib && shx rm -rf lib", 41 | "package": "shx echo '{ \"type\": \"commonjs\" }' > lib/cjs/package.json", 42 | "test": "jest", 43 | "build:umd": "node ../../../scripts/build-umd.js" 44 | }, 45 | "dependencies": { 46 | "@bitget-wallet/web3-sdk": "^0.0.8", 47 | "@tronweb3/tronwallet-abstract-adapter": "workspace:^", 48 | "@tronweb3/tronwallet-adapter-tronlink": "workspace:^" 49 | }, 50 | "devDependencies": { 51 | "@testing-library/dom": "^8.20.0", 52 | "jest-environment-jsdom": "^29.3.1", 53 | "shx": "^0.3.4" 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /packages/adapters/bitkeep/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './adapter.js'; 2 | export * from './utils.js'; 3 | -------------------------------------------------------------------------------- /packages/adapters/bitkeep/src/utils.ts: -------------------------------------------------------------------------------- 1 | import { isInMobileBrowser } from '@tronweb3/tronwallet-abstract-adapter'; 2 | 3 | export function supportBitgetWallet() { 4 | return !!window.tronLink && (window as any).isBitKeep; 5 | } 6 | 7 | export function openBitgetWallet() { 8 | if (isInMobileBrowser() && !supportBitgetWallet()) { 9 | const { origin, pathname, search, hash } = window.location; 10 | const url = origin + pathname + search + hash; 11 | location.href = `https://bkcode.vip?action=dapp&url=${encodeURIComponent(url)}`; 12 | return true; 13 | } 14 | return false; 15 | } 16 | -------------------------------------------------------------------------------- /packages/adapters/bitkeep/tests/units/adapter.test.ts: -------------------------------------------------------------------------------- 1 | import { BitKeepAdapter } from '../../src/adapter.js'; 2 | 3 | describe('BitKeepAdapter', () => { 4 | test('should be defined', () => { 5 | expect(BitKeepAdapter).not.toBeNull(); 6 | }); 7 | test('#constructor() should work fine', () => { 8 | const adapter = new BitKeepAdapter(); 9 | expect(adapter.name).toEqual('Bitget Wallet'); 10 | }); 11 | }); 12 | -------------------------------------------------------------------------------- /packages/adapters/bitkeep/tsconfig.all.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../tsconfig.root.json", 3 | "references": [ 4 | { 5 | "path": "../abstract-adapter/tsconfig.all.json" 6 | }, 7 | { 8 | "path": "../tronlink/tsconfig.all.json" 9 | }, 10 | { 11 | "path": "./tsconfig.cjs.json" 12 | }, 13 | { 14 | "path": "./tsconfig.esm.json" 15 | } 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /packages/adapters/bitkeep/tsconfig.cjs.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../tsconfig.cjs.json", 3 | "include": ["src"], 4 | "compilerOptions": { 5 | "outDir": "lib/cjs" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /packages/adapters/bitkeep/tsconfig.esm.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../tsconfig.esm.json", 3 | "include": ["src"], 4 | "compilerOptions": { 5 | "outDir": "lib/esm", 6 | "declarationDir": "lib/types" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /packages/adapters/ledger/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright (c) 2022-Present, tronprotocol 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | -------------------------------------------------------------------------------- /packages/adapters/ledger/__mocks__/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "node": true 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /packages/adapters/ledger/__mocks__/@ledgerhq/hw-app-trx.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/no-unused-vars */ 2 | module.exports = class Trx { 3 | static _getAddress(path, display = false) { 4 | return Promise.resolve({ 5 | address: 'testaddress', 6 | publicKey: 'testPublicKey', 7 | }); 8 | } 9 | static async _signTransaction(path, rawTxHex, tokenSignatures) { 10 | return new Promise((resolve) => { 11 | resolve('signedResponse'); 12 | }); 13 | } 14 | static async _signPersonalMessage(path, hex) { 15 | return new Promise((resolve, reject) => { 16 | resolve('signPersonalMessageResponse'); 17 | }); 18 | } 19 | async getAddress(path, display = false) { 20 | return Trx._getAddress(path, display); 21 | } 22 | async signTransaction(path, rawTxHex, tokenSignatures) { 23 | return Trx._signTransaction(path, rawTxHex, tokenSignatures); 24 | } 25 | async signPersonalMessage(path, hex) { 26 | return Trx._signPersonalMessage(path, hex); 27 | } 28 | }; 29 | -------------------------------------------------------------------------------- /packages/adapters/ledger/__mocks__/@ledgerhq/hw-transport-webhid.js: -------------------------------------------------------------------------------- 1 | module.exports = class TransportWebHID { 2 | static create() { 3 | return new TransportWebHID(); 4 | } 5 | 6 | static _close() { 7 | return Promise.resolve(); 8 | } 9 | 10 | close() { 11 | return TransportWebHID._close(); 12 | } 13 | }; 14 | -------------------------------------------------------------------------------- /packages/adapters/ledger/jest.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('ts-jest').JestConfigWithTsJest} */ 2 | export default { 3 | preset: 'ts-jest', 4 | testEnvironment: 'jsdom', 5 | transform: { 6 | '\\.tsx?$': [ 7 | 'ts-jest', 8 | { 9 | useESM: true, 10 | }, 11 | ], 12 | }, 13 | moduleNameMapper: { 14 | '(.+)\\.js': '$1', 15 | }, 16 | extensionsToTreatAsEsm: ['.ts'], 17 | resolver: './resolver.cjs', 18 | }; 19 | -------------------------------------------------------------------------------- /packages/adapters/ledger/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@tronweb3/tronwallet-adapter-ledger", 3 | "version": "1.1.8", 4 | "description": "Wallet adapter for the Ledger wallet.", 5 | "keywords": [ 6 | "TRON", 7 | "TronWeb", 8 | "Ledger" 9 | ], 10 | "author": "tronprotocol", 11 | "repository": { 12 | "type": "git", 13 | "url": "https://github.com/tronprotocol/tronwallet-adapter" 14 | }, 15 | "license": "MIT", 16 | "type": "module", 17 | "sideEffects": true, 18 | "engines": { 19 | "node": ">=16", 20 | "pnpm": ">=7" 21 | }, 22 | "main": "./lib/cjs/index.js", 23 | "module": "./lib/esm/index.js", 24 | "types": "./lib/types/index.d.ts", 25 | "exports": { 26 | "require": "./lib/cjs/index.js", 27 | "import": "./lib/esm/index.js", 28 | "types": "./lib/types/index.d.ts" 29 | }, 30 | "files": [ 31 | "lib", 32 | "src", 33 | "LICENSE" 34 | ], 35 | "publishConfig": { 36 | "access": "public" 37 | }, 38 | "scripts": { 39 | "clean": "shx mkdir -p lib && shx rm -rf lib", 40 | "package": "shx echo '{ \"type\": \"commonjs\" }' > lib/cjs/package.json", 41 | "test": "jest", 42 | "build:umd": "node ../../../scripts/build-umd.js" 43 | }, 44 | "dependencies": { 45 | "@ledgerhq/hw-app-trx": "^6.27.8", 46 | "@ledgerhq/hw-transport": "6.27.1", 47 | "@ledgerhq/hw-transport-webhid": "6.27.1", 48 | "@tronweb3/tronwallet-abstract-adapter": "workspace:^", 49 | "buffer": "^6.0.3", 50 | "eventemitter3": "^4.0.0", 51 | "preact": "^10.11.3" 52 | }, 53 | "devDependencies": { 54 | "@testing-library/dom": "^8.20.0", 55 | "jest-environment-jsdom": "^29.3.1", 56 | "shx": "^0.3.4" 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /packages/adapters/ledger/resolver.cjs: -------------------------------------------------------------------------------- 1 | // eslint-disable-next-line no-undef 2 | module.exports = (path, options) => { 3 | return options.defaultResolver(path, { 4 | ...options, 5 | packageFilter: (pkg) => { 6 | if (pkg?.name?.includes('preact')) { 7 | Object.values(pkg.exports).forEach((exp) => { 8 | exp.browser = exp.require; 9 | }); 10 | return pkg; 11 | } 12 | return pkg; 13 | }, 14 | }); 15 | }; 16 | -------------------------------------------------------------------------------- /packages/adapters/ledger/src/Modal/ConfirmContent.tsx: -------------------------------------------------------------------------------- 1 | import React, { useMemo } from 'preact/compat'; 2 | import { getLangText } from './lang.js'; 3 | import { LedgerIcon } from './LedgerIcon.js'; 4 | import { LoadingIcon } from './LoadingIcon.js'; 5 | export function ConfirmContent(props: { address: string }) { 6 | const langText = useMemo(() => getLangText(), []); 7 | return ( 8 |

9 | 10 |
11 |
    12 |
  • 13 | {langText.checkTitle} 14 |
  • 15 |
  • 16 | 20 | {props.address} 21 | 22 |
  • 23 |
  • {langText.checkTip0}
  • 24 |
  • {langText.checkTip1}
  • 25 |
26 |
27 | 28 |
29 |
30 | {langText.confirmTip} 31 |
32 |
33 |
34 |
35 |
36 | ); 37 | } 38 | -------------------------------------------------------------------------------- /packages/adapters/ledger/src/Modal/ConnectingContent.tsx: -------------------------------------------------------------------------------- 1 | import React, { useMemo } from 'preact/compat'; 2 | import { getLangText } from './lang.js'; 3 | import { LedgerIcon } from './LedgerIcon.js'; 4 | import { LoadingIcon } from './LoadingIcon.js'; 5 | export function ConnectingContent() { 6 | const langText = useMemo(() => getLangText(), []); 7 | return ( 8 |
9 | 10 |
11 |
    12 |
  • {langText.loadingTip0}
  • 13 |
14 |
15 | 16 |
17 |
18 | {langText.loadingTip4} 19 |
20 |
21 |
22 |
23 |
24 | ); 25 | } 26 | -------------------------------------------------------------------------------- /packages/adapters/ledger/src/Modal/LoadingIcon.tsx: -------------------------------------------------------------------------------- 1 | import React from 'preact/compat'; 2 | 3 | export function LoadingIcon() { 4 | return ( 5 |
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | ); 14 | } 15 | -------------------------------------------------------------------------------- /packages/adapters/ledger/src/__mocks__/LedgerWallet.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/no-unused-vars */ 2 | /* eslint-disable @typescript-eslint/no-empty-function */ 3 | export class LedgerWallet { 4 | static _constructor(...args: any[]) {} 5 | static _connect(...args: any[]) {} 6 | static _disconnect(...args: any[]) {} 7 | static _signPersonalMessage(...args: any[]) {} 8 | static _signTransaction(...args: any[]) {} 9 | static _getAccounts(...args: any[]) {} 10 | static _getAddress(...args: any[]) {} 11 | constructor(...args: any[]) { 12 | LedgerWallet._constructor(...args); 13 | } 14 | async connect(...args: any[]) { 15 | return await LedgerWallet._connect(...args); 16 | } 17 | disconnect(...args: any[]) { 18 | return LedgerWallet._disconnect(...args); 19 | } 20 | async signPersonalMessage(...args: any[]) { 21 | return await LedgerWallet._signPersonalMessage(...args); 22 | } 23 | async signTransaction(...args: any[]) { 24 | return await LedgerWallet._signTransaction(...args); 25 | } 26 | async getAccounts(...args: any[]) { 27 | return await LedgerWallet._getAccounts(...args); 28 | } 29 | async getAddress(...args: any[]) { 30 | return await LedgerWallet._getAddress(...args); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /packages/adapters/ledger/src/index.ts: -------------------------------------------------------------------------------- 1 | import './polyfills/index.js'; 2 | export * from './adapter.js'; 3 | export * from './Modal/openModal.js'; 4 | export type { LedgerUtils, Account, GetAccounts, SelectAccount } from './LedgerWallet.js'; 5 | -------------------------------------------------------------------------------- /packages/adapters/ledger/src/polyfills/Buffer.ts: -------------------------------------------------------------------------------- 1 | import { Buffer } from 'buffer'; 2 | 3 | if (typeof window !== 'undefined' && window.Buffer === undefined) { 4 | (window as any).Buffer = Buffer; 5 | } 6 | 7 | export {}; 8 | -------------------------------------------------------------------------------- /packages/adapters/ledger/src/polyfills/index.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | import './Buffer.js'; 4 | -------------------------------------------------------------------------------- /packages/adapters/ledger/tsconfig.all.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../tsconfig.root.json", 3 | "references": [ 4 | { 5 | "path": "../abstract-adapter/tsconfig.all.json" 6 | }, 7 | { 8 | "path": "./tsconfig.cjs.json" 9 | }, 10 | { 11 | "path": "./tsconfig.esm.json" 12 | } 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /packages/adapters/ledger/tsconfig.cjs.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../tsconfig.cjs.json", 3 | "include": ["src"], 4 | "compilerOptions": { 5 | "outDir": "lib/cjs", 6 | "jsx": "react-jsx", 7 | "jsxImportSource": "preact", 8 | "skipLibCheck": true, 9 | "baseUrl": "./", 10 | "paths": { 11 | "react": ["./node_modules/preact/compat/"], 12 | "react-dom": ["./node_modules/preact/compat/"] 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /packages/adapters/ledger/tsconfig.esm.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../tsconfig.esm.json", 3 | "include": ["src"], 4 | "compilerOptions": { 5 | "outDir": "lib/esm", 6 | "declarationDir": "lib/types", 7 | "jsx": "react-jsx", 8 | "jsxImportSource": "preact", 9 | "skipLibCheck": true, 10 | "baseUrl": "./", 11 | "paths": { 12 | "react": ["./node_modules/preact/compat/"], 13 | "react-dom": ["./node_modules/preact/compat/"] 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /packages/adapters/ledger/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES2016", 4 | "module": "ESNext", 5 | "moduleResolution": "Node", 6 | "esModuleInterop": true, 7 | "declaration": true, 8 | "declarationDir": "lib/types", 9 | "jsx": "react-jsx", 10 | "jsxImportSource": "preact", 11 | "skipLibCheck": true, 12 | "baseUrl": "./", 13 | "rootDir": ".", 14 | "paths": { 15 | "react": ["./node_modules/preact/compat/"], 16 | "react-dom": ["./node_modules/preact/compat/"] 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /packages/adapters/metamask/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright (c) 2022-Present, tronprotocol 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | -------------------------------------------------------------------------------- /packages/adapters/metamask/README.md: -------------------------------------------------------------------------------- 1 | # `@tronweb3/tronwallet-adapter-metamask` 2 | 3 | This package provides an adapter to enable DApps to connect to the [MetaMask Wallet extension](https://chrome.google.com/webstore/detail/metamask/nkbihfbeogaeaoehlefnkodbefgpgknn) and [MetaMask Wallet App](https://metamask.io/). 4 | 5 | ## Demo 6 | 7 | ```typescript 8 | import { MetaMaskAdapter } from '@tronweb3/tronwallet-adapter-metamask'; 9 | 10 | const adapter = new MetaMaskAdapter(); 11 | // connect 12 | await adapter.connect(); 13 | 14 | // then you can get address 15 | console.log(adapter.address); 16 | 17 | // just use the sendTransaction method to send a transfer transaction. 18 | const transaction = { 19 | value: '0x' + Number(0.01 * Math.pow(10, 18)).toString(16), // 0.01 is 0.01ETH 20 | to: 'your target address', 21 | from: adapter.address, 22 | }; 23 | await adapter.sendTransaction(transaction); 24 | ``` 25 | 26 | ## Documentation 27 | 28 | ### API 29 | 30 | - `Constructor(config: MetaMaskAdapterOptions)` 31 | 32 | ```typescript 33 | import { MetaMaskAdapter } from '@tronweb3/tronwallet-adapter-metamask'; 34 | interface MetaMaskAdapterOptions { 35 | /** 36 | * Set if open MetaMask app when in mobile device. 37 | * Default is true. 38 | */ 39 | useDeeplink?: boolean; 40 | } 41 | const metaMaskAdapter = new MetaMaskAdapter({ useDeeplink: false }); 42 | ``` 43 | 44 | More detailed API can be found in [Abstract Adapter](https://github.com/tronprotocol/tronwallet-adapter/blob/main/packages/adapters/abstract-adapter-evm/README.md). 45 | -------------------------------------------------------------------------------- /packages/adapters/metamask/jest.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('ts-jest').JestConfigWithTsJest} */ 2 | export default { 3 | preset: 'ts-jest', 4 | testEnvironment: 'jsdom', 5 | transform: { 6 | '\\.tsx?$': [ 7 | 'ts-jest', 8 | { 9 | useESM: true, 10 | }, 11 | ], 12 | }, 13 | moduleNameMapper: { 14 | '(.+)\\.js': '$1', 15 | }, 16 | extensionsToTreatAsEsm: ['.ts'], 17 | }; 18 | -------------------------------------------------------------------------------- /packages/adapters/metamask/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@tronweb3/tronwallet-adapter-metamask", 3 | "version": "1.0.1", 4 | "description": "Wallet adapter for Metamask wallet extension and app.", 5 | "keywords": [ 6 | "EVM", 7 | "Ethereum Wallet", 8 | "Metamask wallet" 9 | ], 10 | "author": "tronprotocol", 11 | "repository": { 12 | "type": "git", 13 | "url": "https://github.com/tronprotocol/tronwallet-adapter" 14 | }, 15 | "license": "MIT", 16 | "type": "module", 17 | "sideEffects": false, 18 | "engines": { 19 | "node": ">=16", 20 | "pnpm": ">=7" 21 | }, 22 | "main": "./lib/cjs/index.js", 23 | "module": "./lib/esm/index.js", 24 | "types": "./lib/types/index.d.ts", 25 | "exports": { 26 | "require": "./lib/cjs/index.js", 27 | "import": "./lib/esm/index.js", 28 | "types": "./lib/types/index.d.ts" 29 | }, 30 | "files": [ 31 | "lib", 32 | "src", 33 | "LICENSE" 34 | ], 35 | "publishConfig": { 36 | "access": "public" 37 | }, 38 | "scripts": { 39 | "clean": "shx mkdir -p lib && shx rm -rf lib", 40 | "package": "shx echo '{ \"type\": \"commonjs\" }' > lib/cjs/package.json", 41 | "test": "jest", 42 | "test:coverage": "jest --coverage", 43 | "build:umd": "node ../../../scripts/build-umd.js" 44 | }, 45 | "dependencies": { 46 | "@tronweb3/abstract-adapter-evm": "workspace:^" 47 | }, 48 | "devDependencies": { 49 | "@testing-library/dom": "^8.20.0", 50 | "jest": "28", 51 | "jest-environment-jsdom": "28", 52 | "shx": "^0.3.4" 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /packages/adapters/metamask/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './adapter.js'; 2 | -------------------------------------------------------------------------------- /packages/adapters/metamask/src/utils.ts: -------------------------------------------------------------------------------- 1 | import type { EIP1193Provider } from '@tronweb3/abstract-adapter-evm'; 2 | 3 | export function getMetaMaskProvider(): null | EIP1193Provider { 4 | if (!window.ethereum) { 5 | return null; 6 | } 7 | if (window.ethereum.isMetaMask && !(window.ethereum as any).overrideIsMetaMask) { 8 | return window.ethereum as EIP1193Provider; 9 | } 10 | /** 11 | * When install CoinBase Wallet and MetaMask Wallet, ethereum will be override by CoinBase. 12 | */ 13 | // @ts-ignore 14 | return window.ethereum.providers?.find((item: EIP1193Provider) => item.isMetaMask) || null; 15 | } 16 | 17 | export function isMetaMaskMobileWebView() { 18 | if (typeof window === 'undefined') { 19 | return false; 20 | } 21 | 22 | // @ts-ignore 23 | return Boolean(window.ReactNativeWebView) && Boolean(navigator.userAgent.endsWith('MetaMaskMobile')); 24 | } 25 | 26 | export function openMetaMaskWithDeeplink() { 27 | const { href, protocol } = window.location; 28 | const originLink = href.replace(protocol, '').slice(2); 29 | const link = `https://metamask.app.link/dapp/${originLink}`; 30 | const dappLink = `dapp://${originLink}`; 31 | const userAgent = window?.navigator?.userAgent || ''; 32 | if (/\bAndroid(?:.+)Mobile\b/i.test(userAgent)) { 33 | window.location.href = dappLink; 34 | } else { 35 | window.open(link, '_blank'); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /packages/adapters/metamask/tests/units/metamask-provider.ts: -------------------------------------------------------------------------------- 1 | import { EventEmitter } from '@tronweb3/abstract-adapter-evm'; 2 | 3 | jest.useFakeTimers(); 4 | export class MetaMaskProvider extends EventEmitter { 5 | isMetaMask = true; 6 | providers = [MetaMaskProvider]; 7 | constructor() { 8 | super(); 9 | } 10 | 11 | request({ method }: { method: string }): Promise { 12 | if (method === 'eth_accounts') { 13 | return new Promise((resolve) => { 14 | resolve(this._accountsRes); 15 | }); 16 | } 17 | if (method === 'eth_requestAccounts') { 18 | return new Promise((resolve) => { 19 | resolve(this._requestAccountsRes); 20 | this.emit('accountsChanged', this._requestAccountsRes); 21 | }); 22 | } 23 | if (method === 'personal_sign') { 24 | return new Promise((resolve) => { 25 | resolve(this._personalSignRes); 26 | }); 27 | } 28 | return new Promise((resolve) => { 29 | resolve(null); 30 | }); 31 | } 32 | 33 | _accountsRes: string[] = []; 34 | _requestAccountsRes: string[] = []; 35 | _personalSignRes = ''; 36 | _setAccountsRes(accounts: string[]) { 37 | this._accountsRes = accounts; 38 | } 39 | _setRequestAccountsRes(accounts: string[]) { 40 | this._requestAccountsRes = accounts; 41 | } 42 | _setPersonalSignRes(res: string) { 43 | this._personalSignRes = res; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /packages/adapters/metamask/tsconfig.all.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../tsconfig.root.json", 3 | "references": [ 4 | { 5 | "path": "../abstract-adapter/tsconfig.all.json" 6 | }, 7 | { 8 | "path": "./tsconfig.cjs.json" 9 | }, 10 | { 11 | "path": "./tsconfig.esm.json" 12 | } 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /packages/adapters/metamask/tsconfig.cjs.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../tsconfig.cjs.json", 3 | "include": ["src"], 4 | "compilerOptions": { 5 | "outDir": "lib/cjs" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /packages/adapters/metamask/tsconfig.esm.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../tsconfig.esm.json", 3 | "include": ["src"], 4 | "compilerOptions": { 5 | "outDir": "lib/esm", 6 | "declarationDir": "lib/types" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /packages/adapters/okxwallet/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright (c) 2022-Present, tronprotocol 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | -------------------------------------------------------------------------------- /packages/adapters/okxwallet/jest.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('ts-jest').JestConfigWithTsJest} */ 2 | export default { 3 | preset: 'ts-jest', 4 | testEnvironment: 'jsdom', 5 | transform: { 6 | '\\.tsx?$': [ 7 | 'ts-jest', 8 | { 9 | useESM: true, 10 | }, 11 | ], 12 | }, 13 | moduleNameMapper: { 14 | '(.+)\\.js': '$1', 15 | }, 16 | extensionsToTreatAsEsm: ['.ts'], 17 | }; 18 | -------------------------------------------------------------------------------- /packages/adapters/okxwallet/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@tronweb3/tronwallet-adapter-okxwallet", 3 | "version": "1.0.3", 4 | "description": "Wallet adapter for Okx Wallet extension and Okx Wallet app.", 5 | "keywords": [ 6 | "TRON", 7 | "TronWeb", 8 | "Okx Wallet" 9 | ], 10 | "author": "tronprotocol", 11 | "repository": { 12 | "type": "git", 13 | "url": "https://github.com/tronprotocol/tronwallet-adapter" 14 | }, 15 | "license": "MIT", 16 | "type": "module", 17 | "sideEffects": false, 18 | "engines": { 19 | "node": ">=16", 20 | "pnpm": ">=7" 21 | }, 22 | "main": "./lib/cjs/index.js", 23 | "module": "./lib/esm/index.js", 24 | "types": "./lib/types/index.d.ts", 25 | "exports": { 26 | "require": "./lib/cjs/index.js", 27 | "import": "./lib/esm/index.js", 28 | "types": "./lib/types/index.d.ts" 29 | }, 30 | "files": [ 31 | "lib", 32 | "src", 33 | "LICENSE" 34 | ], 35 | "publishConfig": { 36 | "access": "public" 37 | }, 38 | "scripts": { 39 | "clean": "shx mkdir -p lib && shx rm -rf lib", 40 | "package": "shx echo '{ \"type\": \"commonjs\" }' > lib/cjs/package.json", 41 | "test": "jest", 42 | "test:coverage": "jest --coverage", 43 | "build:umd": "node ../../../scripts/build-umd.js" 44 | }, 45 | "dependencies": { 46 | "@tronweb3/tronwallet-abstract-adapter": "workspace:^", 47 | "@tronweb3/tronwallet-adapter-tronlink": "workspace:^" 48 | }, 49 | "devDependencies": { 50 | "@testing-library/dom": "^8.20.0", 51 | "jest-environment-jsdom": "^29.3.1", 52 | "shx": "^0.3.4" 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /packages/adapters/okxwallet/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './adapter.js'; 2 | export * from './utils.js'; 3 | -------------------------------------------------------------------------------- /packages/adapters/okxwallet/src/utils.ts: -------------------------------------------------------------------------------- 1 | import { isInMobileBrowser } from '@tronweb3/tronwallet-abstract-adapter'; 2 | 3 | export function supportOkxWallet() { 4 | return !!(window.okxwallet && window.okxwallet.tronLink); 5 | } 6 | 7 | export const isOKApp = /OKApp/i.test(navigator.userAgent); 8 | 9 | export function openOkxWallet() { 10 | if (!isOKApp && isInMobileBrowser()) { 11 | window.location.href = 'okx://wallet/dapp/url?dappUrl=' + encodeURIComponent(window.location.href); 12 | return true; 13 | } 14 | return false; 15 | } 16 | -------------------------------------------------------------------------------- /packages/adapters/okxwallet/tests/units/adapter.test.ts: -------------------------------------------------------------------------------- 1 | import { OkxWalletAdapter } from '../../src/index.js'; 2 | 3 | window.open = jest.fn(); 4 | beforeEach(function () { 5 | jest.useFakeTimers(); 6 | global.document = window.document; 7 | global.navigator = window.navigator; 8 | window.tronLink = undefined; 9 | window.tron = undefined; 10 | }); 11 | describe('OkxWalletAdapter', function () { 12 | describe('#adapter()', function () { 13 | test('constructor', () => { 14 | const adapter = new OkxWalletAdapter(); 15 | expect(adapter.name).toEqual('OKX Wallet'); 16 | expect(adapter).toHaveProperty('icon'); 17 | expect(adapter).toHaveProperty('url'); 18 | expect(adapter).toHaveProperty('readyState'); 19 | expect(adapter).toHaveProperty('address'); 20 | expect(adapter).toHaveProperty('connecting'); 21 | expect(adapter).toHaveProperty('connected'); 22 | 23 | expect(adapter).toHaveProperty('connect'); 24 | expect(adapter).toHaveProperty('disconnect'); 25 | expect(adapter).toHaveProperty('signMessage'); 26 | expect(adapter).toHaveProperty('signTransaction'); 27 | 28 | expect(adapter).toHaveProperty('on'); 29 | expect(adapter).toHaveProperty('off'); 30 | }); 31 | }); 32 | }); 33 | -------------------------------------------------------------------------------- /packages/adapters/okxwallet/tsconfig.all.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../tsconfig.root.json", 3 | "references": [ 4 | { 5 | "path": "../abstract-adapter/tsconfig.all.json" 6 | }, 7 | { 8 | "path": "../tronlink/tsconfig.all.json" 9 | }, 10 | { 11 | "path": "./tsconfig.cjs.json" 12 | }, 13 | { 14 | "path": "./tsconfig.esm.json" 15 | } 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /packages/adapters/okxwallet/tsconfig.cjs.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../tsconfig.cjs.json", 3 | "include": ["src"], 4 | "compilerOptions": { 5 | "outDir": "lib/cjs" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /packages/adapters/okxwallet/tsconfig.esm.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../tsconfig.esm.json", 3 | "include": ["src"], 4 | "compilerOptions": { 5 | "outDir": "lib/esm", 6 | "declarationDir": "lib/types" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /packages/adapters/tokenpocket/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright (c) 2022-Present, tronprotocol 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | -------------------------------------------------------------------------------- /packages/adapters/tokenpocket/jest.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('ts-jest').JestConfigWithTsJest} */ 2 | export default { 3 | preset: 'ts-jest', 4 | testEnvironment: 'jsdom', 5 | transform: { 6 | '\\.tsx?$': [ 7 | 'ts-jest', 8 | { 9 | useESM: true, 10 | }, 11 | ], 12 | }, 13 | moduleNameMapper: { 14 | '(.+)\\.js': '$1', 15 | }, 16 | extensionsToTreatAsEsm: ['.ts'], 17 | }; 18 | -------------------------------------------------------------------------------- /packages/adapters/tokenpocket/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@tronweb3/tronwallet-adapter-tokenpocket", 3 | "version": "1.0.3", 4 | "description": "Wallet adapter for TokenPocket Wallet app.", 5 | "keywords": [ 6 | "TRON", 7 | "TronWeb", 8 | "TokenPocket" 9 | ], 10 | "author": "tronprotocol", 11 | "repository": { 12 | "type": "git", 13 | "url": "https://github.com/tronprotocol/tronwallet-adapter" 14 | }, 15 | "license": "MIT", 16 | "type": "module", 17 | "sideEffects": false, 18 | "engines": { 19 | "node": ">=16", 20 | "pnpm": ">=7" 21 | }, 22 | "main": "./lib/cjs/index.js", 23 | "module": "./lib/esm/index.js", 24 | "types": "./lib/types/index.d.ts", 25 | "exports": { 26 | "require": "./lib/cjs/index.js", 27 | "import": "./lib/esm/index.js", 28 | "types": "./lib/types/index.d.ts" 29 | }, 30 | "files": [ 31 | "lib", 32 | "src", 33 | "LICENSE" 34 | ], 35 | "publishConfig": { 36 | "access": "public" 37 | }, 38 | "scripts": { 39 | "clean": "shx mkdir -p lib && shx rm -rf lib", 40 | "package": "shx echo '{ \"type\": \"commonjs\" }' > lib/cjs/package.json", 41 | "test": "jest", 42 | "build:umd": "node ../../../scripts/build-umd.js" 43 | }, 44 | "dependencies": { 45 | "@tronweb3/tronwallet-abstract-adapter": "workspace:^", 46 | "@tronweb3/tronwallet-adapter-tronlink": "workspace:^" 47 | }, 48 | "devDependencies": { 49 | "@testing-library/dom": "^8.20.0", 50 | "jest-environment-jsdom": "^29.3.1", 51 | "shx": "^0.3.4" 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /packages/adapters/tokenpocket/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './adapter.js'; 2 | export * from './utils.js'; 3 | -------------------------------------------------------------------------------- /packages/adapters/tokenpocket/src/utils.ts: -------------------------------------------------------------------------------- 1 | import { isInBrowser, isInMobileBrowser } from '@tronweb3/tronwallet-abstract-adapter'; 2 | 3 | export function supportTokenPocket() { 4 | return !!isInMobileBrowser() && !!window.tronWeb && typeof (window as any).tokenpocket !== 'undefined'; 5 | } 6 | 7 | /** 8 | * Detect if in TokenPocketApp 9 | * There will be a `tokenpocket` object on window 10 | */ 11 | export function isInTokenPocket() { 12 | return isInBrowser() && typeof (window as any).tokenpocket !== 'undefined'; 13 | } 14 | 15 | export function openTokenPocket() { 16 | if (!supportTokenPocket() && isInMobileBrowser() && !isInTokenPocket()) { 17 | const { origin, pathname, search, hash } = window.location; 18 | const url = origin + pathname + search + hash; 19 | const params = { 20 | action: 'open', 21 | actionId: Date.now() + '', 22 | callbackUrl: 'http://someurl.com', // no need callback 23 | blockchain: 'Tron', 24 | chain: 'Tron', 25 | url, 26 | protocol: 'TokenPocket', 27 | version: '1.0', 28 | }; 29 | window.location.href = `tpdapp://open?params=${encodeURIComponent(JSON.stringify(params))}`; 30 | return true; 31 | } 32 | return false; 33 | } 34 | -------------------------------------------------------------------------------- /packages/adapters/tokenpocket/tests/units/adapter.test.ts: -------------------------------------------------------------------------------- 1 | import { TokenPocketAdapter } from '../../src/adapter.js'; 2 | 3 | describe('TokenPocketAdapter', () => { 4 | test('should be defined', () => { 5 | expect(TokenPocketAdapter).not.toBeNull(); 6 | }); 7 | test('#constructor() should work fine', () => { 8 | const adapter = new TokenPocketAdapter(); 9 | expect(adapter.name).toEqual('TokenPocket'); 10 | }); 11 | }); 12 | -------------------------------------------------------------------------------- /packages/adapters/tokenpocket/tsconfig.all.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../tsconfig.root.json", 3 | "references": [ 4 | { 5 | "path": "../abstract-adapter/tsconfig.all.json" 6 | }, 7 | { 8 | "path": "../tronlink/tsconfig.all.json" 9 | }, 10 | { 11 | "path": "./tsconfig.cjs.json" 12 | }, 13 | { 14 | "path": "./tsconfig.esm.json" 15 | } 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /packages/adapters/tokenpocket/tsconfig.cjs.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../tsconfig.cjs.json", 3 | "include": ["src"], 4 | "compilerOptions": { 5 | "outDir": "lib/cjs" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /packages/adapters/tokenpocket/tsconfig.esm.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../tsconfig.esm.json", 3 | "include": ["src"], 4 | "compilerOptions": { 5 | "outDir": "lib/esm", 6 | "declarationDir": "lib/types" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /packages/adapters/tronlink-evm/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright (c) 2022-Present, tronprotocol 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | -------------------------------------------------------------------------------- /packages/adapters/tronlink-evm/README.md: -------------------------------------------------------------------------------- 1 | # `@tronweb3/tronwallet-adapter-tronlink-evm` 2 | 3 | This package provides an adapter to enable DApps to connect to the [TronLink Wallet extension](https://chrome.google.com/webstore/detail/tronlink/ibnejdfjmmkpcnlpebklmnkoeoihofec). 4 | 5 | ## Demo 6 | 7 | ```typescript 8 | import { TronLinkEvmAdapter } from '@tronweb3/tronwallet-adapter-tronlink-evm'; 9 | 10 | const adapter = new TronLinkEvmAdapter(); 11 | // connect 12 | await adapter.connect(); 13 | 14 | // then you can get address 15 | console.log(adapter.address); 16 | 17 | // just use the sendTransaction method to send a transfer transaction. 18 | const transaction = { 19 | value: '0x' + Number(0.01 * Math.pow(10, 18)).toString(16), // 0.01 is 0.01ETH 20 | to: 'your target address', 21 | from: adapter.address, 22 | }; 23 | await adapter.sendTransaction(transaction); 24 | ``` 25 | 26 | ## Documentation 27 | 28 | ### API 29 | 30 | - `Constructor()` 31 | 32 | ```typescript 33 | import { TronLinkEvmAdapter } from '@tronweb3/tronwallet-adapter-tronlink-evm'; 34 | const tronLinkEvmAdapter = new TronLinkEvmAdapter(); 35 | ``` 36 | 37 | **Caveat** Currently TronLink wallet does not support `addChain()` and `signTypedData()`. 38 | 39 | More detailed API can be found in [Abstract Adapter](https://github.com/tronprotocol/tronwallet-adapter/blob/main/packages/adapters/abstract-adapter-evm/README.md). 40 | -------------------------------------------------------------------------------- /packages/adapters/tronlink-evm/jest.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('ts-jest').JestConfigWithTsJest} */ 2 | export default { 3 | preset: 'ts-jest', 4 | testEnvironment: 'jsdom', 5 | transform: { 6 | '\\.tsx?$': [ 7 | 'ts-jest', 8 | { 9 | useESM: true, 10 | }, 11 | ], 12 | }, 13 | moduleNameMapper: { 14 | '(.+)\\.js': '$1', 15 | }, 16 | extensionsToTreatAsEsm: ['.ts'], 17 | }; 18 | -------------------------------------------------------------------------------- /packages/adapters/tronlink-evm/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@tronweb3/tronwallet-adapter-tronlink-evm", 3 | "version": "1.0.0", 4 | "description": "Wallet adapter for TronLink wallet extension.", 5 | "keywords": [ 6 | "EVM", 7 | "Ethereum Wallet", 8 | "TronLink wallet" 9 | ], 10 | "author": "tronprotocol", 11 | "repository": { 12 | "type": "git", 13 | "url": "https://github.com/tronprotocol/tronwallet-adapter" 14 | }, 15 | "license": "MIT", 16 | "type": "module", 17 | "sideEffects": false, 18 | "engines": { 19 | "node": ">=16", 20 | "pnpm": ">=7" 21 | }, 22 | "main": "./lib/cjs/index.js", 23 | "module": "./lib/esm/index.js", 24 | "types": "./lib/types/index.d.ts", 25 | "exports": { 26 | "require": "./lib/cjs/index.js", 27 | "import": "./lib/esm/index.js", 28 | "types": "./lib/types/index.d.ts" 29 | }, 30 | "files": [ 31 | "lib", 32 | "src", 33 | "LICENSE" 34 | ], 35 | "publishConfig": { 36 | "access": "public" 37 | }, 38 | "scripts": { 39 | "clean": "shx mkdir -p lib && shx rm -rf lib", 40 | "package": "shx echo '{ \"type\": \"commonjs\" }' > lib/cjs/package.json", 41 | "test": "jest", 42 | "test:coverage": "jest --coverage", 43 | "build:umd": "node ../../../scripts/build-umd.js" 44 | }, 45 | "dependencies": { 46 | "@tronweb3/abstract-adapter-evm": "workspace:^" 47 | }, 48 | "devDependencies": { 49 | "@testing-library/dom": "^8.20.0", 50 | "jest": "28", 51 | "jest-environment-jsdom": "28", 52 | "shx": "^0.3.4" 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /packages/adapters/tronlink-evm/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './adapter.js'; 2 | -------------------------------------------------------------------------------- /packages/adapters/tronlink-evm/src/utils.ts: -------------------------------------------------------------------------------- 1 | import type { EIP1193Provider } from '@tronweb3/abstract-adapter-evm'; 2 | 3 | export function getTronLinkEvmProvider(): null | EIP1193Provider { 4 | if (window.TronLinkEVM && (window.TronLinkEVM as any).isTronLink) { 5 | return window.TronLinkEVM; 6 | } 7 | return null; 8 | } 9 | -------------------------------------------------------------------------------- /packages/adapters/tronlink-evm/tests/units/adapter.test.ts: -------------------------------------------------------------------------------- 1 | import { TronLinkEvmAdapter } from '../../src/adapter.js'; 2 | 3 | describe('TronLinkEvmAdapter', () => { 4 | test('base props should be valid', () => { 5 | const adapter = new TronLinkEvmAdapter(); 6 | expect(adapter.name).toEqual('TronLinkEvm'); 7 | expect(adapter.url).toEqual('https://www.tronlink.org/'); 8 | expect(adapter.readyState).toEqual('Loading'); 9 | expect(adapter.address).toEqual(null); 10 | expect(adapter.connected).toEqual(false); 11 | jest.advanceTimersByTime(4000); 12 | expect(adapter.readyState).toEqual('Loading'); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /packages/adapters/tronlink-evm/tsconfig.all.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../tsconfig.root.json", 3 | "references": [ 4 | { 5 | "path": "../abstract-adapter/tsconfig.all.json" 6 | }, 7 | { 8 | "path": "./tsconfig.cjs.json" 9 | }, 10 | { 11 | "path": "./tsconfig.esm.json" 12 | } 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /packages/adapters/tronlink-evm/tsconfig.cjs.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../tsconfig.cjs.json", 3 | "include": ["src"], 4 | "compilerOptions": { 5 | "outDir": "lib/cjs" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /packages/adapters/tronlink-evm/tsconfig.esm.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../tsconfig.esm.json", 3 | "include": ["src"], 4 | "compilerOptions": { 5 | "outDir": "lib/esm", 6 | "declarationDir": "lib/types" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /packages/adapters/tronlink/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright (c) 2022-Present, tronprotocol 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | -------------------------------------------------------------------------------- /packages/adapters/tronlink/jest.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('ts-jest').JestConfigWithTsJest} */ 2 | export default { 3 | preset: 'ts-jest', 4 | testEnvironment: 'jsdom', 5 | transform: { 6 | '\\.tsx?$': [ 7 | 'ts-jest', 8 | { 9 | useESM: true, 10 | }, 11 | ], 12 | }, 13 | moduleNameMapper: { 14 | '(.+)\\.js': '$1', 15 | }, 16 | extensionsToTreatAsEsm: ['.ts'], 17 | }; 18 | -------------------------------------------------------------------------------- /packages/adapters/tronlink/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@tronweb3/tronwallet-adapter-tronlink", 3 | "version": "1.1.9", 4 | "description": "Wallet adapter for TronLink Wallet extension and TronLink app.", 5 | "keywords": [ 6 | "TRON", 7 | "TronWeb", 8 | "TronLink" 9 | ], 10 | "author": "tronprotocol", 11 | "repository": { 12 | "type": "git", 13 | "url": "https://github.com/tronprotocol/tronwallet-adapter" 14 | }, 15 | "license": "MIT", 16 | "type": "module", 17 | "sideEffects": false, 18 | "engines": { 19 | "node": ">=16", 20 | "pnpm": ">=7" 21 | }, 22 | "main": "./lib/cjs/index.js", 23 | "module": "./lib/esm/index.js", 24 | "types": "./lib/types/index.d.ts", 25 | "exports": { 26 | "require": "./lib/cjs/index.js", 27 | "import": "./lib/esm/index.js", 28 | "types": "./lib/types/index.d.ts" 29 | }, 30 | "files": [ 31 | "lib", 32 | "src", 33 | "LICENSE" 34 | ], 35 | "publishConfig": { 36 | "access": "public" 37 | }, 38 | "scripts": { 39 | "clean": "shx mkdir -p lib && shx rm -rf lib", 40 | "package": "shx echo '{ \"type\": \"commonjs\" }' > lib/cjs/package.json", 41 | "test": "jest", 42 | "test:coverage": "jest --coverage", 43 | "build:umd": "node ../../../scripts/build-umd.js" 44 | }, 45 | "dependencies": { 46 | "@tronweb3/tronwallet-abstract-adapter": "workspace:^" 47 | }, 48 | "devDependencies": { 49 | "@testing-library/dom": "^8.20.0", 50 | "jest-environment-jsdom": "^29.3.1", 51 | "shx": "^0.3.4" 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /packages/adapters/tronlink/src/error.ts: -------------------------------------------------------------------------------- 1 | import { WalletError } from '@tronweb3/tronwallet-abstract-adapter'; 2 | 3 | export class WalletGetNetworkError extends WalletError { 4 | name = 'WalletGetNetworkError'; 5 | } 6 | -------------------------------------------------------------------------------- /packages/adapters/tronlink/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './adapter.js'; 2 | export * from './types.js'; 3 | export * from './utils.js'; 4 | -------------------------------------------------------------------------------- /packages/adapters/tronlink/tests/units/adapter-mobile.test.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @jest-environment node 3 | */ 4 | import { TronLinkAdapter } from '../../src/adapter.js'; 5 | import { MockTron } from './mock.js'; 6 | 7 | globalThis.window = { 8 | open: jest.fn(), 9 | location: { 10 | origin: '', 11 | pathname: '', 12 | search: '', 13 | hash: '', 14 | }, 15 | } as any; 16 | let adapter: TronLinkAdapter; 17 | 18 | beforeEach(() => { 19 | jest.useFakeTimers(); 20 | globalThis.navigator = {} as any; 21 | // @ts-ignore 22 | globalThis.navigator.userAgent = 'Android'; 23 | adapter = new TronLinkAdapter(); 24 | }); 25 | afterEach(() => { 26 | globalThis.window.location.href = ''; 27 | }); 28 | 29 | describe('when on mobile device browser', () => { 30 | test('will open TronLink app when tron is undefined ', async () => { 31 | jest.advanceTimersByTime(1000); 32 | try { 33 | await adapter.connect(); 34 | } catch { 35 | // 36 | } finally { 37 | expect(window.location.href).toContain('tronlinkoutside://'); 38 | } 39 | }); 40 | test('will not open TronLink app when tron exists', async () => { 41 | globalThis.window.tron = new MockTron(); 42 | adapter = new TronLinkAdapter(); 43 | jest.advanceTimersByTime(1000); 44 | try { 45 | await adapter.connect(); 46 | } catch { 47 | // 48 | } finally { 49 | expect(window.location.href).not.toContain('tronlinkoutside://'); 50 | } 51 | }); 52 | test('config.openTronLinkOnMobile should work fine', async () => { 53 | adapter = new TronLinkAdapter({ 54 | checkTimeout: 3000, 55 | openTronLinkAppOnMobile: false, 56 | }); 57 | try { 58 | await adapter.connect(); 59 | } catch { 60 | // 61 | } 62 | expect(window.location.href).not.toContain('tronlinkoutside://'); 63 | }); 64 | }); 65 | -------------------------------------------------------------------------------- /packages/adapters/tronlink/tests/units/utils.ts: -------------------------------------------------------------------------------- 1 | export async function wait() { 2 | const p = new Promise((resolve) => { 3 | setTimeout(resolve, 1000); 4 | }); 5 | jest.advanceTimersByTime(1000); 6 | await p; 7 | await p; 8 | } 9 | export const ONE_MINUTE = 62 * 1000; 10 | -------------------------------------------------------------------------------- /packages/adapters/tronlink/tsconfig.all.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../tsconfig.root.json", 3 | "references": [ 4 | { 5 | "path": "../abstract-adapter/tsconfig.all.json" 6 | }, 7 | { 8 | "path": "./tsconfig.cjs.json" 9 | }, 10 | { 11 | "path": "./tsconfig.esm.json" 12 | } 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /packages/adapters/tronlink/tsconfig.cjs.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../tsconfig.cjs.json", 3 | "include": ["src"], 4 | "compilerOptions": { 5 | "outDir": "lib/cjs" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /packages/adapters/tronlink/tsconfig.esm.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../tsconfig.esm.json", 3 | "include": ["src"], 4 | "compilerOptions": { 5 | "outDir": "lib/esm", 6 | "declarationDir": "lib/types" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /packages/adapters/walletconnect/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright (c) 2022-Present, tronprotocol 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | -------------------------------------------------------------------------------- /packages/adapters/walletconnect/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@tronweb3/tronwallet-adapter-walletconnect", 3 | "version": "1.0.6", 4 | "description": "Wallet adapter for WalletConnect wallet.", 5 | "keywords": [ 6 | "TRON", 7 | "TronWeb", 8 | "walletconnect" 9 | ], 10 | "author": "tronprotocol", 11 | "repository": { 12 | "type": "git", 13 | "url": "https://github.com/tronprotocol/tronwallet-adapter" 14 | }, 15 | "license": "MIT", 16 | "type": "module", 17 | "sideEffects": false, 18 | "engines": { 19 | "node": ">=16", 20 | "pnpm": ">=7" 21 | }, 22 | "main": "./lib/cjs/index.js", 23 | "module": "./lib/esm/index.js", 24 | "types": "./lib/types/index.d.ts", 25 | "exports": { 26 | "require": "./lib/cjs/index.js", 27 | "import": "./lib/esm/index.js", 28 | "types": "./lib/types/index.d.ts" 29 | }, 30 | "files": [ 31 | "lib", 32 | "src", 33 | "LICENSE" 34 | ], 35 | "publishConfig": { 36 | "access": "public" 37 | }, 38 | "scripts": { 39 | "clean": "shx mkdir -p lib && shx rm -rf lib", 40 | "package": "shx echo '{ \"type\": \"commonjs\" }' > lib/cjs/package.json", 41 | "build:umd": "node ../../../scripts/build-umd.js" 42 | }, 43 | "dependencies": { 44 | "@tronweb3/tronwallet-abstract-adapter": "workspace:^", 45 | "@tronweb3/walletconnect-tron": "2.0.0", 46 | "@wagmi/core": "^1.1.0", 47 | "@walletconnect/sign-client": "^2.1.4", 48 | "@walletconnect/types": "^2.1.4", 49 | "viem": "^0.3.50" 50 | }, 51 | "devDependencies": { 52 | "shx": "^0.3.4" 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /packages/adapters/walletconnect/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './adapter.js'; 2 | -------------------------------------------------------------------------------- /packages/adapters/walletconnect/tsconfig.all.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../tsconfig.root.json", 3 | "references": [ 4 | { 5 | "path": "./tsconfig.cjs.json" 6 | }, 7 | { 8 | "path": "./tsconfig.esm.json" 9 | } 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /packages/adapters/walletconnect/tsconfig.cjs.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../tsconfig.cjs.json", 3 | "include": ["src"], 4 | "compilerOptions": { 5 | "outDir": "lib/cjs", 6 | "skipLibCheck": true 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /packages/adapters/walletconnect/tsconfig.esm.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../tsconfig.esm.json", 3 | "include": ["src"], 4 | "compilerOptions": { 5 | "outDir": "lib/esm", 6 | "skipLibCheck": true, 7 | "declarationDir": "lib/types" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /packages/react/react-hooks/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright (c) 2022-Present, tronprotocol 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | -------------------------------------------------------------------------------- /packages/react/react-hooks/jest.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('ts-jest').JestConfigWithTsJest} */ 2 | export default { 3 | preset: 'ts-jest', 4 | testEnvironment: 'jsdom', 5 | transform: { 6 | '\\.tsx?$': [ 7 | 'ts-jest', 8 | { 9 | useESM: true, 10 | }, 11 | ], 12 | }, 13 | moduleNameMapper: { 14 | '(.+)\\.js': '$1', 15 | }, 16 | globals: { 17 | IS_REACT_ACT_ENVIRONMENT: true, 18 | }, 19 | extensionsToTreatAsEsm: ['.ts'], 20 | }; 21 | -------------------------------------------------------------------------------- /packages/react/react-hooks/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@tronweb3/tronwallet-adapter-react-hooks", 3 | "version": "1.1.7", 4 | "description": "A `useWallet()` hook to make it easy to interact with Tron wallets.", 5 | "keywords": [ 6 | "TRON", 7 | "TronWeb", 8 | "adapter" 9 | ], 10 | "author": "tronprotocol", 11 | "repository": { 12 | "type": "git", 13 | "url": "https://github.com/tronprotocol/tronwallet-adapter" 14 | }, 15 | "license": "MIT", 16 | "type": "module", 17 | "sideEffects": false, 18 | "engines": { 19 | "node": ">=16", 20 | "pnpm": ">=7" 21 | }, 22 | "main": "./lib/cjs/index.js", 23 | "module": "./lib/esm/index.js", 24 | "types": "./lib/types/index.d.ts", 25 | "exports": { 26 | "require": "./lib/cjs/index.js", 27 | "import": "./lib/esm/index.js", 28 | "types": "./lib/types/index.d.ts" 29 | }, 30 | "files": [ 31 | "lib", 32 | "src", 33 | "LICENSE" 34 | ], 35 | "publishConfig": { 36 | "access": "public" 37 | }, 38 | "scripts": { 39 | "clean": "shx mkdir -p lib && shx rm -rf lib", 40 | "package": "shx echo '{ \"type\": \"commonjs\" }' > lib/cjs/package.json", 41 | "test": "jest" 42 | }, 43 | "peerDependencies": { 44 | "react": "*", 45 | "react-dom": "*" 46 | }, 47 | "dependencies": { 48 | "@tronweb3/tronwallet-abstract-adapter": "workspace:^", 49 | "@tronweb3/tronwallet-adapter-tronlink": "workspace:^" 50 | }, 51 | "devDependencies": { 52 | "@types/react": "^18.0.26", 53 | "@types/react-dom": "^18.0.6", 54 | "jest-localstorage-mock": "^2.4.22", 55 | "react": "^18.2.0", 56 | "react-dom": "^18.2.0", 57 | "shx": "^0.3.4" 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /packages/react/react-hooks/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './useLocalStorage.js'; 2 | export * from './useWallet.js'; 3 | export * from './WalletProvider.js'; 4 | -------------------------------------------------------------------------------- /packages/react/react-hooks/src/useLocalStorage.ts: -------------------------------------------------------------------------------- 1 | import type { Dispatch, SetStateAction } from 'react'; 2 | import { useEffect, useRef, useState } from 'react'; 3 | import { isInBrowser } from '@tronweb3/tronwallet-abstract-adapter'; 4 | 5 | export function useLocalStorage(key: string, defaultState: T): [T, Dispatch>] { 6 | const [state, setState] = useState(() => { 7 | try { 8 | const value = localStorage.getItem(key); 9 | if (value) return JSON.parse(value) as T; 10 | } catch (error: unknown) { 11 | if (isInBrowser()) { 12 | console.error(error); 13 | } 14 | } 15 | 16 | return defaultState; 17 | }); 18 | 19 | const isFirstRender = useRef(true); 20 | useEffect(() => { 21 | if (isFirstRender.current) { 22 | isFirstRender.current = false; 23 | return; 24 | } 25 | try { 26 | if (state === null) { 27 | localStorage.removeItem(key); 28 | } else { 29 | localStorage.setItem(key, JSON.stringify(state)); 30 | } 31 | } catch (error: any) { 32 | if (isInBrowser()) { 33 | console.error(error); 34 | } 35 | } 36 | }, [state, key]); 37 | 38 | return [state, setState]; 39 | } 40 | -------------------------------------------------------------------------------- /packages/react/react-hooks/tsconfig.all.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../tsconfig.root.json", 3 | "references": [ 4 | { 5 | "path": "./tsconfig.cjs.json" 6 | }, 7 | { 8 | "path": "./tsconfig.esm.json" 9 | } 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /packages/react/react-hooks/tsconfig.cjs.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../tsconfig.cjs.json", 3 | "include": ["src"], 4 | "compilerOptions": { 5 | "outDir": "lib/cjs", 6 | "jsx": "react" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /packages/react/react-hooks/tsconfig.esm.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../tsconfig.esm.json", 3 | "include": ["src"], 4 | "compilerOptions": { 5 | "outDir": "lib/esm", 6 | "declarationDir": "lib/types", 7 | "jsx": "react" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /packages/react/react-ui/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright (c) 2022-Present, tronprotocol 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | -------------------------------------------------------------------------------- /packages/react/react-ui/action-button.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tronprotocol/tronwallet-adapter/3b2bdf995a7c3d834a0e3bb5ec71565cd961b2b0/packages/react/react-ui/action-button.gif -------------------------------------------------------------------------------- /packages/react/react-ui/jest.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('ts-jest').JestConfigWithTsJest} */ 2 | export default { 3 | preset: 'ts-jest', 4 | testEnvironment: 'jsdom', 5 | transform: { 6 | '\\.[t]sx?$': [ 7 | 'ts-jest', 8 | { 9 | useESM: true, 10 | }, 11 | ], 12 | }, 13 | moduleNameMapper: { 14 | '(.+)\\.js': '$1', 15 | }, 16 | extensionsToTreatAsEsm: ['.ts'], 17 | }; 18 | -------------------------------------------------------------------------------- /packages/react/react-ui/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@tronweb3/tronwallet-adapter-react-ui", 3 | "version": "1.1.8", 4 | "description": "A set of out-of-the-box components to make it easy to interact with Tron wallets.", 5 | "keywords": [ 6 | "TRON", 7 | "TronWeb", 8 | "adapter" 9 | ], 10 | "author": "tronprotocol", 11 | "repository": { 12 | "type": "git", 13 | "url": "https://github.com/tronprotocol/tronwallet-adapter" 14 | }, 15 | "license": "MIT", 16 | "type": "module", 17 | "sideEffects": false, 18 | "engines": { 19 | "node": ">=16", 20 | "pnpm": ">=7" 21 | }, 22 | "main": "./lib/cjs/index.js", 23 | "module": "./lib/esm/index.js", 24 | "types": "./lib/types/index.d.ts", 25 | "exports": { 26 | ".": { 27 | "import": "./lib/esm/index.js", 28 | "require": "./lib/cjs/index.js", 29 | "types": "./lib/types/index.d.ts" 30 | }, 31 | "./style.css": "./style.css" 32 | }, 33 | "files": [ 34 | "lib", 35 | "src", 36 | "LICENSE", 37 | "style.css" 38 | ], 39 | "publishConfig": { 40 | "access": "public" 41 | }, 42 | "scripts": { 43 | "clean": "shx mkdir -p lib && shx rm -rf lib", 44 | "package": "shx echo '{ \"type\": \"commonjs\" }' > lib/cjs/package.json", 45 | "test": "jest" 46 | }, 47 | "peerDependencies": { 48 | "react": "*", 49 | "react-dom": "*" 50 | }, 51 | "dependencies": { 52 | "@tronweb3/tronwallet-abstract-adapter": "workspace:^", 53 | "@tronweb3/tronwallet-adapter-react-hooks": "workspace:^" 54 | }, 55 | "devDependencies": { 56 | "@testing-library/jest-dom": "^5.16.5", 57 | "@testing-library/react": "^13.4.0", 58 | "@testing-library/user-event": "^13.5.0", 59 | "@tronweb3/tronwallet-adapter-tronlink": "workspace:^", 60 | "@types/jest": "^27.5.2", 61 | "@types/react": "^18.0.26", 62 | "@types/react-dom": "^18.0.0", 63 | "@types/testing-library__jest-dom": "^5.14.5", 64 | "jest": "^29.3.1", 65 | "jest-environment-jsdom": "^29.3.1", 66 | "jest-localstorage-mock": "^2.4.22", 67 | "react": "^18.0.0", 68 | "react-dom": "^18.0.0", 69 | "shx": "^0.3.4" 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /packages/react/react-ui/src/Button.tsx: -------------------------------------------------------------------------------- 1 | import React, { useRef } from 'react'; 2 | import type { CSSProperties, FC, MouseEvent, PropsWithChildren } from 'react'; 3 | 4 | export type ButtonProps = PropsWithChildren<{ 5 | className?: string; 6 | disabled?: boolean; 7 | onClick?: (e: MouseEvent) => void; 8 | style?: CSSProperties; 9 | tabIndex?: number; 10 | icon?: string; 11 | }>; 12 | 13 | export const Button: FC = ({ children, onClick, className = '', tabIndex = 0, icon, ...rest }) => { 14 | const ref = useRef(null); 15 | function handleClick(event: MouseEvent) { 16 | onClick?.(event); 17 | setTimeout(() => { 18 | ref.current?.blur(); 19 | }, 300); 20 | } 21 | return ( 22 | 36 | ); 37 | }; 38 | -------------------------------------------------------------------------------- /packages/react/react-ui/src/Collapse.tsx: -------------------------------------------------------------------------------- 1 | import type { FC, PropsWithChildren } from 'react'; 2 | import React, { useLayoutEffect, useRef, useEffect, useState } from 'react'; 3 | 4 | export type CollapseProps = PropsWithChildren<{ 5 | isOpen: boolean; 6 | id?: string; 7 | className?: string; 8 | transition?: string; 9 | onMouseEnter?: () => void; 10 | onMouseLeave?: () => void; 11 | }>; 12 | 13 | export const Collapse: FC = function ({ 14 | children, 15 | className, 16 | transition = 'height 250ms ease-out', 17 | isOpen, 18 | onMouseEnter, 19 | onMouseLeave, 20 | }) { 21 | const initialState = { height: '0px', transition }; 22 | const wrapRef = useRef(null); 23 | const [style, setStyle] = useState(initialState); 24 | 25 | useEffect( 26 | function () { 27 | setStyle((style) => ({ ...style, transition })); 28 | }, 29 | [transition] 30 | ); 31 | 32 | function open() { 33 | if (!wrapRef.current) { 34 | return; 35 | } 36 | setStyle((style) => ({ 37 | ...style, 38 | height: wrapRef.current?.scrollHeight + 'px', 39 | })); 40 | } 41 | 42 | function close() { 43 | if (!wrapRef.current) { 44 | return; 45 | } 46 | setStyle((style) => ({ 47 | ...style, 48 | height: '0px', 49 | })); 50 | } 51 | 52 | useLayoutEffect(() => { 53 | if (isOpen) { 54 | open(); 55 | } else { 56 | close(); 57 | } 58 | }, [isOpen]); 59 | 60 | return ( 61 |
71 | {children} 72 |
73 | ); 74 | }; 75 | -------------------------------------------------------------------------------- /packages/react/react-ui/src/Modal/ReactPortal.tsx: -------------------------------------------------------------------------------- 1 | import { useState, useLayoutEffect } from 'react'; 2 | import type { PropsWithChildren, FC } from 'react'; 3 | import { createPortal } from 'react-dom'; 4 | 5 | function createWrapperAndAppendToBody(wrapperId: string) { 6 | const wrapperElement = document.createElement('div'); 7 | wrapperElement.setAttribute('id', wrapperId); 8 | wrapperElement.style.position = 'relative'; 9 | document.body.appendChild(wrapperElement); 10 | return wrapperElement; 11 | } 12 | 13 | type ReactPortalProps = PropsWithChildren<{ 14 | wrapperId: string; 15 | }>; 16 | export const ReactPortal: FC = function ({ children, wrapperId = 'react-portal-wrapper' }) { 17 | const [wrapperElement, setWrapperElement] = useState(null); 18 | 19 | useLayoutEffect(() => { 20 | let element: HTMLElement | null = document.getElementById(wrapperId); 21 | let systemCreated = false; 22 | // if element is not found with wrapperId or wrapperId is not provided, 23 | // create and append to body 24 | if (!element) { 25 | systemCreated = true; 26 | element = createWrapperAndAppendToBody(wrapperId); 27 | } 28 | setWrapperElement(element); 29 | 30 | return () => { 31 | // delete the programatically created element 32 | if (systemCreated && element?.parentNode) { 33 | element.parentNode.removeChild(element); 34 | } 35 | }; 36 | }, [wrapperId]); 37 | 38 | // wrapperElement state will be null on very first render. 39 | if (wrapperElement === null) return null; 40 | 41 | return createPortal(children, wrapperElement); 42 | }; 43 | -------------------------------------------------------------------------------- /packages/react/react-ui/src/WalletConnectButton.tsx: -------------------------------------------------------------------------------- 1 | import { useWallet } from '@tronweb3/tronwallet-adapter-react-hooks'; 2 | import type { FC, MouseEvent } from 'react'; 3 | import React, { useCallback, useMemo } from 'react'; 4 | import type { ButtonProps } from './Button.js'; 5 | import { Button } from './Button.js'; 6 | 7 | export const WalletConnectButton: FC = ({ children, disabled, onClick, ...props }) => { 8 | const { wallet, connect, connecting, connected } = useWallet(); 9 | 10 | const handleClick = useCallback( 11 | async (event: MouseEvent) => { 12 | if (onClick) onClick(event); 13 | // eslint-disable-next-line @typescript-eslint/no-empty-function 14 | if (!event.defaultPrevented) { 15 | await connect(); 16 | } 17 | }, 18 | [onClick, connect] 19 | ); 20 | 21 | const content = useMemo(() => { 22 | if (children) return children; 23 | if (connecting) return 'Connecting ...'; 24 | if (connected) return 'Connected'; 25 | if (wallet) return 'Connect'; 26 | return 'Connect Wallet'; 27 | }, [children, connecting, connected, wallet]); 28 | 29 | return ( 30 | 40 | ); 41 | }; 42 | -------------------------------------------------------------------------------- /packages/react/react-ui/src/WalletDisconnectButton.tsx: -------------------------------------------------------------------------------- 1 | import { useWallet } from '@tronweb3/tronwallet-adapter-react-hooks'; 2 | import type { FC, MouseEventHandler } from 'react'; 3 | import React, { useCallback, useMemo } from 'react'; 4 | import type { ButtonProps } from './Button.js'; 5 | import { Button } from './Button.js'; 6 | 7 | export const WalletDisconnectButton: FC = ({ children, disabled, onClick, ...props }) => { 8 | const { wallet, disconnect, disconnecting, connected } = useWallet(); 9 | 10 | const handleClick: MouseEventHandler = useCallback( 11 | (event) => { 12 | if (onClick) onClick(event); 13 | // eslint-disable-next-line @typescript-eslint/no-empty-function 14 | if (!event.defaultPrevented) disconnect().catch(() => {}); 15 | }, 16 | [onClick, disconnect] 17 | ); 18 | 19 | const content = useMemo(() => { 20 | if (children) return children; 21 | if (disconnecting) return 'Disconnecting ...'; 22 | if (wallet) return 'Disconnect'; 23 | return 'Disconnect Wallet'; 24 | }, [children, disconnecting, wallet]); 25 | 26 | return ( 27 | 36 | ); 37 | }; 38 | -------------------------------------------------------------------------------- /packages/react/react-ui/src/WalletItem.tsx: -------------------------------------------------------------------------------- 1 | import { AdapterState } from '@tronweb3/tronwallet-abstract-adapter'; 2 | import type { Wallet } from '@tronweb3/tronwallet-adapter-react-hooks'; 3 | import type { FC } from 'react'; 4 | import React from 'react'; 5 | import { Button } from './Button.js'; 6 | 7 | export interface WalletItemProps { 8 | onClick: () => void; 9 | wallet: Wallet; 10 | } 11 | 12 | export const WalletItem: FC = ({ onClick, wallet }) => { 13 | return ( 14 |
15 | 19 |
20 | ); 21 | }; 22 | -------------------------------------------------------------------------------- /packages/react/react-ui/src/WalletModalProvider.tsx: -------------------------------------------------------------------------------- 1 | import React, { useState } from 'react'; 2 | import { WalletSelectModal } from './Modal/WalletSelectModal.js'; 3 | import { WalletModalContext } from './useWalletModal.js'; 4 | 5 | export function WalletModalProvider({ children, ...props }: any) { 6 | const [visible, setVisible] = useState(false); 7 | return ( 8 | 14 | {children} 15 | { setVisible(false)} {...props} />} 16 | 17 | ); 18 | } 19 | -------------------------------------------------------------------------------- /packages/react/react-ui/src/WalletSelectButton.tsx: -------------------------------------------------------------------------------- 1 | import React, { useCallback } from 'react'; 2 | import type { MouseEvent, FC } from 'react'; 3 | import { Button } from './Button.js'; 4 | import type { ButtonProps } from './Button.js'; 5 | import { useWalletModal } from './useWalletModal.js'; 6 | 7 | export const WalletSelectButton: FC = function ({ children = 'Select Wallet', onClick, ...props }) { 8 | const { visible, setVisible } = useWalletModal(); 9 | 10 | const handleClick = useCallback( 11 | (event: MouseEvent) => { 12 | if (onClick) onClick(event); 13 | if (!event.defaultPrevented) setVisible(!visible); 14 | }, 15 | [onClick, setVisible, visible] 16 | ); 17 | 18 | return ( 19 | 22 | ); 23 | }; 24 | -------------------------------------------------------------------------------- /packages/react/react-ui/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './Collapse.js'; 2 | export * from './Button.js'; 3 | export * from './Modal/WalletSelectModal.js'; 4 | export * from './WalletConnectButton.js'; 5 | export * from './WalletDisconnectButton.js'; 6 | export * from './WalletItem.js'; 7 | export * from './WalletActionButton.js'; 8 | export * from './WalletSelectButton.js'; 9 | export * from './useWalletModal.js'; 10 | export * from './WalletModalProvider.js'; 11 | -------------------------------------------------------------------------------- /packages/react/react-ui/src/useWalletModal.tsx: -------------------------------------------------------------------------------- 1 | import { createContext, useContext } from 'react'; 2 | 3 | export interface WalletModalContextProps { 4 | visible: boolean; 5 | setVisible: (open: boolean) => void; 6 | } 7 | 8 | const DEFAULT_VALUE = { 9 | // eslint-disable-next-line @typescript-eslint/no-unused-vars 10 | setVisible(_open: boolean) { 11 | printError(); 12 | }, 13 | visible: false, 14 | }; 15 | Object.defineProperty(DEFAULT_VALUE, 'visible', { 16 | get() { 17 | printError(); 18 | return false; 19 | }, 20 | }); 21 | 22 | function printError() { 23 | console.error('WalletModalProvider is not provided.' + 'Please wrap your components with WalletModalProvider.'); 24 | } 25 | 26 | export const WalletModalContext = createContext(DEFAULT_VALUE as any); 27 | 28 | export function useWalletModal(): WalletModalContextProps { 29 | return useContext(WalletModalContext); 30 | } 31 | -------------------------------------------------------------------------------- /packages/react/react-ui/src/utils.tsx: -------------------------------------------------------------------------------- 1 | export function copyData(copyText: string) { 2 | const textArea = document.createElement('textarea'); 3 | textArea.value = copyText; 4 | document.body.appendChild(textArea); 5 | textArea.select(); 6 | textArea.style.position = 'fixed'; 7 | textArea.style.top = '-9999px'; 8 | textArea.style.left = '-9999px'; 9 | document.execCommand('copy'); 10 | textArea.blur(); 11 | } 12 | -------------------------------------------------------------------------------- /packages/react/react-ui/tests/units/MockTronLink.ts: -------------------------------------------------------------------------------- 1 | import type { ReqestAccountsResponse, TronLinkWallet, TronWeb } from '@tronweb3/tronwallet-adapter-tronlink'; 2 | jest.useFakeTimers(); 3 | export class MockTronLink implements TronLinkWallet { 4 | ready: boolean; 5 | 6 | address: string; 7 | 8 | constructor() { 9 | this.address = 'address'; 10 | this.ready = true; 11 | } 12 | get tronWeb() { 13 | return { 14 | ready: true, 15 | defaultAddress: { 16 | base58: this.address, 17 | }, 18 | fullNode: { host: '' }, 19 | solidityNode: { host: '' }, 20 | eventServer: { host: '' }, 21 | toHex(m: string) { 22 | return m; 23 | }, 24 | trx: { 25 | sign(message: any) { 26 | return message; 27 | }, 28 | }, 29 | } as TronWeb; 30 | } 31 | 32 | request() { 33 | return new Promise((resolve) => { 34 | setTimeout(() => { 35 | resolve({ 36 | code: 200, 37 | message: 'success', 38 | }); 39 | }, 200); 40 | }); 41 | } 42 | 43 | setReadyState(state: boolean) { 44 | this.ready = state; 45 | this.tronWeb.ready = state; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /packages/react/react-ui/tests/units/WalletSelectButton.test.tsx: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/no-non-null-assertion */ 2 | import type { FC, PropsWithChildren } from 'react'; 3 | import React from 'react'; 4 | import { fireEvent, render, act, waitFor } from '@testing-library/react'; 5 | import '@testing-library/jest-dom'; 6 | import 'jest-localstorage-mock'; 7 | 8 | import type { ButtonProps } from '../../src/Button.js'; 9 | import { WalletProvider } from '@tronweb3/tronwallet-adapter-react-hooks'; 10 | import { WalletModalProvider } from '../../src/WalletModalProvider.js'; 11 | import { MockTronLink } from './MockTronLink.js'; 12 | import { WalletSelectButton } from '../../src/WalletSelectButton.js'; 13 | 14 | const Providers: FC = function (props) { 15 | return ( 16 | 17 | {props.children} 18 | 19 | ); 20 | }; 21 | const makeSut = (props: ButtonProps = {}) => render(, { wrapper: Providers }); 22 | 23 | window.open = jest.fn(); 24 | beforeEach(() => { 25 | localStorage.clear(); 26 | window.tronLink = new MockTronLink(); 27 | window.tronWeb = window.tronLink.tronWeb; 28 | }); 29 | describe('WalletSelectButton', () => { 30 | test('should work fine with basic usage', () => { 31 | const { container } = makeSut({}); 32 | const button = container.querySelector('button'); 33 | expect(button).toBeInTheDocument(); 34 | expect(button?.disabled).toBe(false); 35 | expect(button?.textContent).toEqual('Select Wallet'); 36 | }); 37 | 38 | test('should work fine when select', async () => { 39 | jest.useFakeTimers(); 40 | const { getByTestId, getByText, queryByTestId } = makeSut({}); 41 | await waitFor(() => { 42 | jest.advanceTimersByTime(500); 43 | }); 44 | act(() => { 45 | fireEvent.click(getByTestId('wallet-select-button')); 46 | }); 47 | 48 | expect(getByTestId('wallet-select-modal')).toBeInTheDocument(); 49 | fireEvent.click(getByText('TronLink')); 50 | await waitFor(() => { 51 | expect(queryByTestId('wallet-select-modal')).toBeNull(); 52 | }); 53 | expect(localStorage.getItem('tronAdapterName')).toEqual(`"TronLink"`); 54 | }); 55 | }); 56 | -------------------------------------------------------------------------------- /packages/react/react-ui/tsconfig.all.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../tsconfig.root.json", 3 | "references": [ 4 | { 5 | "path": "../../adapters/abstract-adapter/tsconfig.all.json" 6 | }, 7 | { 8 | "path": "../../adapters/adapters/tsconfig.all.json" 9 | }, 10 | { 11 | "path": "../../react/react-hooks/tsconfig.all.json" 12 | }, 13 | { 14 | "path": "./tsconfig.cjs.json" 15 | }, 16 | { 17 | "path": "./tsconfig.esm.json" 18 | } 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /packages/react/react-ui/tsconfig.cjs.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../tsconfig.cjs.json", 3 | "include": ["src"], 4 | "exclude": ["src/**/__tests__"], 5 | "compilerOptions": { 6 | "outDir": "lib/cjs", 7 | "jsx": "react" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /packages/react/react-ui/tsconfig.esm.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../tsconfig.esm.json", 3 | "include": ["src"], 4 | "exclude": ["src/**/__tests__"], 5 | "compilerOptions": { 6 | "outDir": "lib/esm", 7 | "declarationDir": "lib/types", 8 | "jsx": "react" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /packages/vue/vue-hooks/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright (c) 2022-Present, tronprotocol 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | -------------------------------------------------------------------------------- /packages/vue/vue-hooks/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@tronweb3/tronwallet-adapter-vue-hooks", 3 | "version": "1.0.0", 4 | "description": "A `useWallet()` hook to make it easy to interact with Tron wallets.", 5 | "keywords": [ 6 | "TRON", 7 | "TronWeb", 8 | "adapter" 9 | ], 10 | "author": "tronprotocol", 11 | "repository": { 12 | "type": "git", 13 | "url": "https://github.com/tronprotocol/tronwallet-adapter" 14 | }, 15 | "license": "MIT", 16 | "type": "module", 17 | "sideEffects": false, 18 | "engines": { 19 | "node": ">=16", 20 | "pnpm": ">=7" 21 | }, 22 | "main": "./lib/cjs/index.js", 23 | "module": "./lib/esm/index.js", 24 | "types": "./lib/types/index.d.ts", 25 | "exports": { 26 | "require": "./lib/cjs/index.js", 27 | "import": "./lib/esm/index.js", 28 | "types": "./lib/types/index.d.ts" 29 | }, 30 | "files": [ 31 | "lib", 32 | "src", 33 | "LICENSE" 34 | ], 35 | "publishConfig": { 36 | "access": "public" 37 | }, 38 | "scripts": { 39 | "clean": "shx mkdir -p lib && shx rm -rf lib", 40 | "package": "shx echo '{ \"type\": \"commonjs\" }' > lib/cjs/package.json", 41 | "test": "vitest run" 42 | }, 43 | "dependencies": { 44 | "@tronweb3/tronwallet-abstract-adapter": "workspace:^", 45 | "@tronweb3/tronwallet-adapter-tronlink": "workspace:^" 46 | }, 47 | "devDependencies": { 48 | "jsdom": "^23.0.1", 49 | "shx": "^0.3.4", 50 | "vitest": "^1.0.2", 51 | "vue": "^3.3.11", 52 | "@vue/test-utils": "^2.4.3" 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /packages/vue/vue-hooks/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './useLocalStorage.js'; 2 | export * from './useWallet.js'; 3 | export * from './WalletProvider.js'; 4 | -------------------------------------------------------------------------------- /packages/vue/vue-hooks/src/useLocalStorage.ts: -------------------------------------------------------------------------------- 1 | import { isInBrowser } from '@tronweb3/tronwallet-abstract-adapter'; 2 | import { shallowRef, watch } from 'vue'; 3 | import type { Ref, ShallowRef } from 'vue'; 4 | 5 | export function useLocalStorage(key: Ref, defaultState: T): [ShallowRef, (state: T) => void] { 6 | const state = shallowRef(defaultState); 7 | try { 8 | const value = localStorage.getItem(key.value); 9 | if (value) { 10 | state.value = JSON.parse(value); 11 | } 12 | } catch (error: unknown) { 13 | if (isInBrowser()) { 14 | console.error(error); 15 | } 16 | } 17 | 18 | const setState = (v: T) => { 19 | state.value = v; 20 | }; 21 | 22 | watch( 23 | [state, key], 24 | ([state, key]) => { 25 | try { 26 | if (state === null) { 27 | localStorage.removeItem(key); 28 | } else { 29 | localStorage.setItem(key, JSON.stringify(state)); 30 | } 31 | } catch (error: any) { 32 | if (isInBrowser()) { 33 | console.error(error); 34 | } 35 | } 36 | }, 37 | { 38 | immediate: false, 39 | } 40 | ); 41 | 42 | return [state, setState]; 43 | } 44 | -------------------------------------------------------------------------------- /packages/vue/vue-hooks/tsconfig.all.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../tsconfig.root.json", 3 | "references": [ 4 | { 5 | "path": "./tsconfig.cjs.json" 6 | }, 7 | { 8 | "path": "./tsconfig.esm.json" 9 | } 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /packages/vue/vue-hooks/tsconfig.cjs.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../tsconfig.cjs.json", 3 | "include": ["src"], 4 | "compilerOptions": { 5 | "outDir": "lib/cjs", 6 | "jsx": "preserve" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /packages/vue/vue-hooks/tsconfig.esm.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../tsconfig.esm.json", 3 | "include": ["src"], 4 | "compilerOptions": { 5 | "outDir": "lib/esm", 6 | "declarationDir": "lib/types", 7 | "jsx": "preserve" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /packages/vue/vue-hooks/vitest.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vitest/config'; 2 | 3 | export default defineConfig({ 4 | test: { 5 | server: { 6 | deps: { 7 | inline: ['chai', 'get-func-name'], 8 | }, 9 | }, 10 | environment: 'jsdom', 11 | }, 12 | }); 13 | -------------------------------------------------------------------------------- /packages/vue/vue-ui/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright (c) 2022-Present, tronprotocol 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | -------------------------------------------------------------------------------- /packages/vue/vue-ui/action-button.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tronprotocol/tronwallet-adapter/3b2bdf995a7c3d834a0e3bb5ec71565cd961b2b0/packages/vue/vue-ui/action-button.gif -------------------------------------------------------------------------------- /packages/vue/vue-ui/babel.config.cjs.json: -------------------------------------------------------------------------------- 1 | { 2 | "plugins": ["@vue/babel-plugin-jsx"], 3 | "presets": ["@babel/preset-env", "@babel/preset-typescript"], 4 | "sourceMaps": true 5 | } 6 | -------------------------------------------------------------------------------- /packages/vue/vue-ui/babel.config.esm.json: -------------------------------------------------------------------------------- 1 | { 2 | "plugins": ["@vue/babel-plugin-jsx"], 3 | "presets": [["@babel/preset-env", { "modules": false }], "@babel/preset-typescript"], 4 | "sourceMaps": true, 5 | "targets": { 6 | "esmodules": true 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /packages/vue/vue-ui/src/Button.tsx: -------------------------------------------------------------------------------- 1 | import type { PropType, CSSProperties } from 'vue'; 2 | import { defineComponent, ref } from 'vue'; 3 | export const ButtonProps = { 4 | className: { 5 | type: String, 6 | default: '', 7 | }, 8 | disabled: { 9 | type: Boolean, 10 | default: false, 11 | }, 12 | style: { 13 | type: Object as PropType, 14 | default: () => ({}), 15 | }, 16 | tabIndex: { 17 | type: Number, 18 | default: 0, 19 | }, 20 | icon: { 21 | type: String, 22 | default: '', 23 | }, 24 | onClick: { 25 | type: Function, 26 | required: false, 27 | }, 28 | }; 29 | export const Button = defineComponent({ 30 | props: ButtonProps, 31 | setup(props, { slots }) { 32 | const buttonRef = ref(); 33 | 34 | function handleClick() { 35 | props.onClick?.(); 36 | setTimeout(() => { 37 | buttonRef.value?.blur(); 38 | }, 300); 39 | } 40 | return () => ( 41 | 57 | ); 58 | }, 59 | }); 60 | -------------------------------------------------------------------------------- /packages/vue/vue-ui/src/Modal/VuePortal.tsx: -------------------------------------------------------------------------------- 1 | import { defineComponent, Teleport } from 'vue'; 2 | 3 | export const VuePortal = defineComponent({ 4 | props: { 5 | wrapperId: { 6 | type: String, 7 | default: 'vue-portal-wrapper', 8 | }, 9 | }, 10 | setup(props, { slots }) { 11 | return () => {() => (slots.default ? slots.default() : '')}; 12 | }, 13 | }); 14 | -------------------------------------------------------------------------------- /packages/vue/vue-ui/src/WalletConnectButton.tsx: -------------------------------------------------------------------------------- 1 | import { useWallet } from '@tronweb3/tronwallet-adapter-vue-hooks'; 2 | import { computed, defineComponent } from 'vue'; 3 | import { Button, ButtonProps } from './Button.js'; 4 | export const WalletConnectButton = defineComponent({ 5 | props: ButtonProps, 6 | setup(props, { slots }) { 7 | const { wallet, connect, connecting, connected } = useWallet(); 8 | async function handleClick() { 9 | let preventDefault = false; 10 | if (props.onClick) { 11 | preventDefault = await props.onClick(); 12 | } 13 | // eslint-disable-next-line @typescript-eslint/no-empty-function 14 | if (!preventDefault) { 15 | await connect().catch(() => { 16 | // 17 | }); 18 | } 19 | } 20 | 21 | const content = computed(() => { 22 | return slots.default 23 | ? slots.default() 24 | : connecting.value 25 | ? 'Connecting ...' 26 | : connected.value 27 | ? 'Connected' 28 | : wallet.value 29 | ? 'Connect' 30 | : 'Connect Wallet'; 31 | }); 32 | 33 | return () => ( 34 | 43 | ); 44 | }, 45 | }); 46 | -------------------------------------------------------------------------------- /packages/vue/vue-ui/src/WalletDisconnectButton.tsx: -------------------------------------------------------------------------------- 1 | import { useWallet } from '@tronweb3/tronwallet-adapter-vue-hooks'; 2 | import { computed, defineComponent } from 'vue'; 3 | import { Button, ButtonProps } from './Button.js'; 4 | export const WalletDisconnectButton = defineComponent({ 5 | props: ButtonProps, 6 | setup(props, { slots }) { 7 | const { wallet, disconnect, disconnecting, connected } = useWallet(); 8 | async function handleClick() { 9 | let preventDefault = false; 10 | if (props.onClick) { 11 | preventDefault = await props.onClick(); 12 | } 13 | if (!preventDefault) { 14 | disconnect().catch(() => { 15 | // 16 | }); 17 | } 18 | } 19 | const content = computed(() => { 20 | if (slots.default) return slots.default(); 21 | if (disconnecting.value) return 'Disconnecting ...'; 22 | if (wallet.value) return 'Disconnect'; 23 | return 'Disconnect Wallet'; 24 | }); 25 | return () => ( 26 | 34 | ); 35 | }, 36 | }); 37 | -------------------------------------------------------------------------------- /packages/vue/vue-ui/src/WalletItem.tsx: -------------------------------------------------------------------------------- 1 | import { AdapterState } from '@tronweb3/tronwallet-abstract-adapter'; 2 | import type { Wallet } from '@tronweb3/tronwallet-adapter-vue-hooks'; 3 | import { defineComponent } from 'vue'; 4 | import type { PropType } from 'vue'; 5 | import { Button } from './Button.js'; 6 | 7 | export interface WalletItemProps { 8 | onClick: () => void; 9 | wallet: Wallet; 10 | } 11 | export const WalletItem = defineComponent({ 12 | props: { 13 | wallet: { 14 | type: Object as PropType, 15 | required: true, 16 | }, 17 | }, 18 | emits: ['click'], 19 | setup(props, { emit }) { 20 | function onClick() { 21 | emit('click'); 22 | } 23 | return () => ( 24 |
25 | 31 |
32 | ); 33 | }, 34 | }); 35 | -------------------------------------------------------------------------------- /packages/vue/vue-ui/src/WalletModalProvider.tsx: -------------------------------------------------------------------------------- 1 | import { defineComponent, provide, readonly, ref } from 'vue'; 2 | import { WalletSelectModal } from './Modal/WalletSelectModal.js'; 3 | export const WalletModalProvider = defineComponent({ 4 | setup(props, { slots }) { 5 | const visible = ref(false); 6 | function setVisible(v: boolean) { 7 | visible.value = v; 8 | } 9 | provide('TronWalletModalContext', { 10 | visible: readonly(visible), 11 | setVisible, 12 | }); 13 | return () => ( 14 | <> 15 | {slots.default ? slots.default() : ''} 16 | setVisible(false)}> 17 | 18 | ); 19 | }, 20 | }); 21 | -------------------------------------------------------------------------------- /packages/vue/vue-ui/src/WalletSelectButton.tsx: -------------------------------------------------------------------------------- 1 | import { Button } from './Button.js'; 2 | import { ButtonProps } from './Button.js'; 3 | import { useWalletModal } from './useWalletModal.js'; 4 | import { defineComponent } from 'vue'; 5 | 6 | export const WalletSelectButton = defineComponent({ 7 | props: ButtonProps, 8 | setup(props, { slots }) { 9 | const { visible, setVisible } = useWalletModal(); 10 | const handleClick = async () => { 11 | let preventDefault = false; 12 | if (props.onClick) { 13 | preventDefault = await props.onClick(); 14 | } 15 | if (!preventDefault) setVisible(!visible.value); 16 | }; 17 | return () => ( 18 | 21 | ); 22 | }, 23 | }); 24 | -------------------------------------------------------------------------------- /packages/vue/vue-ui/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './WalletActionButton/Collapse.js'; 2 | export * from './Button.js'; 3 | export * from './Modal/WalletSelectModal.js'; 4 | export * from './WalletConnectButton.js'; 5 | export * from './WalletDisconnectButton.js'; 6 | export * from './WalletItem.js'; 7 | export * from './WalletActionButton/WalletActionButton.js'; 8 | export * from './WalletSelectButton.js'; 9 | export * from './useWalletModal.js'; 10 | export * from './WalletModalProvider.js'; 11 | -------------------------------------------------------------------------------- /packages/vue/vue-ui/src/useWalletModal.tsx: -------------------------------------------------------------------------------- 1 | import type { Ref } from 'vue'; 2 | import { inject, readonly, ref } from 'vue'; 3 | 4 | export interface WalletModalContextProps { 5 | visible: Readonly>; 6 | setVisible: (open: boolean) => void; 7 | } 8 | 9 | const DEFAULT_VALUE = { 10 | // eslint-disable-next-line @typescript-eslint/no-unused-vars 11 | setVisible(_open: boolean) { 12 | printError(); 13 | }, 14 | visible: readonly(ref(false)), 15 | }; 16 | Object.defineProperty(DEFAULT_VALUE, 'visible', { 17 | get() { 18 | printError(); 19 | return false; 20 | }, 21 | }); 22 | 23 | function printError() { 24 | console.error('WalletModalProvider is not provided.' + 'Please wrap your components with WalletModalProvider.'); 25 | } 26 | 27 | export function useWalletModal(): WalletModalContextProps { 28 | const TronWalletModalContext = inject('TronWalletModalContext', DEFAULT_VALUE); 29 | return TronWalletModalContext; 30 | } 31 | -------------------------------------------------------------------------------- /packages/vue/vue-ui/src/utils.tsx: -------------------------------------------------------------------------------- 1 | export function copyData(copyText: string) { 2 | const textArea = document.createElement('textarea'); 3 | textArea.value = copyText; 4 | document.body.appendChild(textArea); 5 | textArea.select(); 6 | textArea.style.position = 'fixed'; 7 | textArea.style.top = '-9999px'; 8 | textArea.style.left = '-9999px'; 9 | document.execCommand('copy'); 10 | textArea.blur(); 11 | } 12 | 13 | export function createWrapperAndAppendToBody(wrapperId?: string) { 14 | if (!wrapperId) { 15 | wrapperId = `wallet-${String(Math.random()).replace('.', '')}`; 16 | } 17 | const wrapperElement = document.createElement('div'); 18 | wrapperElement.setAttribute('id', wrapperId); 19 | wrapperElement.style.position = 'relative'; 20 | document.body.appendChild(wrapperElement); 21 | return wrapperElement; 22 | } 23 | 24 | export function getRelatedPosition(child: HTMLElement, parent: HTMLElement) { 25 | let offsetParent: HTMLElement = child.offsetParent as HTMLElement; 26 | let left = 0, 27 | top = 0; 28 | while (offsetParent && offsetParent !== parent) { 29 | left += child.offsetLeft; 30 | top += child.offsetTop; 31 | child = offsetParent; 32 | offsetParent = child.offsetParent as HTMLElement; 33 | } 34 | left += child.offsetLeft; 35 | top += child.offsetTop; 36 | 37 | return { left, top }; 38 | } 39 | -------------------------------------------------------------------------------- /packages/vue/vue-ui/tests/units/MockTronLink.ts: -------------------------------------------------------------------------------- 1 | import { vi } from 'vitest'; 2 | import type { ReqestAccountsResponse, TronLinkWallet, TronWeb } from '@tronweb3/tronwallet-adapter-tronlink'; 3 | vi.useFakeTimers(); 4 | export class MockTronLink implements TronLinkWallet { 5 | ready: boolean; 6 | 7 | address: string; 8 | 9 | constructor() { 10 | this.address = 'address'; 11 | this.ready = true; 12 | } 13 | get tronWeb() { 14 | return { 15 | ready: true, 16 | defaultAddress: { 17 | base58: this.address, 18 | }, 19 | fullNode: { host: '' }, 20 | solidityNode: { host: '' }, 21 | eventServer: { host: '' }, 22 | toHex(m: string) { 23 | return m; 24 | }, 25 | trx: { 26 | sign(message: any) { 27 | return message; 28 | }, 29 | }, 30 | } as TronWeb; 31 | } 32 | 33 | request() { 34 | return new Promise((resolve) => { 35 | setTimeout(() => { 36 | resolve({ 37 | code: 200, 38 | message: 'success', 39 | }); 40 | }, 200); 41 | }); 42 | } 43 | 44 | setReadyState(state: boolean) { 45 | this.ready = state; 46 | this.tronWeb.ready = state; 47 | } 48 | setAddress(address: '') { 49 | this.address = address; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /packages/vue/vue-ui/tsconfig.all.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../tsconfig.root.json", 3 | "references": [ 4 | { 5 | "path": "../../adapters/abstract-adapter/tsconfig.all.json" 6 | }, 7 | { 8 | "path": "../../adapters/adapters/tsconfig.all.json" 9 | }, 10 | { 11 | "path": "../../vue/vue-hooks/tsconfig.all.json" 12 | }, 13 | { 14 | "path": "./tsconfig.cjs.json" 15 | }, 16 | { 17 | "path": "./tsconfig.esm.json" 18 | } 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /packages/vue/vue-ui/tsconfig.cjs.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../tsconfig.cjs.json", 3 | "include": ["src"], 4 | "exclude": ["test"], 5 | "compilerOptions": { 6 | "outDir": "lib/cjs", 7 | "jsx": "preserve" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /packages/vue/vue-ui/tsconfig.esm.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../tsconfig.esm.json", 3 | "include": ["src"], 4 | "exclude": ["test"], 5 | "compilerOptions": { 6 | "outDir": "./lib/esm", 7 | "declarationDir": "./lib/types", 8 | "jsx": "preserve", 9 | "emitDeclarationOnly": true, 10 | // "noEmit": true, 11 | "jsxImportSource": "vue" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /packages/vue/vue-ui/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.esm.json", 3 | "include": ["src"], 4 | "exclude": [""], 5 | "compilerOptions": { 6 | "jsx": "preserve", 7 | "jsxImportSource": "vue", 8 | // "noImplicitAny": false, 9 | // "strict": false, 10 | "target": "esnext", 11 | "lib": ["esnext", "dom"], 12 | "module": "esnext", 13 | "moduleResolution": "node", 14 | "resolveJsonModule": true, 15 | "strict": true, 16 | "strictNullChecks": true, 17 | "declaration": true, 18 | "outDir": "./dist", 19 | "skipDefaultLibCheck": true, 20 | "skipLibCheck": true 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /packages/vue/vue-ui/vite.config.js: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | import { defineConfig } from 'vite'; 3 | import Vue from '@vitejs/plugin-vue'; 4 | import Jsx from '@vitejs/plugin-vue-jsx'; 5 | 6 | export default defineConfig({ 7 | plugins: [Vue(), Jsx()], 8 | test: { 9 | globals: true, 10 | environment: 'jsdom', 11 | }, 12 | }); 13 | -------------------------------------------------------------------------------- /pnpm-workspace.yaml: -------------------------------------------------------------------------------- 1 | packages: 2 | - 'packages/*/*' 3 | - 'demos/*/*' 4 | - 'demos/dev-demo' 5 | - 'demos/cdn-demo' 6 | -------------------------------------------------------------------------------- /scripts/build-umd.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/no-var-requires */ 2 | /* eslint-disable no-undef */ 3 | const { rollup } = require('rollup'); 4 | const nodeResolve = require('@rollup/plugin-node-resolve'); 5 | const commonjs = require('@rollup/plugin-commonjs'); 6 | const terser = require('@rollup/plugin-terser'); 7 | const json = require('@rollup/plugin-json'); 8 | const nodePolyfills = require('rollup-plugin-polyfill-node'); 9 | 10 | const { cwd } = require('process'); 11 | const { resolve } = require('path'); 12 | 13 | const inputOptions = { 14 | input: './lib/cjs/index.js', 15 | plugins: [commonjs(), nodeResolve(), json(), nodePolyfills()], 16 | external: ['@walletconnect/sign-client'], 17 | }; 18 | const commonOptions = { 19 | format: 'umd', 20 | name: getOutputName(), 21 | globals: { 22 | '@walletconnect/sign-client': '@walletconnect/sign-client', 23 | }, 24 | inlineDynamicImports: true, 25 | }; 26 | const outputOptionsList = [ 27 | { 28 | ...commonOptions, 29 | file: './lib/umd/index.js', 30 | }, 31 | { 32 | ...commonOptions, 33 | file: './lib/umd/index.min.js', 34 | plugins: [terser()], 35 | }, 36 | ]; 37 | build(); 38 | 39 | async function build() { 40 | let bundle; 41 | let bundleFailed = false; 42 | try { 43 | bundle = await rollup(inputOptions); 44 | await generateOutputs(bundle); 45 | } catch (e) { 46 | bundleFailed = true; 47 | console.error(e); 48 | } 49 | if (bundle) { 50 | bundle.close(); 51 | } 52 | process.exit(bundleFailed ? 1 : 0); 53 | } 54 | 55 | async function generateOutputs(bundle) { 56 | for (const outputOptions of outputOptionsList) { 57 | await bundle.write(outputOptions); 58 | } 59 | } 60 | 61 | function getOutputName() { 62 | const packageJson = require(resolve(cwd(), 'package.json')); 63 | const name = packageJson.name; 64 | console.log('[build:umd] current name: ' + name); 65 | return name; 66 | } 67 | -------------------------------------------------------------------------------- /scripts/list-pkg-versions.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/no-var-requires */ 2 | /* eslint-disable no-undef */ 3 | const { execSync } = require('child_process'); 4 | const fs = require('fs'); 5 | const path = require('path'); 6 | 7 | const DIRS = [path.resolve(__dirname, '../packages/adapters'), path.resolve(__dirname, '../packages/react')]; 8 | const pkgVersions = []; 9 | DIRS.forEach((dir) => { 10 | const subDirs = fs.readdirSync(dir); 11 | subDirs.forEach((pkg) => { 12 | try { 13 | const { name, version } = JSON.parse(fs.readFileSync(path.resolve(dir, pkg, 'package.json'))); 14 | pkgVersions.push({ 15 | name, 16 | version, 17 | }); 18 | } catch (e) { 19 | console.error(e); 20 | } 21 | }); 22 | }); 23 | 24 | pkgVersions.forEach(({ name, version }) => { 25 | try { 26 | const oldVersion = execSync(`npm view ${name} version`); 27 | console.log(`${name}: ${oldVersion.toString().trim()} -> ${version}`); 28 | } catch (e) { 29 | // ignore 30 | } 31 | }); 32 | 33 | console.log('Tag Content: '); 34 | pkgVersions.forEach(({ name, version }) => { 35 | console.log(`- [${name}@${version}](https://www.npmjs.com/package/${name})`); 36 | }); 37 | -------------------------------------------------------------------------------- /tsconfig.all.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.root.json", 3 | "references": [ 4 | { 5 | "path": "./packages/adapters/abstract-adapter/tsconfig.all.json" 6 | }, 7 | { 8 | "path": "./packages/adapters/adapters/tsconfig.all.json" 9 | }, 10 | { 11 | "path": "./packages/adapters/tronlink/tsconfig.all.json" 12 | }, 13 | { 14 | "path": "./packages/adapters/ledger/tsconfig.all.json" 15 | }, 16 | { 17 | "path": "./packages/adapters/walletconnect/tsconfig.all.json" 18 | }, 19 | { 20 | "path": "./packages/adapters/tokenpocket/tsconfig.all.json" 21 | }, 22 | { 23 | "path": "./packages/adapters/bitkeep/tsconfig.all.json" 24 | }, 25 | { 26 | "path": "./packages/adapters/okxwallet/tsconfig.all.json" 27 | }, 28 | { 29 | "path": "./packages/adapters/abstract-adapter-evm/tsconfig.all.json" 30 | }, 31 | { 32 | "path": "./packages/adapters/metamask/tsconfig.all.json" 33 | }, 34 | { 35 | "path": "./packages/adapters/tronlink-evm/tsconfig.all.json" 36 | }, 37 | { 38 | "path": "./packages/react/react-hooks/tsconfig.all.json" 39 | }, 40 | { 41 | "path": "./packages/react/react-ui/tsconfig.all.json" 42 | }, 43 | { 44 | "path": "./packages/vue/vue-hooks/tsconfig.all.json" 45 | } 46 | ] 47 | } 48 | -------------------------------------------------------------------------------- /tsconfig.base.json: -------------------------------------------------------------------------------- 1 | { 2 | "include": [], 3 | "exclude": ["./packages/**/__mocks__", "./packages/*/*/lib"], 4 | "compilerOptions": { 5 | "target": "ES2016", 6 | "module": "ESNext", 7 | "moduleResolution": "Node", 8 | "esModuleInterop": true, 9 | "isolatedModules": true, 10 | "noEmitOnError": true, 11 | "resolveJsonModule": true, 12 | "strict": true, 13 | "stripInternal": true 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /tsconfig.cjs.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.base.json", 3 | "compilerOptions": { 4 | "target": "ES2016", 5 | "module": "CommonJS", 6 | "sourceMap": true 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /tsconfig.esm.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.base.json", 3 | "compilerOptions": { 4 | "target": "ES2016", 5 | "module": "ES2020", 6 | "sourceMap": true, 7 | "declaration": true, 8 | "declarationMap": true 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.all.json", 3 | "include": ["./packages/*/*/src", "./packages/*/*/tests", "./packages/*/*/package.json"], 4 | "exclude": ["./packages/*/*/lib", "./packages/**/__mocks__"], 5 | "compilerOptions": { 6 | "noEmit": true, 7 | "skipLibCheck": true, 8 | "jsx": "react", 9 | "types": ["jest", "node"] 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /tsconfig.root.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.base.json", 3 | "compilerOptions": { 4 | "composite": true 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /tsconfig.tests.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.base.json", 3 | "compilerOptions": { 4 | "noEmit": true 5 | } 6 | } 7 | --------------------------------------------------------------------------------