├── .editorconfig ├── .eslintrc.js ├── .github └── ISSUE_TEMPLATE │ ├── bug_report.md │ ├── custom.md │ └── feature_request.md ├── .gitignore ├── .idea ├── .gitignore ├── SubConnect.iml ├── modules.xml └── vcs.xml ├── .prettierignore ├── .prettierrc.cjs ├── .yarn ├── plugins │ └── @yarnpkg │ │ ├── plugin-interactive-tools.cjs │ │ └── plugin-version.cjs └── releases │ └── yarn-3.2.0.cjs ├── .yarnrc.yml ├── LICENSE ├── README.md ├── babel.config.cjs ├── jest.config.cjs ├── package.json ├── packages ├── sub-connect │ ├── .skip-build │ ├── .skip-npm │ ├── LICENSE │ ├── package.json │ ├── public │ │ ├── KoniverseLogo.svg │ │ ├── SubConnect.png │ │ ├── favicon.ico │ │ ├── fonts │ │ │ ├── Lexend-Black.ttf │ │ │ ├── Lexend-Bold.ttf │ │ │ ├── Lexend-ExtraBold.ttf │ │ │ ├── Lexend-ExtraLight.ttf │ │ │ ├── Lexend-Light.ttf │ │ │ ├── Lexend-Medium.ttf │ │ │ ├── Lexend-Regular.ttf │ │ │ ├── Lexend-SemiBold.ttf │ │ │ ├── Lexend-Thin.ttf │ │ │ └── lexend.css │ │ ├── icon-128.png │ │ ├── icon-16.png │ │ ├── icon-32.png │ │ ├── icon-48.png │ │ ├── icon-64.png │ │ ├── index.html │ │ ├── manifest.json │ │ └── robots.txt │ ├── src │ │ ├── App.scss │ │ ├── App.tsx │ │ ├── components │ │ │ ├── AccountList.scss │ │ │ ├── AccountList.tsx │ │ │ ├── Layout.scss │ │ │ ├── Layout.tsx │ │ │ ├── SelectWallet.scss │ │ │ ├── SelectWallet.tsx │ │ │ ├── SelectWalletModal.tsx │ │ │ ├── WalletHeader.scss │ │ │ ├── WalletHeader.tsx │ │ │ ├── WalletMetadata.scss │ │ │ ├── WalletMetadata.tsx │ │ │ ├── Welcome.scss │ │ │ └── Welcome.tsx │ │ ├── contexts │ │ │ └── index.tsx │ │ ├── hooks │ │ │ ├── useLocalStorage.ts │ │ │ └── useMobileDetect.ts │ │ ├── index.scss │ │ ├── index.tsx │ │ ├── logo.svg │ │ ├── new-wallet-example │ │ │ ├── ExampleWallet.svg │ │ │ ├── README.md │ │ │ └── newWalletExample.ts │ │ ├── pages │ │ │ ├── EvmWalletInfo.scss │ │ │ ├── EvmWalletInfo.tsx │ │ │ ├── WalletInfo.scss │ │ │ ├── WalletInfo.tsx │ │ │ ├── evmChains.json │ │ │ └── methods.ts │ │ ├── providers │ │ │ └── WalletContextProvider.tsx │ │ ├── reportWebVitals.ts │ │ ├── setupTests.ts │ │ └── utils │ │ │ └── window.ts │ ├── tsconfig.build.json │ ├── tsconfig.json │ ├── webpack.config.cjs │ ├── webpack.shared.cjs │ └── webpack.watch.cjs ├── wagmi-connector │ ├── LICENSE │ ├── README.md │ ├── package.json │ ├── src │ │ ├── detectOther.ts │ │ ├── detectPackage.ts │ │ ├── env.d.ts │ │ ├── index.ts │ │ └── packageInfo.ts │ ├── tsconfig.build.json │ └── tsconfig.json ├── wallet-connect │ ├── LICENSE │ ├── README.md │ ├── package.json │ ├── src │ │ ├── detectOther.ts │ │ ├── detectPackage.ts │ │ ├── dotsama │ │ │ ├── BaseDotSamaWallet.ts │ │ │ ├── predefinedWallet │ │ │ │ ├── FearlessWalletLogo.svg │ │ │ │ ├── NovaWalletLogo.svg │ │ │ │ ├── PolkadotLogo.svg │ │ │ │ ├── SubWalletLogo.svg │ │ │ │ ├── TalismanLogo.svg │ │ │ │ └── index.ts │ │ │ ├── wallets.spec.ts │ │ │ └── wallets.ts │ │ ├── evm │ │ │ ├── BaseEvmWallet.ts │ │ │ ├── evmWallets.ts │ │ │ └── predefinedWallet │ │ │ │ ├── MetaMaskLogo.svg │ │ │ │ ├── NovaWalletLogo.svg │ │ │ │ ├── SubWalletLogo.svg │ │ │ │ └── index.ts │ │ ├── index.ts │ │ ├── packageInfo.ts │ │ └── types.ts │ ├── tsconfig.build.json │ └── tsconfig.json └── web3-react-subwallet-connector-v6 │ ├── LICENSE │ ├── README.md │ ├── package.json │ ├── src │ ├── declarations.ts │ ├── detectOther.ts │ ├── detectPackage.ts │ ├── index.ts │ ├── packageInfo.ts │ └── types.ts │ ├── tsconfig.build.json │ └── tsconfig.json ├── rollup.config.mjs ├── scripts ├── koni-ci-build-dev.mjs ├── koni-ci-ghact-build.mjs └── koni-dev-build-ts.mjs ├── tsconfig.base.json ├── tsconfig.build.json ├── tsconfig.eslint.json ├── tsconfig.json └── yarn.lock /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | [*] 3 | indent_style=space 4 | indent_size=2 5 | tab_width=2 6 | end_of_line=lf 7 | charset=utf-8 8 | trim_trailing_whitespace=true 9 | max_line_length=120 10 | insert_final_newline=true 11 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2022 @subwallet/sub-connect authors & contributors 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | const base = require('@polkadot/dev/config/eslint.cjs'); 5 | 6 | module.exports = { 7 | ...base, 8 | ignorePatterns: [ 9 | ...base.ignorePatterns, 10 | "webpack.*js", 11 | "koni*.mjs", 12 | "**/build/**.*", 13 | ], 14 | parserOptions: { 15 | ...base.parserOptions, 16 | project: [ 17 | './tsconfig.eslint.json' 18 | ] 19 | }, 20 | rules: { 21 | ...base.rules, 22 | 'header/header': [2, 'line', [ 23 | { pattern: ' Copyright 20(17|18|19|20|21|22)(-2022)? (@polkadot|@subwallet)/' }, 24 | ' SPDX-License-Identifier: Apache-2.0' 25 | ], 2], 26 | // this seems very broken atm, false positives 27 | '@typescript-eslint/unbound-method': 'off', 28 | '@typescript-eslint/ban-ts-comment': 'off', 29 | 'sort-keys': 'off' 30 | } 31 | }; 32 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Smartphone (please complete the following information):** 32 | - Device: [e.g. iPhone6] 33 | - OS: [e.g. iOS8.1] 34 | - Browser [e.g. stock browser, safari] 35 | - Version [e.g. 22] 36 | 37 | **Additional context** 38 | Add any other context about the problem here. 39 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/custom.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Custom issue template 3 | about: Describe this issue template's purpose here. 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | 11 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | _book/ 2 | build/ 3 | build-cjs/ 4 | build-esm/ 5 | build-docs/ 6 | coverage/ 7 | docs/.vuepress/dist/ 8 | docs/substrate/*.md 9 | node_modules/ 10 | tmp/ 11 | NOTES.md 12 | .idea 13 | .DS_Store 14 | .env.local 15 | .env.development.local 16 | .env.test.local 17 | .env.production.local 18 | .npmrc 19 | .rpt2_cache 20 | .yarn/* 21 | !.yarn/releases 22 | !.yarn/plugins 23 | .pnp.* 24 | .vscode/ 25 | cc-test-reporter 26 | lerna-debug.log* 27 | npm-debug.log* 28 | package-lock.json 29 | tsconfig*buildinfo 30 | yarn-debug.log* 31 | yarn-error.log* 32 | -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Editor-based HTTP Client requests 5 | /httpRequests/ 6 | -------------------------------------------------------------------------------- /.idea/SubConnect.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | build 2 | coverage 3 | packages 4 | -------------------------------------------------------------------------------- /.prettierrc.cjs: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2022 @polkadot/api authors & contributors 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | module.exports = require('@polkadot/dev/config/prettier.cjs'); 5 | -------------------------------------------------------------------------------- /.yarnrc.yml: -------------------------------------------------------------------------------- 1 | enableImmutableInstalls: false 2 | 3 | enableProgressBars: false 4 | 5 | nodeLinker: node-modules 6 | 7 | plugins: 8 | - path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs 9 | spec: "@yarnpkg/plugin-interactive-tools" 10 | - path: .yarn/plugins/@yarnpkg/plugin-version.cjs 11 | spec: "@yarnpkg/plugin-version" 12 | 13 | yarnPath: .yarn/releases/yarn-3.2.0.cjs 14 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SubConnect 2 | 3 | Note: We have stopped further development of this version and replaced it with a new and more complete version here: https://github.com/Koniverse/SubConnect-v2 4 | 5 | Simple DApp used to test wallets in Dotsama Ecosystem. 6 | 7 | ![image](https://user-images.githubusercontent.com/11567273/170807399-78fa0f2c-0c45-443a-9573-1c830b524149.png) 8 | 9 | This repository also connect with **SubWallet EVM provider** and **MetaMask provider** with idea from [this issue](https://github.com/Koniverse/SubWallet-Extension/issues/235) 10 | 11 | ## Requirement: 12 | This project require [nodejs](https://nodejs.org/en/) and [yarn](https://classic.yarnpkg.com/lang/en/docs/install/#windows-stable) before start. 13 | 14 | ## Available Scripts 15 | In the project directory, you can start work project with these commands: 16 | 17 | ### `yarn install` 18 | Run to install project dependencies. Wait until all done before use another command. 19 | 20 | ### `yarn start` 21 | Runs the app in the development mode.\ 22 | Open [http://localhost:3333](http://localhost:3333) to view it in the browser. 23 | 24 | The page will reload if you make edits.\ 25 | You will also see any lint errors in the console. 26 | 27 | ### `yarn build:ui` 28 | Build package to `sub-connect` to `packages/sub-connect/build`. 29 | 30 | ### `yarn build` 31 | Build `wallet-connect`, `web3-react-subwallet-connector-v6` packages. 32 | 33 | ## Documentations: 34 | You can find more information about this project with below link: 35 | - [How to integrate SubWallet to Substrate DApp](https://github.com/Koniverse/SubConnect/wiki/How-to-integrate-SubWallet-to-Substrate-DApp) 36 | - [Integrate SubWallet with EVM DApp](https://github.com/Koniverse/SubConnect/wiki/Integrate-SubWallet-with-EVM-DApp) 37 | -------------------------------------------------------------------------------- /babel.config.cjs: -------------------------------------------------------------------------------- 1 | // Copyright 2019-2022 @subwallet/extension authors & contributors 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | module.exports = require('@polkadot/dev/config/babel-config-cjs.cjs'); 5 | -------------------------------------------------------------------------------- /jest.config.cjs: -------------------------------------------------------------------------------- 1 | // Copyright 2019-2022 @subwallet/extension authors & contributors 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | const config = require('@polkadot/dev/config/jest.cjs'); 5 | 6 | module.exports = { 7 | ...config, 8 | modulePathIgnorePatterns: [ 9 | ...config.modulePathIgnorePatterns 10 | ], 11 | moduleNameMapper: { 12 | '@subwallet/(wallet-connect|sub-connect)/(.*)$': '/packages/$1/src/$2', 13 | }, 14 | transform: { 15 | ...config.transform, 16 | ".+\\.(svg|css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$": "jest-transform-stub" 17 | }, 18 | testPathIgnorePatterns: [ 19 | '/node_modules/*' 20 | ], 21 | testEnvironment: 'jsdom' 22 | }; 23 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "author": "Koni Studio", 3 | "bugs": "https://github.com/Koniverse/SubConnect/issues", 4 | "homepage": "https://github.com/Koniverse/SubConnect#readme", 5 | "license": "Apache-2.0", 6 | "packageManager": "yarn@3.2.0", 7 | "private": true, 8 | "repository": { 9 | "type": "git", 10 | "url": "https://github.com/Koniverse/SubConnect.git" 11 | }, 12 | "sideEffects": false, 13 | "version": "0.2.6-beta.1", 14 | "workspaces": [ 15 | "packages/*" 16 | ], 17 | "bin": { 18 | "koni-ci-build-dev": "./scripts/koni-ci-build-dev.mjs", 19 | "koni-ci-ghact-build": "./scripts/koni-ci-ghact-build.mjs", 20 | "koni-dev-build-ts": "./scripts/koni-dev-build-ts.mjs" 21 | }, 22 | "scripts": { 23 | "build": "koni-dev-build-ts", 24 | "build:ui": "yarn clean && cd packages/sub-connect && yarn polkadot-exec-webpack --config webpack.config.cjs --mode production", 25 | "clean": "polkadot-dev-clean-build", 26 | "deploy:ui": "yarn build:ui && gh-pages --dist 'packages/sub-connect/build' --branch 'gh-pages'", 27 | "lint": "polkadot-dev-run-lint", 28 | "start": "yarn watch", 29 | "test": "polkadot-dev-run-test --detectOpenHandles'", 30 | "watch": "cd packages/sub-connect && yarn webpack-dev-server --config webpack.watch.cjs --mode development" 31 | }, 32 | "devDependencies": { 33 | "@polkadot/dev": "^0.66.28", 34 | "gh-pages": "^4.0.0", 35 | "jest-environment-jsdom": "^28.1.0", 36 | "jest-svg-transformer": "^1.0.0", 37 | "jest-transform-stub": "^2.0.0" 38 | }, 39 | "resolutions": { 40 | "@babel/runtime": "^7.16.7", 41 | "@polkadot/api": "^10.9.1", 42 | "@polkadot/types": "^10.9.1", 43 | "@polkadot/util": "^10.1.2", 44 | "@types/node": "^16.7.13", 45 | "typescript": "^4.6.4" 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /packages/sub-connect/.skip-build: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Koniverse/SubConnect/d8a53ce483204a0bb6bfc3d62c92625b49867a63/packages/sub-connect/.skip-build -------------------------------------------------------------------------------- /packages/sub-connect/.skip-npm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Koniverse/SubConnect/d8a53ce483204a0bb6bfc3d62c92625b49867a63/packages/sub-connect/.skip-npm -------------------------------------------------------------------------------- /packages/sub-connect/LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /packages/sub-connect/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "author": "Koni Studio", 3 | "bugs": "https://github.com/Koniverse/SubConnect/issues", 4 | "homepage": "https://github.com/Koniverse/SubConnect/tree/master/packages/sub-connect#readme", 5 | "license": "Apache-2.0", 6 | "name": "@subwallet/sub-connect", 7 | "private": true, 8 | "repository": { 9 | "directory": "packages/sub-connect", 10 | "type": "git", 11 | "url": "https://github.com/Koniverse/SubConnect.git" 12 | }, 13 | "sideEffects": false, 14 | "type": "commonjs", 15 | "version": "0.2.6-beta.1", 16 | "dependencies": { 17 | "@ant-design/icons": "^4.7.0", 18 | "@ethersproject/keccak256": "^5.6.1", 19 | "@subwallet/wallet-connect": "^0.2.6-beta.1", 20 | "@testing-library/jest-dom": "^5.14.1", 21 | "@testing-library/react": "^12.0.0", 22 | "@testing-library/user-event": "^13.2.1", 23 | "@types/jest": "^27.0.1", 24 | "@types/node": "^16.7.13", 25 | "@types/react": "^17.0.20", 26 | "@types/react-dom": "^17.0.9", 27 | "antd": "^4.18.6", 28 | "react": "^17.0.2", 29 | "react-dom": "^17.0.2", 30 | "react-router-dom": "^6.2.1", 31 | "react-scripts": "5.0.0", 32 | "typescript": "^4.4.2", 33 | "web-vitals": "^2.1.0", 34 | "web3": "^1.7.3" 35 | }, 36 | "devDependencies": { 37 | "@polkadot/dev": "^0.66.28", 38 | "assert": "^2.0.0", 39 | "babel-loader": "^8.2.3", 40 | "browser-resolve": "^2.0.0", 41 | "buffer": "^6.0.3", 42 | "copy-webpack-plugin": "^10.2.0", 43 | "crypto-browserify": "^3.12.0", 44 | "css-loader": "^6.7.1", 45 | "eth-sig-util": "^3.0.1", 46 | "extract-loader": "^5.1.0", 47 | "file-loader": "^6.2.0", 48 | "html-loader": "^3.1.0", 49 | "html-webpack-plugin": "^5.5.0", 50 | "https-browserify": "^1.0.0", 51 | "node-sass": "^9.0.0", 52 | "os-browserify": "^0.3.0", 53 | "path-browserify": "^1.0.1", 54 | "process": "^0.11.10", 55 | "sass-loader": "^13.0.0", 56 | "stream-browserify": "^3.0.0", 57 | "stream-http": "^3.2.0", 58 | "thread-loader": "^3.0.4", 59 | "url-loader": "^4.1.1", 60 | "webpack": "^5.65.0", 61 | "webpack-cli": "^4.9.1", 62 | "webpack-dev-server": "^4.9.0" 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /packages/sub-connect/public/SubConnect.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Koniverse/SubConnect/d8a53ce483204a0bb6bfc3d62c92625b49867a63/packages/sub-connect/public/SubConnect.png -------------------------------------------------------------------------------- /packages/sub-connect/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Koniverse/SubConnect/d8a53ce483204a0bb6bfc3d62c92625b49867a63/packages/sub-connect/public/favicon.ico -------------------------------------------------------------------------------- /packages/sub-connect/public/fonts/Lexend-Black.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Koniverse/SubConnect/d8a53ce483204a0bb6bfc3d62c92625b49867a63/packages/sub-connect/public/fonts/Lexend-Black.ttf -------------------------------------------------------------------------------- /packages/sub-connect/public/fonts/Lexend-Bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Koniverse/SubConnect/d8a53ce483204a0bb6bfc3d62c92625b49867a63/packages/sub-connect/public/fonts/Lexend-Bold.ttf -------------------------------------------------------------------------------- /packages/sub-connect/public/fonts/Lexend-ExtraBold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Koniverse/SubConnect/d8a53ce483204a0bb6bfc3d62c92625b49867a63/packages/sub-connect/public/fonts/Lexend-ExtraBold.ttf -------------------------------------------------------------------------------- /packages/sub-connect/public/fonts/Lexend-ExtraLight.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Koniverse/SubConnect/d8a53ce483204a0bb6bfc3d62c92625b49867a63/packages/sub-connect/public/fonts/Lexend-ExtraLight.ttf -------------------------------------------------------------------------------- /packages/sub-connect/public/fonts/Lexend-Light.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Koniverse/SubConnect/d8a53ce483204a0bb6bfc3d62c92625b49867a63/packages/sub-connect/public/fonts/Lexend-Light.ttf -------------------------------------------------------------------------------- /packages/sub-connect/public/fonts/Lexend-Medium.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Koniverse/SubConnect/d8a53ce483204a0bb6bfc3d62c92625b49867a63/packages/sub-connect/public/fonts/Lexend-Medium.ttf -------------------------------------------------------------------------------- /packages/sub-connect/public/fonts/Lexend-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Koniverse/SubConnect/d8a53ce483204a0bb6bfc3d62c92625b49867a63/packages/sub-connect/public/fonts/Lexend-Regular.ttf -------------------------------------------------------------------------------- /packages/sub-connect/public/fonts/Lexend-SemiBold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Koniverse/SubConnect/d8a53ce483204a0bb6bfc3d62c92625b49867a63/packages/sub-connect/public/fonts/Lexend-SemiBold.ttf -------------------------------------------------------------------------------- /packages/sub-connect/public/fonts/Lexend-Thin.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Koniverse/SubConnect/d8a53ce483204a0bb6bfc3d62c92625b49867a63/packages/sub-connect/public/fonts/Lexend-Thin.ttf -------------------------------------------------------------------------------- /packages/sub-connect/public/fonts/lexend.css: -------------------------------------------------------------------------------- 1 | /*@font-face {*/ 2 | /* font-family: 'Lexend';*/ 3 | /* src: url('./Lexend-Black.ttf'); !* IE9 Compat Modes *!*/ 4 | /* font-weight: 900;*/ 5 | /* font-style: normal;*/ 6 | /*}*/ 7 | 8 | /*@font-face {*/ 9 | /* font-family: 'Lexend';*/ 10 | /* src: url('./Lexend-ExtraBold.ttf'); !* IE9 Compat Modes *!*/ 11 | /* font-weight: 800;*/ 12 | /* font-style: normal;*/ 13 | /*}*/ 14 | 15 | @font-face { 16 | font-family: 'Lexend'; 17 | src: url('./Lexend-SemiBold.ttf'); /* IE9 Compat Modes */ 18 | font-weight: 700; 19 | font-style: normal; 20 | } 21 | 22 | @font-face { 23 | font-family: 'Lexend'; 24 | src: url('./Lexend-Medium.ttf'); /* IE9 Compat Modes */ 25 | font-weight: 600; 26 | font-style: normal; 27 | } 28 | 29 | @font-face { 30 | font-family: 'Lexend'; 31 | src: url('./Lexend-Regular.ttf'); /* IE9 Compat Modes */ 32 | font-weight: 500; 33 | font-style: normal; 34 | } 35 | 36 | @font-face { 37 | font-family: 'Lexend'; 38 | src: url('./Lexend-Light.ttf'); /* IE9 Compat Modes */ 39 | font-weight: 400; 40 | font-style: normal; 41 | } 42 | 43 | /*@font-face {*/ 44 | /* font-family: 'Lexend';*/ 45 | /* src: url('./Lexend-Light.ttf'); !* IE9 Compat Modes *!*/ 46 | /* font-weight: 300;*/ 47 | /* font-style: normal;*/ 48 | /*}*/ 49 | 50 | /*@font-face {*/ 51 | /* font-family: 'Lexend';*/ 52 | /* src: url('./Lexend-ExtraLight.ttf'); !* IE9 Compat Modes *!*/ 53 | /* font-weight: 200;*/ 54 | /* font-style: normal;*/ 55 | /*}*/ 56 | 57 | /*@font-face {*/ 58 | /* font-family: 'Lexend';*/ 59 | /* src: url('./Lexend-Thin.ttf'); !* IE9 Compat Modes *!*/ 60 | /* font-weight: 100;*/ 61 | /* font-style: normal;*/ 62 | /*}*/ 63 | -------------------------------------------------------------------------------- /packages/sub-connect/public/icon-128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Koniverse/SubConnect/d8a53ce483204a0bb6bfc3d62c92625b49867a63/packages/sub-connect/public/icon-128.png -------------------------------------------------------------------------------- /packages/sub-connect/public/icon-16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Koniverse/SubConnect/d8a53ce483204a0bb6bfc3d62c92625b49867a63/packages/sub-connect/public/icon-16.png -------------------------------------------------------------------------------- /packages/sub-connect/public/icon-32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Koniverse/SubConnect/d8a53ce483204a0bb6bfc3d62c92625b49867a63/packages/sub-connect/public/icon-32.png -------------------------------------------------------------------------------- /packages/sub-connect/public/icon-48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Koniverse/SubConnect/d8a53ce483204a0bb6bfc3d62c92625b49867a63/packages/sub-connect/public/icon-48.png -------------------------------------------------------------------------------- /packages/sub-connect/public/icon-64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Koniverse/SubConnect/d8a53ce483204a0bb6bfc3d62c92625b49867a63/packages/sub-connect/public/icon-64.png -------------------------------------------------------------------------------- /packages/sub-connect/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 13 | 14 | 18 | 19 | SubWallet Connect 20 | 21 | 22 | 23 |
24 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /packages/sub-connect/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "SubWallet Connect", 3 | "name": "SubWallet Connect Examples", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "icon-32.png", 12 | "type": "image/png", 13 | "sizes": "32x32" 14 | }, 15 | { 16 | "src": "icon-64.png", 17 | "type": "image/png", 18 | "sizes": "64x64" 19 | }, 20 | { 21 | "src": "icon-128.png", 22 | "type": "image/png", 23 | "sizes": "128x128" 24 | } 25 | ], 26 | "start_url": ".", 27 | "display": "standalone", 28 | "theme_color": "#000000", 29 | "background_color": "#ffffff" 30 | } 31 | -------------------------------------------------------------------------------- /packages/sub-connect/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /packages/sub-connect/src/App.scss: -------------------------------------------------------------------------------- 1 | .App { 2 | height: 100vh; 3 | } 4 | 5 | .main-layout { 6 | height: 100%; 7 | } 8 | 9 | .main-content { 10 | height: 100%; 11 | position: relative; 12 | overflow: auto; 13 | } 14 | 15 | .main-content.-dark { 16 | background-color: #020412; 17 | color: #fff; 18 | 19 | .ant-input { 20 | background-color: #262C4A; 21 | border-color: rgba(128, 128, 128, 0.2); 22 | color: #ddd; 23 | } 24 | 25 | } 26 | 27 | .dark-theme { 28 | .ant-select .ant-select-selector, .ant-select:not(.ant-select-customize-input) .ant-select-selector { 29 | background-color: #262C4A; 30 | border-color: rgba(128, 128, 128, 0.2)!important; 31 | color: #ddd; 32 | } 33 | 34 | .ant-select-dropdown { 35 | background-color: #262C4A; 36 | color: #fff; 37 | border-color: rgba(128, 128, 128, 0.2); 38 | 39 | .ant-select-item { 40 | color: #fff; 41 | background-color: #262C4A; 42 | 43 | &.ant-select-item-option-selected, &:hover { 44 | background-color: rgba(128,128,128,0.2); 45 | } 46 | } 47 | } 48 | 49 | .ant-select-arrow { 50 | color: #ddd; 51 | } 52 | } 53 | 54 | .main-content.-light { 55 | background-color: #FFF; 56 | color: #444; 57 | 58 | .welcome-content__text, .wallet-title, .wallet-info-page__text, .account-item__title, .metadata-item__title { 59 | color: #020412; 60 | } 61 | 62 | .account-item__content, .metadata-item__content { 63 | color: #888; 64 | } 65 | 66 | .select-wallet-modal .ant-modal-content { 67 | background-color: #FFF; 68 | } 69 | 70 | .account-item, .metadata-item, .wallet-header-wrapper { 71 | border-color: #EEE; 72 | } 73 | 74 | .sub-wallet-sign-btn { 75 | background-color: #F0F4FF; 76 | } 77 | 78 | .sub-wallet-sign-btn > span { 79 | color: #004BFF; 80 | } 81 | } 82 | 83 | .boxed-container { 84 | padding-left: 16px; 85 | padding-right: 16px; 86 | margin-left: auto; 87 | margin-right: auto; 88 | overflow: auto; 89 | max-width: 618px; 90 | } 91 | 92 | .select-wallet-modal.-light { 93 | .ant-modal-content, .ant-modal-header { 94 | background-color: #FFF; 95 | } 96 | 97 | .ant-modal-header { 98 | border-bottom-color: #EEE; 99 | } 100 | 101 | .ant-modal-title, .ant-modal-close, .wallet-title { 102 | color: #020412; 103 | } 104 | 105 | .wallet-item { 106 | border-color: #EEE; 107 | } 108 | 109 | .wallet-item:hover { 110 | background-color: #EEE; 111 | } 112 | 113 | } -------------------------------------------------------------------------------- /packages/sub-connect/src/App.tsx: -------------------------------------------------------------------------------- 1 | // Copyright 2019-2022 @subwallet/sub-connect authors & contributors 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import EvmWalletInfo from '@subwallet/sub-connect/pages/EvmWalletInfo'; 5 | import { WalletContextProvider } from '@subwallet/sub-connect/providers/WalletContextProvider'; 6 | import React from 'react'; 7 | import { HashRouter, Route, Routes } from 'react-router-dom'; 8 | 9 | import Layout from './components/Layout'; 10 | import Welcome from './components/Welcome'; 11 | import WalletInfo from './pages/WalletInfo'; 12 | 13 | require('./App.scss'); 14 | 15 | // Add new example wallet 16 | // doAddWallet(); 17 | 18 | export function App () { 19 | return ( 20 | 21 | 22 | 23 | } 25 | path='/' 26 | > 27 | } 29 | index 30 | /> 31 | } 33 | path='/welcome' 34 | /> 35 | } 37 | path='/wallet-info' 38 | /> 39 | } 41 | path='/evm-wallet-info' 42 | /> 43 | 44 | 45 | 46 | 47 | ); 48 | } 49 | -------------------------------------------------------------------------------- /packages/sub-connect/src/components/AccountList.scss: -------------------------------------------------------------------------------- 1 | .account-list { 2 | position: relative; 3 | } 4 | 5 | .account-item { 6 | padding: 16px 20px; 7 | border: 2px solid #151A30; 8 | border-radius: 8px; 9 | margin-bottom: 16px; 10 | 11 | .info { 12 | margin-bottom: 16px; 13 | } 14 | } 15 | 16 | .account-item-info { 17 | display: flex; 18 | flex-wrap: wrap; 19 | } 20 | 21 | .account-item__title { 22 | font-size: 15px; 23 | line-height: 26px; 24 | font-weight: 500; 25 | padding-right: 5px; 26 | } 27 | 28 | .account-item__content { 29 | 30 | font-size: 15px; 31 | line-height: 26px; 32 | color: #7B8098; 33 | text-overflow: ellipsis; 34 | overflow: hidden; 35 | } -------------------------------------------------------------------------------- /packages/sub-connect/src/components/AccountList.tsx: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/no-floating-promises */ 2 | // Copyright 2019-2022 @subwallet/sub-connect authors & contributors 3 | // SPDX-License-Identifier: Apache-2.0 4 | 5 | // eslint-disable-next-line header/header 6 | import { EditOutlined } from '@ant-design/icons'; 7 | import { Button, message } from 'antd'; 8 | import React, { useCallback, useContext } from 'react'; 9 | 10 | import { WalletContext } from '../contexts'; 11 | 12 | require('./AccountList.scss'); 13 | 14 | function AccountList (): React.ReactElement { 15 | const walletContext = useContext(WalletContext); 16 | 17 | const signDummy = useCallback( 18 | (address: string) => { 19 | const signer = walletContext.wallet?.signer; 20 | 21 | if (signer && signer.signRaw) { 22 | const signPromise = signer.signRaw({ address, data: 'This is dummy message', type: 'bytes' }); 23 | const key = 'sign-status'; 24 | 25 | message.loading({ content: 'Signing', key }); 26 | signPromise.then((rs: any) => { 27 | message.success({ content: 'Sign Successfully!', key }); 28 | }).catch((error) => { 29 | console.error(error); 30 | message.warn({ content: 'Sign Failed or Cancelled!', key }); 31 | }); 32 | } 33 | }, 34 | [walletContext.wallet?.signer] 35 | ); 36 | 37 | const onSignClicked = useCallback( 38 | (address: string) => { 39 | return () => { 40 | signDummy(address); 41 | }; 42 | }, 43 | [signDummy] 44 | ); 45 | 46 | return (
47 | {walletContext.accounts.map((acc) => ( 48 |
52 |
53 |
54 | Name: 55 | {acc.name} 56 |
57 |
58 | Address: 59 | {acc.address} 60 |
61 |
62 |
63 | 72 |
73 |
74 | ))} 75 |
); 76 | } 77 | 78 | export default AccountList; 79 | -------------------------------------------------------------------------------- /packages/sub-connect/src/components/Layout.scss: -------------------------------------------------------------------------------- 1 | .ant-switch.sub-wallet-switch-theme { 2 | position: absolute; 3 | } 4 | 5 | .sub-wallet-switch-theme { 6 | position: absolute; 7 | top: 30px; 8 | right: 30px; 9 | z-index: 1000; 10 | background-color: #004BFF; 11 | } 12 | 13 | @media (max-width: 840px) { 14 | .sub-wallet-switch-theme.with-header { 15 | right: calc((100% - 620px)/2 + 186px); 16 | } 17 | } 18 | 19 | @media (max-width: 600px) { 20 | .sub-wallet-switch-theme.with-header { 21 | right: 185px; 22 | } 23 | } 24 | 25 | @media (max-width: 501px) { 26 | .sub-wallet-switch-theme.with-header { 27 | top: 100px; 28 | right: 30px; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /packages/sub-connect/src/components/Layout.tsx: -------------------------------------------------------------------------------- 1 | // Copyright 2019-2022 @subwallet/sub-connect authors & contributors 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import { useLocalStorage } from '@subwallet/sub-connect/hooks/useLocalStorage'; 5 | import { Switch } from 'antd'; 6 | import React, { useCallback, useContext, useEffect } from 'react'; 7 | import { Outlet, useNavigate } from 'react-router-dom'; 8 | 9 | import { WalletContext } from '../contexts'; 10 | import SelectWalletModal from './SelectWalletModal'; 11 | import WalletHeader from './WalletHeader'; 12 | 13 | require('./Layout.scss'); 14 | 15 | function Layout (): React.ReactElement { 16 | const walletContext = useContext(WalletContext); 17 | const [theme, setTheme] = useLocalStorage('sub-wallet-theme', 'dark'); 18 | const navigate = useNavigate(); 19 | 20 | useEffect(() => { 21 | if (!walletContext.wallet && !walletContext.evmWallet) { 22 | navigate('/welcome'); 23 | } 24 | 25 | const isDark = theme === 'dark'; 26 | 27 | document.body.style.backgroundColor = isDark ? '#020412' : '#FFF'; 28 | document.body.className = isDark ? 'dark-theme' : 'light-theme'; 29 | }, [theme, navigate, walletContext]); 30 | 31 | const _onChangeTheme = useCallback(() => { 32 | setTheme(theme === 'dark' ? 'light' : 'dark'); 33 | document.body.className = theme === 'dark' ? 'dark-theme' : 'light-theme'; 34 | }, [setTheme, theme]); 35 | 36 | return (
37 |
38 | 45 | 46 | 47 | 48 |
49 |
); 50 | } 51 | 52 | export default Layout; 53 | -------------------------------------------------------------------------------- /packages/sub-connect/src/components/SelectWallet.scss: -------------------------------------------------------------------------------- 1 | .select-wallet-modal { 2 | width: 570px !important; 3 | } 4 | 5 | .select-wallet-modal .ant-modal-content { 6 | color: #FFF; 7 | background-color: #020412; 8 | border-radius: 15px; 9 | } 10 | 11 | .select-wallet-modal .ant-modal-header { 12 | background-color: #020412; 13 | border-radius: 15px 15px 0 0; 14 | border-bottom: 1px solid #151A30; 15 | padding: 20px; 16 | } 17 | 18 | .select-wallet-modal .ant-modal-close { 19 | color: #FFF; 20 | top: 20px; 21 | right: 10px; 22 | } 23 | 24 | .select-wallet-modal .ant-modal-close-x { 25 | width: 32px; 26 | height: 32px; 27 | line-height: 32px; 28 | } 29 | 30 | .select-wallet-modal .ant-modal-body { 31 | font-size: 15px; 32 | line-height: 26px; 33 | padding: 30px 20px; 34 | } 35 | 36 | .select-wallet-modal .ant-modal-title { 37 | color: #FFF; 38 | font-size: 20px; 39 | line-height: 32px; 40 | } 41 | 42 | .select-wallet-wrapper { 43 | .wallet-cat-title { 44 | font-size: 18px; 45 | margin-bottom: 16px; 46 | } 47 | 48 | .dotsama-wallet-list { 49 | margin-bottom: 36px; 50 | } 51 | } 52 | 53 | .select-wallet-content { 54 | overflow: auto; 55 | } 56 | 57 | .wallet-item { 58 | position: relative; 59 | padding: 8px 12px; 60 | overflow: hidden; 61 | border: 2px solid #151A30; 62 | border-radius: 8px; 63 | cursor: pointer; 64 | display: flex; 65 | align-items: center; 66 | align-content: center; 67 | margin-bottom: 15px; 68 | transition-duration: 0.3s; 69 | 70 | .wallet-logo { 71 | width: 32px; 72 | height: 32px; 73 | margin: 6px 2px 6px 8px; 74 | } 75 | 76 | .wallet-title { 77 | font-weight: 600; 78 | flex: 1 1 300px; 79 | padding: 8px; 80 | 81 | } 82 | 83 | .wallet-install { 84 | padding: 8px; 85 | } 86 | 87 | .wallet-install > a { 88 | color: #42C59A; 89 | font-weight: 500; 90 | } 91 | 92 | 93 | //&:first-child { 94 | // border-top-left-radius: 6px; 95 | // border-top-right-radius: 6px; 96 | //} 97 | // 98 | &:last-child { 99 | margin-bottom: 0; 100 | } 101 | 102 | &:hover { 103 | background-color: #151A30; 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /packages/sub-connect/src/components/SelectWallet.tsx: -------------------------------------------------------------------------------- 1 | // Copyright 2019-2022 @subwallet/sub-connect authors & contributors 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import { getWallets } from '@subwallet/wallet-connect/dotsama/wallets'; 5 | import { getEvmWallets } from '@subwallet/wallet-connect/evm/evmWallets'; 6 | import { EvmWallet, Wallet } from '@subwallet/wallet-connect/types'; 7 | import React, { useCallback } from 'react'; 8 | 9 | require('./SelectWallet.scss'); 10 | 11 | interface Props { 12 | onSelectWallet: (walletKey: string, walletType?: 'substrate' | 'evm') => void 13 | } 14 | 15 | function SelectWallet ({ onSelectWallet }: Props): React.ReactElement { 16 | const dotsamaWallets = getWallets(); 17 | const evmWallets = getEvmWallets(); 18 | 19 | const onClickDotsamaWallet = useCallback( 20 | (wallet: Wallet | EvmWallet) => { 21 | return () => { 22 | if (wallet.installed) { 23 | onSelectWallet(wallet.extensionName); 24 | } 25 | }; 26 | }, 27 | [onSelectWallet] 28 | ); 29 | 30 | const onClickEvmWallet = useCallback( 31 | (wallet: Wallet | EvmWallet) => { 32 | return () => { 33 | if (wallet.installed) { 34 | onSelectWallet(wallet.extensionName, 'evm'); 35 | } 36 | }; 37 | }, 38 | [onSelectWallet] 39 | ); 40 | 41 | const walletItem: (wallet: Wallet|EvmWallet, onSelect: (wallet: Wallet|EvmWallet) => () => void) => React.ReactElement = (wallet, onSelect) => ( 42 |
47 |
48 | {wallet.logo?.alt} 53 |
54 |
55 | {wallet.title} 56 |
57 |
58 | {wallet.installed 59 | ? '' 60 | : ( 65 | Install 66 | )} 67 |
68 |
69 | ); 70 | 71 | return
72 |
73 |
74 |
75 | Dotsama Wallets 76 |
77 | {dotsamaWallets.map((wallet) => (walletItem(wallet, onClickDotsamaWallet)))} 78 |
79 |
80 |
81 | EVM Wallets 82 |
83 | {evmWallets.map((wallet) => (walletItem(wallet, onClickEvmWallet)))} 84 |
85 |
86 |
; 87 | } 88 | 89 | export default SelectWallet; 90 | -------------------------------------------------------------------------------- /packages/sub-connect/src/components/SelectWalletModal.tsx: -------------------------------------------------------------------------------- 1 | // Copyright 2019-2022 @subwallet/sub-connect authors & contributors 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import './SelectWallet.scss'; 5 | 6 | import { getWalletBySource } from '@subwallet/wallet-connect/dotsama/wallets'; 7 | import { getEvmWalletBySource } from '@subwallet/wallet-connect/evm/evmWallets'; 8 | import { Modal } from 'antd'; 9 | import React, { useCallback, useContext } from 'react'; 10 | import { useNavigate } from 'react-router-dom'; 11 | 12 | import { OpenSelectWallet, WalletContext } from '../contexts'; 13 | import SelectWallet from './SelectWallet'; 14 | 15 | interface Props { 16 | theme: string; 17 | } 18 | 19 | function SelectWalletModal ({ theme }: Props): React.ReactElement { 20 | const openSelectWalletContext = useContext(OpenSelectWallet); 21 | const walletContext = useContext(WalletContext); 22 | const navigate = useNavigate(); 23 | const onSelectWallet = useCallback( 24 | (walletKey, walletType: 'substrate' | 'evm' = 'substrate') => { 25 | if (walletType === 'substrate') { 26 | walletContext.setWallet(getWalletBySource(walletKey), walletType); 27 | openSelectWalletContext.close(); 28 | navigate('/wallet-info'); 29 | } else { 30 | walletContext.setWallet(getEvmWalletBySource(walletKey), walletType); 31 | openSelectWalletContext.close(); 32 | navigate('/evm-wallet-info'); 33 | } 34 | }, 35 | [navigate, openSelectWalletContext, walletContext] 36 | ); 37 | 38 | return 48 | 49 | ; 50 | } 51 | 52 | export default SelectWalletModal; 53 | -------------------------------------------------------------------------------- /packages/sub-connect/src/components/WalletHeader.scss: -------------------------------------------------------------------------------- 1 | .wallet-header-wrapper { 2 | border-bottom: 1px solid #151A30; 3 | } 4 | 5 | .wallet-header-content { 6 | overflow: auto; 7 | display: flex; 8 | align-items: center; 9 | padding: 20px 0; 10 | 11 | .wallet-logo { 12 | margin-right: 8px; 13 | height: 40px; 14 | } 15 | 16 | .wallet-title { 17 | padding-left: 0; 18 | font-weight: 500; 19 | font-size: 20px; 20 | line-height: 32px; 21 | } 22 | 23 | .spacer { 24 | flex: 1 1 100px; 25 | } 26 | 27 | .select-wallet { 28 | margin: 8px; 29 | } 30 | } 31 | 32 | @media (max-width: 501px) { 33 | .wallet-header-content { 34 | .wallet-title { 35 | font-size: 18px; 36 | } 37 | 38 | .spacer { 39 | flex: 1 1 10px; 40 | } 41 | 42 | .sub-wallet-btn { 43 | padding-left: 3px; 44 | padding-right: 3px; 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /packages/sub-connect/src/components/WalletHeader.tsx: -------------------------------------------------------------------------------- 1 | // Copyright 2019-2022 @subwallet/sub-connect authors & contributors 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import { Button } from 'antd'; 5 | import React, { useContext } from 'react'; 6 | 7 | import { OpenSelectWallet, WalletContext } from '../contexts'; 8 | 9 | require('./WalletHeader.scss'); 10 | 11 | interface Props { 12 | visible?: boolean 13 | } 14 | 15 | function WalletHeader ({ visible }: Props): React.ReactElement { 16 | const walletContext = useContext(WalletContext); 17 | const selectWallet = useContext(OpenSelectWallet); 18 | const wallet = walletContext.wallet || walletContext.evmWallet; 19 | 20 | if (!visible) { 21 | return (<>); 22 | } 23 | 24 | return (
25 |
26 |
27 |
28 | {wallet?.logo?.alt} 33 |
34 |
35 | {wallet?.title} 36 |
37 |
38 | 43 |
44 |
45 |
); 46 | } 47 | 48 | export default WalletHeader; 49 | -------------------------------------------------------------------------------- /packages/sub-connect/src/components/WalletMetadata.scss: -------------------------------------------------------------------------------- 1 | .metadata-item { 2 | border: 2px solid #151A30; 3 | padding: 16px 20px; 4 | border-radius: 8px; 5 | margin-bottom: 16px; 6 | overflow: hidden; 7 | } 8 | 9 | .metadata-item-info { 10 | display: flex; 11 | flex-wrap: wrap; 12 | } 13 | 14 | .metadata-item__title { 15 | font-size: 15px; 16 | line-height: 26px; 17 | font-weight: 500; 18 | padding-right: 5px; 19 | } 20 | 21 | .metadata-item__content { 22 | font-size: 15px; 23 | line-height: 26px; 24 | color: #7B8098; 25 | text-overflow: ellipsis; 26 | overflow: hidden; 27 | } -------------------------------------------------------------------------------- /packages/sub-connect/src/components/WalletMetadata.tsx: -------------------------------------------------------------------------------- 1 | // Copyright 2019-2022 @subwallet/sub-connect authors & contributors 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | /* eslint-disable @typescript-eslint/no-floating-promises */ 5 | import { PlusCircleOutlined } from '@ant-design/icons'; 6 | import { Button, message } from 'antd'; 7 | import React, { useCallback, useContext, useEffect, useState } from 'react'; 8 | 9 | import { InjectedMetadataKnown, MetadataDef } from '@polkadot/extension-inject/types'; 10 | 11 | import { WalletContext } from '../contexts'; 12 | 13 | require('./WalletMetadata.scss'); 14 | 15 | function WalletMetadata (): React.ReactElement { 16 | const walletContext = useContext(WalletContext); 17 | const [injectedMetas, setInjectedMetas] = useState([]); 18 | 19 | const loadMetadata = useCallback( 20 | () => { 21 | const metadata = walletContext.wallet?.metadata; 22 | 23 | if (metadata) { 24 | metadata.get().then((rs) => { 25 | setInjectedMetas(rs); 26 | }); 27 | } 28 | }, 29 | [walletContext.wallet?.metadata] 30 | ); 31 | 32 | useEffect(() => { 33 | setTimeout(() => { 34 | loadMetadata(); 35 | }, 300); 36 | }, [loadMetadata, walletContext.wallet]); 37 | 38 | const addMetadata = useCallback( 39 | () => { 40 | const metadata = walletContext.wallet?.metadata; 41 | 42 | if (metadata) { 43 | const newMetaDef: MetadataDef = { 44 | chain: 'SubWallet Connect Demo', 45 | genesisHash: '0x1bf2a278799868de66ea8610f2ce7c8c43706561b6476031315f6640fe38e888', 46 | icon: 'substrate', 47 | ss58Format: 0, 48 | chainType: 'substrate', 49 | color: '#F0F0F0', 50 | specVersion: Math.floor(Date.now() / 1000), 51 | tokenDecimals: 12, 52 | tokenSymbol: 'SWCC', 53 | types: {} 54 | }; 55 | const key = 'add-metadata'; 56 | 57 | message.loading({ content: 'Adding Metadata', key }); 58 | metadata.provide(newMetaDef) 59 | .then((rs) => { 60 | message.success({ content: 'Add Metadata Successfully!', key }); 61 | loadMetadata(); 62 | }) 63 | .catch((error) => { 64 | console.error(error); 65 | message.warn({ content: 'Add Metadata Failed or Cancelled!', key }); 66 | }); 67 | } 68 | }, 69 | [loadMetadata, walletContext.wallet?.metadata] 70 | ); 71 | 72 | return (
73 |
74 | {injectedMetas.map((meta) => 75 |
79 |
80 | Genesis Hash: 81 | {meta.genesisHash} 82 |
83 |
84 | Spec Version: 85 | {meta.specVersion} 86 |
87 |
)} 88 |
89 | 95 |
); 96 | } 97 | 98 | export default WalletMetadata; 99 | -------------------------------------------------------------------------------- /packages/sub-connect/src/components/Welcome.scss: -------------------------------------------------------------------------------- 1 | .welcome-wrapper { 2 | position: relative; 3 | width: 100vw; 4 | height: 100vh; 5 | display: table-cell; 6 | vertical-align: middle; 7 | } 8 | 9 | .welcome-content { 10 | text-align: center; 11 | display: flex; 12 | flex-direction: column; 13 | align-items: center; 14 | } 15 | 16 | .welcome-content__text { 17 | font-size: 32px; 18 | line-height: 44px; 19 | color: #FFF; 20 | font-weight: 500; 21 | padding-bottom: 50px; 22 | padding-left: 30px; 23 | padding-right: 30px; 24 | } 25 | 26 | .welcome-content__btn { 27 | padding: 11px 13px; 28 | display: flex; 29 | justify-content: center; 30 | align-items: center; 31 | background-color: #004BFF; 32 | border: none; 33 | border-radius: 8px; 34 | height: auto; 35 | } 36 | 37 | .welcome-content__btn > span { 38 | font-size: 15px; 39 | line-height: 26px; 40 | font-weight: 500; 41 | color: #fff; 42 | padding: 0 20px; 43 | } 44 | 45 | .welcome-content__btn:hover,.welcome-content__btn:focus,.welcome-content__btn:active { 46 | background-color: #004BFF; 47 | } 48 | -------------------------------------------------------------------------------- /packages/sub-connect/src/components/Welcome.tsx: -------------------------------------------------------------------------------- 1 | // Copyright 2019-2022 @subwallet/sub-connect authors & contributors 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import {Button} from 'antd'; 5 | import React, {useContext, useEffect} from 'react'; 6 | import {useNavigate} from 'react-router-dom'; 7 | 8 | import {OpenSelectWallet, WalletContext} from '../contexts'; 9 | 10 | require('./Welcome.scss'); 11 | 12 | function Welcome (): React.ReactElement { 13 | const selectWallet = useContext(OpenSelectWallet); 14 | const walletContext = useContext(WalletContext); 15 | const navigate = useNavigate(); 16 | 17 | useEffect(() => { 18 | if (walletContext.wallet && walletContext.walletType === 'substrate') { 19 | navigate('/wallet-info'); 20 | } else if (walletContext.evmWallet && walletContext.walletType === 'evm') { 21 | navigate('/evm-wallet-info'); 22 | } 23 | }, [navigate, walletContext]); 24 | 25 | return (
26 |
27 |
Welcome to SubWallet Connect
28 | 32 |
33 |
); 34 | } 35 | 36 | export default Welcome; 37 | -------------------------------------------------------------------------------- /packages/sub-connect/src/contexts/index.tsx: -------------------------------------------------------------------------------- 1 | // Copyright 2019-2022 @subwallet/sub-connect authors & contributors 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import { Wallet, WalletAccount } from '@subwallet/wallet-connect/src/types'; 5 | import { EvmWallet } from '@subwallet/wallet-connect/types'; 6 | import React from 'react'; 7 | 8 | export interface WalletContextInterface { 9 | wallet?: Wallet, 10 | evmWallet?: EvmWallet, 11 | accounts: WalletAccount[], 12 | setWallet: (wallet: Wallet | EvmWallet | undefined, walletType: 'substrate'|'evm') => void 13 | walletType: 'substrate'|'evm'; 14 | } 15 | 16 | export const WalletContext = React.createContext({ 17 | accounts: [], 18 | // eslint-disable-next-line @typescript-eslint/no-empty-function 19 | setWallet: (wallet, walletType: 'substrate'|'evm') => {}, 20 | walletType: 'substrate' 21 | }); 22 | 23 | interface OpenSelectWalletInterface { 24 | isOpen: boolean, 25 | open: () => void 26 | close: () => void 27 | } 28 | 29 | export const OpenSelectWallet = React.createContext({ 30 | isOpen: false, 31 | // eslint-disable-next-line @typescript-eslint/no-empty-function 32 | open: () => {}, 33 | // eslint-disable-next-line @typescript-eslint/no-empty-function 34 | close: () => {} 35 | }); 36 | -------------------------------------------------------------------------------- /packages/sub-connect/src/hooks/useLocalStorage.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2019-2022 @subwallet/sub-connect authors & contributors 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import { useEffect, useState } from 'react'; 5 | 6 | export function useLocalStorage ( 7 | key: string, 8 | initialValue = '' 9 | ): [string, (v: string) => void] { 10 | const [storedValue, setStoredValue] = useState(initialValue); 11 | 12 | useEffect(() => { 13 | const item = 14 | typeof window !== 'undefined' ? window.localStorage.getItem(key) : false; 15 | 16 | if (item) { 17 | try { 18 | // eslint-disable-next-line @typescript-eslint/no-unsafe-argument 19 | setStoredValue(JSON.parse(item as string)); 20 | } catch (e) { 21 | setStoredValue(initialValue); 22 | } 23 | } 24 | }, [initialValue, key, setStoredValue]); 25 | 26 | const setValue = (value: string) => { 27 | setStoredValue(value); 28 | window.localStorage.setItem(key, JSON.stringify(value)); 29 | }; 30 | 31 | return [storedValue, setValue]; 32 | } 33 | -------------------------------------------------------------------------------- /packages/sub-connect/src/hooks/useMobileDetect.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2019-2022 @subwallet/sub-connect authors & contributors 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import {useEffect, useState} from "react"; 5 | 6 | export function useMobileDetect () { 7 | const [isMobile, setIsMobile] = useState(false); 8 | 9 | useEffect(() => { 10 | // @ts-ignore 11 | const detection = navigator.userAgent||navigator.vendor||window.opera; 12 | if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(detection)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(detection.substring(0,4))) { 13 | setIsMobile(true); 14 | } 15 | }); 16 | 17 | return isMobile; 18 | } 19 | -------------------------------------------------------------------------------- /packages/sub-connect/src/index.scss: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: 'Lexend', serif !important; 4 | -webkit-font-smoothing: antialiased; 5 | -moz-osx-font-smoothing: grayscale; 6 | background-color: #020412; 7 | } 8 | 9 | #root { 10 | height: 100%; 11 | } 12 | 13 | code { 14 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 15 | monospace; 16 | } 17 | 18 | .sub-wallet-btn { 19 | display: flex; 20 | justify-content: center; 21 | align-items: center; 22 | background-color: #004BFF; 23 | border: none; 24 | border-radius: 8px; 25 | height: auto; 26 | outline: 0; 27 | box-shadow: none; 28 | } 29 | 30 | .sub-wallet-btn > span { 31 | font-size: 15px; 32 | line-height: 26px; 33 | font-weight: 500; 34 | color: #fff; 35 | } 36 | 37 | .sub-wallet-btn:hover, .sub-wallet-btn:focus, .sub-wallet-btn:active { 38 | background-color: #004BFF; 39 | } 40 | 41 | .sub-wallet-btn-normal-size { 42 | padding: 11px 13px; 43 | } 44 | 45 | .sub-wallet-btn-normal-size > span:last-child { 46 | padding: 0 20px; 47 | } 48 | 49 | .sub-wallet-btn-small-size { 50 | padding: 7px 16px; 51 | } 52 | 53 | .sub-wallet-btn-small-size > span { 54 | padding: 0 12px; 55 | } 56 | 57 | .sub-wallet-icon-btn { 58 | padding: 11px 13px; 59 | } 60 | 61 | .sub-wallet-sign-btn { 62 | background-color: #181E42; 63 | padding: 7px 16px; 64 | } 65 | 66 | .sub-wallet-sign-btn > span { 67 | color: #42C59A; 68 | } 69 | 70 | .sub-wallet-sign-btn:hover, .sub-wallet-sign-btn:focus, .sub-wallet-sign-btn:active { 71 | background-color: #181E42; 72 | } 73 | 74 | .ant-input { 75 | outline: none; 76 | 77 | &:focus { 78 | box-shadow: none; 79 | } 80 | } 81 | 82 | .ant-select { 83 | outline: none; 84 | 85 | .ant-select-selector { 86 | outline: none; 87 | box-shadow: none!important; 88 | } 89 | } 90 | 91 | .ant-btn[disabled], .ant-btn[disabled]:active, .ant-btn[disabled]:focus, .ant-btn[disabled]:hover { 92 | background-color: #5485fc; 93 | } 94 | 95 | .font-mono { 96 | font-family: monospace; 97 | } -------------------------------------------------------------------------------- /packages/sub-connect/src/index.tsx: -------------------------------------------------------------------------------- 1 | // Copyright 2019-2022 @subwallet/sub-connect authors & contributors 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import React from 'react'; 5 | import ReactDOM from 'react-dom'; 6 | 7 | import { App } from './App'; 8 | import reportWebVitals from './reportWebVitals'; 9 | 10 | require('antd/dist/antd.min.css'); 11 | require('./index.scss'); 12 | 13 | ReactDOM.render( 14 | 15 | 16 | , 17 | document.getElementById('root') 18 | ); 19 | 20 | // If you want to start measuring performance in your app, pass a function 21 | // to log results (for example: reportWebVitals(console.log)) 22 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals 23 | reportWebVitals(); 24 | -------------------------------------------------------------------------------- /packages/sub-connect/src/logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /packages/sub-connect/src/new-wallet-example/ExampleWallet.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 9 | 11 | 14 | 15 | 16 | 17 | 19 | 20 | 23 | 25 | 27 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /packages/sub-connect/src/new-wallet-example/README.md: -------------------------------------------------------------------------------- 1 | # Add more wallet 2 | You can add more wallet and not required to modify this `wallet-connect` package. 3 | 4 | You can add new wallet like folder code by follow these step: 5 | - Add svg logo should not exceed 10KB 6 | - Create some code like `newWalletExample.ts`: 7 | ```typescript 8 | import { addWallet } from '@subwallet/wallet-connect/dotsama/wallets'; 9 | 10 | import SubWalletLogo from './ExampleWallet.svg'; 11 | 12 | export const doAddWallet = () => { 13 | addWallet({ 14 | extensionName: 'example', 15 | title: 'New Wallet Example', 16 | installUrl: 'https://github.com/Koniverse/SubConnect', 17 | logo: { 18 | src: SubWalletLogo as string, 19 | alt: 'New Wallet Example' 20 | } 21 | }); 22 | }; 23 | ``` 24 | - Call doAddWallet before any functions in `packages/wallet-connect/src/dotsama/wallets.ts` is called. 25 | ```typescript 26 | // Import codes found here 27 | require('./App.scss'); 28 | 29 | // Add new example wallet 30 | doAddWallet(); 31 | 32 | export function App () { 33 | const [walletKey, setWalletKey] = useLocalStorage('wallet-key'); 34 | const [currentWallet, setCurrentWallet] = useState(getWalletBySource(walletKey)); 35 | const [isSelectWallet, setIsSelectWallet] = useState(false); 36 | const [accounts, setAccounts] = useState([]); 37 | 38 | // Another code found here 39 | } 40 | ``` -------------------------------------------------------------------------------- /packages/sub-connect/src/new-wallet-example/newWalletExample.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2019-2022 @subwallet/sub-connect authors & contributors 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import { addWallet } from '@subwallet/wallet-connect/dotsama/wallets'; 5 | 6 | // @ts-ignore 7 | import SubWalletLogo from './ExampleWallet.svg'; 8 | 9 | export const doAddWallet = () => { 10 | addWallet({ 11 | extensionName: 'example', 12 | title: 'New Wallet Example', 13 | installUrl: 'https://github.com/Koniverse/SubConnect/tree/master/packages/sub-connect/src/new-wallet-example', 14 | logo: { 15 | src: SubWalletLogo as string, 16 | alt: 'New Wallet Example' 17 | } 18 | }); 19 | }; 20 | -------------------------------------------------------------------------------- /packages/sub-connect/src/pages/EvmWalletInfo.scss: -------------------------------------------------------------------------------- 1 | .evm-wallet-info-page { 2 | padding: 50px 8px; 3 | 4 | input.code { 5 | font-family: monospace; 6 | } 7 | } 8 | 9 | .evm-wallet-info-page__text { 10 | font-size: 20px; 11 | line-height: 32px; 12 | font-weight: 500; 13 | padding-bottom: 16px; 14 | } 15 | .evm-wallet-info-page__section { 16 | margin-bottom: 24px; 17 | } 18 | 19 | .evm-wallet-info__button_group { 20 | .ant-btn { 21 | width: 100%; 22 | margin-bottom: 16px; 23 | } 24 | } 25 | 26 | .evm-wallet-info__button_row { 27 | display: flex; 28 | flex-wrap: wrap; 29 | margin-left: -16px; 30 | 31 | .ant-btn { 32 | width: 100%; 33 | margin-left: 16px; 34 | flex: 1 1 260px; 35 | } 36 | } 37 | 38 | .warning-text { 39 | color: #d7a22f; 40 | white-space: pre-wrap; 41 | margin-bottom: 16px; 42 | } 43 | 44 | .evm-wallet-transaction_row { 45 | display: flex; 46 | margin-bottom: 8px; 47 | align-items: center; 48 | flex-wrap: wrap; 49 | 50 | .label { 51 | width: 110px; 52 | margin-bottom: 8px; 53 | } 54 | .ant-input, .ant-select, .input-wrapper,.max-w { 55 | flex: 1 1 200px; 56 | margin-bottom: 8px; 57 | } 58 | .input-wrapper { 59 | display: flex; 60 | flex-wrap: wrap; 61 | margin-bottom: 0; 62 | align-items: center; 63 | 64 | .ant-input { 65 | flex: 1 1 120px; 66 | } 67 | } 68 | .suffix { 69 | padding-left: 12px; 70 | margin-bottom: 8px; 71 | } 72 | } 73 | 74 | .transaction-button { 75 | width: 100%; 76 | margin-bottom: 8px; 77 | } -------------------------------------------------------------------------------- /packages/sub-connect/src/pages/WalletInfo.scss: -------------------------------------------------------------------------------- 1 | .wallet-info-page { 2 | padding: 50px 8px; 3 | } 4 | 5 | .wallet-info-page__text { 6 | font-size: 20px; 7 | line-height: 32px; 8 | font-weight: 500; 9 | padding-bottom: 16px; 10 | } -------------------------------------------------------------------------------- /packages/sub-connect/src/pages/WalletInfo.tsx: -------------------------------------------------------------------------------- 1 | // Copyright 2019-2022 @subwallet/sub-connect authors & contributors 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import { Wallet } from '@subwallet/wallet-connect/types'; 5 | import React, { useContext } from 'react'; 6 | 7 | import AccountList from '../components/AccountList'; 8 | import WalletMetadata from '../components/WalletMetadata'; 9 | import { WalletContext } from '../contexts'; 10 | 11 | require('./WalletInfo.scss'); 12 | 13 | function WalletInfo (): React.ReactElement { 14 | const walletContext = useContext(WalletContext); 15 | 16 | return
17 |
18 |
Version: {(walletContext?.wallet as Wallet)?.extension?.version}
19 |
Account List
20 | 21 |
Metadata
22 | 23 |
24 |
; 25 | } 26 | 27 | export default WalletInfo; 28 | -------------------------------------------------------------------------------- /packages/sub-connect/src/pages/methods.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2019-2022 @subwallet/sub-connect authors & contributors 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | // Some code of this file refer to https://github.com/MetaMask/test-dapp/blob/main/src/index.js 5 | import { RequestArguments } from '@metamask/providers/dist/BaseProvider'; 6 | 7 | export const METHOD_MAP: Record = { 8 | addMoonbeamNetwork: { 9 | method: 'wallet_addEthereumChain', 10 | params: [ 11 | { 12 | chainId: '0x504', 13 | rpcUrls: ['https://rpc.api.moonbeam.network'], 14 | chainName: 'Moonbeam', 15 | nativeCurrency: { name: 'GLMR', decimals: 18, symbol: 'GLMR' }, 16 | blockExplorerUrls: ['https://moonbeam.moonscan.io/'] 17 | } 18 | ] 19 | }, 20 | switchToMoonbeamNetwork: { 21 | method: 'wallet_switchEthereumChain', 22 | params: [ 23 | { 24 | chainId: '0x504' 25 | } 26 | ] 27 | }, 28 | addMoonriverNetwork: { 29 | method: 'wallet_addEthereumChain', 30 | params: [ 31 | { 32 | chainId: '0x505', 33 | rpcUrls: ['https://rpc.api.moonriver.moonbeam.network'], 34 | chainName: 'Moonriver', 35 | nativeCurrency: { name: 'MOVR', decimals: 18, symbol: 'MOVR' }, 36 | blockExplorerUrls: ['https://moonriver.moonscan.io/'] 37 | } 38 | ] 39 | }, 40 | switchToMoonriverNetwork: { 41 | method: 'wallet_switchEthereumChain', 42 | params: [ 43 | { 44 | chainId: '0x505' 45 | } 46 | ] 47 | }, 48 | addMoonbaseAlphaNetwork: { 49 | method: 'wallet_addEthereumChain', 50 | params: [ 51 | { 52 | chainId: '0x507', 53 | rpcUrls: ['https://rpc.api.moonbase.moonbeam.network'], 54 | chainName: 'MoonbaseAlpha', 55 | nativeCurrency: { name: 'DEV', decimals: 18, symbol: 'DEV' }, 56 | blockExplorerUrls: ['https://moonbase.moonscan.io/'] 57 | } 58 | ] 59 | }, 60 | switchToMoonbaseAlphaNetwork: { 61 | method: 'wallet_switchEthereumChain', 62 | params: [ 63 | { 64 | chainId: '0x507' 65 | } 66 | ] 67 | }, 68 | addAstarNetwork: { 69 | method: 'wallet_addEthereumChain', 70 | params: [ 71 | { 72 | chainId: '0x250', 73 | rpcUrls: ['https://astar.public.blastapi.io'], 74 | chainName: 'Astar', 75 | nativeCurrency: { name: 'ASTR', decimals: 18, symbol: 'ASTR' }, 76 | blockExplorerUrls: ['https://blockscout.com/astar'] 77 | } 78 | ] 79 | }, 80 | switchToAstarNetwork: { 81 | method: 'wallet_switchEthereumChain', 82 | params: [ 83 | { 84 | chainId: '0x250' // 592 85 | } 86 | ] 87 | }, 88 | addShidenNetwork: { 89 | method: 'wallet_addEthereumChain', 90 | params: [ 91 | { 92 | chainId: '0x150', // 336 93 | rpcUrls: ['https://shiden.public.blastapi.io'], 94 | chainName: 'Shiden', 95 | nativeCurrency: { name: 'SDN', decimals: 18, symbol: 'SDN' }, 96 | blockExplorerUrls: ['https://blockscout.com/astar'] 97 | } 98 | ] 99 | }, 100 | switchToShidenNetwork: { 101 | method: 'wallet_switchEthereumChain', 102 | params: [ 103 | { 104 | chainId: '0x150' 105 | } 106 | ] 107 | }, 108 | addShibuyaNetwork: { 109 | method: 'wallet_addEthereumChain', 110 | params: [ 111 | { 112 | chainId: '0x51', 113 | rpcUrls: ['https://evm.shibuya.astar.network'], 114 | chainName: 'Shibuya Testnet', 115 | nativeCurrency: { name: 'SBY', decimals: 18, symbol: 'SBY' }, 116 | blockExplorerUrls: ['https://blockscout.com/shibuya'] 117 | } 118 | ] 119 | }, 120 | switchToShibuyaNetwork: { 121 | method: 'wallet_switchEthereumChain', 122 | params: [ 123 | { 124 | chainId: '0x51' // 81 125 | } 126 | ] 127 | }, 128 | addMumbaiNetwork: { 129 | method: 'wallet_addEthereumChain', 130 | params: [ 131 | { 132 | chainId: '0x13881', 133 | rpcUrls: ['https://endpoints.omniatech.io/v1/matic/mumbai/public'], 134 | chainName: 'Mumbai', 135 | nativeCurrency: { name: 'MATIC', decimals: 18, symbol: 'MATIC' }, 136 | blockExplorerUrls: ['https://mumbai.polygonscan.com'] 137 | } 138 | ] 139 | }, 140 | switchToMumbaiNetwork: { 141 | method: 'wallet_switchEthereumChain', 142 | params: [ 143 | { 144 | chainId: '0x13881' // 81 145 | } 146 | ] 147 | }, 148 | addBobaTestnet: { 149 | method: 'wallet_addEthereumChain', 150 | params: [ 151 | { 152 | chainId: '0x511', 153 | rpcUrls: ['https://endpoints.omniatech.io/v1/matic/mumbai/public'], 154 | chainName: 'Boba Testnet', 155 | nativeCurrency: { name: 'BOBA', decimals: 18, symbol: 'BOBA' }, 156 | blockExplorerUrls: ['https://mumbai.polygonscan.com'] 157 | } 158 | ] 159 | }, 160 | switchToBobaTestnet: { 161 | method: 'wallet_switchEthereumChain', 162 | params: [ 163 | { 164 | chainId: '0x511' // 81 165 | } 166 | ] 167 | }, 168 | getPermissions: { 169 | method: 'wallet_getPermissions', 170 | params: [{ eth_accounts: {} }] 171 | }, 172 | requestPermissions: { 173 | method: 'wallet_requestPermissions', 174 | params: [{ eth_accounts: {} }] 175 | } 176 | }; 177 | -------------------------------------------------------------------------------- /packages/sub-connect/src/providers/WalletContextProvider.tsx: -------------------------------------------------------------------------------- 1 | // Copyright 2019-2022 @subwallet/wallet-connect authors & contributors 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import { useLocalStorage } from '@subwallet/sub-connect/hooks/useLocalStorage'; 5 | import { windowReload } from '@subwallet/sub-connect/utils/window'; 6 | import { getWalletBySource } from '@subwallet/wallet-connect/dotsama/wallets'; 7 | import { getEvmWalletBySource } from '@subwallet/wallet-connect/evm/evmWallets'; 8 | import { EvmWallet, Wallet, WalletAccount } from '@subwallet/wallet-connect/types'; 9 | import React, { useCallback, useEffect, useState } from 'react'; 10 | 11 | import { OpenSelectWallet, WalletContext, WalletContextInterface } from '../contexts'; 12 | 13 | interface Props { 14 | children: React.ReactElement; 15 | } 16 | 17 | export function WalletContextProvider ({ children }: Props) { 18 | const [walletKey, setWalletKey] = useLocalStorage('wallet-key'); 19 | const [walletType, setWalletType] = useLocalStorage('wallet-type', 'substrate'); 20 | const [currentWallet, setCurrentWallet] = useState(getWalletBySource(walletKey)); 21 | const [isSelectWallet, setIsSelectWallet] = useState(false); 22 | const [accounts, setAccounts] = useState([]); 23 | 24 | const afterSelectWallet = useCallback( 25 | async (wallet: Wallet) => { 26 | const infos = await wallet.getAccounts(); 27 | 28 | infos && setAccounts(infos); 29 | }, 30 | [] 31 | ); 32 | 33 | const selectWallet = useCallback( 34 | async (wallet: Wallet) => { 35 | setCurrentWallet(currentWallet); 36 | 37 | await wallet.enable(); 38 | setWalletKey(wallet.extensionName); 39 | 40 | await afterSelectWallet(wallet); 41 | }, 42 | [afterSelectWallet, currentWallet, setWalletKey] 43 | ); 44 | 45 | const afterSelectEvmWallet = useCallback( 46 | async (wallet: EvmWallet) => { 47 | await wallet?.enable(); // Quick call extension?.request({ method: 'eth_requestAccounts' }); 48 | }, 49 | [] 50 | ); 51 | 52 | const selectEvmWallet = useCallback( 53 | async (wallet: EvmWallet) => { 54 | await afterSelectEvmWallet(wallet); 55 | 56 | setCurrentWallet(currentWallet); 57 | 58 | setWalletKey(wallet.extensionName); 59 | 60 | windowReload(); 61 | }, 62 | [afterSelectEvmWallet, currentWallet, setWalletKey] 63 | ); 64 | 65 | const walletContext = { 66 | wallet: getWalletBySource(walletKey), 67 | evmWallet: getEvmWalletBySource(walletKey), 68 | accounts, 69 | setWallet: (wallet: Wallet | EvmWallet | undefined, walletType: 'substrate' | 'evm') => { 70 | if (walletType === 'substrate') { 71 | wallet && selectWallet(wallet as Wallet); 72 | } else { 73 | wallet && selectEvmWallet(wallet as EvmWallet); 74 | } 75 | 76 | wallet && setWalletType(walletType); 77 | }, 78 | walletType 79 | }; 80 | 81 | const selectWalletContext = { 82 | isOpen: isSelectWallet, 83 | open: () => { 84 | setIsSelectWallet(true); 85 | }, 86 | close: () => { 87 | setIsSelectWallet(false); 88 | } 89 | }; 90 | 91 | useEffect( 92 | () => { 93 | if (walletType === 'substrate') { 94 | const wallet = getWalletBySource(walletKey); 95 | 96 | setTimeout(() => { 97 | if (wallet && wallet?.installed) { 98 | // eslint-disable-next-line no-void 99 | void afterSelectWallet(wallet); 100 | } 101 | }, 150); 102 | } else { 103 | const evmWallet = getEvmWalletBySource(walletKey); 104 | 105 | evmWallet && evmWallet?.isReady.then(() => { 106 | afterSelectEvmWallet(evmWallet).catch(console.error); 107 | }); 108 | } 109 | }, 110 | [afterSelectEvmWallet, afterSelectWallet, walletKey, walletType] 111 | ); 112 | 113 | return 114 | 115 | {children} 116 | 117 | ; 118 | } 119 | -------------------------------------------------------------------------------- /packages/sub-connect/src/reportWebVitals.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2019-2022 @subwallet/sub-connect authors & contributors 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import { ReportHandler } from 'web-vitals'; 5 | 6 | const reportWebVitals = (onPerfEntry?: ReportHandler) => { 7 | if (onPerfEntry && onPerfEntry instanceof Function) { 8 | import('web-vitals').then(({ getCLS, getFCP, getFID, getLCP, getTTFB }) => { 9 | getCLS(onPerfEntry); 10 | getFID(onPerfEntry); 11 | getFCP(onPerfEntry); 12 | getLCP(onPerfEntry); 13 | getTTFB(onPerfEntry); 14 | }).catch(console.error); 15 | } 16 | }; 17 | 18 | export default reportWebVitals; 19 | -------------------------------------------------------------------------------- /packages/sub-connect/src/setupTests.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2019-2022 @subwallet/sub-connect authors & contributors 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 5 | // allows you to do things like: 6 | // expect(element).toHaveTextContent(/react/i) 7 | // learn more: https://github.com/testing-library/jest-dom 8 | import '@testing-library/jest-dom'; 9 | -------------------------------------------------------------------------------- /packages/sub-connect/src/utils/window.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2019-2022 @subwallet/sub-connect authors & contributors 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | export function windowReload () { 5 | window.location.reload(); 6 | } 7 | -------------------------------------------------------------------------------- /packages/sub-connect/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "baseUrl": "..", 5 | "outDir": "./build", 6 | "rootDir": "./src" 7 | }, 8 | "references": [ 9 | { "path": "../wallet-connect/tsconfig.build.json" 10 | } 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /packages/sub-connect/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "baseUrl": "..", 5 | "outDir": "./build", 6 | "rootDir": "./src" 7 | }, 8 | "references": [ 9 | { "path": "../sub-connect" }, 10 | { "path": "../wallet-connect" }, 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /packages/sub-connect/webpack.config.cjs: -------------------------------------------------------------------------------- 1 | // Copyright 2019-2022 @subwallet/sub-connect authors & contributors 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | const createConfig = require('./webpack.shared.cjs'); 5 | 6 | module.exports = [createConfig({ 7 | index: './src/index.tsx' 8 | })]; -------------------------------------------------------------------------------- /packages/sub-connect/webpack.shared.cjs: -------------------------------------------------------------------------------- 1 | // Copyright 2019-2022 @subwallet/sub-connect authors & contributors 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | const path = require('path'); 5 | const webpack = require('webpack'); 6 | 7 | const CopyPlugin = require('copy-webpack-plugin'); 8 | 9 | const pkgJson = require('./package.json'); 10 | const HtmlWebpackPlugin = require('html-webpack-plugin'); 11 | const MiniCssExtractPlugin = require("mini-css-extract-plugin"); 12 | 13 | const args = process.argv.slice(2); 14 | let mode = 'production'; 15 | 16 | if (args) { 17 | args.forEach((p, index) => { 18 | if (p === '--mode') { 19 | mode = args[index + 1] || mode; 20 | } 21 | }); 22 | } 23 | 24 | console.log('You are using ' + mode + ' mode.'); 25 | 26 | const packages = [ 27 | 'sub-connect', 28 | 'wallet-connect', 29 | ]; 30 | 31 | const cssRegex = /\.css$/; 32 | const cssModuleRegex = /\.module\.css$/; 33 | const sassRegex = /\.(scss|sass)$/; 34 | const sassModuleRegex = /\.module\.(scss|sass)$/; 35 | 36 | const getStyleLoaders = (cssOptions, preProcessor) => { 37 | const loaders = [ 38 | isEnvDevelopment && require.resolve('style-loader'), 39 | isEnvProduction && { 40 | loader: MiniCssExtractPlugin.loader, 41 | // css is located in `static/css`, use '../../' to locate index.html folder 42 | // in production `paths.publicUrlOrPath` can be a relative path 43 | options: paths.publicUrlOrPath.startsWith('.') 44 | ? {publicPath: '../../'} 45 | : {}, 46 | }, 47 | { 48 | loader: require.resolve('css-loader'), 49 | options: cssOptions, 50 | }, 51 | { 52 | // Options for PostCSS as we reference these options twice 53 | // Adds vendor prefixing based on your specified browser support in 54 | // package.json 55 | loader: require.resolve('postcss-loader'), 56 | options: { 57 | postcssOptions: { 58 | // Necessary for external CSS imports to work 59 | // https://github.com/facebook/create-react-app/issues/2677 60 | ident: 'postcss', 61 | config: false, 62 | plugins: !useTailwind 63 | ? [ 64 | 'postcss-flexbugs-fixes', 65 | [ 66 | 'postcss-preset-env', 67 | { 68 | autoprefixer: { 69 | flexbox: 'no-2009', 70 | }, 71 | stage: 3, 72 | }, 73 | ], 74 | // Adds PostCSS Normalize as the reset css with default options, 75 | // so that it honors browserslist config in package.json 76 | // which in turn let's users customize the target behavior as per their needs. 77 | 'postcss-normalize', 78 | ] 79 | : [ 80 | 'tailwindcss', 81 | 'postcss-flexbugs-fixes', 82 | [ 83 | 'postcss-preset-env', 84 | { 85 | autoprefixer: { 86 | flexbox: 'no-2009', 87 | }, 88 | stage: 3, 89 | }, 90 | ], 91 | ], 92 | }, 93 | sourceMap: isEnvProduction ? shouldUseSourceMap : isEnvDevelopment, 94 | }, 95 | }, 96 | ].filter(Boolean); 97 | if (preProcessor) { 98 | loaders.push( 99 | { 100 | loader: require.resolve('resolve-url-loader'), 101 | options: { 102 | sourceMap: isEnvProduction ? shouldUseSourceMap : isEnvDevelopment, 103 | root: paths.appSrc, 104 | }, 105 | }, 106 | { 107 | loader: require.resolve(preProcessor), 108 | options: { 109 | sourceMap: true, 110 | }, 111 | } 112 | ); 113 | } 114 | return loaders; 115 | }; 116 | 117 | 118 | module.exports = (entry, alias = {}, useSplitChunk = false) => { 119 | const result = { 120 | context: __dirname, 121 | devtool: false, 122 | entry, 123 | devServer: { 124 | port: 8080, 125 | hot: false 126 | }, 127 | module: { 128 | rules: [ 129 | { 130 | exclude: /(node_modules)/, 131 | test: /\.(js|mjs|ts|tsx)$/, 132 | use: [ 133 | { 134 | loader: require.resolve('babel-loader'), 135 | options: require('@polkadot/dev/config/babel-config-webpack.cjs') 136 | } 137 | ] 138 | }, 139 | { 140 | test: /\.(sa|sc|c)ss$/i, 141 | use: [ 142 | // Creates `style` nodes from JS strings 143 | "style-loader", 144 | // Translates CSS into CommonJS 145 | { 146 | loader: 'css-loader', 147 | options: { 148 | modules: { 149 | // Callback must return "local", "global", or "pure" values 150 | mode: (resourcePath) => { 151 | return 'global'; 152 | }, 153 | }, 154 | }, 155 | }, 156 | // Compiles Sass to CSS 157 | "sass-loader", 158 | ], 159 | }, 160 | { 161 | test: [/\.svg$/, /\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/, /\.woff2?$/], 162 | use: [ 163 | { 164 | loader: require.resolve('url-loader'), 165 | options: { 166 | esModule: false, 167 | limit: 10000, 168 | name: 'static/[name].[ext]' 169 | } 170 | } 171 | ] 172 | } 173 | ] 174 | }, 175 | output: { 176 | chunkFilename: '[name].[contenthash].js', 177 | filename: '[name].[contenthash].js', 178 | globalObject: '(typeof self !== \'undefined\' ? self : this)', 179 | path: path.join(__dirname, 'build'), 180 | publicPath: '' 181 | }, 182 | performance: { 183 | hints: false 184 | }, 185 | plugins: [ 186 | new webpack.ProvidePlugin({ 187 | Buffer: ['buffer', 'Buffer'], 188 | process: 'process/browser.js' 189 | }), 190 | new webpack.IgnorePlugin({ 191 | contextRegExp: /moment$/, 192 | resourceRegExp: /^\.\/locale$/ 193 | }), 194 | new webpack.DefinePlugin({ 195 | 'process.env': { 196 | NODE_ENV: JSON.stringify(mode), 197 | PKG_NAME: JSON.stringify(pkgJson.name), 198 | PKG_VERSION: JSON.stringify(pkgJson.version) 199 | } 200 | }), 201 | new CopyPlugin({ 202 | patterns: [{ 203 | from: 'public', 204 | globOptions: { 205 | ignore: [ 206 | '**/*.html' 207 | ] 208 | } 209 | }] 210 | }), 211 | new HtmlWebpackPlugin({ 212 | filename: 'index.html', 213 | template: 'public/index.html', 214 | chunks: ['index'] 215 | }) 216 | ], 217 | resolve: { 218 | alias: packages.reduce((alias, p) => ({ 219 | ...alias, 220 | [`@subwallet/${p}`]: path.resolve(__dirname, `../${p}/src`) 221 | }), { 222 | ...alias, 223 | 'react/jsx-runtime': require.resolve('react/jsx-runtime') 224 | }), 225 | extensions: ['.js', '.jsx', '.ts', '.tsx'], 226 | fallback: { 227 | crypto: require.resolve('crypto-browserify'), 228 | path: require.resolve('path-browserify'), 229 | stream: require.resolve('stream-browserify'), 230 | os: require.resolve('os-browserify/browser'), 231 | http: require.resolve('stream-http'), 232 | https: require.resolve('https-browserify'), 233 | assert: require.resolve('assert'), 234 | zlib: false, 235 | url: false 236 | } 237 | }, 238 | watch: false 239 | }; 240 | 241 | if (useSplitChunk) { 242 | result.optimization = { 243 | splitChunks: { 244 | chunks: 'all', 245 | maxSize: 2000000, 246 | cacheGroups: { 247 | vendors: { 248 | test: /[\\/]node_modules[\\/]/, 249 | priority: -10 250 | }, 251 | default: { 252 | priority: -20, 253 | reuseExistingChunk: true 254 | } 255 | } 256 | } 257 | }; 258 | } 259 | 260 | return result; 261 | }; 262 | -------------------------------------------------------------------------------- /packages/sub-connect/webpack.watch.cjs: -------------------------------------------------------------------------------- 1 | // Copyright 2019-2022 @subwallet/sub-connect authors & contributors 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | const createConfig = require('./webpack.shared.cjs'); 5 | 6 | module.exports = [createConfig({ 7 | index: './src/index.tsx' 8 | })]; 9 | -------------------------------------------------------------------------------- /packages/wagmi-connector/LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /packages/wagmi-connector/README.md: -------------------------------------------------------------------------------- 1 | # @subwallet/wagmi-connector 2 | -------------------------------------------------------------------------------- /packages/wagmi-connector/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "bugs": "https://github.com/Koniverse/SubConnect/issues", 3 | "homepage": "https://github.com/Koniverse/SubConnect/tree/master/packages/wagmi-connector#readme", 4 | "license": "Apache-2.0", 5 | "name": "@subwallet/wagmi-connector", 6 | "repository": { 7 | "directory": "packages/wagmi-connector", 8 | "type": "git", 9 | "url": "https://github.com/Koniverse/SubConnect.git" 10 | }, 11 | "sideEffects": [ 12 | "./detectPackage.js", 13 | "./detectPackage.cjs" 14 | ], 15 | "type": "module", 16 | "version": "0.2.1", 17 | "main": "index.js", 18 | "dependencies": { 19 | "@polkadot/util": "^10.1.11", 20 | "@wagmi/core": "^1.1.0", 21 | "viem": "^1.0.0" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /packages/wagmi-connector/src/detectOther.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2022 @subwallet/wagmi-connector authors & contributors 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | // Empty template, auto-generated by @polkadot/dev 5 | 6 | export default []; 7 | -------------------------------------------------------------------------------- /packages/wagmi-connector/src/detectPackage.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2022 @subwallet/wagmi-connector authors & contributors 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | // Do not edit, auto-generated by @polkadot/dev 5 | 6 | import { detectPackage } from '@polkadot/util'; 7 | 8 | import others from './detectOther'; 9 | import { packageInfo } from './packageInfo'; 10 | 11 | detectPackage(packageInfo, null, others); 12 | -------------------------------------------------------------------------------- /packages/wagmi-connector/src/env.d.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2022 @subwallet/wagmi-connector authors & contributors 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | declare interface Window { 5 | SubWallet?: Window['ethereum']; 6 | } 7 | -------------------------------------------------------------------------------- /packages/wagmi-connector/src/index.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2022 @subwallet/wagmi-connector authors & contributors 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import { Chain, InjectedConnector, InjectedConnectorOptions, WindowProvider } from '@wagmi/core'; 5 | 6 | export type WagmiSubConnectOptions = InjectedConnectorOptions 7 | 8 | type WagmiConstructorParams = { 9 | chains?: Chain[], 10 | options?: WagmiSubConnectOptions 11 | } 12 | 13 | export class SubWalletConnector extends InjectedConnector { 14 | override readonly id = 'subwallet'; 15 | override readonly ready = typeof window !== 'undefined' && !!window.SubWallet; 16 | 17 | constructor ({ chains, options: _options }: WagmiConstructorParams = {}) { 18 | super({ 19 | chains, 20 | options: { 21 | name: 'SubWallet', 22 | shimDisconnect: true, 23 | ..._options 24 | } 25 | }); 26 | } 27 | 28 | override async getProvider (): Promise { 29 | if (typeof window === 'undefined') { 30 | return; 31 | } 32 | 33 | return Promise.resolve(window.SubWallet); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /packages/wagmi-connector/src/packageInfo.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2022 @subwallet/wagmi-connector authors & contributors 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | // Do not edit, auto-generated by @polkadot/dev 5 | 6 | export const packageInfo = { name: '@subwallet/wagmi-connector', path: 'auto', type: 'auto', version: '0.2.1' }; 7 | -------------------------------------------------------------------------------- /packages/wagmi-connector/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "baseUrl": "..", 5 | "outDir": "./build", 6 | "rootDir": "./src" 7 | }, 8 | "references": [] 9 | } 10 | -------------------------------------------------------------------------------- /packages/wagmi-connector/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "baseUrl": "..", 5 | "outDir": "./build", 6 | "rootDir": "./src" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /packages/wallet-connect/LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /packages/wallet-connect/README.md: -------------------------------------------------------------------------------- 1 | # @subwallet/wallet-connect 2 | 3 | ## Overview 4 | 5 | This library aim to connect multiple extension wallets of Dotsama ecosystem that use the `@polkadot/extension-dapp` 6 | package with web3Enable. You can use this with any webUI to get features of extension. 7 | 8 | We built this packages with idea and some code from [@talisman-connect/wallets](https://github.com/TalismanSociety/talisman-connect/tree/master/libs/wallets). 9 | 10 | Here is main concept of this package: 11 | 12 | ![image](https://user-images.githubusercontent.com/11567273/170807488-fc23c8af-e6fa-4bf5-ba20-3968b9a6b23f.png) 13 | 14 | --- 15 | 16 | ## Getting start 17 | 18 | `wallet.ts` public some useful method will help to start connect with wallets. 19 | 20 | You can enable all supported wallets that activated on your browser with this code. Authentication popup of support and 21 | activated extension will be showed after this code first time. 22 | 23 | ```typescript 24 | // examples/example1.ts 25 | import { getWallets } from '../wallets'; 26 | import { Wallet } from '../types'; 27 | 28 | // Get all supported wallets 29 | const supportedWallets: Wallet[] = getWallets(); 30 | 31 | // Enable each supported wallet. 32 | supportedWallets.forEach((wallet) => { 33 | if (wallet.installed) { 34 | wallet.enable(); 35 | } 36 | }); 37 | ``` 38 | 39 | You can use wallet methods after enable extension. Example get account list: 40 | 41 | ```typescript 42 | // examples/example2.ts 43 | import { getWalletBySource } from '../wallets'; 44 | import { BaseDotsamaWallet } from '../base-dotsama-wallet'; 45 | 46 | const wallet = getWalletBySource('subwallet-js') as BaseDotsamaWallet; 47 | if (wallet) { 48 | wallet.enable() 49 | .then(() => { 50 | wallet.getAccounts() 51 | .then((accounts) => { 52 | accounts && accounts.forEach((account) => { 53 | console.log(account.name, account.address) 54 | }) 55 | }).catch(console.error) 56 | }).catch(console.error); 57 | } 58 | ``` 59 | 60 | You also can use object signer with [smart contract](https://polkadot.js.org/docs/api-contract/start/contract.read/) call 61 | 62 | ```typescript 63 | const contract = await new ContractPromise(api, abi, address); 64 | const address = '...' // Account address 65 | const wallet = getWalletBySource('subwallet-js') as BaseDotsamaWallet; 66 | if (wallet) { 67 | await wallet.enable() 68 | const signer = wallet.signer; 69 | if (signer && signer.signRaw && signer.signPayload) { 70 | await contract.tx 71 | .doSomething({ /* Smart contract method input go here */ }) 72 | .signAndSend( 73 | address, 74 | { signer }, 75 | async ({ status, dispatchError }) => { 76 | // Handle status callback here 77 | } 78 | ); 79 | //Run something after fisish 80 | } 81 | } 82 | ``` 83 | --- 84 | 85 | ## Add more wallet 86 | You can add more wallet and not required to modify this packages. 87 | To add new wallet you should you can see and example from `packages/sub-connect/src/new-wallet-example` 88 | - Add svg logo should not exceed 10KB 89 | - Create some code like `packages/sub-connect/src/new-wallet-example/newWalletExample.ts`: 90 | ```typescript 91 | import { addWallet } from '@subwallet/wallet-connect/dotsama/wallets'; 92 | 93 | import SubWalletLogo from './ExampleWallet.svg'; 94 | 95 | export const doAddWallet = () => { 96 | addWallet({ 97 | extensionName: 'example', 98 | title: 'New Wallet Example', 99 | installUrl: 'https://github.com/Koniverse/SubConnect', 100 | logo: { 101 | src: SubWalletLogo as string, 102 | alt: 'New Wallet Example' 103 | } 104 | }); 105 | }; 106 | ``` 107 | - Call doAddWallet before any functions in `packages/wallet-connect/src/dotsama/wallets.ts` is called. 108 | ```typescript 109 | // Import codes found here 110 | require('./App.scss'); 111 | 112 | // Add new example wallet 113 | doAddWallet(); 114 | 115 | export function App () { 116 | const [walletKey, setWalletKey] = useLocalStorage('wallet-key'); 117 | const [currentWallet, setCurrentWallet] = useState(getWalletBySource(walletKey)); 118 | const [isSelectWallet, setIsSelectWallet] = useState(false); 119 | const [accounts, setAccounts] = useState([]); 120 | 121 | // Another code found here 122 | } 123 | ``` 124 | 125 | --- 126 | ## Functions 127 | Basic functions from wallet.ts: 128 | - `addWallet(data: WalletInfo): void`: Add your custom wallet to the wallet list. This method need to be call before other method in this file is called. 129 | - `getWallets(): Wallet[]`: Get all supported wallets 130 | - `getWalletBySource( source: string | unknown )`: Get wallet by extensionName 131 | - `isWalletInstalled(source: string | unknown)` Check installation, activation of a wallet. 132 | 133 | Basic functions of wallets (BaseDotsamaWallet): 134 | - `wallet.intalled`: Check extension is installed and activated or not by checking object `window.injectedWeb3` 135 | - `wallet.enable(): Promise`: Enable wallet with your url by authentication popup in the first time and any time before use another wallet functions. 136 | - `wallet.getAccounts(): WalletAccount[]`: Get all account of the wallet. 137 | - `wallet.subscribeAccounts(callback): UnsubscribeFn`: Get and subscribe account changes. This will return self unsubscribe function. 138 | - `wallet.extention`: Return `InjectExtension` object that is provided wallet extension. You can found all extension interface in package `@polkadot/extension-inject`. We also make quick access of extension with these props: 139 | - `wallet.signer`: Quick access of `wallet.extension.signer` 140 | - `wallet.metadata`: Quick access of `wallet.extension.metadata` 141 | - `wallet.provider`: Quick access of `wallet.extension.provider` 142 | -------------------------------------------------------------------------------- /packages/wallet-connect/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "author": "Koni Studio", 3 | "bugs": "https://github.com/Koniverse/SubConnect/issues", 4 | "contributors": [], 5 | "description": "Provides an interfaces around the injected globals for ease of access by dapp developers.", 6 | "homepage": "https://github.com/Koniverse/SubConnect/tree/master/packages/wallet-connect#readme", 7 | "license": "Apache-2.0", 8 | "maintainers": [], 9 | "name": "@subwallet/wallet-connect", 10 | "repository": { 11 | "directory": "packages/wallet-connect", 12 | "type": "git", 13 | "url": "https://github.com/Koniverse/SubConnect.git" 14 | }, 15 | "sideEffects": [ 16 | "./detectPackage.js", 17 | "./detectPackage.cjs" 18 | ], 19 | "type": "module", 20 | "version": "0.2.6-beta.1", 21 | "main": "index.js", 22 | "dependencies": { 23 | "@babel/runtime": "^7.16.7", 24 | "@metamask/providers": "^11.1.1", 25 | "@metamask/types": "^1.1.0", 26 | "@polkadot/extension-dapp": "^0.46.5", 27 | "@polkadot/extension-inject": "^0.46.5", 28 | "@polkadot/types": "^10.9.1", 29 | "@polkadot/util": "^10.2.1" 30 | }, 31 | "devDependencies": { 32 | "@metamask/detect-provider": "^2.0.0", 33 | "@types/web3-provider-engine": "^14.0.1", 34 | "web3-core": "^1.10.1" 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /packages/wallet-connect/src/detectOther.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2022 @subwallet/wallet-connect authors & contributors 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | // Empty template, auto-generated by @polkadot/dev 5 | 6 | export default []; 7 | -------------------------------------------------------------------------------- /packages/wallet-connect/src/detectPackage.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2022 @subwallet/wallet-connect authors & contributors 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | // Do not edit, auto-generated by @polkadot/dev 5 | 6 | import { detectPackage } from '@polkadot/util'; 7 | 8 | import others from './detectOther'; 9 | import { packageInfo } from './packageInfo'; 10 | 11 | detectPackage(packageInfo, null, others); 12 | -------------------------------------------------------------------------------- /packages/wallet-connect/src/dotsama/BaseDotSamaWallet.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2019-2022 @subwallet/wallet-connect authors & contributors 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | // This file is get idea from https://github.com/TalismanSociety/talisman-connect/blob/master/libs/wallets/src/lib/base-dotsama-wallet/index.ts 5 | 6 | import { SubscriptionFn, Wallet, WalletAccount, WalletInfo, WalletLogoProps } from '@subwallet/wallet-connect/types'; 7 | 8 | import { InjectedAccount, InjectedExtension, InjectedMetadata, InjectedProvider, InjectedWindow } from '@polkadot/extension-inject/types'; 9 | import { Signer } from '@polkadot/types/types'; 10 | 11 | const DAPP_NAME = 'SubWallet Connect'; 12 | 13 | export class BaseDotSamaWallet implements Wallet { 14 | extensionName: string; 15 | title: string; 16 | installUrl: string; 17 | logo: WalletLogoProps; 18 | 19 | _extension: InjectedExtension | undefined; 20 | _signer: Signer | undefined; 21 | _metadata: InjectedMetadata | undefined; 22 | _provider: InjectedProvider | undefined; 23 | 24 | constructor ({ extensionName, installUrl, logo, title }: WalletInfo) { 25 | this.extensionName = extensionName; 26 | this.title = title; 27 | this.installUrl = installUrl; 28 | // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment 29 | this.logo = logo; 30 | 31 | return this; 32 | } 33 | 34 | // API docs: https://polkadot.js.org/docs/extension/ 35 | get extension () { 36 | return this._extension; 37 | } 38 | 39 | // API docs: https://polkadot.js.org/docs/extension/ 40 | get signer () { 41 | return this._signer; 42 | } 43 | 44 | get metadata () { 45 | return this._metadata; 46 | } 47 | 48 | get provider () { 49 | return this._provider; 50 | } 51 | 52 | get installed () { 53 | const injectedWindow = window as Window & InjectedWindow; 54 | const injectedExtension = 55 | injectedWindow?.injectedWeb3?.[this.extensionName]; 56 | 57 | return !!injectedExtension; 58 | } 59 | 60 | get rawExtension () { 61 | const injectedWindow = window as Window & InjectedWindow; 62 | 63 | return injectedWindow?.injectedWeb3?.[this.extensionName]; 64 | } 65 | 66 | enable = async () => { 67 | if (!this.installed) { 68 | return; 69 | } 70 | 71 | try { 72 | const injectedExtension = this.rawExtension; 73 | 74 | if (!injectedExtension || !injectedExtension.enable) { 75 | return; 76 | } 77 | 78 | const rawExtension = await injectedExtension.enable(DAPP_NAME); 79 | 80 | if (!rawExtension) { 81 | return; 82 | } 83 | 84 | const extension: InjectedExtension = { 85 | ...rawExtension, 86 | // Manually add `InjectedExtensionInfo` so as to have a consistent response. 87 | name: this.extensionName, 88 | version: injectedExtension.version || 'unknown' 89 | }; 90 | 91 | this._extension = extension; 92 | this._signer = extension?.signer; 93 | this._metadata = extension?.metadata; 94 | this._provider = extension?.provider; 95 | } catch (err) { 96 | console.error(err); 97 | } 98 | }; 99 | 100 | private generateWalletAccount = (account: InjectedAccount): WalletAccount => { 101 | return { 102 | ...account, 103 | source: this._extension?.name as string, 104 | // Added extra fields here for convenience 105 | wallet: this, 106 | signer: this._extension?.signer 107 | } as WalletAccount; 108 | }; 109 | 110 | subscribeAccounts = async (callback: SubscriptionFn) => { 111 | if (!this._extension) { 112 | await this?.enable(); 113 | } 114 | 115 | if (!this._extension) { 116 | // eslint-disable-next-line @typescript-eslint/no-floating-promises 117 | callback(undefined); 118 | 119 | return null; 120 | } 121 | 122 | return this._extension.accounts.subscribe( 123 | (accounts: InjectedAccount[]) => { 124 | const accountsWithWallet = accounts.map(this.generateWalletAccount); 125 | 126 | // eslint-disable-next-line @typescript-eslint/no-floating-promises 127 | callback(accountsWithWallet); 128 | } 129 | ); 130 | }; 131 | 132 | getAccounts = async () => { 133 | if (!this._extension) { 134 | await this?.enable(); 135 | } 136 | 137 | if (!this._extension) { 138 | return null; 139 | } 140 | 141 | const accounts = await this._extension.accounts.get(); 142 | 143 | return accounts.map(this.generateWalletAccount); 144 | }; 145 | } 146 | -------------------------------------------------------------------------------- /packages/wallet-connect/src/dotsama/predefinedWallet/FearlessWalletLogo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /packages/wallet-connect/src/dotsama/predefinedWallet/NovaWalletLogo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 19 | 23 | 24 | -------------------------------------------------------------------------------- /packages/wallet-connect/src/dotsama/predefinedWallet/PolkadotLogo.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /packages/wallet-connect/src/dotsama/predefinedWallet/SubWalletLogo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /packages/wallet-connect/src/dotsama/predefinedWallet/TalismanLogo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /packages/wallet-connect/src/dotsama/predefinedWallet/index.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2019-2022 @subwallet/wallet-connect authors & contributors 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import { WalletInfo } from '@subwallet/wallet-connect/types'; 5 | 6 | // @ts-ignore 7 | import FearlessWalletLogo from './FearlessWalletLogo.svg'; 8 | // @ts-ignore 9 | import PolkadotJsLogo from './PolkadotLogo.svg'; 10 | // @ts-ignore 11 | import SubWalletLogo from './SubWalletLogo.svg'; 12 | // @ts-ignore 13 | import TalismanLogo from './TalismanLogo.svg'; 14 | // @ts-ignore 15 | import NovaWalletLogo from './NovaWalletLogo.svg'; 16 | 17 | export const PREDEFINED_WALLETS: WalletInfo[] = [ 18 | { 19 | extensionName: 'subwallet-js', 20 | title: 'SubWallet', 21 | installUrl: 'https://chrome.google.com/webstore/detail/subwallet/onhogfjeacnfoofkfgppdlbmlmnplgbn', 22 | logo: { 23 | src: SubWalletLogo as string, 24 | alt: 'SubWallet' 25 | } 26 | }, 27 | { 28 | extensionName: 'polkadot-js', 29 | title: 'Polkadot{.js}', 30 | installUrl: 'https://chrome.google.com/webstore/detail/polkadot%7Bjs%7D-extension/mopnmbcafieddcagagdcbnhejhlodfdd', 31 | logo: { 32 | src: PolkadotJsLogo as string, 33 | alt: 'Polkadot{.js} Extension' 34 | } 35 | }, 36 | { 37 | extensionName: 'talisman', 38 | title: 'Talisman', 39 | installUrl: 'https://chrome.google.com/webstore/detail/talisman-wallet/fijngjgcjhjmmpcmkeiomlglpeiijkld', 40 | logo: { 41 | src: TalismanLogo as string, 42 | alt: 'Talisman' 43 | } 44 | }, 45 | { 46 | extensionName: 'fearless-wallet', 47 | title: 'Fearless Wallet', 48 | installUrl: 'https://chrome.google.com/webstore/detail/fearless-wallet/nhlnehondigmgckngjomcpcefcdplmgc', 49 | logo: { 50 | src: FearlessWalletLogo as string, 51 | alt: 'Fearless Wallet Extension' 52 | } 53 | }, 54 | { 55 | extensionName: 'polkadot-js', 56 | title: 'Nova Wallet', 57 | installUrl: 'https://novawallet.io', 58 | logo: { 59 | src: NovaWalletLogo as string, 60 | alt: 'Nova Wallet' 61 | } 62 | } 63 | ]; 64 | -------------------------------------------------------------------------------- /packages/wallet-connect/src/dotsama/wallets.spec.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2019-2022 @subwallet/wallet-connect authors & contributors 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import { addWallet, getWalletBySource, getWallets } from '@subwallet/wallet-connect/dotsama/wallets'; 5 | import { WalletInfo } from '@subwallet/wallet-connect/types'; 6 | 7 | describe('Test Wallets Methods', () => { 8 | it('Test getWallets', () => { 9 | const wallets = getWallets(); 10 | 11 | expect(wallets.length).toEqual(3); 12 | }); 13 | 14 | it('Test getWalletBySource', () => { 15 | expect(getWalletBySource('subwallet-js')?.title).toEqual('SubWallet'); 16 | expect(getWalletBySource('polkadot-js')?.title).toEqual('Polkadot{.js}'); 17 | }); 18 | 19 | it('Test addWallet', () => { 20 | const walletInfo = { 21 | title: 'Custom', 22 | extensionName: 'custom-wallet', 23 | installUrl: '', 24 | logo: { 25 | src: '', 26 | alt: 'Custom' 27 | } 28 | } as WalletInfo; 29 | 30 | addWallet(walletInfo); 31 | const wallets = getWallets(); 32 | 33 | expect(wallets.length).toEqual(4); 34 | expect(getWalletBySource(walletInfo.extensionName)?.title).toEqual(walletInfo.title); 35 | }); 36 | }); 37 | -------------------------------------------------------------------------------- /packages/wallet-connect/src/dotsama/wallets.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2019-2022 @subwallet/wallet-connect authors & contributors 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | // This file is get idea from https://github.com/TalismanSociety/talisman-connect/blob/master/libs/wallets/src/lib/wallets.ts 5 | 6 | import { BaseDotSamaWallet } from '@subwallet/wallet-connect/dotsama/BaseDotSamaWallet'; 7 | import { PREDEFINED_WALLETS } from '@subwallet/wallet-connect/dotsama/predefinedWallet'; 8 | import { Wallet, WalletInfo } from '@subwallet/wallet-connect/types'; 9 | 10 | const walletList: Wallet[] = []; 11 | 12 | // Add more wallet, please sure you call this method before any getWallets or getWalletBySource 13 | export function addWallet (data: WalletInfo) { 14 | const wallet = (new BaseDotSamaWallet(data)) as Wallet; 15 | 16 | walletList.push(wallet); 17 | } 18 | 19 | // Implement predefined wallets 20 | PREDEFINED_WALLETS.forEach((walletInfo) => { 21 | addWallet(walletInfo); 22 | }); 23 | 24 | // Get all wallet 25 | export function getWallets (): Wallet[] { 26 | return walletList; 27 | } 28 | 29 | export function getWalletBySource (source: string | unknown): Wallet | undefined { 30 | return getWallets().find((wallet) => { 31 | return wallet.extensionName === source; 32 | }); 33 | } 34 | 35 | export function isWalletInstalled (source: string | unknown): boolean { 36 | const wallet = getWalletBySource(source); 37 | 38 | return wallet?.installed as boolean; 39 | } 40 | -------------------------------------------------------------------------------- /packages/wallet-connect/src/evm/BaseEvmWallet.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2019-2022 @subwallet/wallet-connect authors & contributors 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import { MetaMaskInpageProvider } from '@metamask/providers'; 5 | import { RequestArguments } from '@metamask/providers/dist/BaseProvider'; 6 | import { Maybe } from '@metamask/types'; 7 | import { EvmWallet, EvmWalletInfo, WalletLogoProps } from '@subwallet/wallet-connect/types'; 8 | 9 | export class BaseEvmWallet implements EvmWallet { 10 | extensionName = ''; 11 | installUrl = ''; 12 | logo: WalletLogoProps; 13 | title: string; 14 | isSetGlobalString: string; 15 | initEvent?: string; 16 | _isReady = false; 17 | _handledReady = false; 18 | isReady: Promise; 19 | 20 | _extension: MetaMaskInpageProvider | undefined; 21 | 22 | constructor ({ extensionName, initEvent, installUrl, isSetGlobalString, logo, title }: EvmWalletInfo) { 23 | this.extensionName = extensionName; 24 | this.logo = logo; 25 | this.title = title; 26 | this.installUrl = installUrl; 27 | this.isSetGlobalString = isSetGlobalString; 28 | this.initEvent = initEvent; 29 | this.isReady = this.waitReady() 30 | .then((extension) => { 31 | this._extension = extension; 32 | this._isReady = true; 33 | 34 | return extension; 35 | }); 36 | } 37 | 38 | private lookupProvider () { 39 | // @ts-ignore 40 | // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access 41 | return ((window && window[this.extensionName]) || (window?.ethereum && window?.ethereum[this.isSetGlobalString])) as MetaMaskInpageProvider; 42 | } 43 | 44 | private async waitReady (timeout = 3000): Promise { 45 | if (this._isReady) { 46 | return Promise.resolve(this.extension); 47 | } 48 | 49 | return new Promise((resolve) => { 50 | let currentProvider = this.lookupProvider(); 51 | const initEvent = this.initEvent; 52 | 53 | if (currentProvider) { 54 | this._handledReady = true; 55 | resolve(currentProvider); 56 | } else if (initEvent) { 57 | const handleProvider = () => { 58 | if (this._handledReady) { 59 | return; 60 | } 61 | 62 | this._handledReady = true; 63 | 64 | window.removeEventListener(initEvent, handleProvider); 65 | 66 | currentProvider = this.lookupProvider(); 67 | 68 | if (!currentProvider) { 69 | console.warn(`Not found provider of ${this.title}(${this.extensionName})`); 70 | } 71 | 72 | resolve(currentProvider); 73 | }; 74 | 75 | window.addEventListener(initEvent, handleProvider, { once: true }); 76 | setTimeout(() => { 77 | handleProvider(); 78 | }, timeout); 79 | } 80 | }); 81 | } 82 | 83 | get extension () { 84 | if (!this._extension) { 85 | this._extension = this.lookupProvider(); 86 | } 87 | 88 | return this._extension; 89 | } 90 | 91 | get installed () { 92 | return !!this.extension; 93 | } 94 | 95 | async enable (): Promise { 96 | await this.isReady; 97 | const accounts = await this.request({ method: 'eth_requestAccounts' }); 98 | 99 | return !!(accounts && accounts.length > 0); 100 | } 101 | 102 | async request (args: RequestArguments): Promise> { 103 | await this.isReady; 104 | 105 | return await this.extension.request(args); 106 | } 107 | 108 | // addProvider (provider: any): void { 109 | // } 110 | // 111 | // on (event: string, handler: () => void): void { 112 | // } 113 | // 114 | // send (payload: JSONRPCRequestPayload): void { 115 | // } 116 | // 117 | // sendAsync (payload: JSONRPCRequestPayload, callback: (error: (Error | null), response: JSONRPCResponsePayload) => void): void; 118 | // sendAsync (payload: JSONRPCRequestPayload, callback: JSONRPCErrorCallback): void; 119 | // sendAsync (payload: JSONRPCRequestPayload, callback: ((error: (Error | null), response: JSONRPCResponsePayload) => void) | JSONRPCErrorCallback): void { 120 | // } 121 | // 122 | // start (callback?: () => void): void { 123 | // } 124 | // 125 | // stop (): void { 126 | // } 127 | } 128 | -------------------------------------------------------------------------------- /packages/wallet-connect/src/evm/evmWallets.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2019-2022 @subwallet/wallet-connect authors & contributors 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import { BaseEvmWallet } from '@subwallet/wallet-connect/evm/BaseEvmWallet'; 5 | import { PREDEFINED_EVM_WALLETS } from '@subwallet/wallet-connect/evm/predefinedWallet'; 6 | import { EvmWallet, EvmWalletInfo } from '@subwallet/wallet-connect/types'; 7 | 8 | const evmWallets: EvmWallet[] = []; 9 | 10 | // Add more wallet, please sure you call this method before any getEvmWallets or getEvmWalletBySource 11 | export function addEvmWallet (data: EvmWalletInfo) { 12 | const wallet = (new BaseEvmWallet(data)) as EvmWallet; 13 | 14 | evmWallets.push(wallet); 15 | } 16 | 17 | PREDEFINED_EVM_WALLETS.forEach((data) => { 18 | evmWallets.push(new BaseEvmWallet(data)); 19 | }); 20 | 21 | export function getEvmWallets () { 22 | return evmWallets; 23 | } 24 | 25 | export function getEvmWalletBySource (source: string | unknown): EvmWallet | undefined { 26 | return getEvmWallets().find((wallet) => { 27 | return wallet.extensionName === source; 28 | }); 29 | } 30 | 31 | export function isEvmWalletInstalled (source: string | unknown): boolean { 32 | const wallet = getEvmWalletBySource(source); 33 | 34 | return wallet?.installed as boolean; 35 | } 36 | -------------------------------------------------------------------------------- /packages/wallet-connect/src/evm/predefinedWallet/MetaMaskLogo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 49 | 50 | 51 | 53 | 55 | 56 | 57 | 58 | 60 | 61 | -------------------------------------------------------------------------------- /packages/wallet-connect/src/evm/predefinedWallet/NovaWalletLogo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 19 | 23 | 24 | -------------------------------------------------------------------------------- /packages/wallet-connect/src/evm/predefinedWallet/SubWalletLogo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /packages/wallet-connect/src/evm/predefinedWallet/index.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2019-2022 @subwallet/wallet-connect authors & contributors 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import { EvmWalletInfo } from '@subwallet/wallet-connect/types'; 5 | 6 | // @ts-ignore 7 | import MetaMaskLogo from './MetaMaskLogo.svg'; 8 | // @ts-ignore 9 | import SubWalletLogo from './SubWalletLogo.svg'; 10 | // @ts-ignore 11 | import NovaWalletLogo from './NovaWalletLogo.svg'; 12 | 13 | export const PREDEFINED_EVM_WALLETS: EvmWalletInfo[] = [ 14 | { 15 | extensionName: 'SubWallet', 16 | title: 'SubWallet (EVM)', 17 | installUrl: 'https://chrome.google.com/webstore/detail/subwallet/onhogfjeacnfoofkfgppdlbmlmnplgbn', 18 | logo: { 19 | src: SubWalletLogo as string, 20 | alt: 'SubWallet (EVM)' 21 | }, 22 | isSetGlobalString: 'isSubWallet', 23 | initEvent: 'subwallet#initialized' 24 | }, 25 | { 26 | extensionName: 'ethereum', 27 | title: 'MetaMask', 28 | installUrl: 'https://chrome.google.com/webstore/detail/metamask/nkbihfbeogaeaoehlefnkodbefgpgknn', 29 | logo: { 30 | src: MetaMaskLogo as string, 31 | alt: 'MetaMask Extension' 32 | }, 33 | isSetGlobalString: 'isMetaMask', 34 | initEvent: 'ethereum#initialized' 35 | }, 36 | { 37 | extensionName: 'ethereum', 38 | title: 'Nova Wallet (EVM)', 39 | installUrl: 'https://novawallet.io', 40 | logo: { 41 | src: NovaWalletLogo as string, 42 | alt: 'NovaWallet (EVM)' 43 | }, 44 | isSetGlobalString: 'isNovaWallet', 45 | initEvent: 'ethereum#initialized' 46 | } 47 | ]; 48 | -------------------------------------------------------------------------------- /packages/wallet-connect/src/index.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2019-2022 @subwallet/wallet-connect authors & contributors 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | // no direct exports 5 | -------------------------------------------------------------------------------- /packages/wallet-connect/src/packageInfo.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2022 @subwallet/wallet-connect authors & contributors 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | // Do not edit, auto-generated by @polkadot/dev 5 | 6 | export const packageInfo = { name: '@subwallet/wallet-connect', path: 'auto', type: 'auto', version: '0.2.6-beta.1' }; 7 | -------------------------------------------------------------------------------- /packages/wallet-connect/src/types.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2019-2022 @subwallet/wallet-connect authors & contributors 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import { MetaMaskInpageProvider } from '@metamask/providers'; 5 | import { RequestArguments } from '@metamask/providers/dist/BaseProvider'; 6 | import { Maybe } from '@metamask/providers/dist/utils'; 7 | 8 | import { InjectedExtension, InjectedMetadata, InjectedProvider, Unsubcall } from '@polkadot/extension-inject/types'; 9 | import { Signer } from '@polkadot/types/types'; 10 | 11 | export type SubscriptionFn = ( 12 | accounts: WalletAccount[] | undefined 13 | ) => void | Promise; 14 | 15 | export interface WalletLogoProps { 16 | src: string; 17 | alt: string; 18 | } 19 | 20 | export interface WalletAccount { 21 | address: string; 22 | source: string; 23 | name?: string; 24 | wallet?: Wallet; 25 | signer?: unknown; 26 | } 27 | 28 | export interface WalletInfo { 29 | extensionName: string; 30 | title: string; 31 | installUrl: string; 32 | logo: WalletLogoProps; 33 | } 34 | 35 | export interface WalletMethods { 36 | enable: () => Promise; 37 | 38 | subscribeAccounts: (callback: SubscriptionFn) => Promise; 39 | 40 | getAccounts: () => Promise 41 | } 42 | 43 | export interface Wallet extends WalletInfo, WalletMethods { 44 | installed: boolean | undefined; 45 | 46 | extension: InjectedExtension | undefined; 47 | 48 | signer: Signer | undefined; 49 | 50 | metadata: InjectedMetadata | undefined; 51 | 52 | provider: InjectedProvider | undefined; 53 | } 54 | export interface EvmWalletMethods { 55 | request(args: RequestArguments): Promise>; 56 | enable(): Promise 57 | } 58 | 59 | export interface EvmWalletInfo extends WalletInfo { 60 | isSetGlobalString: string; 61 | initEvent?: string 62 | } 63 | 64 | export interface EvmWallet extends EvmWalletInfo, EvmWalletMethods { 65 | installed: boolean; 66 | extension: MetaMaskInpageProvider | undefined; 67 | isReady: Promise; 68 | } 69 | 70 | // EVM request method callback event params 71 | export interface EvmConnectParams { 72 | chainId: string; 73 | } 74 | -------------------------------------------------------------------------------- /packages/wallet-connect/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "baseUrl": "..", 5 | "outDir": "./build", 6 | "rootDir": "./src" 7 | }, 8 | "references": [] 9 | } 10 | -------------------------------------------------------------------------------- /packages/wallet-connect/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "baseUrl": "..", 5 | "outDir": "./build", 6 | "rootDir": "./src" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /packages/web3-react-subwallet-connector-v6/README.md: -------------------------------------------------------------------------------- 1 | # @subwallet/web3-react-subwallet-connector-v6 2 | 3 | ## Overview 4 | Connector of SubWallet on web3-react v6 5 | 6 | This connector have been implemented on https://github.com/saltict/web3-react/tree/v6/example -------------------------------------------------------------------------------- /packages/web3-react-subwallet-connector-v6/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "author": "Koni Studio", 3 | "bugs": "https://github.com/Koniverse/SubConnect/issues", 4 | "contributors": [], 5 | "description": "Connector of SubWallet on web3-react.", 6 | "homepage": "https://github.com/Koniverse/SubConnect/tree/master/packages/web3-react-subwallet-connector-v6#readme", 7 | "license": "Apache-2.0", 8 | "maintainers": [], 9 | "name": "@subwallet/web3-react-subwallet-connector-v6", 10 | "repository": { 11 | "directory": "packages/web3-react-subwallet-connector-v6", 12 | "type": "git", 13 | "url": "https://github.com/Koniverse/SubConnect.git" 14 | }, 15 | "sideEffects": [ 16 | "./detectPackage.js", 17 | "./detectPackage.cjs" 18 | ], 19 | "type": "module", 20 | "version": "0.2.6-beta.1", 21 | "main": "index.js", 22 | "dependencies": { 23 | "@polkadot/util": "^10.1.11", 24 | "@web3-react/abstract-connector": "^6.0.7", 25 | "@web3-react/types": "^6.0.7", 26 | "tiny-warning": "^1.0.3" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /packages/web3-react-subwallet-connector-v6/src/declarations.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2019-2022 @subwallet/web3-react-subwallet-connector-v6 authors & contributors 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | interface Ethereum { 5 | request: (args: { method: string, params?: any[] }) => Promise 6 | isSubWallet: boolean; 7 | on?: (method: string, listener: (...args: any[]) => void) => void 8 | off?: (method: string, listener: (...args: any[]) => void) => void 9 | } 10 | 11 | declare interface Window { 12 | SubWallet?: Ethereum 13 | } 14 | -------------------------------------------------------------------------------- /packages/web3-react-subwallet-connector-v6/src/detectOther.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2022 @subwallet/web3-react-subwallet-connector-v6 authors & contributors 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | // Empty template, auto-generated by @polkadot/dev 5 | 6 | export default []; 7 | -------------------------------------------------------------------------------- /packages/web3-react-subwallet-connector-v6/src/detectPackage.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2022 @subwallet/web3-react-subwallet-connector-v6 authors & contributors 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | // Do not edit, auto-generated by @polkadot/dev 5 | 6 | import { detectPackage } from '@polkadot/util'; 7 | 8 | import others from './detectOther'; 9 | import { packageInfo } from './packageInfo'; 10 | 11 | detectPackage(packageInfo, null, others); 12 | -------------------------------------------------------------------------------- /packages/web3-react-subwallet-connector-v6/src/index.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2019-2022 @subwallet/web3-react-subwallet-connector-v6 authors & contributors 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import { AbstractConnector } from '@web3-react/abstract-connector'; 5 | import { AbstractConnectorArguments, ConnectorUpdate } from '@web3-react/types'; 6 | import warning from 'tiny-warning'; 7 | 8 | import { RequestResponse } from './types'; 9 | 10 | function parseRequest (response: RequestResponse): any { 11 | return response; 12 | } 13 | 14 | function parseHex (response: RequestResponse): number | undefined { 15 | try { 16 | if (typeof response === 'string') { 17 | return parseInt(response, 16); 18 | } 19 | } catch (e) { 20 | return undefined; 21 | } 22 | 23 | return 0; 24 | } 25 | 26 | export class NoEthereumProviderError extends Error { 27 | public constructor () { 28 | super(); 29 | this.name = this.constructor.name; 30 | this.message = 'No Ethereum provider was found on window.SubWallet.'; 31 | } 32 | } 33 | 34 | export class UserRejectedRequestError extends Error { 35 | public constructor () { 36 | super(); 37 | this.name = this.constructor.name; 38 | this.message = 'The user rejected the request.'; 39 | } 40 | } 41 | 42 | export class SubWalletConnector extends AbstractConnector { 43 | constructor (kwargs: AbstractConnectorArguments) { 44 | super(kwargs); 45 | 46 | this.handleChainChanged = this.handleChainChanged.bind(this); 47 | this.handleAccountsChanged = this.handleAccountsChanged.bind(this); 48 | this.handleClose = this.handleClose.bind(this); 49 | } 50 | 51 | private handleChainChanged (chainId: string | number): void { 52 | this.emitUpdate({ chainId: parseHex(chainId), provider: window.SubWallet }); 53 | } 54 | 55 | private handleAccountsChanged (accounts: string[]): void { 56 | if (accounts.length === 0) { 57 | this.emitDeactivate(); 58 | } else { 59 | this.emitUpdate({ account: accounts[0] }); 60 | } 61 | } 62 | 63 | private handleError (error: Error): void { 64 | console.error(error); 65 | this.emitDeactivate(); 66 | } 67 | 68 | private handleClose (code: number, reason: string): void { 69 | this.emitDeactivate(); 70 | } 71 | 72 | public async activate (): Promise { 73 | const provider = await this.getProvider(); 74 | 75 | if (provider?.on) { 76 | provider.on('chainChanged', this.handleChainChanged); 77 | provider.on('accountsChanged', this.handleAccountsChanged); 78 | provider.on('error', this.handleError); 79 | provider.on('close', this.handleClose); 80 | } 81 | 82 | // try to activate + get account via eth_requestAccounts 83 | let account; 84 | 85 | try { 86 | account = await provider?.request({ method: 'eth_requestAccounts' }) 87 | .then((result) => (result as string[])[0]); 88 | } catch (error) { 89 | // @ts-ignore 90 | if (error.code === 4001) { 91 | throw new UserRejectedRequestError(); 92 | } 93 | 94 | warning(false, 'eth_requestAccounts was unsuccessful, falling back to enable'); 95 | } 96 | 97 | // if unsuccessful, try enable 98 | if (!account) { 99 | // if enable is successful but doesn't return accounts, fall back to getAccount (not happy i have to do this...) 100 | // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment 101 | account = await provider?.request({ method: 'eth_accounts' }) 102 | // eslint-disable-next-line @typescript-eslint/no-unsafe-return 103 | .then((result) => result && (result as string[])[0]); 104 | } 105 | 106 | // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment 107 | return { provider, ...(account ? { account } : {}) }; 108 | } 109 | 110 | public async getProvider (): Promise { 111 | return new Promise((resolve, reject) => { 112 | if (window.SubWallet) { 113 | resolve(window.SubWallet); 114 | } else { 115 | const throwNoEthereumError = setTimeout(() => { 116 | reject(new NoEthereumProviderError()); 117 | }, 3000); 118 | 119 | window.addEventListener('subwallet#initialized', () => { 120 | clearTimeout(throwNoEthereumError); 121 | 122 | resolve(window.SubWallet); 123 | }); 124 | } 125 | }); 126 | } 127 | 128 | public async getChainId (): Promise { 129 | const provider = await this.getProvider(); 130 | 131 | let chainId; 132 | 133 | try { 134 | chainId = await provider?.request({ method: 'eth_chainId' }) 135 | .then(parseHex); 136 | } catch { 137 | warning(false, 'eth_chainId was unsuccessful, falling back to net_version'); 138 | } 139 | 140 | return chainId as number; 141 | } 142 | 143 | public async getAccount (): Promise { 144 | const provider = await this.getProvider(); 145 | 146 | let account; 147 | 148 | try { 149 | account = await provider?.request({ method: 'eth_accounts' }) 150 | .then((result) => (result as string[])[0]); 151 | } catch { 152 | warning(false, 'eth_accounts was unsuccessful, falling back to enable'); 153 | } 154 | 155 | if (!account) { 156 | try { 157 | account = await provider?.request({ method: 'eth_requestAccounts' }) 158 | .then((result) => (result as string[])[0]); 159 | } catch { 160 | warning(false, 'enable was unsuccessful, falling back to eth_accounts v2'); 161 | } 162 | } 163 | 164 | return account as string; 165 | } 166 | 167 | public deactivate () { 168 | this.getProvider().then((provider) => { 169 | if (provider && provider.off) { 170 | provider.off('chainChanged', this.handleChainChanged); 171 | provider.off('accountsChanged', this.handleAccountsChanged); 172 | provider.off('error', this.handleClose); 173 | provider.off('close', this.handleClose); 174 | } 175 | }).catch(console.error); 176 | } 177 | 178 | public async isAuthorized (): Promise { 179 | try { 180 | const provider = await this.getProvider(); 181 | let isAuthorized = false; 182 | 183 | await Promise.race([ 184 | provider?.request({ method: 'eth_accounts' }) 185 | .then((result) => { 186 | // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access 187 | if (parseRequest(result).length > 0) { 188 | isAuthorized = true; 189 | } else { 190 | isAuthorized = false; 191 | } 192 | }), 193 | new Promise((resolve) => { 194 | // Timeout used to quick fix error of SubWallet v0.4.6 only 195 | setTimeout(() => { 196 | isAuthorized = false; 197 | 198 | resolve(); 199 | }, 1000); 200 | }) 201 | ]); 202 | 203 | return isAuthorized; 204 | } catch (e) { 205 | return false; 206 | } 207 | } 208 | } 209 | -------------------------------------------------------------------------------- /packages/web3-react-subwallet-connector-v6/src/packageInfo.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2022 @subwallet/web3-react-subwallet-connector-v6 authors & contributors 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | // Do not edit, auto-generated by @polkadot/dev 5 | 6 | export const packageInfo = { name: '@subwallet/web3-react-subwallet-connector-v6', path: 'auto', type: 'auto', version: '0.2.6-beta.1' }; 7 | -------------------------------------------------------------------------------- /packages/web3-react-subwallet-connector-v6/src/types.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2019-2022 @subwallet/web3-react-subwallet-connector-v6 authors & contributors 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | export type RequestResponse = any 5 | 6 | export type Request = (args: {method: string, params?: any[]}) => Promise 7 | -------------------------------------------------------------------------------- /packages/web3-react-subwallet-connector-v6/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "baseUrl": "..", 5 | "outDir": "./build", 6 | "rootDir": "./src" 7 | }, 8 | "references": [] 9 | } 10 | -------------------------------------------------------------------------------- /packages/web3-react-subwallet-connector-v6/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "baseUrl": "..", 5 | "outDir": "./build", 6 | "rootDir": "./src" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /rollup.config.mjs: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2022 @subwallet/extension authors & contributors 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | import pluginAlias from '@rollup/plugin-alias'; 5 | import pluginCommonjs from '@rollup/plugin-commonjs'; 6 | import pluginInject from '@rollup/plugin-inject'; 7 | import pluginJson from '@rollup/plugin-json'; 8 | import { nodeResolve as pluginResolve } from '@rollup/plugin-node-resolve'; 9 | import fs from 'fs'; 10 | import path from 'path'; 11 | import pluginCleanup from 'rollup-plugin-cleanup'; 12 | 13 | function sanitizePkg (pkg) { 14 | return pkg.replace('@subwallet/', ''); 15 | } 16 | 17 | function createName (input) { 18 | return `polkadot-${sanitizePkg(input)}` 19 | .toLowerCase() 20 | .replace(/[^a-zA-Z0-9]+(.)/g, (_, c) => c.toUpperCase()); 21 | } 22 | 23 | export function createInput (pkg, _index) { 24 | const partialPath = `packages/${sanitizePkg(pkg)}/build`; 25 | const index = ( 26 | _index || 27 | fs.existsSync(path.join(process.cwd(), partialPath, 'bundle.js')) 28 | ? 'bundle.js' 29 | : ( 30 | JSON.parse(fs.readFileSync(path.join(process.cwd(), partialPath, 'package.json'), 'utf8')).browser || 31 | 'index.js' 32 | ) 33 | ); 34 | 35 | return `${partialPath}/${index}`; 36 | } 37 | 38 | export function createOutput (_pkg, external, globals) { 39 | const pkg = sanitizePkg(_pkg); 40 | 41 | return { 42 | file: `packages/${pkg}/build/bundle-polkadot-${pkg}.js`, 43 | format: 'umd', 44 | globals: external.reduce((all, pkg) => ({ 45 | [pkg]: createName(pkg), 46 | ...all 47 | }), { ...globals }), 48 | intro: 'const global = window;', 49 | name: createName(_pkg), 50 | preferConst: true 51 | }; 52 | } 53 | 54 | export function createBundle ({ entries = {}, external, globals = {}, index, inject = {}, pkg }) { 55 | return { 56 | external, 57 | input: createInput(pkg, index), 58 | output: createOutput(pkg, external, globals), 59 | plugins: [ 60 | pluginAlias({ entries }), 61 | pluginJson(), 62 | pluginCommonjs(), 63 | pluginInject(inject), 64 | pluginResolve({ browser: true }), 65 | pluginCleanup() 66 | ] 67 | }; 68 | } 69 | 70 | 71 | const pkgs = [ 72 | '@subwallet/wallet-connect', 73 | '@subwallet/wagmi-connector', 74 | '@subwallet/web3-react-subwallet-connector-v6' 75 | ]; 76 | 77 | const external = [ 78 | ...pkgs, 79 | '@polkadot/networks', 80 | '@polkadot/util' 81 | ]; 82 | 83 | const entries = [].reduce((all, p) => ({ 84 | ...all, 85 | [`@subwallet/${p}`]: path.resolve(process.cwd(), `packages/${p}/build`) 86 | }), {}); 87 | 88 | const overrides = {}; 89 | 90 | export default pkgs.map((pkg) => { 91 | const override = (overrides[pkg] || {}); 92 | 93 | return createBundle({ 94 | external, 95 | pkg, 96 | ...override, 97 | entries: { 98 | ...entries, 99 | ...(override.entries || {}) 100 | }, 101 | resolve: { 102 | fallback: { 103 | "url": false, 104 | "zlib": false, 105 | "https": false, 106 | "http": false, 107 | } 108 | } 109 | }); 110 | }); 111 | -------------------------------------------------------------------------------- /scripts/koni-ci-build-dev.mjs: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | // Copyright 2017-2022 @polkadot/dev authors & contributors 3 | // SPDX-License-Identifier: Apache-2.0 4 | 5 | import path from 'path'; 6 | import axios from 'axios'; 7 | import fs from "fs"; 8 | 9 | import execSync from '@polkadot/dev/scripts/execSync.mjs'; 10 | import {Webhook} from "discord-webhook-node"; 11 | 12 | console.log('$ polkadot-ci-ghact-build', process.argv.slice(2).join(' ')); 13 | 14 | const discordHook = new Webhook(process.env.DISCORD_WEBHOOK); 15 | 16 | function runClean() { 17 | execSync('yarn polkadot-dev-clean-build'); 18 | } 19 | 20 | function runCheck() { 21 | execSync('yarn lint'); 22 | } 23 | 24 | function runTest() { 25 | execSync('yarn test'); 26 | } 27 | 28 | function runBuild() { 29 | execSync('yarn build'); 30 | } 31 | 32 | function npmGetVersion() { 33 | return JSON.parse(fs.readFileSync(path.resolve(process.cwd(), 'package.json'), 'utf8')).version; 34 | } 35 | 36 | async function uploadBuild() { 37 | const refName = process.env.REF_NAME 38 | const commitMessage = process.env.COMMIT_MESSAGE 39 | const nowTimestamp = new Date().getTime() 40 | const sRefName = refName.replace(/(\/)/g, '-'); 41 | 42 | discordHook.send('Finish build ' + refName + ': ' + commitMessage) 43 | 44 | try { 45 | const cloudConfig = JSON.parse(process.env.NEXTCLOUD_CONFIG) 46 | const {nextCloudUrl, nextCloudUsername, nextCloudPassword, folder, shareFolder} = cloudConfig; 47 | 48 | const newName = `./${sRefName}-build-${npmGetVersion()}-${nowTimestamp}.zip` 49 | const downloadLink = `${nextCloudUrl}/s/${shareFolder}/download?path=%2F&files=${newName}`; 50 | const uploadUrl = `${nextCloudUrl}/remote.php/dav/files/${nextCloudUsername}/${folder}/${newName}`; 51 | 52 | const file = await fs.readFileSync('./master-build.zip'); 53 | 54 | const rs = await axios.put(uploadUrl, file, { 55 | auth: { 56 | username: nextCloudUsername, password: nextCloudPassword 57 | }, 58 | headers: {'Content-Type': 'text/octet-stream'}, 59 | maxContentLength: Infinity, 60 | maxBodyLength: Infinity 61 | }) 62 | 63 | if (rs.statusText === 'Created') { 64 | discordHook.send('Upload success! Please download here:') 65 | discordHook.send(downloadLink) 66 | } else { 67 | console.warn('Can not upload build to discord!') 68 | } 69 | } catch (e) { 70 | console.warn('NEXTCLOUD_CONFIG WRONG', e) 71 | } 72 | } 73 | 74 | runClean(); 75 | runCheck(); 76 | runTest(); 77 | runBuild(); 78 | 79 | uploadBuild() 80 | -------------------------------------------------------------------------------- /scripts/koni-ci-ghact-build.mjs: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | // Copyright 2017-2022 @polkadot/dev authors & contributors 3 | // SPDX-License-Identifier: Apache-2.0 4 | 5 | import fs from 'fs'; 6 | import os from 'os'; 7 | import path from 'path'; 8 | import yargs from 'yargs'; 9 | 10 | import copySync from '@polkadot/dev/scripts/copySync.mjs'; 11 | import execSync from '@polkadot/dev/scripts/execSync.mjs'; 12 | import {Webhook} from "discord-webhook-node"; 13 | 14 | console.log('$ polkadot-ci-ghact-build', process.argv.slice(2).join(' ')); 15 | 16 | const discordHook = new Webhook(process.env.DISCORD_WEBHOOK); 17 | 18 | const repo = `https://${process.env.GH_PAT}@github.com/${process.env.GITHUB_REPOSITORY}.git`; 19 | 20 | const argv = yargs(process.argv.slice(2)) 21 | .options({ 22 | 'skip-beta': { 23 | description: 'Do not increment as beta', 24 | type: 'boolean' 25 | } 26 | }) 27 | .strict() 28 | .argv; 29 | 30 | function runClean () { 31 | execSync('yarn polkadot-dev-clean-build'); 32 | } 33 | 34 | function runCheck () { 35 | execSync('yarn lint'); 36 | } 37 | 38 | function runTest () { 39 | execSync('yarn test'); 40 | 41 | // if [ -f "coverage/lcov.info" ] && [ -n "$COVERALLS_REPO_TOKEN" ]; then 42 | // console.log('*** Submitting to coveralls.io'); 43 | 44 | // (cat coverage/lcov.info | yarn run coveralls) || true 45 | // fi 46 | } 47 | 48 | function runBuild () { 49 | execSync('yarn build'); 50 | } 51 | 52 | function npmGetVersion () { 53 | return JSON.parse( 54 | fs.readFileSync(path.resolve(process.cwd(), 'package.json'), 'utf8') 55 | ).version; 56 | } 57 | 58 | function npmSetup () { 59 | const registry = 'registry.npmjs.org'; 60 | 61 | fs.writeFileSync(path.join(os.homedir(), '.npmrc'), `//${registry}/:_authToken=${process.env.NPM_TOKEN}`); 62 | } 63 | 64 | function npmPublish () { 65 | if (fs.existsSync('.skip-npm')) { 66 | return; 67 | } 68 | 69 | ['LICENSE', 'package.json'] 70 | .filter((file) => !fs.existsSync(path.join(process.cwd(), 'build', file))) 71 | .forEach((file) => copySync(file, 'build')); 72 | 73 | process.chdir('build'); 74 | 75 | const tag = npmGetVersion().includes('-') ? '--tag beta' : ''; 76 | let count = 1; 77 | 78 | while (true) { 79 | try { 80 | execSync(`npm publish --access public ${tag}`); 81 | 82 | break; 83 | } catch (error) { 84 | if (count < 5) { 85 | const end = Date.now() + 15000; 86 | 87 | console.error(`Publish failed on attempt ${count}/5. Retrying in 15s`); 88 | count++; 89 | 90 | while (Date.now() < end) { 91 | // just spin our wheels 92 | } 93 | } 94 | } 95 | } 96 | 97 | process.chdir('..'); 98 | } 99 | 100 | function gitSetup () { 101 | execSync('git config push.default simple'); 102 | execSync('git config merge.ours.driver true'); 103 | execSync('git config user.name "github-actions[bot]"'); 104 | execSync('git config user.email "action@github.com"'); 105 | execSync('git checkout master'); 106 | } 107 | 108 | function gitBump () { 109 | const currentVersion = npmGetVersion(); 110 | const [version, tag] = currentVersion.split('-'); 111 | const [,, patch] = version.split('.'); 112 | 113 | if (argv['skip-beta'] || patch === '0') { 114 | // don't allow beta versions 115 | execSync('yarn polkadot-dev-version patch'); 116 | } else { 117 | const triggerPath = path.join(process.cwd(), '.123trigger'); 118 | const available = fs.readFileSync(triggerPath, 'utf-8').split('\n'); 119 | 120 | if (tag || patch === '1' || available.includes(currentVersion)) { 121 | // if we have a beta version, just continue the stream of betas 122 | execSync('yarn polkadot-dev-version pre'); 123 | } else { 124 | // manual setting of version, make some changes so we can commit 125 | fs.appendFileSync(triggerPath, `\n${currentVersion}`); 126 | } 127 | } 128 | 129 | execSync('yarn polkadot-dev-contrib'); 130 | execSync('git add --all .'); 131 | } 132 | 133 | function gitPush () { 134 | const version = npmGetVersion(); 135 | let doGHRelease = false; 136 | 137 | if (process.env.GH_RELEASE_GITHUB_API_TOKEN) { 138 | const changes = fs.readFileSync('CHANGELOG.md', 'utf8'); 139 | 140 | if (changes.includes(`## ${version}`)) { 141 | doGHRelease = true; 142 | } else if (version.endsWith('.1')) { 143 | discordHook.send(`Unable to release, no CHANGELOG entry for ${version}`) 144 | throw new Error(`Unable to release, no CHANGELOG entry for ${version}`); 145 | } 146 | } 147 | 148 | execSync('git add --all .'); 149 | 150 | if (fs.existsSync('docs/README.md')) { 151 | execSync('git add --all -f docs'); 152 | } 153 | 154 | // add the skip checks for GitHub ... 155 | execSync(`git commit --no-status --quiet -m "[CI Skip] release/${version.includes('-') ? 'beta' : 'stable'} ${version} 156 | 157 | 158 | skip-checks: true"`); 159 | 160 | execSync(`git push ${repo} HEAD:${process.env.GITHUB_REF}`, true); 161 | discordHook.send(`Auto to increase version to ${version} on origin/master`) 162 | 163 | if (doGHRelease) { 164 | const files = process.env.GH_RELEASE_FILES 165 | ? `--assets ${process.env.GH_RELEASE_FILES}` 166 | : ''; 167 | 168 | execSync(`yarn polkadot-exec-ghrelease --draft ${files} --yes`); 169 | discordHook.send(`Release finished ${version}. Please review and publish!`) 170 | } 171 | } 172 | 173 | function loopFunc (fn) { 174 | if (fs.existsSync('packages')) { 175 | fs 176 | .readdirSync('packages') 177 | .filter((dir) => { 178 | const pkgDir = path.join(process.cwd(), 'packages', dir); 179 | 180 | return fs.statSync(pkgDir).isDirectory() && 181 | fs.existsSync(path.join(pkgDir, 'package.json')) && 182 | fs.existsSync(path.join(pkgDir, 'build')); 183 | }) 184 | .forEach((dir) => { 185 | process.chdir(path.join('packages', dir)); 186 | fn(); 187 | process.chdir('../..'); 188 | }); 189 | } else { 190 | fn(); 191 | } 192 | } 193 | 194 | gitSetup(); 195 | gitBump(); 196 | npmSetup(); 197 | 198 | runClean(); 199 | runCheck(); 200 | runTest(); 201 | runBuild(); 202 | 203 | gitPush(); 204 | loopFunc(npmPublish); 205 | -------------------------------------------------------------------------------- /tsconfig.base.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@polkadot/dev/config/tsconfig.json", 3 | "compilerOptions": { 4 | "composite": true, 5 | "paths": { 6 | "@subwallet/sub-connect": ["sub-connect/src"], 7 | "@subwallet/sub-connect/*": ["sub-connect/src/*"], 8 | "@subwallet/wallet-connect": ["wallet-connect/src"], 9 | "@subwallet/wallet-connect/*": ["wallet-connect/src/*"], 10 | "@subwallet/web3-react-subwallet-connector-v6": ["web3-react-subwallet-connector-v6/src"], 11 | "@subwallet/web3-react-subwallet-connector-v6/*": ["web3-react-subwallet-connector-v6/src/*"], 12 | "@subwallet/wagmi-connector": ["wagmi-connector/src"], 13 | "@subwallet/wagmi-connector/*": ["wagmi-connector/src/*"] 14 | }, 15 | "skipLibCheck": true 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "composite": true 4 | }, 5 | "files": [], 6 | "references": [ 7 | { "path": "./packages/sub-connect/tsconfig.build.json" }, 8 | { "path": "./packages/wallet-connect/tsconfig.build.json" }, 9 | { "path": "./packages/web3-react-subwallet-connector-v6/tsconfig.build.json" }, 10 | { "path": "./packages/wagmi-connector/tsconfig.build.json"} 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /tsconfig.eslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.base.json", 3 | "compilerOptions": { 4 | "baseUrl": "./packages", 5 | "composite": false 6 | }, 7 | "include": [ 8 | "packages/**/src/**/*", 9 | "packages/**/scripts/**/*", 10 | "packages/**/test/**/*" 11 | ], 12 | "exclude": [ 13 | "**/node_modules/**/*" 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.base.json", 3 | "compilerOptions": { 4 | "baseUrl": "./packages", 5 | "composite": false 6 | }, 7 | "include": [ 8 | "packages/**/src/**/*" 9 | ], 10 | "exclude": [ 11 | "**/node_modules/**/*" 12 | ] 13 | } 14 | --------------------------------------------------------------------------------