Skip to content

Commit

Permalink
Merge branch 'main' into chore/add-cloud-auth-siwx-changeset
Browse files Browse the repository at this point in the history
  • Loading branch information
zoruka authored Dec 11, 2024
2 parents 3398cac + 3e9758e commit 2fe846f
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 10 deletions.
23 changes: 23 additions & 0 deletions .changeset/swift-ladybugs-smile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
'@reown/appkit': patch
'@apps/builder': patch
'@reown/appkit-adapter-ethers': patch
'@reown/appkit-adapter-ethers5': patch
'@reown/appkit-adapter-solana': patch
'@reown/appkit-adapter-wagmi': 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
---

Fix an issue where wagmi connectors are unable to restore a session
41 changes: 31 additions & 10 deletions packages/appkit/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -836,16 +836,37 @@ export class AppKit {
throw new Error('Adapter not found')
}

const res = await adapter.connect({
id,
info,
type,
provider,
chainId: caipNetwork?.id || this.getCaipNetwork()?.id,
rpcUrl:
caipNetwork?.rpcUrls?.default?.http?.[0] ||
this.getCaipNetwork()?.rpcUrls?.default?.http?.[0]
})
let res: AdapterBlueprint.ConnectResult | undefined = undefined
try {
res = await adapter.connect({
id,
info,
type,
provider,
chainId: caipNetwork?.id || this.getCaipNetwork()?.id,
rpcUrl:
caipNetwork?.rpcUrls?.default?.http?.[0] ||
this.getCaipNetwork()?.rpcUrls?.default?.http?.[0]
})
/**
* In some cases with wagmi connectors, the connector is already connected
* which throws an `Is already connected`error. In such cases, we need to reconnect
* to restore the session.
* We check if the reconnect method exists (which it does for wagmi connectors) and if so
* we attempt to reconnect and restore the session state.
*/
} catch (error) {
if (!adapter?.reconnect) {
throw new Error('Adapter is not able to connect')
}
await adapter.reconnect({
id,
info,
type,
provider,
chainId: this.getCaipNetwork()?.id
})
}

if (res) {
this.syncProvider({
Expand Down

0 comments on commit 2fe846f

Please sign in to comment.