Skip to content

Commit

Permalink
Fixed StaticJsonRpcProvider when auto-detecting network (#901).
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Jul 5, 2020
1 parent 2a73b6e commit 0fd9aa5
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions packages/providers/src.ts/url-json-rpc-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,26 @@ type getUrlFunc = (network: Network, apiKey: string) => string | ConnectionInfo;
// - locking up the UI
// - block skew warnings
// - wrong results
// If the network is not explicit (i.e. auto-detection is expected), the
// node MUST be running and available to respond to requests BEFORE this
// is instantiated.
export class StaticJsonRpcProvider extends JsonRpcProvider {
async detectNetwork(): Promise<Network> {
let network = this.network;
if (network == null) {
// After this call completes, network is defined
network = await super._ready();
network = await super.detectNetwork();

if (!network) {
logger.throwError("no network detected", Logger.errors.UNKNOWN_ERROR, { });
}

// If still not set, set it
if (this._network == null) {
// A static network does not support "any"
defineReadOnly(this, "_network", network);

this.emit("network", network, null);
}
}
return network;
}
Expand Down

0 comments on commit 0fd9aa5

Please sign in to comment.