Skip to content

Commit 33bb0bf

Browse files
committed
Added Options for BrowserProvider (#4707).
1 parent d8cb849 commit 33bb0bf

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

src.ts/ethers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ export type { TypedDataDomain, TypedDataField } from "./hash/index.js";
164164
export type {
165165
Provider, Signer,
166166

167-
AbstractProviderOptions, FallbackProviderOptions,
167+
AbstractProviderOptions, BrowserProviderOptions, FallbackProviderOptions,
168168

169169
AbstractProviderPlugin, BlockParams, BlockTag, ContractRunner, DebugEventBrowserProvider,
170170
Eip1193Provider, EventFilter, Filter, FilterByBlockHash, GasCostParameters,

src.ts/providers/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export type {
114114
} from "./provider.js";
115115

116116
export type {
117-
DebugEventBrowserProvider, Eip1193Provider
117+
BrowserProviderOptions, DebugEventBrowserProvider, Eip1193Provider
118118
} from "./provider-browser.js";
119119

120120
export type { FallbackProviderOptions } from "./provider-fallback.js";

src.ts/providers/provider-browser.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import { assertArgument } from "../utils/index.js";
33
import { JsonRpcApiPollingProvider } from "./provider-jsonrpc.js";
44

55
import type {
6+
JsonRpcApiProviderOptions,
67
JsonRpcError, JsonRpcPayload, JsonRpcResult,
78
JsonRpcSigner
89
} from "./provider-jsonrpc.js";
9-
import type { Networkish } from "./network.js";
10+
import type { Network, Networkish } from "./network.js";
1011

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

39+
export type BrowserProviderOptions = {
40+
polling?: boolean;
41+
staticNetwork?: null | boolean | Network;
42+
43+
cacheTimeout?: number;
44+
pollingInterval?: number;
45+
};
3846

3947
/**
4048
* A **BrowserProvider** is intended to wrap an injected provider which
@@ -48,10 +56,15 @@ export class BrowserProvider extends JsonRpcApiPollingProvider {
4856
* Connnect to the %%ethereum%% provider, optionally forcing the
4957
* %%network%%.
5058
*/
51-
constructor(ethereum: Eip1193Provider, network?: Networkish) {
59+
constructor(ethereum: Eip1193Provider, network?: Networkish, _options?: BrowserProviderOptions) {
60+
// Copy the options
61+
const options: JsonRpcApiProviderOptions = Object.assign({ },
62+
((_options != null) ? _options: { }),
63+
{ batchMaxCount: 1 });
64+
5265
assertArgument(ethereum && ethereum.request, "invalid EIP-1193 provider", "ethereum", ethereum);
5366

54-
super(network, { batchMaxCount: 1 });
67+
super(network, options);
5568

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

0 commit comments

Comments
 (0)