Skip to content

Commit

Permalink
Fix JsonRpcProvider out-of-order super call (#822).
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed May 8, 2020
1 parent 84d37fd commit 963197d
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions packages/providers/src.ts/json-rpc-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,34 +219,32 @@ export class JsonRpcProvider extends BaseProvider {
constructor(url?: ConnectionInfo | string, network?: Networkish) {
logger.checkNew(new.target, JsonRpcProvider);

const getNetwork = getStatic<(network: Networkish) => Network>(new.target, "getNetwork");

// One parameter, but it is a network name, so swap it with the URL
if (typeof(url) === "string") {
if (network === null) {
const checkNetwork = getNetwork(url);
network = checkNetwork;
url = null;
}
let networkOrReady: Networkish | Promise<Network> = network;

// The network is unknown, query the JSON-RPC for it
if (networkOrReady == null) {
networkOrReady = new Promise((resolve, reject) => {
setTimeout(() => {
this.detectNetwork().then((network) => {
resolve(network);
}, (error) => {
reject(error);
});
}, 0);
});
}

if (network) {
// The network has been specified explicitly, we can use it
super(network);
} else {
// The network is unknown, query the JSON-RPC for it
super(this.detectNetwork());
}
super(networkOrReady);

// Default URL
if (!url) { url = getStatic<() => string>(this.constructor, "defaultUrl")(); }

if (typeof(url) === "string") {
this.connection = Object.freeze({
defineReadOnly(this, "connection",Object.freeze({
url: url
});
}));
} else {
this.connection = Object.freeze(shallowCopy(url));
defineReadOnly(this, "connection", Object.freeze(shallowCopy(url)));
}

this._nextId = 42;
Expand Down

0 comments on commit 963197d

Please sign in to comment.