Skip to content

Commit

Permalink
fix: Connection not set on WC connections (#3417)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomiir authored Dec 10, 2024
1 parent 82b3476 commit fc59868
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 5 deletions.
21 changes: 21 additions & 0 deletions .changeset/honest-insects-argue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
'@reown/appkit-adapter-solana': patch
'@reown/appkit-adapter-ethers': patch
'@reown/appkit-adapter-ethers5': patch
'@reown/appkit-adapter-wagmi': patch
'@reown/appkit': patch
'@reown/appkit-utils': patch
'@reown/appkit-cdn': patch
'appkit-cli': patch
'@reown/appkit-common': patch
'@reown/appkit-core': patch
'@reown/appkit-experimental': patch
'@reown/appkit-polyfills': patch
'@reown/appkit-scaffold-ui': patch
'@reown/appkit-siwe': patch
'@reown/appkit-siwx': patch
'@reown/appkit-ui': patch
'@reown/appkit-wallet': patch
---

Fixes issue where Solana Connection was not being set on WC Relay wallets, causing transactions to fail.
8 changes: 5 additions & 3 deletions packages/adapters/solana/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,12 +394,14 @@ export class SolanaAdapter extends AdapterBlueprint {
)
}

provider.on('display_uri', (uri: string) => {
onUri(uri)
})
provider.on('display_uri', onUri)

const namespaces = WcHelpersUtil.createNamespaces(this.caipNetworks)
await provider.connect({ optionalNamespaces: namespaces })
const rpcUrl = this.caipNetworks[0]?.rpcUrls?.default?.http?.[0] as string
const connection = new Connection(rpcUrl, 'confirmed')

SolStoreUtil.setConnection(connection)
}

public async disconnect(params: AdapterBlueprint.DisconnectParams): Promise<void> {
Expand Down
30 changes: 28 additions & 2 deletions packages/adapters/solana/src/tests/client.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { describe, it, expect, beforeEach, vi } from 'vitest'
import { SolanaAdapter } from '../client'
import { CaipNetworksUtil } from '@reown/appkit-utils'
import { solana } from '@reown/appkit/networks'
import type { Provider } from '@reown/appkit-core'
import type { ConnectorType, Provider } from '@reown/appkit-core'
import type { W3mFrameProvider } from '@reown/appkit-wallet'
import UniversalProvider from '@walletconnect/universal-provider'
import type { ChainNamespace } from '@reown/appkit-common'
import { SolanaAdapter } from '../client'
import { SolStoreUtil } from '../utils/SolanaStoreUtil'
import type { WalletStandardProvider } from '../providers/WalletStandardProvider'

Expand Down Expand Up @@ -61,12 +62,25 @@ const mockCaipNetworks = CaipNetworksUtil.extendCaipNetworks(mockNetworks, {
customNetworkImageUrls: {}
})

const mockWalletConnectConnector = {
id: 'walletconnect',
provider: mockWalletConnectProvider,
type: 'WALLET_CONNECT' as ConnectorType,
chains: mockNetworks,
chain: 'solana' as ChainNamespace
}

describe('SolanaAdapter', () => {
let adapter: SolanaAdapter

beforeEach(() => {
vi.clearAllMocks()
adapter = new SolanaAdapter()
adapter.construct({
networks: mockNetworks,
projectId: 'test-project-id',
namespace: 'solana'
})
})

describe('SolanaAdapter - constructor', () => {
Expand Down Expand Up @@ -155,6 +169,18 @@ describe('SolanaAdapter', () => {
})
})

describe('SolanaAdapter - connectWalletConnect', () => {
it('should connect WalletConnect provider', async () => {
const onUri = vi.fn()
vi.mocked(adapter['connectors']).push(mockWalletConnectConnector)
await adapter.connectWalletConnect(onUri)

expect(mockWalletConnectProvider.connect).toHaveBeenCalled()
expect(mockWalletConnectProvider.on).toHaveBeenCalledWith('display_uri', onUri)
expect(SolStoreUtil.setConnection).toHaveBeenCalled()
})
})

describe('SolanaAdapter - getWalletConnectProvider', () => {
it('should return WalletConnect provider', () => {
const result = adapter.getWalletConnectProvider({
Expand Down

0 comments on commit fc59868

Please sign in to comment.