From 2f95f1aa30dad10cc6c13e5da3c1c5428c3c065e Mon Sep 17 00:00:00 2001 From: Gancho Radkov <43912948+ganchoradkov@users.noreply.github.com> Date: Tue, 23 Jul 2024 03:09:03 +0300 Subject: [PATCH] fix: gets chains from approved accounts (#2562) Co-authored-by: tomiir --- apps/laboratory/package.json | 4 +- packages/ethers/package.json | 1 + packages/ethers/src/client.ts | 5 +- packages/ethers5/package.json | 1 + packages/ethers5/src/client.ts | 5 +- packages/solana/package.json | 2 +- packages/wagmi/package.json | 1 + packages/wagmi/src/utils/helpers.ts | 5 +- pnpm-lock.yaml | 112 ++++------------------------ 9 files changed, 34 insertions(+), 102 deletions(-) diff --git a/apps/laboratory/package.json b/apps/laboratory/package.json index a890457b71..b1331b09db 100644 --- a/apps/laboratory/package.json +++ b/apps/laboratory/package.json @@ -43,8 +43,8 @@ "@tanstack/react-query": "5.24.8", "@wagmi/core": "2.11.6", "@wagmi/connectors": "5.0.21", - "@walletconnect/ethereum-provider": "2.13.0", - "@walletconnect/utils": "2.13.1", + "@walletconnect/ethereum-provider": "2.14.0", + "@walletconnect/utils": "2.14.0", "@web3modal/ethers": "workspace:*", "@web3modal/siwe": "workspace:*", "@web3modal/solana": "workspace:*", diff --git a/packages/ethers/package.json b/packages/ethers/package.json index e98c99b3b5..3a57522d0c 100644 --- a/packages/ethers/package.json +++ b/packages/ethers/package.json @@ -45,6 +45,7 @@ "dependencies": { "@coinbase/wallet-sdk": "4.0.3", "@walletconnect/ethereum-provider": "2.14.0", + "@walletconnect/utils": "2.14.0", "@web3modal/common": "workspace:*", "@web3modal/wallet": "workspace:*", "@web3modal/polyfills": "workspace:*", diff --git a/packages/ethers/src/client.ts b/packages/ethers/src/client.ts index 1a7e160ff6..4807e16da2 100644 --- a/packages/ethers/src/client.ts +++ b/packages/ethers/src/client.ts @@ -16,6 +16,7 @@ import { Web3ModalScaffold } from '@web3modal/scaffold' import { ConstantsUtil, PresetsUtil, HelpersUtil } from '@web3modal/scaffold-utils' import { ConstantsUtil as CommonConstantsUtil } from '@web3modal/common' import EthereumProvider, { OPTIONAL_METHODS } from '@walletconnect/ethereum-provider' +import { getChainsFromAccounts } from '@walletconnect/utils' import type { Web3ModalSIWEClient } from '@web3modal/siwe' import { ConstantsUtil as CommonConstants } from '@web3modal/common' import type { Chain as AvailableChain } from '@web3modal/common' @@ -171,7 +172,9 @@ export class Web3Modal extends Web3ModalScaffold { } const ns = provider.signer?.session?.namespaces const nsMethods = ns?.[ConstantsUtil.EIP155]?.methods - const nsChains = ns?.[ConstantsUtil.EIP155]?.chains + const nsChains = getChainsFromAccounts( + ns?.[ConstantsUtil.EIP155]?.accounts || [] + ) as CaipNetworkId[] const result = { supportsAllNetworks: nsMethods?.includes(ConstantsUtil.ADD_CHAIN_METHOD) ?? false, diff --git a/packages/ethers5/package.json b/packages/ethers5/package.json index c6d319bbcb..1769c2c5f4 100644 --- a/packages/ethers5/package.json +++ b/packages/ethers5/package.json @@ -45,6 +45,7 @@ "dependencies": { "@coinbase/wallet-sdk": "4.0.3", "@walletconnect/ethereum-provider": "2.14.0", + "@walletconnect/utils": "2.14.0", "@web3modal/common": "workspace:*", "@web3modal/polyfills": "workspace:*", "@web3modal/scaffold": "workspace:*", diff --git a/packages/ethers5/src/client.ts b/packages/ethers5/src/client.ts index 3e2f194868..18d8fdc12c 100644 --- a/packages/ethers5/src/client.ts +++ b/packages/ethers5/src/client.ts @@ -16,6 +16,7 @@ import type { Web3ModalSIWEClient } from '@web3modal/siwe' import { ConstantsUtil, PresetsUtil, HelpersUtil } from '@web3modal/scaffold-utils' import { ConstantsUtil as CommonConstantsUtil } from '@web3modal/common' import EthereumProvider, { OPTIONAL_METHODS } from '@walletconnect/ethereum-provider' +import { getChainsFromAccounts } from '@walletconnect/utils' import type { Address, Metadata, @@ -146,7 +147,9 @@ export class Web3Modal extends Web3ModalScaffold { } const ns = provider.signer?.session?.namespaces const nsMethods = ns?.[ConstantsUtil.EIP155]?.methods - const nsChains = ns?.[ConstantsUtil.EIP155]?.chains + const nsChains = getChainsFromAccounts( + ns?.[ConstantsUtil.EIP155]?.accounts || [] + ) as CaipNetworkId[] const result = { supportsAllNetworks: nsMethods?.includes(ConstantsUtil.ADD_CHAIN_METHOD) ?? false, diff --git a/packages/solana/package.json b/packages/solana/package.json index fd57d61ba1..10a41cab57 100644 --- a/packages/solana/package.json +++ b/packages/solana/package.json @@ -77,7 +77,7 @@ }, "devDependencies": { "@types/bn.js": "5.1.5", - "@walletconnect/types": "2.13.3" + "@walletconnect/types": "2.14.0" }, "peerDependencies": { "react": ">=17", diff --git a/packages/wagmi/package.json b/packages/wagmi/package.json index 7a4b3ad1b9..4bc680dcbf 100644 --- a/packages/wagmi/package.json +++ b/packages/wagmi/package.json @@ -52,6 +52,7 @@ }, "dependencies": { "@walletconnect/ethereum-provider": "2.14.0", + "@walletconnect/utils": "2.14.0", "@web3modal/polyfills": "workspace:*", "@web3modal/wallet": "workspace:*", "@web3modal/common": "workspace:*", diff --git a/packages/wagmi/src/utils/helpers.ts b/packages/wagmi/src/utils/helpers.ts index 11026d27d2..21437561d8 100644 --- a/packages/wagmi/src/utils/helpers.ts +++ b/packages/wagmi/src/utils/helpers.ts @@ -1,6 +1,7 @@ import { CoreHelperUtil } from '@web3modal/scaffold' import { ConstantsUtil, PresetsUtil } from '@web3modal/scaffold-utils' import { EthereumProvider } from '@walletconnect/ethereum-provider' +import { getChainsFromAccounts } from '@walletconnect/utils' import { fallback, http } from 'viem' import type { CaipNetwork, CaipNetworkId } from '@web3modal/scaffold' @@ -28,7 +29,9 @@ export async function getWalletConnectCaipNetworks(connector?: Connector) { > const ns = provider?.signer?.session?.namespaces const nsMethods = ns?.[ConstantsUtil.EIP155]?.methods - const nsChains = ns?.[ConstantsUtil.EIP155]?.chains as CaipNetworkId[] + const nsChains = getChainsFromAccounts( + ns?.[ConstantsUtil.EIP155]?.accounts || [] + ) as CaipNetworkId[] return { supportsAllNetworks: Boolean(nsMethods?.includes(ConstantsUtil.ADD_CHAIN_METHOD)), diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 47a0de7f7c..887a19b2a3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -206,11 +206,11 @@ importers: specifier: 2.11.6 version: 2.11.6(@tanstack/query-core@5.24.8)(@types/react@18.2.62)(bufferutil@4.0.8)(react@18.2.0)(typescript@5.3.3)(utf-8-validate@5.0.10)(viem@2.16.2(bufferutil@4.0.8)(typescript@5.3.3)(utf-8-validate@5.0.10)(zod@3.22.4))(zod@3.22.4) '@walletconnect/ethereum-provider': - specifier: 2.13.0 - version: 2.13.0(@types/react@18.2.62)(bufferutil@4.0.8)(react@18.2.0)(utf-8-validate@5.0.10) + specifier: 2.14.0 + version: 2.14.0(@types/react@18.2.62)(bufferutil@4.0.8)(react@18.2.0)(utf-8-validate@5.0.10) '@walletconnect/utils': - specifier: 2.13.1 - version: 2.13.1 + specifier: 2.14.0 + version: 2.14.0 '@web3modal/ethers': specifier: workspace:* version: link:../../packages/ethers @@ -614,6 +614,9 @@ importers: '@walletconnect/ethereum-provider': specifier: 2.14.0 version: 2.14.0(@types/react@18.2.62)(bufferutil@4.0.8)(react@18.2.0)(utf-8-validate@5.0.10) + '@walletconnect/utils': + specifier: 2.14.0 + version: 2.14.0 '@web3modal/common': specifier: workspace:* version: link:../common @@ -663,6 +666,9 @@ importers: '@walletconnect/ethereum-provider': specifier: 2.14.0 version: 2.14.0(@types/react@18.2.62)(bufferutil@4.0.8)(react@18.2.0)(utf-8-validate@5.0.10) + '@walletconnect/utils': + specifier: 2.14.0 + version: 2.14.0 '@web3modal/common': specifier: workspace:* version: link:../common @@ -927,8 +933,8 @@ importers: specifier: 5.1.5 version: 5.1.5 '@walletconnect/types': - specifier: 2.13.3 - version: 2.13.3 + specifier: 2.14.0 + version: 2.14.0 packages/ui: dependencies: @@ -963,6 +969,9 @@ importers: '@walletconnect/ethereum-provider': specifier: 2.14.0 version: 2.14.0(@types/react@18.2.62)(bufferutil@4.0.8)(react@18.2.0)(utf-8-validate@5.0.10) + '@walletconnect/utils': + specifier: 2.14.0 + version: 2.14.0 '@web3modal/common': specifier: workspace:* version: link:../common @@ -5745,12 +5754,6 @@ packages: '@walletconnect/types@2.13.0': resolution: {integrity: sha512-MWaVT0FkZwzYbD3tvk8F+2qpPlz1LUSWHuqbINUtMXnSzJtXN49Y99fR7FuBhNFtDalfuWsEK17GrNA+KnAsPQ==} - '@walletconnect/types@2.13.1': - resolution: {integrity: sha512-CIrdt66d38xdunGCy5peOOP17EQkCEGKweXc3+Gn/RWeSiRU35I7wjC/Bp4iWcgAQ6iBTZv4jGGST5XyrOp+Pg==} - - '@walletconnect/types@2.13.3': - resolution: {integrity: sha512-9UdtLoQqwGFfepCPprUAXeUbKg9zyDarPRmEJVco51OWXHCOpvRgroWk54fQHDhCUIfDELjObY6XNAzNrmNYUA==} - '@walletconnect/types@2.14.0': resolution: {integrity: sha512-vevMi4jZLJ55vLuFOicQFmBBbLyb+S0sZS4IsaBdZkQflfGIq34HkN13c/KPl4Ye0aoR4/cUcUSitmGIzEQM5g==} @@ -5766,9 +5769,6 @@ packages: '@walletconnect/utils@2.13.0': resolution: {integrity: sha512-q1eDCsRHj5iLe7fF8RroGoPZpdo2CYMZzQSrw1iqL+2+GOeqapxxuJ1vaJkmDUkwgklfB22ufqG6KQnz78sD4w==} - '@walletconnect/utils@2.13.1': - resolution: {integrity: sha512-EcooXXlqy5hk9hy/nK2wBF/qxe7HjH0K8ZHzjKkXRkwAE5pCvy0IGXIXWmUR9sw8LFJEqZyd8rZdWLKNUe8hqA==} - '@walletconnect/utils@2.14.0': resolution: {integrity: sha512-vRVomYQEtEAyCK2c5bzzEvtgxaGGITF8mWuIL+WYSAMyEJLY97mirP2urDucNwcUczwxUgI+no9RiNFbUHreQQ==} @@ -14413,7 +14413,7 @@ snapshots: '@solana/web3.js': 1.91.7(bufferutil@4.0.8)(utf-8-validate@5.0.10) '@walletconnect/qrcode-modal': 1.8.0 '@walletconnect/sign-client': 2.14.0(bufferutil@4.0.8)(utf-8-validate@5.0.10) - '@walletconnect/utils': 2.13.1 + '@walletconnect/utils': 2.14.0 bs58: 5.0.0 transitivePeerDependencies: - '@azure/app-configuration' @@ -18961,54 +18961,6 @@ snapshots: - ioredis - uWebSockets.js - '@walletconnect/types@2.13.1': - dependencies: - '@walletconnect/events': 1.0.1 - '@walletconnect/heartbeat': 1.2.2 - '@walletconnect/jsonrpc-types': 1.0.4 - '@walletconnect/keyvaluestorage': 1.1.1 - '@walletconnect/logger': 2.1.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' - - '@upstash/redis' - - '@vercel/kv' - - ioredis - - uWebSockets.js - - '@walletconnect/types@2.13.3': - dependencies: - '@walletconnect/events': 1.0.1 - '@walletconnect/heartbeat': 1.2.2 - '@walletconnect/jsonrpc-types': 1.0.4 - '@walletconnect/keyvaluestorage': 1.1.1 - '@walletconnect/logger': 2.1.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' - - '@upstash/redis' - - '@vercel/kv' - - ioredis - - uWebSockets.js - '@walletconnect/types@2.14.0': dependencies: '@walletconnect/events': 1.0.1 @@ -19157,38 +19109,6 @@ snapshots: - ioredis - uWebSockets.js - '@walletconnect/utils@2.13.1': - dependencies: - '@stablelib/chacha20poly1305': 1.0.1 - '@stablelib/hkdf': 1.0.1 - '@stablelib/random': 1.0.2 - '@stablelib/sha256': 1.0.1 - '@stablelib/x25519': 1.0.3 - '@walletconnect/relay-api': 1.0.10 - '@walletconnect/safe-json': 1.0.2 - '@walletconnect/time': 1.0.2 - '@walletconnect/types': 2.13.1 - '@walletconnect/window-getters': 1.0.1 - '@walletconnect/window-metadata': 1.0.1 - detect-browser: 5.3.0 - query-string: 7.1.3 - uint8arrays: 3.1.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' - - '@upstash/redis' - - '@vercel/kv' - - ioredis - - uWebSockets.js - '@walletconnect/utils@2.14.0': dependencies: '@stablelib/chacha20poly1305': 1.0.1