Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add JsonRpcSigner code back #205

Merged
merged 2 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions src/providers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,14 @@ export { AbstractProvider, UnmanagedSubscriber } from './abstract-provider.js';

export { Network } from './network.js';

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

export { BrowserProvider } from './provider-browser.js';

export { SocketProvider } from './provider-socket.js';
export { WebSocketProvider } from './provider-websocket.js';

export {
Block,
FeeData,
Log,
TransactionReceipt,
TransactionResponse,
copyRequest
} from './provider.js';
export { Block, FeeData, Log, TransactionReceipt, TransactionResponse, copyRequest } from './provider.js';

export {
SocketSubscriber,
Expand Down
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
Loading
Loading