UNPKG

blackbull-sdk

Version:

An SDK for building applications on top of Blackbullswap

3 lines (2 loc) 6 kB
"use strict";var e=require("@web3-react/abstract-connector");function t(){return(t=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function n(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}function r(e){return(r=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function o(e,t){return(o=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}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(e){return!1}}function u(e,t,n){return(u=i()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var i=new(Function.bind.apply(e,r));return n&&o(i,n.prototype),i}).apply(null,arguments)}function c(e){var t="function"==typeof Map?new Map:void 0;return(c=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return u(e,arguments,r(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),o(n,e)})(e)}function h(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function a(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}function s(e){return e.hasOwnProperty("result")?e.result:e}require("tiny-warning"),"undefined"!=typeof Symbol&&(Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator"))),"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var f=function(e){function t(){var t;return(t=e.call(this)||this).name=t.constructor.name,t.message="No Ethereum provider was found on window.ethereum.",t}return n(t,e),t}(c(Error)),d=function(e){function t(){var t;return(t=e.call(this)||this).name=t.constructor.name,t.message="The user rejected the request.",t}return n(t,e),t}(c(Error));exports.InjectedConnector=function(e){function r(t){var n;return(n=e.call(this,t)||this).handleChainChanged=n.handleChainChanged.bind(h(n)),n.handleAccountsChanged=n.handleAccountsChanged.bind(h(n)),n.handleClose=n.handleClose.bind(h(n)),n}n(r,e);var o=r.prototype;return o.handleChainChanged=function(e){this.emitUpdate({chainId:e,provider:window.ethereum})},o.handleAccountsChanged=function(e){0===e.length?this.emitDeactivate():this.emitUpdate({account:e[0]})},o.handleClose=function(e,t){this.emitDeactivate()},o.activate=function(){try{var e,n=function(n){function r(){return t({provider:window.ethereum},e?{account:e}:{})}var o=function(){if(!e)return Promise.resolve(window.ethereum.enable().then((function(e){return e&&s(e)[0]}))).then((function(t){e=t}))}();return o&&o.then?o.then(r):r()};if(!window.ethereum)throw new f;window.ethereum.on&&(window.ethereum.on("chainChanged",this.handleChainChanged),window.ethereum.on("accountsChanged",this.handleAccountsChanged),window.ethereum.on("close",this.handleClose)),window.ethereum.isMetaMask&&(window.ethereum.autoRefreshOnNetworkChange=!1);var r=a((function(){return Promise.resolve(window.ethereum.send("eth_requestAccounts").then((function(e){return s(e)[0]}))).then((function(t){e=t}))}),(function(e){if(4001===e.code)throw new d}));return Promise.resolve(r&&r.then?r.then(n):n())}catch(e){return Promise.reject(e)}},o.getProvider=function(){try{return Promise.resolve(window.ethereum)}catch(e){return Promise.reject(e)}},o.getChainId=function(){try{var e,t=function(){function t(){if(!e)try{e=s(window.ethereum.send({method:"net_version"}))}catch(e){}return e||(e=window.ethereum.isDapper?s(window.ethereum.cachedResults.net_version):window.ethereum.chainId||window.ethereum.netVersion||window.ethereum.networkVersion||window.ethereum._chainId),e}var n=function(){if(!e){var t=a((function(){return Promise.resolve(window.ethereum.send("net_version").then(s)).then((function(t){e=t}))}),(function(){}));if(t&&t.then)return t.then((function(){}))}}();return n&&n.then?n.then(t):t()};if(!window.ethereum)throw new f;var n=a((function(){return Promise.resolve(window.ethereum.send("eth_chainId").then(s)).then((function(t){e=t}))}),(function(){}));return Promise.resolve(n&&n.then?n.then(t):t())}catch(e){return Promise.reject(e)}},o.getAccount=function(){try{var e,t=function(){function t(){return e||(e=s(window.ethereum.send({method:"eth_accounts"}))[0]),e}var n=function(){if(!e){var t=a((function(){return Promise.resolve(window.ethereum.enable().then((function(e){return s(e)[0]}))).then((function(t){e=t}))}),(function(){}));if(t&&t.then)return t.then((function(){}))}}();return n&&n.then?n.then(t):t()};if(!window.ethereum)throw new f;var n=a((function(){return Promise.resolve(window.ethereum.send("eth_accounts").then((function(e){return s(e)[0]}))).then((function(t){e=t}))}),(function(){}));return Promise.resolve(n&&n.then?n.then(t):t())}catch(e){return Promise.reject(e)}},o.deactivate=function(){window.ethereum&&window.ethereum.removeListener&&(window.ethereum.removeListener("chainChanged",this.handleChainChanged),window.ethereum.removeListener("accountsChanged",this.handleAccountsChanged),window.ethereum.removeListener("close",this.handleClose))},o.isAuthorized=function(){try{return window.ethereum?Promise.resolve(a((function(){return Promise.resolve(window.ethereum.send("eth_accounts").then((function(e){return s(e).length>0})))}),(function(){return!1}))):Promise.resolve(!1)}catch(e){return Promise.reject(e)}},r}(e.AbstractConnector),exports.NoEthereumProviderError=f,exports.UserRejectedRequestError=d; //# sourceMappingURL=web3-react-injected-connector.cjs.production.min.js.map