@web3-react/network
Advanced tools
Comparing version 8.0.24-beta.0 to 8.0.25-beta.0
@@ -1,2 +0,2 @@ | ||
import type { FallbackProvider, JsonRpcProvider } from '@ethersproject/providers'; | ||
import type { JsonRpcProvider } from '@ethersproject/providers'; | ||
import type { ConnectionInfo } from '@ethersproject/web'; | ||
@@ -10,3 +10,4 @@ import type { Actions } from '@web3-react/types'; | ||
/** {@inheritdoc Connector.customProvider} */ | ||
customProvider: JsonRpcProvider | FallbackProvider | undefined; | ||
customProvider: JsonRpcProvider | undefined; | ||
private readonly timeout?; | ||
private readonly urlMap; | ||
@@ -19,10 +20,13 @@ private readonly defaultChainId; | ||
* @param defaultChainId - The chainId to connect to if connectEagerly is true. | ||
* @param timeout - Timeout, in milliseconds, after which to treat network calls as failed when selecting | ||
* online providers. | ||
*/ | ||
constructor({ actions, urlMap, connectEagerly, defaultChainId, }: { | ||
constructor({ actions, urlMap, connectEagerly, defaultChainId, timeout, }: { | ||
actions: Actions; | ||
urlMap: { | ||
[chainId: number]: url | url[] | JsonRpcProvider | JsonRpcProvider[] | FallbackProvider; | ||
[chainId: number]: url | url[] | JsonRpcProvider | JsonRpcProvider[]; | ||
}; | ||
connectEagerly?: boolean; | ||
defaultChainId?: number; | ||
timeout?: number; | ||
}); | ||
@@ -29,0 +33,0 @@ private isomorphicInitialize; |
@@ -37,12 +37,9 @@ "use strict"; | ||
const types_1 = require("@web3-react/types"); | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const utils_1 = require("./utils"); | ||
function isUrl(url) { | ||
return typeof url === 'string' || ('url' in url && !('connection' in url) && !('quorum' in url)); | ||
return typeof url === 'string' || ('url' in url && !('connection' in url)); | ||
} | ||
function isJsonRpcProvider(url) { | ||
return !isUrl(url) && 'connection' in url && !('quorum' in url); | ||
return !isUrl(url); | ||
} | ||
function isFallbackProvider(url) { | ||
return !isUrl(url) && 'quorum' in url && !('connection' in url); | ||
} | ||
class Network extends types_1.Connector { | ||
@@ -53,4 +50,6 @@ /** | ||
* @param defaultChainId - The chainId to connect to if connectEagerly is true. | ||
* @param timeout - Timeout, in milliseconds, after which to treat network calls as failed when selecting | ||
* online providers. | ||
*/ | ||
constructor({ actions, urlMap, connectEagerly = false, defaultChainId = Number(Object.keys(urlMap)[0]), }) { | ||
constructor({ actions, urlMap, connectEagerly = false, defaultChainId = Number(Object.keys(urlMap)[0]), timeout, }) { | ||
super(actions); | ||
@@ -67,3 +66,4 @@ this.providerCache = {}; | ||
else { | ||
accumulator[Number(chainId)] = isFallbackProvider(urls) ? urls : isJsonRpcProvider(urls) ? [urls] : [urls]; | ||
// thie ternary just makes typescript happy, since it can't infer that the array has elements of the same type | ||
accumulator[Number(chainId)] = isJsonRpcProvider(urls) ? [urls] : [urls]; | ||
} | ||
@@ -73,2 +73,3 @@ return accumulator; | ||
this.defaultChainId = defaultChainId; | ||
this.timeout = timeout; | ||
if (connectEagerly) | ||
@@ -82,18 +83,10 @@ void this.activate(); | ||
const urls = this.urlMap[chainId]; | ||
if (Array.isArray(urls)) { | ||
// early return if we have a single jsonrpc provider already | ||
if (urls.length === 1 && isJsonRpcProvider(urls[0])) | ||
return (this.providerCache[chainId] = Promise.resolve(urls[0])); | ||
// early return if we have a single jsonrpc provider already | ||
if (urls.length === 1 && isJsonRpcProvider(urls[0])) { | ||
return (this.providerCache[chainId] = Promise.resolve(urls[0])); | ||
} | ||
else { | ||
// if we're here we know urls is a FallbackProvider | ||
return (this.providerCache[chainId] = Promise.resolve(urls)); | ||
} | ||
return (this.providerCache[chainId] = Promise.resolve().then(() => __importStar(require('@ethersproject/providers'))).then(({ JsonRpcProvider, FallbackProvider }) => ({ | ||
JsonRpcProvider, | ||
FallbackProvider, | ||
})) | ||
.then(({ JsonRpcProvider, FallbackProvider }) => { | ||
return (this.providerCache[chainId] = Promise.resolve().then(() => __importStar(require('@ethersproject/providers'))).then(({ JsonRpcProvider }) => JsonRpcProvider) | ||
.then((JsonRpcProvider) => { | ||
const providers = urls.map((url) => (isUrl(url) ? new JsonRpcProvider(url, chainId) : url)); | ||
return providers.length === 1 ? providers[0] : new FallbackProvider(providers); | ||
return (0, utils_1.getBestProvider)(providers, this.timeout); | ||
})); | ||
@@ -100,0 +93,0 @@ }); |
@@ -12,3 +12,3 @@ { | ||
}, | ||
"version": "8.0.24-beta.0", | ||
"version": "8.0.25-beta.0", | ||
"files": [ | ||
@@ -33,3 +33,3 @@ "dist/*" | ||
}, | ||
"gitHead": "b497295f7f4aeecf86845551e8fd0ee53d27d202" | ||
"gitHead": "47b1164980cf7a65bd54ecfb8a11c5acdd80f648" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
46755
7
226