From d22a649ae15f43840163f561ef0f0276c62f6c89 Mon Sep 17 00:00:00 2001 From: Jonas Daniels Date: Thu, 2 Jun 2022 12:40:21 -0700 Subject: [PATCH] handle ws rpc urls & alias matic -> polygon mapping --- etc/sdk.api.md | 2 +- src/constants/urls.ts | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/etc/sdk.api.md b/etc/sdk.api.md index 50e5571ed..598b02470 100644 --- a/etc/sdk.api.md +++ b/etc/sdk.api.md @@ -208,7 +208,7 @@ export const ChainlinkVrf: Record; // Warning: (ae-internal-missing-underscore) The name "ChainOrRpc" should be prefixed with an underscore because the declaration is marked as @internal // // @internal (undocumented) -export type ChainOrRpc = "mumbai" | "polygon" | "rinkeby" | "goerli" | "mainnet" | "fantom" | "avalanche" | (string & {}); +export type ChainOrRpc = "mumbai" | "polygon" | "matic" | "rinkeby" | "goerli" | "mainnet" | "ethereum" | "fantom" | "avalanche" | (string & {}); // Warning: (ae-internal-missing-underscore) The name "CidWithFileName" should be prefixed with an underscore because the declaration is marked as @internal // diff --git a/src/constants/urls.ts b/src/constants/urls.ts index 77e651563..4f155ce7d 100644 --- a/src/constants/urls.ts +++ b/src/constants/urls.ts @@ -27,9 +27,13 @@ export const PINATA_IPFS_URL = `https://api.pinata.cloud/pinning/pinFileToIPFS`; export type ChainOrRpc = | "mumbai" | "polygon" + // common alias for `polygon` + | "matic" | "rinkeby" | "goerli" | "mainnet" + // common alias for `mainnet` + | "ethereum" | "fantom" | "avalanche" // ideally we could use `https://${string}` notation here, but doing that causes anything that is a generic string to throw a type error => not worth the hassle for now @@ -58,15 +62,17 @@ export function getProviderForNetwork(network: ChainOrRpc | SignerOrProvider) { case "goerli": return `https://eth-goerli.g.alchemy.com/v2/${DEFAULT_API_KEY}`; case "polygon": + case "matic": return `https://polygon-mainnet.g.alchemy.com/v2/${DEFAULT_API_KEY}`; - case "mainnet" || "ethereum": + case "mainnet": + case "ethereum": return `https://eth-mainnet.g.alchemy.com/v2/${DEFAULT_API_KEY}`; case "fantom": return "https://rpc.ftm.tools"; case "avalanche": return "https://rpc.ankr.com/avalanche"; default: - if (network.startsWith("http")) { + if (network.startsWith("http") || network.startsWith("ws")) { return network; } else { throw new Error(`Unrecognized chain name or RPC url: ${network}`);