diff --git a/common/changes/@cityofzion/wallet-connect-sdk-react/main_2024-06-18-20-09.json b/common/changes/@cityofzion/wallet-connect-sdk-react/main_2024-06-18-20-09.json new file mode 100644 index 0000000..c4aac4d --- /dev/null +++ b/common/changes/@cityofzion/wallet-connect-sdk-react/main_2024-06-18-20-09.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@cityofzion/wallet-connect-sdk-react", + "comment": "Fix emitter", + "type": "patch" + } + ], + "packageName": "@cityofzion/wallet-connect-sdk-react" +} \ No newline at end of file diff --git a/common/changes/@cityofzion/wallet-connect-sdk-svelte/main_2024-06-18-20-09.json b/common/changes/@cityofzion/wallet-connect-sdk-svelte/main_2024-06-18-20-09.json new file mode 100644 index 0000000..db1e430 --- /dev/null +++ b/common/changes/@cityofzion/wallet-connect-sdk-svelte/main_2024-06-18-20-09.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@cityofzion/wallet-connect-sdk-svelte", + "comment": "Fix emitter", + "type": "patch" + } + ], + "packageName": "@cityofzion/wallet-connect-sdk-svelte" +} \ No newline at end of file diff --git a/common/changes/@cityofzion/wallet-connect-sdk-wallet-react/main_2024-06-18-20-09.json b/common/changes/@cityofzion/wallet-connect-sdk-wallet-react/main_2024-06-18-20-09.json new file mode 100644 index 0000000..c00073d --- /dev/null +++ b/common/changes/@cityofzion/wallet-connect-sdk-wallet-react/main_2024-06-18-20-09.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@cityofzion/wallet-connect-sdk-wallet-react", + "comment": "Fix emitter", + "type": "patch" + } + ], + "packageName": "@cityofzion/wallet-connect-sdk-wallet-react" +} \ No newline at end of file diff --git a/common/config/rush/command-line.json b/common/config/rush/command-line.json index b3f09e2..076a0a9 100644 --- a/common/config/rush/command-line.json +++ b/common/config/rush/command-line.json @@ -23,6 +23,17 @@ "safeForSimultaneousRushProcesses": true, "autoinstallerName": "rush-format", "shellCommand": "prettier . --write --config .prettierrc && npm run format -p --prefix ./packages/wallet-connect-sdk-core && npm run format -p --prefix ./packages/wallet-connect-sdk-react && npm run format -p --prefix ./packages/wallet-connect-sdk-wallet-core && npm run format -p --prefix ./packages/wallet-connect-sdk-wallet-react && npm run format -p --prefix ./e2e" + }, + { + "commandKind": "bulk", + "name": "build", + "summary": "Build all projects that haven't been built, or have changed since they were last built", + "description": "It's the rush build, but overriding the `allowWarningsInSuccessfulBuild`option", + "safeForSimultaneousRushProcesses": false, + "enableParallelism": true, + "ignoreDependencyOrder": false, + "ignoreMissingScript": false, + "allowWarningsInSuccessfulBuild": true } ] } diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index 3f04e40..790d19e 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -72,6 +72,9 @@ importers: eslint: specifier: ^8.51.0 version: 8.57.0 + events: + specifier: ^3.3.0 + version: 3.3.0 gh-pages: specifier: ^2.2.0 version: 2.2.0 @@ -93,6 +96,9 @@ importers: react-scripts: specifier: ^4.0.3 version: 4.0.3(react@16.14.0)(typescript@4.9.5) + typed-emitter: + specifier: ^2.1.0 + version: 2.1.0 typedoc: specifier: ^0.22.10 version: 0.22.18(typescript@4.9.5) @@ -124,24 +130,33 @@ importers: eslint: specifier: ^8.51.0 version: 8.57.0 + events: + specifier: ^3.3.0 + version: 3.3.0 rollup: specifier: ~4.1.4 version: 4.1.6 rollup-plugin-auto-external: specifier: ~2.0.0 version: 2.0.0(rollup@4.1.6) - rollup-plugin-dts: - specifier: ~6.1.0 - version: 6.1.1(rollup@4.1.6)(typescript@4.9.5) rollup-plugin-esbuild: specifier: ~6.1.0 version: 6.1.1(esbuild@0.21.4)(rollup@4.1.6) + rollup-plugin-polyfill-node: + specifier: ^0.13.0 + version: 0.13.0(rollup@4.1.6) + rollup-plugin-ts: + specifier: ^3.4.5 + version: 3.4.5(rollup@4.1.6)(typescript@4.9.5) svelte: specifier: ^4.0.5 version: 4.2.17 tslib: specifier: ^2.4.1 version: 2.6.2 + typed-emitter: + specifier: ^2.1.0 + version: 2.1.0 typedoc: specifier: ^0.22.10 version: 0.22.18(typescript@4.9.5) @@ -231,6 +246,9 @@ importers: eslint: specifier: ^8.51.0 version: 8.57.0 + events: + specifier: ^3.3.0 + version: 3.3.0 microbundle-crl: specifier: ^0.13.10 version: 0.13.11 @@ -249,6 +267,9 @@ importers: react-scripts: specifier: ^4.0.3 version: 4.0.3(react@16.14.0)(typescript@4.9.5) + typed-emitter: + specifier: ^2.1.0 + version: 2.1.0 typedoc: specifier: ^0.22.10 version: 0.22.18(typescript@4.9.5) @@ -3727,6 +3748,10 @@ packages: '@jridgewell/sourcemap-codec': 1.4.15 dev: true + /@mdn/browser-compat-data@5.5.34: + resolution: {integrity: sha512-e8k7+8r3jiJuP7FMH6AL1OnmfQqLyABhTM+NmRDvFeAbMgtFcNQLHpmT7uza5cBnxI01+CAU3aSsIgcKGRdEBQ==} + dev: true + /@noble/curves@1.0.0: resolution: {integrity: sha512-2upgEu0iLiDVDZkNLeFV2+ht0BAVgQnEmCk6JsOch9Rp8xfkMCbvbAZlA2pBHQc73dbl+vFOXfqkf4uemdn0bw==} dependencies: @@ -3997,6 +4022,21 @@ packages: rollup: 4.1.6 dev: true + /@rollup/plugin-inject@5.0.5(rollup@4.1.6): + resolution: {integrity: sha512-2+DEJbNBoPROPkgTDNe8/1YXWcqxbN5DTjASVIOx8HS+pITXushyNiBV56RB08zuptzz8gT3YfkqriTBVycepg==} + engines: {node: '>=14.0.0'} + peerDependencies: + rollup: ^1.20.0||^2.0.0||^3.0.0||^4.0.0 + peerDependenciesMeta: + rollup: + optional: true + dependencies: + '@rollup/pluginutils': 5.1.0(rollup@4.1.6) + estree-walker: 2.0.2 + magic-string: 0.30.10 + rollup: 4.1.6 + dev: true + /@rollup/plugin-json@4.1.0(rollup@1.32.1): resolution: {integrity: sha512-yfLbTdNS6amI/2OpmbiBoW12vngr5NW2jCJVZSBEz+H5KfUJZ2M7sDjk0U6GOOdCWFVScShte29o9NezJ53TPw==} peerDependencies: @@ -4547,6 +4587,10 @@ packages: resolution: {integrity: sha512-K0VQKziLUWkVKiRVrx4a40iPaxTUefQmjtkQofBkYRcoaaL/8rhwDWww9qWbrgicNOgnpIsMxyNIUM4+n6dUIA==} dev: true + /@types/node@17.0.45: + resolution: {integrity: sha512-w+tIMs3rq2afQdsPJlODhoUEKzFP1ayaoyl1CcnwtIlsVe7K7bA1NGm4s3PraqTLlXnbIN84zuBlxBWo1u9BLw==} + dev: true + /@types/node@20.12.12: resolution: {integrity: sha512-eWLDGF/FOSPtAvEqeRAQ4C8LSA7M1I7i0ky1I8U7kD1J5ITyW3AsRhQrKVoWf5pFKZ2kILsEGJhsI9r93PYnOw==} dependencies: @@ -4557,6 +4601,10 @@ packages: resolution: {integrity: sha512-37i+OaWTh9qeK4LSHPsyRC7NahnGotNuZvjLSgcPzblpHB3rrCJxAOgI5gCdKm7coonsaX1Of0ILiTcnZjbfxA==} dev: true + /@types/object-path@0.11.4: + resolution: {integrity: sha512-4tgJ1Z3elF/tOMpA8JLVuR9spt9Ynsf7+JjqsQ2IqtiPJtcLoHoXcT6qU4E10cPFqyXX5HDm9QwIzZhBSkLxsw==} + dev: true + /@types/parse-json@4.0.2: resolution: {integrity: sha512-dISoDXWWQwUquiKsyZ4Ng+HX2KsPL7LyHKHQwgGFEA3IaKac4Obd+h2a/a6waisAoepJlBcx9paWqjA8/HVjCw==} dev: true @@ -4622,6 +4670,10 @@ packages: resolution: {integrity: sha512-bTHG8fcxEqv1M9+TD14P8ok8hjxoOCkfKc8XXLaaD05kI7ohpeI956jtDOD3XHKBQrlyPughUtzm1jtVhHpA5Q==} dev: true + /@types/ua-parser-js@0.7.39: + resolution: {integrity: sha512-P/oDfpofrdtF5xw433SPALpdSchtJmY7nsJItf8h3KXqOslkbySh8zq4dSWXH2oTjRvJ5PczVEoCZPow6GicLg==} + dev: true + /@types/uglify-js@3.17.5: resolution: {integrity: sha512-TU+fZFBTBcXj/GpDpDaBmgWk/gn96kMZ+uocaFUlV2f8a6WdMzzI44QBCmGcCiYR0Y6ZlNRiyUyKKt5nl/lbzQ==} dependencies: @@ -5341,6 +5393,11 @@ packages: '@xtuc/long': 4.2.2 dev: true + /@wessberg/stringutil@1.0.19: + resolution: {integrity: sha512-9AZHVXWlpN8Cn9k5BC/O0Dzb9E9xfEMXzYrNunwvkUTvuK7xgQPVRZpLo+jWCOZ5r8oBa8NIrHuPEu1hzbb6bg==} + engines: {node: '>=8.0.0'} + dev: true + /@xtuc/ieee754@1.2.0: resolution: {integrity: sha512-DX8nKgqcGwsc0eJSqYt5lwP4DH5FlHnmuWWBRy7X0NcaGR0ZtuyeESgMwTYVEtxmsNGY+qit4QYT/MIYTOTPeA==} dev: true @@ -6335,6 +6392,22 @@ packages: pako: 1.0.11 dev: true + /browserslist-generator@2.1.0: + resolution: {integrity: sha512-ZFz4mAOgqm0cbwKaZsfJbYDbTXGoPANlte7qRsRJOfjB9KmmISQrXJxAVrnXG8C8v/QHNzXyeJt0Cfcks6zZvQ==} + engines: {node: '>=16.15.1', npm: '>=7.0.0', pnpm: '>=3.2.0', yarn: '>=1.13'} + dependencies: + '@mdn/browser-compat-data': 5.5.34 + '@types/object-path': 0.11.4 + '@types/semver': 7.5.8 + '@types/ua-parser-js': 0.7.39 + browserslist: 4.23.0 + caniuse-lite: 1.0.30001624 + isbot: 3.8.0 + object-path: 0.11.8 + semver: 7.6.2 + ua-parser-js: 1.0.38 + dev: true + /browserslist@4.14.2: resolution: {integrity: sha512-HI4lPveGKUR0x2StIz+2FXfDk9SfVMrxn6PLh1JeGUwcuoDkdKZebWiyLRJ68iIPDpMI4JLVDf7S7XzslgWOhw==} engines: {node: ^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7} @@ -6803,6 +6876,16 @@ packages: resolution: {integrity: sha512-W9pAhw0ja1Edb5GVdIF1mjZw/ASI0AlShXM83UUGe2DVr5TdAPEA1OA8m/g8zWp9x6On7gqufY+FatDbC3MDQg==} dev: true + /compatfactory@3.0.0(typescript@4.9.5): + resolution: {integrity: sha512-WD5kF7koPwVoyKL8p0LlrmIZtilrD46sQStyzzxzTFinMKN2Dxk1hN+sddLSQU1mGIZvQfU8c+ONSghvvM40jg==} + engines: {node: '>=14.9.0'} + peerDependencies: + typescript: '>=3.x || >= 4.x || >= 5.x' + dependencies: + helpertypes: 0.0.19 + typescript: 4.9.5 + dev: true + /component-emitter@1.3.1: resolution: {integrity: sha512-T0+barUSQRTUQASh8bx02dl+DhF54GtIDY13Y3m9oWTklKbb3Wv974meRpeZ3lp1JpLVECWWNHC4vaG2XHXouQ==} dev: true @@ -7051,6 +7134,13 @@ packages: shebang-command: 2.0.0 which: 2.0.2 + /crosspath@2.0.0: + resolution: {integrity: sha512-ju88BYCQ2uvjO2bR+SsgLSTwTSctU+6Vp2ePbKPgSCZyy4MWZxYsT738DlKVRE5utUjobjPRm1MkTYKJxCmpTA==} + engines: {node: '>=14.9.0'} + dependencies: + '@types/node': 17.0.45 + dev: true + /crossws@0.2.4: resolution: {integrity: sha512-DAxroI2uSOgUKLz00NX6A8U/8EE3SZHmIND+10jkVSaypvyt57J5JEOxAQOL6lQxyzi/wZbTIwssU1uy69h5Vg==} peerDependencies: @@ -9542,6 +9632,11 @@ packages: hasBin: true dev: true + /helpertypes@0.0.19: + resolution: {integrity: sha512-J00e55zffgi3yVnUp0UdbMztNkr2PnizEkOe9URNohnrNhW5X0QpegkuLpOmFQInpi93Nb8MCjQRHAiCDF42NQ==} + engines: {node: '>=10.0.0'} + dev: true + /hex-color-regex@1.1.0: resolution: {integrity: sha512-l9sfDFsuqtOqKDsQdqrMRk0U85RZc0RtOR9yPI7mRVOa4FsR/BVnZ0shmQRM96Ji99kYZP/7hn1cedc1+ApsTQ==} dev: true @@ -10378,6 +10473,11 @@ packages: resolution: {integrity: sha512-xHjhDr3cNBK0BzdUJSPXZntQUx/mwMS5Rw4A7lPJ90XGAO6ISP/ePDNuo0vhqOZU+UD5JoodwCAAoZQd3FeAKw==} dev: true + /isbot@3.8.0: + resolution: {integrity: sha512-vne1mzQUTR+qsMLeCBL9+/tgnDXRyc2pygLGl/WsgA+EZKIiB5Ehu0CiVTHIIk30zhJ24uGz4M5Ppse37aR0Hg==} + engines: {node: '>=12'} + dev: true + /isexe@2.0.0: resolution: {integrity: sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==} @@ -12006,7 +12106,7 @@ packages: dependencies: growly: 1.3.0 is-wsl: 2.2.0 - semver: 7.3.2 + semver: 7.6.2 shellwords: 0.1.1 uuid: 8.3.2 which: 2.0.2 @@ -12154,6 +12254,11 @@ packages: engines: {node: '>= 0.4'} dev: true + /object-path@0.11.8: + resolution: {integrity: sha512-YJjNZrlXJFM42wTBn6zgOJVar9KFJvzx6sTWDte8sWZF//cnjl0BxHNpfZx+ZffXX63A9q0b1zsFiBX4g4X5KA==} + engines: {node: '>= 10.12.0'} + dev: true + /object-visit@1.0.1: resolution: {integrity: sha512-GBaMwwAVK9qbQN3Scdo0OyvgPW7l3lnaVMj84uTOZlswkX0KpF6fyDBJhtTthf7pymztoN36/KEr1DyhF96zEA==} engines: {node: '>=0.10.0'} @@ -14282,20 +14387,6 @@ packages: maxmin: 2.1.0 dev: true - /rollup-plugin-dts@6.1.1(rollup@4.1.6)(typescript@4.9.5): - resolution: {integrity: sha512-aSHRcJ6KG2IHIioYlvAOcEq6U99sVtqDDKVhnwt70rW6tsz3tv5OSjEiWcgzfsHdLyGXZ/3b/7b/+Za3Y6r1XA==} - engines: {node: '>=16'} - peerDependencies: - rollup: ^3.29.4 || ^4 - typescript: ^4.5 || ^5.0 - dependencies: - magic-string: 0.30.10 - rollup: 4.1.6 - typescript: 4.9.5 - optionalDependencies: - '@babel/code-frame': 7.24.6 - dev: true - /rollup-plugin-es3@1.1.0: resolution: {integrity: sha512-jTMqQgMZ/tkjRW4scf4ln5c0OiTSi+Lx/IEyFd41ldgGoLvvg9AQxmVOl93+KaoyB7XRYToYjiHDvO40NPF/fA==} dependencies: @@ -14319,6 +14410,15 @@ packages: - supports-color dev: true + /rollup-plugin-polyfill-node@0.13.0(rollup@4.1.6): + resolution: {integrity: sha512-FYEvpCaD5jGtyBuBFcQImEGmTxDTPbiHjJdrYIp+mFIwgXiXabxvKUK7ZT9P31ozu2Tqm9llYQMRWsfvTMTAOw==} + peerDependencies: + rollup: ^1.20.0 || ^2.0.0 || ^3.0.0 || ^4.0.0 + dependencies: + '@rollup/plugin-inject': 5.0.5(rollup@4.1.6) + rollup: 4.1.6 + dev: true + /rollup-plugin-postcss@2.9.0: resolution: {integrity: sha512-Y7qDwlqjZMBexbB1kRJf+jKIQL8HR6C+ay53YzN+nNJ64hn1PNZfBE3c61hFUhD//zrMwmm7uBW30RuTi+CD0w==} engines: {node: '>=10'} @@ -14366,6 +14466,49 @@ packages: terser: 4.8.1 dev: true + /rollup-plugin-ts@3.4.5(rollup@4.1.6)(typescript@4.9.5): + resolution: {integrity: sha512-9iCstRJpEZXSRQuXitlSZAzcGlrqTbJg1pE4CMbEi6xYldxVncdPyzA2I+j6vnh73wBymZckerS+Q/iEE/M3Ow==} + engines: {node: '>=16.15.1', npm: '>=7.0.0', pnpm: '>=3.2.0', yarn: '>=1.13'} + peerDependencies: + '@babel/core': '>=7.x' + '@babel/plugin-transform-runtime': '>=7.x' + '@babel/preset-env': '>=7.x' + '@babel/preset-typescript': '>=7.x' + '@babel/runtime': '>=7.x' + '@swc/core': '>=1.x' + '@swc/helpers': '>=0.2' + rollup: '>=1.x || >=2.x || >=3.x' + typescript: '>=3.2.x || >= 4.x || >= 5.x' + peerDependenciesMeta: + '@babel/core': + optional: true + '@babel/plugin-transform-runtime': + optional: true + '@babel/preset-env': + optional: true + '@babel/preset-typescript': + optional: true + '@babel/runtime': + optional: true + '@swc/core': + optional: true + '@swc/helpers': + optional: true + dependencies: + '@rollup/pluginutils': 5.1.0(rollup@4.1.6) + '@wessberg/stringutil': 1.0.19 + ansi-colors: 4.1.3 + browserslist: 4.23.0 + browserslist-generator: 2.1.0 + compatfactory: 3.0.0(typescript@4.9.5) + crosspath: 2.0.0 + magic-string: 0.30.10 + rollup: 4.1.6 + ts-clone-node: 3.0.0(typescript@4.9.5) + tslib: 2.6.2 + typescript: 4.9.5 + dev: true + /rollup-plugin-typescript2@0.25.3(rollup@1.32.1)(typescript@3.9.10): resolution: {integrity: sha512-ADkSaidKBovJmf5VBnZBZe+WzaZwofuvYdzGAKTN/J4hN7QJCFYAq7IrH9caxlru6T5qhX41PNFS1S4HqhsGQg==} peerDependencies: @@ -15679,6 +15822,16 @@ packages: typescript: 4.9.5 dev: true + /ts-clone-node@3.0.0(typescript@4.9.5): + resolution: {integrity: sha512-egavvyHbIoelkgh1IC2agNB1uMNjB8VJgh0g/cn0bg2XXTcrtjrGMzEk4OD3Fi2hocICjP3vMa56nkzIzq0FRg==} + engines: {node: '>=14.9.0'} + peerDependencies: + typescript: ^3.x || ^4.x || ^5.x + dependencies: + compatfactory: 3.0.0(typescript@4.9.5) + typescript: 4.9.5 + dev: true + /ts-pnp@1.2.0(typescript@4.9.5): resolution: {integrity: sha512-csd+vJOb/gkzvcCHgTGSChYpy5f1/XKNsmvBGO4JXS+z1v2HobugDz4s1IeFXM3wZB44uczs+eazB5Q/ccdhQw==} engines: {node: '>=6'} @@ -15866,6 +16019,10 @@ packages: hasBin: true dev: true + /ua-parser-js@1.0.38: + resolution: {integrity: sha512-Aq5ppTOfvrCMgAPneW1HfWj66Xi7XL+/mIy996R1/CLS/rcyJQm6QZdsKrUeivDFQ+Oc9Wyuwor8Ze8peEoUoQ==} + dev: true + /ufo@1.5.3: resolution: {integrity: sha512-Y7HYmWaFwPUmkoQCUIAYpKqkOf+SbVj/2fJJZ4RJMCfZp0rTGwRbzQD+HghfnhKOjL9E01okqz+ncJskGYfBNw==} dev: false diff --git a/e2e/src/constants/DevConstants.ts b/e2e/src/constants/DevConstants.ts index a481749..cc4fc4a 100644 --- a/e2e/src/constants/DevConstants.ts +++ b/e2e/src/constants/DevConstants.ts @@ -1,9 +1,10 @@ -import { DAPP_REACT, DAPP_VITE_VANILLA, WALLET_REACT } from './ProjectsDefinitions' +import { DAPP_REACT, DAPP_VITE_SVELTEKIT, DAPP_VITE_VANILLA, WALLET_REACT } from './ProjectsDefinitions' export const RUN_CONCURRENTLY_COMMAND: string = `concurrently ${[ DAPP_REACT.runCommand, WALLET_REACT.runCommand, DAPP_VITE_VANILLA.runCommand, + DAPP_VITE_SVELTEKIT.runCommand, ].join(' ')}` export const HTML_ENTITIES = { diff --git a/e2e/src/constants/ProjectsDefinitions.ts b/e2e/src/constants/ProjectsDefinitions.ts index 4c24386..7681842 100644 --- a/e2e/src/constants/ProjectsDefinitions.ts +++ b/e2e/src/constants/ProjectsDefinitions.ts @@ -2,3 +2,4 @@ import ExampleProject from '../models/ExampleProject' export const DAPP_REACT: ExampleProject = new ExampleProject('wc-dapp-react', 3000) export const WALLET_REACT: ExampleProject = new ExampleProject('wc-wallet-react', 3001) export const DAPP_VITE_VANILLA: ExampleProject = new ExampleProject('wc-dapp-vite-vanilla', 3002) +export const DAPP_VITE_SVELTEKIT: ExampleProject = new ExampleProject('wc-dapp-sveltekit', 3003) diff --git a/e2e/src/helpers/CommonStepsHelper.ts b/e2e/src/helpers/CommonStepsHelper.ts index b2464ec..196568f 100644 --- a/e2e/src/helpers/CommonStepsHelper.ts +++ b/e2e/src/helpers/CommonStepsHelper.ts @@ -1,22 +1,45 @@ import { BrowserContext } from '@playwright/test' import ExampleProject from '../models/ExampleProject' import { connectDappToReactWallet, createNewReactWallet } from '../pageCommonSteps/WalletReactSteps' -import { getReactDappUri } from '../pageCommonSteps/DappReactSteps' +import { getDappUri } from '../pageCommonSteps/DappReactSteps' -export async function connectReactDappToNewReactAccount( +async function connectGenericDappToNewReactAccount( context: BrowserContext, dappPage: ExampleProject, + dappComponentTestId: string, walletPage: ExampleProject, + actionBeforeConnectWallet?: (dappPage: ExampleProject, walletPage: ExampleProject) => Promise | void, ) { // Initialize a variable to store the dapp URI let dappUri: string | null = null // Open the dapp and wallet pages in the browser context await dappPage.openPage(context) await walletPage.openPage(context) + + if (actionBeforeConnectWallet) await actionBeforeConnectWallet(dappPage, walletPage) + // Get the URI of the dapp - dappUri = await getReactDappUri(dappPage) + dappUri = await getDappUri(dappPage, dappComponentTestId) // Create a wallet await createNewReactWallet(walletPage) // Connect to the dapp await connectDappToReactWallet(walletPage, dappUri) } + +export async function connectReactDappToNewReactAccount( + context: BrowserContext, + dappPage: ExampleProject, + walletPage: ExampleProject, + actionBeforeConnectWallet?: (dappPage: ExampleProject, walletPage: ExampleProject) => Promise | void, +) { + await connectGenericDappToNewReactAccount(context, dappPage, 'hello-world', walletPage, actionBeforeConnectWallet) +} + +export async function connectSvelteDappToNewReactAccount( + context: BrowserContext, + dappPage: ExampleProject, + walletPage: ExampleProject, + actionBeforeConnectWallet?: (dappPage: ExampleProject, walletPage: ExampleProject) => Promise | void, +) { + await connectGenericDappToNewReactAccount(context, dappPage, 'page', walletPage, actionBeforeConnectWallet) +} diff --git a/e2e/src/models/ExampleProject.ts b/e2e/src/models/ExampleProject.ts index 02f7cea..14cc47c 100644 --- a/e2e/src/models/ExampleProject.ts +++ b/e2e/src/models/ExampleProject.ts @@ -15,7 +15,7 @@ export default class ExampleProject { get runCommand(): string { if (this.projectPathName.includes('react')) return `"cd ${EXAMPLES_PATH}/${this.projectPathName} && cross-env PORT=${this.projectPort} npx serve -s build"` - else if (this.projectPathName.includes('vite')) + else if (this.projectPathName.includes('vite') || this.projectPathName.includes('sveltekit')) return `"cd ${EXAMPLES_PATH}/${this.projectPathName} && pnpm vite preview --port ${this.projectPort}"` else throw Error('Unknown project framework') } diff --git a/e2e/src/pageCommonSteps/DappReactSteps.ts b/e2e/src/pageCommonSteps/DappReactSteps.ts index a24abf1..416f66b 100644 --- a/e2e/src/pageCommonSteps/DappReactSteps.ts +++ b/e2e/src/pageCommonSteps/DappReactSteps.ts @@ -1,8 +1,8 @@ import ExampleProject from '../models/ExampleProject' import { getCleanInnerHTML } from '../helpers/CleanerHelper' -export async function getReactDappUri(dappPage: ExampleProject): Promise { - await dappPage.awaitAndClickTestId('hello-world__get-uri-button') // Click the button to get the dapp URI - await dappPage.awaitAndClickTestId('hello-world__get-uri-button') // Click the button to get the dapp URI - return await getCleanInnerHTML(await dappPage.awaitAndGetTestId('hello-world__dapp-uri')) // Get and store the clean dapp URI +export async function getDappUri(dappPage: ExampleProject, componentTestId: string): Promise { + await dappPage.awaitAndClickTestId(`${componentTestId}__get-uri-button`) // Click the button to get the dapp URI + await dappPage.awaitAndClickTestId(`${componentTestId}__get-uri-button`) // Click the button to get the dapp URI + return await getCleanInnerHTML(await dappPage.awaitAndGetTestId(`${componentTestId}__dapp-uri`)) // Get and store the clean dapp URI } diff --git a/e2e/src/scripts/examplesInstall.ts b/e2e/src/scripts/examplesInstall.ts index 7eba4a5..6dc138a 100644 --- a/e2e/src/scripts/examplesInstall.ts +++ b/e2e/src/scripts/examplesInstall.ts @@ -1,3 +1,3 @@ import { runCommandInEachExampleProj } from '../helpers/CommandsHelper' -runCommandInEachExampleProj('pnpm i') +runCommandInEachExampleProj('pnpm i --force') diff --git a/e2e/tests/DappMethods.spec.ts b/e2e/tests/DappMethods.spec.ts index 3e41da8..be0f794 100644 --- a/e2e/tests/DappMethods.spec.ts +++ b/e2e/tests/DappMethods.spec.ts @@ -1,6 +1,6 @@ import { expect, test } from '@playwright/test' -import { DAPP_REACT, WALLET_REACT } from '../src/constants/ProjectsDefinitions' -import { connectReactDappToNewReactAccount } from '../src/helpers/CommonStepsHelper' +import { DAPP_REACT, WALLET_REACT, DAPP_VITE_SVELTEKIT } from '../src/constants/ProjectsDefinitions' +import { connectReactDappToNewReactAccount, connectSvelteDappToNewReactAccount } from '../src/helpers/CommonStepsHelper' import { getAnyFromInnerHTML, getCleanInnerHTML } from '../src/helpers/CleanerHelper' import { acceptPendingRequestToReactWallet } from '../src/pageCommonSteps/WalletReactSteps' import { DAPP_METHOD_CONTEXT_MESSAGE } from '../src/constants/GenericData' @@ -10,11 +10,49 @@ test('Create a new account and connect with a dapp (React)', async ({ context }) const dappPage = DAPP_REACT const walletPage = WALLET_REACT - await connectReactDappToNewReactAccount(context, dappPage, walletPage) - const dappCard = await walletPage.awaitAndGetTestId('default-card_sesseion-card') // Get the dapp card element + await connectReactDappToNewReactAccount( + context, + dappPage, + walletPage, + // eslint-disable-next-line @typescript-eslint/no-unused-vars + async (dappPageBeforeConnection, walletPageBeforeConnection) => { + const hasSession = await getAnyFromInnerHTML( + await dappPageBeforeConnection.awaitAndGetTestId('hello-world__has-session'), + ) + expect(hasSession).toBeFalsy() + }, + ) + const dappCard = await walletPage.awaitAndGetTestId('default-card_session-card') // Get the dapp card element + const hasSession = await getAnyFromInnerHTML(await dappPage.awaitAndGetTestId('hello-world__has-session')) // Check if the dapp card element is defined, indicating successful connection expect(dappCard).toBeDefined() + expect(hasSession).toBeTruthy() +}) + +test('Create a new account and connect with a dapp (Svelte)', async ({ context }) => { + // Define the dapp and wallet pages + const dappPage = DAPP_VITE_SVELTEKIT + const walletPage = WALLET_REACT + + await connectSvelteDappToNewReactAccount( + context, + dappPage, + walletPage, + // eslint-disable-next-line @typescript-eslint/no-unused-vars + async (dappPageBeforeConnection, walletPageBeforeConnection) => { + const hasSession = await getAnyFromInnerHTML( + await dappPageBeforeConnection.awaitAndGetTestId('page__has-session'), + ) + expect(hasSession).toBeFalsy() + }, + ) + const disconnectButton = await walletPage.awaitAndGetTestId('page__get-disconnect') // Get the dapp card element + + const hasSession = await getAnyFromInnerHTML(await dappPage.awaitAndGetTestId('page__has-session')) + // Check if the dapp card element is defined, indicating successful connection + expect(disconnectButton).toBeDefined() + expect(hasSession).toBeTruthy() }) test('Test Disconnect on dapp (React)', async ({ context }) => { diff --git a/examples/wc-dapp-react/src/components/HelloWorld.tsx b/examples/wc-dapp-react/src/components/HelloWorld.tsx index 93d479f..6425a1e 100644 --- a/examples/wc-dapp-react/src/components/HelloWorld.tsx +++ b/examples/wc-dapp-react/src/components/HelloWorld.tsx @@ -1,4 +1,4 @@ -import React, { useState } from 'react' +import React, { useEffect, useState } from 'react' import { TypeChecker } from '@cityofzion/neon-dappkit-types' import { NetworkType, useWalletConnect, SignMessageVersion } from '@cityofzion/wallet-connect-sdk-react' import { dappMethods, networks } from '../Constants' @@ -9,9 +9,19 @@ import Toastify from 'toastify-js' function HelloWorld() { const [dappUri, setDappUri] = useState('') const [response, setResponse] = useState('') + const [hasSession, setHasSession] = useState(false) const wcSdk = useWalletConnect() const [networkType, setNetworkType] = React.useState('neo3:testnet') + useEffect(() => { + wcSdk.emitter.on('session', (session) => { + setHasSession(!!session) + }) + return () => { + wcSdk.emitter.removeAllListeners() + } + }, [wcSdk.emitter]) + const connect = async (): Promise => { await wcSdk.connect(networkType, dappMethods) } @@ -467,6 +477,10 @@ function HelloWorld() { {!wcSdk && Loading...} {wcSdk && (
+
+ The SDK has a session? + {String(hasSession)} +
{!wcSdk.isConnected() && ( <> @@ -466,14 +483,14 @@ {/each} - + +
{:else} - + {/if}
- @@ -491,5 +508,9 @@
+
+ Response: +
+ {response} diff --git a/examples/wc-dapp-sveltekit/vite.config.ts b/examples/wc-dapp-sveltekit/vite.config.ts index dd1b8b7..6a1720f 100644 --- a/examples/wc-dapp-sveltekit/vite.config.ts +++ b/examples/wc-dapp-sveltekit/vite.config.ts @@ -2,5 +2,12 @@ import { sveltekit } from '@sveltejs/kit/vite' import { defineConfig } from 'vite' export default defineConfig({ + optimizeDeps: { + esbuildOptions: { + define: { + global: 'globalThis', + }, + }, + }, plugins: [sveltekit()], }) diff --git a/examples/wc-wallet-react/src/components/DefaultCard.tsx b/examples/wc-wallet-react/src/components/DefaultCard.tsx index 44645ed..68333e5 100644 --- a/examples/wc-wallet-react/src/components/DefaultCard.tsx +++ b/examples/wc-wallet-react/src/components/DefaultCard.tsx @@ -42,7 +42,7 @@ export default function DefaultCard( {walletConnectCtx.sessions.map((session) => ( > + /** + * The current WalletConnect event emitter + */ + emitter: TypedEventEmitter + /** * returns if the session is connected */ @@ -125,6 +133,7 @@ export const WalletConnectProvider: React.FC<{ }> = ({ children, options, autoManageSession = false }) => { const sdkRef = useRef() const [session, setSession] = useState() + const emitter = useRef(new EventEmitter() as TypedEventEmitter) const getSdkOrError = useCallback(() => { if (!sdkRef.current) throw Error('no client') @@ -277,6 +286,7 @@ export const WalletConnectProvider: React.FC<{ const wcSdk = await WcSdk.init(options) wcSdk.emitter.removeAllListeners() wcSdk.emitter.on('session', (session) => { + emitter.current.emit('session', session) setSession(session ?? undefined) }) @@ -293,6 +303,7 @@ export const WalletConnectProvider: React.FC<{ const contextValue: IWalletConnectContext = { sdk: sdkRef.current, + emitter: emitter.current, session, setSession, isConnected, diff --git a/packages/wallet-connect-sdk-svelte/package.json b/packages/wallet-connect-sdk-svelte/package.json index 45e133a..66bac28 100644 --- a/packages/wallet-connect-sdk-svelte/package.json +++ b/packages/wallet-connect-sdk-svelte/package.json @@ -36,18 +36,21 @@ "svelte": "*" }, "devDependencies": { - "svelte": "^4.0.5", - "tslib": "^2.4.1", "@rollup/plugin-commonjs": "~25.0.7", + "@typescript-eslint/eslint-plugin": "^6.8.0", + "@typescript-eslint/parser": "^6.8.0", + "eslint": "^8.51.0", + "events": "^3.3.0", "rollup": "~4.1.4", "rollup-plugin-auto-external": "~2.0.0", - "rollup-plugin-dts": "~6.1.0", "rollup-plugin-esbuild": "~6.1.0", - "typescript": "^4.3.2", + "rollup-plugin-polyfill-node": "^0.13.0", + "rollup-plugin-ts": "^3.4.5", + "svelte": "^4.0.5", + "tslib": "^2.4.1", + "typed-emitter": "^2.1.0", "typedoc": "^0.22.10", - "@typescript-eslint/eslint-plugin": "^6.8.0", - "@typescript-eslint/parser": "^6.8.0", - "eslint": "^8.51.0" + "typescript": "^4.3.2" }, "types": "./dist/index.d.ts", "type": "module", diff --git a/packages/wallet-connect-sdk-svelte/rollup.config.js b/packages/wallet-connect-sdk-svelte/rollup.config.js index 74fbc8b..5569c3c 100644 --- a/packages/wallet-connect-sdk-svelte/rollup.config.js +++ b/packages/wallet-connect-sdk-svelte/rollup.config.js @@ -2,8 +2,9 @@ import { readFileSync } from 'fs' import commonjs from '@rollup/plugin-commonjs' import autoExternal from 'rollup-plugin-auto-external' -import dts from 'rollup-plugin-dts' +import typescript from 'rollup-plugin-ts' import esbuild from 'rollup-plugin-esbuild' +import nodePolyfills from 'rollup-plugin-polyfill-node' const pkg = JSON.parse(readFileSync('./package.json')) @@ -19,11 +20,11 @@ export default [ input: 'src/index.ts', output: [{ file: pkg.main, format: 'es' }], external, - plugins: [commonjs(), autoExternal(), esbuild()], + plugins: [nodePolyfills(), commonjs(), autoExternal(), esbuild()], }, { input: 'src/index.ts', output: [{ file: pkg.types, format: 'es' }], - plugins: [dts()], + plugins: [nodePolyfills(), typescript()], }, ] diff --git a/packages/wallet-connect-sdk-svelte/src/WcSdkStore.ts b/packages/wallet-connect-sdk-svelte/src/WcSdkStore.ts index 52bafdb..206897b 100644 --- a/packages/wallet-connect-sdk-svelte/src/WcSdkStore.ts +++ b/packages/wallet-connect-sdk-svelte/src/WcSdkStore.ts @@ -1,6 +1,6 @@ import { writable, type Writable, type Readable, derived } from 'svelte/store' import SignClient from '@walletconnect/sign-client' -import { WcSdk } from '@cityofzion/wallet-connect-sdk-core' +import { CoreEvents, WcSdk } from '@cityofzion/wallet-connect-sdk-core' import type { NetworkType, Method, @@ -19,6 +19,8 @@ import type { WalletInfo, } from '@cityofzion/wallet-connect-sdk-core' import type { SessionTypes, SignClientTypes } from '@walletconnect/types' +import TypedEventEmitter from 'typed-emitter' +import { EventEmitter } from 'events' export interface IWalletConnectStore extends Neo3Invoker, Neo3Signer { /** @@ -32,6 +34,11 @@ export interface IWalletConnectStore extends Neo3Invoker, Neo3Signer { session: Readable setSession(session: SessionTypes.Struct): void + /** + * The current WalletConnect event emitter + */ + emitter: TypedEventEmitter + /** * returns if the session is connected */ @@ -122,10 +129,11 @@ export class WCSDKStore implements IWalletConnectStore { private sessionWritable: Writable = writable(null) private signClientWritable: Writable = writable(null) private autoManageSession: boolean + emitter = new EventEmitter() as TypedEventEmitter constructor(options: SignClientTypes.Options, autoManageSession?: boolean) { - this.setupWcClient(options) this.sdk = null + this.setupWcClient(options) this.autoManageSession = autoManageSession ?? true } @@ -139,7 +147,7 @@ export class WCSDKStore implements IWalletConnectStore { return this.sdk?.getChainId() ?? null } manageDisconnect(): void { - this.onSignClient((signClient) => { + this.signClientWritable.subscribe((signClient) => { if (signClient) { //@ts-ignore signClient.events.removeAllListeners() @@ -230,17 +238,16 @@ export class WCSDKStore implements IWalletConnectStore { return derived(this.signClientWritable, (signClient) => signClient) } - onSession(callback: (session: SessionTypes.Struct | null) => T) { - return this.sessionWritable.subscribe((session) => callback(session)) - } - - onSignClient(callback: (signClient: SignClient | null) => T) { - return this.signClientWritable.subscribe((signClient) => callback(signClient)) - } - private async setupWcClient(options: SignClientTypes.Options) { this.sdk = await WcSdk.init(options) + this.sdk.emitter.removeAllListeners() + this.sdk.emitter.on('session', (session) => { + this.emitter.emit('session', session) + this.sessionWritable.set(session ?? null) + }) + const signClient = this.sdk.signClient + if (this.autoManageSession) { this.manageSession() } diff --git a/packages/wallet-connect-sdk-wallet-react/package.json b/packages/wallet-connect-sdk-wallet-react/package.json index 687f4e0..3673619 100644 --- a/packages/wallet-connect-sdk-wallet-react/package.json +++ b/packages/wallet-connect-sdk-wallet-react/package.json @@ -44,6 +44,7 @@ "@types/react": "^16.9.27", "@types/react-dom": "^16.9.7", "cross-env": "^7.0.2", + "events": "^3.3.0", "microbundle-crl": "^0.13.10", "npm-run-all": "^4.1.5", "react": "^16.13.1", @@ -53,6 +54,7 @@ "@typescript-eslint/eslint-plugin": "^6.8.0", "@typescript-eslint/parser": "^6.8.0", "eslint": "^8.51.0", + "typed-emitter": "^2.1.0", "typescript": "^4.3.2", "typedoc": "^0.22.10" }, diff --git a/packages/wallet-connect-sdk-wallet-react/src/context.tsx b/packages/wallet-connect-sdk-wallet-react/src/context.tsx index 1b304ae..90506ed 100644 --- a/packages/wallet-connect-sdk-wallet-react/src/context.tsx +++ b/packages/wallet-connect-sdk-wallet-react/src/context.tsx @@ -9,7 +9,10 @@ import { TSession, TSessionProposal, TSessionRequest, + TWalletCoreEvents, } from '@cityofzion/wallet-connect-sdk-wallet-core' +import TypedEventEmitter from 'typed-emitter' +import EventEmitter from 'events' export const WalletConnectWalletContext = React.createContext({} as IWalletConnectWalletContext) @@ -23,6 +26,7 @@ export const WalletConnectWalletContext = React.createContext({} as IWalletConne */ export const WalletConnectWalletProvider = ({ children, options }: TWalletConnectWalletProps) => { const sdk = useRef(new WcWalletSDK(options)) + const emitter = useRef(new EventEmitter() as TypedEventEmitter) const [sessions, setSessions] = useState([]) const [proposals, setProposals] = useState([]) @@ -67,18 +71,22 @@ export const WalletConnectWalletProvider = ({ children, options }: TWalletConnec useEffect(() => { sdk.current.emitter.on('proposals', (items: TSessionProposal[]) => { + emitter.current.emit('proposals', items) setProposals(items) }) sdk.current.emitter.on('sessions', (items: TSession[]) => { + emitter.current.emit('sessions', items) setSessions(items) }) sdk.current.emitter.on('requests', (items: TSessionRequest[]) => { + emitter.current.emit('requests', items) setRequests(items) }) sdk.current.emitter.on('status', (item: EStatus) => { + emitter.current.emit('status', item) setStatus(item) }) @@ -93,6 +101,7 @@ export const WalletConnectWalletProvider = ({ children, options }: TWalletConnec + /** * The list of WalletConnect connected sessions */