@tonconnect/ui 2.0.3-beta.1 → 2.0.3-beta.2

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.
@@ -1020,5 +1020,5 @@ var __defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnP
1020
1020
  width: 16px;
1021
1021
  `,_u=Hn($o)`
1022
1022
  margin-top: 32px;
1023
- `,ku=e=>{const t=No(e),n=xt(da),[r,o]=dt(!0),[i,s]=dt(!1);let a,l;gt((()=>{const e=Rr();s(!!e&&"sent"in e&&e.sent)})),(null==n?void 0:n.wallet)&&"universalLink"in n.wallet&&("universal-link"===n.wallet.openMethod||te(n.wallet.universalLink)&&yo())&&(a=n.wallet.universalLink),(null==n?void 0:n.wallet)&&"deepLink"in n.wallet&&("custom-deeplink"===n.wallet.openMethod||te(n.wallet.deepLink)&&yo())&&(l=n.wallet.deepLink);const c=()=>{const e=Rr(),t="returnStrategy"in e?e.returnStrategy:Pl.returnStrategy,n=!r();o(!1),te(a)?gc(a,{returnStrategy:t,twaReturnUrl:"twaReturnUrl"in e?e.twaReturnUrl:Pl.twaReturnUrl,forceRedirect:n}):pc(a,l,{returnStrategy:t,forceRedirect:n},(()=>{}))};return Ht(vu,qt(t,{get children(){return[pt((()=>e.icon)),Ht(yu,{get translationKey(){return e.headerTranslationKey},get translationValues(){return e.headerTranslationValues}}),Ht(bu,{get translationKey(){return e.textTranslationKey},get translationValues(){return e.textTranslationValues}}),Ht(Gt,{get when(){return!i()&&("open-wallet"===e.showButton&&a||"open-wallet"!==e.showButton)},get children(){return Ht(Cu,{disabled:!0,"data-tc-connect-button-loading":"true",get children(){return Ht(xu,{})}})}}),Ht(Gt,{get when(){return i()},get children(){return[Ht(Gt,{get when(){return"open-wallet"!==e.showButton},get children(){return Ht(_u,{onClick:()=>e.onClose(),get children(){return Ht(hc,{translationKey:"common.close",children:"Close"})}})}}),Ht(Gt,{get when(){return"open-wallet"===e.showButton&&a},get children(){return Ht(_u,{onClick:c,get children(){return Ht(hc,{translationKey:"common.openWallet",children:"Open wallet"})}})}})]}})]}}))},Su=e=>{const t=xt(da),[n]=$i();return Ht(ku,{headerTranslationKey:"actionModal.confirmTransaction.header",get headerTranslationValues(){return{name:t.wallet&&"name"in t.wallet?t.wallet.name:n("common.yourWallet",{},"Your wallet")}},textTranslationKey:"actionModal.confirmTransaction.text",get icon(){return Ht(ps,{size:"m"})},onClose:()=>e.onClose(),showButton:"open-wallet","data-tc-confirm-modal":"true"})},Eu=e=>Ht(ku,{headerTranslationKey:"actionModal.transactionCanceled.header",textTranslationKey:"actionModal.transactionCanceled.text",get icon(){return Ht(ds,{size:"m"})},onClose:()=>e.onClose(),"data-tc-transaction-canceled-modal":"true"}),Ru=e=>Ht(ku,{headerTranslationKey:"actionModal.transactionSent.header",textTranslationKey:"actionModal.transactionSent.text",get icon(){return Ht(as,{size:"m"})},onClose:()=>e.onClose(),"data-tc-transaction-sent-modal":"true"}),Tu=()=>Ht(di,{get opened(){var e;return pt((()=>null!==Rr()))()&&!0===(null==(e=Rr())?void 0:e.openModal)},get enableAndroidBackHandler(){return Pl.enableAndroidBackHandler},onClose:()=>Tr(null),"data-tc-actions-modal-container":"true",get children(){return Ht(Yt,{get children(){return[Ht(Qt,{get when(){return"transaction-sent"===Rr().name},get children(){return Ht(Ru,{onClose:()=>Tr(null)})}}),Ht(Qt,{get when(){return"transaction-canceled"===Rr().name},get children(){return Ht(Eu,{onClose:()=>Tr(null)})}}),Ht(Qt,{get when(){return"confirm-transaction"===Rr().name},get children(){return Ht(Su,{onClose:()=>Tr(null)})}})]}})}}),Lu=()=>{const{locale:e}=$i()[1];gt((()=>e(Pl.language))),gt((()=>{Cr()&&aa()}));const t=xt(Or),n=xt(da),[r,o]=dt(!1),i=()=>{var e;return"loading"===(null==(e=Pl.connectRequestParameters)?void 0:e.state)},s=pt((()=>{var e;if(!i())return null==(e=Pl.connectRequestParameters)?void 0:e.value})),a=e=>{n.closeSingleWalletModal(e)};return yt(t.onStatusChange((e=>{e&&a("wallet-selected")}))),yt((()=>{o(!1)})),Ht(Ol,{get opened(){return Cr()},get enableAndroidBackHandler(){return Pl.enableAndroidBackHandler},onClose:()=>a("action-cancelled"),onClickQuestion:()=>o((e=>!e)),"data-tc-wallets-modal-container":"true",get children(){return[Ht(Gt,{get when(){return r()},get children(){return Ht(Rc,{onBackClick:()=>o(!1)})}}),Ht(Gt,{get when(){return!r()},get children(){return[Ht(Gt,{get when(){return i()},get children(){return[Ht(Nl,{translationKey:"walletModal.loading",children:"Wallets list is loading"}),Ht($l,{get children(){return Ht(ps,{size:"m"})}})]}}),Ht(Gt,{get when(){return!i()},get children(){return Ht(kn,{get component(){return ia()?Kc:mc},get wallet(){return xr()},get additionalRequest(){return s()},onBackClick:()=>{},backDisabled:!0})}})]}})]}})},Au=e=>{const t=Oi(Ar,Pl.language);return customElements.define(Fn,class extends HTMLElement{}),document.body.hasAttribute("ontouchstart")||document.body.setAttribute("ontouchstart",""),Ht(Ni.Provider,{value:t,get children(){return Ht(da.Provider,{get value(){return e.tonConnectUI},get children(){return Ht(Or.Provider,{get value(){return Pl.connector},get children(){return[Ht(zn,{}),Ht(jn,{theme:ao,get children(){return[Ht(Gt,{get when(){return Pl.buttonRootId},get children(){return Ht(_n,{get mount(){return document.getElementById(Pl.buttonRootId)},get children(){return Ht(Ml,{})}})}}),Ht(kn,{component:Fn,get children(){return[Ht(mu,{}),Ht(Lu,{}),Ht(Tu,{})]}})]}})]}})}})}})},Mu=()=>{setTimeout((()=>mr({status:"opened",closeReason:null})))},Ou=e=>{setTimeout((()=>mr({status:"closed",closeReason:e})))},Nu=e=>{setTimeout((()=>br({status:"opened",closeReason:null,walletInfo:e})))},$u=e=>{setTimeout((()=>br({status:"closed",closeReason:e})))},Pu=e=>{setTimeout((()=>Tr(e)))},Iu=()=>{setTimeout((()=>Tr(null)))},Uu=()=>kr(),Wu=()=>Er(null),ju=(e,t)=>function(e,t,n,r={}){let o;return ut((r=>{o=r,t===document?e():hn(t,e(),t.firstChild?null:void 0,n)}),r.owner),()=>{o(),t.textContent=""}}((()=>Ht(Au,{tonConnectUI:t})),document.getElementById(e));class Bu{constructor(e){__publicField(this,"connector"),__publicField(this,"setConnectRequestParametersCallback"),__publicField(this,"consumers",[]),__publicField(this,"tracker"),__publicField(this,"state",wr()),this.connector=e.connector,this.tracker=e.tracker,this.setConnectRequestParametersCallback=e.setConnectRequestParametersCallback,gt((()=>{const e=wr();this.state=e,this.consumers.forEach((t=>t(e)))}))}open(){return __async(this,null,(function*(){this.tracker.trackConnectionStarted();const e=(yield this.connector.getWallets()).find(Ce);return e?this.connectEmbeddedWallet(e):this.openWalletsModal()}))}close(e="action-cancelled"){"action-cancelled"===e&&this.tracker.trackConnectionError("Connection was cancelled"),Ou(e)}onStateChange(e){return this.consumers.push(e),()=>{this.consumers=this.consumers.filter((t=>t!==e))}}connectEmbeddedWallet(e){const t=t=>{Er(e),this.connector.connect({jsBridgeKey:e.jsBridgeKey},t)},n=Pl.connectRequestParameters;"loading"===(null==n?void 0:n.state)?this.setConnectRequestParametersCallback(t):t(null==n?void 0:n.value)}openWalletsModal(){return __async(this,null,(function*(){return yo()&&bo(),Mu(),new Promise((e=>{const t=this.onStateChange((n=>{const{status:r}=n;"opened"===r&&(t(),e())}))}))}))}}class Du{constructor(e){__publicField(this,"connector"),__publicField(this,"consumers",[]),this.connector=e.connector,gt((()=>{const e=Rr();this.consumers.forEach((t=>t(e)))}))}onStateChange(e){return this.consumers.push(e),()=>{this.consumers=this.consumers.filter((t=>t!==e))}}}class Hu{constructor(e){__publicField(this,"connector"),__publicField(this,"setConnectRequestParametersCallback"),__publicField(this,"consumers",[]),__publicField(this,"tracker"),__publicField(this,"state",yr()),this.connector=e.connector,this.tracker=e.tracker,this.setConnectRequestParametersCallback=e.setConnectRequestParametersCallback,gt((()=>{const e=yr();this.state=e,this.consumers.forEach((t=>t(e)))}))}open(e){return __async(this,null,(function*(){this.tracker.trackConnectionStarted();const t=Wl(yield this.connector.getWallets(),Pl.walletsListConfiguration),n=t.find(Ce);if(!!n)return this.connectEmbeddedWallet(n);const r=t.filter(_e).find((t=>Hl(t,e)));if(!!r)return this.openSingleWalletModal(r);const o=`Trying to open modal window with unknown wallet "${e}".`;throw this.tracker.trackConnectionError(o),new er(o)}))}close(e="action-cancelled"){"action-cancelled"===e&&this.tracker.trackConnectionError("Connection was cancelled"),$u("action-cancelled")}onStateChange(e){return this.consumers.push(e),()=>{this.consumers=this.consumers.filter((t=>t!==e))}}connectEmbeddedWallet(e){const t=t=>{Er(e),this.connector.connect({jsBridgeKey:e.jsBridgeKey},t)},n=Pl.connectRequestParameters;"loading"===(null==n?void 0:n.state)?this.setConnectRequestParametersCallback(t):t(null==n?void 0:n.value)}openSingleWalletModal(e){return __async(this,null,(function*(){return yo()&&bo(),Nu(e),new Promise((e=>{const t=this.onStateChange((n=>{const{status:r}=n;"opened"===r&&(t(),e())}))}))}))}}class Ku{constructor(e){__publicField(this,"eventPrefix","ton-connect-ui-"),__publicField(this,"eventDispatcher"),this.eventDispatcher=null!=e?e:new Be}dispatchUserActionEvent(e){var t;try{const n=`${this.eventPrefix}${e.type}`;null==(t=this.eventDispatcher)||t.dispatchEvent(n,e).catch()}catch(Fu){}}trackConnectionStarted(...e){try{const e={type:"connection-started"};this.dispatchUserActionEvent(e)}catch(Fu){}}trackConnectionCompleted(...e){try{const t=Ae(...e);this.dispatchUserActionEvent(t)}catch(Fu){}}trackConnectionError(...e){try{const t=Me(...e);this.dispatchUserActionEvent(t)}catch(Fu){}}trackConnectionRestoringStarted(...e){try{const e={type:"connection-restoring-started"};this.dispatchUserActionEvent(e)}catch(Fu){}}trackConnectionRestoringCompleted(...e){try{const t=Ne(...e);this.dispatchUserActionEvent(t)}catch(Fu){}}trackConnectionRestoringError(...e){try{const t=$e(...e);this.dispatchUserActionEvent(t)}catch(Fu){}}trackDisconnection(...e){try{const t=je(...e);this.dispatchUserActionEvent(t)}catch(Fu){}}trackTransactionSentForSignature(...e){try{const t=Ie(...e);this.dispatchUserActionEvent(t)}catch(Fu){}}trackTransactionSigned(...e){try{const t=Ue(...e);this.dispatchUserActionEvent(t)}catch(Fu){}}trackTransactionSigningFailed(...e){try{const t=We(...e);this.dispatchUserActionEvent(t)}catch(Fu){}}}e.BadRequestError=B,e.BrowserEventDispatcher=Be,e.FetchWalletsError=F,e.LocalstorageNotFoundError=K,e.ParseHexError=q,e.THEME=Sn,e.TonConnect=He,e.TonConnectError=N,e.TonConnectUI=class{constructor(e){if(__publicField(this,"walletInfoStorage",new fr),__publicField(this,"preferredWalletStorage",new gr),__publicField(this,"tracker"),__publicField(this,"walletInfo",null),__publicField(this,"systemThemeChangeUnsubscribe",null),__publicField(this,"actionsConfiguration"),__publicField(this,"walletsList"),__publicField(this,"connectRequestParametersCallback"),__publicField(this,"connector"),__publicField(this,"modal"),__publicField(this,"singleWalletModal"),__publicField(this,"transactionModal"),__publicField(this,"connectionRestored",Promise.resolve(!1)),e&&"connector"in e&&e.connector)this.connector=e.connector;else{if(!(e&&"manifestUrl"in e&&e.manifestUrl))throw new er("You have to specify a `manifestUrl` or a `connector` in the options.");this.connector=new He({manifestUrl:e.manifestUrl,eventDispatcher:null==e?void 0:e.eventDispatcher})}this.tracker=new Ku(null==e?void 0:e.eventDispatcher),this.modal=new Bu({connector:this.connector,tracker:this.tracker,setConnectRequestParametersCallback:e=>{this.connectRequestParametersCallback=e}}),this.singleWalletModal=new Hu({connector:this.connector,tracker:this.tracker,setConnectRequestParametersCallback:e=>{this.connectRequestParametersCallback=e}}),this.transactionModal=new Du({connector:this.connector}),this.walletsList=this.getWallets(),this.walletsList.then((e=>{return sr((t=e.map((e=>e.imageUrl)),[...new Set(t)]));var t}));const t=this.normalizeWidgetRoot(null==e?void 0:e.widgetRootId);this.subscribeToWalletChange(),!1!==(null==e?void 0:e.restoreConnection)&&(this.tracker.trackConnectionRestoringStarted(),this.connectionRestored=new Promise((e=>__async(this,null,(function*(){yield this.connector.restoreConnection(),this.connector.connected?this.tracker.trackConnectionRestoringCompleted(this.wallet):(this.tracker.trackConnectionRestoringError("Connection was not restored"),this.walletInfoStorage.removeWalletInfo()),e(this.connector.connected)}))))),this.uiOptions=so(e,{uiPreferences:{theme:"SYSTEM"}});const n=this.preferredWalletStorage.getPreferredWalletAppName();Il({connector:this.connector,preferredWalletAppName:n}),ju(t,this)}static getWallets(){return He.getWallets()}get connected(){return this.connector.connected}get account(){return this.connector.account}get wallet(){return this.connector.wallet?__spreadValues(__spreadValues({},this.connector.wallet),this.walletInfo):null}set uiOptions(e){var t,n,r,o,i,s,a;this.checkButtonRootExist(e.buttonRootId),this.actionsConfiguration=e.actionsConfiguration,(null==(t=e.uiPreferences)?void 0:t.theme)?"SYSTEM"!==(null==(n=e.uiPreferences)?void 0:n.theme)?(null==(r=this.systemThemeChangeUnsubscribe)||r.call(this),ho(e.uiPreferences.theme,e.uiPreferences.colorsSet)):(ho(window.matchMedia&&window.matchMedia("(prefers-color-scheme: light)").matches?Sn.LIGHT:Sn.DARK,e.uiPreferences.colorsSet),this.systemThemeChangeUnsubscribe||(this.systemThemeChangeUnsubscribe=function(e){const t=t=>e(t.matches?Sn.DARK:Sn.LIGHT);return window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",t),()=>window.matchMedia("(prefers-color-scheme: dark)").removeEventListener("change",t)}(ho))):(null==(o=e.uiPreferences)?void 0:o.colorsSet)&&(s=e.uiPreferences.colorsSet,uo[Sn.DARK]=so(s[Sn.DARK],uo[Sn.DARK]),uo[Sn.LIGHT]=so(s[Sn.LIGHT],uo[Sn.LIGHT]),lo((e=>({colors:so(uo[e.theme],co[e.theme])})))),(null==(i=e.uiPreferences)?void 0:i.borderRadius)&&(a=e.uiPreferences.borderRadius,lo({borderRadius:a})),Il((t=>{var n,r;const o=so(__spreadValues(__spreadValues(__spreadValues(__spreadValues({},e.language&&{language:e.language}),!!(null==(n=e.actionsConfiguration)?void 0:n.returnStrategy)&&{returnStrategy:e.actionsConfiguration.returnStrategy}),!!(null==(r=e.actionsConfiguration)?void 0:r.twaReturnUrl)&&{twaReturnUrl:e.actionsConfiguration.twaReturnUrl}),!!e.walletsListConfiguration&&{walletsListConfiguration:e.walletsListConfiguration}),Wr(t));return void 0!==e.buttonRootId&&(o.buttonRootId=e.buttonRootId),void 0!==e.enableAndroidBackHandler&&(o.enableAndroidBackHandler=e.enableAndroidBackHandler),o}))}setConnectRequestParameters(e){var t;Il({connectRequestParameters:e}),"ready"!==(null==e?void 0:e.state)&&e||null==(t=this.connectRequestParametersCallback)||t.call(this,null==e?void 0:e.value)}getWallets(){return __async(this,null,(function*(){return this.connector.getWallets()}))}onStatusChange(e,t){return this.connector.onStatusChange((t=>__async(this,null,(function*(){if(t){const n=yield this.getSelectedWalletInfo(t);e(__spreadValues(__spreadValues({},t),n||this.walletInfoStorage.getWalletInfo()))}else e(t)}))),t)}openModal(){return __async(this,null,(function*(){return this.modal.open()}))}closeModal(e){this.modal.close(e)}onModalStateChange(e){return this.modal.onStateChange(e)}get modalState(){return this.modal.state}openSingleWalletModal(e){return __async(this,null,(function*(){return this.singleWalletModal.open(e)}))}closeSingleWalletModal(e){this.singleWalletModal.close(e)}onSingleWalletModalStateChange(e){return this.singleWalletModal.onStateChange(e)}get singleWalletModalState(){return this.singleWalletModal.state}connectWallet(){return __async(this,null,(function*(){const e=(yield this.getWallets()).find(Ce);return e?yield this.connectEmbeddedWallet(e):yield this.connectExternalWallet()}))}disconnect(){return this.tracker.trackDisconnection(this.wallet,"dapp"),Iu(),Wu(),this.walletInfoStorage.removeWalletInfo(),this.connector.disconnect()}sendTransaction(e,t){return __async(this,null,(function*(){if(this.tracker.trackTransactionSentForSignature(this.wallet,e),!this.connected)throw this.tracker.trackTransactionSigningFailed(this.wallet,e,"Wallet was not connected"),new er("Connect wallet to send a transaction.");yo()&&bo();const{notifications:n,modals:r,returnStrategy:o,twaReturnUrl:i,skipRedirectToWallet:s}=this.getModalsAndNotificationsConfiguration(t);Pu({name:"confirm-transaction",showNotification:n.includes("before"),openModal:r.includes("before"),sent:!1});const a=()=>{l.signal.aborted||(Pu({name:"confirm-transaction",showNotification:n.includes("before"),openModal:r.includes("before"),sent:!0}),this.walletInfo&&"universalLink"in this.walletInfo&&("universal-link"===this.walletInfo.openMethod||"custom-deeplink"===this.walletInfo.openMethod)&&(te(this.walletInfo.universalLink)?gc(this.walletInfo.universalLink,{returnStrategy:o,twaReturnUrl:i||Pl.twaReturnUrl,forceRedirect:!1}):pc(this.walletInfo.universalLink,this.walletInfo.deepLink,{returnStrategy:o,forceRedirect:!1},(()=>{}))))},l=new AbortController,c=this.onTransactionModalStateChange((e=>{(null==e?void 0:e.openModal)||(c(),e||l.abort())}));try{const t=yield this.waitForSendTransaction({transaction:e,signal:l.signal},a);return this.tracker.trackTransactionSigned(this.wallet,e,t),Pu({name:"transaction-sent",showNotification:n.includes("success"),openModal:r.includes("success")}),t}catch(Fu){throw this.tracker.trackTransactionSigningFailed(this.wallet,e,Fu.message),Pu({name:"transaction-canceled",showNotification:n.includes("error"),openModal:r.includes("error")}),Fu instanceof N?Fu:(console.error(Fu),new er("Unhandled error:"+Fu))}finally{c()}}))}connectEmbeddedWallet(e){return __async(this,null,(function*(){const t=t=>{Er(e),this.connector.connect({jsBridgeKey:e.jsBridgeKey},t)},n=Pl.connectRequestParameters;return"loading"===(null==n?void 0:n.state)?this.connectRequestParametersCallback=t:t(null==n?void 0:n.value),yield this.waitForWalletConnection({ignoreErrors:!1})}))}connectExternalWallet(){return __async(this,null,(function*(){const e=new AbortController;Mu();const t=this.onModalStateChange((n=>{const{status:r,closeReason:o}=n;"opened"!==r&&(t(),"action-cancelled"===o&&e.abort())}));return yield this.waitForWalletConnection({ignoreErrors:!0,signal:e.signal})}))}waitForWalletConnection(e){return __async(this,null,(function*(){return new Promise(((t,n)=>{this.tracker.trackConnectionStarted();const{ignoreErrors:r=!1,signal:o=null}=e;if(o&&o.aborted)return this.tracker.trackConnectionError("Connection was cancelled"),n(new er("Wallet was not connected"));const i=e=>__async(this,null,(function*(){if(e)this.tracker.trackConnectionCompleted(e),a(),t(e);else{if(this.tracker.trackConnectionError("Connection was cancelled"),r)return;a(),n(new er("Wallet was not connected"))}})),s=e=>{this.tracker.trackConnectionError(e.message),r||(a(),n(e))},a=this.onStatusChange((e=>i(e)),(e=>s(e)));o&&o.addEventListener("abort",(()=>{a(),n(new er("Wallet was not connected"))}),{once:!0})}))}))}waitForSendTransaction(e,t){return __async(this,null,(function*(){return new Promise(((n,r)=>{const{transaction:o,signal:i}=e;if(i.aborted)return r(new er("Transaction was not sent"));const s=e=>__async(this,null,(function*(){n(e)}));this.connector.sendTransaction(o,{onRequestSent:t,signal:i}).then((e=>s(e))).catch((e=>(e=>{r(e)})(e))),i.addEventListener("abort",(()=>{r(new er("Transaction was not sent"))}),{once:!0})}))}))}onTransactionModalStateChange(e){return this.transactionModal.onStateChange(e)}subscribeToWalletChange(){this.connector.onStatusChange((e=>__async(this,null,(function*(){var t;e?(yield this.updateWalletInfo(e),this.setPreferredWalletAppName((null==(t=this.walletInfo)?void 0:t.appName)||e.device.appName)):this.walletInfoStorage.removeWalletInfo()}))))}setPreferredWalletAppName(e){this.preferredWalletStorage.setPreferredWalletAppName(e),Il({preferredWalletAppName:e})}getSelectedWalletInfo(e){return __async(this,null,(function*(){let t,n=Uu();if(!n)return null;if("name"in n)t=n;else{const r=Wl(yield this.walletsList,Pl.walletsListConfiguration).find((t=>Hl(t,e.device.appName)));if(!r)throw new er(`Cannot find WalletInfo for the '${e.device.appName}' wallet`);t=__spreadValues(__spreadValues({},r),n)}return t}))}updateWalletInfo(e){return __async(this,null,(function*(){const t=yield this.getSelectedWalletInfo(e);if(t)return this.walletInfo=t,void this.walletInfoStorage.setWalletInfo(t);const n=this.walletInfoStorage.getWalletInfo();this.walletInfo=n||((yield this.walletsList).find((t=>Hl(t,e.device.appName)))||null)}))}normalizeWidgetRoot(e){if(!e||!document.getElementById(e)){e="tc-widget-root";const t=document.createElement("div");t.id=e,document.body.appendChild(t)}return e}checkButtonRootExist(e){if(null!=e&&!document.getElementById(e))throw new er(`${e} element not found in the document.`)}getModalsAndNotificationsConfiguration(e){var t,n,r,o,i,s;const a=["before","success","error"];let l=a;(null==(t=this.actionsConfiguration)?void 0:t.notifications)&&"all"!==(null==(n=this.actionsConfiguration)?void 0:n.notifications)&&(l=this.actionsConfiguration.notifications),(null==e?void 0:e.notifications)&&(l="all"===e.notifications?a:e.notifications);let c=["before"];(null==(r=this.actionsConfiguration)?void 0:r.modals)&&(c="all"===this.actionsConfiguration.modals?a:this.actionsConfiguration.modals),(null==e?void 0:e.modals)&&(c="all"===e.modals?a:e.modals);const u=(null==e?void 0:e.returnStrategy)||(null==(o=this.actionsConfiguration)?void 0:o.returnStrategy)||"back",d=(null==e?void 0:e.twaReturnUrl)||(null==(i=this.actionsConfiguration)?void 0:i.twaReturnUrl);let h=(null==e?void 0:e.skipRedirectToWallet)||(null==(s=this.actionsConfiguration)?void 0:s.skipRedirectToWallet)||"ios";return yo()&&(h="never"),{notifications:l,modals:c,returnStrategy:u,twaReturnUrl:d,skipRedirectToWallet:h}}},e.TonConnectUIError=er,e.UnknownAppError=D,e.UnknownError=z,e.UserRejectsError=j,e.WalletAlreadyConnectedError=U,e.WalletNotConnectedError=W,e.WalletNotInjectedError=H,e.WalletsListManager=Se,e.WrongAddressError=V,e.createConnectionCompletedEvent=Ae,e.createConnectionErrorEvent=Me,e.createConnectionRestoringCompletedEvent=Ne,e.createConnectionRestoringErrorEvent=$e,e.createConnectionRestoringStartedEvent=Oe,e.createConnectionStartedEvent=Le,e.createDisconnectionEvent=je,e.createTransactionSentForSignatureEvent=Ie,e.createTransactionSignedEvent=Ue,e.createTransactionSigningFailedEvent=We,e.encodeTelegramUrlParameters=ne,e.isTelegramUrl=te,e.isWalletInfoCurrentlyEmbedded=Ce,e.isWalletInfoCurrentlyInjected=be,e.isWalletInfoInjectable=xe,e.isWalletInfoInjected=function(e){return"jsBridgeKey"in e},e.isWalletInfoRemote=_e,e.toUserFriendlyAddress=Ve,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
1023
+ `,ku=e=>{const t=No(e),n=xt(da),[r,o]=dt(!0),[i,s]=dt(!1);let a,l;gt((()=>{const e=Rr();s(!!e&&"sent"in e&&e.sent)})),(null==n?void 0:n.wallet)&&"universalLink"in n.wallet&&("universal-link"===n.wallet.openMethod||te(n.wallet.universalLink)&&yo())&&(a=n.wallet.universalLink),(null==n?void 0:n.wallet)&&"deepLink"in n.wallet&&("custom-deeplink"===n.wallet.openMethod||te(n.wallet.deepLink)&&yo())&&(l=n.wallet.deepLink);const c=()=>{const e=Rr(),t="returnStrategy"in e?e.returnStrategy:Pl.returnStrategy,n=!r();o(!1),te(a)?gc(a,{returnStrategy:t,twaReturnUrl:"twaReturnUrl"in e?e.twaReturnUrl:Pl.twaReturnUrl,forceRedirect:n}):pc(a,l,{returnStrategy:t,forceRedirect:n},(()=>{}))};return Ht(vu,qt(t,{get children(){return[pt((()=>e.icon)),Ht(yu,{get translationKey(){return e.headerTranslationKey},get translationValues(){return e.headerTranslationValues}}),Ht(bu,{get translationKey(){return e.textTranslationKey},get translationValues(){return e.textTranslationValues}}),Ht(Gt,{get when(){return!i()&&("open-wallet"===e.showButton&&a||"open-wallet"!==e.showButton)},get children(){return Ht(Cu,{disabled:!0,"data-tc-connect-button-loading":"true",get children(){return Ht(xu,{})}})}}),Ht(Gt,{get when(){return i()},get children(){return[Ht(Gt,{get when(){return"open-wallet"!==e.showButton},get children(){return Ht(_u,{onClick:()=>e.onClose(),get children(){return Ht(hc,{translationKey:"common.close",children:"Close"})}})}}),Ht(Gt,{get when(){return"open-wallet"===e.showButton&&a},get children(){return Ht(_u,{onClick:c,get children(){return Ht(hc,{translationKey:"common.openWallet",children:"Open wallet"})}})}})]}})]}}))},Su=e=>{const t=xt(da),[n]=$i();return Ht(ku,{headerTranslationKey:"actionModal.confirmTransaction.header",get headerTranslationValues(){return{name:t.wallet&&"name"in t.wallet?t.wallet.name:n("common.yourWallet",{},"Your wallet")}},textTranslationKey:"actionModal.confirmTransaction.text",get icon(){return Ht(ps,{size:"m"})},onClose:()=>e.onClose(),showButton:"open-wallet","data-tc-confirm-modal":"true"})},Eu=e=>Ht(ku,{headerTranslationKey:"actionModal.transactionCanceled.header",textTranslationKey:"actionModal.transactionCanceled.text",get icon(){return Ht(ds,{size:"m"})},onClose:()=>e.onClose(),"data-tc-transaction-canceled-modal":"true"}),Ru=e=>Ht(ku,{headerTranslationKey:"actionModal.transactionSent.header",textTranslationKey:"actionModal.transactionSent.text",get icon(){return Ht(as,{size:"m"})},onClose:()=>e.onClose(),"data-tc-transaction-sent-modal":"true"}),Tu=()=>Ht(di,{get opened(){var e;return pt((()=>null!==Rr()))()&&!0===(null==(e=Rr())?void 0:e.openModal)},get enableAndroidBackHandler(){return Pl.enableAndroidBackHandler},onClose:()=>Tr(null),"data-tc-actions-modal-container":"true",get children(){return Ht(Yt,{get children(){return[Ht(Qt,{get when(){return"transaction-sent"===Rr().name},get children(){return Ht(Ru,{onClose:()=>Tr(null)})}}),Ht(Qt,{get when(){return"transaction-canceled"===Rr().name},get children(){return Ht(Eu,{onClose:()=>Tr(null)})}}),Ht(Qt,{get when(){return"confirm-transaction"===Rr().name},get children(){return Ht(Su,{onClose:()=>Tr(null)})}})]}})}}),Lu=()=>{const{locale:e}=$i()[1];gt((()=>e(Pl.language))),gt((()=>{Cr()&&aa()}));const t=xt(Or),n=xt(da),[r,o]=dt(!1),i=()=>{var e;return"loading"===(null==(e=Pl.connectRequestParameters)?void 0:e.state)},s=pt((()=>{var e;if(!i())return null==(e=Pl.connectRequestParameters)?void 0:e.value})),a=e=>{n.closeSingleWalletModal(e)};return yt(t.onStatusChange((e=>{e&&a("wallet-selected")}))),yt((()=>{o(!1)})),Ht(Ol,{get opened(){return Cr()},get enableAndroidBackHandler(){return Pl.enableAndroidBackHandler},onClose:()=>a("action-cancelled"),onClickQuestion:()=>o((e=>!e)),"data-tc-wallets-modal-container":"true",get children(){return[Ht(Gt,{get when(){return r()},get children(){return Ht(Rc,{onBackClick:()=>o(!1)})}}),Ht(Gt,{get when(){return!r()},get children(){return[Ht(Gt,{get when(){return i()},get children(){return[Ht(Nl,{translationKey:"walletModal.loading",children:"Wallets list is loading"}),Ht($l,{get children(){return Ht(ps,{size:"m"})}})]}}),Ht(Gt,{get when(){return!i()},get children(){return Ht(kn,{get component(){return ia()?Kc:mc},get wallet(){return xr()},get additionalRequest(){return s()},onBackClick:()=>{},backDisabled:!0})}})]}})]}})},Au=e=>{const t=Oi(Ar,Pl.language);return customElements.define(Fn,class extends HTMLElement{}),document.body.hasAttribute("ontouchstart")||document.body.setAttribute("ontouchstart",""),Ht(Ni.Provider,{value:t,get children(){return Ht(da.Provider,{get value(){return e.tonConnectUI},get children(){return Ht(Or.Provider,{get value(){return Pl.connector},get children(){return[Ht(zn,{}),Ht(jn,{theme:ao,get children(){return[Ht(Gt,{get when(){return Pl.buttonRootId},get children(){return Ht(_n,{get mount(){return document.getElementById(Pl.buttonRootId)},get children(){return Ht(Ml,{})}})}}),Ht(kn,{component:Fn,get children(){return[Ht(mu,{}),Ht(Lu,{}),Ht(Tu,{})]}})]}})]}})}})}})},Mu=()=>{setTimeout((()=>mr({status:"opened",closeReason:null})))},Ou=e=>{setTimeout((()=>mr({status:"closed",closeReason:e})))},Nu=e=>{setTimeout((()=>br({status:"opened",closeReason:null,walletInfo:e})))},$u=e=>{setTimeout((()=>br({status:"closed",closeReason:e})))},Pu=e=>{setTimeout((()=>Tr(e)))},Iu=()=>{setTimeout((()=>Tr(null)))},Uu=()=>kr(),Wu=()=>Er(null),ju=(e,t)=>function(e,t,n,r={}){let o;return ut((r=>{o=r,t===document?e():hn(t,e(),t.firstChild?null:void 0,n)}),r.owner),()=>{o(),t.textContent=""}}((()=>Ht(Au,{tonConnectUI:t})),document.getElementById(e));class Bu{constructor(e){__publicField(this,"connector"),__publicField(this,"setConnectRequestParametersCallback"),__publicField(this,"consumers",[]),__publicField(this,"tracker"),__publicField(this,"state",wr()),this.connector=e.connector,this.tracker=e.tracker,this.setConnectRequestParametersCallback=e.setConnectRequestParametersCallback,gt((()=>{const e=wr();this.state=e,this.consumers.forEach((t=>t(e)))}))}open(){return __async(this,null,(function*(){this.tracker.trackConnectionStarted();const e=(yield this.connector.getWallets()).find(Ce);return e?this.connectEmbeddedWallet(e):this.openWalletsModal()}))}close(e="action-cancelled"){"action-cancelled"===e&&this.tracker.trackConnectionError("Connection was cancelled"),Ou(e)}onStateChange(e){return this.consumers.push(e),()=>{this.consumers=this.consumers.filter((t=>t!==e))}}connectEmbeddedWallet(e){const t=t=>{Er(e),this.connector.connect({jsBridgeKey:e.jsBridgeKey},t)},n=Pl.connectRequestParameters;"loading"===(null==n?void 0:n.state)?this.setConnectRequestParametersCallback(t):t(null==n?void 0:n.value)}openWalletsModal(){return __async(this,null,(function*(){return yo()&&bo(),Mu(),new Promise((e=>{const t=this.onStateChange((n=>{const{status:r}=n;"opened"===r&&(t(),e())}))}))}))}}class Du{constructor(e){__publicField(this,"connector"),__publicField(this,"consumers",[]),this.connector=e.connector,gt((()=>{const e=Rr();this.consumers.forEach((t=>t(e)))}))}onStateChange(e){return this.consumers.push(e),()=>{this.consumers=this.consumers.filter((t=>t!==e))}}}class Hu{constructor(e){__publicField(this,"connector"),__publicField(this,"setConnectRequestParametersCallback"),__publicField(this,"consumers",[]),__publicField(this,"tracker"),__publicField(this,"state",yr()),this.connector=e.connector,this.tracker=e.tracker,this.setConnectRequestParametersCallback=e.setConnectRequestParametersCallback,gt((()=>{const e=yr();this.state=e,this.consumers.forEach((t=>t(e)))}))}open(e){return __async(this,null,(function*(){this.tracker.trackConnectionStarted();const t=Wl(yield this.connector.getWallets(),Pl.walletsListConfiguration),n=t.find(Ce);if(!!n)return this.connectEmbeddedWallet(n);const r=t.filter(_e).find((t=>Hl(t,e)));if(!!r)return this.openSingleWalletModal(r);const o=`Trying to open modal window with unknown wallet "${e}".`;throw this.tracker.trackConnectionError(o),new er(o)}))}close(e="action-cancelled"){"action-cancelled"===e&&this.tracker.trackConnectionError("Connection was cancelled"),$u("action-cancelled")}onStateChange(e){return this.consumers.push(e),()=>{this.consumers=this.consumers.filter((t=>t!==e))}}connectEmbeddedWallet(e){const t=t=>{Er(e),this.connector.connect({jsBridgeKey:e.jsBridgeKey},t)},n=Pl.connectRequestParameters;"loading"===(null==n?void 0:n.state)?this.setConnectRequestParametersCallback(t):t(null==n?void 0:n.value)}openSingleWalletModal(e){return __async(this,null,(function*(){return yo()&&bo(),Nu(e),new Promise((e=>{const t=this.onStateChange((n=>{const{status:r}=n;"opened"===r&&(t(),e())}))}))}))}}class Ku{constructor(e){__publicField(this,"eventPrefix","ton-connect-ui-"),__publicField(this,"eventDispatcher"),this.eventDispatcher=null!=e?e:new Be}dispatchUserActionEvent(e){var t;try{const n=`${this.eventPrefix}${e.type}`;null==(t=this.eventDispatcher)||t.dispatchEvent(n,e).catch()}catch(Fu){}}trackConnectionStarted(...e){try{const e={type:"connection-started"};this.dispatchUserActionEvent(e)}catch(Fu){}}trackConnectionCompleted(...e){try{const t=Ae(...e);this.dispatchUserActionEvent(t)}catch(Fu){}}trackConnectionError(...e){try{const t=Me(...e);this.dispatchUserActionEvent(t)}catch(Fu){}}trackConnectionRestoringStarted(...e){try{const e={type:"connection-restoring-started"};this.dispatchUserActionEvent(e)}catch(Fu){}}trackConnectionRestoringCompleted(...e){try{const t=Ne(...e);this.dispatchUserActionEvent(t)}catch(Fu){}}trackConnectionRestoringError(...e){try{const t=$e(...e);this.dispatchUserActionEvent(t)}catch(Fu){}}trackDisconnection(...e){try{const t=je(...e);this.dispatchUserActionEvent(t)}catch(Fu){}}trackTransactionSentForSignature(...e){try{const t=Ie(...e);this.dispatchUserActionEvent(t)}catch(Fu){}}trackTransactionSigned(...e){try{const t=Ue(...e);this.dispatchUserActionEvent(t)}catch(Fu){}}trackTransactionSigningFailed(...e){try{const t=We(...e);this.dispatchUserActionEvent(t)}catch(Fu){}}}e.BadRequestError=B,e.BrowserEventDispatcher=Be,e.FetchWalletsError=F,e.LocalstorageNotFoundError=K,e.ParseHexError=q,e.THEME=Sn,e.TonConnect=He,e.TonConnectError=N,e.TonConnectUI=class{constructor(e){if(__publicField(this,"walletInfoStorage",new fr),__publicField(this,"preferredWalletStorage",new gr),__publicField(this,"tracker"),__publicField(this,"walletInfo",null),__publicField(this,"systemThemeChangeUnsubscribe",null),__publicField(this,"actionsConfiguration"),__publicField(this,"walletsList"),__publicField(this,"connectRequestParametersCallback"),__publicField(this,"connector"),__publicField(this,"modal"),__publicField(this,"singleWalletModal"),__publicField(this,"transactionModal"),__publicField(this,"connectionRestored",Promise.resolve(!1)),e&&"connector"in e&&e.connector)this.connector=e.connector;else{if(!(e&&"manifestUrl"in e&&e.manifestUrl))throw new er("You have to specify a `manifestUrl` or a `connector` in the options.");this.connector=new He({manifestUrl:e.manifestUrl,eventDispatcher:null==e?void 0:e.eventDispatcher})}this.tracker=new Ku(null==e?void 0:e.eventDispatcher),this.modal=new Bu({connector:this.connector,tracker:this.tracker,setConnectRequestParametersCallback:e=>{this.connectRequestParametersCallback=e}}),this.singleWalletModal=new Hu({connector:this.connector,tracker:this.tracker,setConnectRequestParametersCallback:e=>{this.connectRequestParametersCallback=e}}),this.transactionModal=new Du({connector:this.connector}),this.walletsList=this.getWallets(),this.walletsList.then((e=>{return sr((t=e.map((e=>e.imageUrl)),[...new Set(t)]));var t}));const t=this.normalizeWidgetRoot(null==e?void 0:e.widgetRootId);this.subscribeToWalletChange(),!1!==(null==e?void 0:e.restoreConnection)&&(this.tracker.trackConnectionRestoringStarted(),this.connectionRestored=new Promise((e=>__async(this,null,(function*(){yield this.connector.restoreConnection(),this.connector.connected?this.tracker.trackConnectionRestoringCompleted(this.wallet):(this.tracker.trackConnectionRestoringError("Connection was not restored"),this.walletInfoStorage.removeWalletInfo()),e(this.connector.connected)}))))),this.uiOptions=so(e,{uiPreferences:{theme:"SYSTEM"}});const n=this.preferredWalletStorage.getPreferredWalletAppName();Il({connector:this.connector,preferredWalletAppName:n}),ju(t,this)}static getWallets(){return He.getWallets()}get connected(){return this.connector.connected}get account(){return this.connector.account}get wallet(){return this.connector.wallet?__spreadValues(__spreadValues({},this.connector.wallet),this.walletInfo):null}set uiOptions(e){var t,n,r,o,i,s,a;this.checkButtonRootExist(e.buttonRootId),this.actionsConfiguration=e.actionsConfiguration,(null==(t=e.uiPreferences)?void 0:t.theme)?"SYSTEM"!==(null==(n=e.uiPreferences)?void 0:n.theme)?(null==(r=this.systemThemeChangeUnsubscribe)||r.call(this),ho(e.uiPreferences.theme,e.uiPreferences.colorsSet)):(ho(window.matchMedia&&window.matchMedia("(prefers-color-scheme: light)").matches?Sn.LIGHT:Sn.DARK,e.uiPreferences.colorsSet),this.systemThemeChangeUnsubscribe||(this.systemThemeChangeUnsubscribe=function(e){const t=t=>e(t.matches?Sn.DARK:Sn.LIGHT);return window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",t),()=>window.matchMedia("(prefers-color-scheme: dark)").removeEventListener("change",t)}(ho))):(null==(o=e.uiPreferences)?void 0:o.colorsSet)&&(s=e.uiPreferences.colorsSet,uo[Sn.DARK]=so(s[Sn.DARK],uo[Sn.DARK]),uo[Sn.LIGHT]=so(s[Sn.LIGHT],uo[Sn.LIGHT]),lo((e=>({colors:so(uo[e.theme],co[e.theme])})))),(null==(i=e.uiPreferences)?void 0:i.borderRadius)&&(a=e.uiPreferences.borderRadius,lo({borderRadius:a})),Il((t=>{var n,r;const o=so(__spreadValues(__spreadValues(__spreadValues(__spreadValues({},e.language&&{language:e.language}),!!(null==(n=e.actionsConfiguration)?void 0:n.returnStrategy)&&{returnStrategy:e.actionsConfiguration.returnStrategy}),!!(null==(r=e.actionsConfiguration)?void 0:r.twaReturnUrl)&&{twaReturnUrl:e.actionsConfiguration.twaReturnUrl}),!!e.walletsListConfiguration&&{walletsListConfiguration:e.walletsListConfiguration}),Wr(t));return void 0!==e.buttonRootId&&(o.buttonRootId=e.buttonRootId),void 0!==e.enableAndroidBackHandler&&(o.enableAndroidBackHandler=e.enableAndroidBackHandler),o}))}setConnectRequestParameters(e){var t;Il({connectRequestParameters:e}),"ready"!==(null==e?void 0:e.state)&&e||null==(t=this.connectRequestParametersCallback)||t.call(this,null==e?void 0:e.value)}getWallets(){return __async(this,null,(function*(){return this.connector.getWallets()}))}onStatusChange(e,t){return this.connector.onStatusChange((t=>__async(this,null,(function*(){if(t){const n=yield this.getSelectedWalletInfo(t);e(__spreadValues(__spreadValues({},t),n||this.walletInfoStorage.getWalletInfo()))}else e(t)}))),t)}openModal(){return __async(this,null,(function*(){return this.modal.open()}))}closeModal(e){this.modal.close(e)}onModalStateChange(e){return this.modal.onStateChange(e)}get modalState(){return this.modal.state}openSingleWalletModal(e){return __async(this,null,(function*(){return this.singleWalletModal.open(e)}))}closeSingleWalletModal(e){this.singleWalletModal.close(e)}onSingleWalletModalStateChange(e){return this.singleWalletModal.onStateChange(e)}get singleWalletModalState(){return this.singleWalletModal.state}connectWallet(){return __async(this,null,(function*(){const e=(yield this.getWallets()).find(Ce);return e?yield this.connectEmbeddedWallet(e):yield this.connectExternalWallet()}))}disconnect(){return this.tracker.trackDisconnection(this.wallet,"dapp"),Iu(),Wu(),this.walletInfoStorage.removeWalletInfo(),this.connector.disconnect()}sendTransaction(e,t){return __async(this,null,(function*(){if(this.tracker.trackTransactionSentForSignature(this.wallet,e),!this.connected)throw this.tracker.trackTransactionSigningFailed(this.wallet,e,"Wallet was not connected"),new er("Connect wallet to send a transaction.");yo()&&bo();const{notifications:n,modals:r,returnStrategy:o,twaReturnUrl:i,skipRedirectToWallet:s}=this.getModalsAndNotificationsConfiguration(t);Pu({name:"confirm-transaction",showNotification:n.includes("before"),openModal:r.includes("before"),sent:!1});const a=()=>{l.signal.aborted||(Pu({name:"confirm-transaction",showNotification:n.includes("before"),openModal:r.includes("before"),sent:!0}),this.walletInfo&&"universalLink"in this.walletInfo&&("universal-link"===this.walletInfo.openMethod||"custom-deeplink"===this.walletInfo.openMethod)&&(te(this.walletInfo.universalLink)?gc(this.walletInfo.universalLink,{returnStrategy:o,twaReturnUrl:i||Pl.twaReturnUrl,forceRedirect:!1}):pc(this.walletInfo.universalLink,this.walletInfo.deepLink,{returnStrategy:o,forceRedirect:!1},(()=>{}))))},l=new AbortController,c=this.onTransactionModalStateChange((e=>{(null==e?void 0:e.openModal)||(c(),e||l.abort())}));try{const t=yield this.waitForSendTransaction({transaction:e,signal:l.signal},a);return this.tracker.trackTransactionSigned(this.wallet,e,t),Pu({name:"transaction-sent",showNotification:n.includes("success"),openModal:r.includes("success")}),t}catch(Fu){throw Pu({name:"transaction-canceled",showNotification:n.includes("error"),openModal:r.includes("error")}),Fu instanceof N?Fu:(console.error(Fu),new er("Unhandled error:"+Fu))}finally{c()}}))}connectEmbeddedWallet(e){return __async(this,null,(function*(){const t=t=>{Er(e),this.connector.connect({jsBridgeKey:e.jsBridgeKey},t)},n=Pl.connectRequestParameters;return"loading"===(null==n?void 0:n.state)?this.connectRequestParametersCallback=t:t(null==n?void 0:n.value),yield this.waitForWalletConnection({ignoreErrors:!1})}))}connectExternalWallet(){return __async(this,null,(function*(){const e=new AbortController;Mu();const t=this.onModalStateChange((n=>{const{status:r,closeReason:o}=n;"opened"!==r&&(t(),"action-cancelled"===o&&e.abort())}));return yield this.waitForWalletConnection({ignoreErrors:!0,signal:e.signal})}))}waitForWalletConnection(e){return __async(this,null,(function*(){return new Promise(((t,n)=>{this.tracker.trackConnectionStarted();const{ignoreErrors:r=!1,signal:o=null}=e;if(o&&o.aborted)return this.tracker.trackConnectionError("Connection was cancelled"),n(new er("Wallet was not connected"));const i=e=>__async(this,null,(function*(){if(e)this.tracker.trackConnectionCompleted(e),a(),t(e);else{if(this.tracker.trackConnectionError("Connection was cancelled"),r)return;a(),n(new er("Wallet was not connected"))}})),s=e=>{this.tracker.trackConnectionError(e.message),r||(a(),n(e))},a=this.onStatusChange((e=>i(e)),(e=>s(e)));o&&o.addEventListener("abort",(()=>{a(),n(new er("Wallet was not connected"))}),{once:!0})}))}))}waitForSendTransaction(e,t){return __async(this,null,(function*(){return new Promise(((n,r)=>{const{transaction:o,signal:i}=e;if(i.aborted)return this.tracker.trackTransactionSigningFailed(this.wallet,o,"Transaction was cancelled"),r(new er("Transaction was not sent"));const s=e=>__async(this,null,(function*(){n(e)})),a=()=>{this.tracker.trackTransactionSigningFailed(this.wallet,o,"Transaction was cancelled"),r(new er("Transaction was not sent"))};i.addEventListener("abort",a,{once:!0}),this.connector.sendTransaction(o,{onRequestSent:t,signal:i}).then((e=>(i.removeEventListener("abort",a),s(e)))).catch((e=>(i.removeEventListener("abort",a),(e=>{r(e)})(e))))}))}))}onTransactionModalStateChange(e){return this.transactionModal.onStateChange(e)}subscribeToWalletChange(){this.connector.onStatusChange((e=>__async(this,null,(function*(){var t;e?(yield this.updateWalletInfo(e),this.setPreferredWalletAppName((null==(t=this.walletInfo)?void 0:t.appName)||e.device.appName)):this.walletInfoStorage.removeWalletInfo()}))))}setPreferredWalletAppName(e){this.preferredWalletStorage.setPreferredWalletAppName(e),Il({preferredWalletAppName:e})}getSelectedWalletInfo(e){return __async(this,null,(function*(){let t,n=Uu();if(!n)return null;if("name"in n)t=n;else{const r=Wl(yield this.walletsList,Pl.walletsListConfiguration).find((t=>Hl(t,e.device.appName)));if(!r)throw new er(`Cannot find WalletInfo for the '${e.device.appName}' wallet`);t=__spreadValues(__spreadValues({},r),n)}return t}))}updateWalletInfo(e){return __async(this,null,(function*(){const t=yield this.getSelectedWalletInfo(e);if(t)return this.walletInfo=t,void this.walletInfoStorage.setWalletInfo(t);const n=this.walletInfoStorage.getWalletInfo();this.walletInfo=n||((yield this.walletsList).find((t=>Hl(t,e.device.appName)))||null)}))}normalizeWidgetRoot(e){if(!e||!document.getElementById(e)){e="tc-widget-root";const t=document.createElement("div");t.id=e,document.body.appendChild(t)}return e}checkButtonRootExist(e){if(null!=e&&!document.getElementById(e))throw new er(`${e} element not found in the document.`)}getModalsAndNotificationsConfiguration(e){var t,n,r,o,i,s;const a=["before","success","error"];let l=a;(null==(t=this.actionsConfiguration)?void 0:t.notifications)&&"all"!==(null==(n=this.actionsConfiguration)?void 0:n.notifications)&&(l=this.actionsConfiguration.notifications),(null==e?void 0:e.notifications)&&(l="all"===e.notifications?a:e.notifications);let c=["before"];(null==(r=this.actionsConfiguration)?void 0:r.modals)&&(c="all"===this.actionsConfiguration.modals?a:this.actionsConfiguration.modals),(null==e?void 0:e.modals)&&(c="all"===e.modals?a:e.modals);const u=(null==e?void 0:e.returnStrategy)||(null==(o=this.actionsConfiguration)?void 0:o.returnStrategy)||"back",d=(null==e?void 0:e.twaReturnUrl)||(null==(i=this.actionsConfiguration)?void 0:i.twaReturnUrl);let h=(null==e?void 0:e.skipRedirectToWallet)||(null==(s=this.actionsConfiguration)?void 0:s.skipRedirectToWallet)||"ios";return yo()&&(h="never"),{notifications:l,modals:c,returnStrategy:u,twaReturnUrl:d,skipRedirectToWallet:h}}},e.TonConnectUIError=er,e.UnknownAppError=D,e.UnknownError=z,e.UserRejectsError=j,e.WalletAlreadyConnectedError=U,e.WalletNotConnectedError=W,e.WalletNotInjectedError=H,e.WalletsListManager=Se,e.WrongAddressError=V,e.createConnectionCompletedEvent=Ae,e.createConnectionErrorEvent=Me,e.createConnectionRestoringCompletedEvent=Ne,e.createConnectionRestoringErrorEvent=$e,e.createConnectionRestoringStartedEvent=Oe,e.createConnectionStartedEvent=Le,e.createDisconnectionEvent=je,e.createTransactionSentForSignatureEvent=Ie,e.createTransactionSignedEvent=Ue,e.createTransactionSigningFailedEvent=We,e.encodeTelegramUrlParameters=ne,e.isTelegramUrl=te,e.isWalletInfoCurrentlyEmbedded=Ce,e.isWalletInfoCurrentlyInjected=be,e.isWalletInfoInjectable=xe,e.isWalletInfoInjected=function(e){return"jsBridgeKey"in e},e.isWalletInfoRemote=_e,e.toUserFriendlyAddress=Ve,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
1024
1024
  //# sourceMappingURL=tonconnect-ui.min.js.map