Skip to content

Commit

Permalink
Fixed FallbackProvider ESM super-this out-of-order issue (#822).
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed May 12, 2020
1 parent fdf2253 commit fde102b
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions packages/providers/src.ts/fallback-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,14 +424,20 @@ export class FallbackProvider extends BaseProvider {
logger.throwArgumentError("quorum will always fail; larger than total weight", "quorum", quorum);
}

// All networks are ready, we can know the network for certain
const network = checkNetworks(providerConfigs.map((c) => (<any>(c.provider)).network));
if (network) {
super(network);
} else {
super(this.detectNetwork());
// Are all providers' networks are known
let networkOrReady: Network | Promise<Network> = checkNetworks(providerConfigs.map((c) => (<any>(c.provider)).network));

// Not all networks are known; we must stall
if (networkOrReady == null) {
networkOrReady = new Promise((resolve, reject) => {
setTimeout(() => {
this.detectNetwork().then(resolve, reject);
}, 0);
});
}

super(networkOrReady);

// Preserve a copy, so we do not get mutated
defineReadOnly(this, "providerConfigs", Object.freeze(providerConfigs));
defineReadOnly(this, "quorum", quorum);
Expand Down

0 comments on commit fde102b

Please sign in to comment.