@tronweb3/tronwallet-adapter-tokenpocket 1.0.9 → 1.2.0

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 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self)["@tronweb3/tronwallet-adapter-tokenpocket"]=t()}(this,(function(){"use strict";function e(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var t,n,o={},r={},i={},s={},a={exports:{}};function c(){if(n)return s;n=1;var e=s&&s.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(s,"__esModule",{value:!0}),s.Adapter=s.AdapterState=s.WalletReadyState=s.EventEmitter=void 0;const o=e((t||(t=1,function(e){var t=Object.prototype.hasOwnProperty,n="~";function o(){}function r(e,t,n){this.fn=e,this.context=t,this.once=n||!1}function i(e,t,o,i,s){if("function"!=typeof o)throw new TypeError("The listener must be a function");var a=new r(o,i||e,s),c=n?n+t:t;return e._events[c]?e._events[c].fn?e._events[c]=[e._events[c],a]:e._events[c].push(a):(e._events[c]=a,e._eventsCount++),e}function s(e,t){0==--e._eventsCount?e._events=new o:delete e._events[t]}function a(){this._events=new o,this._eventsCount=0}Object.create&&(o.prototype=Object.create(null),(new o).__proto__||(n=!1)),a.prototype.eventNames=function(){var e,o,r=[];if(0===this._eventsCount)return r;for(o in e=this._events)t.call(e,o)&&r.push(n?o.slice(1):o);return Object.getOwnPropertySymbols?r.concat(Object.getOwnPropertySymbols(e)):r},a.prototype.listeners=function(e){var t=n?n+e:e,o=this._events[t];if(!o)return[];if(o.fn)return[o.fn];for(var r=0,i=o.length,s=new Array(i);r<i;r++)s[r]=o[r].fn;return s},a.prototype.listenerCount=function(e){var t=n?n+e:e,o=this._events[t];return o?o.fn?1:o.length:0},a.prototype.emit=function(e,t,o,r,i,s){var a=n?n+e:e;if(!this._events[a])return!1;var c,l,d=this._events[a],h=arguments.length;if(d.fn){switch(d.once&&this.removeListener(e,d.fn,void 0,!0),h){case 1:return d.fn.call(d.context),!0;case 2:return d.fn.call(d.context,t),!0;case 3:return d.fn.call(d.context,t,o),!0;case 4:return d.fn.call(d.context,t,o,r),!0;case 5:return d.fn.call(d.context,t,o,r,i),!0;case 6:return d.fn.call(d.context,t,o,r,i,s),!0}for(l=1,c=new Array(h-1);l<h;l++)c[l-1]=arguments[l];d.fn.apply(d.context,c)}else{var u,w=d.length;for(l=0;l<w;l++)switch(d[l].once&&this.removeListener(e,d[l].fn,void 0,!0),h){case 1:d[l].fn.call(d[l].context);break;case 2:d[l].fn.call(d[l].context,t);break;case 3:d[l].fn.call(d[l].context,t,o);break;case 4:d[l].fn.call(d[l].context,t,o,r);break;default:if(!c)for(u=1,c=new Array(h-1);u<h;u++)c[u-1]=arguments[u];d[l].fn.apply(d[l].context,c)}}return!0},a.prototype.on=function(e,t,n){return i(this,e,t,n,!1)},a.prototype.once=function(e,t,n){return i(this,e,t,n,!0)},a.prototype.removeListener=function(e,t,o,r){var i=n?n+e:e;if(!this._events[i])return this;if(!t)return s(this,i),this;var a=this._events[i];if(a.fn)a.fn!==t||r&&!a.once||o&&a.context!==o||s(this,i);else{for(var c=0,l=[],d=a.length;c<d;c++)(a[c].fn!==t||r&&!a[c].once||o&&a[c].context!==o)&&l.push(a[c]);l.length?this._events[i]=1===l.length?l[0]:l:s(this,i)}return this},a.prototype.removeAllListeners=function(e){var t;return e?(t=n?n+e:e,this._events[t]&&s(this,t)):(this._events=new o,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=n,a.EventEmitter=a,e.exports=a}(a)),a.exports));var r,i;s.EventEmitter=o.default,function(e){e.Loading="Loading",e.NotFound="NotFound",e.Found="Found"}(r||(s.WalletReadyState=r={})),function(e){e.Loading="Loading",e.NotFound="NotFound",e.Disconnect="Disconnected",e.Connected="Connected"}(i||(s.AdapterState=i={}));class c extends o.default{get connected(){return this.state===i.Connected}disconnect(){return console.info("The current adapter doesn't support disconnect by DApp."),Promise.resolve()}multiSign(e,t={}){return Promise.reject("The current wallet doesn't support multiSign.")}switchChain(e){return Promise.reject("The current wallet doesn't support switch chain.")}}return s.Adapter=c,s}var l,d={};var h,u={};var w,p,A={};function v(){return p||(p=1,e=i,o=i&&i.__createBinding||(Object.create?function(e,t,n,o){void 0===o&&(o=n);var r=Object.getOwnPropertyDescriptor(t,n);r&&!("get"in r?!t.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,o,r)}:function(e,t,n,o){void 0===o&&(o=n),e[o]=t[n]}),r=i&&i.__exportStar||function(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||o(t,e,n)},Object.defineProperty(e,"__esModule",{value:!0}),r(c(),e),r(function(){if(l)return d;l=1,Object.defineProperty(d,"__esModule",{value:!0}),d.WalletGetNetworkError=d.WalletSwitchChainError=d.WalletWindowClosedError=d.WalletWalletLoadError=d.WalletSignTransactionError=d.WalletSignMessageError=d.WalletDisconnectionError=d.WalletConnectionError=d.WalletDisconnectedError=d.WalletNotSelectedError=d.WalletNotFoundError=d.WalletError=void 0;class e extends Error{constructor(e,t){super(e),this.error=t}}return d.WalletError=e,d.WalletNotFoundError=class extends e{constructor(e,t){super(e||"The wallet is not found.",t),this.name="WalletNotFoundError"}},d.WalletNotSelectedError=class extends e{constructor(){super(...arguments),this.name="WalletNotSelectedError",this.message="No wallet is selected. Please select a wallet."}},d.WalletDisconnectedError=class extends e{constructor(){super(...arguments),this.name="WalletDisconnectedError",this.message="The wallet is disconnected. Please connect first."}},d.WalletConnectionError=class extends e{constructor(){super(...arguments),this.name="WalletConnectionError"}},d.WalletDisconnectionError=class extends e{constructor(){super(...arguments),this.name="WalletDisconnectionError"}},d.WalletSignMessageError=class extends e{constructor(){super(...arguments),this.name="WalletSignMessageError"}},d.WalletSignTransactionError=class extends e{constructor(){super(...arguments),this.name="WalletSignTransactionError"}},d.WalletWalletLoadError=class extends e{constructor(){super(...arguments),this.name="WalletWalletLoadError"}},d.WalletWindowClosedError=class extends e{constructor(e,t){super(e||"The QR window is closed.",t),this.name="WalletWindowClosedError"}},d.WalletSwitchChainError=class extends e{constructor(){super(...arguments),this.name="WalletSwitchChainError"}},d.WalletGetNetworkError=class extends e{constructor(){super(...arguments),this.name="WalletGetNetworkError"}},d}(),e),r((h||(h=1,Object.defineProperty(u,"__esModule",{value:!0}),u.TIP6963RequestProviderEventName=u.TIP6963AnnounceProviderEventName=u.ChainNetwork=u.NetworkType=void 0,function(e){e.Mainnet="Mainnet",e.Shasta="Shasta",e.Nile="Nile",e.Unknown="Unknown"}(t||(u.NetworkType=t={})),function(e){e.Mainnet="Mainnet",e.Shasta="Shasta",e.Nile="Nile"}(n||(u.ChainNetwork=n={})),u.TIP6963AnnounceProviderEventName="TIP6963:announceProvider",u.TIP6963RequestProviderEventName="TIP6963:requestProvider"),u),e),r(function(){if(w)return A;function e(){return"undefined"!=typeof window&&"undefined"!=typeof document&&"undefined"!=typeof navigator}return w=1,Object.defineProperty(A,"__esModule",{value:!0}),A.isInBrowser=e,A.checkAdapterState=function(t){if(!e())return;const n=[];function o(){for(const e of n)e()}function r(){t()&&o()}const i=setInterval(r,500);n.push((()=>clearInterval(i))),"loading"===document.readyState&&(document.addEventListener("DOMContentLoaded",r,{once:!0}),n.push((()=>document.removeEventListener("DOMContentLoaded",r)))),"complete"!==document.readyState&&(window.addEventListener("load",r,{once:!0}),n.push((()=>window.removeEventListener("load",r)))),r(),setTimeout(o,6e4)},A.isInMobileBrowser=function(){return"undefined"!=typeof navigator&&navigator.userAgent.match(/Android|webOS|iPhone|iPad|iPod|BlackBerry|Windows Phone/i)},A}(),e)),i;var e,t,n,o,r}var f,y,N={},g={},I={};function k(){if(f)return I;f=1;var e=I&&I.__awaiter||function(e,t,n,o){return new(n||(n=Promise))((function(r,i){function s(e){try{c(o.next(e))}catch(e){i(e)}}function a(e){try{c(o.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((o=o.apply(e,t||[])).next())}))};Object.defineProperty(I,"__esModule",{value:!0}),I.supportTron=n,I.supportTronLink=o,I.isInTronLinkApp=r,I.openTronLink=function({dappIcon:e,dappName:n}={dappIcon:"",dappName:""}){if(!o()&&(0,t.isInMobileBrowser)()&&!r()){let t="",o="";try{t=document.title;const e=document.querySelector('link[rel*="icon"]');e&&(o=new URL(e.getAttribute("href")||"",location.href).toString())}catch(e){}const{origin:r,pathname:i,search:s,hash:a}=window.location,c=r+i+s+(a.includes("?")?a:`${a}?_=1`),l={action:"open",actionId:Date.now()+"",callbackUrl:"http://someurl.com",dappIcon:e||o,dappName:n||t,url:c,protocol:"TronLink",version:"1.0",chainId:"0x2b6653dc"};return window.location.href=`tronlinkoutside://pull.activity?param=${encodeURIComponent(JSON.stringify(l))}`,!0}return!1},I.waitTronwebReady=function(t){return e(this,void 0,void 0,(function*(){return new Promise(((e,n)=>{const o=setInterval((()=>{t.tronWeb&&(clearInterval(o),clearTimeout(r),e())}),50),r=setTimeout((()=>{clearInterval(o),n("`window.tron.tronweb` is not ready.")}),2e3)}))}))};const t=v();function n(){return(0,t.isInBrowser)()&&!(!window.tron||!window.tron.isTronLink)}function o(){return(0,t.isInBrowser)()&&!!(n()||window.tronLink||window.tronWeb)}function r(){return(0,t.isInBrowser)()&&void 0!==window.iTron}return I}function M(){return y||(y=1,function(e){var t=g&&g.__awaiter||function(e,t,n,o){return new(n||(n=Promise))((function(r,i){function s(e){try{c(o.next(e))}catch(e){i(e)}}function a(e){try{c(o.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((o=o.apply(e,t||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0}),e.TronLinkAdapter=e.TronLinkAdapterName=e.chainIdNetworkMap=void 0,e.getNetworkInfoByTronWeb=r;const n=v(),o=k();function r(o){return t(this,void 0,void 0,(function*(){var t,r,i;const{blockID:s=""}=yield o.trx.getBlockByNumber(0),a=`0x${s.slice(-8)}`;return{networkType:e.chainIdNetworkMap[a]||n.NetworkType.Unknown,chainId:a,fullNode:(null===(t=o.fullNode)||void 0===t?void 0:t.host)||"",solidityNode:(null===(r=o.solidityNode)||void 0===r?void 0:r.host)||"",eventServer:(null===(i=o.eventServer)||void 0===i?void 0:i.host)||""}}))}e.chainIdNetworkMap={"0x2b6653dc":n.NetworkType.Mainnet,"0x94a9059e":n.NetworkType.Shasta,"0xcd8690dc":n.NetworkType.Nile},e.TronLinkAdapterName="TronLink";class i extends n.Adapter{constructor(t={}){super(),this.name=e.TronLinkAdapterName,this.url="https://www.tronlink.org/",this.icon="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAF0AAABdCAYAAADHcWrDAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAUGVYSWZNTQAqAAAACAACARIAAwAAAAEAAQAAh2kABAAAAAEAAAAmAAAAAAADoAEAAwAAAAEAAQAAoAIABAAAAAEAAABdoAMABAAAAAEAAABdAAAAAMkTBfIAAAFZaVRYdFhNTDpjb20uYWRvYmUueG1wAAAAAAA8eDp4bXBtZXRhIHhtbG5zOng9ImFkb2JlOm5zOm1ldGEvIiB4OnhtcHRrPSJYTVAgQ29yZSA2LjAuMCI+CiAgIDxyZGY6UkRGIHhtbG5zOnJkZj0iaHR0cDovL3d3dy53My5vcmcvMTk5OS8wMi8yMi1yZGYtc3ludGF4LW5zIyI+CiAgICAgIDxyZGY6RGVzY3JpcHRpb24gcmRmOmFib3V0PSIiCiAgICAgICAgICAgIHhtbG5zOnRpZmY9Imh0dHA6Ly9ucy5hZG9iZS5jb20vdGlmZi8xLjAvIj4KICAgICAgICAgPHRpZmY6T3JpZW50Y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8e/hjvVy/Xim34CVG+21h+ePawjAk4HDG1byFN4q+r/dQH74aaDGOtFvnw4wC+2BJzo8db/XnJc1Njr7EMua7DuJAdXXXTrq8fI2lpUyPvz8LSjjXLjCEXHIw8Ft8eu65sqmTkjok4K+AvNnyZH0Xsb+eO/wWrg46Do/7gYAAAAABJRU5ErkJggg==",this._readyState=(0,n.isInBrowser)()?n.WalletReadyState.Loading:n.WalletReadyState.NotFound,this._state=(0,n.isInBrowser)()?n.AdapterState.Loading:n.AdapterState.NotFound,this._supportNewTronProtocol=!1,this._onChainChanged=e=>{this.emit("chainChanged",e)},this._onAccountsChanged=()=>{var e,t,o;const r=this.address||"",i=(null===(e=this._wallet)||void 0===e?void 0:e.tronWeb)&&(null===(o=null===(t=this._wallet)||void 0===t?void 0:t.tronWeb.defaultAddress)||void 0===o?void 0:o.base58)||"";this.setAddress(i||null),this.setState(this.address?n.AdapterState.Connected:n.AdapterState.Disconnect),this.emit("accountsChanged",this.address||"",r),!r&&this.address?this.emit("connect",this.address):r&&!this.address&&this.emit("disconnect")},this._checkPromise=null,this._updateWallet=()=>{var e,t,o,r,i,s,a,c,l;this._supportNewTronProtocol=!1;let d=this.state,h=this.address;if((0,n.isInMobileBrowser)())window.tronLink?this._wallet=window.tronLink:this._wallet={ready:!!(null===(e=window.tronWeb)||void 0===e?void 0:e.defaultAddress),tronWeb:window.tronWeb,request:()=>Promise.resolve(!0)},h=(null===(o=null===(t=this._wallet.tronWeb)||void 0===t?void 0:t.defaultAddress)||void 0===o?void 0:o.base58)||null,d=h?n.AdapterState.Connected:n.AdapterState.Disconnect;else if(window.tron&&window.tron.isTronLink){this._supportNewTronProtocol=!0,this._wallet=window.tron,this._listenTronEvent();try{h=(null===(r=this._wallet)||void 0===r?void 0:r.tronWeb)&&(null===(s=null===(i=this._wallet.tronWeb)||void 0===i?void 0:i.defaultAddress)||void 0===s?void 0:s.base58)||null,d=h?n.AdapterState.Connected:n.AdapterState.Disconnect}catch(e){return console.error("Unknown error: "+e," Please install TronLink extension wallet."),h=null,d=n.AdapterState.Disconnect,this._readyState=n.WalletReadyState.NotFound,void this.emit("readyStateChanged",this.readyState)}}else window.tronLink?(this._wallet=window.tronLink,h=(null===(c=null===(a=this._wallet.tronWeb)||void 0===a?void 0:a.defaultAddress)||void 0===c?void 0:c.base58)||null,d=this._wallet.ready?n.AdapterState.Connected:n.AdapterState.Disconnect):window.tronWeb?(this._wallet={ready:window.tronWeb.ready,tronWeb:window.tronWeb,request:()=>Promise.resolve(!0)},h=(null===(l=this._wallet.tronWeb.defaultAddress)||void 0===l?void 0:l.base58)||null,d=this._wallet.ready?n.AdapterState.Connected:n.AdapterState.Disconnect):(this._wallet=null,h=null,d=n.AdapterState.NotFound);(0,n.isInMobileBrowser)()&&d===n.AdapterState.Disconnect&&this.checkForWalletReadyForApp(),this.setAddress(h),this.setState(d)},this.checkReadyInterval=null;const{checkTimeout:r=3e4,dappIcon:i="",dappName:s="",openUrlWhenWalletNotFound:a=!0,openTronLinkAppOnMobile:c=!0,openAppWithDeeplink:l=!0}=t;if("number"!=typeof r)throw new Error("[TronLinkAdapter] config.checkTimeout should be a number");this.config={checkTimeout:r,openTronLinkAppOnMobile:c,openAppWithDeeplink:l,openUrlWhenWalletNotFound:a,dappIcon:i,dappName:s},this._connecting=!1,this._wallet=null,this._address=null,(0,o.supportTron)()||(0,n.isInMobileBrowser)()&&(window.tronLink||window.tronWeb)?(this._readyState=n.WalletReadyState.Found,this._updateWallet()):this._checkWallet().then((()=>{this.connected&&this.emit("connect",this.address||"")}))}get address(){return this._address}get state(){return this._state}get readyState(){return this._readyState}get connecting(){return this._connecting}network(){return t(this,void 0,void 0,(function*(){var e;try{if(yield this._checkWallet(),this.state!==n.AdapterState.Connected)throw new n.WalletDisconnectedError;const t=(null===(e=this._wallet)||void 0===e?void 0:e.tronWeb)||window.tronWeb;if(!t)throw new n.WalletDisconnectedError;try{return yield r(t)}catch(e){throw new n.WalletGetNetworkError(null==e?void 0:e.message,e)}}catch(e){throw this.emit("error",e),e}}))}connect(){return t(this,void 0,void 0,(function*(){var e,t;try{if(this.checkIfOpenTronLink(),this.connected||this.connecting)return;if(yield this._checkWallet(),this.state===n.AdapterState.NotFound)throw!1!==this.config.openUrlWhenWalletNotFound&&(0,n.isInBrowser)()&&window.open(this.url,"_blank"),new n.WalletNotFoundError;if(!this._wallet)return;if(this._connecting=!0,this._supportNewTronProtocol){const e=this._wallet;try{const t=(yield e.request({method:"eth_requestAccounts"}))[0];this.setAddress(t),this.setState(n.AdapterState.Connected),this._listenTronEvent(),this._wallet.tronWeb||(yield(0,o.waitTronwebReady)(this._wallet))}catch(e){let t=(null==e?void 0:e.message)||e||"Connect TronLink wallet failed.";throw-32002===e.code&&(t="The same DApp has already initiated a request to connect to TronLink wallet, and the pop-up window has not been closed."),4001===e.code&&(t="The user rejected connection."),new n.WalletConnectionError(t,e)}}else if(window.tronLink){const t=this._wallet;try{const e=yield t.request({method:"tron_requestAccounts"});if(!e)throw new n.WalletConnectionError("TronLink wallet is locked or no wallet account is avaliable.");if(4e3===e.code)throw new n.WalletConnectionError("The same DApp has already initiated a request to connect to TronLink wallet, and the pop-up window has not been closed.");if(4001===e.code)throw new n.WalletConnectionError("The user rejected connection.")}catch(e){throw new n.WalletConnectionError(null==e?void 0:e.message,e)}const o=(null===(e=t.tronWeb.defaultAddress)||void 0===e?void 0:e.base58)||"";this.setAddress(o),this.setState(n.AdapterState.Connected)}else{if(!window.tronWeb)throw new n.WalletConnectionError("Cannot connect wallet.");{const e=(null===(t=this._wallet.tronWeb.defaultAddress)||void 0===t?void 0:t.base58)||"";this.setAddress(e),this.setState(n.AdapterState.Connected)}}this.connected&&this.emit("connect",this.address||"")}catch(e){throw this.emit("error",e),e}finally{this._connecting=!1}}))}disconnect(){return t(this,void 0,void 0,(function*(){this._supportNewTronProtocol&&this._stopListenTronEvent(),this.state===n.AdapterState.Connected&&(this.setAddress(null),this.setState(n.AdapterState.Disconnect),this.emit("disconnect"))}))}_checkAndSign(e,n){return t(this,void 0,void 0,(function*(){try{const t=yield this.checkAndGetWallet();try{return yield e(t)}catch(e){throw e instanceof Error||"object"==typeof e&&e.message?new n(e.message,e):"string"==typeof e?new n(e,new Error(e)):new n("Unknown error",e)}}catch(e){throw this.emit("error",e),e}}))}signTransaction(e){return t(this,void 0,void 0,(function*(){return this._checkAndSign((t=>t.tronWeb.trx.sign(e)),n.WalletSignTransactionError)}))}multiSign(e){return t(this,arguments,void 0,(function*(e,t={}){return this._checkAndSign((n=>n.tronWeb.trx.multiSign(e,void 0,t.permissionId)),n.WalletSignTransactionError)}))}signMessage(e){return t(this,void 0,void 0,(function*(){return this._checkAndSign((n=>t(this,void 0,void 0,(function*(){return n.tronWeb.trx.signMessageV2(e)}))),n.WalletSignMessageError)}))}switchChain(e){return t(this,void 0,void 0,(function*(){try{if(yield this._checkWallet(),this.state===n.AdapterState.NotFound)throw!1!==this.config.openUrlWhenWalletNotFound&&(0,n.isInBrowser)()&&window.open(this.url,"_blank"),new n.WalletNotFoundError;if(!this._supportNewTronProtocol)throw new n.WalletSwitchChainError("Current version of TronLink doesn't support switch chain operation.");const t=this._wallet;try{yield t.request({method:"wallet_switchEthereumChain",params:[{chainId:e}]})}catch(e){throw new n.WalletSwitchChainError((null==e?void 0:e.message)||e,e instanceof Error?e:new Error(e))}}catch(e){throw this.emit("error",e),e}}))}checkAndGetWallet(){return t(this,void 0,void 0,(function*(){if(this.checkIfOpenTronLink(),yield this._checkWallet(),this.state!==n.AdapterState.Connected)throw new n.WalletDisconnectedError;const e=this._wallet;if(!e||!e.tronWeb)throw new n.WalletDisconnectedError;return e}))}checkIfOpenTronLink(){const{dappName:e="",dappIcon:t=""}=this.config;if(!1!==this.config.openTronLinkAppOnMobile&&!1!==this.config.openAppWithDeeplink&&(0,o.openTronLink)({dappIcon:t,dappName:e}))throw new n.WalletNotFoundError}_listenTronEvent(){var e,t;this._stopListenTronEvent();const n=this._wallet;null===(e=n.on)||void 0===e||e.call(n,"chainChanged",this._onChainChanged),null===(t=n.on)||void 0===t||t.call(n,"accountsChanged",this._onAccountsChanged)}_stopListenTronEvent(){var e,t;const n=this._wallet;null===(e=n.removeListener)||void 0===e||e.call(n,"chainChanged",this._onChainChanged),null===(t=n.removeListener)||void 0===t||t.call(n,"accountsChanged",this._onAccountsChanged)}_checkWallet(){if(this.readyState===n.WalletReadyState.Found)return Promise.resolve(!0);if(this._checkPromise)return this._checkPromise;const e=Math.floor(20),t=Math.floor(this.config.checkTimeout/100);let r,i=0;return this._checkPromise=new Promise((s=>{const a=()=>{i++;const a=i<e&&!(0,n.isInMobileBrowser)()?(0,o.supportTron)():(0,o.supportTronLink)();(a||i>t)&&(r&&clearInterval(r),this._readyState=a?n.WalletReadyState.Found:n.WalletReadyState.NotFound,this._updateWallet(),this.emit("readyStateChanged",this.readyState),s(a))};r=setInterval(a,100),a()})),this._checkPromise}checkForWalletReadyForApp(){if(this.checkReadyInterval)return;let e=0;const t=Math.floor(this.config.checkTimeout/200);this.checkReadyInterval=setInterval((()=>{var n,o;(window.tronLink?null===(n=window.tronLink.tronWeb)||void 0===n?void 0:n.defaultAddress:null===(o=window.tronWeb)||void 0===o?void 0:o.defaultAddress)?(this.checkReadyInterval&&clearInterval(this.checkReadyInterval),this.checkReadyInterval=null,this._updateWallet(),this.emit("connect",this.address||"")):e>t?(this.checkReadyInterval&&clearInterval(this.checkReadyInterval),this.checkReadyInterval=null):e++}),200)}setAddress(e){this._address=e}setState(e){e!==this.state&&(this._state=e,this.emit("stateChanged",e))}}e.TronLinkAdapter=i}(g)),g}var W,m,S={};function b(){return m||(m=1,e=N,t=N&&N.__createBinding||(Object.create?function(e,t,n,o){void 0===o&&(o=n);var r=Object.getOwnPropertyDescriptor(t,n);r&&!("get"in r?!t.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,o,r)}:function(e,t,n,o){void 0===o&&(o=n),e[o]=t[n]}),n=N&&N.__exportStar||function(e,n){for(var o in e)"default"===o||Object.prototype.hasOwnProperty.call(n,o)||t(n,e,o)},Object.defineProperty(e,"__esModule",{value:!0}),n(M(),e),n((W||(W=1,Object.defineProperty(S,"__esModule",{value:!0})),S),e),n(k(),e)),N;var e,t,n}var D,T,j,E,C,L,P={};function O(){if(D)return P;D=1,Object.defineProperty(P,"__esModule",{value:!0}),P.supportTokenPocket=t,P.isInTokenPocket=n,P.openTokenPocket=function(){if(!t()&&(0,e.isInMobileBrowser)()&&!n()){const{origin:e,pathname:t,search:n,hash:o}=window.location,r=e+t+n+o,i={action:"open",actionId:Date.now()+"",callbackUrl:"http://someurl.com",blockchain:"Tron",chain:"Tron",url:r,protocol:"TokenPocket",version:"1.0"};return window.location.href=`tpdapp://open?params=${encodeURIComponent(JSON.stringify(i))}`,!0}return!1};const e=v();function t(){return!!window.tronWeb&&void 0!==window.tokenpocket}function n(){return(0,e.isInBrowser)()&&void 0!==window.tokenpocket}return P}function z(){return T||(T=1,function(e){var t=r&&r.__awaiter||function(e,t,n,o){return new(n||(n=Promise))((function(r,i){function s(e){try{c(o.next(e))}catch(e){i(e)}}function a(e){try{c(o.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((o=o.apply(e,t||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0}),e.TokenPocketAdapter=e.TokenPocketAdapterName=void 0;const n=v(),o=b(),i=O(),s=v();e.TokenPocketAdapterName="TokenPocket";class a extends n.Adapter{constructor(t={}){super(),this.name=e.TokenPocketAdapterName,this.url="https://tokenpocket.pro/",this.icon="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTIwIiBoZWlnaHQ9IjEyMCIgdmlld0JveD0iMCAwIDEwMjQgMTAyNCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPGc+CjxwYXRoIGQ9Ik0xMDQxLjUyIDBILTI3VjEwMjRIMTA0MS41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1LjQ1VjY1MC4wNjZDNzA3LjgxNiA2NTAuMDY2IDcwOC44NjQgNjUwLjA2NiA3MDkuNzggNjUwLjA2NloiIGZpbGw9IndoaXRlIi8+CjwvZz4KPC9nPgo8ZGVmcz4KPGxpbmVhckdyYWRpZW50IGlkPSJwYWludDBfbGluZWFyXzQwOF8yMjUiIHgxPSI3MDkuODQ0IiB5MT0iNTU2LjgyNyIgeDI9IjY2Ny43NTMiIHkyPSI1NTYuODI3IiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSI+CjxzdG9wIHN0b3AtY29sb3I9IndoaXRlIi8+CjxzdG9wIG9mZnNldD0iMC45NjY3IiBzdG9wLWNvbG9yPSJ3aGl0ZSIgc3RvcC1vcGFjaXR5PSIwLjMyMzMiLz4KPHN0b3Agb2Zmc2V0PSIxIiBzdG9wLWNvbG9yPSJ3aGl0ZSIgc3RvcC1vcGFjaXR5PSIwLjMiLz4KPC9saW5lYXJHcmFkaWVudD4KPGNsaXBQYXRoIGlkPSJjbGlwMF80MDhfMjI1Ij4KPHJlY3Qgd2lkdGg9IjcyOC40NDgiIGhlaWdodD0iNDcwIiBmaWxsPSJ3aGl0ZSIgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoMTY4IDI3NykiLz4KPC9jbGlwUGF0aD4KPC9kZWZzPgo8L3N2Zz4K",this._readyState=(0,n.isInBrowser)()?n.WalletReadyState.Loading:n.WalletReadyState.NotFound,this._state=n.AdapterState.Loading,this.onAccountsChanged=e=>{const t=this.address||"",o=(null==e?void 0:e[0])||"";if(o){const e=o;this.setAddress(e),this.setState(n.AdapterState.Connected)}else this.setAddress(null),this.setState(n.AdapterState.Disconnect);this.emit("accountsChanged",this.address||"",t),!t&&this.address?this.emit("connect",this.address):t&&!this.address&&this.emit("disconnect")},this.checkReadyInterval=null,this._checkPromise=null,this._updateWallet=()=>{var e,t,o,r,s;let a=this.state,c=this.address;if((0,i.supportTokenPocket)()){const i=null===(e=window.tokenpocket)||void 0===e?void 0:e.tron;this._wallet=(0,n.isInMobileBrowser)()?{tron:i,ready:null===(t=window.tronWeb)||void 0===t?void 0:t.ready,tronWeb:null===(o=window.tokenpocket)||void 0===o?void 0:o.tronWeb}:{tron:i,ready:!!(null===(r=(null==i?void 0:i.tronWeb).defaultAddress)||void 0===r?void 0:r.base58)||!1,tronWeb:null==i?void 0:i.tronWeb},c=(null===(s=this._wallet.tronWeb.defaultAddress)||void 0===s?void 0:s.base58)||null,a=c?n.AdapterState.Connected:n.AdapterState.Disconnect,c||this.checkForWalletReady()}else this._wallet=null,c=null,a=n.AdapterState.NotFound;this.setAddress(c),this.setState(a)};const{checkTimeout:o=2e3,openUrlWhenWalletNotFound:r=!0,openAppWithDeeplink:s=!0}=t;if("number"!=typeof o)throw new Error("[TokenPocketAdapter] config.checkTimeout should be a number");this.config={checkTimeout:o,openAppWithDeeplink:s,openUrlWhenWalletNotFound:r},this._connecting=!1,this._wallet=null,this._address=null,(0,n.isInMobileBrowser)()&&(0,i.supportTokenPocket)()?(this._readyState=n.WalletReadyState.Found,this._updateWallet()):this._checkWallet().then((()=>{this.connected&&this.emit("connect",this.address||"")}))}get address(){return this._address}get state(){return this._state}get readyState(){return this._readyState}get connecting(){return this._connecting}network(){return t(this,void 0,void 0,(function*(){try{if(yield this._checkWallet(),this.state!==n.AdapterState.Connected)throw new n.WalletDisconnectedError;const e=this._wallet;if(!e||!e.tronWeb)throw new n.WalletDisconnectedError;try{return yield(0,o.getNetworkInfoByTronWeb)(e.tronWeb)}catch(e){throw new n.WalletGetNetworkError(null==e?void 0:e.message,e)}}catch(e){throw this.emit("error",e),e}}))}connect(){return t(this,void 0,void 0,(function*(){try{if(this.checkIfOpenApp(),this.connected||this.connecting)return;if(yield this._checkWallet(),this.readyState===n.WalletReadyState.NotFound)throw!1!==this.config.openUrlWhenWalletNotFound&&(0,n.isInBrowser)()&&window.open(this.url,"_blank"),new n.WalletNotFoundError;if(!this._wallet)return;this._connecting=!0;const e=this._wallet;try{const t=yield e.tron.request({method:"eth_requestAccounts"});if(!(null==t?void 0:t[0]))throw new n.WalletConnectionError("Request connect error.");const o=t[0];this.setAddress(o),this.setState(n.AdapterState.Connected),this.emit("connect",this.address||"")}catch(e){throw e instanceof n.WalletError?e:new n.WalletConnectionError(null==e?void 0:e.message,e)}}catch(e){throw this.emit("error",e),e}finally{this._connecting=!1}}))}disconnect(){return t(this,void 0,void 0,(function*(){this.state===n.AdapterState.Connected&&(this.setAddress(null),this.setState(n.AdapterState.Disconnect),this.emit("disconnect"))}))}signTransaction(e){return t(this,void 0,void 0,(function*(){try{const t=yield this.checkAndGetWallet();try{return yield t.tronWeb.trx.sign(e)}catch(e){throw e instanceof Error||"object"==typeof e&&e.message?new n.WalletSignTransactionError(e.message,e):"string"==typeof e?new n.WalletSignTransactionError(e,new Error(e)):new n.WalletSignTransactionError("Unknown error",e)}}catch(e){throw this.emit("error",e),e}}))}multiSign(e){return t(this,arguments,void 0,(function*(e,t={}){try{const o=yield this.checkAndGetWallet();try{return yield o.tronWeb.trx.multiSign(e,void 0,t.permissionId)}catch(e){throw e instanceof Error||"object"==typeof e&&e.message?new n.WalletSignTransactionError(e.message,e):"string"==typeof e?new n.WalletSignTransactionError(e,new Error(e)):new n.WalletSignTransactionError("Unknown error",e)}}catch(e){throw this.emit("error",e),e}}))}signMessage(e){return t(this,void 0,void 0,(function*(){try{const t=yield this.checkAndGetWallet();try{return yield t.tronWeb.trx.signMessageV2(e)}catch(e){throw e instanceof Error||"object"==typeof e&&e.message?new n.WalletSignMessageError(e.message,e):"string"==typeof e?new n.WalletSignMessageError(e,new Error(e)):new n.WalletSignMessageError("Unknown error",e)}}catch(e){throw this.emit("error",e),e}}))}listenTronEvent(){if((0,n.isInMobileBrowser)())return;this.stopListenTronEvent();const e=this._wallet;e&&e.tron&&e.tron.on("accountsChanged",this.onAccountsChanged)}stopListenTronEvent(){if((0,n.isInMobileBrowser)())return;const e=this._wallet;e&&e.tron&&e.tron.removeListener("accountsChanged",this.onAccountsChanged)}checkAndGetWallet(){return t(this,void 0,void 0,(function*(){if(this.checkIfOpenApp(),yield this._checkWallet(),!this.connected)throw new n.WalletDisconnectedError;const e=this._wallet;if(!e||!e.tronWeb)throw new n.WalletDisconnectedError;return e}))}checkIfOpenApp(){if(!1!==this.config.openAppWithDeeplink&&(0,i.openTokenPocket)())throw new n.WalletNotFoundError}checkForWalletReady(){if(this.checkReadyInterval)return;let e=0;const t=Math.floor(this.config.checkTimeout/200);this.checkReadyInterval=setInterval((()=>{var o,r,i,s;if((0,n.isInMobileBrowser)()&&(null===(o=window.tronWeb)||void 0===o?void 0:o.ready))this.checkReadyInterval&&clearInterval(this.checkReadyInterval),this.checkReadyInterval=null,this._updateWallet(),this.emit("connect",this.address||"");else if(null===(s=null===(i=null===(r=this._wallet)||void 0===r?void 0:r.tronWeb)||void 0===i?void 0:i.defaultAddress)||void 0===s?void 0:s.base58){this.checkReadyInterval&&clearInterval(this.checkReadyInterval),this.checkReadyInterval=null,this._wallet.ready=!0;const e=this._wallet.tronWeb.defaultAddress.base58,t=e?n.AdapterState.Connected:n.AdapterState.Disconnect;this.setAddress(e),this.setState(t),this.emit("connect",this.address||"")}else e>t?(this.checkReadyInterval&&clearInterval(this.checkReadyInterval),this.checkReadyInterval=null):e++}),200)}_checkWallet(){if(this.readyState===n.WalletReadyState.Found)return Promise.resolve(!0);if(this._checkPromise)return this._checkPromise;if((0,n.isInBrowser)()&&!(0,n.isInMobileBrowser)())return this._checkPromise=new Promise((e=>{const t=setTimeout((()=>{window.removeEventListener(s.TIP6963AnnounceProviderEventName,o),this._updateWallet(),(0,i.supportTokenPocket)()?(this._readyState=n.WalletReadyState.Found,e(!0)):(this._readyState=n.WalletReadyState.NotFound,e(!1)),this.emit("readyStateChanged",this._readyState)}),this.config.checkTimeout),o=r=>{var i,a,c;const{info:l,provider:d}=r.detail;if("TokenPocket"===l.name){this._wallet={ready:!!(null===(a=null===(i=d.tronWeb)||void 0===i?void 0:i.defaultAddress)||void 0===a?void 0:a.base58),tron:d,tronWeb:d.tronWeb},this.listenTronEvent(),this._readyState=n.WalletReadyState.Found;const r=(null===(c=this._wallet.tronWeb.defaultAddress)||void 0===c?void 0:c.base58)||null,l=r?n.AdapterState.Connected:n.AdapterState.Disconnect;this.setState(l),this.setAddress(r),this.emit("readyStateChanged",this.readyState),window.removeEventListener(s.TIP6963AnnounceProviderEventName,o),clearTimeout(t),e(!0),this.connected||this.checkForWalletReady()}};window.addEventListener(s.TIP6963AnnounceProviderEventName,o),window.dispatchEvent(new Event(s.TIP6963RequestProviderEventName))})),this._checkPromise;const e=Math.floor(this.config.checkTimeout/100);let t,o=0;return this._checkPromise=new Promise((r=>{const s=()=>{o++;const s=(0,i.supportTokenPocket)();(s||o>e)&&(t&&clearInterval(t),this._readyState=s?n.WalletReadyState.Found:n.WalletReadyState.NotFound,this._updateWallet(),this.emit("readyStateChanged",this.readyState),r(s))};t=setInterval(s,100),s()})),this._checkPromise}setAddress(e){this._address=e}setState(e){e!==this.state&&(this._state=e,this.emit("stateChanged",e))}}e.TokenPocketAdapter=a}(r)),r}return e((j||(j=1,E=o,C=o&&o.__createBinding||(Object.create?function(e,t,n,o){void 0===o&&(o=n);var r=Object.getOwnPropertyDescriptor(t,n);r&&!("get"in r?!t.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,o,r)}:function(e,t,n,o){void 0===o&&(o=n),e[o]=t[n]}),L=o&&o.__exportStar||function(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||C(t,e,n)},Object.defineProperty(E,"__esModule",{value:!0}),L(z(),E),L(O(),E)),o))}));
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self)["@tronweb3/tronwallet-adapter-tokenpocket"]=t()}(this,(function(){"use strict";function e(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var t,n={},o={},r={},i={},s={exports:{}};var a,c,l={},d={};function u(){if(a)return d;a=1,Object.defineProperty(d,"__esModule",{value:!0}),d.WalletSignTypedDataError=d.WalletGetNetworkError=d.WalletSwitchChainError=d.WalletWindowClosedError=d.WalletWalletLoadError=d.WalletSignTransactionError=d.WalletSignMessageError=d.WalletDisconnectionError=d.WalletConnectionError=d.WalletDisconnectedError=d.WalletNotSelectedError=d.WalletNotFoundError=d.WalletError=void 0;class e extends Error{constructor(e,t){super(e),this.error=t}}d.WalletError=e;d.WalletNotFoundError=class extends e{constructor(e,t){super(e||"The wallet is not found.",t),this.name="WalletNotFoundError"}};d.WalletNotSelectedError=class extends e{constructor(){super(...arguments),this.name="WalletNotSelectedError",this.message="No wallet is selected. Please select a wallet."}};d.WalletDisconnectedError=class extends e{constructor(){super(...arguments),this.name="WalletDisconnectedError",this.message="The wallet is disconnected. Please connect first."}};d.WalletConnectionError=class extends e{constructor(){super(...arguments),this.name="WalletConnectionError"}};d.WalletDisconnectionError=class extends e{constructor(){super(...arguments),this.name="WalletDisconnectionError"}};d.WalletSignMessageError=class extends e{constructor(){super(...arguments),this.name="WalletSignMessageError"}};d.WalletSignTransactionError=class extends e{constructor(){super(...arguments),this.name="WalletSignTransactionError"}};d.WalletWalletLoadError=class extends e{constructor(){super(...arguments),this.name="WalletWalletLoadError"}};d.WalletWindowClosedError=class extends e{constructor(e,t){super(e||"The QR window is closed.",t),this.name="WalletWindowClosedError"}};d.WalletSwitchChainError=class extends e{constructor(){super(...arguments),this.name="WalletSwitchChainError"}};d.WalletGetNetworkError=class extends e{constructor(){super(...arguments),this.name="WalletGetNetworkError"}};return d.WalletSignTypedDataError=class extends e{constructor(){super(...arguments),this.name="WalletSignTypedDataError"}},d}function h(){if(c)return l;c=1,Object.defineProperty(l,"__esModule",{value:!0}),l.normalizeAndValidateTypedData=function(r){if(!t(r))throw new e.WalletSignTypedDataError("typedData must be an object.");if(!t(r.domain))throw new e.WalletSignTypedDataError("typedData.domain must be an object.");if(!t(r.types))throw new e.WalletSignTypedDataError("typedData.types must be an object.");if(!t(r.message))throw new e.WalletSignTypedDataError("typedData.message must be an object.");const{chainId:i}=r.domain;if("string"==typeof i||"number"==typeof i||"bigint"==typeof i){const t=function(t){if("string"==typeof t){const r=t.trim();if(!n.test(r)&&!o.test(r))throw new e.WalletSignTypedDataError(`Invalid domain.chainId: ${t}. Expected a non-negative decimal or 0x-prefixed hex integer.`)}const r=Number(t);if(!Number.isInteger(r))throw new e.WalletSignTypedDataError(`Invalid domain.chainId: ${t}. Expected a non-negative integer.`);if(r<0)throw new e.WalletSignTypedDataError(`Invalid domain.chainId: ${t}. Expected a non-negative integer.`);if(!Number.isSafeInteger(r))throw new e.WalletSignTypedDataError(`domain.chainId ${t} exceeds Number.MAX_SAFE_INTEGER (${Number.MAX_SAFE_INTEGER}) and cannot be represented as a number without losing precision.`);return r}(i);return t===i?r:Object.assign(Object.assign({},r),{domain:Object.assign(Object.assign({},r.domain),{chainId:t})})}return r};const e=u();function t(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}const n=/^[0-9]+$/,o=/^0[xX][0-9a-fA-F]+$/;return l}var p,f,w={};function y(){return p||(p=1,Object.defineProperty(w,"__esModule",{value:!0}),w.TIP6963RequestProviderEventName=w.TIP6963AnnounceProviderEventName=w.ChainNetwork=w.NetworkType=w.AdapterState=w.WalletReadyState=void 0,function(e){e.Loading="Loading",e.NotFound="NotFound",e.Found="Found"}(e||(w.WalletReadyState=e={})),function(e){e.Loading="Loading",e.NotFound="NotFound",e.Disconnect="Disconnected",e.Connected="Connected"}(t||(w.AdapterState=t={})),function(e){e.Mainnet="Mainnet",e.Shasta="Shasta",e.Nile="Nile",e.Unknown="Unknown"}(n||(w.NetworkType=n={})),function(e){e.Mainnet="Mainnet",e.Shasta="Shasta",e.Nile="Nile"}(o||(w.ChainNetwork=o={})),w.TIP6963AnnounceProviderEventName="TIP6963:announceProvider",w.TIP6963RequestProviderEventName="TIP6963:requestProvider"),w;var e,t,n,o}function v(){if(f)return i;f=1;var e=i&&i.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(i,"__esModule",{value:!0}),i.Adapter=i.EventEmitter=void 0;const n=e((t||(t=1,function(e){var t=Object.prototype.hasOwnProperty,n="~";function o(){}function r(e,t,n){this.fn=e,this.context=t,this.once=n||!1}function i(e,t,o,i,s){if("function"!=typeof o)throw new TypeError("The listener must be a function");var a=new r(o,i||e,s),c=n?n+t:t;return e._events[c]?e._events[c].fn?e._events[c]=[e._events[c],a]:e._events[c].push(a):(e._events[c]=a,e._eventsCount++),e}function s(e,t){0==--e._eventsCount?e._events=new o:delete e._events[t]}function a(){this._events=new o,this._eventsCount=0}Object.create&&(o.prototype=Object.create(null),(new o).__proto__||(n=!1)),a.prototype.eventNames=function(){var e,o,r=[];if(0===this._eventsCount)return r;for(o in e=this._events)t.call(e,o)&&r.push(n?o.slice(1):o);return Object.getOwnPropertySymbols?r.concat(Object.getOwnPropertySymbols(e)):r},a.prototype.listeners=function(e){var t=n?n+e:e,o=this._events[t];if(!o)return[];if(o.fn)return[o.fn];for(var r=0,i=o.length,s=new Array(i);r<i;r++)s[r]=o[r].fn;return s},a.prototype.listenerCount=function(e){var t=n?n+e:e,o=this._events[t];return o?o.fn?1:o.length:0},a.prototype.emit=function(e,t,o,r,i,s){var a=n?n+e:e;if(!this._events[a])return!1;var c,l,d=this._events[a],u=arguments.length;if(d.fn){switch(d.once&&this.removeListener(e,d.fn,void 0,!0),u){case 1:return d.fn.call(d.context),!0;case 2:return d.fn.call(d.context,t),!0;case 3:return d.fn.call(d.context,t,o),!0;case 4:return d.fn.call(d.context,t,o,r),!0;case 5:return d.fn.call(d.context,t,o,r,i),!0;case 6:return d.fn.call(d.context,t,o,r,i,s),!0}for(l=1,c=new Array(u-1);l<u;l++)c[l-1]=arguments[l];d.fn.apply(d.context,c)}else{var h,p=d.length;for(l=0;l<p;l++)switch(d[l].once&&this.removeListener(e,d[l].fn,void 0,!0),u){case 1:d[l].fn.call(d[l].context);break;case 2:d[l].fn.call(d[l].context,t);break;case 3:d[l].fn.call(d[l].context,t,o);break;case 4:d[l].fn.call(d[l].context,t,o,r);break;default:if(!c)for(h=1,c=new Array(u-1);h<u;h++)c[h-1]=arguments[h];d[l].fn.apply(d[l].context,c)}}return!0},a.prototype.on=function(e,t,n){return i(this,e,t,n,!1)},a.prototype.once=function(e,t,n){return i(this,e,t,n,!0)},a.prototype.removeListener=function(e,t,o,r){var i=n?n+e:e;if(!this._events[i])return this;if(!t)return s(this,i),this;var a=this._events[i];if(a.fn)a.fn!==t||r&&!a.once||o&&a.context!==o||s(this,i);else{for(var c=0,l=[],d=a.length;c<d;c++)(a[c].fn!==t||r&&!a[c].once||o&&a[c].context!==o)&&l.push(a[c]);l.length?this._events[i]=1===l.length?l[0]:l:s(this,i)}return this},a.prototype.removeAllListeners=function(e){var t;return e?(t=n?n+e:e,this._events[t]&&s(this,t)):(this._events=new o,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=n,a.EventEmitter=a,e.exports=a}(s)),s.exports));i.EventEmitter=n.default;const o=h(),r=y();class a extends n.default{get connected(){return this.state===r.AdapterState.Connected}disconnect(){return console.info("The current adapter doesn't support disconnect by DApp."),Promise.resolve()}multiSign(e,t={}){return Promise.reject("The current wallet doesn't support multiSign.")}signTypedData(e){let t;try{t=(0,o.normalizeAndValidateTypedData)(e)}catch(e){return Promise.reject(e)}return this._signTypedData(t)}_signTypedData(e){return Promise.reject("The current wallet doesn't support signTypedData.")}switchChain(e){return Promise.reject("The current wallet doesn't support switch chain.")}}return i.Adapter=a,i}var A,g={};function m(){return A||(A=1,function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.MAX_CHECK_TIMEOUT=void 0,e.validateCheckTimeout=function(t,n="[WalletAdapter]"){if("number"!=typeof t)throw new Error(`${n} config.checkTimeout should be a number`);if(!Number.isFinite(t)||t<0||t>e.MAX_CHECK_TIMEOUT)throw new Error(`${n} config.checkTimeout should be a finite number between 0 and ${e.MAX_CHECK_TIMEOUT}, but got ${t}`)},e.omitUndefined=function(e){return Object.fromEntries(Object.entries(null!=e?e:{}).filter((([,e])=>void 0!==e)))},e.assertConnectAddress=function(e){if(!e)throw new t.WalletConnectionError("Request connect error.");return e},e.isInBrowser=n,e.checkAdapterState=function(e){if(!n())return;const t=[];function o(){for(const e of t)e()}function r(){e()&&o()}const i=setInterval(r,500);t.push((()=>clearInterval(i))),"loading"===document.readyState&&(document.addEventListener("DOMContentLoaded",r,{once:!0}),t.push((()=>document.removeEventListener("DOMContentLoaded",r))));"complete"!==document.readyState&&(window.addEventListener("load",r,{once:!0}),t.push((()=>window.removeEventListener("load",r))));r(),setTimeout(o,6e4)},e.isInMobileBrowser=function(){return"undefined"!=typeof navigator&&navigator.userAgent.match(/Android|webOS|iPhone|iPad|iPod|BlackBerry|Windows Phone/i)};const t=u();function n(){return"undefined"!=typeof window&&"undefined"!=typeof document&&"undefined"!=typeof navigator}e.MAX_CHECK_TIMEOUT=6e5}(g)),g}var N,k,I,S={},b={};function T(){return N||(N=1,function(e){var t=b&&b.__awaiter||function(e,t,n,o){return new(n||(n=Promise))((function(r,i){function s(e){try{c(o.next(e))}catch(e){i(e)}}function a(e){try{c(o.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((o=o.apply(e,t||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0}),e.defaultSecurityOptions=void 0,e.validateSecurityOptions=function(e){const{enabled:t,configUrls:s,timeout:a,retries:c,cacheTTL:l,onRiskDetected:d,onConfigFallback:u}=e;if(void 0!==t&&"boolean"!=typeof t)throw new Error("[WalletAdapter] config.securityOptions.enabled should be a boolean, but got "+typeof t);void 0!==s&&function(e){if(!Array.isArray(e))throw new Error("[WalletAdapter] config.securityOptions.configUrls should be an array of URLs, but got "+typeof e);for(const t of e){if("string"!=typeof t||""===t.trim())throw new Error(`[WalletAdapter] config.securityOptions.configUrls should only contain non-empty URL strings, but got ${String(t)}`);const e=i(t);if(e&&"http:"!==e.protocol&&"https:"!==e.protocol)throw new Error(`[WalletAdapter] config.securityOptions.configUrls only supports http(s) URLs, but got ${t}`)}}(s);if(t&&(!s||0===s.length))throw new Error("[WalletAdapter] config.securityOptions.configUrls is required when securityOptions.enabled is true");void 0!==a&&r(a,"timeout",1,n);void 0!==l&&r(l,"cacheTTL",0,Number.MAX_SAFE_INTEGER);if(void 0!==c&&(!Number.isInteger(c)||c<0||c>o))throw new Error(`[WalletAdapter] config.securityOptions.retries should be an integer between 0 and ${o}, but got ${String(c)}`);if(void 0!==d&&"function"!=typeof d)throw new Error("[WalletAdapter] config.securityOptions.onRiskDetected should be a function, but got "+typeof d);if(void 0!==u&&"function"!=typeof u)throw new Error("[WalletAdapter] config.securityOptions.onConfigFallback should be a function, but got "+typeof u)},e.clearCache=function(){Object.keys(l).forEach((e=>{Reflect.deleteProperty(l,e)}))},e.fetchJsonWithCache=function(n){return t(this,void 0,void 0,(function*(){const{configUrls:o=e.defaultSecurityOptions.configUrls,timeout:r=e.defaultSecurityOptions.timeout,retries:i=e.defaultSecurityOptions.retries,onConfigFallback:s,cacheTTL:a=e.defaultSecurityOptions.cacheTTL}=n,d=Date.now();const u=(yield Promise.all(o.map((function(e){return t(this,void 0,void 0,(function*(){const n=l[e];if(n&&d-n.timestamp<a)return n.data;function o(){return t(this,void 0,void 0,(function*(){return new Promise(((t,n)=>{const o=new AbortController,i=setTimeout((()=>o.abort()),r);fetch(e,{signal:o.signal}).then((e=>{clearTimeout(i),e.ok?e.json().then((e=>t(c(e))),n):n(new Error("Fetch failed with code: "+e.status))})).catch((e=>{clearTimeout(i),n(e)}))}))}))}for(let t=0;t<=i;t++)try{const t=yield o();return l[e]={data:t,timestamp:Date.now()},t}catch(n){console.warn(`[WalletAdapter] Fetch attempt ${t+1} for ${e} failed:`,n)}return null}))})))).filter((e=>null!==e));return u.length>0?u.reduce(((e,t)=>{var n;t.ts>e.ts&&(e.v=t.v,e.ts=t.ts);for(const[o,r]of Object.entries(t.wallets))e.wallets[o]=[...null!==(n=e.wallets[o])&&void 0!==n?n:[],...r];return e}),{v:"",ts:0,wallets:{}}):s?c(yield s()):{v:"",ts:0,wallets:{}}}))},e.defaultSecurityOptions={onRiskDetected:e=>t(void 0,void 0,void 0,(function*(){console.log("[WalletAdapter] Risk detected:",e)})),configUrls:[],enabled:!1,timeout:2e3,retries:0,cacheTTL:6e5};const n=6e4,o=10;function r(e,t,n,o){if("number"!=typeof e||!Number.isFinite(e)||e<n||e>o)throw new Error(`[WalletAdapter] config.securityOptions.${t} should be a finite number between ${n} and ${o}, but got ${String(e)}`)}function i(e){try{return new URL(e)}catch(e){return null}}function s(e){return!!e&&"object"==typeof e&&"string"==typeof e.title&&e.title.length>0&&(1===e.noticeType||2===e.noticeType||3===e.noticeType)}function a(e){const t={title:e.title,noticeType:e.noticeType};return"string"==typeof e.ext&&(t.ext=e.ext),"string"==typeof e.ios&&(t.ios=e.ios),"string"==typeof e.and&&(t.and=e.and),t}function c(e){const t=e&&"object"==typeof e?e:{},n={};if(t.wallets&&"object"==typeof t.wallets)for(const[e,o]of Object.entries(t.wallets)){if(!Array.isArray(o)){console.warn(`[WalletAdapter] Ignoring malformed risks for "${e}": expected an array, got ${typeof o}.`);continue}const t=[];for(const n of o)s(n)?t.push(a(n)):console.warn(`[WalletAdapter] Dropping malformed risk entry for "${e}":`,n);t.length>0&&(n[e]=t)}return{v:"string"==typeof t.v?t.v:"",ts:"number"==typeof t.ts?t.ts:0,wallets:n}}const l={}}(b)),b}function M(){if(k)return S;k=1;var e=S&&S.__awaiter||function(e,t,n,o){return new(n||(n=Promise))((function(r,i){function s(e){try{c(o.next(e))}catch(e){i(e)}}function a(e){try{c(o.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((o=o.apply(e,t||[])).next())}))};Object.defineProperty(S,"__esModule",{value:!0}),S.AddonAdapter=void 0;const t=v(),n=u(),o=T(),r=y(),i=m();class s extends t.Adapter{constructor(e){super(),this.commonConfig={checkTimeout:2e3,openAppWithDeeplink:!0,openUrlWhenWalletNotFound:!0,securityOptions:o.defaultSecurityOptions},this._connectPromise=null,this._securityCheckCache=null,this.commonConfig=Object.assign(Object.assign({},this.commonConfig),(0,i.omitUndefined)(e)),(0,i.validateCheckTimeout)(this.commonConfig.checkTimeout),(0,o.validateSecurityOptions)(this.commonConfig.securityOptions)}updateSecurityOptions(e){const t=Object.assign(Object.assign({},this.commonConfig.securityOptions),e);(0,o.validateSecurityOptions)(t),this.commonConfig.securityOptions=t,this._securityCheckCache=null}connect(t){if(this._connectPromise)return this._connectPromise;const n=(()=>e(this,void 0,void 0,(function*(){return this._connect(t)})))().finally((()=>{this._connectPromise===n&&(this._connectPromise=null)}));return this._connectPromise=n,n}_beforeConnect(){return e(this,void 0,void 0,(function*(){if(this.connected||this.connecting)return!1;if(yield this._checkWallet(),this.readyState===r.WalletReadyState.NotFound)throw(0,i.isInBrowser)()&&!this._openAppByDeepLinkIfNeed()&&!1!==this.commonConfig.openUrlWhenWalletNotFound&&window.open(this.url,"_blank"),new n.WalletNotFoundError;return yield this.checkSecurity(),!0}))}checkSecurity(){return e(this,void 0,void 0,(function*(){if(!this.commonConfig.securityOptions.enabled)return;const t=this._securityCheckCache;if(t&&(null===t.settledAt||Date.now()-t.settledAt<s.SECURITY_CHECK_CACHE_TTL))return t.promise;const n=(()=>e(this,void 0,void 0,(function*(){const e=(yield(0,o.fetchJsonWithCache)(this.commonConfig.securityOptions)).wallets[this.name];if(e&&e.length>0){const t=this.commonConfig.securityOptions.onRiskDetected||o.defaultSecurityOptions.onRiskDetected;yield t({risks:e})}})))(),r={promise:n,settledAt:null};return this._securityCheckCache=r,n.finally((()=>{this._securityCheckCache===r&&(r.settledAt=Date.now())})).catch((()=>{})),n}))}}return S.AddonAdapter=s,s.SECURITY_CHECK_CACHE_TTL=5e3,S}function W(){return I||(I=1,e=r,t=r&&r.__createBinding||(Object.create?function(e,t,n,o){void 0===o&&(o=n);var r=Object.getOwnPropertyDescriptor(t,n);r&&!("get"in r?!t.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,o,r)}:function(e,t,n,o){void 0===o&&(o=n),e[o]=t[n]}),n=r&&r.__exportStar||function(e,n){for(var o in e)"default"===o||Object.prototype.hasOwnProperty.call(n,o)||t(n,e,o)},Object.defineProperty(e,"__esModule",{value:!0}),n(v(),e),n(u(),e),n(y(),e),n(h(),e),n(m(),e),n(M(),e),n(T(),e)),r;var e,t,n}var D,E,j={},C={},O={};function P(){if(D)return O;D=1;var e=O&&O.__awaiter||function(e,t,n,o){return new(n||(n=Promise))((function(r,i){function s(e){try{c(o.next(e))}catch(e){i(e)}}function a(e){try{c(o.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((o=o.apply(e,t||[])).next())}))};Object.defineProperty(O,"__esModule",{value:!0}),O.supportTron=n,O.supportTronLink=o,O.isInTronLinkApp=r,O.openTronLink=function({dappIcon:e,dappName:n}={dappIcon:"",dappName:""}){if(!o()&&(0,t.isInMobileBrowser)()&&!r()){let t="",o="";try{t=document.title;const e=document.querySelector('link[rel*="icon"]');e&&(o=new URL(e.getAttribute("href")||"",location.href).toString())}catch(e){}const{origin:r,pathname:i,search:s,hash:a}=window.location,c=r+i+s+(a.includes("?")?a:`${a}?_=1`),l={action:"open",actionId:Date.now()+"",callbackUrl:"http://someurl.com",dappIcon:e||o,dappName:n||t,url:c,protocol:"TronLink",version:"1.0",chainId:"0x2b6653dc"};return window.location.href=`tronlinkoutside://pull.activity?param=${encodeURIComponent(JSON.stringify(l))}`,!0}return!1},O.waitTronwebReady=function(t){return e(this,void 0,void 0,(function*(){return new Promise(((e,n)=>{const o=setInterval((()=>{t.tronWeb&&(clearInterval(o),clearTimeout(r),e())}),50),r=setTimeout((()=>{clearInterval(o),n("`window.tron.tronweb` is not ready.")}),2e3)}))}))};const t=W();function n(){return(0,t.isInBrowser)()&&!(!window.tron||!window.tron.isTronLink)}function o(){return(0,t.isInBrowser)()&&!!(n()||window.tronLink||window.tronWeb)}function r(){return(0,t.isInBrowser)()&&void 0!==window.iTron}return O}function _(){return E||(E=1,function(e){var t=C&&C.__awaiter||function(e,t,n,o){return new(n||(n=Promise))((function(r,i){function s(e){try{c(o.next(e))}catch(e){i(e)}}function a(e){try{c(o.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((o=o.apply(e,t||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0}),e.TronLinkAdapter=e.TronLinkAdapterName=e.chainIdNetworkMap=void 0,e.getNetworkInfoByTronWeb=r;const n=W(),o=P();function r(o){return t(this,void 0,void 0,(function*(){var t,r,i;const{blockID:s=""}=yield o.trx.getBlockByNumber(0),a=`0x${s.slice(-8)}`;return{networkType:e.chainIdNetworkMap[a]||n.NetworkType.Unknown,chainId:a,fullNode:(null===(t=o.fullNode)||void 0===t?void 0:t.host)||"",solidityNode:(null===(r=o.solidityNode)||void 0===r?void 0:r.host)||"",eventServer:(null===(i=o.eventServer)||void 0===i?void 0:i.host)||""}}))}e.chainIdNetworkMap={"0x2b6653dc":n.NetworkType.Mainnet,"0x94a9059e":n.NetworkType.Shasta,"0xcd8690dc":n.NetworkType.Nile},e.TronLinkAdapterName="TronLink";class i extends n.AddonAdapter{constructor(r={}){super(r),this.name=e.TronLinkAdapterName,this.url="https://www.tronlink.org/",this.icon="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAF0AAABdCAYAAADHcWrDAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAUGVYSWZNTQAqAAAACAACAR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n2CSMYuKHkxSl/C2/bAnQerHp5cgl+6niGHax7Tsitpl8KDz8xFd8Z9fGF93x5so4un9Rb5Uno6nWU2AdfH5KVHjnSObdZjmBNBZWxLoQGSkvYwS3A8IqSF6GyNRQBOtuULTmvsnTxxB9YVuB6VG1sxW9O4zc1wb24lZrminHsopzRH482lTccc6eszEpEWoDLbmhEdbEPk1p8U5NTxqF5AAxORyUbVWI1PNbQEJhW9uI5n2laql36zE5T6/IXJi7Nu3H1CsO0r4OmmY2M5CT8oGmmw3IMjURZsWh3h/3pGbas3OKXE5hJy4lMs8s1WESwbAMOejwdUoaIVaR/nt6JKK1GoVAQDEF61lG4+Ks2GPRgQbId3InZl7cxQBeWLJ70ZYzHUYdigs4WHPX4txA9L8qfs34UfM7J2B6NFVmDxLB6i92q0KkLtfcPhX0vSqq3H6geC/98RHg/VwL0MW8e/hjvVy/Xim34CVG+21h+ePawjAk4HDG1byFN4q+r/dQH74aaDGOtFvnw4wC+2BJzo8db/XnJc1Njr7EMua7DuJAdXXXTrq8fI2lpUyPvz8LSjjXLjCEXHIw8Ft8eu65sqmTkjok4K+AvNnyZH0Xsb+eO/wWrg46Do/7gYAAAAABJRU5ErkJggg==",this._readyState=(0,n.isInBrowser)()?n.WalletReadyState.Loading:n.WalletReadyState.NotFound,this._state=(0,n.isInBrowser)()?n.AdapterState.Loading:n.AdapterState.NotFound,this._supportNewTronProtocol=!1,this._onChainChanged=e=>{this.emit("chainChanged",e)},this._onAccountsChanged=()=>{var e,t,o;const r=this.address||"",i=(null===(e=this._wallet)||void 0===e?void 0:e.tronWeb)&&(null===(o=null===(t=this._wallet)||void 0===t?void 0:t.tronWeb.defaultAddress)||void 0===o?void 0:o.base58)||"";this.setAddress(i||null),this.setState(this.address?n.AdapterState.Connected:n.AdapterState.Disconnect),this.emit("accountsChanged",this.address||"",r),!r&&this.address?this.emit("connect",this.address):r&&!this.address&&this.emit("disconnect")},this._checkPromise=null,this._updateWallet=()=>t(this,void 0,void 0,(function*(){var e,t,o,r,i,s,a,c;let l,d;if(this._supportNewTronProtocol=!1,(0,n.isInMobileBrowser)())if(window.tronLink?this._wallet=window.tronLink:this._wallet={ready:!!(null===(e=window.tronWeb)||void 0===e?void 0:e.defaultAddress),tronWeb:window.tronWeb,request:()=>Promise.resolve(!0)},d=(null===(o=null===(t=this._wallet.tronWeb)||void 0===t?void 0:t.defaultAddress)||void 0===o?void 0:o.base58)||null,d){try{yield this.checkSecurity()}catch(e){return this.setAddress(null),void this.setState(n.AdapterState.Disconnect)}l=n.AdapterState.Connected}else l=n.AdapterState.Disconnect;else if(this.isLegacyTronLinkProvider(window.tron)){this._supportNewTronProtocol=!0,this._wallet=window.tron,this._listenTronEvent();try{d=(null===(r=this._wallet)||void 0===r?void 0:r.tronWeb)&&(null===(s=null===(i=this._wallet.tronWeb)||void 0===i?void 0:i.defaultAddress)||void 0===s?void 0:s.base58)||null,l=d?n.AdapterState.Connected:n.AdapterState.Disconnect}catch(e){return console.error("Unknown error: "+e," Please install TronLink extension wallet."),this._readyState=n.WalletReadyState.NotFound,void this.emit("readyStateChanged",this.readyState)}}else window.tronLink?(this._wallet=window.tronLink,d=(null===(c=null===(a=this._wallet.tronWeb)||void 0===a?void 0:a.defaultAddress)||void 0===c?void 0:c.base58)||null,l=this._wallet.ready?n.AdapterState.Connected:n.AdapterState.Disconnect):(this._wallet=null,d=null,l=n.AdapterState.NotFound);(0,n.isInMobileBrowser)()&&l===n.AdapterState.Disconnect&&this.checkForWalletReadyForApp(),this.setAddress(d),this.setState(l)})),this.checkReadyInterval=null;const{checkTimeout:i=5e3,dappIcon:s="",dappName:a="",openUrlWhenWalletNotFound:c=!0,openTronLinkAppOnMobile:l=!0,openAppWithDeeplink:d=!0}=r;if("number"!=typeof i)throw new Error("[TronLinkAdapter] config.checkTimeout should be a number");if(this.config=Object.assign(Object.assign({},this.commonConfig),{checkTimeout:i,openTronLinkAppOnMobile:l,openAppWithDeeplink:d,openUrlWhenWalletNotFound:c,dappIcon:s,dappName:a}),this._connecting=!1,this._wallet=null,this._address=null,!(0,n.isInBrowser)())return this._readyState=n.WalletReadyState.NotFound,void this.setState(n.AdapterState.NotFound);(0,n.isInMobileBrowser)()&&((0,o.supportTron)()||(0,n.isInMobileBrowser)()&&(window.tronLink||window.tronWeb))?(this._readyState=n.WalletReadyState.Found,this._updateWallet().then((()=>{this.connected&&this.emit("connect",this.address||"")}))):this._checkWallet().then((()=>{this.connected&&this.emit("connect",this.address||"")}))}get address(){return this._address}get state(){return this._state}get readyState(){return this._readyState}get connecting(){return this._connecting}network(){return t(this,void 0,void 0,(function*(){var e;try{if(yield this._checkWallet(),this.state!==n.AdapterState.Connected)throw new n.WalletDisconnectedError;const t=(null===(e=this._wallet)||void 0===e?void 0:e.tronWeb)||window.tronWeb;if(!t)throw new n.WalletDisconnectedError;try{return yield r(t)}catch(e){throw new n.WalletGetNetworkError(null==e?void 0:e.message,e)}}catch(e){throw this.emit("error",e),e}}))}_connect(){return t(this,void 0,void 0,(function*(){var e,t;try{if(!(yield this._beforeConnect()))return;if(!this._wallet)return;if(this._connecting=!0,this._supportNewTronProtocol){const e=this._wallet;try{const t=yield e.request({method:"eth_requestAccounts"}),r=(0,n.assertConnectAddress)(null==t?void 0:t[0]);this.setAddress(r),this.setState(n.AdapterState.Connected),this._listenTronEvent(),this._wallet.tronWeb||(yield(0,o.waitTronwebReady)(this._wallet))}catch(e){let t=(null==e?void 0:e.message)||e||"Connect TronLink wallet failed.";throw-32002===e.code&&(t="The same DApp has already initiated a request to connect to TronLink wallet, and the pop-up window has not been closed."),4001===e.code&&(t="The user rejected connection."),new n.WalletConnectionError(t,e)}}else if(window.tronLink){const t=this._wallet,o=yield t.request({method:"tron_requestAccounts"});if(!o)throw new n.WalletConnectionError("TronLink wallet is locked or no wallet account is avaliable.");if(4e3===o.code)throw new n.WalletConnectionError("The same DApp has already initiated a request to connect to TronLink wallet, and the pop-up window has not been closed.");if(4001===o.code)throw new n.WalletConnectionError("The user rejected connection.");const r=(0,n.assertConnectAddress)(null===(e=t.tronWeb.defaultAddress)||void 0===e?void 0:e.base58);this.setAddress(r),this.setState(n.AdapterState.Connected)}else{if(!window.tronWeb)throw new n.WalletConnectionError("Cannot connect wallet.");{const e=this._wallet,o=(0,n.assertConnectAddress)(null===(t=e.tronWeb.defaultAddress)||void 0===t?void 0:t.base58);this.setAddress(o),this.setState(n.AdapterState.Connected)}}this.connected&&this.emit("connect",this.address||"")}catch(e){const t=e instanceof n.WalletError?e:new n.WalletConnectionError(null==e?void 0:e.message,e);throw this.emit("error",t),t}finally{this._connecting=!1}}))}disconnect(){return t(this,void 0,void 0,(function*(){this._supportNewTronProtocol&&this._stopListenTronEvent(),this.state===n.AdapterState.Connected&&(this.setAddress(null),this.setState(n.AdapterState.Disconnect),this.emit("disconnect"))}))}_checkAndSign(e,n){return t(this,void 0,void 0,(function*(){try{const t=yield this.checkAndGetWallet();try{return yield e(t)}catch(e){throw e instanceof Error||"object"==typeof e&&e.message?new n(e.message,e):"string"==typeof e?new n(e,new Error(e)):new n("Unknown error",e)}}catch(e){throw this.emit("error",e),e}}))}signTransaction(e){return t(this,void 0,void 0,(function*(){return this._checkAndSign((t=>t.tronWeb.trx.sign(e)),n.WalletSignTransactionError)}))}multiSign(e){return t(this,arguments,void 0,(function*(e,t={}){return this._checkAndSign((n=>n.tronWeb.trx.multiSign(e,void 0,t.permissionId)),n.WalletSignTransactionError)}))}signMessage(e){return t(this,void 0,void 0,(function*(){return this._checkAndSign((n=>t(this,void 0,void 0,(function*(){return n.tronWeb.trx.signMessageV2(e)}))),n.WalletSignMessageError)}))}_signTypedData(e){return t(this,void 0,void 0,(function*(){return this._checkAndSign((n=>t(this,void 0,void 0,(function*(){return n.tronWeb.trx._signTypedData(e.domain,e.types,e.message)}))),n.WalletSignTypedDataError)}))}switchChain(e){return t(this,void 0,void 0,(function*(){try{if(yield this._checkWallet(),this.state===n.AdapterState.NotFound)throw!1!==this.config.openUrlWhenWalletNotFound&&(0,n.isInBrowser)()&&window.open(this.url,"_blank"),new n.WalletNotFoundError;if(!this._supportNewTronProtocol)throw new n.WalletSwitchChainError("Current version of TronLink doesn't support switch chain operation.");const t=this._wallet;try{yield t.request({method:"wallet_switchEthereumChain",params:[{chainId:e}]})}catch(e){throw new n.WalletSwitchChainError((null==e?void 0:e.message)||e,e instanceof Error?e:new Error(e))}}catch(e){throw this.emit("error",e),e}}))}checkAndGetWallet(){return t(this,void 0,void 0,(function*(){if(this._openAppByDeepLinkIfNeed())throw new n.WalletNotFoundError;if(yield this._checkWallet(),this.state!==n.AdapterState.Connected)throw new n.WalletDisconnectedError;const e=this._wallet;if(!e||!e.tronWeb)throw new n.WalletDisconnectedError;return e}))}_openAppByDeepLinkIfNeed(){if(!1===this.config.openAppWithDeeplink||!1===this.config.openTronLinkAppOnMobile)return!1;const{dappName:e="",dappIcon:t=""}=this.config;return(0,o.openTronLink)({dappIcon:t,dappName:e})}_listenTronEvent(){var e,t;this._stopListenTronEvent();const n=this._wallet;null===(e=n.on)||void 0===e||e.call(n,"chainChanged",this._onChainChanged),null===(t=n.on)||void 0===t||t.call(n,"accountsChanged",this._onAccountsChanged)}_stopListenTronEvent(){var e,t;const n=this._wallet;null===(e=n.removeListener)||void 0===e||e.call(n,"chainChanged",this._onChainChanged),null===(t=n.removeListener)||void 0===t||t.call(n,"accountsChanged",this._onAccountsChanged)}isLegacyTronLinkProvider(e){return!!(null==e?void 0:e.isTronLink)}hasDesktopLegacyTronLinkProvider(){return this.isLegacyTronLinkProvider(window.tron)||!!window.tronLink}_checkWallet(){if(this.readyState===n.WalletReadyState.Found)return Promise.resolve(!0);if(this._checkPromise)return this._checkPromise;if((0,n.isInBrowser)()&&!(0,n.isInMobileBrowser)()){const e=new Promise((e=>{let o=!1,r=null,i=null;const s=()=>{r&&(clearTimeout(r),r=null),"undefined"!=typeof window&&i&&window.removeEventListener(n.TIP6963AnnounceProviderEventName,i)};r=setTimeout((()=>{if(o)return;if(o=!0,s(),"undefined"==typeof window)return void e(!1);this._updateWallet();const t=this.state!==n.AdapterState.NotFound;this._readyState=t?n.WalletReadyState.Found:n.WalletReadyState.NotFound,this.emit("readyStateChanged",this._readyState),e(t)}),this.config.checkTimeout),i=r=>t(this,void 0,void 0,(function*(){var t,i;if(o)return;const{info:a,provider:c}=r.detail;if("TronLink"===a.name){o=!0,this._supportNewTronProtocol=!0,this._wallet=c;try{yield this.checkSecurity()}catch(t){return this.setAddress(null),this.setState(n.AdapterState.Disconnect),this._readyState=n.WalletReadyState.Found,this.emit("readyStateChanged",this.readyState),void e(!0)}this._listenTronEvent(),this._readyState=n.WalletReadyState.Found;const r=(null===(t=this._wallet)||void 0===t?void 0:t.tronWeb)&&(null===(i=this._wallet.tronWeb.defaultAddress)||void 0===i?void 0:i.base58)||null,a=r?n.AdapterState.Connected:n.AdapterState.Disconnect;this.setAddress(r),this.setState(a),this.emit("readyStateChanged",this.readyState),s(),e(!0)}})),window.addEventListener(n.TIP6963AnnounceProviderEventName,i),window.dispatchEvent(new Event(n.TIP6963RequestProviderEventName))}));return this._checkPromise=e,e.then((t=>{t||this._checkPromise!==e||(this._checkPromise=null)})),e}const e=Math.floor(this.config.checkTimeout/100);let o,r=0;const i=new Promise((t=>{const i=()=>{r++,this._updateWallet();const i=!(!(0,n.isInMobileBrowser)()||!window.tronLink&&!window.tronWeb);(i||r>e)&&(o&&clearInterval(o),this._readyState=i?n.WalletReadyState.Found:n.WalletReadyState.NotFound,this.emit("readyStateChanged",this.readyState),t(i))};o=setInterval(i,100),i()}));return this._checkPromise=i,i.then((e=>{e||this._checkPromise!==i||(this._checkPromise=null)})),i}checkForWalletReadyForApp(){if(this.checkReadyInterval)return;let e=0;const t=Math.floor(this.config.checkTimeout/200);this.checkReadyInterval=setInterval((()=>{var n,o;(window.tronLink?null===(n=window.tronLink.tronWeb)||void 0===n?void 0:n.defaultAddress:null===(o=window.tronWeb)||void 0===o?void 0:o.defaultAddress)?(this.checkReadyInterval&&clearInterval(this.checkReadyInterval),this.checkReadyInterval=null,this._updateWallet(),this.emit("connect",this.address||"")):e>t?(this.checkReadyInterval&&clearInterval(this.checkReadyInterval),this.checkReadyInterval=null):e++}),200)}setAddress(e){this._address=e}setState(e){e!==this.state&&(this._state=e,this.emit("stateChanged",e))}}e.TronLinkAdapter=i}(C)),C}var L,x,z={};function R(){return x||(x=1,e=j,t=j&&j.__createBinding||(Object.create?function(e,t,n,o){void 0===o&&(o=n);var r=Object.getOwnPropertyDescriptor(t,n);r&&!("get"in r?!t.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,o,r)}:function(e,t,n,o){void 0===o&&(o=n),e[o]=t[n]}),n=j&&j.__exportStar||function(e,n){for(var o in e)"default"===o||Object.prototype.hasOwnProperty.call(n,o)||t(n,e,o)},Object.defineProperty(e,"__esModule",{value:!0}),n(_(),e),n((L||(L=1,Object.defineProperty(z,"__esModule",{value:!0})),z),e),n(P(),e)),j;var e,t,n}var U,F,B,G,Q,Y,q={};function H(){if(U)return q;U=1,Object.defineProperty(q,"__esModule",{value:!0}),q.supportTokenPocket=t,q.isInTokenPocket=n,q.openTokenPocket=function(){if(!t()&&(0,e.isInMobileBrowser)()&&!n()){const{origin:e,pathname:t,search:n,hash:o}=window.location,r=e+t+n+o,i={action:"open",actionId:Date.now()+"",callbackUrl:"http://someurl.com",blockchain:"Tron",chain:"Tron",url:r,protocol:"TokenPocket",version:"1.0"};return window.location.href=`tpdapp://open?params=${encodeURIComponent(JSON.stringify(i))}`,!0}return!1};const e=W();function t(){return!!window.tronWeb&&void 0!==window.tokenpocket}function n(){return(0,e.isInBrowser)()&&void 0!==window.tokenpocket}return q}function J(){return F||(F=1,function(e){var t=o&&o.__awaiter||function(e,t,n,o){return new(n||(n=Promise))((function(r,i){function s(e){try{c(o.next(e))}catch(e){i(e)}}function a(e){try{c(o.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((o=o.apply(e,t||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0}),e.TokenPocketAdapter=e.TokenPocketAdapterName=void 0;const n=W(),r=R(),i=H(),s=W();e.TokenPocketAdapterName="TokenPocket";class a extends n.AddonAdapter{constructor(o={}){super(o),this.name=e.TokenPocketAdapterName,this.url="https://tokenpocket.pro/",this.icon="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTIwIiBoZWlnaHQ9IjEyMCIgdmlld0JveD0iMCAwIDEwMjQgMTAyNCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPGc+CjxwYXRoIGQ9Ik0xMDQxLjUyIDBILTI3VjEwMjRIMTA0MS41MlYwWiIgZmlsbD0iIzI5ODBGRSIvPgo8ZyBjbGlwLXBhdGg9InVybCgjY2xpcDBfNDA4XzIyNSkiPgo8cGF0aCBkPSJNNDA2Ljc5NiA0MzguNjQzSDQwNi45MjdDNDA2Ljc5NiA0MzcuODU3IDQwNi43OTYgNDM2Ljk0IDQwNi43OTYgNDM2LjE1NFY0MzguNjQzWiIgZmlsbD0iIzI5QUVGRiIvPgo8cGF0aCBkPSJNNjY3LjYwMiA0NjMuNTMzSDUyMy4yNDlWNzI0LjA3NkM1MjMuMjQ5IDczNi4zODkgNTMzLjIwNCA3NDYuMzQ1IDU0NS41MTcgNzQ2LjM0NUg2NDUuMzMzQzY1Ny42NDcgNzQ2LjM0NSA2NjcuNjAyIDczNi4zODkgNjY3LjYwMiA3MjQuMDc2VjQ2My41MzNaIiBmaWxsPSJ3aGl0ZSIvPgo8cGF0aCBkPSJNNDUzLjU2MyAyNzdINDQ4LjcxNkgxOTAuMjY5QzE3Ny45NTUgMjc3IDE2OCAyODYuOTU1IDE2OCAyOTkuMjY5VjM4OS42NTNDMTY4IDQwMS45NjcgMTc3Ljk1NSA0MTEuOTIyIDE5MC4yNjkgNDExLjkyMkgyNTAuOTE4SDI3NS4wMjFWNDM4LjY0NFY3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DI3NykiLz4KPC9jbGlwUGF0aD4KPC9kZWZzPgo8L3N2Zz4K",this._readyState=(0,n.isInBrowser)()?n.WalletReadyState.Loading:n.WalletReadyState.NotFound,this._state=n.AdapterState.Loading,this._securityPassed=!1,this.onAccountsChanged=e=>{if(!this._securityPassed)return;const t=this.address||"",o=(null==e?void 0:e[0])||"";if(o){const e=o;this.setAddress(e),this.setState(n.AdapterState.Connected)}else this.setAddress(null),this.setState(n.AdapterState.Disconnect);this.emit("accountsChanged",this.address||"",t),!t&&this.address?this.emit("connect",this.address):t&&!this.address&&this.emit("disconnect")},this.checkReadyInterval=null,this._checkPromise=null,this._updateWallet=()=>t(this,void 0,void 0,(function*(){var e,t,o,r,s;let a,c;if((0,i.supportTokenPocket)()){try{yield this.checkSecurity(),this._securityPassed=!0}catch(e){return this._securityPassed=!1,this.stopListenTronEvent(),this.setAddress(null),void this.setState(n.AdapterState.Disconnect)}const i=null===(e=window.tokenpocket)||void 0===e?void 0:e.tron;this._wallet=(0,n.isInMobileBrowser)()?{tron:i,ready:null===(t=window.tronWeb)||void 0===t?void 0:t.ready,tronWeb:null===(o=window.tokenpocket)||void 0===o?void 0:o.tronWeb}:{tron:i,ready:!!(null===(r=(null==i?void 0:i.tronWeb).defaultAddress)||void 0===r?void 0:r.base58)||!1,tronWeb:null==i?void 0:i.tronWeb},c=(null===(s=this._wallet.tronWeb.defaultAddress)||void 0===s?void 0:s.base58)||null,a=c?n.AdapterState.Connected:n.AdapterState.Disconnect,c||this.checkForWalletReady()}else this._wallet=null,c=null,a=n.AdapterState.NotFound;this.setAddress(c),this.setState(a)})),this.config=Object.assign({},this.commonConfig),this._connecting=!1,this._wallet=null,this._address=null,(0,n.isInMobileBrowser)()&&(0,i.supportTokenPocket)()?(this._readyState=n.WalletReadyState.Found,this._updateWallet().then((()=>{this.connected&&this.emit("connect",this.address||"")}))):this._checkWallet().then((()=>{this.connected&&this.emit("connect",this.address||"")}))}get address(){return this._address}get state(){return this._state}get readyState(){return this._readyState}get connecting(){return this._connecting}network(){return t(this,void 0,void 0,(function*(){try{if(yield this._checkWallet(),this.state!==n.AdapterState.Connected)throw new n.WalletDisconnectedError;const e=this._wallet;if(!e||!e.tronWeb)throw new n.WalletDisconnectedError;try{return yield(0,r.getNetworkInfoByTronWeb)(e.tronWeb)}catch(e){throw new n.WalletGetNetworkError(null==e?void 0:e.message,e)}}catch(e){throw this.emit("error",e),e}}))}_connect(){return t(this,void 0,void 0,(function*(){try{if(!(yield this._beforeConnect()))return;if(this._securityPassed=!0,!this._wallet)return;this._connecting=!0;const e=this._wallet,t=yield e.tron.request({method:"eth_requestAccounts"});if(!(null==t?void 0:t[0]))throw new n.WalletConnectionError("Request connect error.");const o=t[0];this.setAddress(o),this.setState(n.AdapterState.Connected),this.emit("connect",this.address||"")}catch(e){const t=e instanceof n.WalletError?e:new n.WalletConnectionError(null==e?void 0:e.message,e);throw this.emit("error",t),t}finally{this._connecting=!1}}))}disconnect(){return t(this,void 0,void 0,(function*(){this.state===n.AdapterState.Connected&&(this._securityPassed=!1,this.setAddress(null),this.setState(n.AdapterState.Disconnect),this.emit("disconnect"))}))}signTransaction(e){return t(this,void 0,void 0,(function*(){try{const t=yield this.checkAndGetWallet();try{return yield t.tronWeb.trx.sign(e)}catch(e){throw e instanceof Error||"object"==typeof e&&e.message?new n.WalletSignTransactionError(e.message,e):"string"==typeof e?new n.WalletSignTransactionError(e,new Error(e)):new n.WalletSignTransactionError("Unknown error",e)}}catch(e){throw this.emit("error",e),e}}))}multiSign(e){return t(this,arguments,void 0,(function*(e,t={}){try{const o=yield this.checkAndGetWallet();try{return yield o.tronWeb.trx.multiSign(e,void 0,t.permissionId)}catch(e){throw e instanceof Error||"object"==typeof e&&e.message?new n.WalletSignTransactionError(e.message,e):"string"==typeof e?new n.WalletSignTransactionError(e,new Error(e)):new n.WalletSignTransactionError("Unknown error",e)}}catch(e){throw this.emit("error",e),e}}))}signMessage(e){return t(this,void 0,void 0,(function*(){try{const t=yield this.checkAndGetWallet();try{return yield t.tronWeb.trx.signMessageV2(e)}catch(e){throw e instanceof Error||"object"==typeof e&&e.message?new n.WalletSignMessageError(e.message,e):"string"==typeof e?new n.WalletSignMessageError(e,new Error(e)):new n.WalletSignMessageError("Unknown error",e)}}catch(e){throw this.emit("error",e),e}}))}listenTronEvent(){if((0,n.isInMobileBrowser)())return;this.stopListenTronEvent();const e=this._wallet;e&&e.tron&&e.tron.on("accountsChanged",this.onAccountsChanged)}stopListenTronEvent(){if((0,n.isInMobileBrowser)())return;const e=this._wallet;e&&e.tron&&e.tron.removeListener("accountsChanged",this.onAccountsChanged)}checkAndGetWallet(){return t(this,void 0,void 0,(function*(){if(this.checkIfOpenApp(),yield this._checkWallet(),!this.connected)throw new n.WalletDisconnectedError;const e=this._wallet;if(!e||!e.tronWeb)throw new n.WalletDisconnectedError;return e}))}checkIfOpenApp(){if(!1!==this.config.openAppWithDeeplink&&(0,i.openTokenPocket)())throw new n.WalletNotFoundError}_openAppByDeepLinkIfNeed(){return!1!==this.config.openAppWithDeeplink&&(0,i.openTokenPocket)()}checkForWalletReady(){if(this.checkReadyInterval)return;let e=0;const t=Math.floor(this.config.checkTimeout/200);this.checkReadyInterval=setInterval((()=>{var o,r,i,s;if((0,n.isInMobileBrowser)()&&(null===(o=window.tronWeb)||void 0===o?void 0:o.ready))this.checkReadyInterval&&clearInterval(this.checkReadyInterval),this.checkReadyInterval=null,this._updateWallet(),this.emit("connect",this.address||"");else if(null===(s=null===(i=null===(r=this._wallet)||void 0===r?void 0:r.tronWeb)||void 0===i?void 0:i.defaultAddress)||void 0===s?void 0:s.base58){this.checkReadyInterval&&clearInterval(this.checkReadyInterval),this.checkReadyInterval=null,this._wallet.ready=!0;const e=this._wallet.tronWeb.defaultAddress.base58,t=e?n.AdapterState.Connected:n.AdapterState.Disconnect;this.setAddress(e),this.setState(t),this.emit("connect",this.address||"")}else e>t?(this.checkReadyInterval&&clearInterval(this.checkReadyInterval),this.checkReadyInterval=null):e++}),200)}_checkWallet(){if(this.readyState===n.WalletReadyState.Found)return Promise.resolve(!0);if(this._checkPromise)return this._checkPromise;if((0,n.isInBrowser)()&&!(0,n.isInMobileBrowser)()){const e=new Promise((e=>{const o=setTimeout((()=>{window.removeEventListener(s.TIP6963AnnounceProviderEventName,r),this._updateWallet(),(0,i.supportTokenPocket)()?(this._readyState=n.WalletReadyState.Found,e(!0)):(this._readyState=n.WalletReadyState.NotFound,e(!1)),this.emit("readyStateChanged",this._readyState)}),this.config.checkTimeout),r=i=>t(this,void 0,void 0,(function*(){var t,a,c;const{info:l,provider:d}=i.detail;if("TokenPocket"===l.name){this._wallet={ready:!!(null===(a=null===(t=d.tronWeb)||void 0===t?void 0:t.defaultAddress)||void 0===a?void 0:a.base58),tron:d,tronWeb:d.tronWeb},this.listenTronEvent(),this._readyState=n.WalletReadyState.Found;const i=(null===(c=this._wallet.tronWeb.defaultAddress)||void 0===c?void 0:c.base58)||null,l=i?n.AdapterState.Connected:n.AdapterState.Disconnect;try{yield this.checkSecurity(),this._securityPassed=!0}catch(t){return this._securityPassed=!1,this.stopListenTronEvent(),this.setAddress(null),this.setState(n.AdapterState.Disconnect),clearTimeout(o),void e(!0)}this.setState(l),this.setAddress(i),this.emit("readyStateChanged",this.readyState),window.removeEventListener(s.TIP6963AnnounceProviderEventName,r),clearTimeout(o),e(!0),this.connected||this.checkForWalletReady()}}));window.addEventListener(s.TIP6963AnnounceProviderEventName,r),window.dispatchEvent(new Event(s.TIP6963RequestProviderEventName))}));return this._checkPromise=e,e.then((t=>{t||this._checkPromise!==e||(this._checkPromise=null)})),e}const e=Math.floor(this.config.checkTimeout/100);let o,r=0;const a=new Promise((t=>{const s=()=>{r++;const s=(0,i.supportTokenPocket)();(s||r>e)&&(o&&clearInterval(o),this._readyState=s?n.WalletReadyState.Found:n.WalletReadyState.NotFound,this._updateWallet(),this.emit("readyStateChanged",this.readyState),t(s))};o=setInterval(s,100),s()}));return this._checkPromise=a,a.then((e=>{e||this._checkPromise!==a||(this._checkPromise=null)})),a}setAddress(e){this._address=e}setState(e){e!==this.state&&(this._state=e,this.emit("stateChanged",e))}}e.TokenPocketAdapter=a}(o)),o}return e((B||(B=1,G=n,Q=n&&n.__createBinding||(Object.create?function(e,t,n,o){void 0===o&&(o=n);var r=Object.getOwnPropertyDescriptor(t,n);r&&!("get"in r?!t.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,o,r)}:function(e,t,n,o){void 0===o&&(o=n),e[o]=t[n]}),Y=n&&n.__exportStar||function(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||Q(t,e,n)},Object.defineProperty(G,"__esModule",{value:!0}),Y(J(),G),Y(H(),G)),n))}));
package/package.json CHANGED
@@ -1,53 +1,53 @@
1
1
  {
2
- "name": "@tronweb3/tronwallet-adapter-tokenpocket",
3
- "version": "1.0.9",
4
- "description": "Wallet adapter for TokenPocket Extension and App wallet.",
5
- "keywords": [
6
- "TRON",
7
- "TronWeb",
8
- "TokenPocket"
9
- ],
10
- "author": "tronweb3",
11
- "repository": {
12
- "type": "git",
13
- "url": "https://github.com/tronweb3/tronwallet-adapter"
14
- },
15
- "license": "MIT",
16
- "type": "module",
17
- "sideEffects": false,
18
- "engines": {
19
- "node": ">=16",
20
- "pnpm": ">=7"
21
- },
22
- "main": "./lib/cjs/index.js",
23
- "module": "./lib/esm/index.js",
24
- "types": "./lib/types/index.d.ts",
25
- "exports": {
26
- "require": "./lib/cjs/index.js",
27
- "import": "./lib/esm/index.js",
28
- "types": "./lib/types/index.d.ts"
29
- },
30
- "files": [
31
- "lib",
32
- "src",
33
- "LICENSE"
34
- ],
35
- "publishConfig": {
36
- "access": "public"
37
- },
38
- "dependencies": {
39
- "@tronweb3/tronwallet-abstract-adapter": "^1.1.12",
40
- "@tronweb3/tronwallet-adapter-tronlink": "^1.1.14"
41
- },
42
- "devDependencies": {
43
- "@testing-library/dom": "8.20.1",
44
- "shx": "0.3.4",
45
- "vitest": "3.2.4"
46
- },
47
- "scripts": {
48
- "clean": "shx mkdir -p lib && shx rm -rf lib",
49
- "package": "shx echo '{ \"type\": \"commonjs\" }' > lib/cjs/package.json",
50
- "test": "vitest run",
51
- "build:umd": "node ../../../scripts/build-umd.js"
52
- }
53
- }
2
+ "name": "@tronweb3/tronwallet-adapter-tokenpocket",
3
+ "version": "1.2.0",
4
+ "description": "Wallet adapter for TokenPocket Extension and App wallet.",
5
+ "keywords": [
6
+ "TRON",
7
+ "TronWeb",
8
+ "TokenPocket"
9
+ ],
10
+ "author": "tronweb3",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/tronweb3/tronwallet-adapter"
14
+ },
15
+ "license": "MIT",
16
+ "type": "module",
17
+ "sideEffects": false,
18
+ "engines": {
19
+ "node": ">=16",
20
+ "pnpm": ">=7"
21
+ },
22
+ "main": "./lib/cjs/index.js",
23
+ "module": "./lib/esm/index.js",
24
+ "types": "./lib/types/index.d.ts",
25
+ "exports": {
26
+ "types": "./lib/types/index.d.ts",
27
+ "import": "./lib/esm/index.js",
28
+ "require": "./lib/cjs/index.js"
29
+ },
30
+ "files": [
31
+ "lib",
32
+ "src",
33
+ "LICENSE"
34
+ ],
35
+ "publishConfig": {
36
+ "access": "public"
37
+ },
38
+ "scripts": {
39
+ "clean": "shx mkdir -p lib && shx rm -rf lib",
40
+ "package": "shx echo '{ \"type\": \"commonjs\" }' > lib/cjs/package.json",
41
+ "test": "vitest run",
42
+ "build:umd": "node ../../../scripts/build-umd.js"
43
+ },
44
+ "dependencies": {
45
+ "@tronweb3/tronwallet-abstract-adapter": "^1.3.0",
46
+ "@tronweb3/tronwallet-adapter-tronlink": "^1.3.0"
47
+ },
48
+ "devDependencies": {
49
+ "@testing-library/dom": "8.20.1",
50
+ "shx": "0.3.4",
51
+ "vitest": "3.2.4"
52
+ }
53
+ }
package/src/adapter.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import {
2
- Adapter,
3
2
  AdapterState,
4
3
  isInBrowser,
5
4
  WalletReadyState,
@@ -11,6 +10,7 @@ import {
11
10
  WalletConnectionError,
12
11
  isInMobileBrowser,
13
12
  WalletError,
13
+ AddonAdapter,
14
14
  } from '@tronweb3/tronwallet-abstract-adapter';
15
15
  import type {
16
16
  Transaction,
@@ -29,18 +29,7 @@ import {
29
29
  TIP6963RequestProviderEventName,
30
30
  } from '@tronweb3/tronwallet-abstract-adapter';
31
31
 
32
- export interface TokenPocketAdapterConfig extends BaseAdapterConfig {
33
- /**
34
- * Timeout in millisecond for checking if is in TokenPocket App.
35
- * Default is 2 * 1000ms
36
- */
37
- checkTimeout?: number;
38
- /**
39
- * Set if open TokenPocket app using DeepLink.
40
- * Default is true.
41
- */
42
- openAppWithDeeplink?: boolean;
43
- }
32
+ export type TokenPocketAdapterConfig = BaseAdapterConfig;
44
33
 
45
34
  export const TokenPocketAdapterName = 'TokenPocket' as AdapterName<'TokenPocket'>;
46
35
 
@@ -56,7 +45,7 @@ declare global {
56
45
  }
57
46
  }
58
47
 
59
- export class TokenPocketAdapter extends Adapter {
48
+ export class TokenPocketAdapter extends AddonAdapter {
60
49
  name = TokenPocketAdapterName;
61
50
  url = 'https://tokenpocket.pro/';
62
51
  icon =
@@ -68,17 +57,17 @@ export class TokenPocketAdapter extends Adapter {
68
57
  private _connecting: boolean;
69
58
  private _wallet: TokenPocketWallet | null;
70
59
  private _address: string | null;
60
+ /**
61
+ * Whether the most recent security check passed. Gates the auto-connect
62
+ * paths (e.g. `onAccountsChanged`) so a wallet that failed the security
63
+ * check cannot silently connect when the extension emits account events.
64
+ */
65
+ private _securityPassed = false;
71
66
 
72
67
  constructor(config: TokenPocketAdapterConfig = {}) {
73
- super();
74
- const { checkTimeout = 2 * 1000, openUrlWhenWalletNotFound = true, openAppWithDeeplink = true } = config;
75
- if (typeof checkTimeout !== 'number') {
76
- throw new Error('[TokenPocketAdapter] config.checkTimeout should be a number');
77
- }
68
+ super(config);
78
69
  this.config = {
79
- checkTimeout,
80
- openAppWithDeeplink,
81
- openUrlWhenWalletNotFound,
70
+ ...this.commonConfig,
82
71
  };
83
72
  this._connecting = false;
84
73
  this._wallet = null;
@@ -86,7 +75,11 @@ export class TokenPocketAdapter extends Adapter {
86
75
 
87
76
  if (isInMobileBrowser() && supportTokenPocket()) {
88
77
  this._readyState = WalletReadyState.Found;
89
- this._updateWallet();
78
+ this._updateWallet().then(() => {
79
+ if (this.connected) {
80
+ this.emit('connect', this.address || '');
81
+ }
82
+ });
90
83
  } else {
91
84
  this._checkWallet().then(() => {
92
85
  if (this.connected) {
@@ -132,40 +125,26 @@ export class TokenPocketAdapter extends Adapter {
132
125
  }
133
126
  }
134
127
 
135
- async connect(): Promise<void> {
128
+ protected async _connect(): Promise<void> {
136
129
  try {
137
- this.checkIfOpenApp();
138
- if (this.connected || this.connecting) return;
139
- await this._checkWallet();
140
- if (this.readyState === WalletReadyState.NotFound) {
141
- if (this.config.openUrlWhenWalletNotFound !== false && isInBrowser()) {
142
- window.open(this.url, '_blank');
143
- }
144
- throw new WalletNotFoundError();
145
- }
130
+ if (!(await this._beforeConnect())) return;
131
+ this._securityPassed = true;
146
132
  if (!this._wallet) return;
147
133
  this._connecting = true;
148
134
  const wallet = this._wallet as TokenPocketWallet;
149
- try {
150
- const res = await wallet.tron.request({ method: 'eth_requestAccounts' });
151
- if (!res?.[0]) {
152
- throw new WalletConnectionError('Request connect error.');
153
- }
154
- const address = res[0];
155
-
156
- this.setAddress(address);
157
- this.setState(AdapterState.Connected);
158
- this.emit('connect', this.address || '');
159
- } catch (e: any) {
160
- if (e instanceof WalletError) {
161
- throw e;
162
- } else {
163
- throw new WalletConnectionError(e?.message, e);
164
- }
135
+ const res = await wallet.tron.request({ method: 'eth_requestAccounts' });
136
+ if (!res?.[0]) {
137
+ throw new WalletConnectionError('Request connect error.');
165
138
  }
139
+ const address = res[0];
140
+
141
+ this.setAddress(address);
142
+ this.setState(AdapterState.Connected);
143
+ this.emit('connect', this.address || '');
166
144
  } catch (error: any) {
167
- this.emit('error', error);
168
- throw error;
145
+ const err = error instanceof WalletError ? error : new WalletConnectionError(error?.message, error);
146
+ this.emit('error', err);
147
+ throw err;
169
148
  } finally {
170
149
  this._connecting = false;
171
150
  }
@@ -175,6 +154,7 @@ export class TokenPocketAdapter extends Adapter {
175
154
  if (this.state !== AdapterState.Connected) {
176
155
  return;
177
156
  }
157
+ this._securityPassed = false;
178
158
  this.setAddress(null);
179
159
  this.setState(AdapterState.Disconnect);
180
160
  this.emit('disconnect');
@@ -241,6 +221,8 @@ export class TokenPocketAdapter extends Adapter {
241
221
  }
242
222
 
243
223
  private onAccountsChanged: TronAccountsChangedCallback = (accounts) => {
224
+ // Do not auto-connect via account events when the security check has not passed.
225
+ if (!this._securityPassed) return;
244
226
  const preAddr = this.address || '';
245
227
  const curAddr = accounts?.[0] || '';
246
228
  if (!curAddr) {
@@ -295,6 +277,13 @@ export class TokenPocketAdapter extends Adapter {
295
277
  }
296
278
  }
297
279
 
280
+ protected _openAppByDeepLinkIfNeed(): boolean {
281
+ if (this.config.openAppWithDeeplink === false) {
282
+ return false;
283
+ }
284
+ return openTokenPocket();
285
+ }
286
+
298
287
  private checkReadyInterval: ReturnType<typeof setInterval> | null = null;
299
288
  private checkForWalletReady() {
300
289
  if (this.checkReadyInterval) {
@@ -332,7 +321,7 @@ export class TokenPocketAdapter extends Adapter {
332
321
  * check if wallet exists by interval, the promise only resolve when wallet detected or timeout
333
322
  * @returns if wallet exists
334
323
  */
335
- private _checkWallet(): Promise<boolean> {
324
+ protected _checkWallet(): Promise<boolean> {
336
325
  if (this.readyState === WalletReadyState.Found) {
337
326
  return Promise.resolve(true);
338
327
  }
@@ -341,7 +330,7 @@ export class TokenPocketAdapter extends Adapter {
341
330
  }
342
331
 
343
332
  if (isInBrowser() && !isInMobileBrowser()) {
344
- this._checkPromise = new Promise((resolve) => {
333
+ const detection = new Promise<boolean>((resolve) => {
345
334
  const timer = setTimeout(() => {
346
335
  window.removeEventListener(TIP6963AnnounceProviderEventName, handler);
347
336
  this._updateWallet();
@@ -354,7 +343,7 @@ export class TokenPocketAdapter extends Adapter {
354
343
  }
355
344
  this.emit('readyStateChanged', this._readyState);
356
345
  }, this.config.checkTimeout);
357
- const handler = (event: TIP6963AnnounceProviderEvent) => {
346
+ const handler = async (event: TIP6963AnnounceProviderEvent) => {
358
347
  const { info, provider } = event.detail;
359
348
  if (info.name === 'TokenPocket') {
360
349
  this._wallet = {
@@ -366,6 +355,18 @@ export class TokenPocketAdapter extends Adapter {
366
355
  this._readyState = WalletReadyState.Found;
367
356
  const address = this._wallet.tronWeb.defaultAddress?.base58 || null;
368
357
  const state = address ? AdapterState.Connected : AdapterState.Disconnect;
358
+ try {
359
+ await this.checkSecurity();
360
+ this._securityPassed = true;
361
+ } catch {
362
+ this._securityPassed = false;
363
+ this.stopListenTronEvent();
364
+ this.setAddress(null);
365
+ this.setState(AdapterState.Disconnect);
366
+ clearTimeout(timer);
367
+ resolve(true);
368
+ return;
369
+ }
369
370
  this.setState(state);
370
371
  this.setAddress(address);
371
372
  this.emit('readyStateChanged', this.readyState);
@@ -381,7 +382,17 @@ export class TokenPocketAdapter extends Adapter {
381
382
  window.addEventListener(TIP6963AnnounceProviderEventName, handler);
382
383
  window.dispatchEvent(new Event(TIP6963RequestProviderEventName));
383
384
  });
384
- return this._checkPromise;
385
+ this._checkPromise = detection;
386
+ // Never cache a failed detection: the wallet may inject late or be enabled at
387
+ // runtime. Unlike the polling adapters this keeps the full detection window on a
388
+ // retry, because the TIP-6963 announce is asynchronous and a shortened window
389
+ // would race it.
390
+ void detection.then((found) => {
391
+ if (!found && this._checkPromise === detection) {
392
+ this._checkPromise = null;
393
+ }
394
+ });
395
+ return detection;
385
396
  }
386
397
  // Support TIP-6963 with wallet extension
387
398
 
@@ -389,7 +400,7 @@ export class TokenPocketAdapter extends Adapter {
389
400
  const maxTimes = Math.floor(this.config.checkTimeout / interval);
390
401
  let times = 0,
391
402
  timer: ReturnType<typeof setInterval>;
392
- this._checkPromise = new Promise((resolve) => {
403
+ const detection = new Promise<boolean>((resolve) => {
393
404
  const check = () => {
394
405
  times++;
395
406
  const isSupport = supportTokenPocket();
@@ -404,13 +415,33 @@ export class TokenPocketAdapter extends Adapter {
404
415
  timer = setInterval(check, interval);
405
416
  check();
406
417
  });
407
- return this._checkPromise;
418
+ this._checkPromise = detection;
419
+ // Never cache a failed detection: the wallet may inject late or be enabled at
420
+ // runtime. Unlike the polling adapters this keeps the full detection window on a
421
+ // retry, because the TIP-6963 announce is asynchronous and a shortened window
422
+ // would race it.
423
+ void detection.then((found) => {
424
+ if (!found && this._checkPromise === detection) {
425
+ this._checkPromise = null;
426
+ }
427
+ });
428
+ return detection;
408
429
  }
409
430
 
410
- private _updateWallet = () => {
411
- let state = this.state;
412
- let address = this.address;
431
+ private _updateWallet = async () => {
432
+ let state: AdapterState;
433
+ let address: string | null;
413
434
  if (supportTokenPocket()) {
435
+ try {
436
+ await this.checkSecurity();
437
+ this._securityPassed = true;
438
+ } catch {
439
+ this._securityPassed = false;
440
+ this.stopListenTronEvent();
441
+ this.setAddress(null);
442
+ this.setState(AdapterState.Disconnect);
443
+ return;
444
+ }
414
445
  const tron = window.tokenpocket?.tron as Tron;
415
446
  this._wallet = isInMobileBrowser()
416
447
  ? ({