Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require(`../error-handling/error-codes.constants.cjs`),t=require(`../functions/utils/tron.utils.cjs`),n=require(`../functions/utils/create-provider.cjs`),r=require(`../functions/web3/getContractMetadata.cjs`);require(`../functions/index.cjs`);var i=class{chainId;tronWeb;address;signerAdapter;chainEventListener;accountsChangedHandler;constructor(e){this.chainId=e}initConnector(e){if(this.address=e.address,this.signerAdapter=e.signerAdapter,!this.chainId)throw Error(`TronProviderAdapter: Chain Id Not Set`);this.tronWeb=this.createSignableTronWeb(this.chainId,e.address)}async init(e){this.chainId=e}createSignableTronWeb=(e,n)=>{let r=t.createTronWeb(e);return r.setAddress(n),r.trx.sign=async e=>this.signerAdapter.signTransaction(e),r};async connectToConnector(){return this.chainId??0}async disconnectFromConnector(){}async connectAndPatchProvider(){if(!this.chainId)throw Error(`No Chain Id In Provider Adapter`);return this.chainId}getChainId(){return this.chainId}async waitForTransaction(t,r,i){let a=r.startsWith(`0x`)?r:`0x${r}`;if((await n.createJsonRpcProvider(t).waitForTransaction(a,i))?.status===1)return!0;throw Error(e.transactionErrorCodes.TRANSACTION_NOT_CONFIRMED)}async signMessage(t){let n=typeof t==`string`?t:new TextDecoder().decode(t),r=await this.signerAdapter.signMessage(n);if(r=r?.startsWith(`0x`)?r:`0x${r}`,!r)throw Error(e.transactionErrorCodes.SIGNING_FAILED);return r}async getAddress(){if(!this.address)throw Error(`IllegalState`);return this.address}setChainEventListener(e){this.chainEventListener=e,this.accountsChangedHandler&&this.signerAdapter.off(`accountsChanged`,this.accountsChangedHandler),this.accountsChangedHandler=e=>{this.chainEventListener&&(this.address=e,this.tronWeb?.setAddress(e),this.chainEventListener.onAccountChanged())},this.signerAdapter.on(`accountsChanged`,this.accountsChangedHandler)}async switchNetwork(e){this.chainEventListener?.onChainChanged(e.chainId)}async signTypedData(e,t,n){throw Error(`Typed data signing not supported on Tron`)}async onAccountChanged(){return Promise.resolve()}async onChainChanged(e){return Promise.resolve()}release(){this.chainEventListener=void 0,this.accountsChangedHandler&&=(this.signerAdapter.off(`accountsChanged`,this.accountsChangedHandler),void 0)}getContract(e,t,n,i){return r.getContract(t,e,n,i)}getContractWithSigner(e,t,n){throw Error(`Not implemented from TronProviderAdapter`)}getContractWithFetcher(e,t,r){let i=n.createJsonRpcProvider(e);return this.getContract(e,t,r,i)}async sendTransaction(e){throw Error(`Not implemented from TronProviderAdapter`)}async getGasPrice(e){throw Error(`Not implemented from TronProviderAdapter`)}isPermitterAvailable(){return!1}getTronWeb(){return this.tronWeb}},a=e=>new i(e);exports.TronProviderAdapter=i,exports.default=a;