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.2 to 6.1.3

32

dist/index.d.ts
import { ConnectorUpdate } from '@web3-react/types';
import { AbstractConnector } from '@web3-react/abstract-connector';
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;
};
export declare class RequestError extends Error {
code: number;
data?: unknown;
constructor(message: string, code: number, data?: unknown);
}
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 | {
method: string;
params?: object | unknown[] | undefined;
}, params?: object | unknown[] | undefined) => Promise<unknown>;
}
interface NetworkConnectorArguments {

@@ -14,3 +44,3 @@ urls: {

activate(): Promise<ConnectorUpdate>;
getProvider(): Promise<any>;
getProvider(): Promise<MiniRpcProvider>;
getChainId(): Promise<number>;

@@ -17,0 +47,0 @@ getAccount(): Promise<null>;

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

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

@@ -16,2 +15,165 @@

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) || this;
_this.code = code;
_this.data = data;
_this.name = _this.constructor.name;
_this.message = message;
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) {
console.log('sendAsync', request.method, request.params);
_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 {
if (typeof method !== 'string') {
method = method.method;
params = method.params;
}
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) {

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

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

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

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

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

}) || this;
_this.currentChainId = defaultChainId || Number(Object.keys(urls)[0]);
_this.providers = Object.keys(urls).reduce(function (accumulator, chainId) {
accumulator[Number(chainId)] = provider([urls[Number(chainId)]]);
_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)]);
return accumulator;
}, {});
return _this;
return _this4;
}

@@ -46,7 +208,7 @@

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

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

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

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

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

@@ -102,2 +264,3 @@ return Promise.reject(e);

exports.NetworkConnector = NetworkConnector;
exports.RequestError = RequestError;
//# sourceMappingURL=network-connector.cjs.development.js.map

2

dist/network-connector.cjs.production.min.js

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

"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);
"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 i(t,e){return(i=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function u(){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=u()?Reflect.construct:function(t,e,r){var n=[null];n.push.apply(n,e);var o=new(Function.bind.apply(t,n));return r&&i(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}}),i(r,t)})(t)}var a=function(t){function e(e,r,n){var o;return(o=t.call(this)||this).code=r,o.data=n,o.name=o.constructor.name,o.message=e,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){console.log("sendAsync",t.method,t.params),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"string"!=typeof t&&(e=(t=t.method).params),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,i=e.defaultChainId;return i||1===Object.keys(o).length||r(!1),(n=t.call(this,{supportedChainIds:Object.keys(o).map((function(t){return Number(t)}))})||this).currentChainId=i||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(){},o.changeChainId=function(t){Object.keys(this.providers).includes(t.toString())||r(!1),this.currentChainId=t,this.emitUpdate({provider:this.providers[this.currentChainId],chainId:t})},e}(e.AbstractConnector),exports.RequestError=a;
//# 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';

@@ -11,2 +10,165 @@

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) || this;
_this.code = code;
_this.data = data;
_this.name = _this.constructor.name;
_this.message = message;
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) {
console.log('sendAsync', request.method, request.params);
_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 {
if (typeof method !== 'string') {
method = method.method;
params = method.params;
}
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) {

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

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

@@ -22,3 +184,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;
_this = _AbstractConnector.call(this, {
_this4 = _AbstractConnector.call(this, {
supportedChainIds: Object.keys(urls).map(function (k) {

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

}) || this;
_this.currentChainId = defaultChainId || Number(Object.keys(urls)[0]);
_this.providers = Object.keys(urls).reduce(function (accumulator, chainId) {
accumulator[Number(chainId)] = provider([urls[Number(chainId)]]);
_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)]);
return accumulator;
}, {});
return _this;
return _this4;
}

@@ -41,7 +203,7 @@

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

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

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

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

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

@@ -96,3 +258,3 @@ return Promise.reject(e);

export { NetworkConnector };
export { NetworkConnector, RequestError };
//# sourceMappingURL=network-connector.esm.js.map

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

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

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

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

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