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

@web3-react/network-connector

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@web3-react/network-connector - npm Package Compare versions

Comparing version 6.1.1 to 6.1.2

2

dist/declarations.d.ts

@@ -1,1 +0,1 @@

declare module 'web3-provider-engine/subproviders/cache.js';
declare module 'eth-provider';

@@ -9,24 +9,2 @@ import { ConnectorUpdate } from '@web3-react/types';

}
declare type AsyncSendable = {
isMetaMask?: boolean;
host?: string;
path?: string;
sendAsync?: (request: any, callback: (error: any, response: any) => void) => void;
send?: (request: any, callback: (error: any, response: any) => void) => void;
};
declare class MiniRpcProvider implements AsyncSendable {
readonly isMetaMask: false;
readonly chainId: number;
readonly url: string;
readonly host: string;
readonly path: string;
constructor(chainId: number, url: string);
readonly sendAsync: (request: {
jsonrpc: '2.0';
id: number | string | null;
method: string;
params?: unknown[] | object;
}, callback: (error: any, response: any) => void) => void;
readonly request: (method: string, params?: object | unknown[] | undefined) => Promise<unknown>;
}
export declare class NetworkConnector extends AbstractConnector {

@@ -37,7 +15,8 @@ private readonly providers;

activate(): Promise<ConnectorUpdate>;
getProvider(): Promise<MiniRpcProvider>;
getProvider(): Promise<any>;
getChainId(): Promise<number>;
getAccount(): Promise<null>;
deactivate(): void;
changeChainId(chainId: number): void;
}
export {};

@@ -6,2 +6,3 @@ 'use strict';

var abstractConnector = require('@web3-react/abstract-connector');
var provider = _interopDefault(require('eth-provider'));
var invariant = _interopDefault(require('tiny-invariant'));

@@ -15,156 +16,2 @@

function _getPrototypeOf(o) {
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
return o.__proto__ || Object.getPrototypeOf(o);
};
return _getPrototypeOf(o);
}
function _setPrototypeOf(o, p) {
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
o.__proto__ = p;
return o;
};
return _setPrototypeOf(o, p);
}
function _isNativeReflectConstruct() {
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
if (Reflect.construct.sham) return false;
if (typeof Proxy === "function") return true;
try {
Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
return true;
} catch (e) {
return false;
}
}
function _construct(Parent, args, Class) {
if (_isNativeReflectConstruct()) {
_construct = Reflect.construct;
} else {
_construct = function _construct(Parent, args, Class) {
var a = [null];
a.push.apply(a, args);
var Constructor = Function.bind.apply(Parent, a);
var instance = new Constructor();
if (Class) _setPrototypeOf(instance, Class.prototype);
return instance;
};
}
return _construct.apply(null, arguments);
}
function _isNativeFunction(fn) {
return Function.toString.call(fn).indexOf("[native code]") !== -1;
}
function _wrapNativeSuper(Class) {
var _cache = typeof Map === "function" ? new Map() : undefined;
_wrapNativeSuper = function _wrapNativeSuper(Class) {
if (Class === null || !_isNativeFunction(Class)) return Class;
if (typeof Class !== "function") {
throw new TypeError("Super expression must either be null or a function");
}
if (typeof _cache !== "undefined") {
if (_cache.has(Class)) return _cache.get(Class);
_cache.set(Class, Wrapper);
}
function Wrapper() {
return _construct(Class, arguments, _getPrototypeOf(this).constructor);
}
Wrapper.prototype = Object.create(Class.prototype, {
constructor: {
value: Wrapper,
enumerable: false,
writable: true,
configurable: true
}
});
return _setPrototypeOf(Wrapper, Class);
};
return _wrapNativeSuper(Class);
}
var RequestError = /*#__PURE__*/function (_Error) {
_inheritsLoose(RequestError, _Error);
function RequestError(message, code, data) {
var _this;
_this = _Error.call(this, message) || this;
_this.code = code;
_this.data = data;
return _this;
}
return RequestError;
}( /*#__PURE__*/_wrapNativeSuper(Error));
var MiniRpcProvider = function MiniRpcProvider(chainId, url) {
var _this3 = this;
var _this2 = this;
this.isMetaMask = false;
this.sendAsync = function (request, callback) {
_this2.request(request.method, request.params).then(function (result) {
return callback(null, {
jsonrpc: '2.0',
id: request.id,
result: result
});
})["catch"](function (error) {
return callback(error, null);
});
};
this.request = function (method, params) {
try {
return Promise.resolve(fetch(_this3.url, {
method: 'POST',
body: JSON.stringify({
jsonrpc: '2.0',
id: 1,
method: method,
params: params
})
})).then(function (response) {
if (!response.ok) throw new RequestError(response.status + ": " + response.statusText, -32000);
return Promise.resolve(response.json()).then(function (body) {
if ('error' in body) {
var _body$error, _body$error2, _body$error3;
throw new RequestError(body == null ? void 0 : (_body$error = body.error) == null ? void 0 : _body$error.message, body == null ? void 0 : (_body$error2 = body.error) == null ? void 0 : _body$error2.code, body == null ? void 0 : (_body$error3 = body.error) == null ? void 0 : _body$error3.data);
} else if ('result' in body) {
return body.result;
} else {
throw new RequestError("Received unexpected JSON-RPC response to " + method + " request.", -32000, body);
}
});
});
} catch (e) {
return Promise.reject(e);
}
};
this.chainId = chainId;
this.url = url;
var parsed = new URL(url);
this.host = parsed.host;
this.path = parsed.pathname;
};
var NetworkConnector = /*#__PURE__*/function (_AbstractConnector) {

@@ -174,3 +21,3 @@ _inheritsLoose(NetworkConnector, _AbstractConnector);

function NetworkConnector(_ref) {
var _this4;
var _this;

@@ -180,3 +27,3 @@ var urls = _ref.urls,

!(defaultChainId || Object.keys(urls).length === 1) ? invariant(false, 'defaultChainId is a required argument with >1 url') : void 0;
_this4 = _AbstractConnector.call(this, {
_this = _AbstractConnector.call(this, {
supportedChainIds: Object.keys(urls).map(function (k) {

@@ -186,8 +33,8 @@ return Number(k);

}) || this;
_this4.currentChainId = defaultChainId || Number(Object.keys(urls)[0]);
_this4.providers = Object.keys(urls).reduce(function (accumulator, chainId) {
accumulator[Number(chainId)] = new MiniRpcProvider(Number(chainId), urls[Number(chainId)]);
_this.currentChainId = defaultChainId || Number(Object.keys(urls)[0]);
_this.providers = Object.keys(urls).reduce(function (accumulator, chainId) {
accumulator[Number(chainId)] = provider([urls[Number(chainId)]]);
return accumulator;
}, {});
return _this4;
return _this;
}

@@ -199,7 +46,7 @@

try {
var _this6 = this;
var _this3 = this;
return Promise.resolve({
provider: _this6.providers[_this6.currentChainId],
chainId: _this6.currentChainId,
provider: _this3.providers[_this3.currentChainId],
chainId: _this3.currentChainId,
account: null

@@ -214,5 +61,5 @@ });

try {
var _this8 = this;
var _this5 = this;
return Promise.resolve(_this8.providers[_this8.currentChainId]);
return Promise.resolve(_this5.providers[_this5.currentChainId]);
} catch (e) {

@@ -225,5 +72,5 @@ return Promise.reject(e);

try {
var _this10 = this;
var _this7 = this;
return Promise.resolve(_this10.currentChainId);
return Promise.resolve(_this7.currentChainId);
} catch (e) {

@@ -242,2 +89,11 @@ return Promise.reject(e);

_proto.changeChainId = function changeChainId(chainId) {
!Object.keys(this.providers).includes(chainId.toString()) ? invariant(false, "No url found for chainId " + chainId) : void 0;
this.currentChainId = chainId;
this.emitUpdate({
provider: this.providers[this.currentChainId],
chainId: chainId
});
};
return NetworkConnector;

@@ -244,0 +100,0 @@ }(abstractConnector.AbstractConnector);

@@ -1,2 +0,2 @@

"use strict";var t,e=require("@web3-react/abstract-connector"),r=(t=require("tiny-invariant"))&&"object"==typeof t&&"default"in t?t.default:t;function n(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e}function o(t){return(o=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function u(t,e){return(u=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function i(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}function c(t,e,r){return(c=i()?Reflect.construct:function(t,e,r){var n=[null];n.push.apply(n,e);var o=new(Function.bind.apply(t,n));return r&&u(o,r.prototype),o}).apply(null,arguments)}function s(t){var e="function"==typeof Map?new Map:void 0;return(s=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,r)}function r(){return c(t,arguments,o(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),u(r,t)})(t)}var a=function(t){function e(e,r,n){var o;return(o=t.call(this,e)||this).code=r,o.data=n,o}return n(e,t),e}(s(Error)),f=function(t,e){var r=this,n=this;this.isMetaMask=!1,this.sendAsync=function(t,e){n.request(t.method,t.params).then((function(r){return e(null,{jsonrpc:"2.0",id:t.id,result:r})})).catch((function(t){return e(t,null)}))},this.request=function(t,e){try{return Promise.resolve(fetch(r.url,{method:"POST",body:JSON.stringify({jsonrpc:"2.0",id:1,method:t,params:e})})).then((function(e){if(!e.ok)throw new a(e.status+": "+e.statusText,-32e3);return Promise.resolve(e.json()).then((function(e){var r,n,o;if("error"in e)throw new a(null==e||null==(r=e.error)?void 0:r.message,null==e||null==(n=e.error)?void 0:n.code,null==e||null==(o=e.error)?void 0:o.data);if("result"in e)return e.result;throw new a("Received unexpected JSON-RPC response to "+t+" request.",-32e3,e)}))}))}catch(t){return Promise.reject(t)}},this.chainId=t,this.url=e;var o=new URL(e);this.host=o.host,this.path=o.pathname};exports.NetworkConnector=function(t){function e(e){var n,o=e.urls,u=e.defaultChainId;return u||1===Object.keys(o).length||r(!1),(n=t.call(this,{supportedChainIds:Object.keys(o).map((function(t){return Number(t)}))})||this).currentChainId=u||Number(Object.keys(o)[0]),n.providers=Object.keys(o).reduce((function(t,e){return t[Number(e)]=new f(Number(e),o[Number(e)]),t}),{}),n}n(e,t);var o=e.prototype;return o.activate=function(){try{return Promise.resolve({provider:this.providers[this.currentChainId],chainId:this.currentChainId,account:null})}catch(t){return Promise.reject(t)}},o.getProvider=function(){try{return Promise.resolve(this.providers[this.currentChainId])}catch(t){return Promise.reject(t)}},o.getChainId=function(){try{return Promise.resolve(this.currentChainId)}catch(t){return Promise.reject(t)}},o.getAccount=function(){return Promise.resolve(null)},o.deactivate=function(){},e}(e.AbstractConnector);
"use strict";function r(r){return r&&"object"==typeof r&&"default"in r?r.default:r}var t=require("@web3-react/abstract-connector"),e=r(require("eth-provider")),n=r(require("tiny-invariant"));exports.NetworkConnector=function(r){var t,i;function c(t){var i,c=t.urls,o=t.defaultChainId;return o||1===Object.keys(c).length||n(!1),(i=r.call(this,{supportedChainIds:Object.keys(c).map((function(r){return Number(r)}))})||this).currentChainId=o||Number(Object.keys(c)[0]),i.providers=Object.keys(c).reduce((function(r,t){return r[Number(t)]=e([c[Number(t)]]),r}),{}),i}i=r,(t=c).prototype=Object.create(i.prototype),t.prototype.constructor=t,t.__proto__=i;var o=c.prototype;return o.activate=function(){try{return Promise.resolve({provider:this.providers[this.currentChainId],chainId:this.currentChainId,account:null})}catch(r){return Promise.reject(r)}},o.getProvider=function(){try{return Promise.resolve(this.providers[this.currentChainId])}catch(r){return Promise.reject(r)}},o.getChainId=function(){try{return Promise.resolve(this.currentChainId)}catch(r){return Promise.reject(r)}},o.getAccount=function(){return Promise.resolve(null)},o.deactivate=function(){},o.changeChainId=function(r){Object.keys(this.providers).includes(r.toString())||n(!1),this.currentChainId=r,this.emitUpdate({provider:this.providers[this.currentChainId],chainId:r})},c}(t.AbstractConnector);
//# sourceMappingURL=network-connector.cjs.production.min.js.map
import { AbstractConnector } from '@web3-react/abstract-connector';
import provider from 'eth-provider';
import invariant from 'tiny-invariant';

@@ -10,156 +11,2 @@

function _getPrototypeOf(o) {
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
return o.__proto__ || Object.getPrototypeOf(o);
};
return _getPrototypeOf(o);
}
function _setPrototypeOf(o, p) {
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
o.__proto__ = p;
return o;
};
return _setPrototypeOf(o, p);
}
function _isNativeReflectConstruct() {
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
if (Reflect.construct.sham) return false;
if (typeof Proxy === "function") return true;
try {
Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
return true;
} catch (e) {
return false;
}
}
function _construct(Parent, args, Class) {
if (_isNativeReflectConstruct()) {
_construct = Reflect.construct;
} else {
_construct = function _construct(Parent, args, Class) {
var a = [null];
a.push.apply(a, args);
var Constructor = Function.bind.apply(Parent, a);
var instance = new Constructor();
if (Class) _setPrototypeOf(instance, Class.prototype);
return instance;
};
}
return _construct.apply(null, arguments);
}
function _isNativeFunction(fn) {
return Function.toString.call(fn).indexOf("[native code]") !== -1;
}
function _wrapNativeSuper(Class) {
var _cache = typeof Map === "function" ? new Map() : undefined;
_wrapNativeSuper = function _wrapNativeSuper(Class) {
if (Class === null || !_isNativeFunction(Class)) return Class;
if (typeof Class !== "function") {
throw new TypeError("Super expression must either be null or a function");
}
if (typeof _cache !== "undefined") {
if (_cache.has(Class)) return _cache.get(Class);
_cache.set(Class, Wrapper);
}
function Wrapper() {
return _construct(Class, arguments, _getPrototypeOf(this).constructor);
}
Wrapper.prototype = Object.create(Class.prototype, {
constructor: {
value: Wrapper,
enumerable: false,
writable: true,
configurable: true
}
});
return _setPrototypeOf(Wrapper, Class);
};
return _wrapNativeSuper(Class);
}
var RequestError = /*#__PURE__*/function (_Error) {
_inheritsLoose(RequestError, _Error);
function RequestError(message, code, data) {
var _this;
_this = _Error.call(this, message) || this;
_this.code = code;
_this.data = data;
return _this;
}
return RequestError;
}( /*#__PURE__*/_wrapNativeSuper(Error));
var MiniRpcProvider = function MiniRpcProvider(chainId, url) {
var _this3 = this;
var _this2 = this;
this.isMetaMask = false;
this.sendAsync = function (request, callback) {
_this2.request(request.method, request.params).then(function (result) {
return callback(null, {
jsonrpc: '2.0',
id: request.id,
result: result
});
})["catch"](function (error) {
return callback(error, null);
});
};
this.request = function (method, params) {
try {
return Promise.resolve(fetch(_this3.url, {
method: 'POST',
body: JSON.stringify({
jsonrpc: '2.0',
id: 1,
method: method,
params: params
})
})).then(function (response) {
if (!response.ok) throw new RequestError(response.status + ": " + response.statusText, -32000);
return Promise.resolve(response.json()).then(function (body) {
if ('error' in body) {
var _body$error, _body$error2, _body$error3;
throw new RequestError(body == null ? void 0 : (_body$error = body.error) == null ? void 0 : _body$error.message, body == null ? void 0 : (_body$error2 = body.error) == null ? void 0 : _body$error2.code, body == null ? void 0 : (_body$error3 = body.error) == null ? void 0 : _body$error3.data);
} else if ('result' in body) {
return body.result;
} else {
throw new RequestError("Received unexpected JSON-RPC response to " + method + " request.", -32000, body);
}
});
});
} catch (e) {
return Promise.reject(e);
}
};
this.chainId = chainId;
this.url = url;
var parsed = new URL(url);
this.host = parsed.host;
this.path = parsed.pathname;
};
var NetworkConnector = /*#__PURE__*/function (_AbstractConnector) {

@@ -169,3 +16,3 @@ _inheritsLoose(NetworkConnector, _AbstractConnector);

function NetworkConnector(_ref) {
var _this4;
var _this;

@@ -175,3 +22,3 @@ var urls = _ref.urls,

!(defaultChainId || Object.keys(urls).length === 1) ? process.env.NODE_ENV !== "production" ? invariant(false, 'defaultChainId is a required argument with >1 url') : invariant(false) : void 0;
_this4 = _AbstractConnector.call(this, {
_this = _AbstractConnector.call(this, {
supportedChainIds: Object.keys(urls).map(function (k) {

@@ -181,8 +28,8 @@ return Number(k);

}) || this;
_this4.currentChainId = defaultChainId || Number(Object.keys(urls)[0]);
_this4.providers = Object.keys(urls).reduce(function (accumulator, chainId) {
accumulator[Number(chainId)] = new MiniRpcProvider(Number(chainId), urls[Number(chainId)]);
_this.currentChainId = defaultChainId || Number(Object.keys(urls)[0]);
_this.providers = Object.keys(urls).reduce(function (accumulator, chainId) {
accumulator[Number(chainId)] = provider([urls[Number(chainId)]]);
return accumulator;
}, {});
return _this4;
return _this;
}

@@ -194,7 +41,7 @@

try {
var _this6 = this;
var _this3 = this;
return Promise.resolve({
provider: _this6.providers[_this6.currentChainId],
chainId: _this6.currentChainId,
provider: _this3.providers[_this3.currentChainId],
chainId: _this3.currentChainId,
account: null

@@ -209,5 +56,5 @@ });

try {
var _this8 = this;
var _this5 = this;
return Promise.resolve(_this8.providers[_this8.currentChainId]);
return Promise.resolve(_this5.providers[_this5.currentChainId]);
} catch (e) {

@@ -220,5 +67,5 @@ return Promise.reject(e);

try {
var _this10 = this;
var _this7 = this;
return Promise.resolve(_this10.currentChainId);
return Promise.resolve(_this7.currentChainId);
} catch (e) {

@@ -237,2 +84,11 @@ return Promise.reject(e);

_proto.changeChainId = function changeChainId(chainId) {
!Object.keys(this.providers).includes(chainId.toString()) ? process.env.NODE_ENV !== "production" ? invariant(false, "No url found for chainId " + chainId) : invariant(false) : void 0;
this.currentChainId = chainId;
this.emitUpdate({
provider: this.providers[this.currentChainId],
chainId: chainId
});
};
return NetworkConnector;

@@ -239,0 +95,0 @@ }(AbstractConnector);

@@ -6,3 +6,3 @@ {

},
"version": "6.1.1",
"version": "6.1.2",
"description": "A simple, maximally extensible, dependency minimized framework for building modern Ethereum dApps",

@@ -40,6 +40,7 @@ "keywords": [

"@web3-react/types": "^6.0.7",
"eth-provider": "^0.4.0",
"tiny-invariant": "^1.0.6"
},
"license": "GPL-3.0-or-later",
"gitHead": "3d7c1a3c52ad5ef3109c3481d2e54b5d33975c05"
"gitHead": "5b413ba698e4af630e8083921aa6f67bd12eea77"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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