From 942b07c57ce17c0ef3ffeb7417f25a8a5673f41e Mon Sep 17 00:00:00 2001 From: Gancho Radkov Date: Tue, 30 Apr 2024 09:50:46 +0300 Subject: [PATCH] fix: connector is already connected --- packages/wagmi/src/client.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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 })