From 644fe991b9a679f80ad441e9df59cb5daa9c9243 Mon Sep 17 00:00:00 2001 From: Arthur Geron <3487334+arthurgeron@users.noreply.github.com> Date: Thu, 18 Jul 2024 19:41:56 -0300 Subject: [PATCH 01/26] feat: get evm address from a wallet connect connector instance --- .changeset/eight-bears-prove.md | 6 ++++++ .changeset/fuel-labs-ci.md | 5 +++++ .../src/WalletConnectConnector.ts | 9 +++++++++ 3 files changed, 20 insertions(+) create mode 100644 .changeset/eight-bears-prove.md create mode 100644 .changeset/fuel-labs-ci.md diff --git a/.changeset/eight-bears-prove.md b/.changeset/eight-bears-prove.md new file mode 100644 index 00000000..e07b178a --- /dev/null +++ b/.changeset/eight-bears-prove.md @@ -0,0 +1,6 @@ +--- +"@fuel-connectors/walletconnect-connector": patch +--- + +Wallet Connect Connector will inherently return a predicate address, instead of the actual account, due to the bridge it does between networks. +Added a method to get the actual account address that has originated the predicate, so we can validate if a predicate original from a specific evm address diff --git a/.changeset/fuel-labs-ci.md b/.changeset/fuel-labs-ci.md new file mode 100644 index 00000000..fb7f0c95 --- /dev/null +++ b/.changeset/fuel-labs-ci.md @@ -0,0 +1,5 @@ +--- +"@fuels/connectors": patch +--- + +incremental diff --git a/packages/walletconnect-connector/src/WalletConnectConnector.ts b/packages/walletconnect-connector/src/WalletConnectConnector.ts index c001cea6..9132e456 100644 --- a/packages/walletconnect-connector/src/WalletConnectConnector.ts +++ b/packages/walletconnect-connector/src/WalletConnectConnector.ts @@ -88,6 +88,15 @@ export class WalletConnectConnector extends FuelConnector { }); } + async currentEvmAccount(): Promise { + if (!(await this.isConnected())) { + throw Error('No connected accounts'); + } + const ethAccount = getAccount(this.wagmiConfig).address || null; + + return ethAccount; + } + async setupPredicate(): Promise { if (this.customPredicate?.abi && this.customPredicate?.bytecode) { this.predicateAccount = new PredicateAccount(this.customPredicate); From e7a27c7b6315fc6a7f60524b86a91dd5c5d2d774 Mon Sep 17 00:00:00 2001 From: Arthur Geron <3487334+arthurgeron@users.noreply.github.com> Date: Thu, 18 Jul 2024 20:00:29 -0300 Subject: [PATCH 02/26] chore: improve clarity in changeset --- .changeset/eight-bears-prove.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.changeset/eight-bears-prove.md b/.changeset/eight-bears-prove.md index e07b178a..57a5b2f4 100644 --- a/.changeset/eight-bears-prove.md +++ b/.changeset/eight-bears-prove.md @@ -3,4 +3,5 @@ --- Wallet Connect Connector will inherently return a predicate address, instead of the actual account, due to the bridge it does between networks. -Added a method to get the actual account address that has originated the predicate, so we can validate if a predicate original from a specific evm address +Added a method to retrieve the actual account address that originated the predicate, allowing validation of whether a predicate originated from a specific EVM address. + From b26d25c476ef54fb7309b3859f9f4619135f553f Mon Sep 17 00:00:00 2001 From: Arthur Geron <3487334+arthurgeron@users.noreply.github.com> Date: Fri, 19 Jul 2024 11:14:16 -0300 Subject: [PATCH 03/26] chore: update changeset patch instruction Co-authored-by: Luiz Gomes <8636507+LuizAsFight@users.noreply.github.com> --- .changeset/fuel-labs-ci.md | 1 - 1 file changed, 1 deletion(-) diff --git a/.changeset/fuel-labs-ci.md b/.changeset/fuel-labs-ci.md index fb7f0c95..9bcc7df4 100644 --- a/.changeset/fuel-labs-ci.md +++ b/.changeset/fuel-labs-ci.md @@ -2,4 +2,3 @@ "@fuels/connectors": patch --- -incremental From 50e689df00a133e8e7cfbffcc0431027fc795081 Mon Sep 17 00:00:00 2001 From: Arthur Geron <3487334+arthurgeron@users.noreply.github.com> Date: Fri, 19 Jul 2024 11:14:28 -0300 Subject: [PATCH 04/26] chore: update wording in changeset Co-authored-by: Luiz Gomes <8636507+LuizAsFight@users.noreply.github.com> --- .changeset/eight-bears-prove.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.changeset/eight-bears-prove.md b/.changeset/eight-bears-prove.md index 57a5b2f4..81bf8932 100644 --- a/.changeset/eight-bears-prove.md +++ b/.changeset/eight-bears-prove.md @@ -2,6 +2,5 @@ "@fuel-connectors/walletconnect-connector": patch --- -Wallet Connect Connector will inherently return a predicate address, instead of the actual account, due to the bridge it does between networks. -Added a method to retrieve the actual account address that originated the predicate, allowing validation of whether a predicate originated from a specific EVM address. +Add `currentEvmAccount` method to `WalletConnectConnector`, which will return the current ethereum account connected. From bc0a18d3f330293ff38639dd2216f8c697ea2685 Mon Sep 17 00:00:00 2001 From: Arthur Geron <3487334+arthurgeron@users.noreply.github.com> Date: Fri, 19 Jul 2024 14:20:04 -0300 Subject: [PATCH 05/26] chore: release pr tag --- .github/workflows/pr-release.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-release.yaml b/.github/workflows/pr-release.yaml index a32546bb..956b94db 100644 --- a/.github/workflows/pr-release.yaml +++ b/.github/workflows/pr-release.yaml @@ -8,7 +8,7 @@ jobs: name: 'Release PR to npm' runs-on: buildjet-4vcpu-ubuntu-2204 # comment out if:false to enable release PR to npm - if: false + # if: false permissions: write-all steps: - uses: actions/checkout@v3 From 09745dbc238791525235b10055fcbb29aa777b34 Mon Sep 17 00:00:00 2001 From: Arthur Geron <3487334+arthurgeron@users.noreply.github.com> Date: Fri, 19 Jul 2024 16:35:20 -0300 Subject: [PATCH 06/26] feat: update wagmi and wagmi connectors --- examples/react-app/package.json | 4 +- examples/react-next/package.json | 4 +- packages/connectors/package.json | 2 +- packages/walletconnect-connector/package.json | 2 +- pnpm-lock.yaml | 369 ++++++------------ 5 files changed, 119 insertions(+), 262 deletions(-) diff --git a/examples/react-app/package.json b/examples/react-app/package.json index 643fd996..95aa04da 100644 --- a/examples/react-app/package.json +++ b/examples/react-app/package.json @@ -14,8 +14,8 @@ "@fuels/react": "0.20.0", "@radix-ui/react-toast": "1.1.5", "@tanstack/react-query": "5.35.1", - "@wagmi/connectors": "4.3.3", - "@wagmi/core": "2.9.1", + "@wagmi/connectors": "5.0.26", + "@wagmi/core": "2.12.2", "clsx": "2.1.1", "fuels": "0.92.0", "react": "18.3.1", diff --git a/examples/react-next/package.json b/examples/react-next/package.json index d4bd1dcd..4fa76858 100644 --- a/examples/react-next/package.json +++ b/examples/react-next/package.json @@ -11,12 +11,12 @@ "@fuels/connectors": "workspace:*", "@fuels/react": "0.20.0", "@tanstack/react-query": "5.35.1", - "@wagmi/connectors": "4.3.3", + "@wagmi/connectors": "5.0.26", "fuels": "0.92.0", "next": "14.2.3", "react": "18.3.1", "react-dom": "18.3.1", - "wagmi": "2.8.1" + "wagmi": "2.11.3" }, "devDependencies": { "@tanstack/react-query-devtools": "5.35.1", diff --git a/packages/connectors/package.json b/packages/connectors/package.json index d23a6d44..8342168c 100644 --- a/packages/connectors/package.json +++ b/packages/connectors/package.json @@ -23,7 +23,7 @@ "dependencies": { "@ethereumjs/util": "9.0.3", "@ethersproject/bytes": "5.7.0", - "@wagmi/core": "2.9.1", + "@wagmi/core": "2.12.2", "@web3modal/wagmi": "5.0.0", "viem": "2.10.2", "socket.io-client": "4.7.2", diff --git a/packages/walletconnect-connector/package.json b/packages/walletconnect-connector/package.json index 8a0c161f..7eb6beaf 100644 --- a/packages/walletconnect-connector/package.json +++ b/packages/walletconnect-connector/package.json @@ -29,7 +29,7 @@ "dependencies": { "@ethereumjs/util": "9.0.3", "@ethersproject/bytes": "5.7.0", - "@wagmi/core": "2.9.1", + "@wagmi/core": "2.12.2", "@web3modal/wagmi": "5.0.0", "memoizee": "0.4.15", "viem": "2.10.2" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 86eb33b1..7b8d711f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -66,11 +66,11 @@ importers: specifier: 5.35.1 version: 5.35.1(react@18.3.1) '@wagmi/connectors': - specifier: 4.3.3 - version: 4.3.3(@types/react@18.3.1)(@wagmi/core@2.9.1)(react-dom@18.3.1)(react-i18next@13.5.0)(react-native@0.74.1)(react@18.3.1)(typescript@5.4.5)(viem@2.10.2) + specifier: 5.0.26 + version: 5.0.26(@types/react@18.3.1)(@wagmi/core@2.12.2)(react-dom@18.3.1)(react-native@0.74.1)(react@18.3.1)(typescript@5.4.5)(viem@2.10.2) '@wagmi/core': - specifier: 2.9.1 - version: 2.9.1(@types/react@18.3.1)(react@18.3.1)(typescript@5.4.5)(viem@2.10.2) + specifier: 2.12.2 + version: 2.12.2(@types/react@18.3.1)(react@18.3.1)(typescript@5.4.5)(viem@2.10.2) clsx: specifier: 2.1.1 version: 2.1.1 @@ -124,8 +124,8 @@ importers: specifier: 5.35.1 version: 5.35.1(react@18.3.1) '@wagmi/connectors': - specifier: 4.3.3 - version: 4.3.3(@types/react@18.3.1)(@wagmi/core@2.9.1)(react-dom@18.3.1)(react-i18next@13.5.0)(react-native@0.74.1)(react@18.3.1)(typescript@5.4.5)(viem@2.10.2) + specifier: 5.0.26 + version: 5.0.26(@types/react@18.3.1)(@wagmi/core@2.12.2)(react-dom@18.3.1)(react-native@0.74.1)(react@18.3.1)(typescript@5.4.5)(viem@2.10.2) fuels: specifier: 0.92.0 version: 0.92.0 @@ -139,8 +139,8 @@ importers: specifier: 18.3.1 version: 18.3.1(react@18.3.1) wagmi: - specifier: 2.8.1 - version: 2.8.1(@tanstack/react-query@5.35.1)(@types/react@18.3.1)(react-dom@18.3.1)(react-i18next@13.5.0)(react-native@0.74.1)(react@18.3.1)(typescript@5.4.5)(viem@2.10.2) + specifier: 2.11.3 + version: 2.11.3(@tanstack/react-query@5.35.1)(@types/react@18.3.1)(react-dom@18.3.1)(react-native@0.74.1)(react@18.3.1)(typescript@5.4.5)(viem@2.10.2) devDependencies: '@tanstack/react-query-devtools': specifier: 5.35.1 @@ -216,8 +216,8 @@ importers: specifier: 1.93.1 version: 1.93.1 '@wagmi/core': - specifier: 2.9.1 - version: 2.9.1(@types/react@18.3.1)(react@18.3.1)(typescript@5.4.5)(viem@2.10.2) + specifier: 2.12.2 + version: 2.12.2(@types/react@18.3.1)(react@18.3.1)(typescript@5.4.5)(viem@2.10.2) '@web3modal/core': specifier: 5.0.0 version: 5.0.0(react@18.3.1) @@ -229,7 +229,7 @@ importers: version: 5.0.0(react@18.3.1) '@web3modal/wagmi': specifier: 5.0.0 - version: 5.0.0(@wagmi/connectors@4.3.3)(@wagmi/core@2.9.1)(react@18.3.1)(viem@2.10.2) + version: 5.0.0(@wagmi/connectors@5.0.26)(@wagmi/core@2.12.2)(react@18.3.1)(viem@2.10.2) rpc-websockets: specifier: 7.11.0 version: 7.11.0 @@ -469,14 +469,14 @@ importers: specifier: 5.7.0 version: 5.7.0 '@wagmi/core': - specifier: 2.9.1 - version: 2.9.1(@types/react@18.3.1)(react@18.3.1)(typescript@5.4.5)(viem@2.10.2) + specifier: 2.12.2 + version: 2.12.2(@types/react@18.3.1)(react@18.3.1)(typescript@5.4.5)(viem@2.10.2) '@web3modal/scaffold': specifier: '>=5.0.0' version: 5.0.0(react@18.3.1) '@web3modal/wagmi': specifier: 5.0.0 - version: 5.0.0(@wagmi/connectors@4.3.3)(@wagmi/core@2.9.1)(react@18.3.1)(viem@2.10.2) + version: 5.0.0(@wagmi/connectors@5.0.26)(@wagmi/core@2.12.2)(react@18.3.1)(viem@2.10.2) memoizee: specifier: 0.4.15 version: 0.4.15 @@ -2403,8 +2403,8 @@ packages: prettier: 2.8.8 dev: true - /@coinbase/wallet-sdk@3.9.1: - resolution: {integrity: sha512-cGUE8wm1/cMI8irRMVOqbFWYcnNugqCtuy2lnnHfgloBg+GRLs9RsrkOUDMdv/StfUeeKhCDyYudsXXvcL1xIA==} + /@coinbase/wallet-sdk@3.9.3: + resolution: {integrity: sha512-N/A2DRIf0Y3PHc1XAMvbBUu4zisna6qAdqABMZwBMNEfWrXpAwx16pZGkYCLGE+Rvv1edbcB2LYDRnACNcmCiw==} dependencies: bn.js: 5.2.1 buffer: 6.0.3 @@ -2419,6 +2419,17 @@ packages: - supports-color dev: false + /@coinbase/wallet-sdk@4.0.4: + resolution: {integrity: sha512-74c040CRnGhfRjr3ArnkAgud86erIqdkPHNt5HR1k9u97uTIZCJww9eGYT67Qf7gHPpGS/xW8Be1D4dvRm63FA==} + dependencies: + buffer: 6.0.3 + clsx: 1.2.1 + eventemitter3: 5.0.1 + keccak: 3.0.4 + preact: 10.22.0 + sha.js: 2.4.11 + dev: false + /@cspotcode/source-map-support@0.8.1: resolution: {integrity: sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==} engines: {node: '>=12'} @@ -3958,11 +3969,22 @@ packages: - supports-color dev: false - /@metamask/json-rpc-middleware-stream@6.0.2: - resolution: {integrity: sha512-jtyx3PRfc1kqoLpYveIVQNwsxYKefc64/LCl9h9Da1m3nUKEvypbYuXSIwi237qvOjKmNHQKsDOZg6f4uBf62Q==} + /@metamask/json-rpc-engine@8.0.2: + resolution: {integrity: sha512-IoQPmql8q7ABLruW7i4EYVHWUbF74yrp63bRuXV5Zf9BQwcn5H9Ww1eLtROYvI1bUXwOiHZ6qT5CWTrDc/t/AA==} engines: {node: '>=16.0.0'} dependencies: - '@metamask/json-rpc-engine': 7.3.3 + '@metamask/rpc-errors': 6.2.1 + '@metamask/safe-event-emitter': 3.1.1 + '@metamask/utils': 8.4.0 + transitivePeerDependencies: + - supports-color + dev: false + + /@metamask/json-rpc-middleware-stream@7.0.2: + resolution: {integrity: sha512-yUdzsJK04Ev98Ck4D7lmRNQ8FPioXYhEUZOMS01LXW8qTvPGiRVXmVltj2p4wrLkh0vW7u6nv0mNl5xzC5Qmfg==} + engines: {node: '>=16.0.0'} + dependencies: + '@metamask/json-rpc-engine': 8.0.2 '@metamask/safe-event-emitter': 3.1.1 '@metamask/utils': 8.4.0 readable-stream: 3.6.2 @@ -3984,12 +4006,12 @@ packages: bowser: 2.11.0 dev: false - /@metamask/providers@15.0.0: - resolution: {integrity: sha512-FXvL1NQNl6I7fMOJTfQYcBlBZ33vSlm6w80cMpmn8sJh0Lb7wcBpe02UwBsNlARnI+Qsr26XeDs6WHUHQh8CuA==} + /@metamask/providers@16.1.0: + resolution: {integrity: sha512-znVCvux30+3SaUwcUGaSf+pUckzT5ukPRpcBmy+muBLC0yaWnBcvDqGfcsw6CBIenUdFrVoAFa8B6jsuCY/a+g==} engines: {node: ^18.18 || >=20} dependencies: - '@metamask/json-rpc-engine': 7.3.3 - '@metamask/json-rpc-middleware-stream': 6.0.2 + '@metamask/json-rpc-engine': 8.0.2 + '@metamask/json-rpc-middleware-stream': 7.0.2 '@metamask/object-multiplex': 2.0.0 '@metamask/rpc-errors': 6.2.1 '@metamask/safe-event-emitter': 3.1.1 @@ -4023,10 +4045,10 @@ packages: engines: {node: '>=12.0.0'} dev: false - /@metamask/sdk-communication-layer@0.18.5(cross-fetch@4.0.0)(eciesjs@0.3.18)(eventemitter2@6.4.9)(readable-stream@3.6.2)(socket.io-client@4.7.2): - resolution: {integrity: sha512-WMf9oJa3rAimjCXMAaaRVFPD0Q6dfZR0r9037KCpD5g9SlVh+TeMISfdQCEKAyhXP3d4CGxmp/Kib8C3mn2YLw==} + /@metamask/sdk-communication-layer@0.26.4(cross-fetch@4.0.0)(eciesjs@0.3.18)(eventemitter2@6.4.9)(readable-stream@3.6.2)(socket.io-client@4.7.2): + resolution: {integrity: sha512-+X4GEc5mV1gWK4moSswVlKsUh+RsA48qPlkxBLTUxQODSnyBe0TRMxE6mH+bSrfponnTzvBkGUXyEjvDwDjDHw==} peerDependencies: - cross-fetch: ^3.1.5 + cross-fetch: ^4.0.0 eciesjs: ^0.3.16 eventemitter2: ^6.4.7 readable-stream: ^3.6.2 @@ -4040,19 +4062,18 @@ packages: eventemitter2: 6.4.9 readable-stream: 3.6.2 socket.io-client: 4.7.2 - utf-8-validate: 6.0.4 + utf-8-validate: 5.0.10 uuid: 8.3.2 transitivePeerDependencies: - supports-color dev: false - /@metamask/sdk-install-modal-web@0.18.5(i18next@22.5.1)(react-dom@18.3.1)(react-i18next@13.5.0)(react-native@0.74.1)(react@18.3.1): - resolution: {integrity: sha512-Wygc0dgr1PwIA/Sg9WW9QWAsQr4G2GV6iveXt2xw8VKW/9cRORWqYukH1NZLr71hBKzi9AKYBU54Tk5Dfg41zg==} + /@metamask/sdk-install-modal-web@0.26.5(i18next@23.11.5)(react-dom@18.3.1)(react-native@0.74.1)(react@18.3.1): + resolution: {integrity: sha512-qVA9Nk+NorGx5hXyODy5wskptE8R7RNYTYt49VbQpJogqbbVe1dnJ98+KaA43PBN4XYMCXmcIhULNiEHGsLynA==} peerDependencies: - i18next: 22.5.1 + i18next: 23.11.5 react: ^18.2.0 react-dom: ^18.2.0 - react-i18next: ^13.2.2 react-native: '*' peerDependenciesMeta: react: @@ -4062,21 +4083,19 @@ packages: react-native: optional: true dependencies: - i18next: 22.5.1 + i18next: 23.11.5 qr-code-styling: 1.6.0-rc.1 react: 18.3.1 react-dom: 18.3.1(react@18.3.1) - react-i18next: 13.5.0(i18next@22.5.1)(react-dom@18.3.1)(react-native@0.74.1)(react@18.3.1) react-native: 0.74.1(@babel/core@7.24.0)(@babel/preset-env@7.24.6)(@types/react@18.3.1)(react@18.3.1) dev: false - /@metamask/sdk-install-modal-web@0.18.5(i18next@22.5.1)(react-i18next@13.5.0)(react-native@0.74.1)(react@18.3.1): - resolution: {integrity: sha512-Wygc0dgr1PwIA/Sg9WW9QWAsQr4G2GV6iveXt2xw8VKW/9cRORWqYukH1NZLr71hBKzi9AKYBU54Tk5Dfg41zg==} + /@metamask/sdk-install-modal-web@0.26.5(i18next@23.11.5)(react-native@0.74.1)(react@18.3.1): + resolution: {integrity: sha512-qVA9Nk+NorGx5hXyODy5wskptE8R7RNYTYt49VbQpJogqbbVe1dnJ98+KaA43PBN4XYMCXmcIhULNiEHGsLynA==} peerDependencies: - i18next: 22.5.1 + i18next: 23.11.5 react: ^18.2.0 react-dom: ^18.2.0 - react-i18next: ^13.2.2 react-native: '*' peerDependenciesMeta: react: @@ -4086,34 +4105,27 @@ packages: react-native: optional: true dependencies: - i18next: 22.5.1 + i18next: 23.11.5 qr-code-styling: 1.6.0-rc.1 react: 18.3.1 - react-i18next: 13.5.0(i18next@23.11.5)(react-native@0.74.1)(react@18.3.1) react-native: 0.74.1(@babel/core@7.24.0)(@babel/preset-env@7.24.6)(react@18.3.1) dev: false - /@metamask/sdk@0.18.6(react-dom@18.3.1)(react-i18next@13.5.0)(react-native@0.74.1)(react@18.3.1): - resolution: {integrity: sha512-ZT8e4BrcWrm44apLb412WR0fDsgeaS8UlI1c0wKRUPu1w/UntpXuUVO+EaY8WDlnOPAiAsjyqWKey64/DfvbXQ==} + /@metamask/sdk@0.26.5(react-dom@18.3.1)(react-native@0.74.1)(react@18.3.1): + resolution: {integrity: sha512-HS/MPQCCYRS+m3dDdGLcAagwYHiPv9iUshDMBjINUywCtfUN4P2BH8xdvPOgtnzRIuRSMXqMWBbZnTvEvBeQvA==} peerDependencies: - '@react-native-async-storage/async-storage': ^1.19.6 react: ^18.2.0 react-dom: ^18.2.0 - react-native: '*' peerDependenciesMeta: - '@react-native-async-storage/async-storage': - optional: true react: optional: true react-dom: optional: true - react-native: - optional: true dependencies: '@metamask/onboarding': 1.0.1 - '@metamask/providers': 15.0.0 - '@metamask/sdk-communication-layer': 0.18.5(cross-fetch@4.0.0)(eciesjs@0.3.18)(eventemitter2@6.4.9)(readable-stream@3.6.2)(socket.io-client@4.7.2) - '@metamask/sdk-install-modal-web': 0.18.5(i18next@22.5.1)(react-dom@18.3.1)(react-i18next@13.5.0)(react-native@0.74.1)(react@18.3.1) + '@metamask/providers': 16.1.0 + '@metamask/sdk-communication-layer': 0.26.4(cross-fetch@4.0.0)(eciesjs@0.3.18)(eventemitter2@6.4.9)(readable-stream@3.6.2)(socket.io-client@4.7.2) + '@metamask/sdk-install-modal-web': 0.26.5(i18next@23.11.5)(react-dom@18.3.1)(react-native@0.74.1)(react@18.3.1) '@types/dom-screen-wake-lock': 1.0.3 bowser: 2.11.0 cross-fetch: 4.0.0 @@ -4121,14 +4133,13 @@ packages: eciesjs: 0.3.18 eth-rpc-errors: 4.0.3 eventemitter2: 6.4.9 - i18next: 22.5.1 + i18next: 23.11.5 i18next-browser-languagedetector: 7.1.0 obj-multiplex: 1.0.0 pump: 3.0.0 qrcode-terminal-nooctal: 0.12.1 react: 18.3.1 react-dom: 18.3.1(react@18.3.1) - react-native: 0.74.1(@babel/core@7.24.0)(@babel/preset-env@7.24.6)(@types/react@18.3.1)(react@18.3.1) react-native-webview: 11.26.1(react-native@0.74.1)(react@18.3.1) readable-stream: 3.6.2 rollup-plugin-visualizer: 5.12.0 @@ -4138,33 +4149,27 @@ packages: transitivePeerDependencies: - bufferutil - encoding - - react-i18next + - react-native - rollup - supports-color - utf-8-validate dev: false - /@metamask/sdk@0.18.6(react-i18next@13.5.0)(react-native@0.74.1)(react@18.3.1): - resolution: {integrity: sha512-ZT8e4BrcWrm44apLb412WR0fDsgeaS8UlI1c0wKRUPu1w/UntpXuUVO+EaY8WDlnOPAiAsjyqWKey64/DfvbXQ==} + /@metamask/sdk@0.26.5(react-native@0.74.1)(react@18.3.1): + resolution: {integrity: sha512-HS/MPQCCYRS+m3dDdGLcAagwYHiPv9iUshDMBjINUywCtfUN4P2BH8xdvPOgtnzRIuRSMXqMWBbZnTvEvBeQvA==} peerDependencies: - '@react-native-async-storage/async-storage': ^1.19.6 react: ^18.2.0 react-dom: ^18.2.0 - react-native: '*' peerDependenciesMeta: - '@react-native-async-storage/async-storage': - optional: true react: optional: true react-dom: optional: true - react-native: - optional: true dependencies: '@metamask/onboarding': 1.0.1 - '@metamask/providers': 15.0.0 - '@metamask/sdk-communication-layer': 0.18.5(cross-fetch@4.0.0)(eciesjs@0.3.18)(eventemitter2@6.4.9)(readable-stream@3.6.2)(socket.io-client@4.7.2) - '@metamask/sdk-install-modal-web': 0.18.5(i18next@22.5.1)(react-i18next@13.5.0)(react-native@0.74.1)(react@18.3.1) + '@metamask/providers': 16.1.0 + '@metamask/sdk-communication-layer': 0.26.4(cross-fetch@4.0.0)(eciesjs@0.3.18)(eventemitter2@6.4.9)(readable-stream@3.6.2)(socket.io-client@4.7.2) + '@metamask/sdk-install-modal-web': 0.26.5(i18next@23.11.5)(react-native@0.74.1)(react@18.3.1) '@types/dom-screen-wake-lock': 1.0.3 bowser: 2.11.0 cross-fetch: 4.0.0 @@ -4172,13 +4177,12 @@ packages: eciesjs: 0.3.18 eth-rpc-errors: 4.0.3 eventemitter2: 6.4.9 - i18next: 22.5.1 + i18next: 23.11.5 i18next-browser-languagedetector: 7.1.0 obj-multiplex: 1.0.0 pump: 3.0.0 qrcode-terminal-nooctal: 0.12.1 react: 18.3.1 - react-native: 0.74.1(@babel/core@7.24.0)(@babel/preset-env@7.24.6)(react@18.3.1) react-native-webview: 11.26.1(react-native@0.74.1)(react@18.3.1) readable-stream: 3.6.2 rollup-plugin-visualizer: 5.12.0 @@ -4188,7 +4192,7 @@ packages: transitivePeerDependencies: - bufferutil - encoding - - react-i18next + - react-native - rollup - supports-color - utf-8-validate @@ -5535,10 +5539,10 @@ packages: - '@types/node' dev: true - /@safe-global/safe-apps-provider@0.18.1(typescript@5.4.5): - resolution: {integrity: sha512-V4a05A3EgJcriqtDoJklDz1BOinWhC6P0hjUSxshA4KOZM7rGPCTto/usXs09zr1vvL28evl/NldSTv97j2bmg==} + /@safe-global/safe-apps-provider@0.18.3(typescript@5.4.5): + resolution: {integrity: sha512-f/0cNv3S4v7p8rowAjj0hDCg8Q8P/wBjp5twkNWeBdvd0RDr7BuRBPPk74LCqmjQ82P+1ltLlkmVFSmxTIT7XQ==} dependencies: - '@safe-global/safe-apps-sdk': 8.1.0(typescript@5.4.5) + '@safe-global/safe-apps-sdk': 9.1.0(typescript@5.4.5) events: 3.3.0 transitivePeerDependencies: - bufferutil @@ -5547,11 +5551,11 @@ packages: - zod dev: false - /@safe-global/safe-apps-sdk@8.1.0(typescript@5.4.5): - resolution: {integrity: sha512-XJbEPuaVc7b9n23MqlF6c+ToYIS3f7P2Sel8f3cSBQ9WORE4xrSuvhMpK9fDSFqJ7by/brc+rmJR/5HViRr0/w==} + /@safe-global/safe-apps-sdk@9.1.0(typescript@5.4.5): + resolution: {integrity: sha512-N5p/ulfnnA2Pi2M3YeWjULeWbjo7ei22JwU/IXnhoHzKq3pYCN6ynL9mJBOlvDVv892EgLPCWCOwQk/uBT2v0Q==} dependencies: '@safe-global/safe-gateway-typescript-sdk': 3.21.1 - viem: 1.21.4(typescript@5.4.5) + viem: 2.10.2(typescript@5.4.5) transitivePeerDependencies: - bufferutil - typescript @@ -6315,23 +6319,24 @@ packages: resolution: {integrity: sha512-PuJe7vDIi6VYSinuEbUIQgMIRZGgM8e4R+G+/dQTk0X1NEdvgvvgv7m+rfmDH1gZzyA1OjjoWskvHlfRNfQf3g==} dev: true - /@wagmi/connectors@4.3.3(@types/react@18.3.1)(@wagmi/core@2.9.1)(react-dom@18.3.1)(react-i18next@13.5.0)(react-native@0.74.1)(react@18.3.1)(typescript@5.4.5)(viem@2.10.2): - resolution: {integrity: sha512-6u/HbWlIS2MI5lxBYbsqNZIQT4sBleFt8rhzH7mJBrHH6v95LmeZZ3qZFpWdopx4bQ6maNEZOIJnCLhv7k37DQ==} + /@wagmi/connectors@5.0.26(@types/react@18.3.1)(@wagmi/core@2.12.2)(react-dom@18.3.1)(react-native@0.74.1)(react@18.3.1)(typescript@5.4.5)(viem@2.10.2): + resolution: {integrity: sha512-aGc3oDQPQwVqJr7S/7IU7rF0bA61OYXGPLzj30Y3MSmmEWXtAEgKpqkhIwiEdYQAMnlR3ukbqROq8qmUm/iYQg==} peerDependencies: - '@wagmi/core': 2.9.1 + '@wagmi/core': 2.12.2 typescript: '>=5.0.4' viem: 2.x peerDependenciesMeta: typescript: optional: true dependencies: - '@coinbase/wallet-sdk': 3.9.1 - '@metamask/sdk': 0.18.6(react-dom@18.3.1)(react-i18next@13.5.0)(react-native@0.74.1)(react@18.3.1) - '@safe-global/safe-apps-provider': 0.18.1(typescript@5.4.5) - '@safe-global/safe-apps-sdk': 8.1.0(typescript@5.4.5) - '@wagmi/core': 2.9.1(@types/react@18.3.1)(react@18.3.1)(typescript@5.4.5)(viem@2.10.2) - '@walletconnect/ethereum-provider': 2.11.2(@types/react@18.3.1)(react@18.3.1) + '@coinbase/wallet-sdk': 4.0.4 + '@metamask/sdk': 0.26.5(react-dom@18.3.1)(react-native@0.74.1)(react@18.3.1) + '@safe-global/safe-apps-provider': 0.18.3(typescript@5.4.5) + '@safe-global/safe-apps-sdk': 9.1.0(typescript@5.4.5) + '@wagmi/core': 2.12.2(@types/react@18.3.1)(react@18.3.1)(typescript@5.4.5)(viem@2.10.2) + '@walletconnect/ethereum-provider': 2.13.0(@types/react@18.3.1)(react@18.3.1) '@walletconnect/modal': 2.6.2(@types/react@18.3.1)(react@18.3.1) + cbw-sdk: /@coinbase/wallet-sdk@3.9.3 typescript: 5.4.5 viem: 2.10.2(typescript@5.4.5) transitivePeerDependencies: @@ -6353,7 +6358,6 @@ packages: - ioredis - react - react-dom - - react-i18next - react-native - rollup - supports-color @@ -6362,23 +6366,24 @@ packages: - zod dev: false - /@wagmi/connectors@4.3.3(@wagmi/core@2.9.1)(react-i18next@13.5.0)(react-native@0.74.1)(react@18.3.1)(typescript@5.4.5)(viem@2.10.2): - resolution: {integrity: sha512-6u/HbWlIS2MI5lxBYbsqNZIQT4sBleFt8rhzH7mJBrHH6v95LmeZZ3qZFpWdopx4bQ6maNEZOIJnCLhv7k37DQ==} + /@wagmi/connectors@5.0.26(@wagmi/core@2.12.2)(react-native@0.74.1)(react@18.3.1)(typescript@5.4.5)(viem@2.10.2): + resolution: {integrity: sha512-aGc3oDQPQwVqJr7S/7IU7rF0bA61OYXGPLzj30Y3MSmmEWXtAEgKpqkhIwiEdYQAMnlR3ukbqROq8qmUm/iYQg==} peerDependencies: - '@wagmi/core': 2.9.1 + '@wagmi/core': 2.12.2 typescript: '>=5.0.4' viem: 2.x peerDependenciesMeta: typescript: optional: true dependencies: - '@coinbase/wallet-sdk': 3.9.1 - '@metamask/sdk': 0.18.6(react-i18next@13.5.0)(react-native@0.74.1)(react@18.3.1) - '@safe-global/safe-apps-provider': 0.18.1(typescript@5.4.5) - '@safe-global/safe-apps-sdk': 8.1.0(typescript@5.4.5) - '@wagmi/core': 2.9.1(@types/react@18.3.1)(react@18.3.1)(typescript@5.4.5)(viem@2.10.2) - '@walletconnect/ethereum-provider': 2.11.2(@types/react@18.3.1)(react@18.3.1) + '@coinbase/wallet-sdk': 4.0.4 + '@metamask/sdk': 0.26.5(react-native@0.74.1)(react@18.3.1) + '@safe-global/safe-apps-provider': 0.18.3(typescript@5.4.5) + '@safe-global/safe-apps-sdk': 9.1.0(typescript@5.4.5) + '@wagmi/core': 2.12.2(@types/react@18.3.1)(react@18.3.1)(typescript@5.4.5)(viem@2.10.2) + '@walletconnect/ethereum-provider': 2.13.0(@types/react@18.3.1)(react@18.3.1) '@walletconnect/modal': 2.6.2(@types/react@18.3.1)(react@18.3.1) + cbw-sdk: /@coinbase/wallet-sdk@3.9.3 typescript: 5.4.5 viem: 2.10.2(typescript@5.4.5) transitivePeerDependencies: @@ -6400,7 +6405,6 @@ packages: - ioredis - react - react-dom - - react-i18next - react-native - rollup - supports-color @@ -6409,8 +6413,8 @@ packages: - zod dev: false - /@wagmi/core@2.9.1(@types/react@18.3.1)(react@18.3.1)(typescript@5.4.5)(viem@2.10.2): - resolution: {integrity: sha512-VUILlj0qFmZEa9XpNsYhIaQe3jsJdFGSRSbn+xsvGBo+yZpNxQXuaLo3+ntuv1kTFdw8Qzk17fLGy2U9a0XFdA==} + /@wagmi/core@2.12.2(@types/react@18.3.1)(react@18.3.1)(typescript@5.4.5)(viem@2.10.2): + resolution: {integrity: sha512-V/KmuTOBHVdg5NG5EIzLyWuXJ3f8a8YwpXM7ywjuEnGkljxh+WROKKd+I/Qc5RHK59nEhFOYWQKXuyz1szmO9A==} peerDependencies: '@tanstack/query-core': '>=5.0.0' typescript: '>=5.0.4' @@ -6422,17 +6426,14 @@ packages: optional: true dependencies: eventemitter3: 5.0.1 - mipd: 0.0.5(typescript@5.4.5) + mipd: 0.0.7(typescript@5.4.5) typescript: 5.4.5 viem: 2.10.2(typescript@5.4.5) zustand: 4.4.1(@types/react@18.3.1)(react@18.3.1) transitivePeerDependencies: - '@types/react' - - bufferutil - immer - react - - utf-8-validate - - zod dev: false /@wallet-standard/base@1.0.1: @@ -6550,42 +6551,7 @@ packages: tslib: 1.14.1 dev: false - /@walletconnect/ethereum-provider@2.11.2(@types/react@18.3.1)(react@18.3.1): - resolution: {integrity: sha512-BUDqee0Uy2rCZVkW5Ao3q6Ado/3fePYnFdryVF+YL6bPhj+xQZ5OfKodl+uvs7Rwq++O5wTX2RqOTzpW7+v+Mg==} - dependencies: - '@walletconnect/jsonrpc-http-connection': 1.0.8 - '@walletconnect/jsonrpc-provider': 1.0.14 - '@walletconnect/jsonrpc-types': 1.0.4 - '@walletconnect/jsonrpc-utils': 1.0.8 - '@walletconnect/modal': 2.6.2(@types/react@18.3.1)(react@18.3.1) - '@walletconnect/sign-client': 2.11.2 - '@walletconnect/types': 2.11.2 - '@walletconnect/universal-provider': 2.11.2 - '@walletconnect/utils': 2.11.2 - events: 3.3.0 - transitivePeerDependencies: - - '@azure/app-configuration' - - '@azure/cosmos' - - '@azure/data-tables' - - '@azure/identity' - - '@azure/keyvault-secrets' - - '@azure/storage-blob' - - '@capacitor/preferences' - - '@netlify/blobs' - - '@planetscale/database' - - '@react-native-async-storage/async-storage' - - '@types/react' - - '@upstash/redis' - - '@vercel/kv' - - bufferutil - - encoding - - ioredis - - react - - uWebSockets.js - - utf-8-validate - dev: false - - /@walletconnect/ethereum-provider@2.13.0(react@18.3.1): + /@walletconnect/ethereum-provider@2.13.0(@types/react@18.3.1)(react@18.3.1): resolution: {integrity: sha512-dnpW8mmLpWl1AZUYGYZpaAfGw1HFkL0WSlhk5xekx3IJJKn4pLacX2QeIOo0iNkzNQxZfux1AK4Grl1DvtzZEA==} dependencies: '@walletconnect/jsonrpc-http-connection': 1.0.8 @@ -7361,7 +7327,7 @@ packages: qrcode: 1.5.3 dev: false - /@web3modal/wagmi@5.0.0(@wagmi/connectors@4.3.3)(@wagmi/core@2.9.1)(react@18.3.1)(viem@2.10.2): + /@web3modal/wagmi@5.0.0(@wagmi/connectors@5.0.26)(@wagmi/core@2.12.2)(react@18.3.1)(viem@2.10.2): resolution: {integrity: sha512-AegPzmmArOpELk9N44/BzNHKE50Fp19nfDJ/eVq8fM/yqDSlq7Gj2D1sEeZuEeXQGxgoAKNOWOlKP6IoQ/+s6g==} peerDependencies: '@wagmi/connectors': '>=4' @@ -7378,9 +7344,9 @@ packages: vue: optional: true dependencies: - '@wagmi/connectors': 4.3.3(@wagmi/core@2.9.1)(react-i18next@13.5.0)(react-native@0.74.1)(react@18.3.1)(typescript@5.4.5)(viem@2.10.2) - '@wagmi/core': 2.9.1(@types/react@18.3.1)(react@18.3.1)(typescript@5.4.5)(viem@2.10.2) - '@walletconnect/ethereum-provider': 2.13.0(react@18.3.1) + '@wagmi/connectors': 5.0.26(@wagmi/core@2.12.2)(react-native@0.74.1)(react@18.3.1)(typescript@5.4.5)(viem@2.10.2) + '@wagmi/core': 2.12.2(@types/react@18.3.1)(react@18.3.1)(typescript@5.4.5)(viem@2.10.2) + '@walletconnect/ethereum-provider': 2.13.0(@types/react@18.3.1)(react@18.3.1) '@web3modal/polyfills': 5.0.0 '@web3modal/scaffold': 5.0.0(react@18.3.1) '@web3modal/scaffold-react': 5.0.0(react@18.3.1) @@ -7538,20 +7504,6 @@ packages: through: 2.3.8 dev: false - /abitype@0.9.8(typescript@5.4.5): - resolution: {integrity: sha512-puLifILdm+8sjyss4S+fsUN09obiT1g2YW6CtcQF+QDzxR0euzgEB29MZujC6zMk2a6SVmtttq1fc6+YFA7WYQ==} - peerDependencies: - typescript: '>=5.0.4' - zod: ^3 >=3.19.1 - peerDependenciesMeta: - typescript: - optional: true - zod: - optional: true - dependencies: - typescript: 5.4.5 - dev: false - /abitype@1.0.0(typescript@5.4.5): resolution: {integrity: sha512-NMeMah//6bJ56H5XRj8QCV4AwuW6hB6zqz2LnhhLdcWVQOsXki6/Pn3APeqxCma62nXIcmZWdu1DlHWS74umVQ==} peerDependencies: @@ -8624,7 +8576,7 @@ packages: resolution: {integrity: sha512-fnULvOpxnC5/Vg3NCiWelDsLiUc9bRwAPs/+LfTLNvetFCtCTN+yQz15C/fs4AwX1R9K5GLtLfn8QW+dWisaAw==} engines: {node: '>=0.11'} dependencies: - '@babel/runtime': 7.24.0 + '@babel/runtime': 7.24.7 dev: false /dayjs@1.11.10: @@ -10073,12 +10025,6 @@ packages: resolution: {integrity: sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==} dev: true - /html-parse-stringify@3.0.1: - resolution: {integrity: sha512-KknJ50kTInJ7qIScF3jeaFRpMpE8/lfiTdzf/twXyPBLAGrLRTmkz3AdTnKeh40X8k9L2fdYwEp/42WGXIRGcg==} - dependencies: - void-elements: 3.1.0 - dev: false - /http-errors@2.0.0: resolution: {integrity: sha512-FtwrG/euBzaEjYeRqOgly7G0qviiXoJWnvEH2Z1plBdXgbyjv34pHTSb9zoeHMyDy33+DWy5Wt9Wo+TURtOYSQ==} engines: {node: '>= 0.8'} @@ -10142,13 +10088,7 @@ packages: /i18next-browser-languagedetector@7.1.0: resolution: {integrity: sha512-cr2k7u1XJJ4HTOjM9GyOMtbOA47RtUoWRAtt52z43r3AoMs2StYKyjS3URPhzHaf+mn10hY9dZWamga5WPQjhA==} dependencies: - '@babel/runtime': 7.24.0 - dev: false - - /i18next@22.5.1: - resolution: {integrity: sha512-8TGPgM3pAD+VRsMtUMNknRz3kzqwp/gPALrWMsDnmC1mKqJwpWyooQRLMcbTwq8z8YwSmuj+ZYvc+xCuEpkssA==} - dependencies: - '@babel/runtime': 7.24.0 + '@babel/runtime': 7.24.7 dev: false /i18next@23.11.5: @@ -11573,8 +11513,8 @@ packages: resolution: {integrity: sha512-jYofLM5Dam9279rdkWzqHozUo4ybjdZmCsDHePy5V/PbBcVMiSZR97gmAy45aqi8CK1lG2ECd356FU86avfwUQ==} engines: {node: '>=16 || 14 >=14.17'} - /mipd@0.0.5(typescript@5.4.5): - resolution: {integrity: sha512-gbKA784D2WKb5H/GtqEv+Ofd1S9Zj+Z/PGDIl1u1QAbswkxD28BQ5bSXQxkeBzPBABg1iDSbiwGG1XqlOxRspA==} + /mipd@0.0.7(typescript@5.4.5): + resolution: {integrity: sha512-aAPZPNDQ3uMTdKbuO2YmAw2TxLHO0moa4YKAyETM/DTj5FloZo+a+8tU+iv4GmW+sOxKLSRwcSFuczk+Cpt6fg==} peerDependencies: typescript: '>=5.0.4' peerDependenciesMeta: @@ -11582,11 +11522,6 @@ packages: optional: true dependencies: typescript: 5.4.5 - viem: 1.21.4(typescript@5.4.5) - transitivePeerDependencies: - - bufferutil - - utf-8-validate - - zod dev: false /mixme@0.5.10: @@ -12515,47 +12450,6 @@ packages: react: 18.3.1 scheduler: 0.23.2 - /react-i18next@13.5.0(i18next@22.5.1)(react-dom@18.3.1)(react-native@0.74.1)(react@18.3.1): - resolution: {integrity: sha512-CFJ5NDGJ2MUyBohEHxljOq/39NQ972rh1ajnadG9BjTk+UXbHLq4z5DKEbEQBDoIhUmmbuS/fIMJKo6VOax1HA==} - peerDependencies: - i18next: '>= 23.2.3' - react: '>= 16.8.0' - react-dom: '*' - react-native: '*' - peerDependenciesMeta: - react-dom: - optional: true - react-native: - optional: true - dependencies: - '@babel/runtime': 7.24.7 - html-parse-stringify: 3.0.1 - i18next: 22.5.1 - react: 18.3.1 - react-dom: 18.3.1(react@18.3.1) - react-native: 0.74.1(@babel/core@7.24.0)(@babel/preset-env@7.24.6)(@types/react@18.3.1)(react@18.3.1) - dev: false - - /react-i18next@13.5.0(i18next@23.11.5)(react-native@0.74.1)(react@18.3.1): - resolution: {integrity: sha512-CFJ5NDGJ2MUyBohEHxljOq/39NQ972rh1ajnadG9BjTk+UXbHLq4z5DKEbEQBDoIhUmmbuS/fIMJKo6VOax1HA==} - peerDependencies: - i18next: '>= 23.2.3' - react: '>= 16.8.0' - react-dom: '*' - react-native: '*' - peerDependenciesMeta: - react-dom: - optional: true - react-native: - optional: true - dependencies: - '@babel/runtime': 7.24.7 - html-parse-stringify: 3.0.1 - i18next: 23.11.5 - react: 18.3.1 - react-native: 0.74.1(@babel/core@7.24.0)(@babel/preset-env@7.24.6)(react@18.3.1) - dev: false - /react-is@17.0.2: resolution: {integrity: sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==} dev: false @@ -14566,14 +14460,6 @@ packages: dependencies: node-gyp-build: 4.8.1 - /utf-8-validate@6.0.4: - resolution: {integrity: sha512-xu9GQDeFp+eZ6LnCywXN/zBancWvOpUMzgjLPSjy4BRHSmTelvn2E0DG0o1sTiw5hkCKBHo8rwSKncfRfv2EEQ==} - engines: {node: '>=6.14.2'} - requiresBuild: true - dependencies: - node-gyp-build: 4.8.1 - dev: false - /util-deprecate@1.0.2: resolution: {integrity: sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==} @@ -14644,29 +14530,6 @@ packages: engines: {node: '>= 0.8'} dev: false - /viem@1.21.4(typescript@5.4.5): - resolution: {integrity: sha512-BNVYdSaUjeS2zKQgPs+49e5JKocfo60Ib2yiXOWBT6LuVxY1I/6fFX3waEtpXvL1Xn4qu+BVitVtMh9lyThyhQ==} - peerDependencies: - typescript: '>=5.0.4' - peerDependenciesMeta: - typescript: - optional: true - dependencies: - '@adraffy/ens-normalize': 1.10.0 - '@noble/curves': 1.2.0 - '@noble/hashes': 1.3.2 - '@scure/bip32': 1.3.2 - '@scure/bip39': 1.2.1 - abitype: 0.9.8(typescript@5.4.5) - isows: 1.0.3(ws@8.17.1) - typescript: 5.4.5 - ws: 8.17.1(bufferutil@4.0.8)(utf-8-validate@5.0.10) - transitivePeerDependencies: - - bufferutil - - utf-8-validate - - zod - dev: false - /viem@2.10.2(typescript@5.4.5): resolution: {integrity: sha512-gcOL+XxA0UWDarli856OEgumaBz4df/qNMpgno4NTSSZtJSC1XixIb3gWjVBei6Vx085ivw/U9ZE8gdniIo7fA==} peerDependencies: @@ -14889,11 +14752,6 @@ packages: resolution: {integrity: sha512-gQpnTgkubC6hQgdIcRdYGDSDc+SaujOdyesZQMv6JlfQee/9Mp0Qhnys6WxDWvQnL5WZdT7o2Ul187aSt0Rq+w==} dev: false - /void-elements@3.1.0: - resolution: {integrity: sha512-Dhxzh5HZuiHQhbvTW9AMetFfBHDMYpo23Uo9btPXgdYP+3T5S+p+jgNy7spra+veYhBP2dCSgxR/i2Y02h5/6w==} - engines: {node: '>=0.10.0'} - dev: false - /vue-template-compiler@2.7.16: resolution: {integrity: sha512-AYbUWAJHLGGQM7+cNTELw+KsOG9nl2CnSv467WobS5Cv9uk3wFcnr1Etsz2sEIHEZvw1U+o9mRlEO6QbZvUPGQ==} dependencies: @@ -14920,8 +14778,8 @@ packages: xml-name-validator: 5.0.0 dev: true - /wagmi@2.8.1(@tanstack/react-query@5.35.1)(@types/react@18.3.1)(react-dom@18.3.1)(react-i18next@13.5.0)(react-native@0.74.1)(react@18.3.1)(typescript@5.4.5)(viem@2.10.2): - resolution: {integrity: sha512-ekd9JHryGelHf9qcoZUDomCF4xDjYXjQ7EO+e9oCg89/i49Pr5CfmzgXfHbusyewhuzRAMWT5Db2oTBWRkqHwQ==} + /wagmi@2.11.3(@tanstack/react-query@5.35.1)(@types/react@18.3.1)(react-dom@18.3.1)(react-native@0.74.1)(react@18.3.1)(typescript@5.4.5)(viem@2.10.2): + resolution: {integrity: sha512-fUY9ABidNGPE5f5fRcs6yn0h7Y/rWq4XzJ7YhrYSHwwDji/ujkeVz54SA8w+UUWgCVn8GIvDjYC0tFaxGO5W8A==} peerDependencies: '@tanstack/react-query': '>=5.0.0' react: '>=18' @@ -14932,8 +14790,8 @@ packages: optional: true dependencies: '@tanstack/react-query': 5.35.1(react@18.3.1) - '@wagmi/connectors': 4.3.3(@types/react@18.3.1)(@wagmi/core@2.9.1)(react-dom@18.3.1)(react-i18next@13.5.0)(react-native@0.74.1)(react@18.3.1)(typescript@5.4.5)(viem@2.10.2) - '@wagmi/core': 2.9.1(@types/react@18.3.1)(react@18.3.1)(typescript@5.4.5)(viem@2.10.2) + '@wagmi/connectors': 5.0.26(@types/react@18.3.1)(@wagmi/core@2.12.2)(react-dom@18.3.1)(react-native@0.74.1)(react@18.3.1)(typescript@5.4.5)(viem@2.10.2) + '@wagmi/core': 2.12.2(@types/react@18.3.1)(react@18.3.1)(typescript@5.4.5)(viem@2.10.2) react: 18.3.1 typescript: 5.4.5 use-sync-external-store: 1.2.0(react@18.3.1) @@ -14958,7 +14816,6 @@ packages: - immer - ioredis - react-dom - - react-i18next - react-native - rollup - supports-color From eb23b2afabbe7b499d0f4c2a74ef2c53d725b032 Mon Sep 17 00:00:00 2001 From: Arthur Geron <3487334+arthurgeron@users.noreply.github.com> Date: Mon, 22 Jul 2024 16:58:59 -0300 Subject: [PATCH 07/26] chore: make currentEvmAccount synchronous --- .../walletconnect-connector/src/WalletConnectConnector.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/walletconnect-connector/src/WalletConnectConnector.ts b/packages/walletconnect-connector/src/WalletConnectConnector.ts index 9132e456..d397948c 100644 --- a/packages/walletconnect-connector/src/WalletConnectConnector.ts +++ b/packages/walletconnect-connector/src/WalletConnectConnector.ts @@ -88,10 +88,7 @@ export class WalletConnectConnector extends FuelConnector { }); } - async currentEvmAccount(): Promise { - if (!(await this.isConnected())) { - throw Error('No connected accounts'); - } + currentEvmAccount(): string | null { const ethAccount = getAccount(this.wagmiConfig).address || null; return ethAccount; From 69c7fba40e0552a389adbc8860ed12925176414a Mon Sep 17 00:00:00 2001 From: Arthur Geron <3487334+arthurgeron@users.noreply.github.com> Date: Tue, 23 Jul 2024 13:14:10 -0300 Subject: [PATCH 08/26] feat: static instance of web3modal config --- .../src/WalletConnectConnector.ts | 41 +++++++++++-------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/packages/walletconnect-connector/src/WalletConnectConnector.ts b/packages/walletconnect-connector/src/WalletConnectConnector.ts index d397948c..eb10e143 100644 --- a/packages/walletconnect-connector/src/WalletConnectConnector.ts +++ b/packages/walletconnect-connector/src/WalletConnectConnector.ts @@ -63,6 +63,7 @@ export class WalletConnectConnector extends FuelConnector { private config: WalletConnectConfig = {}; private _unsubs: Array<() => void> = []; + private static web3ModalConfig: Web3Modal; constructor(config: WalletConnectConfig = {}) { super(); @@ -71,13 +72,16 @@ export class WalletConnectConnector extends FuelConnector { this.customPredicate = config.predicateConfig || null; this.configProvider(config); + if (!WalletConnectConnector.web3ModalConfig) { + WalletConnectConnector.web3ModalConfig = createModalConfig( + this.config, + ).web3Modal; + } } // createModal re-instanciates the modal to update singletons from web3modal createModal() { this.destroy(); - const { web3Modal } = createModalConfig(this.config); - this.web3Modal = web3Modal; ApiController.prefetch(); this.setupWatchers(); } @@ -239,7 +243,6 @@ export class WalletConnectConnector extends FuelConnector { } async requireConnection() { - if (!this.web3Modal) this.createModal(); if (!this.wagmiConfig) return; const { state } = this.wagmiConfig; @@ -258,22 +261,24 @@ export class WalletConnectConnector extends FuelConnector { this.createModal(); return new Promise((resolve) => { - this.web3Modal.open(); - const unsub = this.web3Modal.subscribeEvents(async (event) => { - switch (event.data.event) { - case 'CONNECT_SUCCESS': { - resolve(true); - unsub(); - break; - } - case 'MODAL_CLOSE': - case 'CONNECT_ERROR': { - resolve(false); - unsub(); - break; + WalletConnectConnector.web3ModalConfig.open(); + const unsub = WalletConnectConnector.web3ModalConfig.subscribeEvents( + async (event) => { + switch (event.data.event) { + case 'CONNECT_SUCCESS': { + resolve(true); + unsub(); + break; + } + case 'MODAL_CLOSE': + case 'CONNECT_ERROR': { + resolve(false); + unsub(); + break; + } } - } - }); + }, + ); }); } From d7372dcdd539ab4f1ca1544cb8ad9d5106d9acc6 Mon Sep 17 00:00:00 2001 From: Arthur Geron <3487334+arthurgeron@users.noreply.github.com> Date: Tue, 23 Jul 2024 18:50:07 -0300 Subject: [PATCH 09/26] refactor: web3modal to be instantiated only once for both solana and wallet connect connectors --- .../react-next/src/components/Providers.tsx | 27 +++------- packages/connectors/src/constants.ts | 1 + packages/connectors/src/defaultConnectors.ts | 34 ++++++++++-- packages/connectors/src/web3Modal.ts | 31 +++++++++++ .../solana-connector/src/SolanaConnector.ts | 18 +++---- packages/solana-connector/src/constants.ts | 9 +++- packages/solana-connector/src/index.ts | 3 ++ .../src/test/solanaConnector.test.ts | 11 +++- .../src/test/testConnector.ts | 19 ++++++- packages/solana-connector/src/types.ts | 2 + .../src/utils/solanaConfig.ts | 20 +++++++ .../src/utils/solanaProvider.ts | 46 ---------------- .../solana-connector/src/utils/web3Modal.ts | 29 ++++++++++ .../src/WalletConnectConnector.ts | 54 +++++++++---------- .../walletconnect-connector/src/constants.ts | 1 + packages/walletconnect-connector/src/index.ts | 1 + .../src/test/testConnector.ts | 16 +++++- .../src/test/walletConnector.test.ts | 39 ++++++++++---- packages/walletconnect-connector/src/types.ts | 2 + .../src/utils/wagmiConfig.ts | 34 +----------- 20 files changed, 234 insertions(+), 163 deletions(-) create mode 100644 packages/connectors/src/constants.ts create mode 100644 packages/connectors/src/web3Modal.ts create mode 100644 packages/solana-connector/src/utils/solanaConfig.ts delete mode 100644 packages/solana-connector/src/utils/solanaProvider.ts create mode 100644 packages/solana-connector/src/utils/web3Modal.ts diff --git a/examples/react-next/src/components/Providers.tsx b/examples/react-next/src/components/Providers.tsx index 6059de7c..c7fb875e 100644 --- a/examples/react-next/src/components/Providers.tsx +++ b/examples/react-next/src/components/Providers.tsx @@ -3,34 +3,19 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; import { ReactQueryDevtools } from '@tanstack/react-query-devtools'; -import { - BakoSafeConnector, - FuelWalletConnector, - FuelWalletDevelopmentConnector, - FueletWalletConnector, - SolanaConnector, - WalletConnectConnector, -} from '@fuels/connectors'; +import { defaultConnectors } from '@fuels/connectors'; import { FuelProvider } from '@fuels/react'; const queryClient = new QueryClient(); +const fuelConfig = { + connectors: defaultConnectors({ devMode: true }), +}; + export const Providers = ({ children }: { children: React.ReactNode }) => { return ( - + {children} diff --git a/packages/connectors/src/constants.ts b/packages/connectors/src/constants.ts new file mode 100644 index 00000000..1a285f36 --- /dev/null +++ b/packages/connectors/src/constants.ts @@ -0,0 +1 @@ +export const DEFAULT_WC_PROJECT_ID = '00000000000000000000000000000000'; diff --git a/packages/connectors/src/defaultConnectors.ts b/packages/connectors/src/defaultConnectors.ts index 2596c01d..c2bb35ee 100644 --- a/packages/connectors/src/defaultConnectors.ts +++ b/packages/connectors/src/defaultConnectors.ts @@ -3,19 +3,28 @@ import { BurnerWalletConnector } from '@fuel-connectors/burner-wallet-connector' import { FuelWalletDevelopmentConnector } from '@fuel-connectors/fuel-development-wallet'; import { FuelWalletConnector } from '@fuel-connectors/fuel-wallet'; import { FueletWalletConnector } from '@fuel-connectors/fuelet-wallet'; -import { SolanaConnector } from '@fuel-connectors/solana-connector'; -import { WalletConnectConnector } from '@fuel-connectors/walletconnect-connector'; +import { + SolanaConnector, + createSolanaConfig, + createSolanaWeb3ModalInstance, +} from '@fuel-connectors/solana-connector'; +import { + WalletConnectConnector, + createWagmiConfig, +} from '@fuel-connectors/walletconnect-connector'; import type { Config } from '@wagmi/core'; +import type { ProviderType } from '@web3modal/solana/dist/types/src/utils/scaffold'; import type { FuelConnector } from 'fuels'; import type { BurnerWalletConfig } from '../../burner-wallet-connector/src/types'; - -const DEFAULT_WC_PROJECT_ID = '00000000000000000000000000000000'; +import { DEFAULT_WC_PROJECT_ID } from './constants'; +import { createWeb3ModalInstance } from './web3Modal'; type DefaultConnectors = { devMode?: boolean; wcProjectId?: string; burnerWalletConfig?: BurnerWalletConfig; ethWagmiConfig?: Config; + solanaConfig?: ProviderType; }; export function defaultConnectors({ @@ -23,17 +32,32 @@ export function defaultConnectors({ wcProjectId = DEFAULT_WC_PROJECT_ID, burnerWalletConfig, ethWagmiConfig, + solanaConfig: _solanaConfig, }: DefaultConnectors = {}): Array { - const connectors = [ + const solanaConfig = _solanaConfig || createSolanaConfig(wcProjectId); + + const solanaWeb3Modal = createSolanaWeb3ModalInstance({ + projectId: wcProjectId, + solanaConfig, + }); + const wagmiConfig = ethWagmiConfig || createWagmiConfig(); + const web3Modal = createWeb3ModalInstance({ + wagmiConfig, + projectId: wcProjectId, + }); + + const connectors: Array = [ new FuelWalletConnector(), new BakoSafeConnector(), new FueletWalletConnector(), new WalletConnectConnector({ projectId: wcProjectId, wagmiConfig: ethWagmiConfig, + web3Modal, }), new SolanaConnector({ projectId: wcProjectId, + web3Modal: solanaWeb3Modal, }), new BurnerWalletConnector(burnerWalletConfig), ]; diff --git a/packages/connectors/src/web3Modal.ts b/packages/connectors/src/web3Modal.ts new file mode 100644 index 00000000..7dbeaf6e --- /dev/null +++ b/packages/connectors/src/web3Modal.ts @@ -0,0 +1,31 @@ +import type { Config } from '@wagmi/core'; +import type { ProviderType } from '@web3modal/solana/dist/types/src/utils/scaffold'; +import { type Web3Modal, createWeb3Modal } from '@web3modal/wagmi'; +import { DEFAULT_WC_PROJECT_ID } from './constants'; + +interface CreateWeb3ModalProps { + wagmiConfig: Config | undefined; + projectId?: string; +} + +export function createWeb3ModalInstance({ + wagmiConfig, + projectId, +}: CreateWeb3ModalProps): Web3Modal { + if (!projectId) { + console.warn( + '[WalletConnect Connector]: Get a project ID on https://cloud.walletconnect.com to use WalletConnect features.', + ); + } + + return createWeb3Modal({ + wagmiConfig: { + ...wagmiConfig, + // @ts-ignore + enableWalletConnect: !!projectId, + }, + enableAnalytics: false, + allowUnsupportedChain: true, + projectId: projectId ?? DEFAULT_WC_PROJECT_ID, + }); +} diff --git a/packages/solana-connector/src/SolanaConnector.ts b/packages/solana-connector/src/SolanaConnector.ts index eac004f9..fa390858 100644 --- a/packages/solana-connector/src/SolanaConnector.ts +++ b/packages/solana-connector/src/SolanaConnector.ts @@ -22,7 +22,6 @@ import { SOLANA_ICON, TESTNET_URL } from './constants'; import { predicates } from './generated/predicate'; import type { Maybe, SolanaConfig } from './types'; import { PredicateAccount } from './utils/Predicate'; -import { createSolanaProvider } from './utils/solanaProvider'; import { getSignatureIndex } from './utils/witness'; export class SolanaConnector extends FuelConnector { @@ -46,32 +45,30 @@ export class SolanaConnector extends FuelConnector { predicateAddress: string | null = null; private predicateAccount: PredicateAccount; - private config: SolanaConfig = {}; + private config: SolanaConfig = {} as SolanaConfig; private svmAddress: string | null = null; private subscriptions: Array<() => void> = []; - constructor(config: SolanaConfig = {}) { + constructor(config: SolanaConfig) { super(); - + this.configProviders(config); + this.web3Modal = config.web3Modal; this.predicateAccount = new PredicateAccount( config.predicateConfig ?? predicates['verification-predicate'], ); - - this.configProviders(config); } // createModal re-instanciates the modal to update singletons from web3modal createModal() { this.destroy(); - const { walletConnectModal } = createSolanaProvider(this.config); - this.web3Modal = walletConnectModal; ApiController.prefetch(); this.setupWatchers(); } - async configProviders(config: SolanaConfig = {}) { + async configProviders(config: SolanaConfig) { this.config = Object.assign(config, { - fuelProvider: config.fuelProvider || FuelProvider.create(TESTNET_URL), + fuelProvider: await (config.fuelProvider || + FuelProvider.create(TESTNET_URL)), }); } @@ -177,7 +174,6 @@ export class SolanaConnector extends FuelConnector { * ============================================================ */ async ping(): Promise { - await this.configProviders(); return true; } diff --git a/packages/solana-connector/src/constants.ts b/packages/solana-connector/src/constants.ts index 010c784e..4a0dc689 100644 --- a/packages/solana-connector/src/constants.ts +++ b/packages/solana-connector/src/constants.ts @@ -29,8 +29,15 @@ export const solanaDevnet = { chain: 'solana', }; -export const SolanaChains = { +export const solanaChains = { MAINNET: solana, TESTNET: solanaTestnet, DEVNET: solanaDevnet, }; +export const DEFAULT_PROJECT_ID = '00000000000000000000000000000000'; + +export const DEFAULT_CHAINS = [ + solanaChains.MAINNET, + solanaChains.TESTNET, + solanaChains.DEVNET, +]; diff --git a/packages/solana-connector/src/index.ts b/packages/solana-connector/src/index.ts index a45aef10..58936db7 100644 --- a/packages/solana-connector/src/index.ts +++ b/packages/solana-connector/src/index.ts @@ -1,2 +1,5 @@ export * from './SolanaConnector'; export * from './types'; +export * from './utils/solanaConfig'; +export * from './utils/web3Modal'; +export * from './constants'; diff --git a/packages/solana-connector/src/test/solanaConnector.test.ts b/packages/solana-connector/src/test/solanaConnector.test.ts index a652b5f1..8b507aa3 100644 --- a/packages/solana-connector/src/test/solanaConnector.test.ts +++ b/packages/solana-connector/src/test/solanaConnector.test.ts @@ -10,10 +10,17 @@ import { test, } from 'vitest'; import { SolanaConnector } from '../SolanaConnector'; -import { TESTNET_URL } from '../constants'; +import { createSolanaConfig } from '../utils/solanaConfig'; +import { createSolanaWeb3ModalInstance } from '../utils/web3Modal'; describe('Solana Connector', () => { - const connector = new SolanaConnector({ projectId: '0000' }); + const projectId = '0000'; + const solanaConfig = createSolanaConfig(); + const web3Modal = createSolanaWeb3ModalInstance({ + projectId, + solanaConfig, + }); + const connector = new SolanaConnector({ projectId, web3Modal }); const snapshotPath = path.join(__dirname, ''); diff --git a/packages/solana-connector/src/test/testConnector.ts b/packages/solana-connector/src/test/testConnector.ts index ba4120a3..313f1c4d 100644 --- a/packages/solana-connector/src/test/testConnector.ts +++ b/packages/solana-connector/src/test/testConnector.ts @@ -1,10 +1,25 @@ import type { Provider } from 'fuels'; -import { SolanaConnector } from '../index'; +import { + DEFAULT_PROJECT_ID, + SolanaConnector, + createSolanaConfig, + createSolanaWeb3ModalInstance, +} from '../index'; export class testWalletConnectConnector extends SolanaConnector { constructor(fuelProvider: Provider) { - super(); + const solanaConfig = createSolanaConfig(DEFAULT_PROJECT_ID); + const web3Modal = createSolanaWeb3ModalInstance({ + projectId: DEFAULT_PROJECT_ID, + solanaConfig, + }); + super({ + fuelProvider: fuelProvider, + solanaConfig, + projectId: DEFAULT_PROJECT_ID, + web3Modal, + }); this.fuelProvider = fuelProvider; } diff --git a/packages/solana-connector/src/types.ts b/packages/solana-connector/src/types.ts index bc9d9ce9..ad5f92a8 100644 --- a/packages/solana-connector/src/types.ts +++ b/packages/solana-connector/src/types.ts @@ -1,3 +1,4 @@ +import type { Web3Modal } from '@web3modal/solana'; import type { ProviderType } from '@web3modal/solana/dist/types/src/utils/scaffold'; import type { Provider as FuelProvider, JsonAbi } from 'fuels'; @@ -11,6 +12,7 @@ export type SolanaConfig = { projectId?: string; predicateConfig?: SolanaPredicateConfig; solanaConfig?: ProviderType; + web3Modal: Web3Modal; }; export interface GetAccounts { diff --git a/packages/solana-connector/src/utils/solanaConfig.ts b/packages/solana-connector/src/utils/solanaConfig.ts new file mode 100644 index 00000000..c16c482f --- /dev/null +++ b/packages/solana-connector/src/utils/solanaConfig.ts @@ -0,0 +1,20 @@ +import { + type Web3Modal, + createWeb3Modal, + defaultSolanaConfig, +} from '@web3modal/solana'; +import { DEFAULT_CHAINS, DEFAULT_PROJECT_ID } from '../constants'; + +export function createSolanaConfig(projectId = DEFAULT_PROJECT_ID) { + return defaultSolanaConfig({ + enableInjected: true, + chains: DEFAULT_CHAINS, + projectId, + metadata: { + name: 'Web3Modal', + description: 'Web3Modal Laboratory', + url: 'https://lab.web3modal.com', + icons: ['https://avatars.githubusercontent.com/u/37784886'], + }, + }); +} diff --git a/packages/solana-connector/src/utils/solanaProvider.ts b/packages/solana-connector/src/utils/solanaProvider.ts deleted file mode 100644 index b51a6ad4..00000000 --- a/packages/solana-connector/src/utils/solanaProvider.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { - type Web3Modal, - createWeb3Modal, - defaultSolanaConfig, -} from '@web3modal/solana'; -import { SolanaChains } from '../constants'; -import type { SolanaConfig } from '../types'; - -const DEFAULT_PROJECT_ID = '00000000000000000000000000000000'; - -const chains = [ - SolanaChains.MAINNET, - SolanaChains.TESTNET, - SolanaChains.DEVNET, -]; - -interface ModalConfig { - walletConnectModal: Web3Modal; -} - -export function createSolanaProvider(config: SolanaConfig): ModalConfig { - const solanaConfig = - config.solanaConfig ?? - defaultSolanaConfig({ - enableInjected: true, - chains, - projectId: config.projectId ?? DEFAULT_PROJECT_ID, - metadata: { - name: 'Web3Modal', - description: 'Web3Modal Laboratory', - url: 'https://lab.web3modal.com', - icons: ['https://avatars.githubusercontent.com/u/37784886'], - }, - }); - - const walletConnectModal = createWeb3Modal({ - solanaConfig, - chains, - enableAnalytics: false, - projectId: config.projectId ?? DEFAULT_PROJECT_ID, - }); - - return { - walletConnectModal, - }; -} diff --git a/packages/solana-connector/src/utils/web3Modal.ts b/packages/solana-connector/src/utils/web3Modal.ts new file mode 100644 index 00000000..3efbe605 --- /dev/null +++ b/packages/solana-connector/src/utils/web3Modal.ts @@ -0,0 +1,29 @@ +import { + type Web3Modal as SolanaWeb3Modal, + createWeb3Modal as createSolanaWeb3Modal, +} from '@web3modal/solana'; +import type { ProviderType } from '@web3modal/solana/dist/types/src/utils/scaffold'; +import { DEFAULT_CHAINS, DEFAULT_PROJECT_ID } from '../constants'; + +interface CreateSolanaWeb3ModalProps { + projectId?: string; + solanaConfig: ProviderType; +} + +export function createSolanaWeb3ModalInstance({ + projectId, + solanaConfig, +}: CreateSolanaWeb3ModalProps): SolanaWeb3Modal { + if (!projectId) { + console.warn( + '[WalletConnect Connector]: Get a project ID on https://cloud.walletconnect.com to use WalletConnect features.', + ); + } + + return createSolanaWeb3Modal({ + solanaConfig, + chains: DEFAULT_CHAINS, + enableAnalytics: false, + projectId: projectId ?? DEFAULT_PROJECT_ID, + }); +} diff --git a/packages/walletconnect-connector/src/WalletConnectConnector.ts b/packages/walletconnect-connector/src/WalletConnectConnector.ts index eb10e143..18066064 100644 --- a/packages/walletconnect-connector/src/WalletConnectConnector.ts +++ b/packages/walletconnect-connector/src/WalletConnectConnector.ts @@ -31,7 +31,7 @@ import { VERSIONS } from '../versions/versions-dictionary'; import { ETHEREUM_ICON, TESTNET_URL } from './constants'; import type { Predicate, PredicateConfig, WalletConnectConfig } from './types'; import { PredicateAccount } from './utils/Predicate'; -import { createModalConfig, createWagmiConfig } from './utils/wagmiConfig'; +import { createWagmiConfig } from './utils/wagmiConfig'; import { getSignatureIndex } from './utils/witness'; export class WalletConnectConnector extends FuelConnector { @@ -61,22 +61,17 @@ export class WalletConnectConnector extends FuelConnector { predicateAccount: PredicateAccount | null = null; - private config: WalletConnectConfig = {}; + private config: WalletConnectConfig = {} as WalletConnectConfig; private _unsubs: Array<() => void> = []; - private static web3ModalConfig: Web3Modal; + private web3ModalConfig: Web3Modal; - constructor(config: WalletConnectConfig = {}) { + constructor(config: WalletConnectConfig) { super(); - this.wagmiConfig = createWagmiConfig(config); + this.wagmiConfig = config?.wagmiConfig || createWagmiConfig(); this.customPredicate = config.predicateConfig || null; - + this.web3ModalConfig = config.web3Modal; this.configProvider(config); - if (!WalletConnectConnector.web3ModalConfig) { - WalletConnectConnector.web3ModalConfig = createModalConfig( - this.config, - ).web3Modal; - } } // createModal re-instanciates the modal to update singletons from web3modal @@ -86,9 +81,10 @@ export class WalletConnectConnector extends FuelConnector { this.setupWatchers(); } - configProvider(config: WalletConnectConfig) { + async configProvider(config: WalletConnectConfig) { this.config = Object.assign(config, { - fuelProvider: config.fuelProvider || FuelProvider.create(TESTNET_URL), + fuelProvider: await (config.fuelProvider || + FuelProvider.create(TESTNET_URL)), }); } @@ -261,24 +257,22 @@ export class WalletConnectConnector extends FuelConnector { this.createModal(); return new Promise((resolve) => { - WalletConnectConnector.web3ModalConfig.open(); - const unsub = WalletConnectConnector.web3ModalConfig.subscribeEvents( - async (event) => { - switch (event.data.event) { - case 'CONNECT_SUCCESS': { - resolve(true); - unsub(); - break; - } - case 'MODAL_CLOSE': - case 'CONNECT_ERROR': { - resolve(false); - unsub(); - break; - } + this.web3ModalConfig.open(); + const unsub = this.web3ModalConfig.subscribeEvents(async (event) => { + switch (event.data.event) { + case 'CONNECT_SUCCESS': { + resolve(true); + unsub(); + break; } - }, - ); + case 'MODAL_CLOSE': + case 'CONNECT_ERROR': { + resolve(false); + unsub(); + break; + } + } + }); }); } diff --git a/packages/walletconnect-connector/src/constants.ts b/packages/walletconnect-connector/src/constants.ts index 135cf2ab..5ba5b0fe 100644 --- a/packages/walletconnect-connector/src/constants.ts +++ b/packages/walletconnect-connector/src/constants.ts @@ -1,3 +1,4 @@ +export const DEFAULT_PROJECT_ID = '00000000000000000000000000000000'; export const ETHEREUM_ICON = 'data:image/svg+xml;utf8;base64,PHN2ZyB3aWR0aD0iNTEyIiBoZWlnaHQ9IjUxMiIgdmlld0JveD0iMCAwIDUxMiA1MTIiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxwYXRoIGQ9Ik0yNTMgMzM1LjEyMkwyNTUuODg2IDMzOEwzODggMjU5Ljk4N0wyNTUuODg2IDQxTDI1MyA1MC43OTgzVjMzNS4xMjJaIiBmaWxsPSIjMzQzNDM0Ii8+CjxwYXRoIGQ9Ik0yNTYgMzM4VjQxTDEyNCAyNTkuOTg2TDI1NiAzMzhaIiBmaWxsPSIjOEM4QzhDIi8+CjxwYXRoIGQ9Ik0yNTQgNDY1LjI4MUwyNTUuNjI4IDQ3MEwzODggMjg1TDI1NS42MjkgMzYyLjU2M0wyNTQuMDAxIDM2NC41MzJMMjU0IDQ2NS4yODFaIiBmaWxsPSIjM0MzQzNCIi8+CjxwYXRoIGQ9Ik0xMjQgMjg1TDI1NiA0NzBWMzYyLjU2MkwxMjQgMjg1WiIgZmlsbD0iIzhDOEM4QyIvPgo8cGF0aCBkPSJNMjU2IDIwMFYzMzhMMzg4IDI1OS45ODhMMjU2IDIwMFoiIGZpbGw9IiMxNDE0MTQiLz4KPHBhdGggZD0iTTI1NiAyMDBMMTI0IDI1OS45ODhMMjU2IDMzOFYyMDBaIiBmaWxsPSIjMzkzOTM5Ii8+Cjwvc3ZnPgo='; export const TESTNET_URL = 'https://testnet.fuel.network/v1/graphql'; diff --git a/packages/walletconnect-connector/src/index.ts b/packages/walletconnect-connector/src/index.ts index 6ffd50ec..2d6bef95 100644 --- a/packages/walletconnect-connector/src/index.ts +++ b/packages/walletconnect-connector/src/index.ts @@ -1,2 +1,3 @@ export * from './WalletConnectConnector'; export * from './types'; +export * from './utils/wagmiConfig'; diff --git a/packages/walletconnect-connector/src/test/testConnector.ts b/packages/walletconnect-connector/src/test/testConnector.ts index 8bf6a029..cec9c845 100644 --- a/packages/walletconnect-connector/src/test/testConnector.ts +++ b/packages/walletconnect-connector/src/test/testConnector.ts @@ -1,13 +1,27 @@ import { type Provider, bn } from 'fuels'; import { getAccount } from '@wagmi/core'; +import { createWeb3Modal } from '@web3modal/wagmi'; +import { DEFAULT_PROJECT_ID } from '../constants'; import { type Predicate, WalletConnectConnector } from '../index'; import { PredicateAccount } from '../utils/Predicate'; +import { createWagmiConfig } from '../utils/wagmiConfig'; import { VERSIONS } from './mocked-versions/versions-dictionary'; export class testWalletConnectConnector extends WalletConnectConnector { constructor(fuelProvider: Provider) { - super(); + const wagmiConfig = createWagmiConfig(); + const web3Modal = createWeb3Modal({ + wagmiConfig: { + ...wagmiConfig, + // @ts-ignore + enableWalletConnect: !!projectId, + }, + enableAnalytics: false, + allowUnsupportedChain: true, + projectId: DEFAULT_PROJECT_ID, + }); + super({ wagmiConfig, web3Modal }); this.fuelProvider = fuelProvider; } diff --git a/packages/walletconnect-connector/src/test/walletConnector.test.ts b/packages/walletconnect-connector/src/test/walletConnector.test.ts index 5d56ce24..ebc8493f 100644 --- a/packages/walletconnect-connector/src/test/walletConnector.test.ts +++ b/packages/walletconnect-connector/src/test/walletConnector.test.ts @@ -1,5 +1,6 @@ import path from 'node:path'; import { launchNodeAndGetWallets } from '@fuel-ts/account/test-utils'; +import { createWeb3Modal } from '@web3modal/wagmi'; import { type Asset, type Network, Provider } from 'fuels'; import { afterAll, @@ -12,8 +13,10 @@ import { import { WalletConnectConnector } from '../WalletConnectConnector'; import { TESTNET_URL } from '../constants'; import { PredicateAccount } from '../utils/Predicate'; +import { createWagmiConfig } from '../utils/wagmiConfig'; import { VERSIONS } from './mocked-versions/versions-dictionary'; +const PROJECT_ID = '0000'; describe('WalletConnect Connector', () => { let connector: WalletConnectConnector; @@ -23,6 +26,24 @@ describe('WalletConnect Connector', () => { let stopProvider: () => void; + function connectorFactory( + props?: Partial[0]>, + ) { + const projectId = props?.projectId || PROJECT_ID; + const wagmiConfig = createWagmiConfig(); + const web3Modal = createWeb3Modal({ + wagmiConfig: { + ...wagmiConfig, + // @ts-ignore + enableWalletConnect: !!props?.projectId, + }, + enableAnalytics: false, + allowUnsupportedChain: true, + projectId, + }); + return new WalletConnectConnector({ wagmiConfig, web3Modal, ...props }); + } + beforeAll(async () => { process.env.GENESIS_SECRET = '0x6e48a022f9d4ae187bca4e2645abd62198ae294ee484766edbdaadf78160dc68'; @@ -43,14 +64,12 @@ describe('WalletConnect Connector', () => { beforeEach(() => { // Class contains state, reset the state for each test - connector = new WalletConnectConnector({ projectId: '0000' }); + connector = connectorFactory({ projectId: '0000' }); }); describe('constructor()', () => { test('initialize properties correctly', async () => { - const walletWalletConnector = new WalletConnectConnector({ - projectId: '0000', - }); + const walletWalletConnector = connectorFactory(); await walletWalletConnector.ping(); expect(walletWalletConnector).to.be.an.instanceOf(WalletConnectConnector); @@ -65,9 +84,8 @@ describe('WalletConnect Connector', () => { test('can construct a WalletConnectConnector with a non default Provider', async () => { const nonDefaultProvider = fuelProvider; - const walletWalletConnector = new WalletConnectConnector({ + const walletWalletConnector = connectorFactory({ fuelProvider: nonDefaultProvider, - projectId: '0000', }); await walletWalletConnector.ping(); @@ -83,9 +101,8 @@ describe('WalletConnect Connector', () => { test('can construct a WalletConnectConnector with a non default Promise Provider', async () => { const nonDefaultProvider = Provider.create(fuelProvider.url); - const walletWalletConnector = new WalletConnectConnector({ + const walletWalletConnector = connectorFactory({ fuelProvider: nonDefaultProvider, - projectId: '0000', }); await walletWalletConnector.ping(); @@ -102,7 +119,7 @@ describe('WalletConnect Connector', () => { describe('isConnected()', () => { test('false when not connected', async () => { - const connector = new WalletConnectConnector(); + const connector = connectorFactory(); const connectedAfterConnect = await connector.isConnected(); expect(connectedAfterConnect).to.be.false; @@ -136,7 +153,7 @@ describe('WalletConnect Connector', () => { const version = '0x4a45483e0309350adb9796f7b9f4a4af263a6b03160e52e8c9df9f22d11b4f33'; - const walletConectconnector = new WalletConnectConnector({ + const walletConectconnector = connectorFactory({ predicateConfig: VERSIONS[version].predicate, }); @@ -146,7 +163,7 @@ describe('WalletConnect Connector', () => { }); test('Should setup predicate without given config', async () => { - const walletConectconnector = new WalletConnectConnector(); + const walletConectconnector = connectorFactory(); const predicateAccount = await walletConectconnector.setupPredicate(); diff --git a/packages/walletconnect-connector/src/types.ts b/packages/walletconnect-connector/src/types.ts index cd3ecd80..9d5767c6 100644 --- a/packages/walletconnect-connector/src/types.ts +++ b/packages/walletconnect-connector/src/types.ts @@ -1,4 +1,5 @@ import type { Config as WagmiConfig } from '@wagmi/core'; +import type { Web3Modal } from '@web3modal/wagmi'; import type { Provider as FuelProvider, JsonAbi } from 'fuels'; export interface PredicateConfig { @@ -11,6 +12,7 @@ export type WalletConnectConfig = { projectId?: string; wagmiConfig?: WagmiConfig; predicateConfig?: PredicateConfig; + web3Modal: Web3Modal; }; interface PredicateTypeComponents { diff --git a/packages/walletconnect-connector/src/utils/wagmiConfig.ts b/packages/walletconnect-connector/src/utils/wagmiConfig.ts index b1a3c376..9f02298e 100644 --- a/packages/walletconnect-connector/src/utils/wagmiConfig.ts +++ b/packages/walletconnect-connector/src/utils/wagmiConfig.ts @@ -1,15 +1,7 @@ import { http, type Config, createConfig, injected } from '@wagmi/core'; import { mainnet, sepolia } from '@wagmi/core/chains'; -import { type Web3Modal, createWeb3Modal } from '@web3modal/wagmi'; -import type { WalletConnectConfig } from '../types'; -interface ModalConfig { - wagmiConfig: Config; - web3Modal: Web3Modal; -} - -export const createWagmiConfig = (config: WalletConnectConfig): Config => - config.wagmiConfig ?? +export const createWagmiConfig = (): Config => createConfig({ chains: [sepolia, mainnet], transports: { @@ -18,27 +10,3 @@ export const createWagmiConfig = (config: WalletConnectConfig): Config => }, connectors: [injected({ shimDisconnect: false })], }); - -export function createModalConfig(config: WalletConnectConfig): ModalConfig { - const wagmiConfig = createWagmiConfig(config); - - if (!config.projectId) { - console.warn( - '[WalletConnect Connector]: Get a project ID on https://cloud.walletconnect.com to use WalletConnect features.', - ); - } - - return { - wagmiConfig, - web3Modal: createWeb3Modal({ - wagmiConfig: { - ...wagmiConfig, - // @ts-ignore - enableWalletConnect: !!config.projectId, - }, - enableAnalytics: false, - allowUnsupportedChain: true, - projectId: config.projectId ?? '00000000000000000000000000000000', - }), - }; -} From 78610e902cf0ceaad2dff168003a7ff3351f3571 Mon Sep 17 00:00:00 2001 From: Arthur Geron <3487334+arthurgeron@users.noreply.github.com> Date: Tue, 23 Jul 2024 19:07:25 -0300 Subject: [PATCH 10/26] feat: enforce predicate initialization --- packages/walletconnect-connector/src/WalletConnectConnector.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/walletconnect-connector/src/WalletConnectConnector.ts b/packages/walletconnect-connector/src/WalletConnectConnector.ts index 18066064..a00dcb9e 100644 --- a/packages/walletconnect-connector/src/WalletConnectConnector.ts +++ b/packages/walletconnect-connector/src/WalletConnectConnector.ts @@ -239,6 +239,7 @@ export class WalletConnectConnector extends FuelConnector { } async requireConnection() { + if (!this.predicateAccount) this.createModal(); if (!this.wagmiConfig) return; const { state } = this.wagmiConfig; From be9fb3211e2c8441e4887ab563dfba6bc2e4dbec Mon Sep 17 00:00:00 2001 From: Arthur Geron <3487334+arthurgeron@users.noreply.github.com> Date: Wed, 24 Jul 2024 16:48:46 -0300 Subject: [PATCH 11/26] feat: enforce provider defined during ping on Solana Connector --- packages/solana-connector/src/SolanaConnector.ts | 13 ++++++++++--- .../src/WalletConnectConnector.ts | 5 ++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/solana-connector/src/SolanaConnector.ts b/packages/solana-connector/src/SolanaConnector.ts index fa390858..2461b892 100644 --- a/packages/solana-connector/src/SolanaConnector.ts +++ b/packages/solana-connector/src/SolanaConnector.ts @@ -65,10 +65,12 @@ export class SolanaConnector extends FuelConnector { this.setupWatchers(); } - async configProviders(config: SolanaConfig) { + providerFactory(config?: SolanaConfig) { + return config?.fuelProvider || FuelProvider.create(TESTNET_URL); + } + configProviders(config: SolanaConfig) { this.config = Object.assign(config, { - fuelProvider: await (config.fuelProvider || - FuelProvider.create(TESTNET_URL)), + fuelProvider: this.providerFactory(config), }); } @@ -174,6 +176,11 @@ export class SolanaConnector extends FuelConnector { * ============================================================ */ async ping(): Promise { + if (!this.config?.fuelProvider) { + this.config = Object.assign(this.config, { + fuelProvider: this.providerFactory(this.config), + }); + } return true; } diff --git a/packages/walletconnect-connector/src/WalletConnectConnector.ts b/packages/walletconnect-connector/src/WalletConnectConnector.ts index a00dcb9e..ea825d45 100644 --- a/packages/walletconnect-connector/src/WalletConnectConnector.ts +++ b/packages/walletconnect-connector/src/WalletConnectConnector.ts @@ -81,10 +81,9 @@ export class WalletConnectConnector extends FuelConnector { this.setupWatchers(); } - async configProvider(config: WalletConnectConfig) { + configProvider(config: WalletConnectConfig) { this.config = Object.assign(config, { - fuelProvider: await (config.fuelProvider || - FuelProvider.create(TESTNET_URL)), + fuelProvider: config.fuelProvider || FuelProvider.create(TESTNET_URL), }); } From a4363d2dbbae60aae611439a852a019c75a82c96 Mon Sep 17 00:00:00 2001 From: Arthur Geron <3487334+arthurgeron@users.noreply.github.com> Date: Wed, 24 Jul 2024 18:12:53 -0300 Subject: [PATCH 12/26] chore: generate new test release From 416c423870f3c56a0e8cfa73e23fabd7d3ce57c5 Mon Sep 17 00:00:00 2001 From: Arthur Geron <3487334+arthurgeron@users.noreply.github.com> Date: Wed, 24 Jul 2024 22:21:23 -0300 Subject: [PATCH 13/26] fix: create solana web3modal dynamically fixes network selection not working --- packages/connectors/src/defaultConnectors.ts | 13 +----------- .../solana-connector/src/SolanaConnector.ts | 14 ++++++++++++- packages/solana-connector/src/index.ts | 3 --- .../src/test/solanaConnector.test.ts | 21 ++++--------------- .../src/test/testConnector.ts | 15 +------------ packages/solana-connector/src/types.ts | 2 -- 6 files changed, 19 insertions(+), 49 deletions(-) diff --git a/packages/connectors/src/defaultConnectors.ts b/packages/connectors/src/defaultConnectors.ts index c2bb35ee..caee4d98 100644 --- a/packages/connectors/src/defaultConnectors.ts +++ b/packages/connectors/src/defaultConnectors.ts @@ -3,11 +3,7 @@ import { BurnerWalletConnector } from '@fuel-connectors/burner-wallet-connector' import { FuelWalletDevelopmentConnector } from '@fuel-connectors/fuel-development-wallet'; import { FuelWalletConnector } from '@fuel-connectors/fuel-wallet'; import { FueletWalletConnector } from '@fuel-connectors/fuelet-wallet'; -import { - SolanaConnector, - createSolanaConfig, - createSolanaWeb3ModalInstance, -} from '@fuel-connectors/solana-connector'; +import { SolanaConnector } from '@fuel-connectors/solana-connector'; import { WalletConnectConnector, createWagmiConfig, @@ -34,12 +30,6 @@ export function defaultConnectors({ ethWagmiConfig, solanaConfig: _solanaConfig, }: DefaultConnectors = {}): Array { - const solanaConfig = _solanaConfig || createSolanaConfig(wcProjectId); - - const solanaWeb3Modal = createSolanaWeb3ModalInstance({ - projectId: wcProjectId, - solanaConfig, - }); const wagmiConfig = ethWagmiConfig || createWagmiConfig(); const web3Modal = createWeb3ModalInstance({ wagmiConfig, @@ -57,7 +47,6 @@ export function defaultConnectors({ }), new SolanaConnector({ projectId: wcProjectId, - web3Modal: solanaWeb3Modal, }), new BurnerWalletConnector(burnerWalletConfig), ]; diff --git a/packages/solana-connector/src/SolanaConnector.ts b/packages/solana-connector/src/SolanaConnector.ts index 2461b892..a27606b5 100644 --- a/packages/solana-connector/src/SolanaConnector.ts +++ b/packages/solana-connector/src/SolanaConnector.ts @@ -22,6 +22,8 @@ import { SOLANA_ICON, TESTNET_URL } from './constants'; import { predicates } from './generated/predicate'; import type { Maybe, SolanaConfig } from './types'; import { PredicateAccount } from './utils/Predicate'; +import { createSolanaConfig } from './utils/solanaConfig'; +import { createSolanaWeb3ModalInstance } from './utils/web3Modal'; import { getSignatureIndex } from './utils/witness'; export class SolanaConnector extends FuelConnector { @@ -52,15 +54,25 @@ export class SolanaConnector extends FuelConnector { constructor(config: SolanaConfig) { super(); this.configProviders(config); - this.web3Modal = config.web3Modal; this.predicateAccount = new PredicateAccount( config.predicateConfig ?? predicates['verification-predicate'], ); } + modalFactory(config?: SolanaConfig) { + const solanaConfig = createSolanaConfig(config?.projectId); + + return createSolanaWeb3ModalInstance({ + projectId: config?.projectId, + solanaConfig, + }); + } + // createModal re-instanciates the modal to update singletons from web3modal createModal() { this.destroy(); + const web3Modal = this.modalFactory(this.config); + this.web3Modal = web3Modal; ApiController.prefetch(); this.setupWatchers(); } diff --git a/packages/solana-connector/src/index.ts b/packages/solana-connector/src/index.ts index 58936db7..a45aef10 100644 --- a/packages/solana-connector/src/index.ts +++ b/packages/solana-connector/src/index.ts @@ -1,5 +1,2 @@ export * from './SolanaConnector'; export * from './types'; -export * from './utils/solanaConfig'; -export * from './utils/web3Modal'; -export * from './constants'; diff --git a/packages/solana-connector/src/test/solanaConnector.test.ts b/packages/solana-connector/src/test/solanaConnector.test.ts index 8b507aa3..78953ad1 100644 --- a/packages/solana-connector/src/test/solanaConnector.test.ts +++ b/packages/solana-connector/src/test/solanaConnector.test.ts @@ -1,26 +1,13 @@ import path from 'node:path'; import { launchNodeAndGetWallets } from '@fuel-ts/account/test-utils'; -import type { Asset, Network, Provider } from 'fuels'; -import { - afterAll, - beforeAll, - beforeEach, - describe, - expect, - test, -} from 'vitest'; +import type { Asset, Network } from 'fuels'; +import { beforeAll, describe, expect, test } from 'vitest'; import { SolanaConnector } from '../SolanaConnector'; -import { createSolanaConfig } from '../utils/solanaConfig'; -import { createSolanaWeb3ModalInstance } from '../utils/web3Modal'; describe('Solana Connector', () => { const projectId = '0000'; - const solanaConfig = createSolanaConfig(); - const web3Modal = createSolanaWeb3ModalInstance({ - projectId, - solanaConfig, - }); - const connector = new SolanaConnector({ projectId, web3Modal }); + + const connector = new SolanaConnector({ projectId }); const snapshotPath = path.join(__dirname, ''); diff --git a/packages/solana-connector/src/test/testConnector.ts b/packages/solana-connector/src/test/testConnector.ts index 313f1c4d..60c55977 100644 --- a/packages/solana-connector/src/test/testConnector.ts +++ b/packages/solana-connector/src/test/testConnector.ts @@ -1,24 +1,11 @@ import type { Provider } from 'fuels'; -import { - DEFAULT_PROJECT_ID, - SolanaConnector, - createSolanaConfig, - createSolanaWeb3ModalInstance, -} from '../index'; +import { SolanaConnector } from '../index'; export class testWalletConnectConnector extends SolanaConnector { constructor(fuelProvider: Provider) { - const solanaConfig = createSolanaConfig(DEFAULT_PROJECT_ID); - const web3Modal = createSolanaWeb3ModalInstance({ - projectId: DEFAULT_PROJECT_ID, - solanaConfig, - }); super({ fuelProvider: fuelProvider, - solanaConfig, - projectId: DEFAULT_PROJECT_ID, - web3Modal, }); this.fuelProvider = fuelProvider; } diff --git a/packages/solana-connector/src/types.ts b/packages/solana-connector/src/types.ts index ad5f92a8..8e62a043 100644 --- a/packages/solana-connector/src/types.ts +++ b/packages/solana-connector/src/types.ts @@ -11,8 +11,6 @@ export type SolanaConfig = { fuelProvider?: FuelProvider | Promise; projectId?: string; predicateConfig?: SolanaPredicateConfig; - solanaConfig?: ProviderType; - web3Modal: Web3Modal; }; export interface GetAccounts { From 4fce9e3c366fc4f3f1a18edec889bdf2013e9a40 Mon Sep 17 00:00:00 2001 From: Arthur Geron <3487334+arthurgeron@users.noreply.github.com> Date: Wed, 24 Jul 2024 23:05:17 -0300 Subject: [PATCH 14/26] feat: reinstantiate web3modal on wallet connect necessary because solana connector also is dynamic and will replace state otherwise --- packages/connectors/src/defaultConnectors.ts | 16 ++-------------- .../src/WalletConnectConnector.ts | 19 +++++++++++++------ packages/walletconnect-connector/src/index.ts | 1 - .../src/test/testConnector.ts | 16 +--------------- .../src/test/walletConnector.test.ts | 17 +---------------- packages/walletconnect-connector/src/types.ts | 2 -- .../src/utils}/web3Modal.ts | 7 +++---- 7 files changed, 20 insertions(+), 58 deletions(-) rename packages/{connectors/src => walletconnect-connector/src/utils}/web3Modal.ts (76%) diff --git a/packages/connectors/src/defaultConnectors.ts b/packages/connectors/src/defaultConnectors.ts index caee4d98..a492558d 100644 --- a/packages/connectors/src/defaultConnectors.ts +++ b/packages/connectors/src/defaultConnectors.ts @@ -4,16 +4,11 @@ import { FuelWalletDevelopmentConnector } from '@fuel-connectors/fuel-developmen import { FuelWalletConnector } from '@fuel-connectors/fuel-wallet'; import { FueletWalletConnector } from '@fuel-connectors/fuelet-wallet'; import { SolanaConnector } from '@fuel-connectors/solana-connector'; -import { - WalletConnectConnector, - createWagmiConfig, -} from '@fuel-connectors/walletconnect-connector'; +import { WalletConnectConnector } from '@fuel-connectors/walletconnect-connector'; import type { Config } from '@wagmi/core'; import type { ProviderType } from '@web3modal/solana/dist/types/src/utils/scaffold'; import type { FuelConnector } from 'fuels'; import type { BurnerWalletConfig } from '../../burner-wallet-connector/src/types'; -import { DEFAULT_WC_PROJECT_ID } from './constants'; -import { createWeb3ModalInstance } from './web3Modal'; type DefaultConnectors = { devMode?: boolean; @@ -25,17 +20,11 @@ type DefaultConnectors = { export function defaultConnectors({ devMode, - wcProjectId = DEFAULT_WC_PROJECT_ID, + wcProjectId, burnerWalletConfig, ethWagmiConfig, solanaConfig: _solanaConfig, }: DefaultConnectors = {}): Array { - const wagmiConfig = ethWagmiConfig || createWagmiConfig(); - const web3Modal = createWeb3ModalInstance({ - wagmiConfig, - projectId: wcProjectId, - }); - const connectors: Array = [ new FuelWalletConnector(), new BakoSafeConnector(), @@ -43,7 +32,6 @@ export function defaultConnectors({ new WalletConnectConnector({ projectId: wcProjectId, wagmiConfig: ethWagmiConfig, - web3Modal, }), new SolanaConnector({ projectId: wcProjectId, diff --git a/packages/walletconnect-connector/src/WalletConnectConnector.ts b/packages/walletconnect-connector/src/WalletConnectConnector.ts index ea825d45..76be0edb 100644 --- a/packages/walletconnect-connector/src/WalletConnectConnector.ts +++ b/packages/walletconnect-connector/src/WalletConnectConnector.ts @@ -32,6 +32,7 @@ import { ETHEREUM_ICON, TESTNET_URL } from './constants'; import type { Predicate, PredicateConfig, WalletConnectConfig } from './types'; import { PredicateAccount } from './utils/Predicate'; import { createWagmiConfig } from './utils/wagmiConfig'; +import { createWeb3ModalInstance } from './utils/web3Modal'; import { getSignatureIndex } from './utils/witness'; export class WalletConnectConnector extends FuelConnector { @@ -57,30 +58,36 @@ export class WalletConnectConnector extends FuelConnector { wagmiConfig: Config; ethProvider: unknown | null = null; fuelProvider: FuelProvider | null = null; - web3Modal!: Web3Modal; predicateAccount: PredicateAccount | null = null; private config: WalletConnectConfig = {} as WalletConnectConfig; private _unsubs: Array<() => void> = []; - private web3ModalConfig: Web3Modal; + private web3Modal: Web3Modal = {} as Web3Modal; constructor(config: WalletConnectConfig) { super(); this.wagmiConfig = config?.wagmiConfig || createWagmiConfig(); this.customPredicate = config.predicateConfig || null; - this.web3ModalConfig = config.web3Modal; this.configProvider(config); } // createModal re-instanciates the modal to update singletons from web3modal createModal() { this.destroy(); + this.web3Modal = this.modalFactory(this.config); ApiController.prefetch(); this.setupWatchers(); } + modalFactory(config: WalletConnectConfig) { + return createWeb3ModalInstance({ + projectId: config.projectId, + wagmiConfig: config.wagmiConfig, + }); + } + configProvider(config: WalletConnectConfig) { this.config = Object.assign(config, { fuelProvider: config.fuelProvider || FuelProvider.create(TESTNET_URL), @@ -238,7 +245,7 @@ export class WalletConnectConnector extends FuelConnector { } async requireConnection() { - if (!this.predicateAccount) this.createModal(); + if (!this.web3Modal) this.createModal(); if (!this.wagmiConfig) return; const { state } = this.wagmiConfig; @@ -257,8 +264,8 @@ export class WalletConnectConnector extends FuelConnector { this.createModal(); return new Promise((resolve) => { - this.web3ModalConfig.open(); - const unsub = this.web3ModalConfig.subscribeEvents(async (event) => { + this.web3Modal.open(); + const unsub = this.web3Modal.subscribeEvents(async (event) => { switch (event.data.event) { case 'CONNECT_SUCCESS': { resolve(true); diff --git a/packages/walletconnect-connector/src/index.ts b/packages/walletconnect-connector/src/index.ts index 2d6bef95..6ffd50ec 100644 --- a/packages/walletconnect-connector/src/index.ts +++ b/packages/walletconnect-connector/src/index.ts @@ -1,3 +1,2 @@ export * from './WalletConnectConnector'; export * from './types'; -export * from './utils/wagmiConfig'; diff --git a/packages/walletconnect-connector/src/test/testConnector.ts b/packages/walletconnect-connector/src/test/testConnector.ts index cec9c845..8f270fc0 100644 --- a/packages/walletconnect-connector/src/test/testConnector.ts +++ b/packages/walletconnect-connector/src/test/testConnector.ts @@ -1,27 +1,13 @@ import { type Provider, bn } from 'fuels'; import { getAccount } from '@wagmi/core'; -import { createWeb3Modal } from '@web3modal/wagmi'; -import { DEFAULT_PROJECT_ID } from '../constants'; import { type Predicate, WalletConnectConnector } from '../index'; import { PredicateAccount } from '../utils/Predicate'; -import { createWagmiConfig } from '../utils/wagmiConfig'; import { VERSIONS } from './mocked-versions/versions-dictionary'; export class testWalletConnectConnector extends WalletConnectConnector { constructor(fuelProvider: Provider) { - const wagmiConfig = createWagmiConfig(); - const web3Modal = createWeb3Modal({ - wagmiConfig: { - ...wagmiConfig, - // @ts-ignore - enableWalletConnect: !!projectId, - }, - enableAnalytics: false, - allowUnsupportedChain: true, - projectId: DEFAULT_PROJECT_ID, - }); - super({ wagmiConfig, web3Modal }); + super({ fuelProvider }); this.fuelProvider = fuelProvider; } diff --git a/packages/walletconnect-connector/src/test/walletConnector.test.ts b/packages/walletconnect-connector/src/test/walletConnector.test.ts index ebc8493f..2f41f944 100644 --- a/packages/walletconnect-connector/src/test/walletConnector.test.ts +++ b/packages/walletconnect-connector/src/test/walletConnector.test.ts @@ -1,6 +1,5 @@ import path from 'node:path'; import { launchNodeAndGetWallets } from '@fuel-ts/account/test-utils'; -import { createWeb3Modal } from '@web3modal/wagmi'; import { type Asset, type Network, Provider } from 'fuels'; import { afterAll, @@ -13,10 +12,8 @@ import { import { WalletConnectConnector } from '../WalletConnectConnector'; import { TESTNET_URL } from '../constants'; import { PredicateAccount } from '../utils/Predicate'; -import { createWagmiConfig } from '../utils/wagmiConfig'; import { VERSIONS } from './mocked-versions/versions-dictionary'; -const PROJECT_ID = '0000'; describe('WalletConnect Connector', () => { let connector: WalletConnectConnector; @@ -29,19 +26,7 @@ describe('WalletConnect Connector', () => { function connectorFactory( props?: Partial[0]>, ) { - const projectId = props?.projectId || PROJECT_ID; - const wagmiConfig = createWagmiConfig(); - const web3Modal = createWeb3Modal({ - wagmiConfig: { - ...wagmiConfig, - // @ts-ignore - enableWalletConnect: !!props?.projectId, - }, - enableAnalytics: false, - allowUnsupportedChain: true, - projectId, - }); - return new WalletConnectConnector({ wagmiConfig, web3Modal, ...props }); + return new WalletConnectConnector({ ...props }); } beforeAll(async () => { diff --git a/packages/walletconnect-connector/src/types.ts b/packages/walletconnect-connector/src/types.ts index 9d5767c6..cd3ecd80 100644 --- a/packages/walletconnect-connector/src/types.ts +++ b/packages/walletconnect-connector/src/types.ts @@ -1,5 +1,4 @@ import type { Config as WagmiConfig } from '@wagmi/core'; -import type { Web3Modal } from '@web3modal/wagmi'; import type { Provider as FuelProvider, JsonAbi } from 'fuels'; export interface PredicateConfig { @@ -12,7 +11,6 @@ export type WalletConnectConfig = { projectId?: string; wagmiConfig?: WagmiConfig; predicateConfig?: PredicateConfig; - web3Modal: Web3Modal; }; interface PredicateTypeComponents { diff --git a/packages/connectors/src/web3Modal.ts b/packages/walletconnect-connector/src/utils/web3Modal.ts similarity index 76% rename from packages/connectors/src/web3Modal.ts rename to packages/walletconnect-connector/src/utils/web3Modal.ts index 7dbeaf6e..577e94f8 100644 --- a/packages/connectors/src/web3Modal.ts +++ b/packages/walletconnect-connector/src/utils/web3Modal.ts @@ -1,7 +1,6 @@ import type { Config } from '@wagmi/core'; -import type { ProviderType } from '@web3modal/solana/dist/types/src/utils/scaffold'; import { type Web3Modal, createWeb3Modal } from '@web3modal/wagmi'; -import { DEFAULT_WC_PROJECT_ID } from './constants'; +import { DEFAULT_PROJECT_ID } from '../constants'; interface CreateWeb3ModalProps { wagmiConfig: Config | undefined; @@ -10,7 +9,7 @@ interface CreateWeb3ModalProps { export function createWeb3ModalInstance({ wagmiConfig, - projectId, + projectId = DEFAULT_PROJECT_ID, }: CreateWeb3ModalProps): Web3Modal { if (!projectId) { console.warn( @@ -26,6 +25,6 @@ export function createWeb3ModalInstance({ }, enableAnalytics: false, allowUnsupportedChain: true, - projectId: projectId ?? DEFAULT_WC_PROJECT_ID, + projectId: projectId, }); } From 612a79c8cbaa59707c1b1d38df7ce55a0d670b50 Mon Sep 17 00:00:00 2001 From: Arthur Geron <3487334+arthurgeron@users.noreply.github.com> Date: Thu, 25 Jul 2024 11:17:42 -0300 Subject: [PATCH 15/26] fix: referencing wrong wagmi config instance --- .../src/WalletConnectConnector.ts | 55 +++++++++++++------ .../src/test/testConnector.ts | 7 ++- 2 files changed, 45 insertions(+), 17 deletions(-) diff --git a/packages/walletconnect-connector/src/WalletConnectConnector.ts b/packages/walletconnect-connector/src/WalletConnectConnector.ts index 76be0edb..7ae68661 100644 --- a/packages/walletconnect-connector/src/WalletConnectConnector.ts +++ b/packages/walletconnect-connector/src/WalletConnectConnector.ts @@ -55,22 +55,25 @@ export class WalletConnectConnector extends FuelConnector { }, }; - wagmiConfig: Config; ethProvider: unknown | null = null; fuelProvider: FuelProvider | null = null; + web3Modal!: Web3Modal; predicateAccount: PredicateAccount | null = null; private config: WalletConnectConfig = {} as WalletConnectConfig; private _unsubs: Array<() => void> = []; - private web3Modal: Web3Modal = {} as Web3Modal; constructor(config: WalletConnectConfig) { super(); - this.wagmiConfig = config?.wagmiConfig || createWagmiConfig(); + const wagmiConfig = config?.wagmiConfig ?? createWagmiConfig(); this.customPredicate = config.predicateConfig || null; - this.configProvider(config); + this.configProvider({ ...config, wagmiConfig }); + } + + getWagmiConfig() { + return this.config?.wagmiConfig; } // createModal re-instanciates the modal to update singletons from web3modal @@ -95,7 +98,8 @@ export class WalletConnectConnector extends FuelConnector { } currentEvmAccount(): string | null { - const ethAccount = getAccount(this.wagmiConfig).address || null; + if (!this.config?.wagmiConfig) return null; + const ethAccount = getAccount(this.config.wagmiConfig).address || null; return ethAccount; } @@ -115,13 +119,17 @@ export class WalletConnectConnector extends FuelConnector { let predicateWithBalance: Predicate | null = null; + if (!this.config?.wagmiConfig) { + throw new Error('Wagmi config not found'); + } + for (const predicateVersion of predicateVersions) { const predicateInstance = new PredicateAccount({ abi: predicateVersion.pred.predicate.abi, bytecode: predicateVersion.pred.predicate.bytecode, }); - const account = getAccount(this.wagmiConfig); + const account = getAccount(this.config.wagmiConfig); const address = account.address; if (!address) { @@ -176,13 +184,17 @@ export class WalletConnectConnector extends FuelConnector { * ============================================================ */ evmAccounts(): Array { - const accounts = getAccount(this.wagmiConfig).addresses; + if (!this.config?.wagmiConfig) return []; + const accounts = getAccount(this.config.wagmiConfig).addresses; return accounts as Array; } setupWatchers() { + if (!this.config?.wagmiConfig) { + throw new Error('Wagmi config not found'); + } this._unsubs.push( - watchAccount(this.wagmiConfig, { + watchAccount(this.config.wagmiConfig, { onChange: async (account) => { const predicateAccount = await this.predicateAccount; @@ -246,17 +258,18 @@ export class WalletConnectConnector extends FuelConnector { async requireConnection() { if (!this.web3Modal) this.createModal(); - if (!this.wagmiConfig) return; + if (!this.config?.wagmiConfig) return; - const { state } = this.wagmiConfig; + const { state } = this.config.wagmiConfig; if (state.status === 'disconnected' && state.connections.size > 0) { - await reconnect(this.wagmiConfig); + await reconnect(this.config.wagmiConfig); } } async isConnected(): Promise { await this.requireConnection(); - const account = getAccount(this.wagmiConfig || {}); + if (!this.config?.wagmiConfig) return false; + const account = getAccount(this.config.wagmiConfig || {}); return account.isConnected || false; } @@ -284,8 +297,11 @@ export class WalletConnectConnector extends FuelConnector { } async disconnect(): Promise { - const { connector, isConnected } = getAccount(this.wagmiConfig); - await disconnect(this.wagmiConfig, { + if (!this.config?.wagmiConfig) { + throw new Error('Wagmi config not found'); + } + const { connector, isConnected } = getAccount(this.config.wagmiConfig); + await disconnect(this.config.wagmiConfig, { connector, }); @@ -318,6 +334,10 @@ export class WalletConnectConnector extends FuelConnector { throw Error('No predicate account found'); } + if (!this.config?.wagmiConfig) { + throw new Error('Wagmi config not found'); + } + const { fuelProvider } = await this.getProvider(); const chainId = fuelProvider.getChainId(); const evmAccount = this.predicateAccount.getEVMAddress( @@ -391,7 +411,7 @@ export class WalletConnectConnector extends FuelConnector { const txID = requestWithPredicateAttached.getTransactionId(chainId); // biome-ignore lint/suspicious/noExplicitAny: const provider: any = await getAccount( - this.wagmiConfig, + this.config.wagmiConfig, ).connector?.getProvider(); const signature = await provider.request({ method: 'personal_sign', @@ -419,7 +439,10 @@ export class WalletConnectConnector extends FuelConnector { if (!(await this.isConnected())) { throw Error('No connected accounts'); } - const ethAccount = getAccount(this.wagmiConfig).address || null; + if (!this.config?.wagmiConfig) { + throw new Error('Wagmi config not found'); + } + const ethAccount = getAccount(this.config.wagmiConfig).address || null; return ( this.predicateAccount?.getPredicateAddress(ethAccount as string) ?? null diff --git a/packages/walletconnect-connector/src/test/testConnector.ts b/packages/walletconnect-connector/src/test/testConnector.ts index 8f270fc0..0529d0cf 100644 --- a/packages/walletconnect-connector/src/test/testConnector.ts +++ b/packages/walletconnect-connector/src/test/testConnector.ts @@ -19,6 +19,11 @@ export class testWalletConnectConnector extends WalletConnectConnector { } async setupPredicate(): Promise { + const wagmiConfig = this.getWagmiConfig(); + if (!wagmiConfig) { + throw new Error('Wagmi config not found'); + } + if (this.customPredicate?.abi && this.customPredicate?.bytecode) { this.predicateAccount = new PredicateAccount(this.customPredicate); this.predicateAddress = 'custom'; @@ -39,7 +44,7 @@ export class testWalletConnectConnector extends WalletConnectConnector { bytecode: predicateVersion.pred.predicate.bytecode, }); - const account = getAccount(this.wagmiConfig); + const account = getAccount(wagmiConfig); const address = account.address; if (!address) { From 638ec306b12f311489ae035cfeb56ce8a8f330f9 Mon Sep 17 00:00:00 2001 From: Arthur Geron <3487334+arthurgeron@users.noreply.github.com> Date: Thu, 25 Jul 2024 11:34:43 -0300 Subject: [PATCH 16/26] fix: solana connector parsing evm address from wallet connect --- packages/solana-connector/src/SolanaConnector.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/solana-connector/src/SolanaConnector.ts b/packages/solana-connector/src/SolanaConnector.ts index a27606b5..c9023357 100644 --- a/packages/solana-connector/src/SolanaConnector.ts +++ b/packages/solana-connector/src/SolanaConnector.ts @@ -106,23 +106,28 @@ export class SolanaConnector extends FuelConnector { return account ? [account] : []; } + // Solana Web3Modal is Canary and not yet stable + // It shares the same events as WalletConnect, hence validations must be made in order to avoid running connections with EVM Addresses instead of Solana Addresses setupWatchers() { this.subscriptions.push( this.web3Modal.subscribeEvents((event) => { switch (event.data.event) { case 'CONNECT_SUCCESS': { + const address = this.web3Modal.getAddress() || ''; + + if (!address || address.startsWith('0x')) { + return; + } this.emit(this.events.connection, true); this.emit( this.events.currentAccount, - this.predicateAccount.getPredicateAddress( - this.web3Modal.getAddress() ?? '', - ), + this.predicateAccount.getPredicateAddress(address), ); this.emit( this.events.accounts, this.predicateAccount.getPredicateAccounts(this.svmAccounts()), ); - this.svmAddress = this.web3Modal.getAddress() ?? ''; + this.svmAddress = address; break; } case 'DISCONNECT_SUCCESS': { From 4591a26dacd3cdaf5564207692118547ca791f8a Mon Sep 17 00:00:00 2001 From: Arthur Geron <3487334+arthurgeron@users.noreply.github.com> Date: Thu, 25 Jul 2024 11:56:48 -0300 Subject: [PATCH 17/26] feat: ensure correct web3 state is applied to current modal --- packages/solana-connector/src/SolanaConnector.ts | 4 ++++ .../walletconnect-connector/src/WalletConnectConnector.ts | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/packages/solana-connector/src/SolanaConnector.ts b/packages/solana-connector/src/SolanaConnector.ts index c9023357..c12b8857 100644 --- a/packages/solana-connector/src/SolanaConnector.ts +++ b/packages/solana-connector/src/SolanaConnector.ts @@ -112,6 +112,10 @@ export class SolanaConnector extends FuelConnector { this.subscriptions.push( this.web3Modal.subscribeEvents((event) => { switch (event.data.event) { + case 'MODAL_OPEN': + // Ensures that the Solana Web3Modal config is applied over pre-existing states (e.g. WC Connect Web3Modal) + this.createModal(); + break; case 'CONNECT_SUCCESS': { const address = this.web3Modal.getAddress() || ''; diff --git a/packages/walletconnect-connector/src/WalletConnectConnector.ts b/packages/walletconnect-connector/src/WalletConnectConnector.ts index 7ae68661..b682c8cd 100644 --- a/packages/walletconnect-connector/src/WalletConnectConnector.ts +++ b/packages/walletconnect-connector/src/WalletConnectConnector.ts @@ -280,6 +280,10 @@ export class WalletConnectConnector extends FuelConnector { this.web3Modal.open(); const unsub = this.web3Modal.subscribeEvents(async (event) => { switch (event.data.event) { + case 'MODAL_OPEN': + // Ensures that the WC Web3Modal config is applied over pre-existing states (e.g. Solan Connect Web3Modal) + this.createModal(); + break; case 'CONNECT_SUCCESS': { resolve(true); unsub(); From 7db678a214e86d7670e5fc7558d97538b6f912c5 Mon Sep 17 00:00:00 2001 From: Arthur Geron <3487334+arthurgeron@users.noreply.github.com> Date: Thu, 25 Jul 2024 13:06:03 -0300 Subject: [PATCH 18/26] chore: update changeset --- .changeset/eight-bears-prove.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.changeset/eight-bears-prove.md b/.changeset/eight-bears-prove.md index 81bf8932..a9340d1f 100644 --- a/.changeset/eight-bears-prove.md +++ b/.changeset/eight-bears-prove.md @@ -2,5 +2,8 @@ "@fuel-connectors/walletconnect-connector": patch --- -Add `currentEvmAccount` method to `WalletConnectConnector`, which will return the current ethereum account connected. - +- Add `currentEvmAccount` method to `WalletConnectConnector`, which will return the current ethereum account connected. +- Fixed Wallet Connect Web3Modal instances conflicting and replacing Solana's +- Fixed issue where Wallet Connect's Web3Modal would reference a different Wagmi config instance. +- Updated wagmi and @wagmi/core to 2.11.3 +- Updated @wagmi/connectors to 5.0.26 From 31d3c5cda4429cf2070f79f5a8abec4001fd08c8 Mon Sep 17 00:00:00 2001 From: Arthur Geron <3487334+arthurgeron@users.noreply.github.com> Date: Thu, 25 Jul 2024 13:06:37 -0300 Subject: [PATCH 19/26] chore: disable test release --- .github/workflows/pr-release.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr-release.yaml b/.github/workflows/pr-release.yaml index 956b94db..aae4c558 100644 --- a/.github/workflows/pr-release.yaml +++ b/.github/workflows/pr-release.yaml @@ -7,8 +7,8 @@ jobs: release-pr: name: 'Release PR to npm' runs-on: buildjet-4vcpu-ubuntu-2204 - # comment out if:false to enable release PR to npm - # if: false + # Comment if:false to enable release PR to npm + if: false permissions: write-all steps: - uses: actions/checkout@v3 From ba9789e4f7e577c084f5e5c108a0097c0c63a6ee Mon Sep 17 00:00:00 2001 From: Arthur Geron <3487334+arthurgeron@users.noreply.github.com> Date: Thu, 25 Jul 2024 17:12:15 -0300 Subject: [PATCH 20/26] feat: close web3modal if connection already active --- .../src/WalletConnectConnector.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/walletconnect-connector/src/WalletConnectConnector.ts b/packages/walletconnect-connector/src/WalletConnectConnector.ts index b682c8cd..45f6b77d 100644 --- a/packages/walletconnect-connector/src/WalletConnectConnector.ts +++ b/packages/walletconnect-connector/src/WalletConnectConnector.ts @@ -1,12 +1,6 @@ import { hexToBytes } from '@ethereumjs/util'; import { hexlify, splitSignature } from '@ethersproject/bytes'; -import { - type Config, - disconnect, - getAccount, - reconnect, - watchAccount, -} from '@wagmi/core'; +import { disconnect, getAccount, reconnect, watchAccount } from '@wagmi/core'; import type { Web3Modal } from '@web3modal/wagmi'; import { type AbiMap, @@ -70,6 +64,7 @@ export class WalletConnectConnector extends FuelConnector { const wagmiConfig = config?.wagmiConfig ?? createWagmiConfig(); this.customPredicate = config.predicateConfig || null; this.configProvider({ ...config, wagmiConfig }); + this.requireConnection(); } getWagmiConfig() { @@ -281,6 +276,15 @@ export class WalletConnectConnector extends FuelConnector { const unsub = this.web3Modal.subscribeEvents(async (event) => { switch (event.data.event) { case 'MODAL_OPEN': + if (this.config?.wagmiConfig) { + const account = getAccount(this.config.wagmiConfig); + if (account?.isConnected) { + this.web3Modal.close(); + resolve(true); + unsub(); + break; + } + } // Ensures that the WC Web3Modal config is applied over pre-existing states (e.g. Solan Connect Web3Modal) this.createModal(); break; From 5cdaaeeaceea2f897c4af066539d099bbf5521ca Mon Sep 17 00:00:00 2001 From: Arthur Geron <3487334+arthurgeron@users.noreply.github.com> Date: Thu, 25 Jul 2024 17:12:29 -0300 Subject: [PATCH 21/26] chore: enable test release --- .github/workflows/pr-release.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-release.yaml b/.github/workflows/pr-release.yaml index aae4c558..53aaf862 100644 --- a/.github/workflows/pr-release.yaml +++ b/.github/workflows/pr-release.yaml @@ -8,7 +8,7 @@ jobs: name: 'Release PR to npm' runs-on: buildjet-4vcpu-ubuntu-2204 # Comment if:false to enable release PR to npm - if: false + # if: false permissions: write-all steps: - uses: actions/checkout@v3 From ccb958d6cf9ae1cfe64eed8ed4d345f6a5196d11 Mon Sep 17 00:00:00 2001 From: Arthur Geron <3487334+arthurgeron@users.noreply.github.com> Date: Thu, 25 Jul 2024 17:24:27 -0300 Subject: [PATCH 22/26] chore: disable test release --- .github/workflows/pr-release.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-release.yaml b/.github/workflows/pr-release.yaml index 53aaf862..aae4c558 100644 --- a/.github/workflows/pr-release.yaml +++ b/.github/workflows/pr-release.yaml @@ -8,7 +8,7 @@ jobs: name: 'Release PR to npm' runs-on: buildjet-4vcpu-ubuntu-2204 # Comment if:false to enable release PR to npm - # if: false + if: false permissions: write-all steps: - uses: actions/checkout@v3 From ae2d2c741a88bb59e9c13e8788bb1dbcbf4fae21 Mon Sep 17 00:00:00 2001 From: Arthur Geron <3487334+arthurgeron@users.noreply.github.com> Date: Thu, 25 Jul 2024 19:55:07 -0300 Subject: [PATCH 23/26] feat: connect to persisted connection asap --- .../src/WalletConnectConnector.ts | 48 +++++++++++++------ 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/packages/walletconnect-connector/src/WalletConnectConnector.ts b/packages/walletconnect-connector/src/WalletConnectConnector.ts index 45f6b77d..1a83ebf4 100644 --- a/packages/walletconnect-connector/src/WalletConnectConnector.ts +++ b/packages/walletconnect-connector/src/WalletConnectConnector.ts @@ -1,6 +1,13 @@ import { hexToBytes } from '@ethereumjs/util'; import { hexlify, splitSignature } from '@ethersproject/bytes'; -import { disconnect, getAccount, reconnect, watchAccount } from '@wagmi/core'; +import { + type Config, + type GetAccountReturnType, + disconnect, + getAccount, + reconnect, + watchAccount, +} from '@wagmi/core'; import type { Web3Modal } from '@web3modal/wagmi'; import { type AbiMap, @@ -64,7 +71,14 @@ export class WalletConnectConnector extends FuelConnector { const wagmiConfig = config?.wagmiConfig ?? createWagmiConfig(); this.customPredicate = config.predicateConfig || null; this.configProvider({ ...config, wagmiConfig }); - this.requireConnection(); + this.loadPersistedConnection(); + } + + async loadPersistedConnection() { + if (!this.config?.wagmiConfig) return; + await this.config?.fuelProvider; + await this.requireConnection(); + await this.handleConnect(getAccount(this.config?.wagmiConfig)); } getWagmiConfig() { @@ -184,6 +198,22 @@ export class WalletConnectConnector extends FuelConnector { return accounts as Array; } + async handleConnect(account: NonNullable>) { + if (!account?.address) { + return; + } + await this.setupPredicate(); + this.emit(this.events.connection, true); + this.emit( + this.events.currentAccount, + this.predicateAccount?.getPredicateAddress(account.address), + ); + this.emit( + this.events.accounts, + this.predicateAccount?.getPredicateAccounts(this.evmAccounts()), + ); + } + setupWatchers() { if (!this.config?.wagmiConfig) { throw new Error('Wagmi config not found'); @@ -191,21 +221,9 @@ export class WalletConnectConnector extends FuelConnector { this._unsubs.push( watchAccount(this.config.wagmiConfig, { onChange: async (account) => { - const predicateAccount = await this.predicateAccount; - switch (account.status) { case 'connected': { - await this.setupPredicate(); - - this.emit(this.events.connection, true); - this.emit( - this.events.currentAccount, - predicateAccount?.getPredicateAddress(account.address), - ); - this.emit( - this.events.accounts, - predicateAccount?.getPredicateAccounts(this.evmAccounts()), - ); + await this.handleConnect(account); break; } case 'disconnected': { From 1c478320dedde5bc235f7635ec0fd87986524242 Mon Sep 17 00:00:00 2001 From: Arthur Geron <3487334+arthurgeron@users.noreply.github.com> Date: Thu, 25 Jul 2024 19:55:21 -0300 Subject: [PATCH 24/26] chore: enable test release --- .github/workflows/pr-release.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-release.yaml b/.github/workflows/pr-release.yaml index aae4c558..53aaf862 100644 --- a/.github/workflows/pr-release.yaml +++ b/.github/workflows/pr-release.yaml @@ -8,7 +8,7 @@ jobs: name: 'Release PR to npm' runs-on: buildjet-4vcpu-ubuntu-2204 # Comment if:false to enable release PR to npm - if: false + # if: false permissions: write-all steps: - uses: actions/checkout@v3 From aabaafeecaa73958d7176f833000ed8584779597 Mon Sep 17 00:00:00 2001 From: Arthur Geron <3487334+arthurgeron@users.noreply.github.com> Date: Thu, 25 Jul 2024 20:00:11 -0300 Subject: [PATCH 25/26] chore: disable test release --- .github/workflows/pr-release.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-release.yaml b/.github/workflows/pr-release.yaml index 53aaf862..aae4c558 100644 --- a/.github/workflows/pr-release.yaml +++ b/.github/workflows/pr-release.yaml @@ -8,7 +8,7 @@ jobs: name: 'Release PR to npm' runs-on: buildjet-4vcpu-ubuntu-2204 # Comment if:false to enable release PR to npm - # if: false + if: false permissions: write-all steps: - uses: actions/checkout@v3 From 4682a43cd386bbb22c7d6404ae6b7204fcd2e734 Mon Sep 17 00:00:00 2001 From: Arthur Geron <3487334+arthurgeron@users.noreply.github.com> Date: Fri, 26 Jul 2024 10:35:59 -0300 Subject: [PATCH 26/26] chore: update changeset --- .changeset/eight-bears-prove.md | 1 + 1 file changed, 1 insertion(+) diff --git a/.changeset/eight-bears-prove.md b/.changeset/eight-bears-prove.md index a9340d1f..d83ee8a7 100644 --- a/.changeset/eight-bears-prove.md +++ b/.changeset/eight-bears-prove.md @@ -5,5 +5,6 @@ - Add `currentEvmAccount` method to `WalletConnectConnector`, which will return the current ethereum account connected. - Fixed Wallet Connect Web3Modal instances conflicting and replacing Solana's - Fixed issue where Wallet Connect's Web3Modal would reference a different Wagmi config instance. +- WalletConnect connector now recovers the last active connection during initialization - Updated wagmi and @wagmi/core to 2.11.3 - Updated @wagmi/connectors to 5.0.26