Skip to content

Commit

Permalink
Not show wallet permissions dialog if the client is connected. (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
nesitor authored May 4, 2023
1 parent 618bc6f commit f1194af
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/accounts/providers/JsonRPCWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ export class JsonRPCWallet extends BaseProviderWallet {

public async connect(): Promise<void> {
try {
await this.provider.send("wallet_requestPermissions", [{ eth_accounts: {} }]);
const connected = await this.isConnected();
if (!connected) {
await this.provider.send("wallet_requestPermissions", [{ eth_accounts: {} }]);
}
this.signer = this.provider.getSigner();
this.address = await this.signer.getAddress();
} catch (err: unknown) {
Expand Down Expand Up @@ -145,4 +148,9 @@ export class JsonRPCWallet extends BaseProviderWallet {
public isMetamask(): boolean {
return !!this.provider?.provider?.isMetaMask;
}

public async isConnected(): Promise<boolean> {
const accounts = await this.provider.send("eth_accounts", []);
return accounts.length !== 0;
}
}

0 comments on commit f1194af

Please sign in to comment.