Fix JsonRpcProvider out-of-order super call (#822).
This commit is contained in:
parent
84d37fda83
commit
963197d70c
@ -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");
|
||||
let networkOrReady: Networkish | Promise<Network> = network;
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
if (networkOrReady == null) {
|
||||
networkOrReady = new Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
this.detectNetwork().then((network) => {
|
||||
resolve(network);
|
||||
}, (error) => {
|
||||
reject(error);
|
||||
});
|
||||
}, 0);
|
||||
});
|
||||
}
|
||||
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user