UNPKG

@web3-react/portis-connector

Version:

A simple, maximally extensible, dependency minimized framework for building modern Ethereum dApps

3 lines (2 loc) 3.4 kB
"use strict";var e,t=require("@web3-react/abstract-connector"),r=(e=require("tiny-invariant"))&&"object"==typeof e&&"default"in e?e.default:e;function n(e,t){return(n=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function o(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}var i={1:"mainnet",3:"ropsten",4:"rinkeby",5:"goerli",42:"kovan",100:"xdai",30:"orchid",31:"orchidTestnet",99:"core",77:"sokol",61:"classic",8:"ubiq",108:"thundercore",18:"thundercoreTestnet",163:"lightstreams",122:"fuse",1337:"devChain",31337:"hardhat",137:"matic",80001:"maticMumbai"};exports.PortisConnector=function(e){var t,c;function u(t){var n,c=t.dAppId,u=t.networks,a=t.config,s=void 0===a?{}:a,h=u.map((function(e){return"number"==typeof e?e:Number(e.chainId)}));return h.every((function(e){return!!i[e]}))||r(!1),(n=e.call(this,{supportedChainIds:h})||this).dAppId=c,n.networks=u,n.config=s,n.handleOnLogout=n.handleOnLogout.bind(o(n)),n.handleOnActiveWalletChanged=n.handleOnActiveWalletChanged.bind(o(n)),n.handleOnError=n.handleOnError.bind(o(n)),n}c=e,(t=u).prototype=Object.create(c.prototype),t.prototype.constructor=t,n(t,c);var a=u.prototype;return a.handleOnLogout=function(){this.emitDeactivate()},a.handleOnActiveWalletChanged=function(e){this.emitUpdate({account:e})},a.handleOnError=function(e){this.emitError(e)},a.activate=function(){try{var e=this,t=function(){return e.portis.onLogout(e.handleOnLogout),e.portis.onActiveWalletChanged(e.handleOnActiveWalletChanged),e.portis.onError(e.handleOnError),Promise.resolve(e.portis.provider.enable().then((function(e){return e[0]}))).then((function(t){return{provider:e.portis.provider,account:t}}))},r=function(){if(!e.portis)return Promise.resolve(new Promise((function(e){e(function(e){if(e&&e.__esModule)return e;var t={};return e&&Object.keys(e).forEach((function(r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})})),t.default=e,t}(require("@portis/web3")))})).then((function(e){var t;return null!=(t=null==e?void 0:e.default)?t:e}))).then((function(t){e.portis=new t(e.dAppId,"number"==typeof e.networks[0]?i[e.networks[0]]:e.networks[0],e.config)}))}();return Promise.resolve(r&&r.then?r.then(t):t())}catch(e){return Promise.reject(e)}},a.getProvider=function(){try{return Promise.resolve(this.portis.provider)}catch(e){return Promise.reject(e)}},a.getChainId=function(){try{return Promise.resolve(this.portis.provider.send("eth_chainId"))}catch(e){return Promise.reject(e)}},a.getAccount=function(){try{return Promise.resolve(this.portis.provider.send("eth_accounts").then((function(e){return e[0]})))}catch(e){return Promise.reject(e)}},a.deactivate=function(){this.portis.onLogout((function(){})),this.portis.onActiveWalletChanged((function(){})),this.portis.onError((function(){}))},a.changeNetwork=function(e,t){try{return"number"==typeof e?(i[e]||r(!1),this.portis.changeNetwork(i[e],t),this.emitUpdate({chainId:e})):(this.portis.changeNetwork(e,t),this.emitUpdate({chainId:Number(e.chainId)})),Promise.resolve()}catch(e){return Promise.reject(e)}},a.close=function(){try{var e=this;return Promise.resolve(e.portis.logout()).then((function(){e.emitDeactivate()}))}catch(e){return Promise.reject(e)}},u}(t.AbstractConnector); //# sourceMappingURL=portis-connector.cjs.production.min.js.map