@tonconnect/ui 2.0.3-beta.3 → 2.0.3-beta.4
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.
- package/dist/tonconnect-ui.min.js +2 -2
- package/dist/tonconnect-ui.min.js.map +1 -1
- package/lib/index.cjs +3 -2
- package/lib/index.cjs.map +1 -1
- package/lib/index.mjs +3 -2
- package/lib/index.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -997,7 +997,7 @@ var __defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnP
|
|
|
997
997
|
`,Fn(ji)`
|
|
998
998
|
color: ${e=>e.theme.colors.text.secondary};
|
|
999
999
|
font-size: 16px;
|
|
1000
|
-
`;const bu=un("<li></li>"),Cu=e=>{const[t,n]=gt(!1),r=Wl.connector,o=vt((()=>lu(e.walletsList)),null,{equals:cu});Lr({openMethod:"qrcode"});const i=vt((()=>r.connect(o(),e.additionalRequest)));return Ft(pu,{onClick:()=>n(!1),"data-tc-wallets-modal-universal-desktop":"true",get children(){return[Ft(Ji,{translationKey:"walletModal.desktopUniversalModal.connectYourWallet",children:"Connect your wallet"}),Ft(wu,{translationKey:"walletModal.desktopUniversalModal.scan",children:"Scan with your mobile wallet"}),Ft(vu,{get sourceUrl(){return wc(i(),"none")},get disableCopy(){return t()},get imageUrl(){return ta}}),Ft(mu,{translationKey:"walletModal.desktopUniversalModal.availableWallets",children:"Available wallets"}),Ft(yu,{get children(){return[Ft(Qt,{get each(){return e.walletsList.slice(0,3)},children:t=>(()=>{const n=bu.cloneNode(!0);return pn(n,Ft(ra,{wallet:t,onClick:()=>e.onSelect(t)})),n})()}),Ft(Xs,{labelLine1:"View all",labelLine2:"wallets",get images(){return e.walletsList.slice(3,7).map((e=>e.imageUrl))},onClick:()=>e.onSelectAllWallets()})]}})]}})},xu=()=>{const{locale:e}=Ui()[1];mt((()=>e(Wl.language))),mt((()=>{Cr()
|
|
1000
|
+
`;const bu=un("<li></li>"),Cu=e=>{const[t,n]=gt(!1),r=Wl.connector,o=vt((()=>lu(e.walletsList)),null,{equals:cu});Lr({openMethod:"qrcode"});const i=vt((()=>r.connect(o(),e.additionalRequest)));return Ft(pu,{onClick:()=>n(!1),"data-tc-wallets-modal-universal-desktop":"true",get children(){return[Ft(Ji,{translationKey:"walletModal.desktopUniversalModal.connectYourWallet",children:"Connect your wallet"}),Ft(wu,{translationKey:"walletModal.desktopUniversalModal.scan",children:"Scan with your mobile wallet"}),Ft(vu,{get sourceUrl(){return wc(i(),"none")},get disableCopy(){return t()},get imageUrl(){return ta}}),Ft(mu,{translationKey:"walletModal.desktopUniversalModal.availableWallets",children:"Available wallets"}),Ft(yu,{get children(){return[Ft(Qt,{get each(){return e.walletsList.slice(0,3)},children:t=>(()=>{const n=bu.cloneNode(!0);return pn(n,Ft(ra,{wallet:t,onClick:()=>e.onSelect(t)})),n})()}),Ft(Xs,{labelLine1:"View all",labelLine2:"wallets",get images(){return e.walletsList.slice(3,7).map((e=>e.imageUrl))},onClick:()=>e.onSelectAllWallets()})]}})]}})},xu=()=>{const{locale:e}=Ui()[1];mt((()=>e(Wl.language))),mt((()=>{Cr()?ua():(i(null),a("universal"),c(!1))}));const t=St($r),n=St(ga),[r]=yt((()=>n.getWallets())),[o,i]=gt(null),[s,a]=gt("universal"),[l,c]=gt(!1),u=vt((()=>{if("ready"!==r.state)return null;let e=Dl(r(),Wl.walletsListConfiguration);const t=e.filter(be),n=e.filter((e=>!be(e)));e=(t||[]).concat(n);const o=Wl.preferredWalletAppName,i=e.find((e=>Fl(e,o))),s=e.filter((e=>Fl(e,o))).length>=2;o&&i&&!s&&(e=[__spreadProps(__spreadValues({},i),{isPreferred:!0})].concat(e.filter((e=>!Fl(e,o)))));const a=e.find((e=>Fl(e,ea)));return a&&(e=[a].concat(e.filter((e=>!Fl(e,ea))))),e})),d=()=>{var e;return"loading"===(null==(e=Wl.connectRequestParameters)?void 0:e.state)},h=vt((()=>{var e;if(!d())return null==(e=Wl.connectRequestParameters)?void 0:e.value})),f=e=>{n.closeModal(e)},g=t.onStatusChange((e=>{e&&f("wallet-selected")})),p=()=>{a("all-wallets")},w=()=>{a("universal")},m=()=>{i(null)};return xt((()=>{i(null),c(!1)})),xt(g),Ft($l,{get opened(){return Cr()},get enableAndroidBackHandler(){return Wl.enableAndroidBackHandler},onClose:()=>f("action-cancelled"),onClickQuestion:()=>c((e=>!e)),"data-tc-wallets-modal-container":"true",get children(){return[Ft(Jt,{get when(){return l()},get children(){return Ft(Ac,{onBackClick:()=>c(!1)})}}),Ft(Jt,{get when(){return!l()},get children(){return[Ft(Jt,{get when(){return d()||!u()},get children(){return[Ft(Il,{translationKey:"walletModal.loading",children:"Wallets list is loading"}),Ft(Ul,{get children(){return Ft(vs,{size:"m"})}})]}}),Ft(Jt,{get when(){return vt((()=>!d()))()&&u()},get children(){return Ft(Xt,{get children(){return[Ft(en,{get when(){return o()},get children(){return Ft(Rn,{get component(){return la()?qc:bc},get wallet(){return o()},get additionalRequest(){return h()},onBackClick:m})}}),Ft(en,{get when(){return"universal"===s()},get children(){return Ft(Rn,{get component(){return la()?hu:Cu},onSelect:i,get walletsList(){return u()},get additionalRequest(){return h()},onSelectAllWallets:p})}}),Ft(en,{get when(){return"all-wallets"===s()},get children(){return Ft(Jl,{get walletsList(){return u()},onBack:w,onSelect:i})}})]}})}})]}})]}})},_u=Fn.div`
|
|
1001
1001
|
display: flex;
|
|
1002
1002
|
flex-direction: column;
|
|
1003
1003
|
align-items: center;
|
|
@@ -1020,5 +1020,5 @@ var __defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnP
|
|
|
1020
1020
|
width: 16px;
|
|
1021
1021
|
`,Tu=Fn(Uo)`
|
|
1022
1022
|
margin-top: 32px;
|
|
1023
|
-
`,Lu=e=>{const t=Io(e),n=St(ga),[r,o]=gt(!0),[i,s]=gt(!1);let a,l;mt((()=>{const e=Ar();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)&&xo())&&(a=n.wallet.universalLink),(null==n?void 0:n.wallet)&&"deepLink"in n.wallet&&("custom-deeplink"===n.wallet.openMethod||te(n.wallet.deepLink)&&xo())&&(l=n.wallet.deepLink);const c=()=>{const e=Ar(),t="returnStrategy"in e?e.returnStrategy:Wl.returnStrategy,n=!r();o(!1),te(a)?mc(a,{returnStrategy:t,twaReturnUrl:"twaReturnUrl"in e?e.twaReturnUrl:Wl.twaReturnUrl,forceRedirect:n}):vc(a,l,{returnStrategy:t,forceRedirect:n},(()=>{}))};return Ft(_u,Gt(t,{get children(){return[vt((()=>e.icon)),Ft(ku,{get translationKey(){return e.headerTranslationKey},get translationValues(){return e.headerTranslationValues}}),Ft(Su,{get translationKey(){return e.textTranslationKey},get translationValues(){return e.textTranslationValues}}),Ft(Jt,{get when(){return!i()&&("open-wallet"===e.showButton&&a||"open-wallet"!==e.showButton)},get children(){return Ft(Eu,{disabled:!0,"data-tc-connect-button-loading":"true",get children(){return Ft(Ru,{})}})}}),Ft(Jt,{get when(){return i()},get children(){return[Ft(Jt,{get when(){return"open-wallet"!==e.showButton},get children(){return Ft(Tu,{onClick:()=>e.onClose(),get children(){return Ft(pc,{translationKey:"common.close",children:"Close"})}})}}),Ft(Jt,{get when(){return"open-wallet"===e.showButton&&a},get children(){return Ft(Tu,{onClick:c,get children(){return Ft(pc,{translationKey:"common.openWallet",children:"Open wallet"})}})}})]}})]}}))},Au=e=>{const t=St(ga),[n]=Ui();return Ft(Lu,{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 Ft(vs,{size:"m"})},onClose:()=>e.onClose(),showButton:"open-wallet","data-tc-confirm-modal":"true"})},Ou=e=>Ft(Lu,{headerTranslationKey:"actionModal.transactionCanceled.header",textTranslationKey:"actionModal.transactionCanceled.text",get icon(){return Ft(gs,{size:"m"})},onClose:()=>e.onClose(),"data-tc-transaction-canceled-modal":"true"}),Mu=e=>Ft(Lu,{headerTranslationKey:"actionModal.transactionSent.header",textTranslationKey:"actionModal.transactionSent.text",get icon(){return Ft(us,{size:"m"})},onClose:()=>e.onClose(),"data-tc-transaction-sent-modal":"true"}),Nu=()=>Ft(gi,{get opened(){var e;return vt((()=>null!==Ar()))()&&!0===(null==(e=Ar())?void 0:e.openModal)},get enableAndroidBackHandler(){return Wl.enableAndroidBackHandler},onClose:()=>Or(null),"data-tc-actions-modal-container":"true",get children(){return Ft(Xt,{get children(){return[Ft(en,{get when(){return"transaction-sent"===Ar().name},get children(){return Ft(Mu,{onClose:()=>Or(null)})}}),Ft(en,{get when(){return"transaction-canceled"===Ar().name},get children(){return Ft(Ou,{onClose:()=>Or(null)})}}),Ft(en,{get when(){return"confirm-transaction"===Ar().name},get children(){return Ft(Au,{onClose:()=>Or(null)})}})]}})}}),Pu=()=>{const{locale:e}=Ui()[1];mt((()=>e(Wl.language))),mt((()=>{kr()&&ua()}));const t=St($r),n=St(ga),[r,o]=gt(!1),i=()=>{var e;return"loading"===(null==(e=Wl.connectRequestParameters)?void 0:e.state)},s=vt((()=>{var e;if(!i())return null==(e=Wl.connectRequestParameters)?void 0:e.value})),a=e=>{n.closeSingleWalletModal(e)};return xt(t.onStatusChange((e=>{e&&a("wallet-selected")}))),xt((()=>{o(!1)})),Ft($l,{get opened(){return kr()},get enableAndroidBackHandler(){return Wl.enableAndroidBackHandler},onClose:()=>a("action-cancelled"),onClickQuestion:()=>o((e=>!e)),"data-tc-wallets-modal-container":"true",get children(){return[Ft(Jt,{get when(){return r()},get children(){return Ft(Ac,{onBackClick:()=>o(!1)})}}),Ft(Jt,{get when(){return!r()},get children(){return[Ft(Jt,{get when(){return i()},get children(){return[Ft(Il,{translationKey:"walletModal.loading",children:"Wallets list is loading"}),Ft(Ul,{get children(){return Ft(vs,{size:"m"})}})]}}),Ft(Jt,{get when(){return!i()},get children(){return Ft(Rn,{get component(){return la()?qc:bc},get wallet(){return Sr()},get additionalRequest(){return s()},onBackClick:()=>{},backDisabled:!0})}})]}})]}})},$u=e=>{const t=$i(Nr,Wl.language);return customElements.define(zn,class extends HTMLElement{}),document.body.hasAttribute("ontouchstart")||document.body.setAttribute("ontouchstart",""),Ft(Ii.Provider,{value:t,get children(){return Ft(ga.Provider,{get value(){return e.tonConnectUI},get children(){return Ft($r.Provider,{get value(){return Wl.connector},get children(){return[Ft(Yn,{}),Ft(Hn,{theme:uo,get children(){return[Ft(Jt,{get when(){return Wl.buttonRootId},get children(){return Ft(En,{get mount(){return document.getElementById(Wl.buttonRootId)},get children(){return Ft(Pl,{})}})}}),Ft(Rn,{component:zn,get children(){return[Ft(xu,{}),Ft(Pu,{}),Ft(Nu,{})]}})]}})]}})}})}})},Iu=()=>{setTimeout((()=>br({status:"opened",closeReason:null})))},Uu=e=>{setTimeout((()=>br({status:"closed",closeReason:e})))},Wu=e=>{setTimeout((()=>_r({status:"opened",closeReason:null,walletInfo:e})))},ju=e=>{setTimeout((()=>_r({status:"closed",closeReason:e})))},Bu=e=>{setTimeout((()=>Or(e)))},Du=()=>{setTimeout((()=>Or(null)))},Hu=()=>Rr(),Vu=()=>Lr(null),Ku=(e,t)=>function(e,t,n,r={}){let o;return ft((r=>{o=r,t===document?e():pn(t,e(),t.firstChild?null:void 0,n)}),r.owner),()=>{o(),t.textContent=""}}((()=>Ft($u,{tonConnectUI:t})),document.getElementById(e));class Fu{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,mt((()=>{const e=yr();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"),Uu(e)}onStateChange(e){return this.consumers.push(e),()=>{this.consumers=this.consumers.filter((t=>t!==e))}}connectEmbeddedWallet(e){const t=t=>{Lr(e),this.connector.connect({jsBridgeKey:e.jsBridgeKey},t)},n=Wl.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 xo()&&_o(),Iu(),new Promise((e=>{const t=this.onStateChange((n=>{const{status:r}=n;"opened"===r&&(t(),e())}))}))}))}}class qu{constructor(e){__publicField(this,"connector"),__publicField(this,"consumers",[]),this.connector=e.connector,mt((()=>{const e=Ar();this.consumers.forEach((t=>t(e)))}))}onStateChange(e){return this.consumers.push(e),()=>{this.consumers=this.consumers.filter((t=>t!==e))}}}class zu{constructor(e){__publicField(this,"connector"),__publicField(this,"setConnectRequestParametersCallback"),__publicField(this,"consumers",[]),__publicField(this,"tracker"),__publicField(this,"state",xr()),this.connector=e.connector,this.tracker=e.tracker,this.setConnectRequestParametersCallback=e.setConnectRequestParametersCallback,mt((()=>{const e=xr();this.state=e,this.consumers.forEach((t=>t(e)))}))}open(e){return __async(this,null,(function*(){this.tracker.trackConnectionStarted();const t=Dl(yield this.connector.getWallets(),Wl.walletsListConfiguration),n=t.find(Ce);if(!!n)return this.connectEmbeddedWallet(n);const r=t.filter(_e).find((t=>Fl(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 rr(o)}))}close(e="action-cancelled"){"action-cancelled"===e&&this.tracker.trackConnectionError("Connection was cancelled"),ju("action-cancelled")}onStateChange(e){return this.consumers.push(e),()=>{this.consumers=this.consumers.filter((t=>t!==e))}}connectEmbeddedWallet(e){const t=t=>{Lr(e),this.connector.connect({jsBridgeKey:e.jsBridgeKey},t)},n=Wl.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 xo()&&_o(),Wu(e),new Promise((e=>{const t=this.onStateChange((n=>{const{status:r}=n;"opened"===r&&(t(),e())}))}))}))}}class Zu{constructor(e){var t;__publicField(this,"eventPrefix","ton-connect-ui-"),__publicField(this,"tonConnectUiVersion"),__publicField(this,"tonConnectSdkVersion",null),__publicField(this,"eventDispatcher"),this.eventDispatcher=null!=(t=null==e?void 0:e.eventDispatcher)?t:new Ve,this.tonConnectUiVersion=e.tonConnectUiVersion,this.init().catch()}get version(){return Ae({ton_connect_sdk_lib:this.tonConnectSdkVersion,ton_connect_ui_lib:this.tonConnectUiVersion})}init(){return __async(this,null,(function*(){try{yield this.setRequestVersionHandler(),this.tonConnectSdkVersion=yield this.requestTonConnectSdkVersion()}catch(Gu){}}))}setRequestVersionHandler(){return __async(this,null,(function*(){yield this.eventDispatcher.addEventListener("ton-connect-ui-request-version",(()=>__async(this,null,(function*(){yield this.eventDispatcher.dispatchEvent("ton-connect-ui-response-version",Le(this.tonConnectUiVersion))}))))}))}requestTonConnectSdkVersion(){return __async(this,null,(function*(){return new Promise(((e,t)=>__async(this,null,(function*(){try{yield this.eventDispatcher.addEventListener("ton-connect-response-version",(t=>{e(t.detail.version)}),{once:!0}),yield this.eventDispatcher.dispatchEvent("ton-connect-request-version",{type:"request-version"})}catch(Gu){t(Gu)}}))))}))}dispatchUserActionEvent(e){var t;try{null==(t=this.eventDispatcher)||t.dispatchEvent(`${this.eventPrefix}${e.type}`,e).catch()}catch(Gu){}}trackConnectionStarted(...e){try{const t=Me(this.version,...e);this.dispatchUserActionEvent(t)}catch(Gu){}}trackConnectionCompleted(...e){try{const t=Ne(this.version,...e);this.dispatchUserActionEvent(t)}catch(Gu){}}trackConnectionError(...e){try{const t=Pe(this.version,...e);this.dispatchUserActionEvent(t)}catch(Gu){}}trackConnectionRestoringStarted(...e){try{const t=$e(this.version,...e);this.dispatchUserActionEvent(t)}catch(Gu){}}trackConnectionRestoringCompleted(...e){try{const t=Ie(this.version,...e);this.dispatchUserActionEvent(t)}catch(Gu){}}trackConnectionRestoringError(...e){try{const t=Ue(this.version,...e);this.dispatchUserActionEvent(t)}catch(Gu){}}trackDisconnection(...e){try{const t=He(this.version,...e);this.dispatchUserActionEvent(t)}catch(Gu){}}trackTransactionSentForSignature(...e){try{const t=je(this.version,...e);this.dispatchUserActionEvent(t)}catch(Gu){}}trackTransactionSigned(...e){try{const t=Be(this.version,...e);this.dispatchUserActionEvent(t)}catch(Gu){}}trackTransactionSigningFailed(...e){try{const t=De(this.version,...e);this.dispatchUserActionEvent(t)}catch(Gu){}}}e.BadRequestError=B,e.BrowserEventDispatcher=Ve,e.FetchWalletsError=K,e.LocalstorageNotFoundError=V,e.ParseHexError=q,e.THEME=Tn,e.TonConnect=Fe,e.TonConnectError=N,e.TonConnectUI=class{constructor(e){if(__publicField(this,"walletInfoStorage",new wr),__publicField(this,"preferredWalletStorage",new mr),__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 rr("You have to specify a `manifestUrl` or a `connector` in the options.");this.connector=new Fe({manifestUrl:e.manifestUrl,eventDispatcher:null==e?void 0:e.eventDispatcher})}this.tracker=new Zu({eventDispatcher:null==e?void 0:e.eventDispatcher,tonConnectUiVersion:"2.0.3-beta.3"}),this.modal=new Fu({connector:this.connector,tracker:this.tracker,setConnectRequestParametersCallback:e=>{this.connectRequestParametersCallback=e}}),this.singleWalletModal=new zu({connector:this.connector,tracker:this.tracker,setConnectRequestParametersCallback:e=>{this.connectRequestParametersCallback=e}}),this.transactionModal=new qu({connector:this.connector}),this.walletsList=this.getWallets(),this.walletsList.then((e=>{return cr((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.connectionRestored=function(e){return __async(this,null,(function*(){return yield new Promise((e=>requestAnimationFrame(e))),e()}))}((()=>__async(this,null,(function*(){return this.tracker.trackConnectionRestoringStarted(),yield this.connector.restoreConnection(),this.connector.connected?this.tracker.trackConnectionRestoringCompleted(this.wallet):(this.tracker.trackConnectionRestoringError("Connection was not restored"),this.walletInfoStorage.removeWalletInfo()),this.connector.connected}))))),this.uiOptions=co(e,{uiPreferences:{theme:"SYSTEM"}});const n=this.preferredWalletStorage.getPreferredWalletAppName();jl({connector:this.connector,preferredWalletAppName:n}),Ku(t,this)}static getWallets(){return Fe.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),po(e.uiPreferences.theme,e.uiPreferences.colorsSet)):(po(window.matchMedia&&window.matchMedia("(prefers-color-scheme: light)").matches?Tn.LIGHT:Tn.DARK,e.uiPreferences.colorsSet),this.systemThemeChangeUnsubscribe||(this.systemThemeChangeUnsubscribe=function(e){const t=t=>e(t.matches?Tn.DARK:Tn.LIGHT);return window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",t),()=>window.matchMedia("(prefers-color-scheme: dark)").removeEventListener("change",t)}(po))):(null==(o=e.uiPreferences)?void 0:o.colorsSet)&&(s=e.uiPreferences.colorsSet,go[Tn.DARK]=co(s[Tn.DARK],go[Tn.DARK]),go[Tn.LIGHT]=co(s[Tn.LIGHT],go[Tn.LIGHT]),ho((e=>({colors:co(go[e.theme],fo[e.theme])})))),(null==(i=e.uiPreferences)?void 0:i.borderRadius)&&(a=e.uiPreferences.borderRadius,ho({borderRadius:a})),jl((t=>{var n,r;const o=co(__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}),Dr(t));return void 0!==e.buttonRootId&&(o.buttonRootId=e.buttonRootId),void 0!==e.enableAndroidBackHandler&&(o.enableAndroidBackHandler=e.enableAndroidBackHandler),o}))}setConnectRequestParameters(e){var t;jl({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"),Du(),Vu(),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 rr("Connect wallet to send a transaction.");xo()&&_o();const{notifications:n,modals:r,returnStrategy:o,twaReturnUrl:i,skipRedirectToWallet:s}=this.getModalsAndNotificationsConfiguration(t);Bu({name:"confirm-transaction",showNotification:n.includes("before"),openModal:r.includes("before"),sent:!1});const a=()=>{l.signal.aborted||(Bu({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)?mc(this.walletInfo.universalLink,{returnStrategy:o,twaReturnUrl:i||Wl.twaReturnUrl,forceRedirect:!1}):vc(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),Bu({name:"transaction-sent",showNotification:n.includes("success"),openModal:r.includes("success")}),t}catch(Gu){throw Bu({name:"transaction-canceled",showNotification:n.includes("error"),openModal:r.includes("error")}),Gu instanceof N?Gu:(console.error(Gu),new rr("Unhandled error:"+Gu))}finally{c()}}))}connectEmbeddedWallet(e){return __async(this,null,(function*(){const t=t=>{Lr(e),this.connector.connect({jsBridgeKey:e.jsBridgeKey},t)},n=Wl.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;Iu();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 rr("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 rr("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 rr("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 rr("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 rr("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),jl({preferredWalletAppName:e})}getSelectedWalletInfo(e){return __async(this,null,(function*(){let t,n=Hu();if(!n)return null;if("name"in n)t=n;else{const r=Dl(yield this.walletsList,Wl.walletsListConfiguration).find((t=>Fl(t,e.device.appName)));if(!r)throw new rr(`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=>Fl(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 rr(`${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 xo()&&(h="never"),{notifications:l,modals:c,returnStrategy:u,twaReturnUrl:d,skipRedirectToWallet:h}}},e.TonConnectUIError=rr,e.UnknownAppError=D,e.UnknownError=z,e.UserRejectsError=j,e.WalletAlreadyConnectedError=U,e.WalletNotConnectedError=W,e.WalletNotInjectedError=H,e.WalletsListManager=Se,e.WrongAddressError=F,e.createConnectionCompletedEvent=Ne,e.createConnectionErrorEvent=Pe,e.createConnectionRestoringCompletedEvent=Ie,e.createConnectionRestoringErrorEvent=Ue,e.createConnectionRestoringStartedEvent=$e,e.createConnectionStartedEvent=Me,e.createDisconnectionEvent=He,e.createRequestVersionEvent=Te,e.createResponseVersionEvent=Le,e.createTransactionSentForSignatureEvent=je,e.createTransactionSignedEvent=Be,e.createTransactionSigningFailedEvent=De,e.createVersionInfo=Ae,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=Ze,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
|
|
1023
|
+
`,Lu=e=>{const t=Io(e),n=St(ga),[r,o]=gt(!0),[i,s]=gt(!1);let a,l;mt((()=>{const e=Ar();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)&&xo())&&(a=n.wallet.universalLink),(null==n?void 0:n.wallet)&&"deepLink"in n.wallet&&("custom-deeplink"===n.wallet.openMethod||te(n.wallet.deepLink)&&xo())&&(l=n.wallet.deepLink);const c=()=>{const e=Ar(),t="returnStrategy"in e?e.returnStrategy:Wl.returnStrategy,n=!r();o(!1),te(a)?mc(a,{returnStrategy:t,twaReturnUrl:"twaReturnUrl"in e?e.twaReturnUrl:Wl.twaReturnUrl,forceRedirect:n}):vc(a,l,{returnStrategy:t,forceRedirect:n},(()=>{}))};return Ft(_u,Gt(t,{get children(){return[vt((()=>e.icon)),Ft(ku,{get translationKey(){return e.headerTranslationKey},get translationValues(){return e.headerTranslationValues}}),Ft(Su,{get translationKey(){return e.textTranslationKey},get translationValues(){return e.textTranslationValues}}),Ft(Jt,{get when(){return!i()&&("open-wallet"===e.showButton&&a||"open-wallet"!==e.showButton)},get children(){return Ft(Eu,{disabled:!0,"data-tc-connect-button-loading":"true",get children(){return Ft(Ru,{})}})}}),Ft(Jt,{get when(){return i()},get children(){return[Ft(Jt,{get when(){return"open-wallet"!==e.showButton},get children(){return Ft(Tu,{onClick:()=>e.onClose(),get children(){return Ft(pc,{translationKey:"common.close",children:"Close"})}})}}),Ft(Jt,{get when(){return"open-wallet"===e.showButton&&a},get children(){return Ft(Tu,{onClick:c,get children(){return Ft(pc,{translationKey:"common.openWallet",children:"Open wallet"})}})}})]}})]}}))},Au=e=>{const t=St(ga),[n]=Ui();return Ft(Lu,{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 Ft(vs,{size:"m"})},onClose:()=>e.onClose(),showButton:"open-wallet","data-tc-confirm-modal":"true"})},Ou=e=>Ft(Lu,{headerTranslationKey:"actionModal.transactionCanceled.header",textTranslationKey:"actionModal.transactionCanceled.text",get icon(){return Ft(gs,{size:"m"})},onClose:()=>e.onClose(),"data-tc-transaction-canceled-modal":"true"}),Mu=e=>Ft(Lu,{headerTranslationKey:"actionModal.transactionSent.header",textTranslationKey:"actionModal.transactionSent.text",get icon(){return Ft(us,{size:"m"})},onClose:()=>e.onClose(),"data-tc-transaction-sent-modal":"true"}),Nu=()=>Ft(gi,{get opened(){var e;return vt((()=>null!==Ar()))()&&!0===(null==(e=Ar())?void 0:e.openModal)},get enableAndroidBackHandler(){return Wl.enableAndroidBackHandler},onClose:()=>Or(null),"data-tc-actions-modal-container":"true",get children(){return Ft(Xt,{get children(){return[Ft(en,{get when(){return"transaction-sent"===Ar().name},get children(){return Ft(Mu,{onClose:()=>Or(null)})}}),Ft(en,{get when(){return"transaction-canceled"===Ar().name},get children(){return Ft(Ou,{onClose:()=>Or(null)})}}),Ft(en,{get when(){return"confirm-transaction"===Ar().name},get children(){return Ft(Au,{onClose:()=>Or(null)})}})]}})}}),Pu=()=>{const{locale:e}=Ui()[1];mt((()=>e(Wl.language))),mt((()=>{kr()&&ua()}));const t=St($r),n=St(ga),[r,o]=gt(!1),i=()=>{var e;return"loading"===(null==(e=Wl.connectRequestParameters)?void 0:e.state)},s=vt((()=>{var e;if(!i())return null==(e=Wl.connectRequestParameters)?void 0:e.value})),a=e=>{n.closeSingleWalletModal(e)};return xt(t.onStatusChange((e=>{e&&a("wallet-selected")}))),xt((()=>{o(!1)})),Ft($l,{get opened(){return kr()},get enableAndroidBackHandler(){return Wl.enableAndroidBackHandler},onClose:()=>a("action-cancelled"),onClickQuestion:()=>o((e=>!e)),"data-tc-wallets-modal-container":"true",get children(){return[Ft(Jt,{get when(){return r()},get children(){return Ft(Ac,{onBackClick:()=>o(!1)})}}),Ft(Jt,{get when(){return!r()},get children(){return[Ft(Jt,{get when(){return i()},get children(){return[Ft(Il,{translationKey:"walletModal.loading",children:"Wallets list is loading"}),Ft(Ul,{get children(){return Ft(vs,{size:"m"})}})]}}),Ft(Jt,{get when(){return!i()},get children(){return Ft(Rn,{get component(){return la()?qc:bc},get wallet(){return Sr()},get additionalRequest(){return s()},onBackClick:()=>{},backDisabled:!0})}})]}})]}})},$u=e=>{const t=$i(Nr,Wl.language);return customElements.define(zn,class extends HTMLElement{}),document.body.hasAttribute("ontouchstart")||document.body.setAttribute("ontouchstart",""),Ft(Ii.Provider,{value:t,get children(){return Ft(ga.Provider,{get value(){return e.tonConnectUI},get children(){return Ft($r.Provider,{get value(){return Wl.connector},get children(){return[Ft(Yn,{}),Ft(Hn,{theme:uo,get children(){return[Ft(Jt,{get when(){return Wl.buttonRootId},get children(){return Ft(En,{get mount(){return document.getElementById(Wl.buttonRootId)},get children(){return Ft(Pl,{})}})}}),Ft(Rn,{component:zn,get children(){return[Ft(xu,{}),Ft(Pu,{}),Ft(Nu,{})]}})]}})]}})}})}})},Iu=()=>{setTimeout((()=>br({status:"opened",closeReason:null})))},Uu=e=>{setTimeout((()=>br({status:"closed",closeReason:e})))},Wu=e=>{setTimeout((()=>_r({status:"opened",closeReason:null,walletInfo:e})))},ju=e=>{setTimeout((()=>_r({status:"closed",closeReason:e})))},Bu=e=>{setTimeout((()=>Or(e)))},Du=()=>{setTimeout((()=>Or(null)))},Hu=()=>Rr(),Vu=()=>Lr(null),Ku=(e,t)=>function(e,t,n,r={}){let o;return ft((r=>{o=r,t===document?e():pn(t,e(),t.firstChild?null:void 0,n)}),r.owner),()=>{o(),t.textContent=""}}((()=>Ft($u,{tonConnectUI:t})),document.getElementById(e));class Fu{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,mt((()=>{const e=yr();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"),Uu(e)}onStateChange(e){return this.consumers.push(e),()=>{this.consumers=this.consumers.filter((t=>t!==e))}}connectEmbeddedWallet(e){const t=t=>{Lr(e),this.connector.connect({jsBridgeKey:e.jsBridgeKey},t)},n=Wl.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 xo()&&_o(),Iu(),new Promise((e=>{const t=this.onStateChange((n=>{const{status:r}=n;"opened"===r&&(t(),e())}))}))}))}}class qu{constructor(e){__publicField(this,"connector"),__publicField(this,"consumers",[]),this.connector=e.connector,mt((()=>{const e=Ar();this.consumers.forEach((t=>t(e)))}))}onStateChange(e){return this.consumers.push(e),()=>{this.consumers=this.consumers.filter((t=>t!==e))}}}class zu{constructor(e){__publicField(this,"connector"),__publicField(this,"setConnectRequestParametersCallback"),__publicField(this,"consumers",[]),__publicField(this,"tracker"),__publicField(this,"state",xr()),this.connector=e.connector,this.tracker=e.tracker,this.setConnectRequestParametersCallback=e.setConnectRequestParametersCallback,mt((()=>{const e=xr();this.state=e,this.consumers.forEach((t=>t(e)))}))}open(e){return __async(this,null,(function*(){this.tracker.trackConnectionStarted();const t=Dl(yield this.connector.getWallets(),Wl.walletsListConfiguration),n=t.find(Ce);if(!!n)return this.connectEmbeddedWallet(n);const r=t.filter(_e).find((t=>Fl(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 rr(o)}))}close(e="action-cancelled"){"action-cancelled"===e&&this.tracker.trackConnectionError("Connection was cancelled"),ju("action-cancelled")}onStateChange(e){return this.consumers.push(e),()=>{this.consumers=this.consumers.filter((t=>t!==e))}}connectEmbeddedWallet(e){const t=t=>{Lr(e),this.connector.connect({jsBridgeKey:e.jsBridgeKey},t)},n=Wl.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 xo()&&_o(),Wu(e),new Promise((e=>{const t=this.onStateChange((n=>{const{status:r}=n;"opened"===r&&(t(),e())}))}))}))}}class Zu{constructor(e){var t;__publicField(this,"eventPrefix","ton-connect-ui-"),__publicField(this,"tonConnectUiVersion"),__publicField(this,"tonConnectSdkVersion",null),__publicField(this,"eventDispatcher"),this.eventDispatcher=null!=(t=null==e?void 0:e.eventDispatcher)?t:new Ve,this.tonConnectUiVersion=e.tonConnectUiVersion,this.init().catch()}get version(){return Ae({ton_connect_sdk_lib:this.tonConnectSdkVersion,ton_connect_ui_lib:this.tonConnectUiVersion})}init(){return __async(this,null,(function*(){try{yield this.setRequestVersionHandler(),this.tonConnectSdkVersion=yield this.requestTonConnectSdkVersion()}catch(Gu){}}))}setRequestVersionHandler(){return __async(this,null,(function*(){yield this.eventDispatcher.addEventListener("ton-connect-ui-request-version",(()=>__async(this,null,(function*(){yield this.eventDispatcher.dispatchEvent("ton-connect-ui-response-version",Le(this.tonConnectUiVersion))}))))}))}requestTonConnectSdkVersion(){return __async(this,null,(function*(){return new Promise(((e,t)=>__async(this,null,(function*(){try{yield this.eventDispatcher.addEventListener("ton-connect-response-version",(t=>{e(t.detail.version)}),{once:!0}),yield this.eventDispatcher.dispatchEvent("ton-connect-request-version",{type:"request-version"})}catch(Gu){t(Gu)}}))))}))}dispatchUserActionEvent(e){var t;try{null==(t=this.eventDispatcher)||t.dispatchEvent(`${this.eventPrefix}${e.type}`,e).catch()}catch(Gu){}}trackConnectionStarted(...e){try{const t=Me(this.version,...e);this.dispatchUserActionEvent(t)}catch(Gu){}}trackConnectionCompleted(...e){try{const t=Ne(this.version,...e);this.dispatchUserActionEvent(t)}catch(Gu){}}trackConnectionError(...e){try{const t=Pe(this.version,...e);this.dispatchUserActionEvent(t)}catch(Gu){}}trackConnectionRestoringStarted(...e){try{const t=$e(this.version,...e);this.dispatchUserActionEvent(t)}catch(Gu){}}trackConnectionRestoringCompleted(...e){try{const t=Ie(this.version,...e);this.dispatchUserActionEvent(t)}catch(Gu){}}trackConnectionRestoringError(...e){try{const t=Ue(this.version,...e);this.dispatchUserActionEvent(t)}catch(Gu){}}trackDisconnection(...e){try{const t=He(this.version,...e);this.dispatchUserActionEvent(t)}catch(Gu){}}trackTransactionSentForSignature(...e){try{const t=je(this.version,...e);this.dispatchUserActionEvent(t)}catch(Gu){}}trackTransactionSigned(...e){try{const t=Be(this.version,...e);this.dispatchUserActionEvent(t)}catch(Gu){}}trackTransactionSigningFailed(...e){try{const t=De(this.version,...e);this.dispatchUserActionEvent(t)}catch(Gu){}}}e.BadRequestError=B,e.BrowserEventDispatcher=Ve,e.FetchWalletsError=K,e.LocalstorageNotFoundError=V,e.ParseHexError=q,e.THEME=Tn,e.TonConnect=Fe,e.TonConnectError=N,e.TonConnectUI=class{constructor(e){if(__publicField(this,"walletInfoStorage",new wr),__publicField(this,"preferredWalletStorage",new mr),__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 rr("You have to specify a `manifestUrl` or a `connector` in the options.");this.connector=new Fe({manifestUrl:e.manifestUrl,eventDispatcher:null==e?void 0:e.eventDispatcher})}this.tracker=new Zu({eventDispatcher:null==e?void 0:e.eventDispatcher,tonConnectUiVersion:"2.0.3-beta.4"}),this.modal=new Fu({connector:this.connector,tracker:this.tracker,setConnectRequestParametersCallback:e=>{this.connectRequestParametersCallback=e}}),this.singleWalletModal=new zu({connector:this.connector,tracker:this.tracker,setConnectRequestParametersCallback:e=>{this.connectRequestParametersCallback=e}}),this.transactionModal=new qu({connector:this.connector}),this.walletsList=this.getWallets(),this.walletsList.then((e=>{return cr((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.connectionRestored=function(e){return __async(this,null,(function*(){return yield new Promise((e=>requestAnimationFrame(e))),e()}))}((()=>__async(this,null,(function*(){return this.tracker.trackConnectionRestoringStarted(),yield this.connector.restoreConnection(),this.connector.connected?this.tracker.trackConnectionRestoringCompleted(this.wallet):(this.tracker.trackConnectionRestoringError("Connection was not restored"),this.walletInfoStorage.removeWalletInfo()),this.connector.connected}))))),this.uiOptions=co(e,{uiPreferences:{theme:"SYSTEM"}});const n=this.preferredWalletStorage.getPreferredWalletAppName();jl({connector:this.connector,preferredWalletAppName:n}),Ku(t,this)}static getWallets(){return Fe.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),po(e.uiPreferences.theme,e.uiPreferences.colorsSet)):(po(window.matchMedia&&window.matchMedia("(prefers-color-scheme: light)").matches?Tn.LIGHT:Tn.DARK,e.uiPreferences.colorsSet),this.systemThemeChangeUnsubscribe||(this.systemThemeChangeUnsubscribe=function(e){const t=t=>e(t.matches?Tn.DARK:Tn.LIGHT);return window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",t),()=>window.matchMedia("(prefers-color-scheme: dark)").removeEventListener("change",t)}(po))):(null==(o=e.uiPreferences)?void 0:o.colorsSet)&&(s=e.uiPreferences.colorsSet,go[Tn.DARK]=co(s[Tn.DARK],go[Tn.DARK]),go[Tn.LIGHT]=co(s[Tn.LIGHT],go[Tn.LIGHT]),ho((e=>({colors:co(go[e.theme],fo[e.theme])})))),(null==(i=e.uiPreferences)?void 0:i.borderRadius)&&(a=e.uiPreferences.borderRadius,ho({borderRadius:a})),jl((t=>{var n,r;const o=co(__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}),Dr(t));return void 0!==e.buttonRootId&&(o.buttonRootId=e.buttonRootId),void 0!==e.enableAndroidBackHandler&&(o.enableAndroidBackHandler=e.enableAndroidBackHandler),o}))}setConnectRequestParameters(e){var t;jl({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"),Du(),Vu(),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 rr("Connect wallet to send a transaction.");xo()&&_o();const{notifications:n,modals:r,returnStrategy:o,twaReturnUrl:i,skipRedirectToWallet:s}=this.getModalsAndNotificationsConfiguration(t);Bu({name:"confirm-transaction",showNotification:n.includes("before"),openModal:r.includes("before"),sent:!1});const a=()=>{l.signal.aborted||(Bu({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)?mc(this.walletInfo.universalLink,{returnStrategy:o,twaReturnUrl:i||Wl.twaReturnUrl,forceRedirect:!1}):vc(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),Bu({name:"transaction-sent",showNotification:n.includes("success"),openModal:r.includes("success")}),t}catch(Gu){throw Bu({name:"transaction-canceled",showNotification:n.includes("error"),openModal:r.includes("error")}),Gu instanceof N?Gu:(console.error(Gu),new rr("Unhandled error:"+Gu))}finally{c()}}))}connectEmbeddedWallet(e){return __async(this,null,(function*(){const t=t=>{Lr(e),this.connector.connect({jsBridgeKey:e.jsBridgeKey},t)},n=Wl.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;Iu();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 rr("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 rr("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 rr("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 rr("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 rr("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),jl({preferredWalletAppName:e})}getSelectedWalletInfo(e){return __async(this,null,(function*(){let t,n=Hu();if(!n)return null;if("name"in n)t=n;else{const r=Dl(yield this.walletsList,Wl.walletsListConfiguration).find((t=>Fl(t,e.device.appName)));if(!r)throw new rr(`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=>Fl(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 rr(`${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 xo()&&(h="never"),{notifications:l,modals:c,returnStrategy:u,twaReturnUrl:d,skipRedirectToWallet:h}}},e.TonConnectUIError=rr,e.UnknownAppError=D,e.UnknownError=z,e.UserRejectsError=j,e.WalletAlreadyConnectedError=U,e.WalletNotConnectedError=W,e.WalletNotInjectedError=H,e.WalletsListManager=Se,e.WrongAddressError=F,e.createConnectionCompletedEvent=Ne,e.createConnectionErrorEvent=Pe,e.createConnectionRestoringCompletedEvent=Ie,e.createConnectionRestoringErrorEvent=Ue,e.createConnectionRestoringStartedEvent=$e,e.createConnectionStartedEvent=Me,e.createDisconnectionEvent=He,e.createRequestVersionEvent=Te,e.createResponseVersionEvent=Le,e.createTransactionSentForSignatureEvent=je,e.createTransactionSignedEvent=Be,e.createTransactionSigningFailedEvent=De,e.createVersionInfo=Ae,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=Ze,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
|
|
1024
1024
|
//# sourceMappingURL=tonconnect-ui.min.js.map
|