diff --git a/packages/wagmi/src/client.ts b/packages/wagmi/src/client.ts index 10c04bf364..83985123e1 100644 --- a/packages/wagmi/src/client.ts +++ b/packages/wagmi/src/client.ts @@ -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({ @@ -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 })