Skip to content

Commit

Permalink
core: fix account detection when wallet not authorized
Browse files Browse the repository at this point in the history
**Summary**
When the wallet is not authorized, the `account` method throws.
This commit handles that case.
  • Loading branch information
fracek committed Oct 30, 2023
1 parent 404747a commit cc5e5c9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/core/src/connectors/injected.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 7 additions & 1 deletion packages/core/src/hooks/useAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down

0 comments on commit cc5e5c9

Please sign in to comment.