Skip to content

Commit

Permalink
Added Options for BrowserProvider (#4707).
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Jun 3, 2024
1 parent d8cb849 commit 33bb0bf
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src.ts/ethers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export type { TypedDataDomain, TypedDataField } from "./hash/index.js";
export type {
Provider, Signer,

AbstractProviderOptions, FallbackProviderOptions,
AbstractProviderOptions, BrowserProviderOptions, FallbackProviderOptions,

AbstractProviderPlugin, BlockParams, BlockTag, ContractRunner, DebugEventBrowserProvider,
Eip1193Provider, EventFilter, Filter, FilterByBlockHash, GasCostParameters,
Expand Down
2 changes: 1 addition & 1 deletion src.ts/providers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export type {
} from "./provider.js";

export type {
DebugEventBrowserProvider, Eip1193Provider
BrowserProviderOptions, DebugEventBrowserProvider, Eip1193Provider
} from "./provider-browser.js";

export type { FallbackProviderOptions } from "./provider-fallback.js";
Expand Down
19 changes: 16 additions & 3 deletions src.ts/providers/provider-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import { assertArgument } from "../utils/index.js";
import { JsonRpcApiPollingProvider } from "./provider-jsonrpc.js";

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

/**
* The interface to an [[link-eip-1193]] provider, which is a standard
Expand Down Expand Up @@ -35,6 +36,13 @@ export type DebugEventBrowserProvider = {
error: Error
};

export type BrowserProviderOptions = {
polling?: boolean;
staticNetwork?: null | boolean | Network;

cacheTimeout?: number;
pollingInterval?: number;
};

/**
* A **BrowserProvider** is intended to wrap an injected provider which
Expand All @@ -48,10 +56,15 @@ export class BrowserProvider extends JsonRpcApiPollingProvider {
* Connnect to the %%ethereum%% provider, optionally forcing the
* %%network%%.
*/
constructor(ethereum: Eip1193Provider, network?: Networkish) {
constructor(ethereum: Eip1193Provider, network?: Networkish, _options?: BrowserProviderOptions) {
// Copy the options
const options: JsonRpcApiProviderOptions = Object.assign({ },
((_options != null) ? _options: { }),
{ batchMaxCount: 1 });

assertArgument(ethereum && ethereum.request, "invalid EIP-1193 provider", "ethereum", ethereum);

super(network, { batchMaxCount: 1 });
super(network, options);

this.#request = async (method: string, params: Array<any> | Record<string, any>) => {
const payload = { method, params };
Expand Down

0 comments on commit 33bb0bf

Please sign in to comment.