Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

:fix rainbow wallet unable to reconnect issue #3439

Merged
merged 18 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error needed here?

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 Expand Up @@ -1773,7 +1794,7 @@
}

private createAuthProvider() {
const emailEnabled =

Check warning on line 1797 in packages/appkit/src/client.ts

View workflow job for this annotation

GitHub Actions / code_style (lint)

Variable name `emailEnabled` must have one of the following prefixes: is, has, can, should, will, did
this.options?.features?.email === undefined
? CoreConstantsUtil.DEFAULT_FEATURES.email
: this.options?.features?.email
Expand Down
Loading