From 33bb0bf30e1e6a699c24415a1edf0fa4ed28b6aa Mon Sep 17 00:00:00 2001 From: Richard Moore Date: Mon, 3 Jun 2024 16:29:55 -0400 Subject: [PATCH] Added Options for BrowserProvider (#4707). --- src.ts/ethers.ts | 2 +- src.ts/providers/index.ts | 2 +- src.ts/providers/provider-browser.ts | 19 ++++++++++++++++--- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src.ts/ethers.ts b/src.ts/ethers.ts index a95fe94dbf..c989eeb812 100644 --- a/src.ts/ethers.ts +++ b/src.ts/ethers.ts @@ -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, diff --git a/src.ts/providers/index.ts b/src.ts/providers/index.ts index c0a33dc8aa..47316dd2a1 100644 --- a/src.ts/providers/index.ts +++ b/src.ts/providers/index.ts @@ -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"; diff --git a/src.ts/providers/provider-browser.ts b/src.ts/providers/provider-browser.ts index 8b45957625..9db47045ae 100644 --- a/src.ts/providers/provider-browser.ts +++ b/src.ts/providers/provider-browser.ts @@ -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 @@ -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 @@ -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 | Record) => { const payload = { method, params };