diff --git a/packages/core/src/connectors/injected.ts b/packages/core/src/connectors/injected.ts index 09160317..ab59f38a 100644 --- a/packages/core/src/connectors/injected.ts +++ b/packages/core/src/connectors/injected.ts @@ -123,6 +123,8 @@ export class InjectedConnector extends Connector { const account = this._wallet.account.address; const chainId = await this.chainId(); + this.emit("connect", { account, chainId }); + return { account, chainId, diff --git a/packages/core/src/hooks/useAccount.ts b/packages/core/src/hooks/useAccount.ts index b4e91cbb..b2817cb8 100644 --- a/packages/core/src/hooks/useAccount.ts +++ b/packages/core/src/hooks/useAccount.ts @@ -90,7 +90,13 @@ export function useAccount({ for (const connector of connectors) { if (!connector.available()) continue; - const connAccount = await connector.account(); + + // If the connector is not authorized, `.account()` will throw. + let connAccount; + try { + connAccount = await connector.account(); + } catch {} + if (connAccount && connAccount?.address === connectedAccount.address) { if (state.isDisconnected && onConnect !== undefined) { onConnect({ address: connectedAccount.address, connector });