Skip to content

Commit

Permalink
feat: add skip auto reconnect (#403)
Browse files Browse the repository at this point in the history
  • Loading branch information
LuizAsFight authored Oct 15, 2024
1 parent 9d5e004 commit 02574b4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changeset/strong-bugs-remain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@fuel-connectors/walletconnect-connector": minor
"@fuels/connectors": minor
---

feat: added `skipAutoReconnect` to avoid WalletConnectConnector reconnecting automatically over the Wagmi already reconnected
3 changes: 3 additions & 0 deletions packages/connectors/src/defaultConnectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type DefaultConnectors = {
wcProjectId?: string;
burnerWalletConfig?: BurnerWalletConfig;
ethWagmiConfig?: Config;
ethSkipAutoReconnect?: boolean;
solanaConfig?: ProviderType;
chainId?: number;
fuelProvider?: FuelProvider | Promise<FuelProvider>;
Expand All @@ -28,6 +29,7 @@ export function defaultConnectors({
wcProjectId,
burnerWalletConfig,
ethWagmiConfig,
ethSkipAutoReconnect,
solanaConfig: _solanaConfig,
chainId,
fuelProvider,
Expand All @@ -41,6 +43,7 @@ export function defaultConnectors({
wagmiConfig: ethWagmiConfig,
chainId,
fuelProvider,
skipAutoReconnect: ethSkipAutoReconnect,
}),
new SolanaConnector({
projectId: wcProjectId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,11 @@ export class WalletConnectConnector extends PredicateConnector {
protected async requireConnection() {
const wagmiConfig = this.getWagmiConfig();
if (!this.web3Modal) this.createModal();
if (!wagmiConfig) return;

const { state } = wagmiConfig;
if (state.status === 'disconnected' && state.connections.size > 0) {
if (this.config.skipAutoReconnect || !wagmiConfig) return;

const { status, connections } = wagmiConfig.state;
if (status === 'disconnected' && connections.size > 0) {
await reconnect(wagmiConfig);
}
}
Expand Down
2 changes: 2 additions & 0 deletions packages/walletconnect-connector/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ export type WalletConnectConfig = {
predicateConfig?: PredicateConfig;
storage?: StorageAbstract;
chainId?: number;
// if the dapp already has wagmi from eth connectors, it's better to skip auto reconnection as it can lead to session loss when refreshing the page
skipAutoReconnect?: boolean;
};

0 comments on commit 02574b4

Please sign in to comment.