Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@web3-react/network

Package Overview
Dependencies
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@web3-react/network - npm Package Compare versions

Comparing version 8.0.25-beta.0 to 8.0.26-beta.0

37

dist/index.d.ts

@@ -6,2 +6,16 @@ import type { JsonRpcProvider } from '@ethersproject/providers';

declare type url = string | ConnectionInfo;
/**
* @param urlMap - A mapping from chainIds to RPC urls.
* @param defaultChainId - The chainId to connect to in activate if one is not provided.
* @param timeout - Timeout, in milliseconds, after which to treat network calls to urls as failed when selecting
* online providers.
*/
export interface NetworkConstructorArgs {
actions: Actions;
urlMap: {
[chainId: number]: url | url[] | JsonRpcProvider | JsonRpcProvider[];
};
defaultChainId?: number;
timeout?: number;
}
export declare class Network extends Connector {

@@ -11,23 +25,8 @@ /** {@inheritdoc Connector.provider} */

/** {@inheritdoc Connector.customProvider} */
customProvider: JsonRpcProvider | undefined;
private readonly timeout?;
customProvider?: JsonRpcProvider;
private readonly providerCache;
private readonly urlMap;
private readonly defaultChainId;
private readonly providerCache;
/**
* @param urlMap - A mapping from chainIds to RPC urls.
* @param connectEagerly - A flag indicating whether connection should be initiated when the class is constructed.
* @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, timeout, }: {
actions: Actions;
urlMap: {
[chainId: number]: url | url[] | JsonRpcProvider | JsonRpcProvider[];
};
connectEagerly?: boolean;
defaultChainId?: number;
timeout?: number;
});
private readonly timeout;
constructor({ actions, urlMap, defaultChainId, timeout, }: NetworkConstructorArgs);
private isomorphicInitialize;

@@ -34,0 +33,0 @@ /**

@@ -41,19 +41,6 @@ "use strict";

}
function isJsonRpcProvider(url) {
return !isUrl(url);
}
class Network extends types_1.Connector {
/**
* @param urlMap - A mapping from chainIds to RPC urls.
* @param connectEagerly - A flag indicating whether connection should be initiated when the class is constructed.
* @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]), timeout, }) {
constructor({ actions, urlMap, defaultChainId = Number(Object.keys(urlMap)[0]), timeout = 5000, }) {
super(actions);
this.providerCache = {};
if (connectEagerly && this.serverSide) {
throw new Error('connectEagerly = true is invalid for SSR, instead use the activate method in a useEffect');
}
this.urlMap = Object.keys(urlMap).reduce((accumulator, chainId) => {

@@ -66,3 +53,3 @@ const urls = urlMap[Number(chainId)];

// 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];
accumulator[Number(chainId)] = isUrl(urls) ? [urls] : [urls];
}

@@ -73,7 +60,6 @@ return accumulator;

this.timeout = timeout;
if (connectEagerly)
void this.activate();
}
isomorphicInitialize(chainId) {
return __awaiter(this, void 0, void 0, function* () {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
if (this.providerCache[chainId])

@@ -83,7 +69,6 @@ return this.providerCache[chainId];

// early return if we have a single jsonrpc provider already
if (urls.length === 1 && isJsonRpcProvider(urls[0])) {
if (urls.length === 1 && !isUrl(urls[0])) {
return (this.providerCache[chainId] = Promise.resolve(urls[0]));
}
return (this.providerCache[chainId] = Promise.resolve().then(() => __importStar(require('@ethersproject/providers'))).then(({ JsonRpcProvider }) => JsonRpcProvider)
.then((JsonRpcProvider) => {
return (this.providerCache[chainId] = Promise.resolve().then(() => __importStar(require('@ethersproject/providers'))).then(({ JsonRpcProvider }) => {
const providers = urls.map((url) => (isUrl(url) ? new JsonRpcProvider(url, chainId) : url));

@@ -101,5 +86,7 @@ return (0, utils_1.getBestProvider)(providers, this.timeout);

return __awaiter(this, void 0, void 0, function* () {
if (!this.customProvider)
this.actions.startActivation();
yield this.isomorphicInitialize(desiredChainId)
let cancelActivation;
if (!this.providerCache[desiredChainId]) {
cancelActivation = this.actions.startActivation();
}
return this.isomorphicInitialize(desiredChainId)
.then((customProvider) => __awaiter(this, void 0, void 0, function* () {

@@ -111,3 +98,3 @@ this.customProvider = customProvider;

.catch((error) => {
this.actions.resetState();
cancelActivation === null || cancelActivation === void 0 ? void 0 : cancelActivation();
throw error;

@@ -114,0 +101,0 @@ });

@@ -12,3 +12,3 @@ {

},
"version": "8.0.25-beta.0",
"version": "8.0.26-beta.0",
"files": [

@@ -28,8 +28,8 @@ "dist/*"

"@ethersproject/providers": "^5",
"@web3-react/types": "^8.0.18-beta.0"
"@web3-react/types": "^8.0.19-beta.0"
},
"devDependencies": {
"@web3-react/store": "^8.0.23-beta.0"
"@web3-react/store": "^8.0.24-beta.0"
},
"gitHead": "47b1164980cf7a65bd54ecfb8a11c5acdd80f648"
"gitHead": "9a5d6207c54457de7081755d5d69e5bd7c9fda31"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc