Skip to content

Commit

Permalink
Set sensible defaults for INFURA and AlchemyAPI getWebSocketProvider …
Browse files Browse the repository at this point in the history
…methods.
  • Loading branch information
ricmoo committed Jul 13, 2020
1 parent 619a888 commit e3d3e60
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/providers/src.ts/alchemy-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const defaultApiKey = "_gg7wSSi0KMBsdKnGVfHDueq6xMB9EkC"
export class AlchemyProvider extends UrlJsonRpcProvider {
readonly apiKey: string;

static getWebSocketProvider(network: Networkish, apiKey: any): WebSocketProvider {
static getWebSocketProvider(network?: Networkish, apiKey?: any): WebSocketProvider {
const provider = new AlchemyProvider(network, apiKey);

const url = provider.connection.url.replace(/^http/i, "ws")
Expand Down
15 changes: 7 additions & 8 deletions packages/providers/src.ts/infura-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class InfuraProvider extends UrlJsonRpcProvider {
readonly projectId: string;
readonly projectSecret: string;

static getWebSocketProvider(network: Networkish, apiKey: any): WebSocketProvider {
static getWebSocketProvider(network?: Networkish, apiKey?: any): WebSocketProvider {
const provider = new InfuraProvider(network, apiKey);
const connection = provider.connection;
if (connection.password) {
Expand All @@ -44,12 +44,11 @@ export class InfuraProvider extends UrlJsonRpcProvider {
apiKeyObj.projectId = apiKey;

} else if (apiKey.projectSecret != null) {
if (typeof(apiKey.projectId) !== "string") {
logger.throwArgumentError("projectSecret requires a projectId", "projectId", apiKey.projectId);
}
if (typeof(apiKey.projectSecret) !== "string") {
logger.throwArgumentError("invalid projectSecret", "projectSecret", "[REDACTED]");
}
logger.assertArgument((typeof(apiKey.projectId) === "string"),
"projectSecret requires a projectId", "projectId", apiKey.projectId);
logger.assertArgument((typeof(apiKey.projectSecret) === "string"),
"invalid projectSecret", "projectSecret", "[REDACTED]");

apiKeyObj.projectId = apiKey.projectId;
apiKeyObj.projectSecret = apiKey.projectSecret;

Expand All @@ -64,7 +63,7 @@ export class InfuraProvider extends UrlJsonRpcProvider {

static getUrl(network: Network, apiKey: any): string | ConnectionInfo {
let host: string = null;
switch(network.name) {
switch(network ? network.name: "unknown") {
case "homestead":
host = "mainnet.infura.io";
break;
Expand Down

0 comments on commit e3d3e60

Please sign in to comment.