Skip to content

Commit

Permalink
fix: add deprecated caip network ids for solana chains as a workaround (
Browse files Browse the repository at this point in the history
  • Loading branch information
zoruka authored Nov 6, 2024
1 parent 7052435 commit 1e29cc5
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
3 changes: 2 additions & 1 deletion packages/appkit/src/networks/solana/solana.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
})
3 changes: 2 additions & 1 deletion packages/appkit/src/networks/solana/solanaDevnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
})
5 changes: 4 additions & 1 deletion packages/appkit/src/tests/mocks/UniversalProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ export const mockProvider = {
}
},
solana: {
chains: ['solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp'],
chains: [
'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp',
'solana:4sGjMW1sUnHzSxGspuhpqLDx6wiyjNtZ'
],
methods: [
'solana_signMessage',
'solana_signTransaction',
Expand Down
5 changes: 4 additions & 1 deletion packages/appkit/src/tests/utils/HelpersUtil.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand Down
12 changes: 12 additions & 0 deletions packages/appkit/src/utils/HelpersUtil.ts
Original file line number Diff line number Diff line change
@@ -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[] {
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 1e29cc5

Please sign in to comment.