From 1e29cc5fdf11648874053bc6067787b831c00e92 Mon Sep 17 00:00:00 2001 From: Felipe Mendes Date: Wed, 6 Nov 2024 06:30:46 -0300 Subject: [PATCH] fix: add deprecated caip network ids for solana chains as a workaround (#3205) --- packages/appkit/src/networks/solana/solana.ts | 3 ++- packages/appkit/src/networks/solana/solanaDevnet.ts | 3 ++- packages/appkit/src/tests/mocks/UniversalProvider.ts | 5 ++++- packages/appkit/src/tests/utils/HelpersUtil.test.ts | 5 ++++- packages/appkit/src/utils/HelpersUtil.ts | 12 ++++++++++++ 5 files changed, 24 insertions(+), 4 deletions(-) diff --git a/packages/appkit/src/networks/solana/solana.ts b/packages/appkit/src/networks/solana/solana.ts index a64538ca7b..4dc6ee7030 100644 --- a/packages/appkit/src/networks/solana/solana.ts +++ b/packages/appkit/src/networks/solana/solana.ts @@ -11,5 +11,6 @@ export const solana = defineChain({ blockExplorers: { default: { name: 'Solscan', url: 'https://solscan.io' } }, testnet: false, chainNamespace: 'solana', - caipNetworkId: 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp' + caipNetworkId: 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp', + deprecatedCaipNetworkId: 'solana:4sGjMW1sUnHzSxGspuhpqLDx6wiyjNtZ' }) diff --git a/packages/appkit/src/networks/solana/solanaDevnet.ts b/packages/appkit/src/networks/solana/solanaDevnet.ts index ae24a51503..b7d9fc9c03 100644 --- a/packages/appkit/src/networks/solana/solanaDevnet.ts +++ b/packages/appkit/src/networks/solana/solanaDevnet.ts @@ -11,5 +11,6 @@ export const solanaDevnet = defineChain({ blockExplorers: { default: { name: 'Solscan', url: 'https://solscan.io' } }, testnet: true, chainNamespace: 'solana', - caipNetworkId: 'solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1' + caipNetworkId: 'solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1', + deprecatedCaipNetworkId: 'solana:8E9rvCKLFQia2Y35HXjjpWzj8weVo44K' }) diff --git a/packages/appkit/src/tests/mocks/UniversalProvider.ts b/packages/appkit/src/tests/mocks/UniversalProvider.ts index 412dad1258..fca3d0b872 100644 --- a/packages/appkit/src/tests/mocks/UniversalProvider.ts +++ b/packages/appkit/src/tests/mocks/UniversalProvider.ts @@ -33,7 +33,10 @@ export const mockProvider = { } }, solana: { - chains: ['solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp'], + chains: [ + 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp', + 'solana:4sGjMW1sUnHzSxGspuhpqLDx6wiyjNtZ' + ], methods: [ 'solana_signMessage', 'solana_signTransaction', diff --git a/packages/appkit/src/tests/utils/HelpersUtil.test.ts b/packages/appkit/src/tests/utils/HelpersUtil.test.ts index acf0e7fe17..1677bd14d7 100644 --- a/packages/appkit/src/tests/utils/HelpersUtil.test.ts +++ b/packages/appkit/src/tests/utils/HelpersUtil.test.ts @@ -139,7 +139,10 @@ describe('WcHelpersUtil', () => { 'solana_signAndSendTransaction' ], events: ['accountsChanged', 'chainChanged'], - chains: ['solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp'], + chains: [ + 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp', + 'solana:4sGjMW1sUnHzSxGspuhpqLDx6wiyjNtZ' + ], rpcMap: { '5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp': 'https://api.mainnet-beta.solana.com' } diff --git a/packages/appkit/src/utils/HelpersUtil.ts b/packages/appkit/src/utils/HelpersUtil.ts index cd4ca34d1e..303c85c073 100644 --- a/packages/appkit/src/utils/HelpersUtil.ts +++ b/packages/appkit/src/utils/HelpersUtil.ts @@ -1,6 +1,7 @@ import type { NamespaceConfig, Namespace } from '@walletconnect/universal-provider' import type { CaipNetwork, CaipNetworkId, ChainNamespace } from '@reown/appkit-common' import type { SessionTypes } from '@walletconnect/types' +import { solana, solanaDevnet } from '../networks/index.js' export const WcHelpersUtil = { getMethodsByChainNamespace(chainNamespace: ChainNamespace): string[] { @@ -60,6 +61,17 @@ export const WcHelpersUtil = { namespace.chains.push(caipNetworkId) + // Workaround for wallets that only support deprecated Solana network ID + switch (caipNetworkId) { + case solana.caipNetworkId: + namespace.chains.push(solana.deprecatedCaipNetworkId) + break + case solanaDevnet.deprecatedCaipNetworkId: + namespace.chains.push(solanaDevnet.deprecatedCaipNetworkId) + break + default: + } + if (namespace?.rpcMap && rpcUrl) { namespace.rpcMap[id] = rpcUrl }