UNPKG

@tronweb3/tronwallet-adapter-tronlink

Version:

Wallet adapter for TronLink Wallet extension and TronLink app.

2 lines (1 loc) 37.9 kB
!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-tronlink"]=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(n){if(!t(n))throw new e.WalletSignTypedDataError("typedData must be an object.");if(!t(n.domain))throw new e.WalletSignTypedDataError("typedData.domain must be an object.");if(!t(n.types))throw new e.WalletSignTypedDataError("typedData.types must be an object.");if(!t(n.message))throw new e.WalletSignTypedDataError("typedData.message must be an object.");const{chainId:o}=n.domain;if("string"==typeof o){const t=Number(o);if(!Number.isFinite(t))throw new e.WalletSignTypedDataError(`Invalid domain.chainId: ${o}.`);return Object.assign(Object.assign({},n),{domain:Object.assign(Object.assign({},n.domain),{chainId:t})})}return n};const e=u();function t(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}return l}var p,f,v={};function w(){return p||(p=1,Object.defineProperty(v,"__esModule",{value:!0}),v.TIP6963RequestProviderEventName=v.TIP6963AnnounceProviderEventName=v.ChainNetwork=v.NetworkType=v.AdapterState=v.WalletReadyState=void 0,function(e){e.Loading="Loading",e.NotFound="NotFound",e.Found="Found"}(e||(v.WalletReadyState=e={})),function(e){e.Loading="Loading",e.NotFound="NotFound",e.Disconnect="Disconnected",e.Connected="Connected"}(t||(v.AdapterState=t={})),function(e){e.Mainnet="Mainnet",e.Shasta="Shasta",e.Nile="Nile",e.Unknown="Unknown"}(n||(v.NetworkType=n={})),function(e){e.Mainnet="Mainnet",e.Shasta="Shasta",e.Nile="Nile"}(o||(v.ChainNetwork=o={})),v.TIP6963AnnounceProviderEventName="TIP6963:announceProvider",v.TIP6963RequestProviderEventName="TIP6963:requestProvider"),v;var e,t,n,o}function A(){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=w();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 y,m={};function g(){if(y)return m;function e(){return"undefined"!=typeof window&&"undefined"!=typeof document&&"undefined"!=typeof navigator}return y=1,Object.defineProperty(m,"__esModule",{value:!0}),m.isInBrowser=e,m.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)},m.isInMobileBrowser=function(){return"undefined"!=typeof navigator&&navigator.userAgent.match(/Android|webOS|iPhone|iPad|iPod|BlackBerry|Windows Phone/i)},m}var b,k,W,S={},T={};function C(){return b||(b=1,function(e){var t=T&&T.__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())}))};function n(e){return!!e&&"object"==typeof e&&"string"==typeof e.title&&e.title.length>0&&(1===e.noticeType||2===e.noticeType||3===e.noticeType)}function o(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 r(e){const t=e&&"object"==typeof e?e:{},r={};if(t.wallets&&"object"==typeof t.wallets)for(const[e,i]of Object.entries(t.wallets)){if(!Array.isArray(i)){console.warn(`[WalletAdapter] Ignoring malformed risks for "${e}": expected an array, got ${typeof i}.`);continue}const t=[];for(const r of i)n(r)?t.push(o(r)):console.warn(`[WalletAdapter] Dropping malformed risk entry for "${e}":`,r);t.length>0&&(r[e]=t)}return{v:"string"==typeof t.v?t.v:"",ts:"number"==typeof t.ts?t.ts:0,wallets:r}}Object.defineProperty(e,"__esModule",{value:!0}),e.defaultSecurityOptions=void 0,e.clearCache=function(){Object.keys(i).forEach((e=>{Reflect.deleteProperty(i,e)}))},e.fetchJsonWithCache=function(n){return t(this,void 0,void 0,(function*(){const{configUrls:o=e.defaultSecurityOptions.configUrls,timeout:s=e.defaultSecurityOptions.timeout,retries:a=e.defaultSecurityOptions.retries,onConfigFallback:c,cacheTTL:l=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=i[e];if(n&&d-n.timestamp<l)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()),s);fetch(e,{signal:o.signal}).then((e=>{clearTimeout(i),e.ok?e.json().then((e=>t(r(e))),n):n(new Error("Fetch failed with code: "+e.status))})).catch((e=>{clearTimeout(i),n(e)}))}))}))}for(let t=0;t<=a;t++)try{const t=yield o();return i[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:{}}):c?r(yield c()):{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 i={}}(T)),T}function E(){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=A(),n=u(),o=C(),r=w(),i=g();class s extends t.Adapter{constructor(e){if(super(),this.commonConfig={checkTimeout:2e3,openAppWithDeeplink:!0,openUrlWhenWalletNotFound:!0,securityOptions:o.defaultSecurityOptions},this._securityCheckCache=null,this.commonConfig=Object.assign(Object.assign({},this.commonConfig),e),"number"!=typeof this.commonConfig.checkTimeout)throw new Error("[WalletAdapter] config.checkTimeout should be a number");s._validateSecurityOptions(this.commonConfig.securityOptions)}static _validateSecurityOptions(e){const{enabled:t,configUrls:n}=e;if(t&&(!n||0===n.length))throw new Error("[WalletAdapter] config.securityOptions.configUrls is required when securityOptions.enabled is true")}updateSecurityOptions(e){const t=Object.assign(Object.assign({},this.commonConfig.securityOptions),e);s._validateSecurityOptions(t),this.commonConfig.securityOptions=t,this._securityCheckCache=null}_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 I(){return W||(W=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(A(),e),n(u(),e),n(w(),e),n(h(),e),n(g(),e),n(E(),e),n(C(),e)),r;var e,t,n}var O,N,L={};function P(){if(O)return L;O=1;var e=L&&L.__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(L,"__esModule",{value:!0}),L.supportTron=n,L.supportTronLink=o,L.isInTronLinkApp=r,L.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},L.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=I();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 L}function x(){return N||(N=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.TronLinkAdapter=e.TronLinkAdapterName=e.chainIdNetworkMap=void 0,e.getNetworkInfoByTronWeb=i;const n=I(),r=P();function i(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 s extends n.AddonAdapter{constructor(o={}){super(o),this.name=e.TronLinkAdapterName,this.url="https://www.tronlink.org/",this.icon="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAF0AAABdCAYAAADHcWrDAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAUGVYSWZNTQAqAAAACAACARIAAwAAAAEAAQAAh2kABAAAAAEAAAAmAAAAAAADoAEAAwAAAAEAAQAAoAIABAAAAAEAAABdoAMABAAAAAEAAABdAAAAAMkTBfIAAAFZaVRYdFhNTDpjb20uYWRvYmUueG1wAAAAAAA8eDp4bXBtZXRhIHhtbG5zOng9ImFkb2JlOm5zOm1ldGEvIiB4OnhtcHRrPSJYTVAgQ29yZSA2LjAuMCI+CiAgIDxyZGY6UkRGIHhtbG5zOnJkZj0iaHR0cDovL3d3dy53My5vcm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8oGmmw3IMjURZsWh3h/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;this._supportNewTronProtocol=!1;let l=this.state,d=this.address;if((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."),d=null,l=n.AdapterState.Disconnect,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}=o;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,r.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 i(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"}))[0];this.setAddress(t),this.setState(n.AdapterState.Connected),this._listenTronEvent(),this._wallet.tronWeb||(yield(0,r.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=(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=(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){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,r.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)())return this._checkPromise=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))})),this._checkPromise;const e=Math.floor(this.config.checkTimeout/100);let o,r=0;return this._checkPromise=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()})),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=s}(o)),o}var _,D,j,R,F,B={};return e((D||(D=1,j=n,R=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]}),F=n&&n.__exportStar||function(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||R(t,e,n)},Object.defineProperty(j,"__esModule",{value:!0}),F(x(),j),F((_||(_=1,Object.defineProperty(B,"__esModule",{value:!0})),B),j),F(P(),j)),n))}));