Skip to content

Commit

Permalink
fix: wagmi wc connections default network mismatch (#3868)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomiir authored Feb 14, 2025
1 parent faf3f25 commit 8e11300
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
23 changes: 23 additions & 0 deletions .changeset/swift-coins-hang.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
'@reown/appkit-adapter-wagmi': patch
'@reown/appkit-adapter-bitcoin': patch
'@reown/appkit-adapter-ethers': patch
'@reown/appkit-adapter-ethers5': patch
'@reown/appkit-adapter-solana': patch
'@reown/appkit': patch
'@reown/appkit-utils': patch
'@reown/appkit-cdn': patch
'@reown/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
'@reown/appkit-wallet-button': patch
---

Sets default chain to current appkit chain on WC connections
5 changes: 2 additions & 3 deletions packages/adapters/wagmi/src/connectors/UniversalConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,9 @@ export function walletConnect(
if (provider.session && isChainsStale) {
await provider.disconnect()
}

// If there isn't an active session or chains are stale, connect.
if (!provider.session || isChainsStale) {
const namespaces = WcHelpersUtil.createNamespaces(caipNetworks)

await provider.connect({
optionalNamespaces: namespaces,
...('pairingTopic' in rest ? { pairingTopic: rest.pairingTopic } : {})
Expand Down Expand Up @@ -150,6 +148,8 @@ export function walletConnect(
provider.on('session_delete', sessionDelete)
}

provider.setDefaultChain(`eip155:${currentChainId}`)

return { accounts, chainId: currentChainId }
} catch (error) {
if (
Expand Down Expand Up @@ -232,7 +232,6 @@ export function walletConnect(
},
async getChainId() {
const chainId = appKit.getCaipNetwork()?.id

if (chainId) {
return chainId as number
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ describe('UniversalConnector', () => {
})
expect(mockProvider.on).toHaveBeenCalled()
expect(mockProvider.session.namespaces.eip155.accounts).toEqual([mockCaipAddress])
expect(mockProvider.setDefaultChain).toHaveBeenCalledWith(`eip155:${expectedChainId}`)
})

it('should handle user rejection', async () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/adapters/wagmi/src/tests/mocks/AppKit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export const mockProvider = {
events: {
setMaxListeners: vi.fn()
},
session: mockSession
session: mockSession,
setDefaultChain: vi.fn()
}

export const mockAppKit = {
Expand Down

0 comments on commit 8e11300

Please sign in to comment.