Skip to content

Commit

Permalink
fix: connector is already connected
Browse files Browse the repository at this point in the history
  • Loading branch information
Gancho Radkov committed Apr 30, 2024
1 parent 396a993 commit 942b07c
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/wagmi/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export class Web3Modal extends Web3ModalScaffold {
if (siweConfig?.options?.enabled && typeof provider?.authenticate === 'function') {
const { SIWEController, getDidChainId, getDidAddress } = await import('@web3modal/siwe')
const siweParams = await siweConfig.getMessageParams()
// @ts-expect-error - setting requested chains beforehand avoids wagmi auto disconnecting the session when `connect` is called
// @ts-expect-error - setting requested chains beforehand avoids wagmi auto disconnecting the session when `connect` is called because it things chains are stale
await connector.setRequestedChainsIds(siweParams.chains)

const result = await provider.authenticate({
Expand Down Expand Up @@ -178,6 +178,12 @@ export class Web3Modal extends Web3ModalScaffold {
await SIWEController.signOut().catch(console.error)
throw error
}
/*
* Unassign the connector from the wagmiConfig and allow connect() to reassign it in the next step
* this avoids case where wagmi throws because the connector is already connected
* what we need connect() to do is to only setup internal event listeners
*/
this.wagmiConfig.state.current = ''
}
}
await connect(this.wagmiConfig, { connector, chainId })
Expand Down

0 comments on commit 942b07c

Please sign in to comment.