@ic-pay/icpay-widget 1.1.51 → 1.1.52
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/chunk-DYAAEJP3.js +2 -0
- package/dist/chunk-DYAAEJP3.js.map +1 -0
- package/dist/{chunk-VSRSHD52.js → chunk-ROE27JNI.js} +8 -8
- package/dist/chunk-ROE27JNI.js.map +1 -0
- package/dist/index.d.ts +59 -1
- package/dist/index.js +1 -1
- package/dist/react/index.js +1 -1
- package/dist/wallet-select-F6BSMPEE.js +2 -0
- package/dist/wallet-select-F6BSMPEE.js.map +1 -0
- package/package.json +1 -1
- package/dist/chunk-VSRSHD52.js.map +0 -1
- package/dist/wallet-select-5SAMV2XC.js +0 -2
- package/dist/wallet-select-5SAMV2XC.js.map +0 -1
|
@@ -974,7 +974,7 @@ import{a as n}from"./chunk-LTEQ7OUJ.js";import{css as _e}from"lit";var K=_e`
|
|
|
974
974
|
${null}
|
|
975
975
|
</div>
|
|
976
976
|
</div>
|
|
977
|
-
`}function W(r){try{let d=r||{};d.adapters=d.adapters||{};let e=d.adapters.oisy||{},t=e.config||{},i={...t.transport||{},windowOpenerFeatures:"",detectNonClickEstablishment:!1};return d.adapters.oisy={...e,config:{...t,transport:i}},d}catch{return r}}function k(r,d){try{let e=d&&(d.owner||d.principal)||null,t=r&&r.account&&(r.account.owner||r.account.principal)||null,i=o=>typeof o=="string"?o:o&&typeof o.toString=="function"?o.toString():null,s=i(e)||i(t)||null;return s?{owner:s,principal:s}:d||{owner:null}}catch{return d||{owner:null}}}async function Q(r){try{let d=typeof r?.getEnabledWallets=="function"?r.getEnabledWallets.bind(r):null;if(!d)return null;let t=(d()||[]).find(l=>(l?.id||"").toLowerCase()==="oisy");if(!t||!t.adapter)return null;let i=t.adapter,s=new i({config:r?.config||{}});if(!await s.isConnected())return null;let a=await s.getPrincipal();return a&&a!=="2vxsx-fae"?a:null}catch{return null}}var Ce=typeof window<"u",he=null;function J(r,d,e){r&&(e!==void 0?console.log(`[ICPay Widget] ${d}`,e):console.log(`[ICPay Widget] ${d}`))}var S=class extends et{constructor(){super(...arguments);this.selectedSymbol=null;this.unlocked=!1;this.succeeded=!1;this.processing=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.showOnrampModal=!1;this.onrampSessionId=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.transakMessageHandlerBound=null;this.onrampPollTimer=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="pay",this.showWalletModal=!0,this.requestUpdate();try{let t=Number(this.config?.priceUsd||0),i=this.selectedSymbol||this.config?.defaultSymbol;window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"pay",type:"sendUsd",amount:t,currency:i}}))}catch{}}catch{}}}async tryAutoConnectPNP(){try{if(!this.config||this.config?.useOwnWallet)return;let e=localStorage.getItem("icpay:pnp");if(!e)return;let t=JSON.parse(e);if(!t?.provider||!t?.principal)return;he||(he=(await import("./wallet-select-5SAMV2XC.js")).PNP);let i={...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:o}=await import("./origin-44ZEXSX4.js");i.derivationOrigin=this.config?.derivationOrigin||o()}}catch{}let s=new he(i);this.walletConnected=!1,this.config={...this.config,connectedWallet:{owner:t.principal,principal:t.principal,connected:!1}}}catch{}}get cryptoOptions(){return this.config.cryptoOptions?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){if(super.connectedCallback(),!!Ce){J(this.config?.debug||!1,"Premium content connected",{config:this.config}),this.tryAutoConnectPNP();try{window.addEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers()}}updated(e){if(e.has("config")&&this.pendingAction&&this.config?.actorProvider){let t=this.pendingAction;this.pendingAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}setTimeout(()=>{t==="pay"&&this.onPay()},0)}}async loadVerifiedLedgers(){if(!(!Ce||!this.config?.publishableKey))try{let t=await g(this.config).client.getVerifiedLedgers();this.availableLedgers=t.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||this.availableLedgers[0]?.symbol||"ICP")}catch(e){console.warn("Failed to load verified ledgers:",e),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||"ICP")}}async onPay(){if(Ce&&!(this.processing||this.unlocked)){J(this.config?.debug||!1,"Premium content payment started",{priceUsd:this.config.priceUsd,selectedSymbol:this.selectedSymbol,useOwnWallet:this.config.useOwnWallet}),this.errorMessage=null,this.errorSeverity=null,this.errorAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"pay",type:"sendUsd",amount:this.config.priceUsd,currency:this.selectedSymbol||this.config?.defaultSymbol}}))}catch{}this.processing=!0;try{if(this.config.useOwnWallet){if(!this.config.actorProvider){this.pendingAction="pay",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0}));return}}else if(!this.walletConnected){J(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{he||(he=(await import("./wallet-select-5SAMV2XC.js")).PNP);let l=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab)?W({...this.config?.plugNPlay||{}}):{...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:c}=await import("./origin-44ZEXSX4.js");l.derivationOrigin=this.config?.derivationOrigin||c()}}catch{}this.pnp=new he(l);try{let c=await Q(this.pnp);if(c){this.walletConnected=!0;let h=k(this.pnp,{owner:c,principal:c,connected:!0});this.config={...this.config,connectedWallet:h,actorProvider:($,A)=>this.pnp.getActor({canisterId:$,idl:A,requiresSigning:!0,anon:!1})};try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"oisy"}}))}catch{}this.onPay();return}}catch{}let p=this.pnp.getEnabledWallets();if(J(this.config?.debug||!1,"Available wallets",p),!p?.length)throw new Error("No wallets available");this.pendingAction="pay",this.showWalletModal=!0;return}catch(a){J(this.config?.debug||!1,"Wallet connection error:",a),this.errorMessage=a instanceof Error?a.message:"Wallet connection failed",this.errorSeverity="error";return}}J(this.config?.debug||!1,"Creating SDK for payment");let e=g(this.config),t=this.selectedSymbol||this.config?.defaultSymbol||"ICP",s=this.cryptoOptions.find(a=>a.symbol===t).canisterId||await e.client.getLedgerCanisterIdBySymbol(t);J(this.config?.debug||!1,"Payment details",{priceUsd:this.config.priceUsd,selectedSymbol:t,canisterId:s});let o=await e.sendUsd(this.config.priceUsd,s,{context:"premium-content"});J(this.config?.debug||!1,"Payment completed",{resp:o}),this.unlocked=!0,this.succeeded=!0,this.config.onSuccess&&this.config.onSuccess({id:o.transactionId,status:o.status}),this.dispatchEvent(new CustomEvent("icpay-unlock",{detail:{amount:this.config.priceUsd,tx:o},bubbles:!0}))}catch(e){U(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),B(t)&&(this.errorMessage=R(t),this.errorSeverity=z(t),this.errorAction=D(t))}});try{!this.config.useOwnWallet&&this.pnp&&(await this.pnp.disconnect?.(),this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0})}catch{}}finally{this.processing=!1}}}attachTransakMessageListener(){if(!this.transakMessageHandlerBound){this.transakMessageHandlerBound=e=>this.onTransakMessage(e);try{window.addEventListener("message",this.transakMessageHandlerBound)}catch{}}}detachTransakMessageListener(){if(this.transakMessageHandlerBound){try{window.removeEventListener("message",this.transakMessageHandlerBound)}catch{}this.transakMessageHandlerBound=null}}onTransakMessage(e){let t=e?.data,i=t?.event_id||t?.eventId||t?.id;if(!(!i||typeof i!="string")&&i==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let s=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(s||void 0)}}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1,setTimeout(()=>this.createOnrampIntent(),0)}async createOnrampIntent(){try{let e=g(this.config),t=this.selectedSymbol||this.config?.defaultSymbol||"ICP",s=this.cryptoOptions.find(c=>c.symbol===t).canisterId||await e.client.getLedgerCanisterIdBySymbol(t),o=await e.startOnrampUsd(this.config.priceUsd,s,{context:"premium:onramp"}),a=o?.metadata?.onramp?.sessionId||o?.metadata?.onramp?.session_id||null,l=o?.metadata?.paymentIntentId||o?.paymentIntentId||null,p=o?.metadata?.onramp?.errorMessage||null;this.onrampPaymentIntentId=l,a?(this.onrampSessionId=a,this.onrampErrorMessage=null,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.onrampErrorMessage=p||"Failed to obtain onramp sessionId",this.showOnrampModal=!0)}catch(e){this.onrampSessionId=null,this.onrampErrorMessage=e?.message||"Failed to obtain onramp sessionId",this.showOnrampModal=!0}}startOnrampPolling(e){if(this.onrampPollTimer){try{clearInterval(this.onrampPollTimer)}catch{}this.onrampPollTimer=null}if(this.onrampNotifyController){try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null}let t=this.onrampPaymentIntentId;if(!t)return;let i=g(this.config),s=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>s()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=i.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}select(e){this.selectedSymbol=e}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");this.lastWalletId=(e||"").toLowerCase(),this.pnp.connect(e).then(i=>{if(!!!(i&&(i.connected===!0||i.principal||i.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}let o=k(this.pnp,i);if(this.config={...this.config,connectedWallet:o,actorProvider:(l,p)=>this.pnp.getActor({canisterId:l,idl:p,requiresSigning:!0,anon:!1})},this.lastWalletId==="oisy")this.oisyReadyToPay=!0;else{this.showWalletModal=!1;let l=this.pendingAction;this.pendingAction=null,l==="pay"&&setTimeout(()=>this.onPay(),0)}}).catch(i=>{this.errorMessage=i instanceof Error?i.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1})}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}render(){return this.config?pe`
|
|
977
|
+
`}function W(r){try{let d=r||{};d.adapters=d.adapters||{};let e=d.adapters.oisy||{},t=e.config||{},i={...t.transport||{},windowOpenerFeatures:"",detectNonClickEstablishment:!1};return d.adapters.oisy={...e,config:{...t,transport:i}},d}catch{return r}}function k(r,d){try{let e=d&&(d.owner||d.principal)||null,t=r&&r.account&&(r.account.owner||r.account.principal)||null,i=o=>typeof o=="string"?o:o&&typeof o.toString=="function"?o.toString():null,s=i(e)||i(t)||null;return s?{owner:s,principal:s}:d||{owner:null}}catch{return d||{owner:null}}}async function Q(r){try{let d=typeof r?.getEnabledWallets=="function"?r.getEnabledWallets.bind(r):null;if(!d)return null;let t=(d()||[]).find(l=>(l?.id||"").toLowerCase()==="oisy");if(!t||!t.adapter)return null;let i=t.adapter,s=new i({config:r?.config||{}});if(!await s.isConnected())return null;let a=await s.getPrincipal();return a&&a!=="2vxsx-fae"?a:null}catch{return null}}var Ce=typeof window<"u",he=null;function J(r,d,e){r&&(e!==void 0?console.log(`[ICPay Widget] ${d}`,e):console.log(`[ICPay Widget] ${d}`))}var S=class extends et{constructor(){super(...arguments);this.selectedSymbol=null;this.unlocked=!1;this.succeeded=!1;this.processing=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.showOnrampModal=!1;this.onrampSessionId=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.transakMessageHandlerBound=null;this.onrampPollTimer=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="pay",this.showWalletModal=!0,this.requestUpdate();try{let t=Number(this.config?.priceUsd||0),i=this.selectedSymbol||this.config?.defaultSymbol;window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"pay",type:"sendUsd",amount:t,currency:i}}))}catch{}}catch{}}}async tryAutoConnectPNP(){try{if(!this.config||this.config?.useOwnWallet)return;let e=localStorage.getItem("icpay:pnp");if(!e)return;let t=JSON.parse(e);if(!t?.provider||!t?.principal)return;he||(he=(await import("./wallet-select-F6BSMPEE.js")).WalletSelect);let i={...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:o}=await import("./origin-44ZEXSX4.js");i.derivationOrigin=this.config?.derivationOrigin||o()}}catch{}let s=new he(i);this.walletConnected=!1,this.config={...this.config,connectedWallet:{owner:t.principal,principal:t.principal,connected:!1}}}catch{}}get cryptoOptions(){return this.config.cryptoOptions?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){if(super.connectedCallback(),!!Ce){J(this.config?.debug||!1,"Premium content connected",{config:this.config}),this.tryAutoConnectPNP();try{window.addEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers()}}updated(e){if(e.has("config")&&this.pendingAction&&this.config?.actorProvider){let t=this.pendingAction;this.pendingAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}setTimeout(()=>{t==="pay"&&this.onPay()},0)}}async loadVerifiedLedgers(){if(!(!Ce||!this.config?.publishableKey))try{let t=await g(this.config).client.getVerifiedLedgers();this.availableLedgers=t.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||this.availableLedgers[0]?.symbol||"ICP")}catch(e){console.warn("Failed to load verified ledgers:",e),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||"ICP")}}async onPay(){if(Ce&&!(this.processing||this.unlocked)){J(this.config?.debug||!1,"Premium content payment started",{priceUsd:this.config.priceUsd,selectedSymbol:this.selectedSymbol,useOwnWallet:this.config.useOwnWallet}),this.errorMessage=null,this.errorSeverity=null,this.errorAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"pay",type:"sendUsd",amount:this.config.priceUsd,currency:this.selectedSymbol||this.config?.defaultSymbol}}))}catch{}this.processing=!0;try{if(this.config.useOwnWallet){if(!this.config.actorProvider){this.pendingAction="pay",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0}));return}}else if(!this.walletConnected){J(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{he||(he=(await import("./wallet-select-F6BSMPEE.js")).WalletSelect);let l=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab)?W({...this.config?.plugNPlay||{}}):{...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:c}=await import("./origin-44ZEXSX4.js");l.derivationOrigin=this.config?.derivationOrigin||c()}}catch{}this.pnp=new he(l);try{let c=await Q(this.pnp);if(c){this.walletConnected=!0;let h=k(this.pnp,{owner:c,principal:c,connected:!0});this.config={...this.config,connectedWallet:h,actorProvider:($,A)=>this.pnp.getActor({canisterId:$,idl:A,requiresSigning:!0,anon:!1})};try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"oisy"}}))}catch{}this.onPay();return}}catch{}let p=this.pnp.getEnabledWallets();if(J(this.config?.debug||!1,"Available wallets",p),!p?.length)throw new Error("No wallets available");this.pendingAction="pay",this.showWalletModal=!0;return}catch(a){J(this.config?.debug||!1,"Wallet connection error:",a),this.errorMessage=a instanceof Error?a.message:"Wallet connection failed",this.errorSeverity="error";return}}J(this.config?.debug||!1,"Creating SDK for payment");let e=g(this.config),t=this.selectedSymbol||this.config?.defaultSymbol||"ICP",s=this.cryptoOptions.find(a=>a.symbol===t).canisterId||await e.client.getLedgerCanisterIdBySymbol(t);J(this.config?.debug||!1,"Payment details",{priceUsd:this.config.priceUsd,selectedSymbol:t,canisterId:s});let o=await e.sendUsd(this.config.priceUsd,s,{context:"premium-content"});J(this.config?.debug||!1,"Payment completed",{resp:o}),this.unlocked=!0,this.succeeded=!0,this.config.onSuccess&&this.config.onSuccess({id:o.transactionId,status:o.status}),this.dispatchEvent(new CustomEvent("icpay-unlock",{detail:{amount:this.config.priceUsd,tx:o},bubbles:!0}))}catch(e){U(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),B(t)&&(this.errorMessage=R(t),this.errorSeverity=z(t),this.errorAction=D(t))}});try{!this.config.useOwnWallet&&this.pnp&&(await this.pnp.disconnect?.(),this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0})}catch{}}finally{this.processing=!1}}}attachTransakMessageListener(){if(!this.transakMessageHandlerBound){this.transakMessageHandlerBound=e=>this.onTransakMessage(e);try{window.addEventListener("message",this.transakMessageHandlerBound)}catch{}}}detachTransakMessageListener(){if(this.transakMessageHandlerBound){try{window.removeEventListener("message",this.transakMessageHandlerBound)}catch{}this.transakMessageHandlerBound=null}}onTransakMessage(e){let t=e?.data,i=t?.event_id||t?.eventId||t?.id;if(!(!i||typeof i!="string")&&i==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let s=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(s||void 0)}}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1,setTimeout(()=>this.createOnrampIntent(),0)}async createOnrampIntent(){try{let e=g(this.config),t=this.selectedSymbol||this.config?.defaultSymbol||"ICP",s=this.cryptoOptions.find(c=>c.symbol===t).canisterId||await e.client.getLedgerCanisterIdBySymbol(t),o=await e.startOnrampUsd(this.config.priceUsd,s,{context:"premium:onramp"}),a=o?.metadata?.onramp?.sessionId||o?.metadata?.onramp?.session_id||null,l=o?.metadata?.paymentIntentId||o?.paymentIntentId||null,p=o?.metadata?.onramp?.errorMessage||null;this.onrampPaymentIntentId=l,a?(this.onrampSessionId=a,this.onrampErrorMessage=null,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.onrampErrorMessage=p||"Failed to obtain onramp sessionId",this.showOnrampModal=!0)}catch(e){this.onrampSessionId=null,this.onrampErrorMessage=e?.message||"Failed to obtain onramp sessionId",this.showOnrampModal=!0}}startOnrampPolling(e){if(this.onrampPollTimer){try{clearInterval(this.onrampPollTimer)}catch{}this.onrampPollTimer=null}if(this.onrampNotifyController){try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null}let t=this.onrampPaymentIntentId;if(!t)return;let i=g(this.config),s=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>s()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=i.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}select(e){this.selectedSymbol=e}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");this.lastWalletId=(e||"").toLowerCase(),this.pnp.connect(e).then(i=>{if(!!!(i&&(i.connected===!0||i.principal||i.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}let o=k(this.pnp,i);if(this.config={...this.config,connectedWallet:o,actorProvider:(l,p)=>this.pnp.getActor({canisterId:l,idl:p,requiresSigning:!0,anon:!1})},this.lastWalletId==="oisy")this.oisyReadyToPay=!0;else{this.showWalletModal=!1;let l=this.pendingAction;this.pendingAction=null,l==="pay"&&setTimeout(()=>this.onPay(),0)}}).catch(i=>{this.errorMessage=i instanceof Error?i.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1})}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}render(){return this.config?pe`
|
|
978
978
|
<div class="icpay-card icpay-section icpay-widget-base">
|
|
979
979
|
${this.config?.progressBar?.enabled!==!1?pe`
|
|
980
980
|
<icpay-progress-bar
|
|
@@ -1073,7 +1073,7 @@ import{a as n}from"./chunk-LTEQ7OUJ.js";import{css as _e}from"lit";var K=_e`
|
|
|
1073
1073
|
border-color: rgba(239, 68, 68, 0.3);
|
|
1074
1074
|
color: #ef4444;
|
|
1075
1075
|
}
|
|
1076
|
-
`],n([nt({type:Object})],S.prototype,"config",2),n([L()],S.prototype,"selectedSymbol",2),n([L()],S.prototype,"unlocked",2),n([L()],S.prototype,"succeeded",2),n([L()],S.prototype,"processing",2),n([L()],S.prototype,"availableLedgers",2),n([L()],S.prototype,"errorMessage",2),n([L()],S.prototype,"errorSeverity",2),n([L()],S.prototype,"errorAction",2),n([L()],S.prototype,"walletConnected",2),n([L()],S.prototype,"pendingAction",2),n([L()],S.prototype,"showWalletModal",2),n([L()],S.prototype,"oisyReadyToPay",2),n([L()],S.prototype,"lastWalletId",2),n([L()],S.prototype,"showOnrampModal",2),n([L()],S.prototype,"onrampSessionId",2),n([L()],S.prototype,"onrampPaymentIntentId",2),n([L()],S.prototype,"onrampErrorMessage",2),S=n([it("icpay-premium-content")],S);import{LitElement as st,html as le,css as ot}from"lit";import{customElement as rt,property as at,state as M}from"lit/decorators.js";var Oe=typeof window<"u",ue=null;function ee(r,d,e){r&&(e!==void 0?console.log(`[ICPay Widget] ${d}`,e):console.log(`[ICPay Widget] ${d}`))}var f=class extends st{constructor(){super(...arguments);this.selectedAmount=1;this.selectedSymbol=null;this.total=0;this.processing=!1;this.succeeded=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.showOnrampModal=!1;this.onrampSessionId=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.transakMessageHandlerBound=null;this.onrampPollTimer=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="tip",this.showWalletModal=!0,this.requestUpdate();try{let t=Number(this.selectedAmount||0),i=this.selectedSymbol||this.config?.defaultSymbol;window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"tip",type:"sendUsd",amount:t,currency:i}}))}catch{}}catch{}}}async tryAutoConnectPNP(){try{if(!this.config||this.config?.useOwnWallet)return;let e=localStorage.getItem("icpay:pnp");if(!e)return;let t=JSON.parse(e);if(!t?.provider||!t?.principal)return;ue||(ue=(await import("./wallet-select-5SAMV2XC.js")).PNP);let i=W({...this.config?.plugNPlay||{}});try{if(typeof window<"u"){let{resolveDerivationOrigin:o}=await import("./origin-44ZEXSX4.js");i.derivationOrigin=this.config?.derivationOrigin||o()}}catch{}let s=new ue(i);this.walletConnected=!1,this.config={...this.config,connectedWallet:{owner:t.principal,principal:t.principal,connected:!1}}}catch{}}get amounts(){return this.config?.amountsUsd||[1,5,10]}get cryptoOptions(){return this.config.cryptoOptions?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){if(super.connectedCallback(),!!Oe){ee(this.config?.debug||!1,"Tip jar connected",{config:this.config}),this.config&&this.config.defaultAmountUsd&&(this.selectedAmount=this.config.defaultAmountUsd),this.tryAutoConnectPNP();try{window.addEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers(),this.config?.defaultSymbol&&(this.selectedSymbol=this.config.defaultSymbol)}}updated(e){if(e.has("config")&&this.pendingAction&&this.config?.actorProvider){let t=this.pendingAction;this.pendingAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}setTimeout(()=>{t==="tip"&&this.tip()},0)}}async loadVerifiedLedgers(){if(!(!Oe||!this.config?.publishableKey))try{let t=await g(this.config).client.getVerifiedLedgers();this.availableLedgers=t.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.config?.cryptoOptions&&this.config.cryptoOptions.length===1&&(this.selectedSymbol=this.config.cryptoOptions[0].symbol),!this.selectedSymbol&&this.availableLedgers.length>0&&(this.selectedSymbol=this.config?.defaultSymbol||this.availableLedgers[0].symbol)}catch(e){console.warn("Failed to load verified ledgers:",e),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||"ICP")}}selectAmount(e){this.selectedAmount=e}selectSymbol(e){this.selectedSymbol=e}get fillPercentage(){return Math.min(this.total/50*100,100)}async tip(){if(Oe&&(ee(this.config?.debug||!1,"Tip button clicked!",{config:this.config,processing:this.processing}),!this.processing)){this.errorMessage=null,this.errorSeverity=null,this.errorAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"tip",type:"sendUsd",amount:this.selectedAmount,currency:this.selectedSymbol||this.config?.defaultSymbol}}))}catch{}this.processing=!0;try{if(this.config.useOwnWallet){if(!this.config.actorProvider){this.pendingAction="tip",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0}));return}}else if(!this.walletConnected){ee(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{ue||(ue=(await import("./wallet-select-5SAMV2XC.js")).PNP);let l=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab)?W({...this.config?.plugNPlay||{}}):{...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:c}=await import("./origin-44ZEXSX4.js");l.derivationOrigin=this.config?.derivationOrigin||c()}}catch{}this.pnp=new ue(l);try{let c=await Q(this.pnp);if(c){this.walletConnected=!0;let h=k(this.pnp,{owner:c,principal:c,connected:!0});this.config={...this.config,connectedWallet:h,actorProvider:($,A)=>this.pnp.getActor({canisterId:$,idl:A,requiresSigning:!0,anon:!1})};try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"oisy"}}))}catch{}this.tip();return}}catch{}let p=this.pnp.getEnabledWallets();if(ee(this.config?.debug||!1,"Available wallets",p),!p?.length)throw new Error("No wallets available");this.pendingAction="tip",this.showWalletModal=!0;return}catch(a){ee(this.config?.debug||!1,"Wallet connection error:",a),this.errorMessage=a instanceof Error?a.message:"Wallet connection failed",this.errorSeverity="error";return}}ee(this.config?.debug||!1,"Creating SDK for payment");let e=g(this.config),t=this.selectedSymbol||this.config?.defaultSymbol||"ICP",s=this.cryptoOptions.find(a=>a.symbol===t).canisterId||await e.client.getLedgerCanisterIdBySymbol(t);ee(this.config?.debug||!1,"Tip payment details",{amount:this.selectedAmount,selectedSymbol:t,canisterId:s});let o=await e.sendUsd(this.selectedAmount,s,{context:"tip-jar"});ee(this.config?.debug||!1,"Tip payment completed",{resp:o}),this.total+=this.selectedAmount,this.succeeded=!0,this.config.onSuccess&&this.config.onSuccess({id:o.transactionId,status:o.status,total:this.total}),this.dispatchEvent(new CustomEvent("icpay-tip",{detail:{amount:this.selectedAmount,tx:o},bubbles:!0}))}catch(e){U(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),B(t)&&(this.errorMessage=R(t),this.errorSeverity=z(t),this.errorAction=D(t))}});try{!this.config.useOwnWallet&&this.pnp&&(await this.pnp.disconnect?.(),this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0})}catch{}}finally{this.processing=!1}}}attachTransakMessageListener(){if(!this.transakMessageHandlerBound){this.transakMessageHandlerBound=e=>this.onTransakMessage(e);try{window.addEventListener("message",this.transakMessageHandlerBound)}catch{}}}detachTransakMessageListener(){if(this.transakMessageHandlerBound){try{window.removeEventListener("message",this.transakMessageHandlerBound)}catch{}this.transakMessageHandlerBound=null}}onTransakMessage(e){let t=e?.data,i=t?.event_id||t?.eventId||t?.id;if(!(!i||typeof i!="string")&&i==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let s=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(s||void 0)}}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1,setTimeout(()=>this.createOnrampIntent(),0)}async createOnrampIntent(){try{let e=g(this.config),t=this.selectedSymbol||this.config?.defaultSymbol||"ICP",s=this.cryptoOptions.find(c=>c.symbol===t).canisterId||await e.client.getLedgerCanisterIdBySymbol(t),o=await e.startOnrampUsd(this.selectedAmount,s,{context:"tip:onramp"}),a=o?.metadata?.onramp?.sessionId||o?.metadata?.onramp?.session_id||null,l=o?.metadata?.paymentIntentId||o?.paymentIntentId||null,p=o?.metadata?.onramp?.errorMessage||null;this.onrampPaymentIntentId=l,a?(this.onrampSessionId=a,this.onrampErrorMessage=null,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.onrampErrorMessage=p||"Failed to obtain onramp sessionId",this.showOnrampModal=!0)}catch(e){this.onrampSessionId=null,this.onrampErrorMessage=e?.message||"Failed to obtain onramp sessionId",this.showOnrampModal=!0}}startOnrampPolling(e){if(this.onrampPollTimer){try{clearInterval(this.onrampPollTimer)}catch{}this.onrampPollTimer=null}if(this.onrampNotifyController){try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null}let t=this.onrampPaymentIntentId;if(!t)return;let i=g(this.config),s=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>s()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=i.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");this.lastWalletId=(e||"").toLowerCase(),this.pnp.connect(e).then(i=>{if(!!!(i&&(i.connected===!0||i.principal||i.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}let o=k(this.pnp,i);if(this.config={...this.config,connectedWallet:o,actorProvider:(l,p)=>this.pnp.getActor({canisterId:l,idl:p,requiresSigning:!0,anon:!1})},this.lastWalletId==="oisy")this.oisyReadyToPay=!0;else{this.showWalletModal=!1;let l=this.pendingAction;this.pendingAction=null,l==="tip"&&setTimeout(()=>this.tip(),0)}}).catch(i=>{this.errorMessage=i instanceof Error?i.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1})}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}render(){if(!this.config)return le`<div class="icpay-card icpay-section">Loading...</div>`;let t=(this.cryptoOptions?.length||0)>1,i=this.config?.showLedgerDropdown,s=i==="dropdown"?"dropdown":i==="none"?"none":"buttons",o=s!=="none"&&(t||s==="dropdown"),a=s==="dropdown"?"dropdown":t?"buttons":"none";return le`
|
|
1076
|
+
`],n([nt({type:Object})],S.prototype,"config",2),n([L()],S.prototype,"selectedSymbol",2),n([L()],S.prototype,"unlocked",2),n([L()],S.prototype,"succeeded",2),n([L()],S.prototype,"processing",2),n([L()],S.prototype,"availableLedgers",2),n([L()],S.prototype,"errorMessage",2),n([L()],S.prototype,"errorSeverity",2),n([L()],S.prototype,"errorAction",2),n([L()],S.prototype,"walletConnected",2),n([L()],S.prototype,"pendingAction",2),n([L()],S.prototype,"showWalletModal",2),n([L()],S.prototype,"oisyReadyToPay",2),n([L()],S.prototype,"lastWalletId",2),n([L()],S.prototype,"showOnrampModal",2),n([L()],S.prototype,"onrampSessionId",2),n([L()],S.prototype,"onrampPaymentIntentId",2),n([L()],S.prototype,"onrampErrorMessage",2),S=n([it("icpay-premium-content")],S);import{LitElement as st,html as le,css as ot}from"lit";import{customElement as rt,property as at,state as M}from"lit/decorators.js";var Oe=typeof window<"u",ue=null;function ee(r,d,e){r&&(e!==void 0?console.log(`[ICPay Widget] ${d}`,e):console.log(`[ICPay Widget] ${d}`))}var f=class extends st{constructor(){super(...arguments);this.selectedAmount=1;this.selectedSymbol=null;this.total=0;this.processing=!1;this.succeeded=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.showOnrampModal=!1;this.onrampSessionId=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.transakMessageHandlerBound=null;this.onrampPollTimer=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="tip",this.showWalletModal=!0,this.requestUpdate();try{let t=Number(this.selectedAmount||0),i=this.selectedSymbol||this.config?.defaultSymbol;window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"tip",type:"sendUsd",amount:t,currency:i}}))}catch{}}catch{}}}async tryAutoConnectPNP(){try{if(!this.config||this.config?.useOwnWallet)return;let e=localStorage.getItem("icpay:pnp");if(!e)return;let t=JSON.parse(e);if(!t?.provider||!t?.principal)return;ue||(ue=(await import("./wallet-select-F6BSMPEE.js")).WalletSelect);let i=W({...this.config?.plugNPlay||{}});try{if(typeof window<"u"){let{resolveDerivationOrigin:o}=await import("./origin-44ZEXSX4.js");i.derivationOrigin=this.config?.derivationOrigin||o()}}catch{}let s=new ue(i);this.walletConnected=!1,this.config={...this.config,connectedWallet:{owner:t.principal,principal:t.principal,connected:!1}}}catch{}}get amounts(){return this.config?.amountsUsd||[1,5,10]}get cryptoOptions(){return this.config.cryptoOptions?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){if(super.connectedCallback(),!!Oe){ee(this.config?.debug||!1,"Tip jar connected",{config:this.config}),this.config&&this.config.defaultAmountUsd&&(this.selectedAmount=this.config.defaultAmountUsd),this.tryAutoConnectPNP();try{window.addEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers(),this.config?.defaultSymbol&&(this.selectedSymbol=this.config.defaultSymbol)}}updated(e){if(e.has("config")&&this.pendingAction&&this.config?.actorProvider){let t=this.pendingAction;this.pendingAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}setTimeout(()=>{t==="tip"&&this.tip()},0)}}async loadVerifiedLedgers(){if(!(!Oe||!this.config?.publishableKey))try{let t=await g(this.config).client.getVerifiedLedgers();this.availableLedgers=t.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.config?.cryptoOptions&&this.config.cryptoOptions.length===1&&(this.selectedSymbol=this.config.cryptoOptions[0].symbol),!this.selectedSymbol&&this.availableLedgers.length>0&&(this.selectedSymbol=this.config?.defaultSymbol||this.availableLedgers[0].symbol)}catch(e){console.warn("Failed to load verified ledgers:",e),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||"ICP")}}selectAmount(e){this.selectedAmount=e}selectSymbol(e){this.selectedSymbol=e}get fillPercentage(){return Math.min(this.total/50*100,100)}async tip(){if(Oe&&(ee(this.config?.debug||!1,"Tip button clicked!",{config:this.config,processing:this.processing}),!this.processing)){this.errorMessage=null,this.errorSeverity=null,this.errorAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"tip",type:"sendUsd",amount:this.selectedAmount,currency:this.selectedSymbol||this.config?.defaultSymbol}}))}catch{}this.processing=!0;try{if(this.config.useOwnWallet){if(!this.config.actorProvider){this.pendingAction="tip",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0}));return}}else if(!this.walletConnected){ee(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{ue||(ue=(await import("./wallet-select-F6BSMPEE.js")).WalletSelect);let l=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab)?W({...this.config?.plugNPlay||{}}):{...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:c}=await import("./origin-44ZEXSX4.js");l.derivationOrigin=this.config?.derivationOrigin||c()}}catch{}this.pnp=new ue(l);try{let c=await Q(this.pnp);if(c){this.walletConnected=!0;let h=k(this.pnp,{owner:c,principal:c,connected:!0});this.config={...this.config,connectedWallet:h,actorProvider:($,A)=>this.pnp.getActor({canisterId:$,idl:A,requiresSigning:!0,anon:!1})};try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"oisy"}}))}catch{}this.tip();return}}catch{}let p=this.pnp.getEnabledWallets();if(ee(this.config?.debug||!1,"Available wallets",p),!p?.length)throw new Error("No wallets available");this.pendingAction="tip",this.showWalletModal=!0;return}catch(a){ee(this.config?.debug||!1,"Wallet connection error:",a),this.errorMessage=a instanceof Error?a.message:"Wallet connection failed",this.errorSeverity="error";return}}ee(this.config?.debug||!1,"Creating SDK for payment");let e=g(this.config),t=this.selectedSymbol||this.config?.defaultSymbol||"ICP",s=this.cryptoOptions.find(a=>a.symbol===t).canisterId||await e.client.getLedgerCanisterIdBySymbol(t);ee(this.config?.debug||!1,"Tip payment details",{amount:this.selectedAmount,selectedSymbol:t,canisterId:s});let o=await e.sendUsd(this.selectedAmount,s,{context:"tip-jar"});ee(this.config?.debug||!1,"Tip payment completed",{resp:o}),this.total+=this.selectedAmount,this.succeeded=!0,this.config.onSuccess&&this.config.onSuccess({id:o.transactionId,status:o.status,total:this.total}),this.dispatchEvent(new CustomEvent("icpay-tip",{detail:{amount:this.selectedAmount,tx:o},bubbles:!0}))}catch(e){U(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),B(t)&&(this.errorMessage=R(t),this.errorSeverity=z(t),this.errorAction=D(t))}});try{!this.config.useOwnWallet&&this.pnp&&(await this.pnp.disconnect?.(),this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0})}catch{}}finally{this.processing=!1}}}attachTransakMessageListener(){if(!this.transakMessageHandlerBound){this.transakMessageHandlerBound=e=>this.onTransakMessage(e);try{window.addEventListener("message",this.transakMessageHandlerBound)}catch{}}}detachTransakMessageListener(){if(this.transakMessageHandlerBound){try{window.removeEventListener("message",this.transakMessageHandlerBound)}catch{}this.transakMessageHandlerBound=null}}onTransakMessage(e){let t=e?.data,i=t?.event_id||t?.eventId||t?.id;if(!(!i||typeof i!="string")&&i==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let s=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(s||void 0)}}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1,setTimeout(()=>this.createOnrampIntent(),0)}async createOnrampIntent(){try{let e=g(this.config),t=this.selectedSymbol||this.config?.defaultSymbol||"ICP",s=this.cryptoOptions.find(c=>c.symbol===t).canisterId||await e.client.getLedgerCanisterIdBySymbol(t),o=await e.startOnrampUsd(this.selectedAmount,s,{context:"tip:onramp"}),a=o?.metadata?.onramp?.sessionId||o?.metadata?.onramp?.session_id||null,l=o?.metadata?.paymentIntentId||o?.paymentIntentId||null,p=o?.metadata?.onramp?.errorMessage||null;this.onrampPaymentIntentId=l,a?(this.onrampSessionId=a,this.onrampErrorMessage=null,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.onrampErrorMessage=p||"Failed to obtain onramp sessionId",this.showOnrampModal=!0)}catch(e){this.onrampSessionId=null,this.onrampErrorMessage=e?.message||"Failed to obtain onramp sessionId",this.showOnrampModal=!0}}startOnrampPolling(e){if(this.onrampPollTimer){try{clearInterval(this.onrampPollTimer)}catch{}this.onrampPollTimer=null}if(this.onrampNotifyController){try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null}let t=this.onrampPaymentIntentId;if(!t)return;let i=g(this.config),s=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>s()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=i.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");this.lastWalletId=(e||"").toLowerCase(),this.pnp.connect(e).then(i=>{if(!!!(i&&(i.connected===!0||i.principal||i.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}let o=k(this.pnp,i);if(this.config={...this.config,connectedWallet:o,actorProvider:(l,p)=>this.pnp.getActor({canisterId:l,idl:p,requiresSigning:!0,anon:!1})},this.lastWalletId==="oisy")this.oisyReadyToPay=!0;else{this.showWalletModal=!1;let l=this.pendingAction;this.pendingAction=null,l==="tip"&&setTimeout(()=>this.tip(),0)}}).catch(i=>{this.errorMessage=i instanceof Error?i.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1})}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}render(){if(!this.config)return le`<div class="icpay-card icpay-section">Loading...</div>`;let t=(this.cryptoOptions?.length||0)>1,i=this.config?.showLedgerDropdown,s=i==="dropdown"?"dropdown":i==="none"?"none":"buttons",o=s!=="none"&&(t||s==="dropdown"),a=s==="dropdown"?"dropdown":t?"buttons":"none";return le`
|
|
1077
1077
|
<div class="icpay-card icpay-section icpay-widget-base" style="text-align:center;">
|
|
1078
1078
|
${this.config?.progressBar?.enabled!==!1?le`
|
|
1079
1079
|
<icpay-progress-bar
|
|
@@ -1154,7 +1154,7 @@ import{a as n}from"./chunk-LTEQ7OUJ.js";import{css as _e}from"lit";var K=_e`
|
|
|
1154
1154
|
border-color: rgba(239, 68, 68, 0.3);
|
|
1155
1155
|
color: #ef4444;
|
|
1156
1156
|
}
|
|
1157
|
-
`],n([at({type:Object})],f.prototype,"config",2),n([M()],f.prototype,"selectedAmount",2),n([M()],f.prototype,"selectedSymbol",2),n([M()],f.prototype,"total",2),n([M()],f.prototype,"processing",2),n([M()],f.prototype,"succeeded",2),n([M()],f.prototype,"availableLedgers",2),n([M()],f.prototype,"errorMessage",2),n([M()],f.prototype,"errorSeverity",2),n([M()],f.prototype,"errorAction",2),n([M()],f.prototype,"walletConnected",2),n([M()],f.prototype,"pendingAction",2),n([M()],f.prototype,"showWalletModal",2),n([M()],f.prototype,"oisyReadyToPay",2),n([M()],f.prototype,"lastWalletId",2),n([M()],f.prototype,"showOnrampModal",2),n([M()],f.prototype,"onrampSessionId",2),n([M()],f.prototype,"onrampPaymentIntentId",2),n([M()],f.prototype,"onrampErrorMessage",2),f=n([rt("icpay-tip-jar")],f);import{LitElement as lt,html as Se,css as ct}from"lit";import{customElement as dt,property as ke,state as T}from"lit/decorators.js";var Ie=typeof window<"u",ye=null;function te(r,d,e){r&&(e!==void 0?console.log(`[ICPay Widget] ${d}`,e):console.log(`[ICPay Widget] ${d}`))}var m=class extends lt{constructor(){super(...arguments);this.title="Article Title";this.preview="";this.lockedContent="";this.selectedSymbol=null;this.unlocked=!1;this.succeeded=!1;this.processing=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.showOnrampModal=!1;this.onrampSessionId=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.transakMessageHandlerBound=null;this.onrampPollTimer=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="unlock",this.showWalletModal=!0,this.requestUpdate();try{let t=Number(this.config?.priceUsd||0),i=this.selectedSymbol||this.config?.defaultSymbol;window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"unlock",type:"sendUsd",amount:t,currency:i}}))}catch{}}catch{}}}get obfuscatedLockedContent(){try{return(this.lockedContent||"").replace(/[^\s]/g,"x")}catch{return"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}}async tryAutoConnectPNP(){try{if(!this.config||this.config?.useOwnWallet)return;let e=localStorage.getItem("icpay:pnp");if(!e)return;let t=JSON.parse(e);if(!t?.provider||!t?.principal)return;ye||(ye=(await import("./wallet-select-5SAMV2XC.js")).PNP);let i={...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:o}=await import("./origin-44ZEXSX4.js");i.derivationOrigin=this.config?.derivationOrigin||o()}}catch{}let s=new ye(i);this.walletConnected=!1,this.config={...this.config,connectedWallet:{owner:t.principal,principal:t.principal,connected:!1}}}catch{}}attachTransakMessageListener(){if(!this.transakMessageHandlerBound){this.transakMessageHandlerBound=e=>this.onTransakMessage(e);try{window.addEventListener("message",this.transakMessageHandlerBound)}catch{}}}detachTransakMessageListener(){if(this.transakMessageHandlerBound){try{window.removeEventListener("message",this.transakMessageHandlerBound)}catch{}this.transakMessageHandlerBound=null}}onTransakMessage(e){let t=e?.data,i=t?.event_id||t?.eventId||t?.id;if(!(!i||typeof i!="string")&&i==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let s=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(s||void 0)}}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1,setTimeout(()=>this.createOnrampIntent(),0)}async createOnrampIntent(){try{let e=g(this.config),t=this.selectedSymbol||this.config?.defaultSymbol||"ICP",s=this.cryptoOptions.find(c=>c.symbol===t).canisterId||await e.client.getLedgerCanisterIdBySymbol(t),o=await e.startOnrampUsd(this.config.priceUsd,s,{context:"article:onramp"}),a=o?.metadata?.onramp?.sessionId||o?.metadata?.onramp?.session_id||null,l=o?.metadata?.paymentIntentId||o?.paymentIntentId||null,p=o?.metadata?.onramp?.errorMessage||null;this.onrampPaymentIntentId=l,a?(this.onrampSessionId=a,this.onrampErrorMessage=null,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.onrampErrorMessage=p||"Failed to obtain onramp sessionId",this.showOnrampModal=!0)}catch(e){this.onrampSessionId=null,this.onrampErrorMessage=e?.message||"Failed to obtain onramp sessionId",this.showOnrampModal=!0}}startOnrampPolling(e){if(this.onrampPollTimer){try{clearInterval(this.onrampPollTimer)}catch{}this.onrampPollTimer=null}if(this.onrampNotifyController){try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null}let t=this.onrampPaymentIntentId;if(!t)return;let i=g(this.config),s=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>s()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=i.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}get cryptoOptions(){return this.config.cryptoOptions?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){if(super.connectedCallback(),!!Ie){te(this.config?.debug||!1,"Article paywall connected",{config:this.config}),this.config&&(typeof this.config.title=="string"&&(this.title=this.config.title),typeof this.config.preview=="string"&&(this.preview=this.config.preview),typeof this.config.lockedContent=="string"&&(this.lockedContent=this.config.lockedContent)),this.tryAutoConnectPNP();try{window.addEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers()}}updated(e){if(e.has("config")&&this.config&&(typeof this.config.title=="string"&&(this.title=this.config.title),typeof this.config.preview=="string"&&(this.preview=this.config.preview),typeof this.config.lockedContent=="string"&&(this.lockedContent=this.config.lockedContent)),e.has("config")&&this.pendingAction&&this.config?.actorProvider){let t=this.pendingAction;this.pendingAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}setTimeout(()=>{t==="unlock"&&this.unlock()},0)}}async loadVerifiedLedgers(){if(!(!Ie||!this.config?.publishableKey))try{let t=await g(this.config).client.getVerifiedLedgers();this.availableLedgers=t.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||this.availableLedgers[0]?.symbol||"ICP")}catch(e){console.warn("Failed to load verified ledgers:",e),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||"ICP")}}selectSymbol(e){this.selectedSymbol=e}async unlock(){if(Ie&&!(this.processing||this.unlocked)){te(this.config?.debug||!1,"Article paywall unlock started",{priceUsd:this.config.priceUsd,selectedSymbol:this.selectedSymbol,useOwnWallet:this.config.useOwnWallet}),this.errorMessage=null,this.errorSeverity=null,this.errorAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"unlock",type:"sendUsd",amount:this.config.priceUsd,currency:this.selectedSymbol||this.config?.defaultSymbol}}))}catch{}this.processing=!0;try{if(this.config.useOwnWallet){if(!this.config.actorProvider){this.pendingAction="unlock",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0}));return}}else if(!this.walletConnected){te(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{ye||(ye=(await import("./wallet-select-5SAMV2XC.js")).PNP);let l=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab)?W({...this.config?.plugNPlay||{}}):{...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:c}=await import("./origin-44ZEXSX4.js");l.derivationOrigin=this.config?.derivationOrigin||c()}}catch{}this.pnp=new ye(l);try{let c=await Q(this.pnp);if(c){this.walletConnected=!0;let h=k(this.pnp,{owner:c,principal:c,connected:!0});this.config={...this.config,connectedWallet:h,actorProvider:($,A)=>this.pnp.getActor({canisterId:$,idl:A,requiresSigning:!0,anon:!1})};try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"oisy"}}))}catch{}this.unlock();return}}catch{}let p=this.pnp.getEnabledWallets();if(te(this.config?.debug||!1,"Available wallets",p),!p?.length)throw new Error("No wallets available");this.pendingAction="unlock",this.showWalletModal=!0;return}catch(a){te(this.config?.debug||!1,"Wallet connection error:",a),this.errorMessage=a instanceof Error?a.message:"Wallet connection failed",this.errorSeverity="error";return}}te(this.config?.debug||!1,"Creating SDK for payment");let e=g(this.config),t=this.selectedSymbol||this.config?.defaultSymbol||"ICP",s=this.cryptoOptions.find(a=>a.symbol===t).canisterId||await e.client.getLedgerCanisterIdBySymbol(t);te(this.config?.debug||!1,"Article payment details",{priceUsd:this.config.priceUsd,selectedSymbol:t,canisterId:s});let o=await e.sendUsd(this.config.priceUsd,s,{context:"article"});te(this.config?.debug||!1,"Article payment completed",{resp:o}),this.unlocked=!0,this.succeeded=!0,this.config.onSuccess&&this.config.onSuccess({id:o.transactionId,status:o.status}),this.dispatchEvent(new CustomEvent("icpay-unlock",{detail:{amount:this.config.priceUsd,tx:o},bubbles:!0}))}catch(e){U(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),B(t)&&(this.errorMessage=R(t),this.errorSeverity=z(t),this.errorAction=D(t))}});try{!this.config.useOwnWallet&&this.pnp&&(await this.pnp.disconnect?.(),this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0})}catch{}}finally{this.processing=!1}}}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");this.lastWalletId=(e||"").toLowerCase(),this.pnp.connect(e).then(i=>{if(!!!(i&&(i.connected===!0||i.principal||i.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}let o=k(this.pnp,i);if(this.config={...this.config,connectedWallet:o,actorProvider:(l,p)=>this.pnp.getActor({canisterId:l,idl:p,requiresSigning:!0,anon:!1})},this.lastWalletId==="oisy")this.oisyReadyToPay=!0;else{this.showWalletModal=!1;let l=this.pendingAction;this.pendingAction=null,l==="unlock"&&setTimeout(()=>this.unlock(),0)}}).catch(i=>{this.errorMessage=i instanceof Error?i.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1})}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}render(){return this.config?Se`
|
|
1157
|
+
`],n([at({type:Object})],f.prototype,"config",2),n([M()],f.prototype,"selectedAmount",2),n([M()],f.prototype,"selectedSymbol",2),n([M()],f.prototype,"total",2),n([M()],f.prototype,"processing",2),n([M()],f.prototype,"succeeded",2),n([M()],f.prototype,"availableLedgers",2),n([M()],f.prototype,"errorMessage",2),n([M()],f.prototype,"errorSeverity",2),n([M()],f.prototype,"errorAction",2),n([M()],f.prototype,"walletConnected",2),n([M()],f.prototype,"pendingAction",2),n([M()],f.prototype,"showWalletModal",2),n([M()],f.prototype,"oisyReadyToPay",2),n([M()],f.prototype,"lastWalletId",2),n([M()],f.prototype,"showOnrampModal",2),n([M()],f.prototype,"onrampSessionId",2),n([M()],f.prototype,"onrampPaymentIntentId",2),n([M()],f.prototype,"onrampErrorMessage",2),f=n([rt("icpay-tip-jar")],f);import{LitElement as lt,html as Se,css as ct}from"lit";import{customElement as dt,property as ke,state as T}from"lit/decorators.js";var Ie=typeof window<"u",ye=null;function te(r,d,e){r&&(e!==void 0?console.log(`[ICPay Widget] ${d}`,e):console.log(`[ICPay Widget] ${d}`))}var m=class extends lt{constructor(){super(...arguments);this.title="Article Title";this.preview="";this.lockedContent="";this.selectedSymbol=null;this.unlocked=!1;this.succeeded=!1;this.processing=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.showOnrampModal=!1;this.onrampSessionId=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.transakMessageHandlerBound=null;this.onrampPollTimer=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="unlock",this.showWalletModal=!0,this.requestUpdate();try{let t=Number(this.config?.priceUsd||0),i=this.selectedSymbol||this.config?.defaultSymbol;window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"unlock",type:"sendUsd",amount:t,currency:i}}))}catch{}}catch{}}}get obfuscatedLockedContent(){try{return(this.lockedContent||"").replace(/[^\s]/g,"x")}catch{return"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}}async tryAutoConnectPNP(){try{if(!this.config||this.config?.useOwnWallet)return;let e=localStorage.getItem("icpay:pnp");if(!e)return;let t=JSON.parse(e);if(!t?.provider||!t?.principal)return;ye||(ye=(await import("./wallet-select-F6BSMPEE.js")).WalletSelect);let i={...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:o}=await import("./origin-44ZEXSX4.js");i.derivationOrigin=this.config?.derivationOrigin||o()}}catch{}let s=new ye(i);this.walletConnected=!1,this.config={...this.config,connectedWallet:{owner:t.principal,principal:t.principal,connected:!1}}}catch{}}attachTransakMessageListener(){if(!this.transakMessageHandlerBound){this.transakMessageHandlerBound=e=>this.onTransakMessage(e);try{window.addEventListener("message",this.transakMessageHandlerBound)}catch{}}}detachTransakMessageListener(){if(this.transakMessageHandlerBound){try{window.removeEventListener("message",this.transakMessageHandlerBound)}catch{}this.transakMessageHandlerBound=null}}onTransakMessage(e){let t=e?.data,i=t?.event_id||t?.eventId||t?.id;if(!(!i||typeof i!="string")&&i==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let s=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(s||void 0)}}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1,setTimeout(()=>this.createOnrampIntent(),0)}async createOnrampIntent(){try{let e=g(this.config),t=this.selectedSymbol||this.config?.defaultSymbol||"ICP",s=this.cryptoOptions.find(c=>c.symbol===t).canisterId||await e.client.getLedgerCanisterIdBySymbol(t),o=await e.startOnrampUsd(this.config.priceUsd,s,{context:"article:onramp"}),a=o?.metadata?.onramp?.sessionId||o?.metadata?.onramp?.session_id||null,l=o?.metadata?.paymentIntentId||o?.paymentIntentId||null,p=o?.metadata?.onramp?.errorMessage||null;this.onrampPaymentIntentId=l,a?(this.onrampSessionId=a,this.onrampErrorMessage=null,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.onrampErrorMessage=p||"Failed to obtain onramp sessionId",this.showOnrampModal=!0)}catch(e){this.onrampSessionId=null,this.onrampErrorMessage=e?.message||"Failed to obtain onramp sessionId",this.showOnrampModal=!0}}startOnrampPolling(e){if(this.onrampPollTimer){try{clearInterval(this.onrampPollTimer)}catch{}this.onrampPollTimer=null}if(this.onrampNotifyController){try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null}let t=this.onrampPaymentIntentId;if(!t)return;let i=g(this.config),s=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>s()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=i.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}get cryptoOptions(){return this.config.cryptoOptions?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){if(super.connectedCallback(),!!Ie){te(this.config?.debug||!1,"Article paywall connected",{config:this.config}),this.config&&(typeof this.config.title=="string"&&(this.title=this.config.title),typeof this.config.preview=="string"&&(this.preview=this.config.preview),typeof this.config.lockedContent=="string"&&(this.lockedContent=this.config.lockedContent)),this.tryAutoConnectPNP();try{window.addEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers()}}updated(e){if(e.has("config")&&this.config&&(typeof this.config.title=="string"&&(this.title=this.config.title),typeof this.config.preview=="string"&&(this.preview=this.config.preview),typeof this.config.lockedContent=="string"&&(this.lockedContent=this.config.lockedContent)),e.has("config")&&this.pendingAction&&this.config?.actorProvider){let t=this.pendingAction;this.pendingAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}setTimeout(()=>{t==="unlock"&&this.unlock()},0)}}async loadVerifiedLedgers(){if(!(!Ie||!this.config?.publishableKey))try{let t=await g(this.config).client.getVerifiedLedgers();this.availableLedgers=t.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||this.availableLedgers[0]?.symbol||"ICP")}catch(e){console.warn("Failed to load verified ledgers:",e),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||"ICP")}}selectSymbol(e){this.selectedSymbol=e}async unlock(){if(Ie&&!(this.processing||this.unlocked)){te(this.config?.debug||!1,"Article paywall unlock started",{priceUsd:this.config.priceUsd,selectedSymbol:this.selectedSymbol,useOwnWallet:this.config.useOwnWallet}),this.errorMessage=null,this.errorSeverity=null,this.errorAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"unlock",type:"sendUsd",amount:this.config.priceUsd,currency:this.selectedSymbol||this.config?.defaultSymbol}}))}catch{}this.processing=!0;try{if(this.config.useOwnWallet){if(!this.config.actorProvider){this.pendingAction="unlock",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0}));return}}else if(!this.walletConnected){te(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{ye||(ye=(await import("./wallet-select-F6BSMPEE.js")).WalletSelect);let l=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab)?W({...this.config?.plugNPlay||{}}):{...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:c}=await import("./origin-44ZEXSX4.js");l.derivationOrigin=this.config?.derivationOrigin||c()}}catch{}this.pnp=new ye(l);try{let c=await Q(this.pnp);if(c){this.walletConnected=!0;let h=k(this.pnp,{owner:c,principal:c,connected:!0});this.config={...this.config,connectedWallet:h,actorProvider:($,A)=>this.pnp.getActor({canisterId:$,idl:A,requiresSigning:!0,anon:!1})};try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"oisy"}}))}catch{}this.unlock();return}}catch{}let p=this.pnp.getEnabledWallets();if(te(this.config?.debug||!1,"Available wallets",p),!p?.length)throw new Error("No wallets available");this.pendingAction="unlock",this.showWalletModal=!0;return}catch(a){te(this.config?.debug||!1,"Wallet connection error:",a),this.errorMessage=a instanceof Error?a.message:"Wallet connection failed",this.errorSeverity="error";return}}te(this.config?.debug||!1,"Creating SDK for payment");let e=g(this.config),t=this.selectedSymbol||this.config?.defaultSymbol||"ICP",s=this.cryptoOptions.find(a=>a.symbol===t).canisterId||await e.client.getLedgerCanisterIdBySymbol(t);te(this.config?.debug||!1,"Article payment details",{priceUsd:this.config.priceUsd,selectedSymbol:t,canisterId:s});let o=await e.sendUsd(this.config.priceUsd,s,{context:"article"});te(this.config?.debug||!1,"Article payment completed",{resp:o}),this.unlocked=!0,this.succeeded=!0,this.config.onSuccess&&this.config.onSuccess({id:o.transactionId,status:o.status}),this.dispatchEvent(new CustomEvent("icpay-unlock",{detail:{amount:this.config.priceUsd,tx:o},bubbles:!0}))}catch(e){U(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),B(t)&&(this.errorMessage=R(t),this.errorSeverity=z(t),this.errorAction=D(t))}});try{!this.config.useOwnWallet&&this.pnp&&(await this.pnp.disconnect?.(),this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0})}catch{}}finally{this.processing=!1}}}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");this.lastWalletId=(e||"").toLowerCase(),this.pnp.connect(e).then(i=>{if(!!!(i&&(i.connected===!0||i.principal||i.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}let o=k(this.pnp,i);if(this.config={...this.config,connectedWallet:o,actorProvider:(l,p)=>this.pnp.getActor({canisterId:l,idl:p,requiresSigning:!0,anon:!1})},this.lastWalletId==="oisy")this.oisyReadyToPay=!0;else{this.showWalletModal=!1;let l=this.pendingAction;this.pendingAction=null,l==="unlock"&&setTimeout(()=>this.unlock(),0)}}).catch(i=>{this.errorMessage=i instanceof Error?i.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1})}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}render(){return this.config?Se`
|
|
1158
1158
|
<div class="icpay-card icpay-section icpay-widget-base">
|
|
1159
1159
|
${this.config?.progressBar?.enabled!==!1?Se`
|
|
1160
1160
|
<icpay-progress-bar
|
|
@@ -1232,7 +1232,7 @@ import{a as n}from"./chunk-LTEQ7OUJ.js";import{css as _e}from"lit";var K=_e`
|
|
|
1232
1232
|
border-color: rgba(239, 68, 68, 0.3);
|
|
1233
1233
|
color: #ef4444;
|
|
1234
1234
|
}
|
|
1235
|
-
`],n([ke({type:Object})],m.prototype,"config",2),n([ke({type:String})],m.prototype,"title",2),n([ke({type:String})],m.prototype,"preview",2),n([ke({type:String})],m.prototype,"lockedContent",2),n([T()],m.prototype,"selectedSymbol",2),n([T()],m.prototype,"unlocked",2),n([T()],m.prototype,"succeeded",2),n([T()],m.prototype,"processing",2),n([T()],m.prototype,"availableLedgers",2),n([T()],m.prototype,"errorMessage",2),n([T()],m.prototype,"errorSeverity",2),n([T()],m.prototype,"errorAction",2),n([T()],m.prototype,"walletConnected",2),n([T()],m.prototype,"pendingAction",2),n([T()],m.prototype,"showWalletModal",2),n([T()],m.prototype,"oisyReadyToPay",2),n([T()],m.prototype,"lastWalletId",2),n([T()],m.prototype,"showOnrampModal",2),n([T()],m.prototype,"onrampSessionId",2),n([T()],m.prototype,"onrampPaymentIntentId",2),n([T()],m.prototype,"onrampErrorMessage",2),m=n([dt("icpay-article-paywall")],m);import{LitElement as pt,html as me,css as ht}from"lit";import{customElement as gt,property as ut,state as N}from"lit/decorators.js";var We=typeof window<"u",Le=null;function ie(r,d,e){r&&(e!==void 0?console.log(`[ICPay Widget] ${d}`,e):console.log(`[ICPay Widget] ${d}`))}var E=class extends pt{constructor(){super(...arguments);this.selectedIndex=0;this.selectedSymbol=null;this.processing=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.showOnrampModal=!1;this.onrampSessionId=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.transakMessageHandlerBound=null;this.onrampPollTimer=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="order",this.showWalletModal=!0,this.requestUpdate();try{let t=Number(this.selectedItem?.priceUsd||0),i=this.selectedSymbol||this.config?.defaultSymbol;window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"order",type:"sendUsd",amount:t,currency:i}}))}catch{}}catch{}}}get cryptoOptions(){return this.config.cryptoOptions?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){if(super.connectedCallback(),!!We){ie(this.config?.debug||!1,"Coffee shop connected",{config:this.config}),this.config&&typeof this.config.defaultItemIndex=="number"&&(this.selectedIndex=this.config.defaultItemIndex),this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers();try{window.addEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}}}updated(e){if(e.has("config")&&this.pendingAction&&this.config?.actorProvider){let t=this.pendingAction;this.pendingAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}setTimeout(()=>{t==="order"&&this.order()},0)}}async loadVerifiedLedgers(){if(!(!We||!this.config?.publishableKey))try{let t=await g(this.config).client.getVerifiedLedgers();this.availableLedgers=t.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||this.availableLedgers[0]?.symbol||"ICP")}catch(e){console.warn("Failed to load verified ledgers:",e),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||"ICP")}}selectItem(e){this.selectedIndex=e}selectSymbol(e){this.selectedSymbol=e}get selectedItem(){return this.config?.items?.[this.selectedIndex]||{name:"Loading...",priceUsd:0}}async order(){if(We&&!this.processing){ie(this.config?.debug||!1,"Coffee order started",{selectedItem:this.selectedItem,selectedSymbol:this.selectedSymbol,useOwnWallet:this.config.useOwnWallet}),this.errorMessage=null,this.errorSeverity=null,this.errorAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"order",type:"sendUsd",amount:this.selectedItem.priceUsd,currency:this.selectedSymbol||this.config?.defaultSymbol}}))}catch{}this.processing=!0;try{if(this.config.useOwnWallet){if(!this.config.actorProvider){this.pendingAction="order",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0}));return}}else if(!this.walletConnected){ie(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{Le||(Le=(await import("./wallet-select-5SAMV2XC.js")).PNP);let l=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab)?W({...this.config?.plugNPlay||{}}):{...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:c}=await import("./origin-44ZEXSX4.js");l.derivationOrigin=this.config?.derivationOrigin||c()}}catch{}this.pnp=new Le(l);try{let c=await Q(this.pnp);if(c){this.walletConnected=!0;let h=k(this.pnp,{owner:c,principal:c,connected:!0});this.config={...this.config,connectedWallet:h,actorProvider:($,A)=>this.pnp.getActor({canisterId:$,idl:A,requiresSigning:!0,anon:!1})};try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"oisy"}}))}catch{}this.order();return}}catch{}let p=this.pnp.getEnabledWallets();if(ie(this.config?.debug||!1,"Available wallets",p),!p?.length)throw new Error("No wallets available");this.pendingAction="order",this.showWalletModal=!0;return}catch(a){ie(this.config?.debug||!1,"Wallet connection error:",a),this.errorMessage=a instanceof Error?a.message:"Wallet connection failed",this.errorSeverity="error";return}}ie(this.config?.debug||!1,"Creating SDK for payment");let e=g(this.config),t=this.selectedSymbol||this.config?.defaultSymbol||"ICP",s=this.cryptoOptions.find(a=>a.symbol===t).canisterId||await e.client.getLedgerCanisterIdBySymbol(t);ie(this.config?.debug||!1,"Coffee order payment details",{item:this.selectedItem.name,priceUsd:this.selectedItem.priceUsd,selectedSymbol:t,canisterId:s});let o=await e.sendUsd(this.selectedItem.priceUsd,s,{context:"coffee",item:this.selectedItem.name});ie(this.config?.debug||!1,"Coffee order payment completed",{resp:o}),this.config.onSuccess&&this.config.onSuccess({id:o.transactionId,status:o.status,item:this.selectedItem.name}),this.dispatchEvent(new CustomEvent("icpay-coffee",{detail:{item:this.selectedItem,tx:o},bubbles:!0}))}catch(e){U(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),B(t)&&(this.errorMessage=R(t),this.errorSeverity=z(t),this.errorAction=D(t))}});try{!this.config.useOwnWallet&&this.pnp&&(await this.pnp.disconnect?.(),this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0})}catch{}}finally{this.processing=!1}}}attachTransakMessageListener(){if(!this.transakMessageHandlerBound){this.transakMessageHandlerBound=e=>this.onTransakMessage(e);try{window.addEventListener("message",this.transakMessageHandlerBound)}catch{}}}detachTransakMessageListener(){if(this.transakMessageHandlerBound){try{window.removeEventListener("message",this.transakMessageHandlerBound)}catch{}this.transakMessageHandlerBound=null}}onTransakMessage(e){let t=e?.data,i=t?.event_id||t?.eventId||t?.id;if(!(!i||typeof i!="string")&&i==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let s=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(s||void 0)}}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1,setTimeout(()=>this.createOnrampIntent(),0)}async createOnrampIntent(){try{let e=g(this.config),t=this.selectedSymbol||this.config?.defaultSymbol||"ICP",s=this.cryptoOptions.find(c=>c.symbol===t).canisterId||await e.client.getLedgerCanisterIdBySymbol(t),o=await e.startOnrampUsd(this.selectedItem.priceUsd,s,{context:"coffee:onramp",item:this.selectedItem.name}),a=o?.metadata?.onramp?.sessionId||o?.metadata?.onramp?.session_id||null,l=o?.metadata?.paymentIntentId||o?.paymentIntentId||null,p=o?.metadata?.onramp?.errorMessage||null;this.onrampPaymentIntentId=l,a?(this.onrampSessionId=a,this.onrampErrorMessage=null,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.onrampErrorMessage=p||"Failed to obtain onramp sessionId",this.showOnrampModal=!0)}catch(e){this.onrampSessionId=null,this.onrampErrorMessage=e?.message||"Failed to obtain onramp sessionId",this.showOnrampModal=!0}}startOnrampPolling(e){if(this.onrampPollTimer){try{clearInterval(this.onrampPollTimer)}catch{}this.onrampPollTimer=null}if(this.onrampNotifyController){try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null}let t=this.onrampPaymentIntentId;if(!t)return;let i=g(this.config),s=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>s()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=i.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");this.lastWalletId=(e||"").toLowerCase(),this.pnp.connect(e).then(i=>{if(!!!(i&&(i.connected===!0||i.principal||i.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}let o=k(this.pnp,i);if(this.config={...this.config,connectedWallet:o,actorProvider:(l,p)=>this.pnp.getActor({canisterId:l,idl:p,requiresSigning:!0,anon:!1})},this.lastWalletId==="oisy")this.oisyReadyToPay=!0;else{this.showWalletModal=!1;let l=this.pendingAction;this.pendingAction=null,l==="order"&&setTimeout(()=>this.order(),0)}}).catch(i=>{this.errorMessage=i instanceof Error?i.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1})}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}render(){return this.config?me`
|
|
1235
|
+
`],n([ke({type:Object})],m.prototype,"config",2),n([ke({type:String})],m.prototype,"title",2),n([ke({type:String})],m.prototype,"preview",2),n([ke({type:String})],m.prototype,"lockedContent",2),n([T()],m.prototype,"selectedSymbol",2),n([T()],m.prototype,"unlocked",2),n([T()],m.prototype,"succeeded",2),n([T()],m.prototype,"processing",2),n([T()],m.prototype,"availableLedgers",2),n([T()],m.prototype,"errorMessage",2),n([T()],m.prototype,"errorSeverity",2),n([T()],m.prototype,"errorAction",2),n([T()],m.prototype,"walletConnected",2),n([T()],m.prototype,"pendingAction",2),n([T()],m.prototype,"showWalletModal",2),n([T()],m.prototype,"oisyReadyToPay",2),n([T()],m.prototype,"lastWalletId",2),n([T()],m.prototype,"showOnrampModal",2),n([T()],m.prototype,"onrampSessionId",2),n([T()],m.prototype,"onrampPaymentIntentId",2),n([T()],m.prototype,"onrampErrorMessage",2),m=n([dt("icpay-article-paywall")],m);import{LitElement as pt,html as me,css as ht}from"lit";import{customElement as gt,property as ut,state as N}from"lit/decorators.js";var We=typeof window<"u",Le=null;function ie(r,d,e){r&&(e!==void 0?console.log(`[ICPay Widget] ${d}`,e):console.log(`[ICPay Widget] ${d}`))}var E=class extends pt{constructor(){super(...arguments);this.selectedIndex=0;this.selectedSymbol=null;this.processing=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.showOnrampModal=!1;this.onrampSessionId=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.transakMessageHandlerBound=null;this.onrampPollTimer=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="order",this.showWalletModal=!0,this.requestUpdate();try{let t=Number(this.selectedItem?.priceUsd||0),i=this.selectedSymbol||this.config?.defaultSymbol;window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"order",type:"sendUsd",amount:t,currency:i}}))}catch{}}catch{}}}get cryptoOptions(){return this.config.cryptoOptions?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){if(super.connectedCallback(),!!We){ie(this.config?.debug||!1,"Coffee shop connected",{config:this.config}),this.config&&typeof this.config.defaultItemIndex=="number"&&(this.selectedIndex=this.config.defaultItemIndex),this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers();try{window.addEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}}}updated(e){if(e.has("config")&&this.pendingAction&&this.config?.actorProvider){let t=this.pendingAction;this.pendingAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}setTimeout(()=>{t==="order"&&this.order()},0)}}async loadVerifiedLedgers(){if(!(!We||!this.config?.publishableKey))try{let t=await g(this.config).client.getVerifiedLedgers();this.availableLedgers=t.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||this.availableLedgers[0]?.symbol||"ICP")}catch(e){console.warn("Failed to load verified ledgers:",e),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||"ICP")}}selectItem(e){this.selectedIndex=e}selectSymbol(e){this.selectedSymbol=e}get selectedItem(){return this.config?.items?.[this.selectedIndex]||{name:"Loading...",priceUsd:0}}async order(){if(We&&!this.processing){ie(this.config?.debug||!1,"Coffee order started",{selectedItem:this.selectedItem,selectedSymbol:this.selectedSymbol,useOwnWallet:this.config.useOwnWallet}),this.errorMessage=null,this.errorSeverity=null,this.errorAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"order",type:"sendUsd",amount:this.selectedItem.priceUsd,currency:this.selectedSymbol||this.config?.defaultSymbol}}))}catch{}this.processing=!0;try{if(this.config.useOwnWallet){if(!this.config.actorProvider){this.pendingAction="order",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0}));return}}else if(!this.walletConnected){ie(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{Le||(Le=(await import("./wallet-select-F6BSMPEE.js")).WalletSelect);let l=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab)?W({...this.config?.plugNPlay||{}}):{...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:c}=await import("./origin-44ZEXSX4.js");l.derivationOrigin=this.config?.derivationOrigin||c()}}catch{}this.pnp=new Le(l);try{let c=await Q(this.pnp);if(c){this.walletConnected=!0;let h=k(this.pnp,{owner:c,principal:c,connected:!0});this.config={...this.config,connectedWallet:h,actorProvider:($,A)=>this.pnp.getActor({canisterId:$,idl:A,requiresSigning:!0,anon:!1})};try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"oisy"}}))}catch{}this.order();return}}catch{}let p=this.pnp.getEnabledWallets();if(ie(this.config?.debug||!1,"Available wallets",p),!p?.length)throw new Error("No wallets available");this.pendingAction="order",this.showWalletModal=!0;return}catch(a){ie(this.config?.debug||!1,"Wallet connection error:",a),this.errorMessage=a instanceof Error?a.message:"Wallet connection failed",this.errorSeverity="error";return}}ie(this.config?.debug||!1,"Creating SDK for payment");let e=g(this.config),t=this.selectedSymbol||this.config?.defaultSymbol||"ICP",s=this.cryptoOptions.find(a=>a.symbol===t).canisterId||await e.client.getLedgerCanisterIdBySymbol(t);ie(this.config?.debug||!1,"Coffee order payment details",{item:this.selectedItem.name,priceUsd:this.selectedItem.priceUsd,selectedSymbol:t,canisterId:s});let o=await e.sendUsd(this.selectedItem.priceUsd,s,{context:"coffee",item:this.selectedItem.name});ie(this.config?.debug||!1,"Coffee order payment completed",{resp:o}),this.config.onSuccess&&this.config.onSuccess({id:o.transactionId,status:o.status,item:this.selectedItem.name}),this.dispatchEvent(new CustomEvent("icpay-coffee",{detail:{item:this.selectedItem,tx:o},bubbles:!0}))}catch(e){U(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),B(t)&&(this.errorMessage=R(t),this.errorSeverity=z(t),this.errorAction=D(t))}});try{!this.config.useOwnWallet&&this.pnp&&(await this.pnp.disconnect?.(),this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0})}catch{}}finally{this.processing=!1}}}attachTransakMessageListener(){if(!this.transakMessageHandlerBound){this.transakMessageHandlerBound=e=>this.onTransakMessage(e);try{window.addEventListener("message",this.transakMessageHandlerBound)}catch{}}}detachTransakMessageListener(){if(this.transakMessageHandlerBound){try{window.removeEventListener("message",this.transakMessageHandlerBound)}catch{}this.transakMessageHandlerBound=null}}onTransakMessage(e){let t=e?.data,i=t?.event_id||t?.eventId||t?.id;if(!(!i||typeof i!="string")&&i==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let s=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(s||void 0)}}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1,setTimeout(()=>this.createOnrampIntent(),0)}async createOnrampIntent(){try{let e=g(this.config),t=this.selectedSymbol||this.config?.defaultSymbol||"ICP",s=this.cryptoOptions.find(c=>c.symbol===t).canisterId||await e.client.getLedgerCanisterIdBySymbol(t),o=await e.startOnrampUsd(this.selectedItem.priceUsd,s,{context:"coffee:onramp",item:this.selectedItem.name}),a=o?.metadata?.onramp?.sessionId||o?.metadata?.onramp?.session_id||null,l=o?.metadata?.paymentIntentId||o?.paymentIntentId||null,p=o?.metadata?.onramp?.errorMessage||null;this.onrampPaymentIntentId=l,a?(this.onrampSessionId=a,this.onrampErrorMessage=null,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.onrampErrorMessage=p||"Failed to obtain onramp sessionId",this.showOnrampModal=!0)}catch(e){this.onrampSessionId=null,this.onrampErrorMessage=e?.message||"Failed to obtain onramp sessionId",this.showOnrampModal=!0}}startOnrampPolling(e){if(this.onrampPollTimer){try{clearInterval(this.onrampPollTimer)}catch{}this.onrampPollTimer=null}if(this.onrampNotifyController){try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null}let t=this.onrampPaymentIntentId;if(!t)return;let i=g(this.config),s=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>s()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=i.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");this.lastWalletId=(e||"").toLowerCase(),this.pnp.connect(e).then(i=>{if(!!!(i&&(i.connected===!0||i.principal||i.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}let o=k(this.pnp,i);if(this.config={...this.config,connectedWallet:o,actorProvider:(l,p)=>this.pnp.getActor({canisterId:l,idl:p,requiresSigning:!0,anon:!1})},this.lastWalletId==="oisy")this.oisyReadyToPay=!0;else{this.showWalletModal=!1;let l=this.pendingAction;this.pendingAction=null,l==="order"&&setTimeout(()=>this.order(),0)}}).catch(i=>{this.errorMessage=i instanceof Error?i.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1})}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}render(){return this.config?me`
|
|
1236
1236
|
<div class="icpay-card icpay-section icpay-widget-base">
|
|
1237
1237
|
${this.config?.progressBar?.enabled!==!1?me`
|
|
1238
1238
|
<icpay-progress-bar
|
|
@@ -1312,7 +1312,7 @@ import{a as n}from"./chunk-LTEQ7OUJ.js";import{css as _e}from"lit";var K=_e`
|
|
|
1312
1312
|
border-color: rgba(239, 68, 68, 0.3);
|
|
1313
1313
|
color: #ef4444;
|
|
1314
1314
|
}
|
|
1315
|
-
`],n([ut({type:Object})],E.prototype,"config",2),n([N()],E.prototype,"selectedIndex",2),n([N()],E.prototype,"selectedSymbol",2),n([N()],E.prototype,"processing",2),n([N()],E.prototype,"availableLedgers",2),n([N()],E.prototype,"errorMessage",2),n([N()],E.prototype,"errorSeverity",2),n([N()],E.prototype,"errorAction",2),n([N()],E.prototype,"walletConnected",2),n([N()],E.prototype,"pendingAction",2),n([N()],E.prototype,"showWalletModal",2),n([N()],E.prototype,"oisyReadyToPay",2),n([N()],E.prototype,"lastWalletId",2),n([N()],E.prototype,"showOnrampModal",2),n([N()],E.prototype,"onrampSessionId",2),n([N()],E.prototype,"onrampPaymentIntentId",2),n([N()],E.prototype,"onrampErrorMessage",2),E=n([gt("icpay-coffee-shop")],E);import{LitElement as yt,html as fe,css as mt}from"lit";import{customElement as ft,property as bt,state as C}from"lit/decorators.js";var Te=typeof window<"u",be=null;function ne(r,d,e){r&&(e!==void 0?console.log(`[ICPay Widget] ${d}`,e):console.log(`[ICPay Widget] ${d}`))}var b=class extends yt{constructor(){super(...arguments);this.selectedAmount=10;this.selectedSymbol=null;this.raised=0;this.processing=!1;this.succeeded=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.showOnrampModal=!1;this.onrampSessionId=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.transakMessageHandlerBound=null;this.onrampPollTimer=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="donate",this.showWalletModal=!0,this.requestUpdate();try{let t=Number(this.selectedAmount||0),i=this.selectedSymbol||this.config?.defaultSymbol;window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"donate",type:"sendUsd",amount:t,currency:i}}))}catch{}}catch{}}}async tryAutoConnectPNP(){try{if(!this.config||this.config?.useOwnWallet)return;let e=localStorage.getItem("icpay:pnp");if(!e)return;let t=JSON.parse(e);if(!t?.provider||!t?.principal)return;be||(be=(await import("./wallet-select-5SAMV2XC.js")).PNP);let i=W({...this.config?.plugNPlay||{}});try{if(typeof window<"u"){let{resolveDerivationOrigin:o}=await import("./origin-44ZEXSX4.js");i.derivationOrigin=this.config?.derivationOrigin||o()}}catch{}let s=new be(i);this.walletConnected=!1,this.config={...this.config,connectedWallet:{owner:t.principal,principal:t.principal,connected:!1}}}catch{}}get amounts(){return this.config?.amountsUsd||[10,25,50,100,250,500]}get cryptoOptions(){return this.config.cryptoOptions?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){if(super.connectedCallback(),!!Te){ne(this.config?.debug||!1,"Donation thermometer connected",{config:this.config}),this.config&&typeof this.config.defaultAmountUsd=="number"&&(this.selectedAmount=this.config.defaultAmountUsd),this.tryAutoConnectPNP();try{window.addEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers()}}updated(e){if(e.has("config")&&this.pendingAction&&this.config?.actorProvider){let t=this.pendingAction;this.pendingAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}setTimeout(()=>{t==="donate"&&this.donate()},0)}}async loadVerifiedLedgers(){if(!(!Te||!this.config?.publishableKey))try{let t=await g(this.config).client.getVerifiedLedgers();this.availableLedgers=t.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||this.availableLedgers[0]?.symbol||"ICP")}catch(e){console.warn("Failed to load verified ledgers:",e),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||"ICP")}}selectAmount(e){this.selectedAmount=e}selectSymbol(e){this.selectedSymbol=e}get fillPercentage(){let e=Number(this.config?.goalUsd??1e3),t=e>0?e:1e3;return Math.min(this.raised/t*100,100)}async donate(){if(Te&&!this.processing){ne(this.config?.debug||!1,"Donation started",{amount:this.selectedAmount,selectedSymbol:this.selectedSymbol,useOwnWallet:this.config.useOwnWallet}),this.errorMessage=null,this.errorSeverity=null,this.errorAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"donate",type:"sendUsd",amount:this.selectedAmount,currency:this.selectedSymbol||this.config?.defaultSymbol}}))}catch{}this.processing=!0;try{if(this.config.useOwnWallet){if(!this.config.actorProvider){this.pendingAction="donate",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0}));return}}else if(!this.walletConnected){ne(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{be||(be=(await import("./wallet-select-5SAMV2XC.js")).PNP);let l=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab)?W({...this.config?.plugNPlay||{}}):{...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:c}=await import("./origin-44ZEXSX4.js");l.derivationOrigin=this.config?.derivationOrigin||c()}}catch{}this.pnp=new be(l);try{let c=await Q(this.pnp);if(c){this.walletConnected=!0;let h=k(this.pnp,{owner:c,principal:c,connected:!0});this.config={...this.config,connectedWallet:h,actorProvider:($,A)=>this.pnp.getActor({canisterId:$,idl:A,requiresSigning:!0,anon:!1})};try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"oisy"}}))}catch{}this.donate();return}}catch{}let p=this.pnp.getEnabledWallets();if(ne(this.config?.debug||!1,"Available wallets",p),!p?.length)throw new Error("No wallets available");this.pendingAction="donate",this.showWalletModal=!0;return}catch(a){ne(this.config?.debug||!1,"Wallet connection error:",a),this.errorMessage=a instanceof Error?a.message:"Wallet connection failed",this.errorSeverity="error";return}}ne(this.config?.debug||!1,"Creating SDK for payment");let e=g(this.config),t=this.selectedSymbol||this.config?.defaultSymbol||"ICP",s=this.cryptoOptions.find(a=>a.symbol===t).canisterId||await e.client.getLedgerCanisterIdBySymbol(t);ne(this.config?.debug||!1,"Donation payment details",{amount:this.selectedAmount,selectedSymbol:t,canisterId:s});let o=await e.sendUsd(this.selectedAmount,s,{context:"donation"});ne(this.config?.debug||!1,"Donation payment completed",{resp:o}),this.raised+=this.selectedAmount,this.succeeded=!0,this.config.onSuccess&&this.config.onSuccess({id:o.transactionId,status:o.status,raised:this.raised}),this.dispatchEvent(new CustomEvent("icpay-donation",{detail:{amount:this.selectedAmount,tx:o},bubbles:!0}))}catch(e){U(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),B(t)&&(this.errorMessage=R(t),this.errorSeverity=z(t),this.errorAction=D(t))}});try{!this.config.useOwnWallet&&this.pnp&&(await this.pnp.disconnect?.(),this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0})}catch{}}finally{this.processing=!1}}}attachTransakMessageListener(){if(!this.transakMessageHandlerBound){this.transakMessageHandlerBound=e=>this.onTransakMessage(e);try{window.addEventListener("message",this.transakMessageHandlerBound)}catch{}}}detachTransakMessageListener(){if(this.transakMessageHandlerBound){try{window.removeEventListener("message",this.transakMessageHandlerBound)}catch{}this.transakMessageHandlerBound=null}}onTransakMessage(e){let t=e?.data,i=t?.event_id||t?.eventId||t?.id;if(!(!i||typeof i!="string")&&i==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let s=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(s||void 0)}}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1,setTimeout(()=>this.createOnrampIntent(),0)}async createOnrampIntent(){try{let e=g(this.config),t=this.selectedSymbol||this.config?.defaultSymbol||"ICP",s=this.cryptoOptions.find(c=>c.symbol===t).canisterId||await e.client.getLedgerCanisterIdBySymbol(t),o=await e.startOnrampUsd(this.selectedAmount,s,{context:"donation:onramp"}),a=o?.metadata?.onramp?.sessionId||o?.metadata?.onramp?.session_id||null,l=o?.metadata?.paymentIntentId||o?.paymentIntentId||null,p=o?.metadata?.onramp?.errorMessage||null;this.onrampPaymentIntentId=l,a?(this.onrampSessionId=a,this.onrampErrorMessage=null,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.onrampErrorMessage=p||"Failed to obtain onramp sessionId",this.showOnrampModal=!0)}catch(e){this.onrampSessionId=null,this.onrampErrorMessage=e?.message||"Failed to obtain onramp sessionId",this.showOnrampModal=!0}}startOnrampPolling(e){if(this.onrampPollTimer){try{clearInterval(this.onrampPollTimer)}catch{}this.onrampPollTimer=null}if(this.onrampNotifyController){try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null}let t=this.onrampPaymentIntentId;if(!t)return;let i=g(this.config),s=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>s()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=i.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");this.lastWalletId=(e||"").toLowerCase(),this.pnp.connect(e).then(i=>{if(!!!(i&&(i.connected===!0||i.principal||i.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}let o=k(this.pnp,i);if(this.config={...this.config,connectedWallet:o,actorProvider:(l,p)=>this.pnp.getActor({canisterId:l,idl:p,requiresSigning:!0,anon:!1})},this.lastWalletId==="oisy")this.oisyReadyToPay=!0;else{this.showWalletModal=!1;let l=this.pendingAction;this.pendingAction=null,l==="donate"&&setTimeout(()=>this.donate(),0)}}).catch(i=>{this.errorMessage=i instanceof Error?i.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1})}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}render(){return this.config?fe`
|
|
1315
|
+
`],n([ut({type:Object})],E.prototype,"config",2),n([N()],E.prototype,"selectedIndex",2),n([N()],E.prototype,"selectedSymbol",2),n([N()],E.prototype,"processing",2),n([N()],E.prototype,"availableLedgers",2),n([N()],E.prototype,"errorMessage",2),n([N()],E.prototype,"errorSeverity",2),n([N()],E.prototype,"errorAction",2),n([N()],E.prototype,"walletConnected",2),n([N()],E.prototype,"pendingAction",2),n([N()],E.prototype,"showWalletModal",2),n([N()],E.prototype,"oisyReadyToPay",2),n([N()],E.prototype,"lastWalletId",2),n([N()],E.prototype,"showOnrampModal",2),n([N()],E.prototype,"onrampSessionId",2),n([N()],E.prototype,"onrampPaymentIntentId",2),n([N()],E.prototype,"onrampErrorMessage",2),E=n([gt("icpay-coffee-shop")],E);import{LitElement as yt,html as fe,css as mt}from"lit";import{customElement as ft,property as bt,state as C}from"lit/decorators.js";var Te=typeof window<"u",be=null;function ne(r,d,e){r&&(e!==void 0?console.log(`[ICPay Widget] ${d}`,e):console.log(`[ICPay Widget] ${d}`))}var b=class extends yt{constructor(){super(...arguments);this.selectedAmount=10;this.selectedSymbol=null;this.raised=0;this.processing=!1;this.succeeded=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.showOnrampModal=!1;this.onrampSessionId=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.transakMessageHandlerBound=null;this.onrampPollTimer=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="donate",this.showWalletModal=!0,this.requestUpdate();try{let t=Number(this.selectedAmount||0),i=this.selectedSymbol||this.config?.defaultSymbol;window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"donate",type:"sendUsd",amount:t,currency:i}}))}catch{}}catch{}}}async tryAutoConnectPNP(){try{if(!this.config||this.config?.useOwnWallet)return;let e=localStorage.getItem("icpay:pnp");if(!e)return;let t=JSON.parse(e);if(!t?.provider||!t?.principal)return;be||(be=(await import("./wallet-select-F6BSMPEE.js")).WalletSelect);let i=W({...this.config?.plugNPlay||{}});try{if(typeof window<"u"){let{resolveDerivationOrigin:o}=await import("./origin-44ZEXSX4.js");i.derivationOrigin=this.config?.derivationOrigin||o()}}catch{}let s=new be(i);this.walletConnected=!1,this.config={...this.config,connectedWallet:{owner:t.principal,principal:t.principal,connected:!1}}}catch{}}get amounts(){return this.config?.amountsUsd||[10,25,50,100,250,500]}get cryptoOptions(){return this.config.cryptoOptions?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){if(super.connectedCallback(),!!Te){ne(this.config?.debug||!1,"Donation thermometer connected",{config:this.config}),this.config&&typeof this.config.defaultAmountUsd=="number"&&(this.selectedAmount=this.config.defaultAmountUsd),this.tryAutoConnectPNP();try{window.addEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers()}}updated(e){if(e.has("config")&&this.pendingAction&&this.config?.actorProvider){let t=this.pendingAction;this.pendingAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}setTimeout(()=>{t==="donate"&&this.donate()},0)}}async loadVerifiedLedgers(){if(!(!Te||!this.config?.publishableKey))try{let t=await g(this.config).client.getVerifiedLedgers();this.availableLedgers=t.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||this.availableLedgers[0]?.symbol||"ICP")}catch(e){console.warn("Failed to load verified ledgers:",e),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||"ICP")}}selectAmount(e){this.selectedAmount=e}selectSymbol(e){this.selectedSymbol=e}get fillPercentage(){let e=Number(this.config?.goalUsd??1e3),t=e>0?e:1e3;return Math.min(this.raised/t*100,100)}async donate(){if(Te&&!this.processing){ne(this.config?.debug||!1,"Donation started",{amount:this.selectedAmount,selectedSymbol:this.selectedSymbol,useOwnWallet:this.config.useOwnWallet}),this.errorMessage=null,this.errorSeverity=null,this.errorAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"donate",type:"sendUsd",amount:this.selectedAmount,currency:this.selectedSymbol||this.config?.defaultSymbol}}))}catch{}this.processing=!0;try{if(this.config.useOwnWallet){if(!this.config.actorProvider){this.pendingAction="donate",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0}));return}}else if(!this.walletConnected){ne(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{be||(be=(await import("./wallet-select-F6BSMPEE.js")).WalletSelect);let l=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab)?W({...this.config?.plugNPlay||{}}):{...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:c}=await import("./origin-44ZEXSX4.js");l.derivationOrigin=this.config?.derivationOrigin||c()}}catch{}this.pnp=new be(l);try{let c=await Q(this.pnp);if(c){this.walletConnected=!0;let h=k(this.pnp,{owner:c,principal:c,connected:!0});this.config={...this.config,connectedWallet:h,actorProvider:($,A)=>this.pnp.getActor({canisterId:$,idl:A,requiresSigning:!0,anon:!1})};try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"oisy"}}))}catch{}this.donate();return}}catch{}let p=this.pnp.getEnabledWallets();if(ne(this.config?.debug||!1,"Available wallets",p),!p?.length)throw new Error("No wallets available");this.pendingAction="donate",this.showWalletModal=!0;return}catch(a){ne(this.config?.debug||!1,"Wallet connection error:",a),this.errorMessage=a instanceof Error?a.message:"Wallet connection failed",this.errorSeverity="error";return}}ne(this.config?.debug||!1,"Creating SDK for payment");let e=g(this.config),t=this.selectedSymbol||this.config?.defaultSymbol||"ICP",s=this.cryptoOptions.find(a=>a.symbol===t).canisterId||await e.client.getLedgerCanisterIdBySymbol(t);ne(this.config?.debug||!1,"Donation payment details",{amount:this.selectedAmount,selectedSymbol:t,canisterId:s});let o=await e.sendUsd(this.selectedAmount,s,{context:"donation"});ne(this.config?.debug||!1,"Donation payment completed",{resp:o}),this.raised+=this.selectedAmount,this.succeeded=!0,this.config.onSuccess&&this.config.onSuccess({id:o.transactionId,status:o.status,raised:this.raised}),this.dispatchEvent(new CustomEvent("icpay-donation",{detail:{amount:this.selectedAmount,tx:o},bubbles:!0}))}catch(e){U(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),B(t)&&(this.errorMessage=R(t),this.errorSeverity=z(t),this.errorAction=D(t))}});try{!this.config.useOwnWallet&&this.pnp&&(await this.pnp.disconnect?.(),this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0})}catch{}}finally{this.processing=!1}}}attachTransakMessageListener(){if(!this.transakMessageHandlerBound){this.transakMessageHandlerBound=e=>this.onTransakMessage(e);try{window.addEventListener("message",this.transakMessageHandlerBound)}catch{}}}detachTransakMessageListener(){if(this.transakMessageHandlerBound){try{window.removeEventListener("message",this.transakMessageHandlerBound)}catch{}this.transakMessageHandlerBound=null}}onTransakMessage(e){let t=e?.data,i=t?.event_id||t?.eventId||t?.id;if(!(!i||typeof i!="string")&&i==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let s=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(s||void 0)}}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1,setTimeout(()=>this.createOnrampIntent(),0)}async createOnrampIntent(){try{let e=g(this.config),t=this.selectedSymbol||this.config?.defaultSymbol||"ICP",s=this.cryptoOptions.find(c=>c.symbol===t).canisterId||await e.client.getLedgerCanisterIdBySymbol(t),o=await e.startOnrampUsd(this.selectedAmount,s,{context:"donation:onramp"}),a=o?.metadata?.onramp?.sessionId||o?.metadata?.onramp?.session_id||null,l=o?.metadata?.paymentIntentId||o?.paymentIntentId||null,p=o?.metadata?.onramp?.errorMessage||null;this.onrampPaymentIntentId=l,a?(this.onrampSessionId=a,this.onrampErrorMessage=null,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.onrampErrorMessage=p||"Failed to obtain onramp sessionId",this.showOnrampModal=!0)}catch(e){this.onrampSessionId=null,this.onrampErrorMessage=e?.message||"Failed to obtain onramp sessionId",this.showOnrampModal=!0}}startOnrampPolling(e){if(this.onrampPollTimer){try{clearInterval(this.onrampPollTimer)}catch{}this.onrampPollTimer=null}if(this.onrampNotifyController){try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null}let t=this.onrampPaymentIntentId;if(!t)return;let i=g(this.config),s=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>s()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=i.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");this.lastWalletId=(e||"").toLowerCase(),this.pnp.connect(e).then(i=>{if(!!!(i&&(i.connected===!0||i.principal||i.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}let o=k(this.pnp,i);if(this.config={...this.config,connectedWallet:o,actorProvider:(l,p)=>this.pnp.getActor({canisterId:l,idl:p,requiresSigning:!0,anon:!1})},this.lastWalletId==="oisy")this.oisyReadyToPay=!0;else{this.showWalletModal=!1;let l=this.pendingAction;this.pendingAction=null,l==="donate"&&setTimeout(()=>this.donate(),0)}}).catch(i=>{this.errorMessage=i instanceof Error?i.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1})}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}render(){return this.config?fe`
|
|
1316
1316
|
<div class="icpay-card icpay-section icpay-widget-base" style="text-align:center;">
|
|
1317
1317
|
${this.config?.progressBar?.enabled!==!1?fe`
|
|
1318
1318
|
<icpay-progress-bar
|
|
@@ -1391,7 +1391,7 @@ import{a as n}from"./chunk-LTEQ7OUJ.js";import{css as _e}from"lit";var K=_e`
|
|
|
1391
1391
|
border-color: rgba(239, 68, 68, 0.3);
|
|
1392
1392
|
color: #ef4444;
|
|
1393
1393
|
}
|
|
1394
|
-
`],n([bt({type:Object})],b.prototype,"config",2),n([C()],b.prototype,"selectedAmount",2),n([C()],b.prototype,"selectedSymbol",2),n([C()],b.prototype,"raised",2),n([C()],b.prototype,"processing",2),n([C()],b.prototype,"succeeded",2),n([C()],b.prototype,"availableLedgers",2),n([C()],b.prototype,"errorMessage",2),n([C()],b.prototype,"errorSeverity",2),n([C()],b.prototype,"errorAction",2),n([C()],b.prototype,"walletConnected",2),n([C()],b.prototype,"pendingAction",2),n([C()],b.prototype,"showWalletModal",2),n([C()],b.prototype,"oisyReadyToPay",2),n([C()],b.prototype,"lastWalletId",2),n([C()],b.prototype,"showOnrampModal",2),n([C()],b.prototype,"onrampSessionId",2),n([C()],b.prototype,"onrampPaymentIntentId",2),n([C()],b.prototype,"onrampErrorMessage",2),b=n([ft("icpay-donation-thermometer")],b);import{LitElement as vt,html as ve,css as wt}from"lit";import{customElement as xt,property as St,state as O}from"lit/decorators.js";var $e=typeof window<"u",we=null;function q(r,d,e){r&&(e!==void 0?console.log(`[ICPay Widget] ${d}`,e):console.log(`[ICPay Widget] ${d}`))}var v=class extends vt{constructor(){super(...arguments);this.selectedSymbol=null;this.processing=!1;this.succeeded=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.showOnrampModal=!1;this.onrampSessionId=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.oisyReadyToPay=!1;this.oisySignerPreopened=!1;this.skipDisconnectOnce=!1;this.lastWalletId=null;this.onrampPollTimer=null;this.transakMessageHandlerBound=null;this.pnp=null;this.oisyConnectRetriedNewTab=!1;this.sdk=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="pay",this.showWalletModal=!0,this.requestUpdate();try{let t=Number(this.config?.amountUsd||0),i=this.selectedSymbol||this.config?.defaultSymbol;window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"pay",type:"sendUsd",amount:t,currency:i}}))}catch{}}catch{}}}getSdk(){return this.sdk||(this.sdk=g(this.config)),this.sdk}get cryptoOptions(){return this.config?.cryptoOptions?.length?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){if(super.connectedCallback(),!!$e){q(this.config?.debug||!1,"Pay button connected",{config:this.config}),this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers(),this.config?.defaultSymbol&&(this.selectedSymbol=this.config.defaultSymbol);try{window.addEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}try{window.addEventListener("icpay-sdk-transaction-created",(e=>{q(this.config?.debug||!1,"SDK transaction created",{detail:e?.detail})}))}catch{}}}updated(e){if(e.has("config")&&this.pendingAction&&this.config?.actorProvider){let t=this.pendingAction;this.pendingAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}setTimeout(()=>{t==="pay"&&this.pay()},0)}e.has("config")&&(this.sdk=null,!this.selectedSymbol&&this.config?.defaultSymbol&&(this.selectedSymbol=this.config.defaultSymbol))}async loadVerifiedLedgers(){if(!(!$e||!this.config?.publishableKey))try{let t=await this.getSdk().client.getVerifiedLedgers();this.availableLedgers=t.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||(this.availableLedgers[0]?.symbol??"ICP"))}catch(e){this.dispatchEvent(new CustomEvent("icpay-error",{detail:{message:"Failed to load verified ledgers",cause:e},bubbles:!0})),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||"ICP")}}selectSymbol(e){this.selectedSymbol=e}async ensureWallet(){if(this.config.useOwnWallet)return this.config.actorProvider?!0:(this.pendingAction="pay",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0})),!1);if(this.walletConnected)return!0;try{we||(we=(await import("./wallet-select-5SAMV2XC.js")).PNP);let e=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab),t={...this.config?.plugNPlay||{}},i=e?W(t):t;try{if(typeof window<"u"){let{resolveDerivationOrigin:o}=await import("./origin-44ZEXSX4.js");i.derivationOrigin=this.config?.derivationOrigin||o()}}catch{}this.pnp=new we(i);let s=this.pnp.getEnabledWallets();if(q(this.config?.debug||!1,"Available wallets",s),!s?.length)throw new Error("No wallets available");return this.pendingAction="pay",this.showWalletModal=!0,!1}catch(e){return this.errorMessage=e instanceof Error?e.message:"Wallet connection failed",this.errorSeverity="error",!1}}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");this.lastWalletId=(e||"").toLowerCase(),this.lastWalletId==="oisy"&&(this.oisyConnectRetriedNewTab=!1),this.pnp.connect(e).then(i=>{if(q(this.config?.debug||!1,"Wallet connect result",i),!!!(i&&(i.connected===!0||i.principal||i.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}let o=k(this.pnp,i);if(this.config={...this.config,connectedWallet:o,actorProvider:(l,p)=>this.pnp.getActor({canisterId:l,idl:p,requiresSigning:!0,anon:!1})},(e||"").toLowerCase()==="oisy")this.oisyReadyToPay=!0,this.pendingAction=null;else{this.showWalletModal=!1;let l=this.pendingAction;this.pendingAction=null,l==="pay"&&(this.skipDisconnectOnce=!0,this.pay())}}).catch(i=>{q(this.config?.debug||!1,"Wallet connection error",i);let s=(e||"").toLowerCase()==="oisy",o=i&&(i.message||String(i))||"";if(s&&!this.oisyConnectRetriedNewTab&&(o.includes("Signer window could not be opened")||o.includes("Communication channel could not be established"))){this.oisyConnectRetriedNewTab=!0,(async()=>{try{we||(we=(await import("./wallet-select-5SAMV2XC.js")).PNP);let l={...this.config?.plugNPlay||{}},p=W(l);try{if(typeof window<"u"){let{resolveDerivationOrigin:h}=await import("./origin-44ZEXSX4.js");p.derivationOrigin=this.config?.derivationOrigin||h()}}catch{}this.pnp=new we(p),this.pnp.connect("oisy").then(h=>{if(!!!(h&&(h.connected===!0||h.principal||h.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"oisy"}}))}catch{}let A=k(this.pnp,h);this.config={...this.config,connectedWallet:A,actorProvider:(se,P)=>this.pnp.getActor({canisterId:se,idl:P,requiresSigning:!0,anon:!1})},this.oisyReadyToPay=!0,this.pendingAction=null}).catch(h=>{q(this.config?.debug||!1,"Oisy retry connect (new tab) failed",h),this.errorMessage=h instanceof Error?h.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1})}catch(l){q(this.config?.debug||!1,"Oisy new-tab init failed",l),this.errorMessage=l instanceof Error?l.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}})();return}this.errorMessage=i instanceof Error?i.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1})}catch(t){q(this.config?.debug||!1,"Wallet connection error (sync)",t),this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}renderWalletModal(){if(!this.showWalletModal||!this.pnp)return null;let t=(this.pnp.getEnabledWallets()||[]).map(c=>({id:this.getWalletId(c),label:this.getWalletLabel(c),icon:this.getWalletIcon(c)})),i=this.config?.onramp?.enabled!==!1&&this.config?.onrampDisabled!==!0,s=5,o=Number(this.config?.amountUsd??0),a=i&&o>0&&o<s,l=Math.max(0,s-o),p=a?`Note: Minimum card amount is $${s}. You will pay about $${l.toFixed(2)} more.`:null;return H({visible:this.showWalletModal,wallets:t,isConnecting:!1,onSelect:c=>{this.connectWithWallet(c)},onClose:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1},onCreditCard:i?()=>this.startOnramp():void 0,creditCardLabel:this.config?.onramp?.creditCardLabel||"Pay with credit card",showCreditCard:i,creditCardTooltip:p,oisyReadyToPay:this.oisyReadyToPay,onOisyPay:()=>{this.showWalletModal=!1,this.skipDisconnectOnce=!0,this.oisyReadyToPay=!1,this.pay()}})}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1,setTimeout(()=>this.createOnrampIntent(),0)}async createOnrampIntent(){try{let e=Number(this.config?.amountUsd??0),t=this.getSdk();this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||"ICP");let i=this.selectedSymbol||"ICP",o=this.cryptoOptions.find(h=>h.symbol===i)?.canisterId||await t.client.getLedgerCanisterIdBySymbol(i),a=await t.startOnrampUsd(e,o,{context:"pay-button:onramp"}),l=a?.metadata?.onramp?.sessionId||a?.metadata?.onramp?.session_id||null,p=a?.metadata?.onramp?.errorMessage||null;this.onrampErrorMessage=p||null;let c=a?.metadata?.paymentIntentId||a?.paymentIntentId||null;this.onrampPaymentIntentId=c,l?(this.onrampSessionId=l,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.showOnrampModal=!0)}catch(e){this.onrampSessionId=null,this.onrampErrorMessage=e?.message||null,this.showOnrampModal=!0,U(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),B(t)&&(this.errorMessage=R(t),this.errorSeverity=z(t),this.errorAction=D(t))}})}}attachTransakMessageListener(){if(!this.transakMessageHandlerBound){this.transakMessageHandlerBound=e=>this.onTransakMessage(e);try{window.addEventListener("message",this.transakMessageHandlerBound)}catch{}}}detachTransakMessageListener(){if(this.transakMessageHandlerBound){try{window.removeEventListener("message",this.transakMessageHandlerBound)}catch{}this.transakMessageHandlerBound=null}}onTransakMessage(e){let t=e?.data,i=t?.event_id||t?.eventId||t?.id;if(!(!i||typeof i!="string")&&i==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;let s=t?.data?.id||t?.id||t?.webhookData?.id||null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-success",{detail:{name:"getLedgerBalance"}}))}catch{}try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-success",{detail:{name:"sendFundsToLedger"}}))}catch{}try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-success",{detail:{name:"notifyLedgerTransaction"}}))}catch{}this.showOnrampModal=!1,this.startOnrampPolling(s||void 0)}}startOnrampPolling(e){if(this.onrampPollTimer){try{clearInterval(this.onrampPollTimer)}catch{}this.onrampPollTimer=null}if(this.onrampNotifyController){try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null}let t=this.onrampPaymentIntentId;if(!t)return;let i=this.getSdk(),s=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1},o=a=>{s()};try{window.addEventListener("icpay-sdk-transaction-completed",o,{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=i.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}async pay(){if(!(!$e||this.processing)){this.errorMessage=null,this.errorSeverity=null,this.errorAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"pay",type:"sendUsd",amount:this.config?.amountUsd,currency:this.selectedSymbol||this.config?.defaultSymbol}}))}catch{}this.processing=!0;try{if(this.skipDisconnectOnce)this.skipDisconnectOnce=!1;else try{!this.config.useOwnWallet&&this.pnp&&(await this.pnp.disconnect?.(),this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0})}catch{}if(!await this.ensureWallet())return;let t=this.getSdk();try{let c=this.config?.connectedWallet,h=this?.pnp?.account;q(this.config?.debug||!1,"Wallet state before payment",{connectedWallet:c,pnpAccount:h,principal:c?.owner||c?.principal||h?.owner||h?.principal||null})}catch{}this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||"ICP");let i=this.selectedSymbol||"ICP",o=this.cryptoOptions.find(c=>c.symbol===i)?.canisterId||await t.client.getLedgerCanisterIdBySymbol(i);q(this.config?.debug||!1,"Resolved ledger details",{symbol:i,canisterId:o});let a=Number(this.config?.amountUsd??0),l={context:"pay-button"};q(this.config?.debug||!1,"Calling sdk.sendUsd",{amountUsd:a,canisterId:o,meta:l});let p=await t.sendUsd(a,o,l);q(this.config?.debug||!1,"sdk.sendUsd response",p),this.config.onSuccess&&this.config.onSuccess({id:p.transactionId,status:p.status}),this.succeeded=!0,this.dispatchEvent(new CustomEvent("icpay-pay",{detail:{amount:a,tx:p},bubbles:!0}))}catch(e){q(this.config?.debug||!1,"Payment error",{message:e?.message,code:e?.code,details:e?.details,stack:e?.stack}),U(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),B(t)&&(this.errorMessage=R(t),this.errorSeverity=z(t),this.errorAction=D(t))}});try{!this.config.useOwnWallet&&this.pnp&&(await this.pnp.disconnect?.(),this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0})}catch{}}finally{this.processing=!1}}}render(){if(!this.config)return ve`<div class="icpay-card icpay-section">Loading...</div>`;let t=(this.cryptoOptions?.length||0)>1,i=this.config?.showLedgerDropdown,s=i==="dropdown"?"dropdown":i==="none"?"none":"buttons",o=s!=="none"&&(t||s==="dropdown"),a=s==="dropdown"?"dropdown":t?"buttons":"none",l=this.selectedSymbol||this.config?.defaultSymbol||"ICP",p=typeof this.config?.amountUsd=="number"?`${Number(this.config.amountUsd).toFixed(2)}`:"",h=(this.config?.buttonLabel||(typeof this.config?.amountUsd=="number"?"Pay ${amount} with {symbol}":"Pay with {symbol}")).replace("{amount}",p||"$0.00").replace("{symbol}",l),A=this.config?.progressBar?.enabled!==!1;return ve`
|
|
1394
|
+
`],n([bt({type:Object})],b.prototype,"config",2),n([C()],b.prototype,"selectedAmount",2),n([C()],b.prototype,"selectedSymbol",2),n([C()],b.prototype,"raised",2),n([C()],b.prototype,"processing",2),n([C()],b.prototype,"succeeded",2),n([C()],b.prototype,"availableLedgers",2),n([C()],b.prototype,"errorMessage",2),n([C()],b.prototype,"errorSeverity",2),n([C()],b.prototype,"errorAction",2),n([C()],b.prototype,"walletConnected",2),n([C()],b.prototype,"pendingAction",2),n([C()],b.prototype,"showWalletModal",2),n([C()],b.prototype,"oisyReadyToPay",2),n([C()],b.prototype,"lastWalletId",2),n([C()],b.prototype,"showOnrampModal",2),n([C()],b.prototype,"onrampSessionId",2),n([C()],b.prototype,"onrampPaymentIntentId",2),n([C()],b.prototype,"onrampErrorMessage",2),b=n([ft("icpay-donation-thermometer")],b);import{LitElement as vt,html as ve,css as wt}from"lit";import{customElement as xt,property as St,state as O}from"lit/decorators.js";var $e=typeof window<"u",we=null;function q(r,d,e){r&&(e!==void 0?console.log(`[ICPay Widget] ${d}`,e):console.log(`[ICPay Widget] ${d}`))}var v=class extends vt{constructor(){super(...arguments);this.selectedSymbol=null;this.processing=!1;this.succeeded=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.showOnrampModal=!1;this.onrampSessionId=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.oisyReadyToPay=!1;this.oisySignerPreopened=!1;this.skipDisconnectOnce=!1;this.lastWalletId=null;this.onrampPollTimer=null;this.transakMessageHandlerBound=null;this.pnp=null;this.oisyConnectRetriedNewTab=!1;this.sdk=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="pay",this.showWalletModal=!0,this.requestUpdate();try{let t=Number(this.config?.amountUsd||0),i=this.selectedSymbol||this.config?.defaultSymbol;window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"pay",type:"sendUsd",amount:t,currency:i}}))}catch{}}catch{}}}getSdk(){return this.sdk||(this.sdk=g(this.config)),this.sdk}get cryptoOptions(){return this.config?.cryptoOptions?.length?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){if(super.connectedCallback(),!!$e){q(this.config?.debug||!1,"Pay button connected",{config:this.config}),this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers(),this.config?.defaultSymbol&&(this.selectedSymbol=this.config.defaultSymbol);try{window.addEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}try{window.addEventListener("icpay-sdk-transaction-created",(e=>{q(this.config?.debug||!1,"SDK transaction created",{detail:e?.detail})}))}catch{}}}updated(e){if(e.has("config")&&this.pendingAction&&this.config?.actorProvider){let t=this.pendingAction;this.pendingAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}setTimeout(()=>{t==="pay"&&this.pay()},0)}e.has("config")&&(this.sdk=null,!this.selectedSymbol&&this.config?.defaultSymbol&&(this.selectedSymbol=this.config.defaultSymbol))}async loadVerifiedLedgers(){if(!(!$e||!this.config?.publishableKey))try{let t=await this.getSdk().client.getVerifiedLedgers();this.availableLedgers=t.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||(this.availableLedgers[0]?.symbol??"ICP"))}catch(e){this.dispatchEvent(new CustomEvent("icpay-error",{detail:{message:"Failed to load verified ledgers",cause:e},bubbles:!0})),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||"ICP")}}selectSymbol(e){this.selectedSymbol=e}async ensureWallet(){if(this.config.useOwnWallet)return this.config.actorProvider?!0:(this.pendingAction="pay",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0})),!1);if(this.walletConnected)return!0;try{we||(we=(await import("./wallet-select-F6BSMPEE.js")).WalletSelect);let e=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab),t={...this.config?.plugNPlay||{}},i=e?W(t):t;try{if(typeof window<"u"){let{resolveDerivationOrigin:o}=await import("./origin-44ZEXSX4.js");i.derivationOrigin=this.config?.derivationOrigin||o()}}catch{}this.pnp=new we(i);let s=this.pnp.getEnabledWallets();if(q(this.config?.debug||!1,"Available wallets",s),!s?.length)throw new Error("No wallets available");return this.pendingAction="pay",this.showWalletModal=!0,!1}catch(e){return this.errorMessage=e instanceof Error?e.message:"Wallet connection failed",this.errorSeverity="error",!1}}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");this.lastWalletId=(e||"").toLowerCase(),this.lastWalletId==="oisy"&&(this.oisyConnectRetriedNewTab=!1),this.pnp.connect(e).then(i=>{if(q(this.config?.debug||!1,"Wallet connect result",i),!!!(i&&(i.connected===!0||i.principal||i.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}let o=k(this.pnp,i);if(this.config={...this.config,connectedWallet:o,actorProvider:(l,p)=>this.pnp.getActor({canisterId:l,idl:p,requiresSigning:!0,anon:!1})},(e||"").toLowerCase()==="oisy")this.oisyReadyToPay=!0,this.pendingAction=null;else{this.showWalletModal=!1;let l=this.pendingAction;this.pendingAction=null,l==="pay"&&(this.skipDisconnectOnce=!0,this.pay())}}).catch(i=>{q(this.config?.debug||!1,"Wallet connection error",i);let s=(e||"").toLowerCase()==="oisy",o=i&&(i.message||String(i))||"";if(s&&!this.oisyConnectRetriedNewTab&&(o.includes("Signer window could not be opened")||o.includes("Communication channel could not be established"))){this.oisyConnectRetriedNewTab=!0,(async()=>{try{we||(we=(await import("./wallet-select-F6BSMPEE.js")).WalletSelect);let l={...this.config?.plugNPlay||{}},p=W(l);try{if(typeof window<"u"){let{resolveDerivationOrigin:h}=await import("./origin-44ZEXSX4.js");p.derivationOrigin=this.config?.derivationOrigin||h()}}catch{}this.pnp=new we(p),this.pnp.connect("oisy").then(h=>{if(!!!(h&&(h.connected===!0||h.principal||h.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"oisy"}}))}catch{}let A=k(this.pnp,h);this.config={...this.config,connectedWallet:A,actorProvider:(se,P)=>this.pnp.getActor({canisterId:se,idl:P,requiresSigning:!0,anon:!1})},this.oisyReadyToPay=!0,this.pendingAction=null}).catch(h=>{q(this.config?.debug||!1,"Oisy retry connect (new tab) failed",h),this.errorMessage=h instanceof Error?h.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1})}catch(l){q(this.config?.debug||!1,"Oisy new-tab init failed",l),this.errorMessage=l instanceof Error?l.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}})();return}this.errorMessage=i instanceof Error?i.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1})}catch(t){q(this.config?.debug||!1,"Wallet connection error (sync)",t),this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}renderWalletModal(){if(!this.showWalletModal||!this.pnp)return null;let t=(this.pnp.getEnabledWallets()||[]).map(c=>({id:this.getWalletId(c),label:this.getWalletLabel(c),icon:this.getWalletIcon(c)})),i=this.config?.onramp?.enabled!==!1&&this.config?.onrampDisabled!==!0,s=5,o=Number(this.config?.amountUsd??0),a=i&&o>0&&o<s,l=Math.max(0,s-o),p=a?`Note: Minimum card amount is $${s}. You will pay about $${l.toFixed(2)} more.`:null;return H({visible:this.showWalletModal,wallets:t,isConnecting:!1,onSelect:c=>{this.connectWithWallet(c)},onClose:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1},onCreditCard:i?()=>this.startOnramp():void 0,creditCardLabel:this.config?.onramp?.creditCardLabel||"Pay with credit card",showCreditCard:i,creditCardTooltip:p,oisyReadyToPay:this.oisyReadyToPay,onOisyPay:()=>{this.showWalletModal=!1,this.skipDisconnectOnce=!0,this.oisyReadyToPay=!1,this.pay()}})}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1,setTimeout(()=>this.createOnrampIntent(),0)}async createOnrampIntent(){try{let e=Number(this.config?.amountUsd??0),t=this.getSdk();this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||"ICP");let i=this.selectedSymbol||"ICP",o=this.cryptoOptions.find(h=>h.symbol===i)?.canisterId||await t.client.getLedgerCanisterIdBySymbol(i),a=await t.startOnrampUsd(e,o,{context:"pay-button:onramp"}),l=a?.metadata?.onramp?.sessionId||a?.metadata?.onramp?.session_id||null,p=a?.metadata?.onramp?.errorMessage||null;this.onrampErrorMessage=p||null;let c=a?.metadata?.paymentIntentId||a?.paymentIntentId||null;this.onrampPaymentIntentId=c,l?(this.onrampSessionId=l,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.showOnrampModal=!0)}catch(e){this.onrampSessionId=null,this.onrampErrorMessage=e?.message||null,this.showOnrampModal=!0,U(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),B(t)&&(this.errorMessage=R(t),this.errorSeverity=z(t),this.errorAction=D(t))}})}}attachTransakMessageListener(){if(!this.transakMessageHandlerBound){this.transakMessageHandlerBound=e=>this.onTransakMessage(e);try{window.addEventListener("message",this.transakMessageHandlerBound)}catch{}}}detachTransakMessageListener(){if(this.transakMessageHandlerBound){try{window.removeEventListener("message",this.transakMessageHandlerBound)}catch{}this.transakMessageHandlerBound=null}}onTransakMessage(e){let t=e?.data,i=t?.event_id||t?.eventId||t?.id;if(!(!i||typeof i!="string")&&i==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;let s=t?.data?.id||t?.id||t?.webhookData?.id||null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-success",{detail:{name:"getLedgerBalance"}}))}catch{}try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-success",{detail:{name:"sendFundsToLedger"}}))}catch{}try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-success",{detail:{name:"notifyLedgerTransaction"}}))}catch{}this.showOnrampModal=!1,this.startOnrampPolling(s||void 0)}}startOnrampPolling(e){if(this.onrampPollTimer){try{clearInterval(this.onrampPollTimer)}catch{}this.onrampPollTimer=null}if(this.onrampNotifyController){try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null}let t=this.onrampPaymentIntentId;if(!t)return;let i=this.getSdk(),s=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1},o=a=>{s()};try{window.addEventListener("icpay-sdk-transaction-completed",o,{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=i.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}async pay(){if(!(!$e||this.processing)){this.errorMessage=null,this.errorSeverity=null,this.errorAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"pay",type:"sendUsd",amount:this.config?.amountUsd,currency:this.selectedSymbol||this.config?.defaultSymbol}}))}catch{}this.processing=!0;try{if(this.skipDisconnectOnce)this.skipDisconnectOnce=!1;else try{!this.config.useOwnWallet&&this.pnp&&(await this.pnp.disconnect?.(),this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0})}catch{}if(!await this.ensureWallet())return;let t=this.getSdk();try{let c=this.config?.connectedWallet,h=this?.pnp?.account;q(this.config?.debug||!1,"Wallet state before payment",{connectedWallet:c,pnpAccount:h,principal:c?.owner||c?.principal||h?.owner||h?.principal||null})}catch{}this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||"ICP");let i=this.selectedSymbol||"ICP",o=this.cryptoOptions.find(c=>c.symbol===i)?.canisterId||await t.client.getLedgerCanisterIdBySymbol(i);q(this.config?.debug||!1,"Resolved ledger details",{symbol:i,canisterId:o});let a=Number(this.config?.amountUsd??0),l={context:"pay-button"};q(this.config?.debug||!1,"Calling sdk.sendUsd",{amountUsd:a,canisterId:o,meta:l});let p=await t.sendUsd(a,o,l);q(this.config?.debug||!1,"sdk.sendUsd response",p),this.config.onSuccess&&this.config.onSuccess({id:p.transactionId,status:p.status}),this.succeeded=!0,this.dispatchEvent(new CustomEvent("icpay-pay",{detail:{amount:a,tx:p},bubbles:!0}))}catch(e){q(this.config?.debug||!1,"Payment error",{message:e?.message,code:e?.code,details:e?.details,stack:e?.stack}),U(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),B(t)&&(this.errorMessage=R(t),this.errorSeverity=z(t),this.errorAction=D(t))}});try{!this.config.useOwnWallet&&this.pnp&&(await this.pnp.disconnect?.(),this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0})}catch{}}finally{this.processing=!1}}}render(){if(!this.config)return ve`<div class="icpay-card icpay-section">Loading...</div>`;let t=(this.cryptoOptions?.length||0)>1,i=this.config?.showLedgerDropdown,s=i==="dropdown"?"dropdown":i==="none"?"none":"buttons",o=s!=="none"&&(t||s==="dropdown"),a=s==="dropdown"?"dropdown":t?"buttons":"none",l=this.selectedSymbol||this.config?.defaultSymbol||"ICP",p=typeof this.config?.amountUsd=="number"?`${Number(this.config.amountUsd).toFixed(2)}`:"",h=(this.config?.buttonLabel||(typeof this.config?.amountUsd=="number"?"Pay ${amount} with {symbol}":"Pay with {symbol}")).replace("{amount}",p||"$0.00").replace("{symbol}",l),A=this.config?.progressBar?.enabled!==!1;return ve`
|
|
1395
1395
|
<div class="icpay-card icpay-section icpay-widget-base">
|
|
1396
1396
|
${A?ve`
|
|
1397
1397
|
<icpay-progress-bar
|
|
@@ -1436,7 +1436,7 @@ import{a as n}from"./chunk-LTEQ7OUJ.js";import{css as _e}from"lit";var K=_e`
|
|
|
1436
1436
|
.error-message.info { background: rgba(59,130,246,0.1); border-color: rgba(59,130,246,0.3); color: #3b82f6; }
|
|
1437
1437
|
.error-message.warning { background: rgba(245,158,11,0.1); border-color: rgba(245,158,11,0.3); color: #f59e0b; }
|
|
1438
1438
|
.error-message.error { background: rgba(239,68,68,0.1); border-color: rgba(239,68,68,0.3); color: #ef4444; }
|
|
1439
|
-
`],n([St({type:Object})],v.prototype,"config",2),n([O()],v.prototype,"selectedSymbol",2),n([O()],v.prototype,"processing",2),n([O()],v.prototype,"succeeded",2),n([O()],v.prototype,"availableLedgers",2),n([O()],v.prototype,"errorMessage",2),n([O()],v.prototype,"errorSeverity",2),n([O()],v.prototype,"errorAction",2),n([O()],v.prototype,"walletConnected",2),n([O()],v.prototype,"pendingAction",2),n([O()],v.prototype,"showWalletModal",2),n([O()],v.prototype,"showOnrampModal",2),n([O()],v.prototype,"onrampSessionId",2),n([O()],v.prototype,"onrampPaymentIntentId",2),n([O()],v.prototype,"onrampErrorMessage",2),n([O()],v.prototype,"oisyReadyToPay",2),n([O()],v.prototype,"oisySignerPreopened",2),n([O()],v.prototype,"skipDisconnectOnce",2),n([O()],v.prototype,"lastWalletId",2),v=n([xt("icpay-pay-button")],v);import{LitElement as Et,html as xe,css as kt}from"lit";import{customElement as Mt,property as Ct,state as I}from"lit/decorators.js";var Ae=typeof window<"u",Ne=null;function Ot(r,d,e){r&&(e!==void 0?console.log(`[ICPay Widget] ${d}`,e):console.log(`[ICPay Widget] ${d}`))}var w=class extends Et{constructor(){super(...arguments);this.amountUsd=0;this.hasUserAmount=!1;this.selectedSymbol=null;this.processing=!1;this.succeeded=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.showOnrampModal=!1;this.onrampSessionId=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.transakMessageHandlerBound=null;this.onrampPollTimer=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="pay",this.showWalletModal=!0,this.requestUpdate();try{let t=Number(this.amountUsd||0),i=this.selectedSymbol||this.config?.defaultSymbol;window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"pay",type:"sendUsd",amount:t,currency:i}}))}catch{}}catch{}}}get cryptoOptions(){return this.config?.cryptoOptions?.length?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){if(super.connectedCallback(),!!Ae){Ot(this.config?.debug||!1,"Amount input connected",{config:this.config}),this.amountUsd=Number(this.config?.defaultAmountUsd??0),this.hasUserAmount=!1,this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers(),this.config?.defaultSymbol&&(this.selectedSymbol=this.config.defaultSymbol);try{window.addEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}}}updated(e){if(e.has("config")&&(!this.hasUserAmount&&typeof this.config?.defaultAmountUsd=="number"&&(this.amountUsd===0||this.amountUsd==null||Number.isNaN(this.amountUsd))&&(this.amountUsd=Number(this.config.defaultAmountUsd)),!this.selectedSymbol&&this.config?.defaultSymbol&&(this.selectedSymbol=this.config.defaultSymbol),!(this.config?.cryptoOptions&&this.config.cryptoOptions.length>0)&&this.availableLedgers.length===0&&this.loadVerifiedLedgers(),this.pendingAction&&this.config?.actorProvider)){let t=this.pendingAction;this.pendingAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}setTimeout(()=>{t==="pay"&&this.pay()},0)}}async loadVerifiedLedgers(){if(!(!Ae||!this.config?.publishableKey))try{let t=await g(this.config).client.getVerifiedLedgers();this.availableLedgers=t.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||(this.availableLedgers[0]?.symbol??"ICP"))}catch(e){this.dispatchEvent(new CustomEvent("icpay-error",{detail:{message:"Failed to load verified ledgers",cause:e},bubbles:!0})),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||"ICP")}}onInputChange(e){let t=Number(this.config?.stepUsd??.5),i=Math.max(0,Number(e.target.value||0)),s=Math.round(i/t)*t;this.amountUsd=Number(s.toFixed(2)),this.hasUserAmount=!0}selectSymbol(e){this.selectedSymbol=e}isValidAmount(){let e=Number(this.config?.minUsd??.5),t=this.config?.maxUsd!==void 0?Number(this.config.maxUsd):1/0;return this.amountUsd>=e&&this.amountUsd<=t}async ensureWallet(){if(this.config.useOwnWallet)return this.config.actorProvider?!0:(this.pendingAction="pay",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0})),!1);if(this.walletConnected)return!0;try{Ne||(Ne=(await import("./wallet-select-5SAMV2XC.js")).PNP);let e=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab),t={...this.config?.plugNPlay||{}},i=e?W(t):t;try{if(typeof window<"u"){let{resolveDerivationOrigin:o}=await import("./origin-44ZEXSX4.js");i.derivationOrigin=this.config?.derivationOrigin||o()}}catch{}if(this.pnp=new Ne(i),!this.pnp.getEnabledWallets()?.length)throw new Error("No wallets available");return this.pendingAction="pay",this.showWalletModal=!0,!1}catch(e){return this.errorMessage=e instanceof Error?e.message:"Wallet connection failed",this.errorSeverity="error",!1}}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");this.lastWalletId=(e||"").toLowerCase(),this.pnp.connect(e).then(i=>{if(!!!(i&&(i.connected===!0||i.principal||i.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}let o=k(this.pnp,i);if(this.config={...this.config,connectedWallet:o,actorProvider:(l,p)=>this.pnp.getActor({canisterId:l,idl:p,requiresSigning:!0,anon:!1})},this.lastWalletId==="oisy")this.oisyReadyToPay=!0;else{this.showWalletModal=!1;let l=this.pendingAction;this.pendingAction=null,l==="pay"&&setTimeout(()=>this.pay(),0)}}).catch(i=>{this.errorMessage=i instanceof Error?i.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1})}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}attachTransakMessageListener(){if(!this.transakMessageHandlerBound){this.transakMessageHandlerBound=e=>this.onTransakMessage(e);try{window.addEventListener("message",this.transakMessageHandlerBound)}catch{}}}detachTransakMessageListener(){if(this.transakMessageHandlerBound){try{window.removeEventListener("message",this.transakMessageHandlerBound)}catch{}this.transakMessageHandlerBound=null}}onTransakMessage(e){let t=e?.data,i=t?.event_id||t?.eventId||t?.id;if(!(!i||typeof i!="string")&&i==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let s=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(s||void 0)}}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1,setTimeout(()=>this.createOnrampIntent(),0)}async createOnrampIntent(){try{let e=g(this.config),t=this.selectedSymbol||this.config?.defaultSymbol||"ICP",s=this.cryptoOptions.find(h=>h.symbol===t)?.canisterId||await e.client.getLedgerCanisterIdBySymbol(t),o=Number(this.amountUsd),a=await e.startOnrampUsd(o,s,{context:"amount-input:onramp"}),l=a?.metadata?.onramp?.sessionId||a?.metadata?.onramp?.session_id||null,p=a?.metadata?.paymentIntentId||a?.paymentIntentId||null,c=a?.metadata?.onramp?.errorMessage||null;this.onrampPaymentIntentId=p,l?(this.onrampSessionId=l,this.onrampErrorMessage=null,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.onrampErrorMessage=c||"Failed to obtain onramp sessionId",this.showOnrampModal=!0)}catch(e){this.onrampSessionId=null,this.onrampErrorMessage=e?.message||"Failed to obtain onramp sessionId",this.showOnrampModal=!0}}startOnrampPolling(e){if(this.onrampPollTimer){try{clearInterval(this.onrampPollTimer)}catch{}this.onrampPollTimer=null}if(this.onrampNotifyController){try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null}let t=this.onrampPaymentIntentId;if(!t)return;let i=g(this.config),s=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>s()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=i.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}async pay(){if(!(!Ae||this.processing)){if(this.errorMessage=null,this.errorSeverity=null,this.errorAction=null,!this.isValidAmount()){this.errorMessage="Please enter a valid amount",this.errorSeverity="warning";return}try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"pay",type:"sendUsd",amount:this.amountUsd,currency:this.selectedSymbol||this.config?.defaultSymbol}}))}catch{}this.processing=!0;try{if(!await this.ensureWallet())return;let t=g(this.config),i=this.selectedSymbol||this.config?.defaultSymbol||"ICP",o=this.cryptoOptions.find(c=>c.symbol===i)?.canisterId||await t.client.getLedgerCanisterIdBySymbol(i),a=Number(this.amountUsd),l={context:"amount-input"},p=await t.sendUsd(a,o,l);this.config.onSuccess&&this.config.onSuccess({id:p.transactionId,status:p.status,amountUsd:a}),this.succeeded=!0,this.dispatchEvent(new CustomEvent("icpay-amount-pay",{detail:{amount:a,tx:p},bubbles:!0}))}catch(e){U(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),B(t)&&(this.errorMessage=R(t),this.errorSeverity=z(t),this.errorAction=D(t))}});try{!this.config.useOwnWallet&&this.pnp&&(await this.pnp.disconnect?.(),this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0})}catch{}}finally{this.processing=!1}}}render(){if(!this.config)return xe`<div class="icpay-card icpay-section">Loading...</div>`;let e=this.config?.placeholder||"Enter amount in USD",i=(this.config?.buttonLabel||"Pay ${amount} with {symbol}").replace("{amount}",this.amountUsd?`${Number(this.amountUsd).toFixed(2)}`:"$0.00").replace("{symbol}",this.selectedSymbol||this.config?.defaultSymbol||"ICP"),s=this.cryptoOptions.find(P=>P.symbol===(this.selectedSymbol||""))?.label||this.cryptoOptions[0]?.label||this.config?.defaultSymbol||"ICP",o=this.config?.progressBar?.mode||"modal",a=this.config?.showLedgerDropdown,l=a==="buttons"?"buttons":a==="none"?"none":"dropdown",c=(this.cryptoOptions?.length||0)>1,h=l!=="none"&&(c||l==="dropdown"),$=l==="dropdown"?"dropdown":c?"buttons":"none",se=this.config?.progressBar?.enabled!==!1&&(o==="modal"?!0:this.processing);return xe`
|
|
1439
|
+
`],n([St({type:Object})],v.prototype,"config",2),n([O()],v.prototype,"selectedSymbol",2),n([O()],v.prototype,"processing",2),n([O()],v.prototype,"succeeded",2),n([O()],v.prototype,"availableLedgers",2),n([O()],v.prototype,"errorMessage",2),n([O()],v.prototype,"errorSeverity",2),n([O()],v.prototype,"errorAction",2),n([O()],v.prototype,"walletConnected",2),n([O()],v.prototype,"pendingAction",2),n([O()],v.prototype,"showWalletModal",2),n([O()],v.prototype,"showOnrampModal",2),n([O()],v.prototype,"onrampSessionId",2),n([O()],v.prototype,"onrampPaymentIntentId",2),n([O()],v.prototype,"onrampErrorMessage",2),n([O()],v.prototype,"oisyReadyToPay",2),n([O()],v.prototype,"oisySignerPreopened",2),n([O()],v.prototype,"skipDisconnectOnce",2),n([O()],v.prototype,"lastWalletId",2),v=n([xt("icpay-pay-button")],v);import{LitElement as Et,html as xe,css as kt}from"lit";import{customElement as Mt,property as Ct,state as I}from"lit/decorators.js";var Ae=typeof window<"u",Ne=null;function Ot(r,d,e){r&&(e!==void 0?console.log(`[ICPay Widget] ${d}`,e):console.log(`[ICPay Widget] ${d}`))}var w=class extends Et{constructor(){super(...arguments);this.amountUsd=0;this.hasUserAmount=!1;this.selectedSymbol=null;this.processing=!1;this.succeeded=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.showOnrampModal=!1;this.onrampSessionId=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.transakMessageHandlerBound=null;this.onrampPollTimer=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="pay",this.showWalletModal=!0,this.requestUpdate();try{let t=Number(this.amountUsd||0),i=this.selectedSymbol||this.config?.defaultSymbol;window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"pay",type:"sendUsd",amount:t,currency:i}}))}catch{}}catch{}}}get cryptoOptions(){return this.config?.cryptoOptions?.length?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){if(super.connectedCallback(),!!Ae){Ot(this.config?.debug||!1,"Amount input connected",{config:this.config}),this.amountUsd=Number(this.config?.defaultAmountUsd??0),this.hasUserAmount=!1,this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers(),this.config?.defaultSymbol&&(this.selectedSymbol=this.config.defaultSymbol);try{window.addEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}}}updated(e){if(e.has("config")&&(!this.hasUserAmount&&typeof this.config?.defaultAmountUsd=="number"&&(this.amountUsd===0||this.amountUsd==null||Number.isNaN(this.amountUsd))&&(this.amountUsd=Number(this.config.defaultAmountUsd)),!this.selectedSymbol&&this.config?.defaultSymbol&&(this.selectedSymbol=this.config.defaultSymbol),!(this.config?.cryptoOptions&&this.config.cryptoOptions.length>0)&&this.availableLedgers.length===0&&this.loadVerifiedLedgers(),this.pendingAction&&this.config?.actorProvider)){let t=this.pendingAction;this.pendingAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}setTimeout(()=>{t==="pay"&&this.pay()},0)}}async loadVerifiedLedgers(){if(!(!Ae||!this.config?.publishableKey))try{let t=await g(this.config).client.getVerifiedLedgers();this.availableLedgers=t.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||(this.availableLedgers[0]?.symbol??"ICP"))}catch(e){this.dispatchEvent(new CustomEvent("icpay-error",{detail:{message:"Failed to load verified ledgers",cause:e},bubbles:!0})),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||"ICP")}}onInputChange(e){let t=Number(this.config?.stepUsd??.5),i=Math.max(0,Number(e.target.value||0)),s=Math.round(i/t)*t;this.amountUsd=Number(s.toFixed(2)),this.hasUserAmount=!0}selectSymbol(e){this.selectedSymbol=e}isValidAmount(){let e=Number(this.config?.minUsd??.5),t=this.config?.maxUsd!==void 0?Number(this.config.maxUsd):1/0;return this.amountUsd>=e&&this.amountUsd<=t}async ensureWallet(){if(this.config.useOwnWallet)return this.config.actorProvider?!0:(this.pendingAction="pay",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0})),!1);if(this.walletConnected)return!0;try{Ne||(Ne=(await import("./wallet-select-F6BSMPEE.js")).WalletSelect);let e=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab),t={...this.config?.plugNPlay||{}},i=e?W(t):t;try{if(typeof window<"u"){let{resolveDerivationOrigin:o}=await import("./origin-44ZEXSX4.js");i.derivationOrigin=this.config?.derivationOrigin||o()}}catch{}if(this.pnp=new Ne(i),!this.pnp.getEnabledWallets()?.length)throw new Error("No wallets available");return this.pendingAction="pay",this.showWalletModal=!0,!1}catch(e){return this.errorMessage=e instanceof Error?e.message:"Wallet connection failed",this.errorSeverity="error",!1}}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");this.lastWalletId=(e||"").toLowerCase(),this.pnp.connect(e).then(i=>{if(!!!(i&&(i.connected===!0||i.principal||i.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}let o=k(this.pnp,i);if(this.config={...this.config,connectedWallet:o,actorProvider:(l,p)=>this.pnp.getActor({canisterId:l,idl:p,requiresSigning:!0,anon:!1})},this.lastWalletId==="oisy")this.oisyReadyToPay=!0;else{this.showWalletModal=!1;let l=this.pendingAction;this.pendingAction=null,l==="pay"&&setTimeout(()=>this.pay(),0)}}).catch(i=>{this.errorMessage=i instanceof Error?i.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1})}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}attachTransakMessageListener(){if(!this.transakMessageHandlerBound){this.transakMessageHandlerBound=e=>this.onTransakMessage(e);try{window.addEventListener("message",this.transakMessageHandlerBound)}catch{}}}detachTransakMessageListener(){if(this.transakMessageHandlerBound){try{window.removeEventListener("message",this.transakMessageHandlerBound)}catch{}this.transakMessageHandlerBound=null}}onTransakMessage(e){let t=e?.data,i=t?.event_id||t?.eventId||t?.id;if(!(!i||typeof i!="string")&&i==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let s=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(s||void 0)}}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1,setTimeout(()=>this.createOnrampIntent(),0)}async createOnrampIntent(){try{let e=g(this.config),t=this.selectedSymbol||this.config?.defaultSymbol||"ICP",s=this.cryptoOptions.find(h=>h.symbol===t)?.canisterId||await e.client.getLedgerCanisterIdBySymbol(t),o=Number(this.amountUsd),a=await e.startOnrampUsd(o,s,{context:"amount-input:onramp"}),l=a?.metadata?.onramp?.sessionId||a?.metadata?.onramp?.session_id||null,p=a?.metadata?.paymentIntentId||a?.paymentIntentId||null,c=a?.metadata?.onramp?.errorMessage||null;this.onrampPaymentIntentId=p,l?(this.onrampSessionId=l,this.onrampErrorMessage=null,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.onrampErrorMessage=c||"Failed to obtain onramp sessionId",this.showOnrampModal=!0)}catch(e){this.onrampSessionId=null,this.onrampErrorMessage=e?.message||"Failed to obtain onramp sessionId",this.showOnrampModal=!0}}startOnrampPolling(e){if(this.onrampPollTimer){try{clearInterval(this.onrampPollTimer)}catch{}this.onrampPollTimer=null}if(this.onrampNotifyController){try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null}let t=this.onrampPaymentIntentId;if(!t)return;let i=g(this.config),s=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>s()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=i.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}async pay(){if(!(!Ae||this.processing)){if(this.errorMessage=null,this.errorSeverity=null,this.errorAction=null,!this.isValidAmount()){this.errorMessage="Please enter a valid amount",this.errorSeverity="warning";return}try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"pay",type:"sendUsd",amount:this.amountUsd,currency:this.selectedSymbol||this.config?.defaultSymbol}}))}catch{}this.processing=!0;try{if(!await this.ensureWallet())return;let t=g(this.config),i=this.selectedSymbol||this.config?.defaultSymbol||"ICP",o=this.cryptoOptions.find(c=>c.symbol===i)?.canisterId||await t.client.getLedgerCanisterIdBySymbol(i),a=Number(this.amountUsd),l={context:"amount-input"},p=await t.sendUsd(a,o,l);this.config.onSuccess&&this.config.onSuccess({id:p.transactionId,status:p.status,amountUsd:a}),this.succeeded=!0,this.dispatchEvent(new CustomEvent("icpay-amount-pay",{detail:{amount:a,tx:p},bubbles:!0}))}catch(e){U(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),B(t)&&(this.errorMessage=R(t),this.errorSeverity=z(t),this.errorAction=D(t))}});try{!this.config.useOwnWallet&&this.pnp&&(await this.pnp.disconnect?.(),this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0})}catch{}}finally{this.processing=!1}}}render(){if(!this.config)return xe`<div class="icpay-card icpay-section">Loading...</div>`;let e=this.config?.placeholder||"Enter amount in USD",i=(this.config?.buttonLabel||"Pay ${amount} with {symbol}").replace("{amount}",this.amountUsd?`${Number(this.amountUsd).toFixed(2)}`:"$0.00").replace("{symbol}",this.selectedSymbol||this.config?.defaultSymbol||"ICP"),s=this.cryptoOptions.find(P=>P.symbol===(this.selectedSymbol||""))?.label||this.cryptoOptions[0]?.label||this.config?.defaultSymbol||"ICP",o=this.config?.progressBar?.mode||"modal",a=this.config?.showLedgerDropdown,l=a==="buttons"?"buttons":a==="none"?"none":"dropdown",c=(this.cryptoOptions?.length||0)>1,h=l!=="none"&&(c||l==="dropdown"),$=l==="dropdown"?"dropdown":c?"buttons":"none",se=this.config?.progressBar?.enabled!==!1&&(o==="modal"?!0:this.processing);return xe`
|
|
1440
1440
|
<div class="icpay-card icpay-section icpay-widget-base">
|
|
1441
1441
|
${se?xe`
|
|
1442
1442
|
<icpay-progress-bar
|
|
@@ -1503,4 +1503,4 @@ import{a as n}from"./chunk-LTEQ7OUJ.js";import{css as _e}from"lit";var K=_e`
|
|
|
1503
1503
|
.top-row { grid-template-columns: 1fr; }
|
|
1504
1504
|
}
|
|
1505
1505
|
`],n([Ct({type:Object})],w.prototype,"config",2),n([I()],w.prototype,"amountUsd",2),n([I()],w.prototype,"hasUserAmount",2),n([I()],w.prototype,"selectedSymbol",2),n([I()],w.prototype,"processing",2),n([I()],w.prototype,"succeeded",2),n([I()],w.prototype,"availableLedgers",2),n([I()],w.prototype,"errorMessage",2),n([I()],w.prototype,"errorSeverity",2),n([I()],w.prototype,"errorAction",2),n([I()],w.prototype,"walletConnected",2),n([I()],w.prototype,"pendingAction",2),n([I()],w.prototype,"showWalletModal",2),n([I()],w.prototype,"showOnrampModal",2),n([I()],w.prototype,"onrampSessionId",2),n([I()],w.prototype,"onrampPaymentIntentId",2),n([I()],w.prototype,"onrampErrorMessage",2),n([I()],w.prototype,"oisyReadyToPay",2),n([I()],w.prototype,"lastWalletId",2),w=n([Mt("icpay-amount-input")],w);export{K as a,de as b,g as c,F as d,S as e,f,m as g,E as h,b as i,v as j,w as k};
|
|
1506
|
-
//# sourceMappingURL=chunk-
|
|
1506
|
+
//# sourceMappingURL=chunk-ROE27JNI.js.map
|