Skip to content

Commit

Permalink
add getSigner back to browser provider
Browse files Browse the repository at this point in the history
  • Loading branch information
robertlincecum committed Jun 17, 2024
1 parent 4ef9fc2 commit 4a6b6bf
Showing 1 changed file with 36 additions and 5 deletions.
41 changes: 36 additions & 5 deletions src/providers/provider-browser.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { assertArgument } from '../utils/index.js';

import { JsonRpcApiProvider } from './provider-jsonrpc.js';
import { JsonRpcApiProvider, JsonRpcSigner } from './provider-jsonrpc.js';

import type {
JsonRpcError, JsonRpcPayload, JsonRpcResult
} from "./provider-jsonrpc.js";
import type { Networkish } from "./network.js";
import type { JsonRpcError, JsonRpcPayload, JsonRpcResult } from './provider-jsonrpc.js';
import type { Networkish } from './network.js';

/**
* The interface to an [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193) provider, which is a standard used by most
Expand Down Expand Up @@ -73,6 +71,20 @@ export class BrowserProvider extends JsonRpcApiProvider {
};
}

async hasSigner(address: number | string): Promise<boolean> {
if (address == null) {
address = 0;
}

const accounts = await this.send('quai_accounts', []);
if (typeof address === 'number') {
return accounts.length > address;
}

address = address.toLowerCase();
return accounts.filter((a: string) => a.toLowerCase() === address).length !== 0;
}

async send(method: string, params: Array<any> | Record<string, any>): Promise<any> {
await this._start();

Expand Down Expand Up @@ -112,6 +124,25 @@ export class BrowserProvider extends JsonRpcApiProvider {
return super.getRpcError(payload, error);
}

async getSigner(address?: number | string): Promise<JsonRpcSigner> {
if (address == null) {
address = 0;
}

if (!(await this.hasSigner(address))) {
try {
//const resp =
await this.#request('quai_requestAccounts', []);
//console.log("RESP", resp);
} catch (error: any) {
const payload = error.payload;
throw this.getRpcError(payload, { id: payload.id, error });
}
}

return await super.getSigner(address);
}

/**
* Resolves to `true` if the provider manages the `address`.
*
Expand Down

0 comments on commit 4a6b6bf

Please sign in to comment.