@dodoex/wallet-web3 0.0.3-2 → 0.0.3-3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- import e from"buffer";import t from"util";import{g as r}from"./index-ecbe3d8d.js";import{g as n}from"./_commonjsHelpers-70de2c37.js";var o,i,a={exports:{}};
1
+ import e from"buffer";import t from"util";import{g as r}from"./index-b869aac9.js";import{g as n}from"./_commonjsHelpers-70de2c37.js";var o,i,a={exports:{}};
2
2
  /*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */function u(){return i?o:(i=1,o=t.deprecate)}!function(t,r){var n=e,o=n.Buffer;function i(e,t){for(var r in e)t[r]=e[r]}function a(e,t,r){return o(e,t,r)}o.from&&o.alloc&&o.allocUnsafe&&o.allocUnsafeSlow?t.exports=n:(i(n,r),r.Buffer=a),a.prototype=Object.create(o.prototype),i(o,a),a.from=function(e,t,r){if("number"==typeof e)throw new TypeError("Argument must not be a number");return o(e,t,r)},a.alloc=function(e,t,r){if("number"!=typeof e)throw new TypeError("Argument must be a number");var n=o(e);return void 0!==t?"string"==typeof r?n.fill(t,r):n.fill(t):n.fill(0),n},a.allocUnsafe=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return o(e)},a.allocUnsafeSlow=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return n.SlowBuffer(e)}}(a,a.exports);var s=function(e){var t=(e=e||{}).max||Number.MAX_SAFE_INTEGER,r=void 0!==e.start?e.start:Math.floor(Math.random()*t);return function(){return r%=t,r++}};var c,p,l={},h={},f=n(r),y={};function _(){if(c)return y;c=1,Object.defineProperty(y,"__esModule",{value:!0});var e=f,t=function(){function t(e){if(this._maxConcurrency=e,this._queue=[],e<=0)throw new Error("semaphore must be initialized to a positive value");this._value=e}return t.prototype.acquire=function(){var e=this,t=this.isLocked(),r=new Promise((function(t){return e._queue.push(t)}));return t||this._dispatch(),r},t.prototype.runExclusive=function(t){return e.__awaiter(this,void 0,void 0,(function(){var r,n,o;return e.__generator(this,(function(e){switch(e.label){case 0:return[4,this.acquire()];case 1:r=e.sent(),n=r[0],o=r[1],e.label=2;case 2:return e.trys.push([2,,4,5]),[4,t(n)];case 3:return[2,e.sent()];case 4:return o(),[7];case 5:return[2]}}))}))},t.prototype.isLocked=function(){return this._value<=0},t.prototype.release=function(){if(this._maxConcurrency>1)throw new Error("this method is unavailabel on semaphores with concurrency > 1; use the scoped release returned by acquire instead");if(this._currentReleaser){var e=this._currentReleaser;this._currentReleaser=void 0,e()}},t.prototype._dispatch=function(){var e=this,t=this._queue.shift();if(t){var r=!1;this._currentReleaser=function(){r||(r=!0,e._value++,e._dispatch())},t([this._value--,this._currentReleaser])}},t}();return y.default=t,y}var m,d,g,v,b,B,w={};function k(){return d||(d=1,function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.withTimeout=e.Semaphore=e.Mutex=void 0;var t=function(){if(p)return h;p=1,Object.defineProperty(h,"__esModule",{value:!0});var e=f,t=_(),r=function(){function r(){this._semaphore=new t.default(1)}return r.prototype.acquire=function(){return e.__awaiter(this,void 0,void 0,(function(){return e.__generator(this,(function(e){switch(e.label){case 0:return[4,this._semaphore.acquire()];case 1:return[2,e.sent()[1]]}}))}))},r.prototype.runExclusive=function(e){return this._semaphore.runExclusive((function(){return e()}))},r.prototype.isLocked=function(){return this._semaphore.isLocked()},r.prototype.release=function(){this._semaphore.release()},r}();return h.default=r,h}();Object.defineProperty(e,"Mutex",{enumerable:!0,get:function(){return t.default}});var r=_();Object.defineProperty(e,"Semaphore",{enumerable:!0,get:function(){return r.default}});var n=function(){if(m)return w;m=1,Object.defineProperty(w,"__esModule",{value:!0}),w.withTimeout=void 0;var e=f;return w.withTimeout=function(t,r,n){var o=this;return void 0===n&&(n=new Error("timeout")),{acquire:function(){return new Promise((function(i,a){return e.__awaiter(o,void 0,void 0,(function(){var o,u;return e.__generator(this,(function(e){switch(e.label){case 0:return o=!1,setTimeout((function(){o=!0,a(n)}),r),[4,t.acquire()];case 1:return u=e.sent(),o?(Array.isArray(u)?u[1]:u)():i(u),[2]}}))}))}))},runExclusive:function(t){return e.__awaiter(this,void 0,void 0,(function(){var r,n;return e.__generator(this,(function(e){switch(e.label){case 0:r=function(){},e.label=1;case 1:return e.trys.push([1,,7,8]),[4,this.acquire()];case 2:return n=e.sent(),Array.isArray(n)?(r=n[1],[4,t(n[0])]):[3,4];case 3:return[2,e.sent()];case 4:return r=n,[4,t()];case 5:return[2,e.sent()];case 6:return[3,8];case 7:return r(),[7];case 8:return[2]}}))}))},release:function(){t.release()},isLocked:function(){return t.isLocked()}}},w}();Object.defineProperty(e,"withTimeout",{enumerable:!0,get:function(){return n.withTimeout}})}(l)),l}function T(){if(v)return g;v=1,g=function(){for(var t={},r=0;r<arguments.length;r++){var n=arguments[r];for(var o in n)e.call(n,o)&&(t[o]=n[o])}return t};var e=Object.prototype.hasOwnProperty;return g}function A(){if(B)return b;B=1;const e=T(),t=s();function r(e){this.currentProvider=e}function n(e){return function(){var t=[].slice.call(arguments),r=t.pop();this.sendAsync({method:e,params:t},r)}}function o(e,t){return function(){var r=[].slice.call(arguments),n=r.pop();r.length<e&&r.push("latest"),this.sendAsync({method:t,params:r},n)}}return b=r,r.prototype.getBalance=o(2,"eth_getBalance"),r.prototype.getCode=o(2,"eth_getCode"),r.prototype.getTransactionCount=o(2,"eth_getTransactionCount"),r.prototype.getStorageAt=o(3,"eth_getStorageAt"),r.prototype.call=o(2,"eth_call"),r.prototype.protocolVersion=n("eth_protocolVersion"),r.prototype.syncing=n("eth_syncing"),r.prototype.coinbase=n("eth_coinbase"),r.prototype.mining=n("eth_mining"),r.prototype.hashrate=n("eth_hashrate"),r.prototype.gasPrice=n("eth_gasPrice"),r.prototype.accounts=n("eth_accounts"),r.prototype.blockNumber=n("eth_blockNumber"),r.prototype.getBlockTransactionCountByHash=n("eth_getBlockTransactionCountByHash"),r.prototype.getBlockTransactionCountByNumber=n("eth_getBlockTransactionCountByNumber"),r.prototype.getUncleCountByBlockHash=n("eth_getUncleCountByBlockHash"),r.prototype.getUncleCountByBlockNumber=n("eth_getUncleCountByBlockNumber"),r.prototype.sign=n("eth_sign"),r.prototype.sendTransaction=n("eth_sendTransaction"),r.prototype.sendRawTransaction=n("eth_sendRawTransaction"),r.prototype.estimateGas=n("eth_estimateGas"),r.prototype.getBlockByHash=n("eth_getBlockByHash"),r.prototype.getBlockByNumber=n("eth_getBlockByNumber"),r.prototype.getTransactionByHash=n("eth_getTransactionByHash"),r.prototype.getTransactionByBlockHashAndIndex=n("eth_getTransactionByBlockHashAndIndex"),r.prototype.getTransactionByBlockNumberAndIndex=n("eth_getTransactionByBlockNumberAndIndex"),r.prototype.getTransactionReceipt=n("eth_getTransactionReceipt"),r.prototype.getUncleByBlockHashAndIndex=n("eth_getUncleByBlockHashAndIndex"),r.prototype.getUncleByBlockNumberAndIndex=n("eth_getUncleByBlockNumberAndIndex"),r.prototype.getCompilers=n("eth_getCompilers"),r.prototype.compileLLL=n("eth_compileLLL"),r.prototype.compileSolidity=n("eth_compileSolidity"),r.prototype.compileSerpent=n("eth_compileSerpent"),r.prototype.newFilter=n("eth_newFilter"),r.prototype.newBlockFilter=n("eth_newBlockFilter"),r.prototype.newPendingTransactionFilter=n("eth_newPendingTransactionFilter"),r.prototype.uninstallFilter=n("eth_uninstallFilter"),r.prototype.getFilterChanges=n("eth_getFilterChanges"),r.prototype.getFilterLogs=n("eth_getFilterLogs"),r.prototype.getLogs=n("eth_getLogs"),r.prototype.getWork=n("eth_getWork"),r.prototype.submitWork=n("eth_submitWork"),r.prototype.submitHashrate=n("eth_submitHashrate"),r.prototype.sendAsync=function(r,n){var o;this.currentProvider.sendAsync((o=r,e({id:t(),jsonrpc:"2.0",params:[]},o)),(function(e,t){if(!e&&t.error&&(e=new Error("EthQuery - RPC Error - "+t.error.message)),e)return n(e);n(null,t.result)}))},b}export{A as a,k as b,f as c,T as d,s as j,u as r,a as s};
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export{H as HD_PATH_LIST,O as OpenBlockIframeWallet,W as WalletType,A as WatchResult,j as allWalletList,I as approve,C as default,F as getContract,B as getEstimateGas,D as getGasPrice,q as getGnosisPackage,z as getIsOpenBlockIframe,l as getIsolatedEnvironmentWallet,p as getLedgerUSBPackage,y as getOpenBlockIframeConnector,t as getPortisConnector,G as getProviderByChain,r as getUAuthPackage,v as getWalletConnectConnector,m as getWalletDisabledStateFunction,u as getWalletLinkConnector,k as getWalletList,i as injectedConnect,h as injectedList,n as injectedListObject,x as registerNetworkWithMetamask,E as sendTransaction,s as standaloneList,o as standaloneListObject,w as walletState,J as watchTx}from"./index-ecbe3d8d.js";import"@ethersproject/providers";import"@ethersproject/constants";import"@ethersproject/contracts";import"@ethersproject/address";import"valtio";
1
+ export{H as HD_PATH_LIST,O as OpenBlockIframeWallet,W as WalletType,A as WatchResult,j as allWalletList,I as approve,C as default,F as getContract,B as getEstimateGas,D as getGasPrice,q as getGnosisPackage,z as getIsOpenBlockIframe,l as getIsolatedEnvironmentWallet,p as getLedgerUSBPackage,y as getOpenBlockIframeConnector,t as getPortisConnector,G as getProviderByChain,r as getUAuthPackage,v as getWalletConnectConnector,m as getWalletDisabledStateFunction,u as getWalletLinkConnector,k as getWalletList,i as injectedConnect,h as injectedList,n as injectedListObject,x as registerNetworkWithMetamask,E as sendTransaction,s as standaloneList,o as standaloneListObject,w as walletState,J as watchTx}from"./index-b869aac9.js";import"@ethersproject/providers";import"@ethersproject/constants";import"@ethersproject/contracts";import"@ethersproject/address";import"valtio";
@@ -1 +1 @@
1
- import{_ as e,a as t,d as n}from"./index-ecbe3d8d.js";import"@ethersproject/providers";import"@ethersproject/constants";import"@ethersproject/contracts";import"@ethersproject/address";import"valtio";function i(e,t){var n="string"==typeof e?Object.assign({},r[e]):e;if("object"!=typeof n)throw new Error("[Portis] illegal 'network' parameter. Read more about it here: https://docs.portis.io/#/configuration?id=network");if(!n.nodeUrl)throw new Error("[Portis] 'nodeUrl' is required. Read more about it here: https://docs.portis.io/#/configuration?id=network");if(t&&!n.gasRelayHubAddress)throw new Error("[Portis] can't find default gas relay hub for "+e);return"string"!=typeof e||t||delete n.gasRelayHubAddress,n}var r={mainnet:{nodeUrl:"https://mainnet.infura.io/v3/faa4639b090f46499f29d894da0551a0",chainId:"1",gasRelayHubAddress:"0xD216153c06E857cD7f72665E0aF1d7D82172F494"},ropsten:{nodeUrl:"https://ropsten.infura.io/v3/faa4639b090f46499f29d894da0551a0",chainId:"3",gasRelayHubAddress:"0xD216153c06E857cD7f72665E0aF1d7D82172F494"},rinkeby:{nodeUrl:"https://rinkeby.infura.io/v3/faa4639b090f46499f29d894da0551a0",chainId:"4",gasRelayHubAddress:"0xD216153c06E857cD7f72665E0aF1d7D82172F494"},goerli:{nodeUrl:"https://goerli.infura.io/v3/faa4639b090f46499f29d894da0551a0",chainId:"5"},ubiq:{nodeUrl:"https://rpc1.ubiqscan.io",chainId:"8"},thundercoreTestnet:{nodeUrl:"https://testnet-rpc.thundercore.com:8544",chainId:"18"},orchid:{nodeUrl:"https://public-node.rsk.co",chainId:"30"},orchidTestnet:{nodeUrl:"https://public-node.testnet.rsk.co",chainId:"31"},kovan:{nodeUrl:"https://kovan.infura.io/v3/faa4639b090f46499f29d894da0551a0",chainId:"42",gasRelayHubAddress:"0xD216153c06E857cD7f72665E0aF1d7D82172F494"},classic:{nodeUrl:"https://ethereumclassic.network",chainId:"61"},sokol:{nodeUrl:"https://sokol.poa.network",chainId:"77"},core:{nodeUrl:"https://core.poa.network",chainId:"99"},xdai:{nodeUrl:"https://dai.poa.network",chainId:"100",gasRelayHubAddress:"0xD216153c06E857cD7f72665E0aF1d7D82172F494"},thundercore:{nodeUrl:"https://mainnet-rpc.thundercore.com",chainId:"108"},fuse:{nodeUrl:"https://rpc.fusenet.io",chainId:"122"},lightstreams:{nodeUrl:"https://node.mainnet.lightstreams.io",chainId:"163"},matic:{nodeUrl:"https://polygon-rpc.com",chainId:"137"},maticMumbai:{nodeUrl:"https://rpc-mumbai.matic.today",chainId:"80001"},maticAlpha:{nodeUrl:"https://alpha.ethereum.matic.network",chainId:"4626"},maticTestnet:{nodeUrl:"https://testnet2.matic.network",chainId:"8995"}},o=function(){return!("undefined"==typeof window||!window.document)},a=!1;function s(){return new Promise((function(e,t){o()?a?e():["loaded","interactive","complete"].indexOf(document.readyState)>-1?(a=!0,e()):window.addEventListener("load",(function(){a=!0,e()}),!1):t()}))}function c(){var e="localhost"===location.hostname||"127.0.0.1"===location.hostname,t="https:"===location.protocol;if(!(e||t))throw"[Portis] Access to the WebCrypto API is restricted to secure origins.\nIf this is a development environment please use http://localhost:"+location.port+" instead.\nOtherwise, please use an SSL certificate."}var u={};Object.defineProperty(u,"__esModule",{value:!0});var d=u.default=u.ERR_NOT_IN_IFRAME=u.ERR_CONNECTION_TIMEOUT=u.ERR_CONNECTION_DESTROYED=void 0,l="handshake",h="handshake-reply",f="call",g="reply",p="fulfilled",m="rejected",v="message",w="ConnectionDestroyed";u.ERR_CONNECTION_DESTROYED=w;var b="ConnectionTimeout";u.ERR_CONNECTION_TIMEOUT=b;var y="NotInIframe";u.ERR_NOT_IN_IFRAME=y;var _,E={"http:":"80","https:":"443"},C=/^(https?:)?\/\/([^/:]+)(:(\d+))?/,k={ERR_CONNECTION_DESTROYED:w,ERR_CONNECTION_TIMEOUT:b,ERR_NOT_IN_IFRAME:y,Promise:function(){try{return window?window.Promise:null}catch(e){return null}}(),debug:!1},P=(_=0,function(){return++_}),I=function(){if(k.debug){for(var e,t=arguments.length,n=new Array(t),i=0;i<t;i++)n[i]=arguments[i];(e=console).log.apply(e,["[Penpal]"].concat(n))}},W=function(e){var t=[];return e((function(){t.forEach((function(e){e()}))})),{then:function(e){t.push(e)}}},x=function(e){return{name:e.name,message:e.message,stack:e.stack}},T=function(e,t,n,i){var r=t.localName,o=t.local,a=t.remote,s=t.remoteOrigin,c=!1;I("".concat(r,": Connecting call sender"));var u=function(e){return function(){for(var t=arguments.length,n=new Array(t),i=0;i<t;i++)n[i]=arguments[i];if(I("".concat(r,": Sending ").concat(e,"() call")),c){var u=new Error("Unable to send ".concat(e,"() call due ")+"to destroyed connection");throw u.code=w,u}return new k.Promise((function(t,i){var c=P();o.addEventListener(v,(function n(u){if(u.source===a&&u.origin===s&&u.data.penpal===g&&u.data.id===c){I("".concat(r,": Received ").concat(e,"() reply")),o.removeEventListener(v,n);var d=u.data.returnValue;u.data.returnValueIsError&&(l=d,h=new Error,Object.keys(l).forEach((function(e){return h[e]=l[e]})),d=h),(u.data.resolution===p?t:i)(d)}var l,h})),a.postMessage({penpal:f,id:c,methodName:e,args:n},s)}))}};i.then((function(){c=!0})),n.reduce((function(e,t){return e[t]=u(t),e}),e)},A=function(e,t,n){var i=e.localName,r=e.local,o=e.remote,a=e.remoteOrigin,s=!1;I("".concat(i,": Connecting call receiver"));var c=function(e){if(e.source===o&&e.origin===a&&e.data.penpal===f){var n=e.data,r=n.methodName,c=n.args,u=n.id;if(I("".concat(i,": Received ").concat(r,"() call")),r in t){var d=function(e){return function(t){if(I("".concat(i,": Sending ").concat(r,"() reply")),s)I("".concat(i,": Unable to send ").concat(r,"() reply due to destroyed connection"));else{var n={penpal:g,id:u,resolution:e,returnValue:t};e===m&&t instanceof Error&&(n.returnValue=x(t),n.returnValueIsError=!0);try{o.postMessage(n,a)}catch(e){throw"DataCloneError"===e.name&&o.postMessage({penpal:g,id:u,resolution:m,returnValue:x(e),returnValueIsError:!0},a),e}}}};new k.Promise((function(e){return e(t[r].apply(t,c))})).then(d(p),d(m))}}};r.addEventListener(v,c),n.then((function(){s=!0,r.removeEventListener(v,c)}))};k.connectToChild=function(e){var t,n=e.url,i=e.appendTo,r=e.methods,o=void 0===r?{}:r,a=e.timeout,s=new W((function(e){t=e})),c=window,u=document.createElement("iframe");(i||document.body).appendChild(u),s.then((function(){u.parentNode&&u.parentNode.removeChild(u)}));var d=u.contentWindow||u.contentDocument.parentWindow,f=function(e){var t,n,i,r=document.location,o=C.exec(e);o?(t=o[1]?o[1]:r.protocol,n=o[2],i=o[4]):(t=r.protocol,n=r.hostname,i=r.port);var a=i&&i!==E[t]?":".concat(i):"";return"".concat(t,"//").concat(n).concat(a)}(n);return{promise:new k.Promise((function(e,i){var r;void 0!==a&&(r=setTimeout((function(){var e=new Error("Connection to child timed out after ".concat(a,"ms"));e.code=b,i(e),t()}),a));var g,p,m={},y=function(t){if(t.source===d&&t.origin===f&&t.data.penpal===l){I("Parent: Received handshake, sending reply"),t.source.postMessage({penpal:h,methodNames:Object.keys(o)},t.origin);var n={localName:"Parent",local:c,remote:d,remoteOrigin:t.origin};p&&p();var i=new W((function(e){s.then(e),p=e}));A(n,o,i),g&&g.forEach((function(e){delete m[e]})),g=t.data.methodNames,T(m,n,g,s),clearTimeout(r),e(m)}};c.addEventListener(v,y),s.then((function(){c.removeEventListener(v,y);var e=new Error("Connection destroyed");e.code=w,i(e)})),I("Parent: Loading iframe"),u.src=n})),iframe:u,destroy:t}},k.connectToParent=function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=t.parentOrigin,i=void 0===n?"*":n,r=t.methods,o=void 0===r?{}:r,a=t.timeout;if(window===window.top){var s=new Error("connectToParent() must be called within an iframe");throw s.code=y,s}var c=new W((function(t){e=t})),u=window,d=u.parent,f=new k.Promise((function(t,n){var r;void 0!==a&&(r=setTimeout((function(){var t=new Error("Connection to parent timed out after ".concat(a,"ms"));t.code=b,n(t),e()}),a));var s=function e(n){if(("*"===i||i===n.origin)&&n.source===d&&n.data.penpal===h){I("Child: Received handshake reply"),u.removeEventListener(v,e);var a={localName:"Child",local:u,remote:d,remoteOrigin:n.origin},s={};A(a,o,c),T(s,a,n.data.methodNames,c),clearTimeout(r),t(s)}};u.addEventListener(v,s),c.then((function(){u.removeEventListener(v,s);var e=new Error("Connection destroyed");e.code=w,n(e)})),I("Child: Sending handshake"),d.postMessage({penpal:l,methodNames:Object.keys(o)},i)}));return{promise:f,destroy:e}};var O=k;d=u.default=O;var M=function(e,t,n,i){return new(n||(n=Promise))((function(r,o){function a(e){try{c(i.next(e))}catch(e){o(e)}}function s(e){try{c(i.throw(e))}catch(e){o(e)}}function c(e){e.done?r(e.value):new n((function(t){t(e.value)})).then(a,s)}c((i=i.apply(e,t||[])).next())}))},N=function(e,t){var n,i,r,o,a={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,i=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(r=a.trys,(r=r.length>0&&r[r.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]<r[3])){a.label=o[1];break}if(6===o[0]&&a.label<r[1]){a.label=r[1],r=o;break}if(r&&a.label<r[2]){a.label=r[2],a.ops.push(o);break}r[2]&&a.ops.pop(),a.trys.pop();continue}o=t.call(e,a)}catch(e){o=[6,e],i=0}finally{n=r=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,s])}}},L=process.env.PORTIS_WIDGET_URL||"https://widget.portis.io",R="por_portis-widget-frame",S="por_portis-container";var D=function(){function e(t,n){this._widgetConfig=t,this._clearProviderSession=n,this._widgetUrl=L,this._onLoginCallback=function(){},this._onLogoutCallback=function(){},this._onErrorCallback=function(){},c(),t.staging?(console.warn("Please note: you are using the Portis STAGING environment."),this._widgetUrl="https://widget-staging.portis.io"):t.feature&&(console.warn("Please note: you are using the Portis FEATURE environment."),this._widgetUrl="https://widget-feature.portis.io"),e._checkIfWidgetAlreadyInitialized()}return e.prototype.getWidget=function(){return M(this,void 0,void 0,(function(){var e;return N(this,(function(t){switch(t.label){case 0:return this.widgetInstance?[3,2]:(this.widgetPromise||(this.widgetPromise=this._initWidget()),e=this,[4,this.widgetPromise]);case 1:e.widgetInstance=t.sent(),t.label=2;case 2:return[2,this.widgetInstance]}}))}))},e.prototype.setDefaultEmail=function(e){this._widgetConfig.defaultEmail=e},e.prototype.setOnLoginCallback=function(e){this._onLoginCallback=e},e.prototype.setOnLogoutCallback=function(e){this._onLogoutCallback=e},e.prototype.setOnActiveWalletChangedCallback=function(e){this._onActiveWalletChangedCallback=e},e.prototype.setOnErrorCallback=function(e){this._onErrorCallback=e},e.prototype.showPortis=function(){return M(this,void 0,void 0,(function(){return N(this,(function(e){switch(e.label){case 0:return[4,this.getWidget()];case 1:return[2,e.sent().communication.showPortis(this._widgetConfig)]}}))}))},e.prototype.getCampaignInfo=function(e){return M(this,void 0,void 0,(function(){return N(this,(function(t){switch(t.label){case 0:return[4,this.getWidget()];case 1:return[2,t.sent().communication.getCampaignInfo(e)]}}))}))},e.prototype.claimVoucher=function(e){return M(this,void 0,void 0,(function(){return N(this,(function(t){switch(t.label){case 0:return[4,this.getWidget()];case 1:return[2,t.sent().communication.claimVoucher(e,this._widgetConfig)]}}))}))},e.prototype.logout=function(){return M(this,void 0,void 0,(function(){return N(this,(function(e){switch(e.label){case 0:return[4,this.getWidget()];case 1:return[2,e.sent().communication.logout()]}}))}))},e.prototype.getExtendedPublicKey=function(e,t){return void 0===e&&(e="m/44'/60'/0'/0/0"),void 0===t&&(t="Ethereum"),M(this,void 0,void 0,(function(){return N(this,(function(n){switch(n.label){case 0:return[4,this.getWidget()];case 1:return[2,n.sent().communication.getExtendedPublicKey(e,t,this._widgetConfig)]}}))}))},e.prototype.importWallet=function(e){return M(this,void 0,void 0,(function(){return N(this,(function(t){switch(t.label){case 0:return[4,this.getWidget()];case 1:return[2,t.sent().communication.importWallet(e,this._widgetConfig)]}}))}))},e.prototype.isLoggedIn=function(){return M(this,void 0,void 0,(function(){return N(this,(function(e){switch(e.label){case 0:return[4,this.getWidget()];case 1:return[2,e.sent().communication.isLoggedIn()]}}))}))},e.prototype.signBitcoinTransaction=function(e){return M(this,void 0,void 0,(function(){return N(this,(function(t){switch(t.label){case 0:return[4,this.getWidget()];case 1:return[2,t.sent().communication.signBitcoinTransaction(e,this._widgetConfig)]}}))}))},e.prototype.showBitcoinWallet=function(e){return void 0===e&&(e="m/49'/0'/0'/0/0"),M(this,void 0,void 0,(function(){return N(this,(function(t){switch(t.label){case 0:return[4,this.getWidget()];case 1:return[2,t.sent().communication.showBitcoinWallet(e,this._widgetConfig)]}}))}))},e.prototype.purchaseERC20=function(e){return M(this,void 0,void 0,(function(){return N(this,(function(t){switch(t.label){case 0:return[4,this.getWidget()];case 1:return[2,t.sent().communication.purchaseERC20(e,this._widgetConfig)]}}))}))},e._checkIfWidgetAlreadyInitialized=function(){document.getElementsByClassName(S).length&&console.warn("An instance of Portis was already initialized. This is probably a mistake. Make sure that you use the same Portis instance throughout your app.")},e.prototype._initWidget=function(){return M(this,void 0,void 0,(function(){var t,n,i,r,o;return N(this,(function(a){switch(a.label){case 0:return[4,s()];case 1:return a.sent(),(t=document.createElement("style")).innerHTML="\n.por_portis-container {\n position: fixed;\n width: 0px;\n height: 0px;\n top: 0px;\n right: 0px;\n z-index: 2147483647;\n}\n\n@media (max-width: 576px) {\n .por_portis-container {\n bottom: 0;\n top: auto;\n }\n}\n\n.por_portis-widget-frame {\n position: fixed;\n width: 375px;\n height: 0;\n top: 20px;\n right: 20px;\n box-shadow: 0 5px 40px rgba(0,0,0,.16);\n border-radius: 8px;\n overflow: hidden;\n z-index: 2147483000;\n}\n\n@media (max-width: 576px) {\n .por_portis-widget-frame {\n bottom: 0;\n top: auto;\n width: 100%;\n right: 0;\n left: 0;\n border-bottom-left-radius: 0;\n border-bottom-right-radius: 0;\n }\n}\n",(n=document.createElement("div")).className=S,(i=document.createElement("div")).id="portis-container-"+Date.now(),i.className=R,n.appendChild(i),document.body.appendChild(n),document.head.appendChild(t),[4,(r=d.connectToChild({url:this._widgetUrl,appendTo:document.getElementById(i.id),methods:{setHeight:this._setHeight.bind(this),getWindowSize:e._getWindowSize.bind(this),onLogin:this._onLogin.bind(this),onLogout:this._onLogout.bind(this),onActiveWalletChanged:this._onActiveWalletChanged.bind(this),hasOnActiveWalletChanged:this.hasOnActiveWalletChanged.bind(this),onError:this._onError.bind(this)}})).promise];case 2:return(o=a.sent()).setSdkConfig(this._widgetConfig),r.iframe.style.position="absolute",r.iframe.style.height="100%",r.iframe.style.width="100%",r.iframe.style.border="0 transparent",[2,{communication:o,widgetFrame:i}]}}))}))},e.prototype._setHeight=function(e){return M(this,void 0,void 0,(function(){return N(this,(function(t){switch(t.label){case 0:return[4,this.getWidget()];case 1:return t.sent().widgetFrame.style.height=e+"px",[2]}}))}))},e._getWindowSize=function(){var e=document.getElementsByTagName("body")[0];return{width:window.innerWidth||document.documentElement.clientWidth||e.clientWidth,height:window.innerHeight||document.documentElement.clientHeight||e.clientHeight}},e.prototype._onLogin=function(e,t,n){this._onLoginCallback&&this._onLoginCallback(e,t,n)},e.prototype._onLogout=function(){this._clearProviderSession(),this._onLogoutCallback&&this._onLogoutCallback()},e.prototype._onActiveWalletChanged=function(e){this._onActiveWalletChangedCallback&&this._onActiveWalletChangedCallback(e)},e.prototype.hasOnActiveWalletChanged=function(){return!!this._onActiveWalletChangedCallback},e.prototype._onError=function(e){this._onErrorCallback&&this._onErrorCallback(e)},e}(),U=function(e,t,n,i){return new(n||(n=Promise))((function(r,o){function a(e){try{c(i.next(e))}catch(e){o(e)}}function s(e){try{c(i.throw(e))}catch(e){o(e)}}function c(e){e.done?r(e.value):new n((function(t){t(e.value)})).then(a,s)}c((i=i.apply(e,t||[])).next())}))},j=function(e,t){var n,i,r,o,a={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,i=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(r=a.trys,(r=r.length>0&&r[r.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]<r[3])){a.label=o[1];break}if(6===o[0]&&a.label<r[1]){a.label=r[1],r=o;break}if(r&&a.label<r[2]){a.label=r[2],a.ops.push(o);break}r[2]&&a.ops.pop(),a.trys.pop();continue}o=t.call(e,a)}catch(e){o=[6,e],i=0}finally{n=r=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,s])}}},B=require("ethereumjs-util"),F=B.addHexPrefix,G=B.stripHexPrefix,V=B.BN,H="0x5208";function q(e,t){return U(this,void 0,void 0,(function(){var n,i,r,o,a;return j(this,(function(s){switch(s.label){case 0:return[4,e.getBlockByNumber("latest",!1)];case 1:return n=s.sent(),[4,z(e,t,n.gasLimit)];case 2:if(i=s.sent(),r=i.safeGas,o=i.simpleSend,a=i.gasLimitSpecified,o||a)return[2,r];s.label=3;case 3:return s.trys.push([3,5,,6]),[4,K(e,t,n.gasLimit,r)];case 4:return[2,s.sent()];case 5:return s.sent(),[2,r];case 6:return[2]}}))}))}function z(e,t,n){return U(this,void 0,void 0,(function(){var i,r,o;return j(this,(function(a){switch(a.label){case 0:return Boolean(t.gas)?[2,{safeGas:t.gas,simpleSend:!1,gasLimitSpecified:!0}]:(i=t.to,Boolean(i)?[4,e.getCode(i)]:[3,2]);case 1:if(r=a.sent(),!r||"0x"===r||"0x0"===r){if(t.data)throw new Error("Trying to call a function on a non-contract address");return[2,{safeGas:H,simpleSend:!0,gasLimitSpecified:!1}]}a.label=2;case 2:return o=J(n),s=o,c=20,u=new V(19),d=new V(c),[2,{safeGas:Q(s.mul(u).div(d)),simpleSend:!1,gasLimitSpecified:!1}]}var s,c,u,d}))}))}function K(e,t,n,i){return U(this,void 0,void 0,(function(){var r;return j(this,(function(o){switch(o.label){case 0:return t.gas=i,r=F,[4,e.estimateGas(t)];case 1:return[2,Y(r.apply(void 0,[o.sent()]),n)]}}))}))}function Y(e,t){var n=J(e),i=J(t).muln(.9),r=n.muln(1.5);return n.gt(i)?Q(n):r.lt(i)?Q(r):Q(i)}function J(e){return new V(G(e),16)}function Q(e){return F(e.toString(16))}var X=function(){function e(e){this.provider=e}return e.prototype.getBlockByNumber=function(e,t){return this.sendAsync("eth_getBlockByNumber",e,t)},e.prototype.getCode=function(e,t){return void 0===t&&(t="latest"),this.sendAsync("eth_getCode",e,t)},e.prototype.estimateGas=function(e){return this.sendAsync("eth_estimateGas",e)},e.prototype.sendAsync=function(e){for(var t=this,n=[],i=1;i<arguments.length;i++)n[i-1]=arguments[i];return new Promise((function(i,r){t.provider.sendAsync({id:42,jsonrpc:"2.0",method:e,params:n},(function(e,t){e?r(e):i(t.result)}))}))},e}(),Z=function(){return Z=Object.assign||function(e){for(var t,n=1,i=arguments.length;n<i;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e},Z.apply(this,arguments)},$=function(e,t,n,i){return new(n||(n=Promise))((function(r,o){function a(e){try{c(i.next(e))}catch(e){o(e)}}function s(e){try{c(i.throw(e))}catch(e){o(e)}}function c(e){e.done?r(e.value):new n((function(t){t(e.value)})).then(a,s)}c((i=i.apply(e,t||[])).next())}))},ee=function(e,t){var n,i,r,o,a={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,i=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(r=a.trys,(r=r.length>0&&r[r.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]<r[3])){a.label=o[1];break}if(6===o[0]&&a.label<r[1]){a.label=r[1],r=o;break}if(r&&a.label<r[2]){a.label=r[2],a.ops.push(o);break}r[2]&&a.ops.pop(),a.trys.pop();continue}o=t.call(e,a)}catch(e){o=[6,e],i=0}finally{n=r=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,s])}}},te=require("web3-provider-engine"),ne=require("web3-provider-engine/dist/es5/subproviders/cache.js"),ie=require("web3-provider-engine/dist/es5/subproviders/fixture.js"),re=require("web3-provider-engine/dist/es5/subproviders/filters.js"),oe=require("web3-provider-engine/dist/es5/subproviders/hooked-wallet.js"),ae=require("web3-provider-engine/dist/es5/subproviders/nonce-tracker.js"),se=require("web3-provider-engine/dist/es5/subproviders/subscriptions.js"),ce=function(){function e(e,t){this.config=e,this._getWidgetCommunication=t,this.provider=this._initProvider()}return e.prototype.setSelectedAddress=function(e){this._selectedAddress=e},e.prototype.changeNetwork=function(e,t){var n=i(e,t);this.clearSubprovider(ae),this.clearSubprovider(ne),this.config.network=n},e.prototype._initProvider=function(){var e=this;if(this.engine)return this.engine;this.engine=new te;var t=new X(this.engine);return this.engine.send=function(t,n){if("string"==typeof t)return new Promise((function(i,r){e.engine.sendAsync({jsonrpc:"2.0",id:42,method:t,params:n||[]},(function(e,t){e?r(e):i(t.result)}))}));if(!n){var i=null;switch(t.method){case"eth_accounts":case"eth_coinbase":i=e._selectedAddress?[e._selectedAddress]:[];break;case"net_version":i=e._network;break;case"eth_uninstallFilter":e.engine.sendAsync(t,(function(e){return e})),i=!0;break;default:var r="The Portis Web3 object does not support synchronous methods like "+t.method+" without a callback parameter.";throw new Error(r)}return{id:t.id,jsonrpc:t.jsonrpc,result:i}}e.engine.sendAsync(t,n)},this.engine.addProvider(new ie({web3_clientVersion:"Portis/v"+this.config.version+"/javascript",net_listening:!0,eth_hashrate:"0x00",eth_mining:!1,eth_syncing:!0})),this.engine.addProvider(new ne),this.engine.addProvider(new se),this.engine.addProvider(new re),this.engine.addProvider(new ae),this.engine.addProvider({setEngine:function(e){return e},handleRequest:function(t,n){return $(e,void 0,void 0,(function(){return ee(this,(function(e){return t.id||(t.id=42),n(),[2]}))}))}}),this.engine.addProvider(new oe({getAccounts:function(t){return $(e,void 0,void 0,(function(){var e,n,i;return ee(this,(function(r){switch(r.label){case 0:return[4,this._getWidgetCommunication()];case 1:return[4,r.sent().getAccounts(this.config)];case 2:return e=r.sent(),n=e.error,i=e.result,!n&&i&&(this._selectedAddress=i[0]),t(n,i),[2]}}))}))},signTransaction:function(t,n){return $(e,void 0,void 0,(function(){var e,i,r;return ee(this,(function(o){switch(o.label){case 0:return[4,this._getWidgetCommunication()];case 1:return[4,o.sent().signTransaction(t,this.config)];case 2:return e=o.sent(),i=e.error,r=e.result,n(i,r),[2]}}))}))},signMessage:function(t,n){return $(e,void 0,void 0,(function(){var e,i,r,o,a;return ee(this,(function(s){switch(s.label){case 0:return[4,this._getWidgetCommunication()];case 1:return e=s.sent(),i=Z({},t,{messageStandard:"signMessage"}),[4,e.signMessage(i,this.config)];case 2:return r=s.sent(),o=r.error,a=r.result,n(o,a),[2]}}))}))},signPersonalMessage:function(t,n){return $(e,void 0,void 0,(function(){var e,i,r,o,a;return ee(this,(function(s){switch(s.label){case 0:return[4,this._getWidgetCommunication()];case 1:return e=s.sent(),i=Z({},t,{messageStandard:"signPersonalMessage"}),[4,e.signMessage(i,this.config)];case 2:return r=s.sent(),o=r.error,a=r.result,n(o,a),[2]}}))}))},signTypedMessage:function(t,n){return $(e,void 0,void 0,(function(){var e,i,r,o,a;return ee(this,(function(s){switch(s.label){case 0:return[4,this._getWidgetCommunication()];case 1:return e=s.sent(),i=Z({},t,{messageStandard:"signTypedMessage"}),[4,e.signMessage(i,this.config)];case 2:return r=s.sent(),o=r.error,a=r.result,n(o,a),[2]}}))}))},signTypedMessageV3:function(t,n){return $(e,void 0,void 0,(function(){var e,i,r,o,a;return ee(this,(function(s){switch(s.label){case 0:return[4,this._getWidgetCommunication()];case 1:return e=s.sent(),i=Z({},t,{messageStandard:"signTypedMessageV3"}),[4,e.signMessage(i,this.config)];case 2:return r=s.sent(),o=r.error,a=r.result,n(o,a),[2]}}))}))},estimateGas:function(n,i){return $(e,void 0,void 0,(function(){var e;return ee(this,(function(r){switch(r.label){case 0:return[4,q(t,n)];case 1:return e=r.sent(),i(null,e),[2]}}))}))},getGasPrice:function(t){return $(e,void 0,void 0,(function(){return ee(this,(function(e){return t(null,""),[2]}))}))}})),this.engine.addProvider({setEngine:function(e){return e},handleRequest:function(t,n,i){return $(e,void 0,void 0,(function(){var e,n,r;return ee(this,(function(o){switch(o.label){case 0:return[4,this._getWidgetCommunication()];case 1:return[4,o.sent().relay(t,this.config)];case 2:return e=o.sent(),n=e.error,r=e.result,"net_version"===t.method&&(this._network=r,this.engine.networkVersion=this._network),i(n,r),[2]}}))}))}}),this.engine.enable=function(){return new Promise((function(t,n){e.engine.sendAsync({method:"eth_accounts"},(function(e,i){e?n(e):t(i.result)}))}))},this.engine.isConnected=function(){return!0},this.engine.isPortis=!0,this.engine.on("error",(function(e){e&&e.message&&e.message.includes("PollingBlockTracker")?console.warn("If you see this warning constantly, there might be an error with your RPC node."):console.error(e)})),this.engine.start(),this.engine},e.prototype.clearSubprovider=function(e){var t=this.provider._providers.find((function(t){return t instanceof e}));this.provider.removeProvider(t),this.provider.addProvider(new e)},e}(),ue=function(e,t,n,i){return new(n||(n=Promise))((function(r,o){function a(e){try{c(i.next(e))}catch(e){o(e)}}function s(e){try{c(i.throw(e))}catch(e){o(e)}}function c(e){e.done?r(e.value):new n((function(t){t(e.value)})).then(a,s)}c((i=i.apply(e,t||[])).next())}))},de=function(e,t){var n,i,r,o,a={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,i=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(r=a.trys,(r=r.length>0&&r[r.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]<r[3])){a.label=o[1];break}if(6===o[0]&&a.label<r[1]){a.label=r[1],r=o;break}if(r&&a.label<r[2]){a.label=r[2],a.ops.push(o);break}r[2]&&a.ops.pop(),a.trys.pop();continue}o=t.call(e,a)}catch(e){o=[6,e],i=0}finally{n=r=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,s])}}},le=["email","reputation"];s().then((function(){document.getElementsByClassName(R).length&&console.warn("Portis script was already loaded. This might cause unexpected behavior. If loading with a <script> tag, please make sure that you only load it once.")})).catch((function(){}));var he=function(){function e(e,t,n){if(void 0===n&&(n={}),!o())return new Proxy(this,{get:function(e,t){return e[t]instanceof Function?function(){}:void 0}});c(),this._validateParams(e,t,n),this._config={dappId:e,network:i(t,n.gasRelay),version:"4.0.7",scope:n.scope,registerPageByDefault:n.registerPageByDefault,staging:n.staging,feature:n.feature},this._getWidgetCommunication=this._getWidgetCommunication.bind(this),this._widgetManagerInstance=new D(this.config,this._clearProviderSession),this._web3ManagerInstance=new ce(this.config,this._getWidgetCommunication),this.setDefaultEmail=this.setDefaultEmail.bind(this),this.changeNetwork=this.changeNetwork.bind(this),this.getWidget=this.getWidget.bind(this),this.onLogin=this.onLogin.bind(this),this.onLogout=this.onLogout.bind(this),this.onActiveWalletChanged=this.onActiveWalletChanged.bind(this),this.onError=this.onError.bind(this),this.showPortis=this.showPortis.bind(this),this.getCampaignInfo=this.getCampaignInfo.bind(this),this.claimVoucher=this.claimVoucher.bind(this),this.getExtendedPublicKey=this.getExtendedPublicKey.bind(this),this.importWallet=this.importWallet.bind(this),this.isLoggedIn=this.isLoggedIn.bind(this),this.signBitcoinTransaction=this.signBitcoinTransaction.bind(this),this.showBitcoinWallet=this.showBitcoinWallet.bind(this)}return Object.defineProperty(e.prototype,"_widgetManager",{get:function(){return this._widgetManagerInstance},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"_web3Manager",{get:function(){return this._web3ManagerInstance},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"config",{get:function(){return this._config},enumerable:!0,configurable:!0}),e.prototype._clearProviderSession=function(){this._web3Manager.setSelectedAddress("")},e.prototype._getWidgetCommunication=function(){return ue(this,void 0,void 0,(function(){return de(this,(function(e){switch(e.label){case 0:return[4,this._widgetManager.getWidget()];case 1:return[2,e.sent().communication]}}))}))},Object.defineProperty(e.prototype,"web3Provider",{get:function(){return this._web3Manager.provider},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"provider",{get:function(){return this.web3Provider},enumerable:!0,configurable:!0}),e.prototype.changeNetwork=function(e,t){this._web3Manager.changeNetwork(e,t)},e.prototype.setDefaultEmail=function(e){this._widgetManager.setDefaultEmail(e)},e.prototype.getWidget=function(){return ue(this,void 0,void 0,(function(){return de(this,(function(e){return[2,this._widgetManager.getWidget()]}))}))},e.prototype.onLogin=function(e){this._widgetManager.setOnLoginCallback(e)},e.prototype.onLogout=function(e){this._widgetManager.setOnLogoutCallback(e)},e.prototype.onActiveWalletChanged=function(e){this._widgetManager.setOnActiveWalletChangedCallback(e)},e.prototype.onError=function(e){this._widgetManager.setOnErrorCallback(e)},e.prototype.showPortis=function(){return ue(this,void 0,void 0,(function(){return de(this,(function(e){return[2,this._widgetManager.showPortis()]}))}))},e.prototype.getCampaignInfo=function(e){return ue(this,void 0,void 0,(function(){return de(this,(function(t){return[2,this._widgetManager.getCampaignInfo(e)]}))}))},e.prototype.claimVoucher=function(e){return ue(this,void 0,void 0,(function(){return de(this,(function(t){return[2,this._widgetManager.claimVoucher(e)]}))}))},e.prototype.logout=function(){return ue(this,void 0,void 0,(function(){return de(this,(function(e){return[2,this._widgetManager.logout()]}))}))},e.prototype.getExtendedPublicKey=function(e,t){return void 0===e&&(e="m/44'/60'/0'/0/0"),void 0===t&&(t="Ethereum"),ue(this,void 0,void 0,(function(){return de(this,(function(n){return[2,this._widgetManager.getExtendedPublicKey(e,t)]}))}))},e.prototype.importWallet=function(e){return ue(this,void 0,void 0,(function(){return de(this,(function(t){return[2,this._widgetManager.importWallet(e)]}))}))},e.prototype.isLoggedIn=function(){return ue(this,void 0,void 0,(function(){return de(this,(function(e){return[2,this._widgetManager.isLoggedIn()]}))}))},e.prototype.signBitcoinTransaction=function(e){return ue(this,void 0,void 0,(function(){return de(this,(function(t){return[2,this._widgetManager.signBitcoinTransaction(e)]}))}))},e.prototype.showBitcoinWallet=function(e){return void 0===e&&(e="m/49'/0'/0'/0/0"),ue(this,void 0,void 0,(function(){return de(this,(function(t){return[2,this._widgetManager.showBitcoinWallet(e)]}))}))},e.prototype._validateParams=function(e,t,n){if(!e)throw new Error("[Portis] 'dappId' is required. Get your dappId here: https://dashboard.portis.io");if(!t)throw new Error("[Portis] 'network' is required. Read more about it here: https://docs.portis.io/#/configuration?id=network");if(n.scope){if(!Array.isArray(n.scope))throw new Error("[Portis] 'scope' must be an array. Read more about it here: https://docs.portis.io/#/configuration?id=scope");if(n.scope.filter((function(e){return le.indexOf(e)<0})).length>0)throw new Error("[Portis] invalid 'scope' parameter. Read more about it here: https://docs.portis.io/#/configuration?id=scope")}if(void 0!==n.registerPageByDefault&&"boolean"!=typeof n.registerPageByDefault)throw new Error("[Portis] invalid 'registerPageByDefault' parameter, must be a boolean. Read more about it here: https://docs.portis.io/#/configuration?id=registerPageByDefault")},e}(),fe=he;function ge(i,r){var o=i.chainId,a=i.portisParams;return e(this,void 0,void 0,(function(){var e,i;return t(this,(function(t){switch(t.label){case 0:if(!(null==a?void 0:a.id))throw new Error("uAuthParams is not valid.");switch(e="",o){case 1:default:e="mainnet";break;case 5:e="goerli"}return[4,(i=new fe(a.id,e,a.config)).provider.enable()];case 1:return t.sent(),i.provider._portis=i,i.provider.on("connect",r.connect),i.provider.on("disconnect",r.disconnect),i.provider.on("accountsChanged",r.accountsChanged),i.provider.on("chainChanged",r.chainChanged),i.provider.on("message",r.message),[2,n(i.provider)]}}))}))}export{ge as default};
1
+ import{_ as e,a as t,d as n}from"./index-b869aac9.js";import"@ethersproject/providers";import"@ethersproject/constants";import"@ethersproject/contracts";import"@ethersproject/address";import"valtio";function i(e,t){var n="string"==typeof e?Object.assign({},r[e]):e;if("object"!=typeof n)throw new Error("[Portis] illegal 'network' parameter. Read more about it here: https://docs.portis.io/#/configuration?id=network");if(!n.nodeUrl)throw new Error("[Portis] 'nodeUrl' is required. Read more about it here: https://docs.portis.io/#/configuration?id=network");if(t&&!n.gasRelayHubAddress)throw new Error("[Portis] can't find default gas relay hub for "+e);return"string"!=typeof e||t||delete n.gasRelayHubAddress,n}var r={mainnet:{nodeUrl:"https://mainnet.infura.io/v3/faa4639b090f46499f29d894da0551a0",chainId:"1",gasRelayHubAddress:"0xD216153c06E857cD7f72665E0aF1d7D82172F494"},ropsten:{nodeUrl:"https://ropsten.infura.io/v3/faa4639b090f46499f29d894da0551a0",chainId:"3",gasRelayHubAddress:"0xD216153c06E857cD7f72665E0aF1d7D82172F494"},rinkeby:{nodeUrl:"https://rinkeby.infura.io/v3/faa4639b090f46499f29d894da0551a0",chainId:"4",gasRelayHubAddress:"0xD216153c06E857cD7f72665E0aF1d7D82172F494"},goerli:{nodeUrl:"https://goerli.infura.io/v3/faa4639b090f46499f29d894da0551a0",chainId:"5"},ubiq:{nodeUrl:"https://rpc1.ubiqscan.io",chainId:"8"},thundercoreTestnet:{nodeUrl:"https://testnet-rpc.thundercore.com:8544",chainId:"18"},orchid:{nodeUrl:"https://public-node.rsk.co",chainId:"30"},orchidTestnet:{nodeUrl:"https://public-node.testnet.rsk.co",chainId:"31"},kovan:{nodeUrl:"https://kovan.infura.io/v3/faa4639b090f46499f29d894da0551a0",chainId:"42",gasRelayHubAddress:"0xD216153c06E857cD7f72665E0aF1d7D82172F494"},classic:{nodeUrl:"https://ethereumclassic.network",chainId:"61"},sokol:{nodeUrl:"https://sokol.poa.network",chainId:"77"},core:{nodeUrl:"https://core.poa.network",chainId:"99"},xdai:{nodeUrl:"https://dai.poa.network",chainId:"100",gasRelayHubAddress:"0xD216153c06E857cD7f72665E0aF1d7D82172F494"},thundercore:{nodeUrl:"https://mainnet-rpc.thundercore.com",chainId:"108"},fuse:{nodeUrl:"https://rpc.fusenet.io",chainId:"122"},lightstreams:{nodeUrl:"https://node.mainnet.lightstreams.io",chainId:"163"},matic:{nodeUrl:"https://polygon-rpc.com",chainId:"137"},maticMumbai:{nodeUrl:"https://rpc-mumbai.matic.today",chainId:"80001"},maticAlpha:{nodeUrl:"https://alpha.ethereum.matic.network",chainId:"4626"},maticTestnet:{nodeUrl:"https://testnet2.matic.network",chainId:"8995"}},o=function(){return!("undefined"==typeof window||!window.document)},a=!1;function s(){return new Promise((function(e,t){o()?a?e():["loaded","interactive","complete"].indexOf(document.readyState)>-1?(a=!0,e()):window.addEventListener("load",(function(){a=!0,e()}),!1):t()}))}function c(){var e="localhost"===location.hostname||"127.0.0.1"===location.hostname,t="https:"===location.protocol;if(!(e||t))throw"[Portis] Access to the WebCrypto API is restricted to secure origins.\nIf this is a development environment please use http://localhost:"+location.port+" instead.\nOtherwise, please use an SSL certificate."}var u={};Object.defineProperty(u,"__esModule",{value:!0});var d=u.default=u.ERR_NOT_IN_IFRAME=u.ERR_CONNECTION_TIMEOUT=u.ERR_CONNECTION_DESTROYED=void 0,l="handshake",h="handshake-reply",f="call",g="reply",p="fulfilled",m="rejected",v="message",w="ConnectionDestroyed";u.ERR_CONNECTION_DESTROYED=w;var b="ConnectionTimeout";u.ERR_CONNECTION_TIMEOUT=b;var y="NotInIframe";u.ERR_NOT_IN_IFRAME=y;var _,E={"http:":"80","https:":"443"},C=/^(https?:)?\/\/([^/:]+)(:(\d+))?/,k={ERR_CONNECTION_DESTROYED:w,ERR_CONNECTION_TIMEOUT:b,ERR_NOT_IN_IFRAME:y,Promise:function(){try{return window?window.Promise:null}catch(e){return null}}(),debug:!1},P=(_=0,function(){return++_}),I=function(){if(k.debug){for(var e,t=arguments.length,n=new Array(t),i=0;i<t;i++)n[i]=arguments[i];(e=console).log.apply(e,["[Penpal]"].concat(n))}},W=function(e){var t=[];return e((function(){t.forEach((function(e){e()}))})),{then:function(e){t.push(e)}}},x=function(e){return{name:e.name,message:e.message,stack:e.stack}},T=function(e,t,n,i){var r=t.localName,o=t.local,a=t.remote,s=t.remoteOrigin,c=!1;I("".concat(r,": Connecting call sender"));var u=function(e){return function(){for(var t=arguments.length,n=new Array(t),i=0;i<t;i++)n[i]=arguments[i];if(I("".concat(r,": Sending ").concat(e,"() call")),c){var u=new Error("Unable to send ".concat(e,"() call due ")+"to destroyed connection");throw u.code=w,u}return new k.Promise((function(t,i){var c=P();o.addEventListener(v,(function n(u){if(u.source===a&&u.origin===s&&u.data.penpal===g&&u.data.id===c){I("".concat(r,": Received ").concat(e,"() reply")),o.removeEventListener(v,n);var d=u.data.returnValue;u.data.returnValueIsError&&(l=d,h=new Error,Object.keys(l).forEach((function(e){return h[e]=l[e]})),d=h),(u.data.resolution===p?t:i)(d)}var l,h})),a.postMessage({penpal:f,id:c,methodName:e,args:n},s)}))}};i.then((function(){c=!0})),n.reduce((function(e,t){return e[t]=u(t),e}),e)},A=function(e,t,n){var i=e.localName,r=e.local,o=e.remote,a=e.remoteOrigin,s=!1;I("".concat(i,": Connecting call receiver"));var c=function(e){if(e.source===o&&e.origin===a&&e.data.penpal===f){var n=e.data,r=n.methodName,c=n.args,u=n.id;if(I("".concat(i,": Received ").concat(r,"() call")),r in t){var d=function(e){return function(t){if(I("".concat(i,": Sending ").concat(r,"() reply")),s)I("".concat(i,": Unable to send ").concat(r,"() reply due to destroyed connection"));else{var n={penpal:g,id:u,resolution:e,returnValue:t};e===m&&t instanceof Error&&(n.returnValue=x(t),n.returnValueIsError=!0);try{o.postMessage(n,a)}catch(e){throw"DataCloneError"===e.name&&o.postMessage({penpal:g,id:u,resolution:m,returnValue:x(e),returnValueIsError:!0},a),e}}}};new k.Promise((function(e){return e(t[r].apply(t,c))})).then(d(p),d(m))}}};r.addEventListener(v,c),n.then((function(){s=!0,r.removeEventListener(v,c)}))};k.connectToChild=function(e){var t,n=e.url,i=e.appendTo,r=e.methods,o=void 0===r?{}:r,a=e.timeout,s=new W((function(e){t=e})),c=window,u=document.createElement("iframe");(i||document.body).appendChild(u),s.then((function(){u.parentNode&&u.parentNode.removeChild(u)}));var d=u.contentWindow||u.contentDocument.parentWindow,f=function(e){var t,n,i,r=document.location,o=C.exec(e);o?(t=o[1]?o[1]:r.protocol,n=o[2],i=o[4]):(t=r.protocol,n=r.hostname,i=r.port);var a=i&&i!==E[t]?":".concat(i):"";return"".concat(t,"//").concat(n).concat(a)}(n);return{promise:new k.Promise((function(e,i){var r;void 0!==a&&(r=setTimeout((function(){var e=new Error("Connection to child timed out after ".concat(a,"ms"));e.code=b,i(e),t()}),a));var g,p,m={},y=function(t){if(t.source===d&&t.origin===f&&t.data.penpal===l){I("Parent: Received handshake, sending reply"),t.source.postMessage({penpal:h,methodNames:Object.keys(o)},t.origin);var n={localName:"Parent",local:c,remote:d,remoteOrigin:t.origin};p&&p();var i=new W((function(e){s.then(e),p=e}));A(n,o,i),g&&g.forEach((function(e){delete m[e]})),g=t.data.methodNames,T(m,n,g,s),clearTimeout(r),e(m)}};c.addEventListener(v,y),s.then((function(){c.removeEventListener(v,y);var e=new Error("Connection destroyed");e.code=w,i(e)})),I("Parent: Loading iframe"),u.src=n})),iframe:u,destroy:t}},k.connectToParent=function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=t.parentOrigin,i=void 0===n?"*":n,r=t.methods,o=void 0===r?{}:r,a=t.timeout;if(window===window.top){var s=new Error("connectToParent() must be called within an iframe");throw s.code=y,s}var c=new W((function(t){e=t})),u=window,d=u.parent,f=new k.Promise((function(t,n){var r;void 0!==a&&(r=setTimeout((function(){var t=new Error("Connection to parent timed out after ".concat(a,"ms"));t.code=b,n(t),e()}),a));var s=function e(n){if(("*"===i||i===n.origin)&&n.source===d&&n.data.penpal===h){I("Child: Received handshake reply"),u.removeEventListener(v,e);var a={localName:"Child",local:u,remote:d,remoteOrigin:n.origin},s={};A(a,o,c),T(s,a,n.data.methodNames,c),clearTimeout(r),t(s)}};u.addEventListener(v,s),c.then((function(){u.removeEventListener(v,s);var e=new Error("Connection destroyed");e.code=w,n(e)})),I("Child: Sending handshake"),d.postMessage({penpal:l,methodNames:Object.keys(o)},i)}));return{promise:f,destroy:e}};var O=k;d=u.default=O;var M=function(e,t,n,i){return new(n||(n=Promise))((function(r,o){function a(e){try{c(i.next(e))}catch(e){o(e)}}function s(e){try{c(i.throw(e))}catch(e){o(e)}}function c(e){e.done?r(e.value):new n((function(t){t(e.value)})).then(a,s)}c((i=i.apply(e,t||[])).next())}))},N=function(e,t){var n,i,r,o,a={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,i=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(r=a.trys,(r=r.length>0&&r[r.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]<r[3])){a.label=o[1];break}if(6===o[0]&&a.label<r[1]){a.label=r[1],r=o;break}if(r&&a.label<r[2]){a.label=r[2],a.ops.push(o);break}r[2]&&a.ops.pop(),a.trys.pop();continue}o=t.call(e,a)}catch(e){o=[6,e],i=0}finally{n=r=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,s])}}},L=process.env.PORTIS_WIDGET_URL||"https://widget.portis.io",R="por_portis-widget-frame",S="por_portis-container";var D=function(){function e(t,n){this._widgetConfig=t,this._clearProviderSession=n,this._widgetUrl=L,this._onLoginCallback=function(){},this._onLogoutCallback=function(){},this._onErrorCallback=function(){},c(),t.staging?(console.warn("Please note: you are using the Portis STAGING environment."),this._widgetUrl="https://widget-staging.portis.io"):t.feature&&(console.warn("Please note: you are using the Portis FEATURE environment."),this._widgetUrl="https://widget-feature.portis.io"),e._checkIfWidgetAlreadyInitialized()}return e.prototype.getWidget=function(){return M(this,void 0,void 0,(function(){var e;return N(this,(function(t){switch(t.label){case 0:return this.widgetInstance?[3,2]:(this.widgetPromise||(this.widgetPromise=this._initWidget()),e=this,[4,this.widgetPromise]);case 1:e.widgetInstance=t.sent(),t.label=2;case 2:return[2,this.widgetInstance]}}))}))},e.prototype.setDefaultEmail=function(e){this._widgetConfig.defaultEmail=e},e.prototype.setOnLoginCallback=function(e){this._onLoginCallback=e},e.prototype.setOnLogoutCallback=function(e){this._onLogoutCallback=e},e.prototype.setOnActiveWalletChangedCallback=function(e){this._onActiveWalletChangedCallback=e},e.prototype.setOnErrorCallback=function(e){this._onErrorCallback=e},e.prototype.showPortis=function(){return M(this,void 0,void 0,(function(){return N(this,(function(e){switch(e.label){case 0:return[4,this.getWidget()];case 1:return[2,e.sent().communication.showPortis(this._widgetConfig)]}}))}))},e.prototype.getCampaignInfo=function(e){return M(this,void 0,void 0,(function(){return N(this,(function(t){switch(t.label){case 0:return[4,this.getWidget()];case 1:return[2,t.sent().communication.getCampaignInfo(e)]}}))}))},e.prototype.claimVoucher=function(e){return M(this,void 0,void 0,(function(){return N(this,(function(t){switch(t.label){case 0:return[4,this.getWidget()];case 1:return[2,t.sent().communication.claimVoucher(e,this._widgetConfig)]}}))}))},e.prototype.logout=function(){return M(this,void 0,void 0,(function(){return N(this,(function(e){switch(e.label){case 0:return[4,this.getWidget()];case 1:return[2,e.sent().communication.logout()]}}))}))},e.prototype.getExtendedPublicKey=function(e,t){return void 0===e&&(e="m/44'/60'/0'/0/0"),void 0===t&&(t="Ethereum"),M(this,void 0,void 0,(function(){return N(this,(function(n){switch(n.label){case 0:return[4,this.getWidget()];case 1:return[2,n.sent().communication.getExtendedPublicKey(e,t,this._widgetConfig)]}}))}))},e.prototype.importWallet=function(e){return M(this,void 0,void 0,(function(){return N(this,(function(t){switch(t.label){case 0:return[4,this.getWidget()];case 1:return[2,t.sent().communication.importWallet(e,this._widgetConfig)]}}))}))},e.prototype.isLoggedIn=function(){return M(this,void 0,void 0,(function(){return N(this,(function(e){switch(e.label){case 0:return[4,this.getWidget()];case 1:return[2,e.sent().communication.isLoggedIn()]}}))}))},e.prototype.signBitcoinTransaction=function(e){return M(this,void 0,void 0,(function(){return N(this,(function(t){switch(t.label){case 0:return[4,this.getWidget()];case 1:return[2,t.sent().communication.signBitcoinTransaction(e,this._widgetConfig)]}}))}))},e.prototype.showBitcoinWallet=function(e){return void 0===e&&(e="m/49'/0'/0'/0/0"),M(this,void 0,void 0,(function(){return N(this,(function(t){switch(t.label){case 0:return[4,this.getWidget()];case 1:return[2,t.sent().communication.showBitcoinWallet(e,this._widgetConfig)]}}))}))},e.prototype.purchaseERC20=function(e){return M(this,void 0,void 0,(function(){return N(this,(function(t){switch(t.label){case 0:return[4,this.getWidget()];case 1:return[2,t.sent().communication.purchaseERC20(e,this._widgetConfig)]}}))}))},e._checkIfWidgetAlreadyInitialized=function(){document.getElementsByClassName(S).length&&console.warn("An instance of Portis was already initialized. This is probably a mistake. Make sure that you use the same Portis instance throughout your app.")},e.prototype._initWidget=function(){return M(this,void 0,void 0,(function(){var t,n,i,r,o;return N(this,(function(a){switch(a.label){case 0:return[4,s()];case 1:return a.sent(),(t=document.createElement("style")).innerHTML="\n.por_portis-container {\n position: fixed;\n width: 0px;\n height: 0px;\n top: 0px;\n right: 0px;\n z-index: 2147483647;\n}\n\n@media (max-width: 576px) {\n .por_portis-container {\n bottom: 0;\n top: auto;\n }\n}\n\n.por_portis-widget-frame {\n position: fixed;\n width: 375px;\n height: 0;\n top: 20px;\n right: 20px;\n box-shadow: 0 5px 40px rgba(0,0,0,.16);\n border-radius: 8px;\n overflow: hidden;\n z-index: 2147483000;\n}\n\n@media (max-width: 576px) {\n .por_portis-widget-frame {\n bottom: 0;\n top: auto;\n width: 100%;\n right: 0;\n left: 0;\n border-bottom-left-radius: 0;\n border-bottom-right-radius: 0;\n }\n}\n",(n=document.createElement("div")).className=S,(i=document.createElement("div")).id="portis-container-"+Date.now(),i.className=R,n.appendChild(i),document.body.appendChild(n),document.head.appendChild(t),[4,(r=d.connectToChild({url:this._widgetUrl,appendTo:document.getElementById(i.id),methods:{setHeight:this._setHeight.bind(this),getWindowSize:e._getWindowSize.bind(this),onLogin:this._onLogin.bind(this),onLogout:this._onLogout.bind(this),onActiveWalletChanged:this._onActiveWalletChanged.bind(this),hasOnActiveWalletChanged:this.hasOnActiveWalletChanged.bind(this),onError:this._onError.bind(this)}})).promise];case 2:return(o=a.sent()).setSdkConfig(this._widgetConfig),r.iframe.style.position="absolute",r.iframe.style.height="100%",r.iframe.style.width="100%",r.iframe.style.border="0 transparent",[2,{communication:o,widgetFrame:i}]}}))}))},e.prototype._setHeight=function(e){return M(this,void 0,void 0,(function(){return N(this,(function(t){switch(t.label){case 0:return[4,this.getWidget()];case 1:return t.sent().widgetFrame.style.height=e+"px",[2]}}))}))},e._getWindowSize=function(){var e=document.getElementsByTagName("body")[0];return{width:window.innerWidth||document.documentElement.clientWidth||e.clientWidth,height:window.innerHeight||document.documentElement.clientHeight||e.clientHeight}},e.prototype._onLogin=function(e,t,n){this._onLoginCallback&&this._onLoginCallback(e,t,n)},e.prototype._onLogout=function(){this._clearProviderSession(),this._onLogoutCallback&&this._onLogoutCallback()},e.prototype._onActiveWalletChanged=function(e){this._onActiveWalletChangedCallback&&this._onActiveWalletChangedCallback(e)},e.prototype.hasOnActiveWalletChanged=function(){return!!this._onActiveWalletChangedCallback},e.prototype._onError=function(e){this._onErrorCallback&&this._onErrorCallback(e)},e}(),U=function(e,t,n,i){return new(n||(n=Promise))((function(r,o){function a(e){try{c(i.next(e))}catch(e){o(e)}}function s(e){try{c(i.throw(e))}catch(e){o(e)}}function c(e){e.done?r(e.value):new n((function(t){t(e.value)})).then(a,s)}c((i=i.apply(e,t||[])).next())}))},j=function(e,t){var n,i,r,o,a={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,i=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(r=a.trys,(r=r.length>0&&r[r.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]<r[3])){a.label=o[1];break}if(6===o[0]&&a.label<r[1]){a.label=r[1],r=o;break}if(r&&a.label<r[2]){a.label=r[2],a.ops.push(o);break}r[2]&&a.ops.pop(),a.trys.pop();continue}o=t.call(e,a)}catch(e){o=[6,e],i=0}finally{n=r=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,s])}}},B=require("ethereumjs-util"),F=B.addHexPrefix,G=B.stripHexPrefix,V=B.BN,H="0x5208";function q(e,t){return U(this,void 0,void 0,(function(){var n,i,r,o,a;return j(this,(function(s){switch(s.label){case 0:return[4,e.getBlockByNumber("latest",!1)];case 1:return n=s.sent(),[4,z(e,t,n.gasLimit)];case 2:if(i=s.sent(),r=i.safeGas,o=i.simpleSend,a=i.gasLimitSpecified,o||a)return[2,r];s.label=3;case 3:return s.trys.push([3,5,,6]),[4,K(e,t,n.gasLimit,r)];case 4:return[2,s.sent()];case 5:return s.sent(),[2,r];case 6:return[2]}}))}))}function z(e,t,n){return U(this,void 0,void 0,(function(){var i,r,o;return j(this,(function(a){switch(a.label){case 0:return Boolean(t.gas)?[2,{safeGas:t.gas,simpleSend:!1,gasLimitSpecified:!0}]:(i=t.to,Boolean(i)?[4,e.getCode(i)]:[3,2]);case 1:if(r=a.sent(),!r||"0x"===r||"0x0"===r){if(t.data)throw new Error("Trying to call a function on a non-contract address");return[2,{safeGas:H,simpleSend:!0,gasLimitSpecified:!1}]}a.label=2;case 2:return o=J(n),s=o,c=20,u=new V(19),d=new V(c),[2,{safeGas:Q(s.mul(u).div(d)),simpleSend:!1,gasLimitSpecified:!1}]}var s,c,u,d}))}))}function K(e,t,n,i){return U(this,void 0,void 0,(function(){var r;return j(this,(function(o){switch(o.label){case 0:return t.gas=i,r=F,[4,e.estimateGas(t)];case 1:return[2,Y(r.apply(void 0,[o.sent()]),n)]}}))}))}function Y(e,t){var n=J(e),i=J(t).muln(.9),r=n.muln(1.5);return n.gt(i)?Q(n):r.lt(i)?Q(r):Q(i)}function J(e){return new V(G(e),16)}function Q(e){return F(e.toString(16))}var X=function(){function e(e){this.provider=e}return e.prototype.getBlockByNumber=function(e,t){return this.sendAsync("eth_getBlockByNumber",e,t)},e.prototype.getCode=function(e,t){return void 0===t&&(t="latest"),this.sendAsync("eth_getCode",e,t)},e.prototype.estimateGas=function(e){return this.sendAsync("eth_estimateGas",e)},e.prototype.sendAsync=function(e){for(var t=this,n=[],i=1;i<arguments.length;i++)n[i-1]=arguments[i];return new Promise((function(i,r){t.provider.sendAsync({id:42,jsonrpc:"2.0",method:e,params:n},(function(e,t){e?r(e):i(t.result)}))}))},e}(),Z=function(){return Z=Object.assign||function(e){for(var t,n=1,i=arguments.length;n<i;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e},Z.apply(this,arguments)},$=function(e,t,n,i){return new(n||(n=Promise))((function(r,o){function a(e){try{c(i.next(e))}catch(e){o(e)}}function s(e){try{c(i.throw(e))}catch(e){o(e)}}function c(e){e.done?r(e.value):new n((function(t){t(e.value)})).then(a,s)}c((i=i.apply(e,t||[])).next())}))},ee=function(e,t){var n,i,r,o,a={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,i=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(r=a.trys,(r=r.length>0&&r[r.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]<r[3])){a.label=o[1];break}if(6===o[0]&&a.label<r[1]){a.label=r[1],r=o;break}if(r&&a.label<r[2]){a.label=r[2],a.ops.push(o);break}r[2]&&a.ops.pop(),a.trys.pop();continue}o=t.call(e,a)}catch(e){o=[6,e],i=0}finally{n=r=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,s])}}},te=require("web3-provider-engine"),ne=require("web3-provider-engine/dist/es5/subproviders/cache.js"),ie=require("web3-provider-engine/dist/es5/subproviders/fixture.js"),re=require("web3-provider-engine/dist/es5/subproviders/filters.js"),oe=require("web3-provider-engine/dist/es5/subproviders/hooked-wallet.js"),ae=require("web3-provider-engine/dist/es5/subproviders/nonce-tracker.js"),se=require("web3-provider-engine/dist/es5/subproviders/subscriptions.js"),ce=function(){function e(e,t){this.config=e,this._getWidgetCommunication=t,this.provider=this._initProvider()}return e.prototype.setSelectedAddress=function(e){this._selectedAddress=e},e.prototype.changeNetwork=function(e,t){var n=i(e,t);this.clearSubprovider(ae),this.clearSubprovider(ne),this.config.network=n},e.prototype._initProvider=function(){var e=this;if(this.engine)return this.engine;this.engine=new te;var t=new X(this.engine);return this.engine.send=function(t,n){if("string"==typeof t)return new Promise((function(i,r){e.engine.sendAsync({jsonrpc:"2.0",id:42,method:t,params:n||[]},(function(e,t){e?r(e):i(t.result)}))}));if(!n){var i=null;switch(t.method){case"eth_accounts":case"eth_coinbase":i=e._selectedAddress?[e._selectedAddress]:[];break;case"net_version":i=e._network;break;case"eth_uninstallFilter":e.engine.sendAsync(t,(function(e){return e})),i=!0;break;default:var r="The Portis Web3 object does not support synchronous methods like "+t.method+" without a callback parameter.";throw new Error(r)}return{id:t.id,jsonrpc:t.jsonrpc,result:i}}e.engine.sendAsync(t,n)},this.engine.addProvider(new ie({web3_clientVersion:"Portis/v"+this.config.version+"/javascript",net_listening:!0,eth_hashrate:"0x00",eth_mining:!1,eth_syncing:!0})),this.engine.addProvider(new ne),this.engine.addProvider(new se),this.engine.addProvider(new re),this.engine.addProvider(new ae),this.engine.addProvider({setEngine:function(e){return e},handleRequest:function(t,n){return $(e,void 0,void 0,(function(){return ee(this,(function(e){return t.id||(t.id=42),n(),[2]}))}))}}),this.engine.addProvider(new oe({getAccounts:function(t){return $(e,void 0,void 0,(function(){var e,n,i;return ee(this,(function(r){switch(r.label){case 0:return[4,this._getWidgetCommunication()];case 1:return[4,r.sent().getAccounts(this.config)];case 2:return e=r.sent(),n=e.error,i=e.result,!n&&i&&(this._selectedAddress=i[0]),t(n,i),[2]}}))}))},signTransaction:function(t,n){return $(e,void 0,void 0,(function(){var e,i,r;return ee(this,(function(o){switch(o.label){case 0:return[4,this._getWidgetCommunication()];case 1:return[4,o.sent().signTransaction(t,this.config)];case 2:return e=o.sent(),i=e.error,r=e.result,n(i,r),[2]}}))}))},signMessage:function(t,n){return $(e,void 0,void 0,(function(){var e,i,r,o,a;return ee(this,(function(s){switch(s.label){case 0:return[4,this._getWidgetCommunication()];case 1:return e=s.sent(),i=Z({},t,{messageStandard:"signMessage"}),[4,e.signMessage(i,this.config)];case 2:return r=s.sent(),o=r.error,a=r.result,n(o,a),[2]}}))}))},signPersonalMessage:function(t,n){return $(e,void 0,void 0,(function(){var e,i,r,o,a;return ee(this,(function(s){switch(s.label){case 0:return[4,this._getWidgetCommunication()];case 1:return e=s.sent(),i=Z({},t,{messageStandard:"signPersonalMessage"}),[4,e.signMessage(i,this.config)];case 2:return r=s.sent(),o=r.error,a=r.result,n(o,a),[2]}}))}))},signTypedMessage:function(t,n){return $(e,void 0,void 0,(function(){var e,i,r,o,a;return ee(this,(function(s){switch(s.label){case 0:return[4,this._getWidgetCommunication()];case 1:return e=s.sent(),i=Z({},t,{messageStandard:"signTypedMessage"}),[4,e.signMessage(i,this.config)];case 2:return r=s.sent(),o=r.error,a=r.result,n(o,a),[2]}}))}))},signTypedMessageV3:function(t,n){return $(e,void 0,void 0,(function(){var e,i,r,o,a;return ee(this,(function(s){switch(s.label){case 0:return[4,this._getWidgetCommunication()];case 1:return e=s.sent(),i=Z({},t,{messageStandard:"signTypedMessageV3"}),[4,e.signMessage(i,this.config)];case 2:return r=s.sent(),o=r.error,a=r.result,n(o,a),[2]}}))}))},estimateGas:function(n,i){return $(e,void 0,void 0,(function(){var e;return ee(this,(function(r){switch(r.label){case 0:return[4,q(t,n)];case 1:return e=r.sent(),i(null,e),[2]}}))}))},getGasPrice:function(t){return $(e,void 0,void 0,(function(){return ee(this,(function(e){return t(null,""),[2]}))}))}})),this.engine.addProvider({setEngine:function(e){return e},handleRequest:function(t,n,i){return $(e,void 0,void 0,(function(){var e,n,r;return ee(this,(function(o){switch(o.label){case 0:return[4,this._getWidgetCommunication()];case 1:return[4,o.sent().relay(t,this.config)];case 2:return e=o.sent(),n=e.error,r=e.result,"net_version"===t.method&&(this._network=r,this.engine.networkVersion=this._network),i(n,r),[2]}}))}))}}),this.engine.enable=function(){return new Promise((function(t,n){e.engine.sendAsync({method:"eth_accounts"},(function(e,i){e?n(e):t(i.result)}))}))},this.engine.isConnected=function(){return!0},this.engine.isPortis=!0,this.engine.on("error",(function(e){e&&e.message&&e.message.includes("PollingBlockTracker")?console.warn("If you see this warning constantly, there might be an error with your RPC node."):console.error(e)})),this.engine.start(),this.engine},e.prototype.clearSubprovider=function(e){var t=this.provider._providers.find((function(t){return t instanceof e}));this.provider.removeProvider(t),this.provider.addProvider(new e)},e}(),ue=function(e,t,n,i){return new(n||(n=Promise))((function(r,o){function a(e){try{c(i.next(e))}catch(e){o(e)}}function s(e){try{c(i.throw(e))}catch(e){o(e)}}function c(e){e.done?r(e.value):new n((function(t){t(e.value)})).then(a,s)}c((i=i.apply(e,t||[])).next())}))},de=function(e,t){var n,i,r,o,a={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,i=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(r=a.trys,(r=r.length>0&&r[r.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]<r[3])){a.label=o[1];break}if(6===o[0]&&a.label<r[1]){a.label=r[1],r=o;break}if(r&&a.label<r[2]){a.label=r[2],a.ops.push(o);break}r[2]&&a.ops.pop(),a.trys.pop();continue}o=t.call(e,a)}catch(e){o=[6,e],i=0}finally{n=r=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,s])}}},le=["email","reputation"];s().then((function(){document.getElementsByClassName(R).length&&console.warn("Portis script was already loaded. This might cause unexpected behavior. If loading with a <script> tag, please make sure that you only load it once.")})).catch((function(){}));var he=function(){function e(e,t,n){if(void 0===n&&(n={}),!o())return new Proxy(this,{get:function(e,t){return e[t]instanceof Function?function(){}:void 0}});c(),this._validateParams(e,t,n),this._config={dappId:e,network:i(t,n.gasRelay),version:"4.0.7",scope:n.scope,registerPageByDefault:n.registerPageByDefault,staging:n.staging,feature:n.feature},this._getWidgetCommunication=this._getWidgetCommunication.bind(this),this._widgetManagerInstance=new D(this.config,this._clearProviderSession),this._web3ManagerInstance=new ce(this.config,this._getWidgetCommunication),this.setDefaultEmail=this.setDefaultEmail.bind(this),this.changeNetwork=this.changeNetwork.bind(this),this.getWidget=this.getWidget.bind(this),this.onLogin=this.onLogin.bind(this),this.onLogout=this.onLogout.bind(this),this.onActiveWalletChanged=this.onActiveWalletChanged.bind(this),this.onError=this.onError.bind(this),this.showPortis=this.showPortis.bind(this),this.getCampaignInfo=this.getCampaignInfo.bind(this),this.claimVoucher=this.claimVoucher.bind(this),this.getExtendedPublicKey=this.getExtendedPublicKey.bind(this),this.importWallet=this.importWallet.bind(this),this.isLoggedIn=this.isLoggedIn.bind(this),this.signBitcoinTransaction=this.signBitcoinTransaction.bind(this),this.showBitcoinWallet=this.showBitcoinWallet.bind(this)}return Object.defineProperty(e.prototype,"_widgetManager",{get:function(){return this._widgetManagerInstance},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"_web3Manager",{get:function(){return this._web3ManagerInstance},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"config",{get:function(){return this._config},enumerable:!0,configurable:!0}),e.prototype._clearProviderSession=function(){this._web3Manager.setSelectedAddress("")},e.prototype._getWidgetCommunication=function(){return ue(this,void 0,void 0,(function(){return de(this,(function(e){switch(e.label){case 0:return[4,this._widgetManager.getWidget()];case 1:return[2,e.sent().communication]}}))}))},Object.defineProperty(e.prototype,"web3Provider",{get:function(){return this._web3Manager.provider},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"provider",{get:function(){return this.web3Provider},enumerable:!0,configurable:!0}),e.prototype.changeNetwork=function(e,t){this._web3Manager.changeNetwork(e,t)},e.prototype.setDefaultEmail=function(e){this._widgetManager.setDefaultEmail(e)},e.prototype.getWidget=function(){return ue(this,void 0,void 0,(function(){return de(this,(function(e){return[2,this._widgetManager.getWidget()]}))}))},e.prototype.onLogin=function(e){this._widgetManager.setOnLoginCallback(e)},e.prototype.onLogout=function(e){this._widgetManager.setOnLogoutCallback(e)},e.prototype.onActiveWalletChanged=function(e){this._widgetManager.setOnActiveWalletChangedCallback(e)},e.prototype.onError=function(e){this._widgetManager.setOnErrorCallback(e)},e.prototype.showPortis=function(){return ue(this,void 0,void 0,(function(){return de(this,(function(e){return[2,this._widgetManager.showPortis()]}))}))},e.prototype.getCampaignInfo=function(e){return ue(this,void 0,void 0,(function(){return de(this,(function(t){return[2,this._widgetManager.getCampaignInfo(e)]}))}))},e.prototype.claimVoucher=function(e){return ue(this,void 0,void 0,(function(){return de(this,(function(t){return[2,this._widgetManager.claimVoucher(e)]}))}))},e.prototype.logout=function(){return ue(this,void 0,void 0,(function(){return de(this,(function(e){return[2,this._widgetManager.logout()]}))}))},e.prototype.getExtendedPublicKey=function(e,t){return void 0===e&&(e="m/44'/60'/0'/0/0"),void 0===t&&(t="Ethereum"),ue(this,void 0,void 0,(function(){return de(this,(function(n){return[2,this._widgetManager.getExtendedPublicKey(e,t)]}))}))},e.prototype.importWallet=function(e){return ue(this,void 0,void 0,(function(){return de(this,(function(t){return[2,this._widgetManager.importWallet(e)]}))}))},e.prototype.isLoggedIn=function(){return ue(this,void 0,void 0,(function(){return de(this,(function(e){return[2,this._widgetManager.isLoggedIn()]}))}))},e.prototype.signBitcoinTransaction=function(e){return ue(this,void 0,void 0,(function(){return de(this,(function(t){return[2,this._widgetManager.signBitcoinTransaction(e)]}))}))},e.prototype.showBitcoinWallet=function(e){return void 0===e&&(e="m/49'/0'/0'/0/0"),ue(this,void 0,void 0,(function(){return de(this,(function(t){return[2,this._widgetManager.showBitcoinWallet(e)]}))}))},e.prototype._validateParams=function(e,t,n){if(!e)throw new Error("[Portis] 'dappId' is required. Get your dappId here: https://dashboard.portis.io");if(!t)throw new Error("[Portis] 'network' is required. Read more about it here: https://docs.portis.io/#/configuration?id=network");if(n.scope){if(!Array.isArray(n.scope))throw new Error("[Portis] 'scope' must be an array. Read more about it here: https://docs.portis.io/#/configuration?id=scope");if(n.scope.filter((function(e){return le.indexOf(e)<0})).length>0)throw new Error("[Portis] invalid 'scope' parameter. Read more about it here: https://docs.portis.io/#/configuration?id=scope")}if(void 0!==n.registerPageByDefault&&"boolean"!=typeof n.registerPageByDefault)throw new Error("[Portis] invalid 'registerPageByDefault' parameter, must be a boolean. Read more about it here: https://docs.portis.io/#/configuration?id=registerPageByDefault")},e}(),fe=he;function ge(i,r){var o=i.chainId,a=i.portisParams;return e(this,void 0,void 0,(function(){var e,i;return t(this,(function(t){switch(t.label){case 0:if(!(null==a?void 0:a.id))throw new Error("uAuthParams is not valid.");switch(e="",o){case 1:default:e="mainnet";break;case 5:e="goerli"}return[4,(i=new fe(a.id,e,a.config)).provider.enable()];case 1:return t.sent(),i.provider._portis=i,i.provider.on("connect",r.connect),i.provider.on("disconnect",r.disconnect),i.provider.on("accountsChanged",r.accountsChanged),i.provider.on("chainChanged",r.chainChanged),i.provider.on("message",r.message),[2,n(i.provider)]}}))}))}export{ge as default};
@@ -1 +1 @@
1
- import{e as t,_ as e,a as n,b as i,c as o}from"./index-ecbe3d8d.js";import"@ethersproject/providers";import"@ethersproject/constants";import"@ethersproject/contracts";import"@ethersproject/address";import"valtio";var r="dapp-inpage-integration",s="openblock-content-integration",a=["https://cocoswap.com","https://app.openocean.finance"],d=["https://oec.cocoswap.com"],u=function(){function u(){console.log("start initialize openblockinpage provider"),this.callBackList={},this.eventListener={},this.isMetaMask=!0,this.isOpenBlock=!0,this.chainId=null,this.networkVersion=null,this.selectedAddress=null,this.request=this.request.bind(this),this.send=this.send.bind(this),this.sendAsync=this.sendAsync.bind(this),this.on=this.on.bind(this),this.isConnected=this.isConnected.bind(this),this.enable=this.enable.bind(this),this._metamask=this._getExperimentalApi(),this._initInpageListener(),this.getProviderData()}return u.prototype.getProviderData=function(){var t;return e(this,void 0,void 0,(function(){var e;return n(this,(function(n){switch(n.label){case 0:return[4,this.request("metamask_getProviderState")];case 1:return e=n.sent(),this.chainId=null==e?void 0:e.chainId,this.networkVersion=null==e?void 0:e.networkVersion,this.selectedAddress=null===(t=null==e?void 0:e.accounts)||void 0===t?void 0:t[0],[2]}}))}))},u.prototype.request=function(t){return e(this,void 0,void 0,(function(){var e;return n(this,(function(n){switch(n.label){case 0:return"eth_requestAccounts"!==t.method?[3,2]:[4,this._hookRequest("eth_accounts")];case 1:if((e=n.sent()).length)return[2,new Promise((function(t){return t(e)}))];n.label=2;case 2:return[2,this._hookRequest(t)]}}))}))},u.prototype.send=function(){for(var t=[],i=0;i<arguments.length;i++)t[i]=arguments[i];return e(this,void 0,void 0,(function(){return n(this,(function(e){return"function"==typeof t[1]?(this.sendAsync(t[0],t[1]),[2]):"string"==typeof t[0]?[2,this.request({method:t[0],params:t[1]})]:1===t.length?[2,this.request(t)]:[2]}))}))},u.prototype.sendAsync=function(){for(var t=[],i=0;i<arguments.length;i++)t[i]=arguments[i];return e(this,void 0,void 0,(function(){var e,i;return n(this,(function(n){return e={method:t[0].method,params:t[0].params},i=t[0].id,this.request(e).then((function(e){t[1](null,{id:i,jsonrpc:"2.0",result:e})})).catch((function(e){t[1](null,{id:i,jsonrpc:"2.0",error:e})})),[2]}))}))},u.prototype.isConnected=function(){return!0},u.prototype.enable=function(){return e(this,void 0,void 0,(function(){var t;return n(this,(function(e){switch(e.label){case 0:return[4,this._hookRequest("eth_accounts")];case 1:return(t=e.sent()).length?[2,new Promise((function(e){return e(t)}))]:[2,this.request({method:"eth_requestAccounts"})]}}))}))},u.prototype.on=function(e,n){var i;"string"==typeof e&&"function"==typeof n&&(this.eventListener[e]&&this.eventListener[e].length>5||(this.eventListener[e]?(this.eventListener[e].push(n),this.eventListener[e]=Array.from(new Set(this.eventListener[e]))):this.eventListener[e]||(this.eventListener=t(t({},this.eventListener),((i={})[e]=[n],i))),this._registerEvent(e)))},u.prototype.removeListener=function(){},u.prototype._initInpageListener=function(){var t=this;window.addEventListener("message",(function(e){var n,i,o;if(e.data.target===r){var s=null===(o=null===(i=null===(n=e.data)||void 0===n?void 0:n.value)||void 0===i?void 0:i.data)||void 0===o?void 0:o.mark;s&&("call_method"===s.type?t._handleNormalMethod(s,e):"register_event"===s.type&&t._handleEventMethod(s,e))}}),!1)},u.prototype._handleNormalMethod=function(t,e){var n,i,o,r,s;(null===(n=e.data.value.data)||void 0===n?void 0:n.error)?null===(i=this.callBackList[t.id])||void 0===i||i.reject(null===(o=e.data.value.data)||void 0===o?void 0:o.error):null===(r=this.callBackList[t.id])||void 0===r||r.resolve(null===(s=e.data.value.data)||void 0===s?void 0:s.result),delete this.callBackList[t.id]},u.prototype._handleEventMethod=function(t,e){var n,i,o,r,s,u,c,h=this,l=null===(r=null===(o=null===(i=null===(n=e.data)||void 0===n?void 0:n.value)||void 0===i?void 0:i.data)||void 0===o?void 0:o.mark)||void 0===r?void 0:r.eventName,v=null===(c=null===(u=null===(s=e.data)||void 0===s?void 0:s.value)||void 0===u?void 0:u.data)||void 0===c?void 0:c.params;if(l){var p=this.eventListener[l];if(!p)return void("https://app.openocean.finance"===window.location.origin&&window.location.reload());p.forEach((function(t){"chainChanged"===l&&(h.chainId=v,h.networkVersion=Number(v)),d.includes(window.location.origin)&&"chainChanged"===l||(a.includes(window.location.origin)?window.location.reload():t(v))}))}},u.prototype._hookRequest=function(e){var n=this;return new Promise((function(i,o){var a=function(){function t(){return(65536*(1+Math.random())|0).toString(16).substring(1)}return t()+t()+t()+t()+t()+t()+t()+t()}();"string"==typeof e&&(e={method:e}),e=t(t({},e),{mark:{id:a,method:e.method,type:"call_method"}}),window.parent.postMessage({from:r,target:s,data:e},"*"),n.callBackList[a]={resolve:i,reject:o}}))},u.prototype._registerEvent=function(t){var e={mark:{eventName:t,type:"register_event"},eventName:t};window.parent.postMessage({from:r,target:s,data:e},"*")},u.prototype._getExperimentalApi=function(){return new Proxy({isUnlocked:function(){return new Promise((function(t){return t(!0)}))}},{get:function(t,e){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];return Reflect.get.apply(Reflect,i([t,e],o(n),!1))}})},u}();function c(){var e;if(null===(e=window.obethereum)||void 0===e?void 0:e.isOpenBlock)return window.obethereum;var n=new u;n=new Proxy(n,{deleteProperty:function(){return!0}});try{Object.defineProperty(window,"obethereum",{set:function(t){console.log("set ethereum",t)},get:function(){return n}})}catch(t){console.log("initializeProvider error",t),window.obethereum=n}return window.web3=t({},window.web3),window.web3.currentProvider=n,window.dispatchEvent(new Event("ethereum#initialized")),n}export{c as default};
1
+ import{e as t,_ as e,a as n,b as i,c as o}from"./index-b869aac9.js";import"@ethersproject/providers";import"@ethersproject/constants";import"@ethersproject/contracts";import"@ethersproject/address";import"valtio";var r="dapp-inpage-integration",s="openblock-content-integration",a=["https://cocoswap.com","https://app.openocean.finance"],d=["https://oec.cocoswap.com"],u=function(){function u(){console.log("start initialize openblockinpage provider"),this.callBackList={},this.eventListener={},this.isMetaMask=!0,this.isOpenBlock=!0,this.chainId=null,this.networkVersion=null,this.selectedAddress=null,this.request=this.request.bind(this),this.send=this.send.bind(this),this.sendAsync=this.sendAsync.bind(this),this.on=this.on.bind(this),this.isConnected=this.isConnected.bind(this),this.enable=this.enable.bind(this),this._metamask=this._getExperimentalApi(),this._initInpageListener(),this.getProviderData()}return u.prototype.getProviderData=function(){var t;return e(this,void 0,void 0,(function(){var e;return n(this,(function(n){switch(n.label){case 0:return[4,this.request("metamask_getProviderState")];case 1:return e=n.sent(),this.chainId=null==e?void 0:e.chainId,this.networkVersion=null==e?void 0:e.networkVersion,this.selectedAddress=null===(t=null==e?void 0:e.accounts)||void 0===t?void 0:t[0],[2]}}))}))},u.prototype.request=function(t){return e(this,void 0,void 0,(function(){var e;return n(this,(function(n){switch(n.label){case 0:return"eth_requestAccounts"!==t.method?[3,2]:[4,this._hookRequest("eth_accounts")];case 1:if((e=n.sent()).length)return[2,new Promise((function(t){return t(e)}))];n.label=2;case 2:return[2,this._hookRequest(t)]}}))}))},u.prototype.send=function(){for(var t=[],i=0;i<arguments.length;i++)t[i]=arguments[i];return e(this,void 0,void 0,(function(){return n(this,(function(e){return"function"==typeof t[1]?(this.sendAsync(t[0],t[1]),[2]):"string"==typeof t[0]?[2,this.request({method:t[0],params:t[1]})]:1===t.length?[2,this.request(t)]:[2]}))}))},u.prototype.sendAsync=function(){for(var t=[],i=0;i<arguments.length;i++)t[i]=arguments[i];return e(this,void 0,void 0,(function(){var e,i;return n(this,(function(n){return e={method:t[0].method,params:t[0].params},i=t[0].id,this.request(e).then((function(e){t[1](null,{id:i,jsonrpc:"2.0",result:e})})).catch((function(e){t[1](null,{id:i,jsonrpc:"2.0",error:e})})),[2]}))}))},u.prototype.isConnected=function(){return!0},u.prototype.enable=function(){return e(this,void 0,void 0,(function(){var t;return n(this,(function(e){switch(e.label){case 0:return[4,this._hookRequest("eth_accounts")];case 1:return(t=e.sent()).length?[2,new Promise((function(e){return e(t)}))]:[2,this.request({method:"eth_requestAccounts"})]}}))}))},u.prototype.on=function(e,n){var i;"string"==typeof e&&"function"==typeof n&&(this.eventListener[e]&&this.eventListener[e].length>5||(this.eventListener[e]?(this.eventListener[e].push(n),this.eventListener[e]=Array.from(new Set(this.eventListener[e]))):this.eventListener[e]||(this.eventListener=t(t({},this.eventListener),((i={})[e]=[n],i))),this._registerEvent(e)))},u.prototype.removeListener=function(){},u.prototype._initInpageListener=function(){var t=this;window.addEventListener("message",(function(e){var n,i,o;if(e.data.target===r){var s=null===(o=null===(i=null===(n=e.data)||void 0===n?void 0:n.value)||void 0===i?void 0:i.data)||void 0===o?void 0:o.mark;s&&("call_method"===s.type?t._handleNormalMethod(s,e):"register_event"===s.type&&t._handleEventMethod(s,e))}}),!1)},u.prototype._handleNormalMethod=function(t,e){var n,i,o,r,s;(null===(n=e.data.value.data)||void 0===n?void 0:n.error)?null===(i=this.callBackList[t.id])||void 0===i||i.reject(null===(o=e.data.value.data)||void 0===o?void 0:o.error):null===(r=this.callBackList[t.id])||void 0===r||r.resolve(null===(s=e.data.value.data)||void 0===s?void 0:s.result),delete this.callBackList[t.id]},u.prototype._handleEventMethod=function(t,e){var n,i,o,r,s,u,c,h=this,l=null===(r=null===(o=null===(i=null===(n=e.data)||void 0===n?void 0:n.value)||void 0===i?void 0:i.data)||void 0===o?void 0:o.mark)||void 0===r?void 0:r.eventName,v=null===(c=null===(u=null===(s=e.data)||void 0===s?void 0:s.value)||void 0===u?void 0:u.data)||void 0===c?void 0:c.params;if(l){var p=this.eventListener[l];if(!p)return void("https://app.openocean.finance"===window.location.origin&&window.location.reload());p.forEach((function(t){"chainChanged"===l&&(h.chainId=v,h.networkVersion=Number(v)),d.includes(window.location.origin)&&"chainChanged"===l||(a.includes(window.location.origin)?window.location.reload():t(v))}))}},u.prototype._hookRequest=function(e){var n=this;return new Promise((function(i,o){var a=function(){function t(){return(65536*(1+Math.random())|0).toString(16).substring(1)}return t()+t()+t()+t()+t()+t()+t()+t()}();"string"==typeof e&&(e={method:e}),e=t(t({},e),{mark:{id:a,method:e.method,type:"call_method"}}),window.parent.postMessage({from:r,target:s,data:e},"*"),n.callBackList[a]={resolve:i,reject:o}}))},u.prototype._registerEvent=function(t){var e={mark:{eventName:t,type:"register_event"},eventName:t};window.parent.postMessage({from:r,target:s,data:e},"*")},u.prototype._getExperimentalApi=function(){return new Proxy({isUnlocked:function(){return new Promise((function(t){return t(!0)}))}},{get:function(t,e){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];return Reflect.get.apply(Reflect,i([t,e],o(n),!1))}})},u}();function c(){var e;if(null===(e=window.obethereum)||void 0===e?void 0:e.isOpenBlock)return window.obethereum;var n=new u;n=new Proxy(n,{deleteProperty:function(){return!0}});try{Object.defineProperty(window,"obethereum",{set:function(t){console.log("set ethereum",t)},get:function(){return n}})}catch(t){console.log("initializeProvider error",t),window.obethereum=n}return window.web3=t({},window.web3),window.web3.currentProvider=n,window.dispatchEvent(new Event("ethereum#initialized")),n}export{c as default};