@ic-pay/icpay-widget 1.1.22 → 1.1.23

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.
@@ -36,6 +36,7 @@ type CommonConfig = {
36
36
  publishableKey: string;
37
37
  apiUrl?: string;
38
38
  icHost?: string;
39
+ metadata?: Record<string, any>;
39
40
  derivationOrigin?: string;
40
41
  actorProvider?: (canisterId: string, idl: any) => any;
41
42
  connectedWallet?: any;
@@ -56,7 +56,7 @@ import{a as n}from"./chunk-LTEQ7OUJ.js";import{css as De}from"lit";var U=De`
56
56
  0%, 100% { opacity: 1; }
57
57
  50% { opacity: 0.7; }
58
58
  }
59
- `;function ie(a,l){if(!a||!l)return;let e=l.primaryColor||void 0,t=l.secondaryColor||void 0,i=(K,F)=>{F&&a.style.setProperty(K,F)};i("--icpay-primary",e),i("--icpay-secondary",t);let s=K=>{if(!K)return null;let F=K.replace("#",""),j=F.length===3?F.split("").map(Te=>Te+Te).join(""):F,V=parseInt(j,16),te=V>>16&255,Re=V>>8&255,Be=V&255;return{r:te,g:Re,b:Be}},c=(K=>{let F=s(K);if(!F)return 0;let j=V=>{let te=V/255;return te<=.03928?te/12.92:Math.pow((te+.055)/1.055,2.4)};return .2126*j(F.r)+.7152*j(F.g)+.0722*j(F.b)})(e||t)>.6,d=l.surfaceColor||(c?"#f3f4f6":"#1f2937"),p=l.surfaceAltColor||(c?"#e5e7eb":"#374151"),k=l.borderColor||(c?"#d1d5db":"#4b5563"),ue=l.textColor||(c?"#111827":"#f9fafb"),be=l.accentColor||t||e||(c?"#6b7280":"#9ca3af"),me=l.mutedTextColor||(c?"#6b7280":"#9ca3af");i("--icpay-accent",be),i("--icpay-text",ue),i("--icpay-muted",me),i("--icpay-surface",d),i("--icpay-surface-alt",p),i("--icpay-border",k)}import{Icpay as Ne}from"@ic-pay/icpay-sdk";var Ue=typeof window<"u";function ve(a,l,e){a&&(e!==void 0?console.log(`[ICPay Widget] ${l}`,e):console.log(`[ICPay Widget] ${l}`))}function h(a){if(!Ue)return{client:{},quoteUsd:async()=>({tokenAmountDecimals:"0"}),sendUsd:async()=>({transactionId:"0",status:"pending"}),startOnrampUsd:async()=>({transactionId:"0",status:"pending",metadata:{onramp:{sessionId:null}}}),notifyIntentUntilComplete:()=>({stop:()=>{}})};ve(a.debug||!1,"Creating SDK with config:",a);let l={publishableKey:a.publishableKey};a.enableEvents!==void 0?l.enableEvents=a.enableEvents:l.enableEvents=!0,a.apiUrl&&(l.apiUrl=a.apiUrl),a.icHost&&(l.icHost=a.icHost),a.actorProvider&&(l.actorProvider=a.actorProvider),a.connectedWallet&&(l.connectedWallet=a.connectedWallet),a.onrampDisabled!==void 0&&(l.onrampDisabled=a.onrampDisabled),a.debug!==void 0&&(l.debug=a.debug),ve(a.debug||!1,"Filtered SDK config:",l);try{let o=function(c,d,p){return t.notifyPaymentIntentOnRamp({paymentIntentId:c,intervalMs:d,orderId:p})};var e=o;ve(a.debug||!1,"typeof Icpay:",typeof Ne);let t=new Ne(l);if(Ue){let c=t,d=p=>{c.addEventListener(p,k=>{window.dispatchEvent(new CustomEvent(p,{detail:k?.detail??k}))})};["icpay-sdk-error","icpay-sdk-transaction-created","icpay-sdk-transaction-updated","icpay-sdk-transaction-completed","icpay-sdk-transaction-failed","icpay-sdk-method-start","icpay-sdk-method-success","icpay-sdk-method-error"].forEach(d)}async function i(c,d){return t.calculateTokenAmountFromUSD({usdAmount:c,ledgerCanisterId:d})}async function s(c,d,p){return t.createPaymentUsd({usdAmount:c,ledgerCanisterId:d,metadata:p})}async function r(c,d,p){return t.createPaymentUsd({usdAmount:c,ledgerCanisterId:d,metadata:p,onrampPayment:!0})}return{client:t,quoteUsd:i,sendUsd:s,startOnrampUsd:r,notifyIntentUntilComplete:o}}catch(t){throw ve(a.debug||!1,"Error creating SDK:",t),t}}import{LitElement as ze,html as f,css as Ke}from"lit";import{customElement as Fe,property as X,state as P}from"lit/decorators.js";function g(a,l,e){a&&(e!==void 0?console.log(l,e):console.log(l))}var je=[{key:"wallet",label:"Connect Wallet",tooltip:"Awaiting wallet connection",status:"pending"},{key:"init",label:"Initialising ICPay",tooltip:"Initializing payment",status:"pending"},{key:"await",label:"Awaiting payment confirmation",tooltip:"Preparing payment",status:"pending"},{key:"transfer",label:"Transferring funds",tooltip:"Submitting payment",status:"pending"},{key:"verify",label:"Verifying payment",tooltip:"Confirming payment",status:"pending"},{key:"confirm",label:"Payment confirmed",tooltip:"Payment completed",status:"pending"}],u=class extends ze{constructor(){super(...arguments);this.open=!1;this.steps=je;this.amount=0;this.currency="";this.ledgerSymbol="";this.debug=!1;this.activeIndex=0;this.completed=!1;this.failed=!1;this.errorMessage=null;this.showSuccess=!1;this.showConfetti=!1;this.currentSteps=[];this.currentAmount=0;this.currentCurrency="";this.currentLedgerSymbol="";this.confirmLoadingStartedAt=null;this.progressionTimer=null;this.currentWalletType=null;this.showWalletSelector=!1;this.isTransitioning=!1;this.onMethodStart=e=>{let t=e?.detail?.name||"",i=e?.detail?.type||"";if(g(this.debug,"ICPay Progress: Method start event received:",e.detail),t==="createPayment"||t==="createPaymentUsd"||t==="sendUsd"||t==="pay"||t==="unlock"||t==="tip"||t==="donate"||t==="order"){if(this.open=!0,this.activeIndex=0,this.completed=!1,this.failed=!1,this.errorMessage=null,this.showSuccess=!1,this.showConfetti=!1,this.showWalletSelector=!1,this.isTransitioning=!1,this.currentSteps=this.currentSteps.map(s=>({...s,status:"pending"})),i==="onramp"){let s=this.getStepIndexByKey("wallet");s>=0&&(this.currentSteps[s]={...this.currentSteps[s],label:"Transak Started",tooltip:"Awaiting Transak information"})}this.setLoadingByKey("wallet"),e?.detail?.amount!==void 0&&(this.currentAmount=e.detail.amount,this.amount=e.detail.amount,g(this.debug,"ICPay Progress: Amount updated to:",e.detail.amount)),e?.detail?.currency&&(this.currentCurrency=e.detail.currency,this.currency=e.detail.currency,g(this.debug,"ICPay Progress: Currency updated to:",e.detail.currency)),e?.detail?.ledgerSymbol&&(this.currentLedgerSymbol=e.detail.ledgerSymbol,this.ledgerSymbol=e.detail.ledgerSymbol,g(this.debug,"ICPay Progress: Current state after method start:",{activeIndex:this.activeIndex,currentAmount:this.currentAmount,currentCurrency:this.currentCurrency,currentLedgerSymbol:this.currentLedgerSymbol})),g(this.debug,"ICPay Progress: Waiting for wallet confirmation before starting progression"),this.requestUpdate()}!this.failed&&!this.completed&&(t==="sendFundsToLedger"?(this.completeByKey("wallet"),this.completeByKey("init"),this.completeByKey("await"),this.setLoadingByKey("transfer")):t==="notifyLedgerTransaction"&&(this.completeByKey("wallet"),this.completeByKey("init"),this.completeByKey("await"),this.completeByKey("transfer"),this.setLoadingByKey("verify")))};this.onMethodSuccess=e=>{let t=e?.detail?.name||"";(t==="createPayment"||t==="createPaymentUsd"||t==="sendUsd"||t==="pay"||t==="unlock"||t==="tip"||t==="donate"||t==="order")&&this.dispatchEvent(new CustomEvent("icpay-progress-method-success",{detail:{methodName:t,step:this.activeIndex},bubbles:!0})),!this.failed&&!this.completed&&(t==="getLedgerBalance"?(this.completeByKey("wallet"),this.completeByKey("init"),this.setLoadingByKey("await")):t==="sendFundsToLedger"?(this.completeByKey("wallet"),this.completeByKey("init"),this.completeByKey("await"),this.completeByKey("transfer"),this.setLoadingByKey("verify")):t==="notifyLedgerTransaction"&&(this.completeByKey("wallet"),this.completeByKey("init"),this.completeByKey("await"),this.completeByKey("transfer"),this.completeByKey("verify"),this.setLoadingByKey("confirm")))};this.onTransactionCreated=e=>{let t=e?.detail?.transactionId||e?.detail?.id;g(this.debug,"ICPay Progress: Transaction created event received:",e.detail),!this.failed&&!this.completed&&(this.completeByKey("wallet"),this.completeByKey("init"),this.completeByKey("await"),this.setLoadingByKey("transfer")),this.dispatchEvent(new CustomEvent("icpay-progress-transaction-created",{detail:{transactionId:t,step:this.activeIndex},bubbles:!0}))};this.onTransactionUpdated=e=>{let t=e?.detail?.status||"pending",i=e?.detail?.transactionId||e?.detail?.id;g(this.debug,"ICPay Progress: Transaction updated event received:",e.detail),!this.failed&&this.completed,this.dispatchEvent(new CustomEvent("icpay-progress-transaction-updated",{detail:{status:t,transactionId:i,step:this.activeIndex},bubbles:!0}))};this.onTransactionCompleted=e=>{let t=e?.detail?.transactionId||e?.detail?.id,i=e?.detail?.status||"completed";g(this.debug,"ICPay Progress: Transaction completed event received:",e.detail),g(this.debug,"ICPay Progress: Current state when transaction completed:",{activeIndex:this.activeIndex,completed:this.completed,failed:this.failed,showSuccess:this.showSuccess}),this.completeByKey("transfer"),this.completeByKey("await"),this.completeByKey("init"),this.completeByKey("verify"),this.completeByKey("confirm"),this.completed=!0,this.showSuccess=!0,this.showConfetti=!0,this.dispatchEvent(new CustomEvent("icpay-progress-completed",{detail:{transactionId:t,status:i,amount:this.currentAmount||this.amount,currency:this.currentCurrency||this.currency,ledgerSymbol:this.currentLedgerSymbol||this.ledgerSymbol},bubbles:!0})),setTimeout(()=>{this.showConfetti=!1},3e3)};this.onTransactionFailed=e=>{let t=e?.detail?.message||e?.detail?.error?.message||"Transaction failed",i=e?.detail?.error?.code||e?.detail?.code||"UNKNOWN_ERROR",s=e?.detail?.transactionId||e?.detail?.id;g(this.debug,"ICPay Progress: Transaction failed event received:",e.detail),this.failed=!0,this.errorMessage=this.transformErrorMessage(t),this.showSuccess=!1,this.updateStepStatus(this.activeIndex,"error",t),this.stopAutomaticProgression(),this.open=!0,this.dispatchEvent(new CustomEvent("icpay-progress-failed",{detail:{errorMessage:t,errorCode:i,transactionId:s,step:this.activeIndex},bubbles:!0}))};this.onTransactionMismatched=e=>{let t=e?.detail?.requestedAmount,i=e?.detail?.paidAmount,s=e?.detail?.transactionId||e?.detail?.id;this.failed=!0;let r=t!=null?String(t):"unknown",o=i!=null?String(i):"unknown";this.errorMessage=`Amount mismatch. Requested ${r}, paid ${o}.`,this.showSuccess=!1,this.updateStepStatus(this.activeIndex,"error",this.errorMessage),this.stopAutomaticProgression(),this.open=!0,this.dispatchEvent(new CustomEvent("icpay-progress-failed",{detail:{errorMessage:this.errorMessage,errorCode:"MISMATCHED_AMOUNT",transactionId:s,step:this.activeIndex,requestedAmount:t,paidAmount:i},bubbles:!0}))};this.onMethodError=e=>{let t=e?.detail?.name||"",i=e?.detail?.error?.message||e?.detail?.message||"An error occurred",s=e?.detail?.error?.code||e?.detail?.code||"METHOD_ERROR";g(this.debug,"ICPay Progress: Method error event received:",e.detail),(t?.startsWith("createPayment")||t==="sendUsd"||t==="pay"||t==="unlock"||t==="tip"||t==="donate"||t==="order")&&(this.failed=!0,this.errorMessage=this.transformErrorMessage(i),this.showSuccess=!1,this.updateStepStatus(this.activeIndex,"error",i),this.stopAutomaticProgression(),this.open=!0,this.dispatchEvent(new CustomEvent("icpay-progress-error",{detail:{methodName:t,errorMessage:i,errorCode:s,step:this.activeIndex},bubbles:!0})))};this.onSDKError=e=>{let t=e?.detail?.message||"SDK error occurred",i=e?.detail?.code||"SDK_ERROR";g(this.debug,"ICPay Progress: SDK error event received:",e.detail),this.failed=!0,this.errorMessage=this.transformErrorMessage(t),this.showSuccess=!1,this.updateStepStatus(this.activeIndex,"error",t),this.stopAutomaticProgression(),this.open=!0,this.dispatchEvent(new CustomEvent("icpay-progress-sdk-error",{detail:{errorMessage:t,errorCode:i,step:this.activeIndex},bubbles:!0}))};this.onWalletConnected=e=>{let t=e?.detail?.walletType||"unknown";g(this.debug,"ICPay Progress: Wallet connected event received:",e.detail),this.completeByKey("wallet"),this.setLoadingByKey("init"),this.startTransitionToProgress(),this.dispatchEvent(new CustomEvent("icpay-progress-wallet-connected",{detail:{walletType:t,step:this.activeIndex},bubbles:!0})),this.currentWalletType=t};this.onWalletDisconnected=e=>{let t=e?.detail?.walletType||"unknown";g(this.debug,"ICPay Progress: Wallet disconnected event received:",e.detail),this.dispatchEvent(new CustomEvent("icpay-progress-wallet-disconnected",{detail:{walletType:t,step:this.activeIndex},bubbles:!0})),this.currentWalletType=null};this.onBalanceCheck=e=>{let t=e?.detail?.hasBalance||!1,i=e?.detail?.balance||0;g(this.debug,"ICPay Progress: Balance check event received:",e.detail),t||(this.failed=!0,this.errorMessage="Insufficient balance for transaction",this.updateStepStatus(this.activeIndex,"error","Insufficient balance for transaction"),this.stopAutomaticProgression(),this.showWalletSelector=!1,this.dispatchEvent(new CustomEvent("icpay-progress-insufficient-balance",{detail:{balance:i,required:this.currentAmount||this.amount,step:this.activeIndex},bubbles:!0})))};this.onLedgerVerified=e=>{let t=e?.detail?.ledgerId||e?.detail?.canisterId,i=e?.detail?.symbol||"unknown";g(this.debug,"ICPay Progress: Ledger verified event received:",e.detail),i&&i!=="unknown"&&(this.currentLedgerSymbol=i,this.ledgerSymbol=i),this.dispatchEvent(new CustomEvent("icpay-progress-ledger-verified",{detail:{ledgerId:t,symbol:i,step:this.activeIndex},bubbles:!0}))};this.onWidgetPayment=e=>{let t=e?.detail?.amount,i=e?.detail?.currency,s=e?.detail?.ledgerSymbol;if(g(this.debug,"ICPay Progress: Widget payment event received:",e.detail),t!==void 0&&(this.currentAmount=t,this.amount=t),i&&(this.currentCurrency=i,this.currency=i),s&&(this.currentLedgerSymbol=s,this.ledgerSymbol=s),!this.failed){for(let r=this.activeIndex;r<this.currentSteps.length;r++)this.updateStepStatus(r,"completed");this.activeIndex=this.currentSteps.length-1,this.completed=!0,this.showSuccess=!0,this.showConfetti=!0}this.dispatchEvent(new CustomEvent("icpay-progress-widget-payment",{detail:{amount:t,currency:i,ledgerSymbol:s,step:this.activeIndex},bubbles:!0}))};this.onWidgetError=e=>{let t=e?.detail?.message||"Widget error occurred",i=e?.detail?.code||"WIDGET_ERROR";g(this.debug,"ICPay Progress: Widget error event received:",e.detail),this.failed=!0,this.errorMessage=this.transformErrorMessage(t),this.showSuccess=!1,this.updateStepStatus(this.activeIndex,"error",t),this.stopAutomaticProgression(),this.open=!0,this.dispatchEvent(new CustomEvent("icpay-progress-widget-error",{detail:{errorMessage:t,errorCode:i,step:this.activeIndex},bubbles:!0}))};this.onWidgetUnlock=e=>{let t=e?.detail?.amount,i=e?.detail?.currency;if(g(this.debug,"ICPay Progress: Widget unlock event received:",e.detail),!this.failed){for(let s=this.activeIndex;s<this.currentSteps.length;s++)this.updateStepStatus(s,"completed");this.activeIndex=this.currentSteps.length-1,this.completed=!0,this.showSuccess=!0,this.showConfetti=!0}this.dispatchEvent(new CustomEvent("icpay-progress-widget-unlock",{detail:{amount:t,currency:i,step:this.activeIndex},bubbles:!0}))};this.onWidgetTip=e=>{let t=e?.detail?.amount,i=e?.detail?.currency;if(g(this.debug,"ICPay Progress: Widget tip event received:",e.detail),!this.failed){for(let s=this.activeIndex;s<this.currentSteps.length;s++)this.updateStepStatus(s,"completed");this.activeIndex=this.currentSteps.length-1,this.completed=!0,this.showSuccess=!0,this.showConfetti=!0}this.dispatchEvent(new CustomEvent("icpay-progress-widget-tip",{detail:{amount:t,currency:i,step:this.activeIndex},bubbles:!0}))};this.onWidgetDonation=e=>{let t=e?.detail?.amount,i=e?.detail?.currency;if(g(this.debug,"ICPay Progress: Widget donation event received:",e.detail),!this.failed){for(let s=this.activeIndex;s<this.currentSteps.length;s++)this.updateStepStatus(s,"completed");this.activeIndex=this.currentSteps.length-1,this.completed=!0,this.showSuccess=!0,this.showConfetti=!0}this.dispatchEvent(new CustomEvent("icpay-progress-widget-donation",{detail:{amount:t,currency:i,step:this.activeIndex},bubbles:!0}))};this.onWidgetCoffee=e=>{let t=e?.detail?.amount,i=e?.detail?.currency;if(g(this.debug,"ICPay Progress: Widget coffee event received:",e.detail),!this.failed){for(let s=this.activeIndex;s<this.currentSteps.length;s++)this.updateStepStatus(s,"completed");this.activeIndex=this.currentSteps.length-1,this.completed=!0,this.showSuccess=!0,this.showConfetti=!0}this.dispatchEvent(new CustomEvent("icpay-progress-widget-coffee",{detail:{amount:t,currency:i,step:this.activeIndex},bubbles:!0}))}}connectedCallback(){super.connectedCallback();try{ie(this,this.theme)}catch{}this.currentSteps=[...this.steps],this.currentAmount=this.amount,this.currentCurrency=this.currency,this.currentLedgerSymbol=this.ledgerSymbol,this.attachSDKEventListeners()}disconnectedCallback(){super.disconnectedCallback(),this.detachSDKEventListeners(),this.stopAutomaticProgression()}updated(e){if(e.has("theme"))try{ie(this,this.theme)}catch{}}attachSDKEventListeners(){window.addEventListener("icpay-sdk-method-start",this.onMethodStart),window.addEventListener("icpay-sdk-method-success",this.onMethodSuccess),window.addEventListener("icpay-sdk-method-error",this.onMethodError),window.addEventListener("icpay-sdk-transaction-created",this.onTransactionCreated),window.addEventListener("icpay-sdk-transaction-updated",this.onTransactionUpdated),window.addEventListener("icpay-sdk-transaction-completed",this.onTransactionCompleted),window.addEventListener("icpay-sdk-transaction-failed",this.onTransactionFailed),window.addEventListener("icpay-sdk-transaction-mismatched",this.onTransactionMismatched),window.addEventListener("icpay-sdk-error",this.onSDKError),window.addEventListener("icpay-sdk-wallet-connected",this.onWalletConnected),window.addEventListener("icpay-sdk-wallet-disconnected",this.onWalletDisconnected),window.addEventListener("icpay-sdk-balance-check",this.onBalanceCheck),window.addEventListener("icpay-sdk-ledger-verified",this.onLedgerVerified),window.addEventListener("icpay-pay",this.onWidgetPayment),window.addEventListener("icpay-error",this.onWidgetError),window.addEventListener("icpay-unlock",this.onWidgetUnlock),window.addEventListener("icpay-tip",this.onWidgetTip),window.addEventListener("icpay-donation",this.onWidgetDonation),window.addEventListener("icpay-coffee",this.onWidgetCoffee)}detachSDKEventListeners(){window.removeEventListener("icpay-sdk-method-start",this.onMethodStart),window.removeEventListener("icpay-sdk-method-success",this.onMethodSuccess),window.removeEventListener("icpay-sdk-method-error",this.onMethodError),window.removeEventListener("icpay-sdk-transaction-created",this.onTransactionCreated),window.removeEventListener("icpay-sdk-transaction-updated",this.onTransactionUpdated),window.removeEventListener("icpay-sdk-transaction-completed",this.onTransactionCompleted),window.removeEventListener("icpay-sdk-transaction-failed",this.onTransactionFailed),window.removeEventListener("icpay-sdk-transaction-mismatched",this.onTransactionMismatched),window.removeEventListener("icpay-sdk-error",this.onSDKError),window.removeEventListener("icpay-sdk-wallet-connected",this.onWalletConnected),window.removeEventListener("icpay-sdk-wallet-disconnected",this.onWalletDisconnected),window.removeEventListener("icpay-sdk-balance-check",this.onBalanceCheck),window.removeEventListener("icpay-sdk-ledger-verified",this.onLedgerVerified),window.removeEventListener("icpay-pay",this.onWidgetPayment),window.removeEventListener("icpay-error",this.onWidgetError),window.removeEventListener("icpay-unlock",this.onWidgetUnlock),window.removeEventListener("icpay-tip",this.onWidgetTip),window.removeEventListener("icpay-donation",this.onWidgetDonation),window.removeEventListener("icpay-coffee",this.onWidgetCoffee)}startAutomaticProgression(){this.progressionTimer&&clearInterval(this.progressionTimer),this.activeIndex=1,this.updateStepStatus(this.activeIndex,"loading"),g(this.debug,"ICPay Progress: Starting automatic progression from step:",this.activeIndex),this.progressionTimer=setInterval(()=>{if(this.failed||this.completed){this.stopAutomaticProgression();return}g(this.debug,"ICPay Progress: Processing step:",this.activeIndex),this.updateStepStatus(this.activeIndex,"completed"),this.activeIndex<this.currentSteps.length-1?(this.activeIndex++,this.updateStepStatus(this.activeIndex,"loading"),g(this.debug,"ICPay Progress: Auto-progressed to step:",this.activeIndex)):(this.stopAutomaticProgression(),g(this.debug,"ICPay Progress: All steps completed, waiting for transaction completion")),this.requestUpdate()},3e3)}stopAutomaticProgression(){this.progressionTimer&&(clearInterval(this.progressionTimer),this.progressionTimer=null)}updateStepStatus(e,t,i){if(e>=0&&e<this.currentSteps.length){let s=this.currentSteps[e],r=s.status;s.status=t,t==="completed"&&(s.timestamp=this.getCurrentTime()),t==="error"&&i&&(s.errorMessage=this.transformErrorMessage(i)),g(this.debug,`ICPay Progress: Step ${e} (${s.label}) status changed from ${r} to ${t}`),this.requestUpdate()}}getCurrentTime(){return new Date().toLocaleTimeString("en-US",{hour12:!1,hour:"2-digit",minute:"2-digit",second:"2-digit"})}getStepIcon(e){switch(e.status){case"loading":return f`<div class="loading-spinner"></div>`;case"completed":return f`<svg fill="none" viewBox="0 0 24 24" stroke="currentColor">
59
+ `;function ie(a,l){if(!a||!l)return;let e=l.primaryColor||void 0,t=l.secondaryColor||void 0,i=(K,F)=>{F&&a.style.setProperty(K,F)};i("--icpay-primary",e),i("--icpay-secondary",t);let s=K=>{if(!K)return null;let F=K.replace("#",""),j=F.length===3?F.split("").map(Te=>Te+Te).join(""):F,V=parseInt(j,16),te=V>>16&255,Re=V>>8&255,Be=V&255;return{r:te,g:Re,b:Be}},c=(K=>{let F=s(K);if(!F)return 0;let j=V=>{let te=V/255;return te<=.03928?te/12.92:Math.pow((te+.055)/1.055,2.4)};return .2126*j(F.r)+.7152*j(F.g)+.0722*j(F.b)})(e||t)>.6,d=l.surfaceColor||(c?"#f3f4f6":"#1f2937"),p=l.surfaceAltColor||(c?"#e5e7eb":"#374151"),w=l.borderColor||(c?"#d1d5db":"#4b5563"),ue=l.textColor||(c?"#111827":"#f9fafb"),be=l.accentColor||t||e||(c?"#6b7280":"#9ca3af"),me=l.mutedTextColor||(c?"#6b7280":"#9ca3af");i("--icpay-accent",be),i("--icpay-text",ue),i("--icpay-muted",me),i("--icpay-surface",d),i("--icpay-surface-alt",p),i("--icpay-border",w)}import{Icpay as Ne}from"@ic-pay/icpay-sdk";var Ue=typeof window<"u";function ve(a,l,e){a&&(e!==void 0?console.log(`[ICPay Widget] ${l}`,e):console.log(`[ICPay Widget] ${l}`))}function h(a){if(!Ue)return{client:{},quoteUsd:async()=>({tokenAmountDecimals:"0"}),sendUsd:async()=>({transactionId:"0",status:"pending"}),startOnrampUsd:async()=>({transactionId:"0",status:"pending",metadata:{onramp:{sessionId:null}}}),notifyIntentUntilComplete:()=>({stop:()=>{}})};ve(a.debug||!1,"Creating SDK with config:",a);let l={publishableKey:a.publishableKey};a.enableEvents!==void 0?l.enableEvents=a.enableEvents:l.enableEvents=!0,a.apiUrl&&(l.apiUrl=a.apiUrl),a.icHost&&(l.icHost=a.icHost),a.actorProvider&&(l.actorProvider=a.actorProvider),a.connectedWallet&&(l.connectedWallet=a.connectedWallet),a.onrampDisabled!==void 0&&(l.onrampDisabled=a.onrampDisabled),a.debug!==void 0&&(l.debug=a.debug),ve(a.debug||!1,"Filtered SDK config:",l);try{let o=function(c,d,p){return t.notifyPaymentIntentOnRamp({paymentIntentId:c,intervalMs:d,orderId:p})};var e=o;ve(a.debug||!1,"typeof Icpay:",typeof Ne);let t=new Ne(l);if(Ue){let c=t,d=p=>{c.addEventListener(p,w=>{window.dispatchEvent(new CustomEvent(p,{detail:w?.detail??w}))})};["icpay-sdk-error","icpay-sdk-transaction-created","icpay-sdk-transaction-updated","icpay-sdk-transaction-completed","icpay-sdk-transaction-failed","icpay-sdk-method-start","icpay-sdk-method-success","icpay-sdk-method-error"].forEach(d)}async function i(c,d){return t.calculateTokenAmountFromUSD({usdAmount:c,ledgerCanisterId:d})}async function s(c,d,p){let w={...a.metadata,...p||{}};return t.createPaymentUsd({usdAmount:c,ledgerCanisterId:d,metadata:w})}async function r(c,d,p){let w={...a.metadata,...p||{}};return t.createPaymentUsd({usdAmount:c,ledgerCanisterId:d,metadata:w,onrampPayment:!0})}return{client:t,quoteUsd:i,sendUsd:s,startOnrampUsd:r,notifyIntentUntilComplete:o}}catch(t){throw ve(a.debug||!1,"Error creating SDK:",t),t}}import{LitElement as ze,html as f,css as Ke}from"lit";import{customElement as Fe,property as X,state as P}from"lit/decorators.js";function g(a,l,e){a&&(e!==void 0?console.log(l,e):console.log(l))}var je=[{key:"wallet",label:"Connect Wallet",tooltip:"Awaiting wallet connection",status:"pending"},{key:"init",label:"Initialising ICPay",tooltip:"Initializing payment",status:"pending"},{key:"await",label:"Awaiting payment confirmation",tooltip:"Preparing payment",status:"pending"},{key:"transfer",label:"Transferring funds",tooltip:"Submitting payment",status:"pending"},{key:"verify",label:"Verifying payment",tooltip:"Confirming payment",status:"pending"},{key:"confirm",label:"Payment confirmed",tooltip:"Payment completed",status:"pending"}],u=class extends ze{constructor(){super(...arguments);this.open=!1;this.steps=je;this.amount=0;this.currency="";this.ledgerSymbol="";this.debug=!1;this.activeIndex=0;this.completed=!1;this.failed=!1;this.errorMessage=null;this.showSuccess=!1;this.showConfetti=!1;this.currentSteps=[];this.currentAmount=0;this.currentCurrency="";this.currentLedgerSymbol="";this.confirmLoadingStartedAt=null;this.progressionTimer=null;this.currentWalletType=null;this.showWalletSelector=!1;this.isTransitioning=!1;this.onMethodStart=e=>{let t=e?.detail?.name||"",i=e?.detail?.type||"";if(g(this.debug,"ICPay Progress: Method start event received:",e.detail),t==="createPayment"||t==="createPaymentUsd"||t==="sendUsd"||t==="pay"||t==="unlock"||t==="tip"||t==="donate"||t==="order"){if(this.open=!0,this.activeIndex=0,this.completed=!1,this.failed=!1,this.errorMessage=null,this.showSuccess=!1,this.showConfetti=!1,this.showWalletSelector=!1,this.isTransitioning=!1,this.currentSteps=this.currentSteps.map(s=>({...s,status:"pending"})),i==="onramp"){let s=this.getStepIndexByKey("wallet");s>=0&&(this.currentSteps[s]={...this.currentSteps[s],label:"Transak Started",tooltip:"Awaiting Transak information"})}this.setLoadingByKey("wallet"),e?.detail?.amount!==void 0&&(this.currentAmount=e.detail.amount,this.amount=e.detail.amount,g(this.debug,"ICPay Progress: Amount updated to:",e.detail.amount)),e?.detail?.currency&&(this.currentCurrency=e.detail.currency,this.currency=e.detail.currency,g(this.debug,"ICPay Progress: Currency updated to:",e.detail.currency)),e?.detail?.ledgerSymbol&&(this.currentLedgerSymbol=e.detail.ledgerSymbol,this.ledgerSymbol=e.detail.ledgerSymbol,g(this.debug,"ICPay Progress: Current state after method start:",{activeIndex:this.activeIndex,currentAmount:this.currentAmount,currentCurrency:this.currentCurrency,currentLedgerSymbol:this.currentLedgerSymbol})),g(this.debug,"ICPay Progress: Waiting for wallet confirmation before starting progression"),this.requestUpdate()}!this.failed&&!this.completed&&(t==="sendFundsToLedger"?(this.completeByKey("wallet"),this.completeByKey("init"),this.completeByKey("await"),this.setLoadingByKey("transfer")):t==="notifyLedgerTransaction"&&(this.completeByKey("wallet"),this.completeByKey("init"),this.completeByKey("await"),this.completeByKey("transfer"),this.setLoadingByKey("verify")))};this.onMethodSuccess=e=>{let t=e?.detail?.name||"";(t==="createPayment"||t==="createPaymentUsd"||t==="sendUsd"||t==="pay"||t==="unlock"||t==="tip"||t==="donate"||t==="order")&&this.dispatchEvent(new CustomEvent("icpay-progress-method-success",{detail:{methodName:t,step:this.activeIndex},bubbles:!0})),!this.failed&&!this.completed&&(t==="getLedgerBalance"?(this.completeByKey("wallet"),this.completeByKey("init"),this.setLoadingByKey("await")):t==="sendFundsToLedger"?(this.completeByKey("wallet"),this.completeByKey("init"),this.completeByKey("await"),this.completeByKey("transfer"),this.setLoadingByKey("verify")):t==="notifyLedgerTransaction"&&(this.completeByKey("wallet"),this.completeByKey("init"),this.completeByKey("await"),this.completeByKey("transfer"),this.completeByKey("verify"),this.setLoadingByKey("confirm")))};this.onTransactionCreated=e=>{let t=e?.detail?.transactionId||e?.detail?.id;g(this.debug,"ICPay Progress: Transaction created event received:",e.detail),!this.failed&&!this.completed&&(this.completeByKey("wallet"),this.completeByKey("init"),this.completeByKey("await"),this.setLoadingByKey("transfer")),this.dispatchEvent(new CustomEvent("icpay-progress-transaction-created",{detail:{transactionId:t,step:this.activeIndex},bubbles:!0}))};this.onTransactionUpdated=e=>{let t=e?.detail?.status||"pending",i=e?.detail?.transactionId||e?.detail?.id;g(this.debug,"ICPay Progress: Transaction updated event received:",e.detail),!this.failed&&this.completed,this.dispatchEvent(new CustomEvent("icpay-progress-transaction-updated",{detail:{status:t,transactionId:i,step:this.activeIndex},bubbles:!0}))};this.onTransactionCompleted=e=>{let t=e?.detail?.transactionId||e?.detail?.id,i=e?.detail?.status||"completed";g(this.debug,"ICPay Progress: Transaction completed event received:",e.detail),g(this.debug,"ICPay Progress: Current state when transaction completed:",{activeIndex:this.activeIndex,completed:this.completed,failed:this.failed,showSuccess:this.showSuccess}),this.completeByKey("transfer"),this.completeByKey("await"),this.completeByKey("init"),this.completeByKey("verify"),this.completeByKey("confirm"),this.completed=!0,this.showSuccess=!0,this.showConfetti=!0,this.dispatchEvent(new CustomEvent("icpay-progress-completed",{detail:{transactionId:t,status:i,amount:this.currentAmount||this.amount,currency:this.currentCurrency||this.currency,ledgerSymbol:this.currentLedgerSymbol||this.ledgerSymbol},bubbles:!0})),setTimeout(()=>{this.showConfetti=!1},3e3)};this.onTransactionFailed=e=>{let t=e?.detail?.message||e?.detail?.error?.message||"Transaction failed",i=e?.detail?.error?.code||e?.detail?.code||"UNKNOWN_ERROR",s=e?.detail?.transactionId||e?.detail?.id;g(this.debug,"ICPay Progress: Transaction failed event received:",e.detail),this.failed=!0,this.errorMessage=this.transformErrorMessage(t),this.showSuccess=!1,this.updateStepStatus(this.activeIndex,"error",t),this.stopAutomaticProgression(),this.open=!0,this.dispatchEvent(new CustomEvent("icpay-progress-failed",{detail:{errorMessage:t,errorCode:i,transactionId:s,step:this.activeIndex},bubbles:!0}))};this.onTransactionMismatched=e=>{let t=e?.detail?.requestedAmount,i=e?.detail?.paidAmount,s=e?.detail?.transactionId||e?.detail?.id;this.failed=!0;let r=t!=null?String(t):"unknown",o=i!=null?String(i):"unknown";this.errorMessage=`Amount mismatch. Requested ${r}, paid ${o}.`,this.showSuccess=!1,this.updateStepStatus(this.activeIndex,"error",this.errorMessage),this.stopAutomaticProgression(),this.open=!0,this.dispatchEvent(new CustomEvent("icpay-progress-failed",{detail:{errorMessage:this.errorMessage,errorCode:"MISMATCHED_AMOUNT",transactionId:s,step:this.activeIndex,requestedAmount:t,paidAmount:i},bubbles:!0}))};this.onMethodError=e=>{let t=e?.detail?.name||"",i=e?.detail?.error?.message||e?.detail?.message||"An error occurred",s=e?.detail?.error?.code||e?.detail?.code||"METHOD_ERROR";g(this.debug,"ICPay Progress: Method error event received:",e.detail),(t?.startsWith("createPayment")||t==="sendUsd"||t==="pay"||t==="unlock"||t==="tip"||t==="donate"||t==="order")&&(this.failed=!0,this.errorMessage=this.transformErrorMessage(i),this.showSuccess=!1,this.updateStepStatus(this.activeIndex,"error",i),this.stopAutomaticProgression(),this.open=!0,this.dispatchEvent(new CustomEvent("icpay-progress-error",{detail:{methodName:t,errorMessage:i,errorCode:s,step:this.activeIndex},bubbles:!0})))};this.onSDKError=e=>{let t=e?.detail?.message||"SDK error occurred",i=e?.detail?.code||"SDK_ERROR";g(this.debug,"ICPay Progress: SDK error event received:",e.detail),this.failed=!0,this.errorMessage=this.transformErrorMessage(t),this.showSuccess=!1,this.updateStepStatus(this.activeIndex,"error",t),this.stopAutomaticProgression(),this.open=!0,this.dispatchEvent(new CustomEvent("icpay-progress-sdk-error",{detail:{errorMessage:t,errorCode:i,step:this.activeIndex},bubbles:!0}))};this.onWalletConnected=e=>{let t=e?.detail?.walletType||"unknown";g(this.debug,"ICPay Progress: Wallet connected event received:",e.detail),this.completeByKey("wallet"),this.setLoadingByKey("init"),this.startTransitionToProgress(),this.dispatchEvent(new CustomEvent("icpay-progress-wallet-connected",{detail:{walletType:t,step:this.activeIndex},bubbles:!0})),this.currentWalletType=t};this.onWalletDisconnected=e=>{let t=e?.detail?.walletType||"unknown";g(this.debug,"ICPay Progress: Wallet disconnected event received:",e.detail),this.dispatchEvent(new CustomEvent("icpay-progress-wallet-disconnected",{detail:{walletType:t,step:this.activeIndex},bubbles:!0})),this.currentWalletType=null};this.onBalanceCheck=e=>{let t=e?.detail?.hasBalance||!1,i=e?.detail?.balance||0;g(this.debug,"ICPay Progress: Balance check event received:",e.detail),t||(this.failed=!0,this.errorMessage="Insufficient balance for transaction",this.updateStepStatus(this.activeIndex,"error","Insufficient balance for transaction"),this.stopAutomaticProgression(),this.showWalletSelector=!1,this.dispatchEvent(new CustomEvent("icpay-progress-insufficient-balance",{detail:{balance:i,required:this.currentAmount||this.amount,step:this.activeIndex},bubbles:!0})))};this.onLedgerVerified=e=>{let t=e?.detail?.ledgerId||e?.detail?.canisterId,i=e?.detail?.symbol||"unknown";g(this.debug,"ICPay Progress: Ledger verified event received:",e.detail),i&&i!=="unknown"&&(this.currentLedgerSymbol=i,this.ledgerSymbol=i),this.dispatchEvent(new CustomEvent("icpay-progress-ledger-verified",{detail:{ledgerId:t,symbol:i,step:this.activeIndex},bubbles:!0}))};this.onWidgetPayment=e=>{let t=e?.detail?.amount,i=e?.detail?.currency,s=e?.detail?.ledgerSymbol;if(g(this.debug,"ICPay Progress: Widget payment event received:",e.detail),t!==void 0&&(this.currentAmount=t,this.amount=t),i&&(this.currentCurrency=i,this.currency=i),s&&(this.currentLedgerSymbol=s,this.ledgerSymbol=s),!this.failed){for(let r=this.activeIndex;r<this.currentSteps.length;r++)this.updateStepStatus(r,"completed");this.activeIndex=this.currentSteps.length-1,this.completed=!0,this.showSuccess=!0,this.showConfetti=!0}this.dispatchEvent(new CustomEvent("icpay-progress-widget-payment",{detail:{amount:t,currency:i,ledgerSymbol:s,step:this.activeIndex},bubbles:!0}))};this.onWidgetError=e=>{let t=e?.detail?.message||"Widget error occurred",i=e?.detail?.code||"WIDGET_ERROR";g(this.debug,"ICPay Progress: Widget error event received:",e.detail),this.failed=!0,this.errorMessage=this.transformErrorMessage(t),this.showSuccess=!1,this.updateStepStatus(this.activeIndex,"error",t),this.stopAutomaticProgression(),this.open=!0,this.dispatchEvent(new CustomEvent("icpay-progress-widget-error",{detail:{errorMessage:t,errorCode:i,step:this.activeIndex},bubbles:!0}))};this.onWidgetUnlock=e=>{let t=e?.detail?.amount,i=e?.detail?.currency;if(g(this.debug,"ICPay Progress: Widget unlock event received:",e.detail),!this.failed){for(let s=this.activeIndex;s<this.currentSteps.length;s++)this.updateStepStatus(s,"completed");this.activeIndex=this.currentSteps.length-1,this.completed=!0,this.showSuccess=!0,this.showConfetti=!0}this.dispatchEvent(new CustomEvent("icpay-progress-widget-unlock",{detail:{amount:t,currency:i,step:this.activeIndex},bubbles:!0}))};this.onWidgetTip=e=>{let t=e?.detail?.amount,i=e?.detail?.currency;if(g(this.debug,"ICPay Progress: Widget tip event received:",e.detail),!this.failed){for(let s=this.activeIndex;s<this.currentSteps.length;s++)this.updateStepStatus(s,"completed");this.activeIndex=this.currentSteps.length-1,this.completed=!0,this.showSuccess=!0,this.showConfetti=!0}this.dispatchEvent(new CustomEvent("icpay-progress-widget-tip",{detail:{amount:t,currency:i,step:this.activeIndex},bubbles:!0}))};this.onWidgetDonation=e=>{let t=e?.detail?.amount,i=e?.detail?.currency;if(g(this.debug,"ICPay Progress: Widget donation event received:",e.detail),!this.failed){for(let s=this.activeIndex;s<this.currentSteps.length;s++)this.updateStepStatus(s,"completed");this.activeIndex=this.currentSteps.length-1,this.completed=!0,this.showSuccess=!0,this.showConfetti=!0}this.dispatchEvent(new CustomEvent("icpay-progress-widget-donation",{detail:{amount:t,currency:i,step:this.activeIndex},bubbles:!0}))};this.onWidgetCoffee=e=>{let t=e?.detail?.amount,i=e?.detail?.currency;if(g(this.debug,"ICPay Progress: Widget coffee event received:",e.detail),!this.failed){for(let s=this.activeIndex;s<this.currentSteps.length;s++)this.updateStepStatus(s,"completed");this.activeIndex=this.currentSteps.length-1,this.completed=!0,this.showSuccess=!0,this.showConfetti=!0}this.dispatchEvent(new CustomEvent("icpay-progress-widget-coffee",{detail:{amount:t,currency:i,step:this.activeIndex},bubbles:!0}))}}connectedCallback(){super.connectedCallback();try{ie(this,this.theme)}catch{}this.currentSteps=[...this.steps],this.currentAmount=this.amount,this.currentCurrency=this.currency,this.currentLedgerSymbol=this.ledgerSymbol,this.attachSDKEventListeners()}disconnectedCallback(){super.disconnectedCallback(),this.detachSDKEventListeners(),this.stopAutomaticProgression()}updated(e){if(e.has("theme"))try{ie(this,this.theme)}catch{}}attachSDKEventListeners(){window.addEventListener("icpay-sdk-method-start",this.onMethodStart),window.addEventListener("icpay-sdk-method-success",this.onMethodSuccess),window.addEventListener("icpay-sdk-method-error",this.onMethodError),window.addEventListener("icpay-sdk-transaction-created",this.onTransactionCreated),window.addEventListener("icpay-sdk-transaction-updated",this.onTransactionUpdated),window.addEventListener("icpay-sdk-transaction-completed",this.onTransactionCompleted),window.addEventListener("icpay-sdk-transaction-failed",this.onTransactionFailed),window.addEventListener("icpay-sdk-transaction-mismatched",this.onTransactionMismatched),window.addEventListener("icpay-sdk-error",this.onSDKError),window.addEventListener("icpay-sdk-wallet-connected",this.onWalletConnected),window.addEventListener("icpay-sdk-wallet-disconnected",this.onWalletDisconnected),window.addEventListener("icpay-sdk-balance-check",this.onBalanceCheck),window.addEventListener("icpay-sdk-ledger-verified",this.onLedgerVerified),window.addEventListener("icpay-pay",this.onWidgetPayment),window.addEventListener("icpay-error",this.onWidgetError),window.addEventListener("icpay-unlock",this.onWidgetUnlock),window.addEventListener("icpay-tip",this.onWidgetTip),window.addEventListener("icpay-donation",this.onWidgetDonation),window.addEventListener("icpay-coffee",this.onWidgetCoffee)}detachSDKEventListeners(){window.removeEventListener("icpay-sdk-method-start",this.onMethodStart),window.removeEventListener("icpay-sdk-method-success",this.onMethodSuccess),window.removeEventListener("icpay-sdk-method-error",this.onMethodError),window.removeEventListener("icpay-sdk-transaction-created",this.onTransactionCreated),window.removeEventListener("icpay-sdk-transaction-updated",this.onTransactionUpdated),window.removeEventListener("icpay-sdk-transaction-completed",this.onTransactionCompleted),window.removeEventListener("icpay-sdk-transaction-failed",this.onTransactionFailed),window.removeEventListener("icpay-sdk-transaction-mismatched",this.onTransactionMismatched),window.removeEventListener("icpay-sdk-error",this.onSDKError),window.removeEventListener("icpay-sdk-wallet-connected",this.onWalletConnected),window.removeEventListener("icpay-sdk-wallet-disconnected",this.onWalletDisconnected),window.removeEventListener("icpay-sdk-balance-check",this.onBalanceCheck),window.removeEventListener("icpay-sdk-ledger-verified",this.onLedgerVerified),window.removeEventListener("icpay-pay",this.onWidgetPayment),window.removeEventListener("icpay-error",this.onWidgetError),window.removeEventListener("icpay-unlock",this.onWidgetUnlock),window.removeEventListener("icpay-tip",this.onWidgetTip),window.removeEventListener("icpay-donation",this.onWidgetDonation),window.removeEventListener("icpay-coffee",this.onWidgetCoffee)}startAutomaticProgression(){this.progressionTimer&&clearInterval(this.progressionTimer),this.activeIndex=1,this.updateStepStatus(this.activeIndex,"loading"),g(this.debug,"ICPay Progress: Starting automatic progression from step:",this.activeIndex),this.progressionTimer=setInterval(()=>{if(this.failed||this.completed){this.stopAutomaticProgression();return}g(this.debug,"ICPay Progress: Processing step:",this.activeIndex),this.updateStepStatus(this.activeIndex,"completed"),this.activeIndex<this.currentSteps.length-1?(this.activeIndex++,this.updateStepStatus(this.activeIndex,"loading"),g(this.debug,"ICPay Progress: Auto-progressed to step:",this.activeIndex)):(this.stopAutomaticProgression(),g(this.debug,"ICPay Progress: All steps completed, waiting for transaction completion")),this.requestUpdate()},3e3)}stopAutomaticProgression(){this.progressionTimer&&(clearInterval(this.progressionTimer),this.progressionTimer=null)}updateStepStatus(e,t,i){if(e>=0&&e<this.currentSteps.length){let s=this.currentSteps[e],r=s.status;s.status=t,t==="completed"&&(s.timestamp=this.getCurrentTime()),t==="error"&&i&&(s.errorMessage=this.transformErrorMessage(i)),g(this.debug,`ICPay Progress: Step ${e} (${s.label}) status changed from ${r} to ${t}`),this.requestUpdate()}}getCurrentTime(){return new Date().toLocaleTimeString("en-US",{hour12:!1,hour:"2-digit",minute:"2-digit",second:"2-digit"})}getStepIcon(e){switch(e.status){case"loading":return f`<div class="loading-spinner"></div>`;case"completed":return f`<svg fill="none" viewBox="0 0 24 24" stroke="currentColor">
60
60
  <path stroke-linecap="round" stroke-linejoin="round" d="M5 13l4 4L19 7" />
61
61
  </svg>`;case"error":return f`<svg fill="none" viewBox="0 0 24 24" stroke="currentColor">
62
62
  <path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />
@@ -963,7 +963,7 @@ import{a as n}from"./chunk-LTEQ7OUJ.js";import{css as De}from"lit";var U=De`
963
963
  ${null}
964
964
  </div>
965
965
  </div>
966
- `}var Se=typeof window<"u",re=null;function G(a,l,e){a&&(e!==void 0?console.log(`[ICPay Widget] ${l}`,e):console.log(`[ICPay Widget] ${l}`))}var w=class extends Qe{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.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)return;if(await this.pnp.disconnect(),(e?.detail?.walletType||"").toLowerCase()==="ii")try{window.open("https://identity.ic0.app/","_blank","noopener,noreferrer")}catch{}this.pendingAction="pay",this.walletConnected=!1,this.showWalletModal=!0,this.requestUpdate()}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;re||(re=(await import("@windoge98/plug-n-play")).PNP);let i={...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:r}=await import("./origin-44ZEXSX4.js");i.derivationOrigin=this.config?.derivationOrigin||r()}}catch{}let s=new re(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(),!!Se){G(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(!(!Se||!this.config?.publishableKey))try{let t=await h(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(Se&&!(this.processing||this.unlocked)){G(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){G(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{re||(re=(await import("@windoge98/plug-n-play")).PNP);let o={...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:d}=await import("./origin-44ZEXSX4.js");o.derivationOrigin=this.config?.derivationOrigin||d()}}catch{}this.pnp=new re(o);let c=this.pnp.getEnabledWallets();if(G(this.config?.debug||!1,"Available wallets",c),!c?.length)throw new Error("No wallets available");this.pendingAction="pay",this.showWalletModal=!0;return}catch(o){G(this.config?.debug||!1,"Wallet connection error:",o),this.errorMessage=o instanceof Error?o.message:"Wallet connection failed",this.errorSeverity="error";return}}G(this.config?.debug||!1,"Creating SDK for payment");let e=h(this.config),t=this.selectedSymbol||this.config?.defaultSymbol||"ICP",s=this.cryptoOptions.find(o=>o.symbol===t).canisterId||await e.client.getLedgerCanisterIdBySymbol(t);G(this.config?.debug||!1,"Payment details",{priceUsd:this.config.priceUsd,selectedSymbol:t,canisterId:s});let r=await e.sendUsd(this.config.priceUsd,s,{context:"premium-content"});G(this.config?.debug||!1,"Payment completed",{resp:r}),this.unlocked=!0,this.succeeded=!0,this.config.onSuccess&&this.config.onSuccess({id:r.transactionId,status:r.status}),this.dispatchEvent(new CustomEvent("icpay-unlock",{detail:{amount:this.config.priceUsd,tx:r},bubbles:!0}))}catch(e){C(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),L(t)&&(this.errorMessage=O(t),this.errorSeverity=A(t),this.errorAction=W(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=h(this.config),t=this.selectedSymbol||this.config?.defaultSymbol||"ICP",s=this.cryptoOptions.find(p=>p.symbol===t).canisterId||await e.client.getLedgerCanisterIdBySymbol(t),r=await e.startOnrampUsd(this.config.priceUsd,s,{context:"premium:onramp"}),o=r?.metadata?.onramp?.sessionId||r?.metadata?.onramp?.session_id||null,c=r?.metadata?.paymentIntentId||r?.paymentIntentId||null,d=r?.metadata?.onramp?.errorMessage||null;this.onrampPaymentIntentId=c,o?(this.onrampSessionId=o,this.onrampErrorMessage=null,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.onrampErrorMessage=d||"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=h(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}async connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");let t=await this.pnp.connect(e);if(!!!(t&&(t.connected===!0||t.principal||t.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{}this.config={...this.config,connectedWallet:t,actorProvider:(r,o)=>this.pnp.getActor({canisterId:r,idl:o,requiresSigning:!0,anon:!1})},this.showWalletModal=!1;let s=this.pendingAction;this.pendingAction=null,s==="pay"&&setTimeout(()=>this.onPay(),0)}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}render(){return this.config?se`
966
+ `}var Se=typeof window<"u",re=null;function G(a,l,e){a&&(e!==void 0?console.log(`[ICPay Widget] ${l}`,e):console.log(`[ICPay Widget] ${l}`))}var x=class extends Qe{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.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)return;if(await this.pnp.disconnect(),(e?.detail?.walletType||"").toLowerCase()==="ii")try{window.open("https://identity.ic0.app/","_blank","noopener,noreferrer")}catch{}this.pendingAction="pay",this.walletConnected=!1,this.showWalletModal=!0,this.requestUpdate()}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;re||(re=(await import("@windoge98/plug-n-play")).PNP);let i={...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:r}=await import("./origin-44ZEXSX4.js");i.derivationOrigin=this.config?.derivationOrigin||r()}}catch{}let s=new re(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(),!!Se){G(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(!(!Se||!this.config?.publishableKey))try{let t=await h(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(Se&&!(this.processing||this.unlocked)){G(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){G(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{re||(re=(await import("@windoge98/plug-n-play")).PNP);let o={...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:d}=await import("./origin-44ZEXSX4.js");o.derivationOrigin=this.config?.derivationOrigin||d()}}catch{}this.pnp=new re(o);let c=this.pnp.getEnabledWallets();if(G(this.config?.debug||!1,"Available wallets",c),!c?.length)throw new Error("No wallets available");this.pendingAction="pay",this.showWalletModal=!0;return}catch(o){G(this.config?.debug||!1,"Wallet connection error:",o),this.errorMessage=o instanceof Error?o.message:"Wallet connection failed",this.errorSeverity="error";return}}G(this.config?.debug||!1,"Creating SDK for payment");let e=h(this.config),t=this.selectedSymbol||this.config?.defaultSymbol||"ICP",s=this.cryptoOptions.find(o=>o.symbol===t).canisterId||await e.client.getLedgerCanisterIdBySymbol(t);G(this.config?.debug||!1,"Payment details",{priceUsd:this.config.priceUsd,selectedSymbol:t,canisterId:s});let r=await e.sendUsd(this.config.priceUsd,s,{context:"premium-content"});G(this.config?.debug||!1,"Payment completed",{resp:r}),this.unlocked=!0,this.succeeded=!0,this.config.onSuccess&&this.config.onSuccess({id:r.transactionId,status:r.status}),this.dispatchEvent(new CustomEvent("icpay-unlock",{detail:{amount:this.config.priceUsd,tx:r},bubbles:!0}))}catch(e){C(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),L(t)&&(this.errorMessage=O(t),this.errorSeverity=A(t),this.errorAction=W(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=h(this.config),t=this.selectedSymbol||this.config?.defaultSymbol||"ICP",s=this.cryptoOptions.find(p=>p.symbol===t).canisterId||await e.client.getLedgerCanisterIdBySymbol(t),r=await e.startOnrampUsd(this.config.priceUsd,s,{context:"premium:onramp"}),o=r?.metadata?.onramp?.sessionId||r?.metadata?.onramp?.session_id||null,c=r?.metadata?.paymentIntentId||r?.paymentIntentId||null,d=r?.metadata?.onramp?.errorMessage||null;this.onrampPaymentIntentId=c,o?(this.onrampSessionId=o,this.onrampErrorMessage=null,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.onrampErrorMessage=d||"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=h(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}async connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");let t=await this.pnp.connect(e);if(!!!(t&&(t.connected===!0||t.principal||t.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{}this.config={...this.config,connectedWallet:t,actorProvider:(r,o)=>this.pnp.getActor({canisterId:r,idl:o,requiresSigning:!0,anon:!1})},this.showWalletModal=!1;let s=this.pendingAction;this.pendingAction=null,s==="pay"&&setTimeout(()=>this.onPay(),0)}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}render(){return this.config?se`
967
967
  <div class="icpay-card icpay-section icpay-widget-base">
968
968
  ${this.config?.progressBar?.enabled!==!1?se`
969
969
  <icpay-progress-bar
@@ -1011,7 +1011,7 @@ import{a as n}from"./chunk-LTEQ7OUJ.js";import{css as De}from"lit";var U=De`
1011
1011
 
1012
1012
  ${this.showOnrampModal?$({visible:this.showOnrampModal,sessionId:this.onrampSessionId,errorMessage:this.onrampErrorMessage,apiKey:this.config?.onramp?.apiKey,environment:this.config?.onramp?.environment||"STAGING",width:this.config?.onramp?.width,height:this.config?.onramp?.height,onClose:()=>{this.showOnrampModal=!1},onBack:()=>{this.showOnrampModal=!1,this.showWalletModal=!0}}):null}
1013
1013
  </div>
1014
- `:se`<div class="icpay-card icpay-section">Loading...</div>`}};w.styles=[U,_e`
1014
+ `:se`<div class="icpay-card icpay-section">Loading...</div>`}};x.styles=[U,_e`
1015
1015
  .image-container {
1016
1016
  position: relative;
1017
1017
  border-radius: 16px;
@@ -1062,7 +1062,7 @@ import{a as n}from"./chunk-LTEQ7OUJ.js";import{css as De}from"lit";var U=De`
1062
1062
  border-color: rgba(239, 68, 68, 0.3);
1063
1063
  color: #ef4444;
1064
1064
  }
1065
- `],n([tt({type:Object})],w.prototype,"config",2),n([T()],w.prototype,"selectedSymbol",2),n([T()],w.prototype,"unlocked",2),n([T()],w.prototype,"succeeded",2),n([T()],w.prototype,"processing",2),n([T()],w.prototype,"availableLedgers",2),n([T()],w.prototype,"errorMessage",2),n([T()],w.prototype,"errorSeverity",2),n([T()],w.prototype,"errorAction",2),n([T()],w.prototype,"walletConnected",2),n([T()],w.prototype,"pendingAction",2),n([T()],w.prototype,"showWalletModal",2),n([T()],w.prototype,"showOnrampModal",2),n([T()],w.prototype,"onrampSessionId",2),n([T()],w.prototype,"onrampPaymentIntentId",2),n([T()],w.prototype,"onrampErrorMessage",2),w=n([et("icpay-premium-content")],w);import{LitElement as it,html as ee,css as nt}from"lit";import{customElement as st,property as rt,state as E}from"lit/decorators.js";var ke=typeof window<"u",ae=null;function Y(a,l,e){a&&(e!==void 0?console.log(`[ICPay Widget] ${l}`,e):console.log(`[ICPay Widget] ${l}`))}var y=class extends it{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.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)return;if(await this.pnp.disconnect(),(e?.detail?.walletType||"").toLowerCase()==="ii")try{window.open("https://identity.ic0.app/","_blank","noopener,noreferrer")}catch{}this.pendingAction="tip",this.walletConnected=!1,this.showWalletModal=!0,this.requestUpdate()}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;ae||(ae=(await import("@windoge98/plug-n-play")).PNP);let i={...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:r}=await import("./origin-44ZEXSX4.js");i.derivationOrigin=this.config?.derivationOrigin||r()}}catch{}let s=new ae(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(),!!ke){Y(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(!(!ke||!this.config?.publishableKey))try{let t=await h(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(ke&&(Y(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){Y(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{ae||(ae=(await import("@windoge98/plug-n-play")).PNP);let o={...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:d}=await import("./origin-44ZEXSX4.js");o.derivationOrigin=this.config?.derivationOrigin||d()}}catch{}this.pnp=new ae(o);let c=this.pnp.getEnabledWallets();if(Y(this.config?.debug||!1,"Available wallets",c),!c?.length)throw new Error("No wallets available");this.pendingAction="tip",this.showWalletModal=!0;return}catch(o){Y(this.config?.debug||!1,"Wallet connection error:",o),this.errorMessage=o instanceof Error?o.message:"Wallet connection failed",this.errorSeverity="error";return}}Y(this.config?.debug||!1,"Creating SDK for payment");let e=h(this.config),t=this.selectedSymbol||this.config?.defaultSymbol||"ICP",s=this.cryptoOptions.find(o=>o.symbol===t).canisterId||await e.client.getLedgerCanisterIdBySymbol(t);Y(this.config?.debug||!1,"Tip payment details",{amount:this.selectedAmount,selectedSymbol:t,canisterId:s});let r=await e.sendUsd(this.selectedAmount,s,{context:"tip-jar"});Y(this.config?.debug||!1,"Tip payment completed",{resp:r}),this.total+=this.selectedAmount,this.succeeded=!0,this.config.onSuccess&&this.config.onSuccess({id:r.transactionId,status:r.status,total:this.total}),this.dispatchEvent(new CustomEvent("icpay-tip",{detail:{amount:this.selectedAmount,tx:r},bubbles:!0}))}catch(e){C(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),L(t)&&(this.errorMessage=O(t),this.errorSeverity=A(t),this.errorAction=W(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=h(this.config),t=this.selectedSymbol||this.config?.defaultSymbol||"ICP",s=this.cryptoOptions.find(p=>p.symbol===t).canisterId||await e.client.getLedgerCanisterIdBySymbol(t),r=await e.startOnrampUsd(this.selectedAmount,s,{context:"tip:onramp"}),o=r?.metadata?.onramp?.sessionId||r?.metadata?.onramp?.session_id||null,c=r?.metadata?.paymentIntentId||r?.paymentIntentId||null,d=r?.metadata?.onramp?.errorMessage||null;this.onrampPaymentIntentId=c,o?(this.onrampSessionId=o,this.onrampErrorMessage=null,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.onrampErrorMessage=d||"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=h(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}async connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");let t=await this.pnp.connect(e);if(!!!(t&&(t.connected===!0||t.principal||t.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{}this.config={...this.config,connectedWallet:t,actorProvider:(r,o)=>this.pnp.getActor({canisterId:r,idl:o,requiresSigning:!0,anon:!1})},this.showWalletModal=!1;let s=this.pendingAction;this.pendingAction=null,s==="tip"&&setTimeout(()=>this.tip(),0)}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}render(){if(!this.config)return ee`<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",r=s!=="none"&&(t||s==="dropdown"),o=s==="dropdown"?"dropdown":t?"buttons":"none";return ee`
1065
+ `],n([tt({type:Object})],x.prototype,"config",2),n([T()],x.prototype,"selectedSymbol",2),n([T()],x.prototype,"unlocked",2),n([T()],x.prototype,"succeeded",2),n([T()],x.prototype,"processing",2),n([T()],x.prototype,"availableLedgers",2),n([T()],x.prototype,"errorMessage",2),n([T()],x.prototype,"errorSeverity",2),n([T()],x.prototype,"errorAction",2),n([T()],x.prototype,"walletConnected",2),n([T()],x.prototype,"pendingAction",2),n([T()],x.prototype,"showWalletModal",2),n([T()],x.prototype,"showOnrampModal",2),n([T()],x.prototype,"onrampSessionId",2),n([T()],x.prototype,"onrampPaymentIntentId",2),n([T()],x.prototype,"onrampErrorMessage",2),x=n([et("icpay-premium-content")],x);import{LitElement as it,html as ee,css as nt}from"lit";import{customElement as st,property as rt,state as E}from"lit/decorators.js";var ke=typeof window<"u",ae=null;function Y(a,l,e){a&&(e!==void 0?console.log(`[ICPay Widget] ${l}`,e):console.log(`[ICPay Widget] ${l}`))}var y=class extends it{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.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)return;if(await this.pnp.disconnect(),(e?.detail?.walletType||"").toLowerCase()==="ii")try{window.open("https://identity.ic0.app/","_blank","noopener,noreferrer")}catch{}this.pendingAction="tip",this.walletConnected=!1,this.showWalletModal=!0,this.requestUpdate()}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;ae||(ae=(await import("@windoge98/plug-n-play")).PNP);let i={...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:r}=await import("./origin-44ZEXSX4.js");i.derivationOrigin=this.config?.derivationOrigin||r()}}catch{}let s=new ae(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(),!!ke){Y(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(!(!ke||!this.config?.publishableKey))try{let t=await h(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(ke&&(Y(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){Y(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{ae||(ae=(await import("@windoge98/plug-n-play")).PNP);let o={...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:d}=await import("./origin-44ZEXSX4.js");o.derivationOrigin=this.config?.derivationOrigin||d()}}catch{}this.pnp=new ae(o);let c=this.pnp.getEnabledWallets();if(Y(this.config?.debug||!1,"Available wallets",c),!c?.length)throw new Error("No wallets available");this.pendingAction="tip",this.showWalletModal=!0;return}catch(o){Y(this.config?.debug||!1,"Wallet connection error:",o),this.errorMessage=o instanceof Error?o.message:"Wallet connection failed",this.errorSeverity="error";return}}Y(this.config?.debug||!1,"Creating SDK for payment");let e=h(this.config),t=this.selectedSymbol||this.config?.defaultSymbol||"ICP",s=this.cryptoOptions.find(o=>o.symbol===t).canisterId||await e.client.getLedgerCanisterIdBySymbol(t);Y(this.config?.debug||!1,"Tip payment details",{amount:this.selectedAmount,selectedSymbol:t,canisterId:s});let r=await e.sendUsd(this.selectedAmount,s,{context:"tip-jar"});Y(this.config?.debug||!1,"Tip payment completed",{resp:r}),this.total+=this.selectedAmount,this.succeeded=!0,this.config.onSuccess&&this.config.onSuccess({id:r.transactionId,status:r.status,total:this.total}),this.dispatchEvent(new CustomEvent("icpay-tip",{detail:{amount:this.selectedAmount,tx:r},bubbles:!0}))}catch(e){C(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),L(t)&&(this.errorMessage=O(t),this.errorSeverity=A(t),this.errorAction=W(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=h(this.config),t=this.selectedSymbol||this.config?.defaultSymbol||"ICP",s=this.cryptoOptions.find(p=>p.symbol===t).canisterId||await e.client.getLedgerCanisterIdBySymbol(t),r=await e.startOnrampUsd(this.selectedAmount,s,{context:"tip:onramp"}),o=r?.metadata?.onramp?.sessionId||r?.metadata?.onramp?.session_id||null,c=r?.metadata?.paymentIntentId||r?.paymentIntentId||null,d=r?.metadata?.onramp?.errorMessage||null;this.onrampPaymentIntentId=c,o?(this.onrampSessionId=o,this.onrampErrorMessage=null,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.onrampErrorMessage=d||"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=h(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}async connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");let t=await this.pnp.connect(e);if(!!!(t&&(t.connected===!0||t.principal||t.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{}this.config={...this.config,connectedWallet:t,actorProvider:(r,o)=>this.pnp.getActor({canisterId:r,idl:o,requiresSigning:!0,anon:!1})},this.showWalletModal=!1;let s=this.pendingAction;this.pendingAction=null,s==="tip"&&setTimeout(()=>this.tip(),0)}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}render(){if(!this.config)return ee`<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",r=s!=="none"&&(t||s==="dropdown"),o=s==="dropdown"?"dropdown":t?"buttons":"none";return ee`
1066
1066
  <div class="icpay-card icpay-section icpay-widget-base" style="text-align:center;">
1067
1067
  ${this.config?.progressBar?.enabled!==!1?ee`
1068
1068
  <icpay-progress-bar
@@ -1107,7 +1107,7 @@ import{a as n}from"./chunk-LTEQ7OUJ.js";import{css as De}from"lit";var U=De`
1107
1107
  `:""}
1108
1108
  </div>
1109
1109
  `:""}
1110
- ${(()=>{let d=(this.pnp?.getEnabledWallets?.()||[]).map(p=>({id:this.getWalletId(p),label:this.getWalletLabel(p),icon:this.getWalletIcon(p)}));return B({visible:!!(this.showWalletModal&&this.pnp),wallets:d,isConnecting:!1,onSelect:p=>this.connectWithWallet(p),onClose:()=>{this.showWalletModal=!1},onCreditCard:this.config?.onramp?.enabled!==!1?()=>this.startOnramp():void 0,creditCardLabel:this.config?.onramp?.creditCardLabel||"Pay with credit card",showCreditCard:this.config?.onramp?.enabled!==!1,creditCardTooltip:(()=>{let k=Number(this.selectedAmount||this.config?.defaultAmountUsd||0);return k>0&&k<5&&this.config?.onramp?.enabled!==!1?`Note: Minimum card amount is $5. You will pay about $${(5-k).toFixed(2)} more.`:null})()})})()}
1110
+ ${(()=>{let d=(this.pnp?.getEnabledWallets?.()||[]).map(p=>({id:this.getWalletId(p),label:this.getWalletLabel(p),icon:this.getWalletIcon(p)}));return B({visible:!!(this.showWalletModal&&this.pnp),wallets:d,isConnecting:!1,onSelect:p=>this.connectWithWallet(p),onClose:()=>{this.showWalletModal=!1},onCreditCard:this.config?.onramp?.enabled!==!1?()=>this.startOnramp():void 0,creditCardLabel:this.config?.onramp?.creditCardLabel||"Pay with credit card",showCreditCard:this.config?.onramp?.enabled!==!1,creditCardTooltip:(()=>{let w=Number(this.selectedAmount||this.config?.defaultAmountUsd||0);return w>0&&w<5&&this.config?.onramp?.enabled!==!1?`Note: Minimum card amount is $5. You will pay about $${(5-w).toFixed(2)} more.`:null})()})})()}
1111
1111
 
1112
1112
  ${this.showOnrampModal?$({visible:this.showOnrampModal,sessionId:this.onrampSessionId,errorMessage:this.onrampErrorMessage,apiKey:this.config?.onramp?.apiKey,environment:this.config?.onramp?.environment||"STAGING",width:this.config?.onramp?.width,height:this.config?.onramp?.height,onClose:()=>{this.showOnrampModal=!1},onBack:()=>{this.showOnrampModal=!1,this.showWalletModal=!0}}):null}
1113
1113
  </div>
@@ -1221,7 +1221,7 @@ import{a as n}from"./chunk-LTEQ7OUJ.js";import{css as De}from"lit";var U=De`
1221
1221
  border-color: rgba(239, 68, 68, 0.3);
1222
1222
  color: #ef4444;
1223
1223
  }
1224
- `],n([we({type:Object})],m.prototype,"config",2),n([we({type:String})],m.prototype,"title",2),n([we({type:String})],m.prototype,"preview",2),n([we({type:String})],m.prototype,"lockedContent",2),n([N()],m.prototype,"selectedSymbol",2),n([N()],m.prototype,"unlocked",2),n([N()],m.prototype,"succeeded",2),n([N()],m.prototype,"processing",2),n([N()],m.prototype,"availableLedgers",2),n([N()],m.prototype,"errorMessage",2),n([N()],m.prototype,"errorSeverity",2),n([N()],m.prototype,"errorAction",2),n([N()],m.prototype,"walletConnected",2),n([N()],m.prototype,"pendingAction",2),n([N()],m.prototype,"showWalletModal",2),n([N()],m.prototype,"showOnrampModal",2),n([N()],m.prototype,"onrampSessionId",2),n([N()],m.prototype,"onrampPaymentIntentId",2),n([N()],m.prototype,"onrampErrorMessage",2),m=n([lt("icpay-article-paywall")],m);import{LitElement as ct,html as ce,css as dt}from"lit";import{customElement as pt,property as ht,state as D}from"lit/decorators.js";var Me=typeof window<"u",Ie=null;function J(a,l,e){a&&(e!==void 0?console.log(`[ICPay Widget] ${l}`,e):console.log(`[ICPay Widget] ${l}`))}var x=class extends ct{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.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)return;if(await this.pnp.disconnect(),(e?.detail?.walletType||"").toLowerCase()==="ii")try{window.open("https://identity.ic0.app/","_blank","noopener,noreferrer")}catch{}this.pendingAction="order",this.walletConnected=!1,this.showWalletModal=!0,this.requestUpdate()}catch{}}}get cryptoOptions(){return this.config.cryptoOptions?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){if(super.connectedCallback(),!!Me){J(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(!(!Me||!this.config?.publishableKey))try{let t=await h(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(Me&&!this.processing){J(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){J(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{Ie||(Ie=(await import("@windoge98/plug-n-play")).PNP);let o={...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:d}=await import("./origin-44ZEXSX4.js");o.derivationOrigin=this.config?.derivationOrigin||d()}}catch{}this.pnp=new Ie(o);let c=this.pnp.getEnabledWallets();if(J(this.config?.debug||!1,"Available wallets",c),!c?.length)throw new Error("No wallets available");this.pendingAction="order",this.showWalletModal=!0;return}catch(o){J(this.config?.debug||!1,"Wallet connection error:",o),this.errorMessage=o instanceof Error?o.message:"Wallet connection failed",this.errorSeverity="error";return}}J(this.config?.debug||!1,"Creating SDK for payment");let e=h(this.config),t=this.selectedSymbol||this.config?.defaultSymbol||"ICP",s=this.cryptoOptions.find(o=>o.symbol===t).canisterId||await e.client.getLedgerCanisterIdBySymbol(t);J(this.config?.debug||!1,"Coffee order payment details",{item:this.selectedItem.name,priceUsd:this.selectedItem.priceUsd,selectedSymbol:t,canisterId:s});let r=await e.sendUsd(this.selectedItem.priceUsd,s,{context:"coffee",item:this.selectedItem.name});J(this.config?.debug||!1,"Coffee order payment completed",{resp:r}),this.config.onSuccess&&this.config.onSuccess({id:r.transactionId,status:r.status,item:this.selectedItem.name}),this.dispatchEvent(new CustomEvent("icpay-coffee",{detail:{item:this.selectedItem,tx:r},bubbles:!0}))}catch(e){C(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),L(t)&&(this.errorMessage=O(t),this.errorSeverity=A(t),this.errorAction=W(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=h(this.config),t=this.selectedSymbol||this.config?.defaultSymbol||"ICP",s=this.cryptoOptions.find(p=>p.symbol===t).canisterId||await e.client.getLedgerCanisterIdBySymbol(t),r=await e.startOnrampUsd(this.selectedItem.priceUsd,s,{context:"coffee:onramp",item:this.selectedItem.name}),o=r?.metadata?.onramp?.sessionId||r?.metadata?.onramp?.session_id||null,c=r?.metadata?.paymentIntentId||r?.paymentIntentId||null,d=r?.metadata?.onramp?.errorMessage||null;this.onrampPaymentIntentId=c,o?(this.onrampSessionId=o,this.onrampErrorMessage=null,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.onrampErrorMessage=d||"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=h(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}async connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");let t=await this.pnp.connect(e);if(!!!(t&&(t.connected===!0||t.principal||t.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{}this.config={...this.config,connectedWallet:t,actorProvider:(r,o)=>this.pnp.getActor({canisterId:r,idl:o,requiresSigning:!0,anon:!1})},this.showWalletModal=!1;let s=this.pendingAction;this.pendingAction=null,s==="order"&&setTimeout(()=>this.order(),0)}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}render(){return this.config?ce`
1224
+ `],n([we({type:Object})],m.prototype,"config",2),n([we({type:String})],m.prototype,"title",2),n([we({type:String})],m.prototype,"preview",2),n([we({type:String})],m.prototype,"lockedContent",2),n([N()],m.prototype,"selectedSymbol",2),n([N()],m.prototype,"unlocked",2),n([N()],m.prototype,"succeeded",2),n([N()],m.prototype,"processing",2),n([N()],m.prototype,"availableLedgers",2),n([N()],m.prototype,"errorMessage",2),n([N()],m.prototype,"errorSeverity",2),n([N()],m.prototype,"errorAction",2),n([N()],m.prototype,"walletConnected",2),n([N()],m.prototype,"pendingAction",2),n([N()],m.prototype,"showWalletModal",2),n([N()],m.prototype,"showOnrampModal",2),n([N()],m.prototype,"onrampSessionId",2),n([N()],m.prototype,"onrampPaymentIntentId",2),n([N()],m.prototype,"onrampErrorMessage",2),m=n([lt("icpay-article-paywall")],m);import{LitElement as ct,html as ce,css as dt}from"lit";import{customElement as pt,property as ht,state as D}from"lit/decorators.js";var Me=typeof window<"u",Ie=null;function J(a,l,e){a&&(e!==void 0?console.log(`[ICPay Widget] ${l}`,e):console.log(`[ICPay Widget] ${l}`))}var S=class extends ct{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.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)return;if(await this.pnp.disconnect(),(e?.detail?.walletType||"").toLowerCase()==="ii")try{window.open("https://identity.ic0.app/","_blank","noopener,noreferrer")}catch{}this.pendingAction="order",this.walletConnected=!1,this.showWalletModal=!0,this.requestUpdate()}catch{}}}get cryptoOptions(){return this.config.cryptoOptions?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){if(super.connectedCallback(),!!Me){J(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(!(!Me||!this.config?.publishableKey))try{let t=await h(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(Me&&!this.processing){J(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){J(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{Ie||(Ie=(await import("@windoge98/plug-n-play")).PNP);let o={...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:d}=await import("./origin-44ZEXSX4.js");o.derivationOrigin=this.config?.derivationOrigin||d()}}catch{}this.pnp=new Ie(o);let c=this.pnp.getEnabledWallets();if(J(this.config?.debug||!1,"Available wallets",c),!c?.length)throw new Error("No wallets available");this.pendingAction="order",this.showWalletModal=!0;return}catch(o){J(this.config?.debug||!1,"Wallet connection error:",o),this.errorMessage=o instanceof Error?o.message:"Wallet connection failed",this.errorSeverity="error";return}}J(this.config?.debug||!1,"Creating SDK for payment");let e=h(this.config),t=this.selectedSymbol||this.config?.defaultSymbol||"ICP",s=this.cryptoOptions.find(o=>o.symbol===t).canisterId||await e.client.getLedgerCanisterIdBySymbol(t);J(this.config?.debug||!1,"Coffee order payment details",{item:this.selectedItem.name,priceUsd:this.selectedItem.priceUsd,selectedSymbol:t,canisterId:s});let r=await e.sendUsd(this.selectedItem.priceUsd,s,{context:"coffee",item:this.selectedItem.name});J(this.config?.debug||!1,"Coffee order payment completed",{resp:r}),this.config.onSuccess&&this.config.onSuccess({id:r.transactionId,status:r.status,item:this.selectedItem.name}),this.dispatchEvent(new CustomEvent("icpay-coffee",{detail:{item:this.selectedItem,tx:r},bubbles:!0}))}catch(e){C(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),L(t)&&(this.errorMessage=O(t),this.errorSeverity=A(t),this.errorAction=W(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=h(this.config),t=this.selectedSymbol||this.config?.defaultSymbol||"ICP",s=this.cryptoOptions.find(p=>p.symbol===t).canisterId||await e.client.getLedgerCanisterIdBySymbol(t),r=await e.startOnrampUsd(this.selectedItem.priceUsd,s,{context:"coffee:onramp",item:this.selectedItem.name}),o=r?.metadata?.onramp?.sessionId||r?.metadata?.onramp?.session_id||null,c=r?.metadata?.paymentIntentId||r?.paymentIntentId||null,d=r?.metadata?.onramp?.errorMessage||null;this.onrampPaymentIntentId=c,o?(this.onrampSessionId=o,this.onrampErrorMessage=null,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.onrampErrorMessage=d||"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=h(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}async connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");let t=await this.pnp.connect(e);if(!!!(t&&(t.connected===!0||t.principal||t.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{}this.config={...this.config,connectedWallet:t,actorProvider:(r,o)=>this.pnp.getActor({canisterId:r,idl:o,requiresSigning:!0,anon:!1})},this.showWalletModal=!1;let s=this.pendingAction;this.pendingAction=null,s==="order"&&setTimeout(()=>this.order(),0)}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}render(){return this.config?ce`
1225
1225
  <div class="icpay-card icpay-section icpay-widget-base">
1226
1226
  ${this.config?.progressBar?.enabled!==!1?ce`
1227
1227
  <icpay-progress-bar
@@ -1270,7 +1270,7 @@ import{a as n}from"./chunk-LTEQ7OUJ.js";import{css as De}from"lit";var U=De`
1270
1270
 
1271
1271
  ${this.showOnrampModal?$({visible:this.showOnrampModal,sessionId:this.onrampSessionId,errorMessage:this.onrampErrorMessage,apiKey:this.config?.onramp?.apiKey,environment:this.config?.onramp?.environment||"STAGING",width:this.config?.onramp?.width,height:this.config?.onramp?.height,onClose:()=>{this.showOnrampModal=!1},onBack:()=>{this.showOnrampModal=!1,this.showWalletModal=!0}}):null}
1272
1272
  </div>
1273
- `:ce`<div class="icpay-card icpay-section">Loading...</div>`}};x.styles=[U,dt`
1273
+ `:ce`<div class="icpay-card icpay-section">Loading...</div>`}};S.styles=[U,dt`
1274
1274
  .menu { display: grid; gap: 8px; margin-bottom: 12px; }
1275
1275
  .item { background: var(--icpay-surface-alt); border: 2px solid var(--icpay-border); border-radius: 12px; padding: 16px; display:flex; justify-content: space-between; align-items:center; cursor: pointer; color: var(--icpay-text); font-weight: 600; }
1276
1276
  .item.selected { background: var(--icpay-primary); color: #111827; border-color: var(--icpay-primary); }
@@ -1301,7 +1301,7 @@ import{a as n}from"./chunk-LTEQ7OUJ.js";import{css as De}from"lit";var U=De`
1301
1301
  border-color: rgba(239, 68, 68, 0.3);
1302
1302
  color: #ef4444;
1303
1303
  }
1304
- `],n([ht({type:Object})],x.prototype,"config",2),n([D()],x.prototype,"selectedIndex",2),n([D()],x.prototype,"selectedSymbol",2),n([D()],x.prototype,"processing",2),n([D()],x.prototype,"availableLedgers",2),n([D()],x.prototype,"errorMessage",2),n([D()],x.prototype,"errorSeverity",2),n([D()],x.prototype,"errorAction",2),n([D()],x.prototype,"walletConnected",2),n([D()],x.prototype,"pendingAction",2),n([D()],x.prototype,"showWalletModal",2),n([D()],x.prototype,"showOnrampModal",2),n([D()],x.prototype,"onrampSessionId",2),n([D()],x.prototype,"onrampPaymentIntentId",2),n([D()],x.prototype,"onrampErrorMessage",2),x=n([pt("icpay-coffee-shop")],x);import{LitElement as gt,html as de,css as ut}from"lit";import{customElement as mt,property as ft,state as M}from"lit/decorators.js";var Ce=typeof window<"u",pe=null;function q(a,l,e){a&&(e!==void 0?console.log(`[ICPay Widget] ${l}`,e):console.log(`[ICPay Widget] ${l}`))}var b=class extends gt{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.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)return;if(await this.pnp.disconnect(),(e?.detail?.walletType||"").toLowerCase()==="ii")try{window.open("https://identity.ic0.app/","_blank","noopener,noreferrer")}catch{}this.pendingAction="donate",this.walletConnected=!1,this.showWalletModal=!0,this.requestUpdate()}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;pe||(pe=(await import("@windoge98/plug-n-play")).PNP);let i={...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:r}=await import("./origin-44ZEXSX4.js");i.derivationOrigin=this.config?.derivationOrigin||r()}}catch{}let s=new pe(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(),!!Ce){q(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(!(!Ce||!this.config?.publishableKey))try{let t=await h(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(Ce&&!this.processing){q(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){q(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{pe||(pe=(await import("@windoge98/plug-n-play")).PNP);let o={...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:d}=await import("./origin-44ZEXSX4.js");o.derivationOrigin=this.config?.derivationOrigin||d()}}catch{}this.pnp=new pe(o);let c=this.pnp.getEnabledWallets();if(q(this.config?.debug||!1,"Available wallets",c),!c?.length)throw new Error("No wallets available");this.pendingAction="donate",this.showWalletModal=!0;return}catch(o){q(this.config?.debug||!1,"Wallet connection error:",o),this.errorMessage=o instanceof Error?o.message:"Wallet connection failed",this.errorSeverity="error";return}}q(this.config?.debug||!1,"Creating SDK for payment");let e=h(this.config),t=this.selectedSymbol||this.config?.defaultSymbol||"ICP",s=this.cryptoOptions.find(o=>o.symbol===t).canisterId||await e.client.getLedgerCanisterIdBySymbol(t);q(this.config?.debug||!1,"Donation payment details",{amount:this.selectedAmount,selectedSymbol:t,canisterId:s});let r=await e.sendUsd(this.selectedAmount,s,{context:"donation"});q(this.config?.debug||!1,"Donation payment completed",{resp:r}),this.raised+=this.selectedAmount,this.succeeded=!0,this.config.onSuccess&&this.config.onSuccess({id:r.transactionId,status:r.status,raised:this.raised}),this.dispatchEvent(new CustomEvent("icpay-donation",{detail:{amount:this.selectedAmount,tx:r},bubbles:!0}))}catch(e){C(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),L(t)&&(this.errorMessage=O(t),this.errorSeverity=A(t),this.errorAction=W(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=h(this.config),t=this.selectedSymbol||this.config?.defaultSymbol||"ICP",s=this.cryptoOptions.find(p=>p.symbol===t).canisterId||await e.client.getLedgerCanisterIdBySymbol(t),r=await e.startOnrampUsd(this.selectedAmount,s,{context:"donation:onramp"}),o=r?.metadata?.onramp?.sessionId||r?.metadata?.onramp?.session_id||null,c=r?.metadata?.paymentIntentId||r?.paymentIntentId||null,d=r?.metadata?.onramp?.errorMessage||null;this.onrampPaymentIntentId=c,o?(this.onrampSessionId=o,this.onrampErrorMessage=null,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.onrampErrorMessage=d||"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=h(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}async connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");let t=await this.pnp.connect(e);if(!!!(t&&(t.connected===!0||t.principal||t.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{}this.config={...this.config,connectedWallet:t,actorProvider:(r,o)=>this.pnp.getActor({canisterId:r,idl:o,requiresSigning:!0,anon:!1})},this.showWalletModal=!1;let s=this.pendingAction;this.pendingAction=null,s==="donate"&&setTimeout(()=>this.donate(),0)}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}render(){return this.config?de`
1304
+ `],n([ht({type:Object})],S.prototype,"config",2),n([D()],S.prototype,"selectedIndex",2),n([D()],S.prototype,"selectedSymbol",2),n([D()],S.prototype,"processing",2),n([D()],S.prototype,"availableLedgers",2),n([D()],S.prototype,"errorMessage",2),n([D()],S.prototype,"errorSeverity",2),n([D()],S.prototype,"errorAction",2),n([D()],S.prototype,"walletConnected",2),n([D()],S.prototype,"pendingAction",2),n([D()],S.prototype,"showWalletModal",2),n([D()],S.prototype,"showOnrampModal",2),n([D()],S.prototype,"onrampSessionId",2),n([D()],S.prototype,"onrampPaymentIntentId",2),n([D()],S.prototype,"onrampErrorMessage",2),S=n([pt("icpay-coffee-shop")],S);import{LitElement as gt,html as de,css as ut}from"lit";import{customElement as mt,property as ft,state as M}from"lit/decorators.js";var Ce=typeof window<"u",pe=null;function q(a,l,e){a&&(e!==void 0?console.log(`[ICPay Widget] ${l}`,e):console.log(`[ICPay Widget] ${l}`))}var b=class extends gt{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.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)return;if(await this.pnp.disconnect(),(e?.detail?.walletType||"").toLowerCase()==="ii")try{window.open("https://identity.ic0.app/","_blank","noopener,noreferrer")}catch{}this.pendingAction="donate",this.walletConnected=!1,this.showWalletModal=!0,this.requestUpdate()}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;pe||(pe=(await import("@windoge98/plug-n-play")).PNP);let i={...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:r}=await import("./origin-44ZEXSX4.js");i.derivationOrigin=this.config?.derivationOrigin||r()}}catch{}let s=new pe(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(),!!Ce){q(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(!(!Ce||!this.config?.publishableKey))try{let t=await h(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(Ce&&!this.processing){q(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){q(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{pe||(pe=(await import("@windoge98/plug-n-play")).PNP);let o={...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:d}=await import("./origin-44ZEXSX4.js");o.derivationOrigin=this.config?.derivationOrigin||d()}}catch{}this.pnp=new pe(o);let c=this.pnp.getEnabledWallets();if(q(this.config?.debug||!1,"Available wallets",c),!c?.length)throw new Error("No wallets available");this.pendingAction="donate",this.showWalletModal=!0;return}catch(o){q(this.config?.debug||!1,"Wallet connection error:",o),this.errorMessage=o instanceof Error?o.message:"Wallet connection failed",this.errorSeverity="error";return}}q(this.config?.debug||!1,"Creating SDK for payment");let e=h(this.config),t=this.selectedSymbol||this.config?.defaultSymbol||"ICP",s=this.cryptoOptions.find(o=>o.symbol===t).canisterId||await e.client.getLedgerCanisterIdBySymbol(t);q(this.config?.debug||!1,"Donation payment details",{amount:this.selectedAmount,selectedSymbol:t,canisterId:s});let r=await e.sendUsd(this.selectedAmount,s,{context:"donation"});q(this.config?.debug||!1,"Donation payment completed",{resp:r}),this.raised+=this.selectedAmount,this.succeeded=!0,this.config.onSuccess&&this.config.onSuccess({id:r.transactionId,status:r.status,raised:this.raised}),this.dispatchEvent(new CustomEvent("icpay-donation",{detail:{amount:this.selectedAmount,tx:r},bubbles:!0}))}catch(e){C(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),L(t)&&(this.errorMessage=O(t),this.errorSeverity=A(t),this.errorAction=W(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=h(this.config),t=this.selectedSymbol||this.config?.defaultSymbol||"ICP",s=this.cryptoOptions.find(p=>p.symbol===t).canisterId||await e.client.getLedgerCanisterIdBySymbol(t),r=await e.startOnrampUsd(this.selectedAmount,s,{context:"donation:onramp"}),o=r?.metadata?.onramp?.sessionId||r?.metadata?.onramp?.session_id||null,c=r?.metadata?.paymentIntentId||r?.paymentIntentId||null,d=r?.metadata?.onramp?.errorMessage||null;this.onrampPaymentIntentId=c,o?(this.onrampSessionId=o,this.onrampErrorMessage=null,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.onrampErrorMessage=d||"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=h(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}async connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");let t=await this.pnp.connect(e);if(!!!(t&&(t.connected===!0||t.principal||t.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{}this.config={...this.config,connectedWallet:t,actorProvider:(r,o)=>this.pnp.getActor({canisterId:r,idl:o,requiresSigning:!0,anon:!1})},this.showWalletModal=!1;let s=this.pendingAction;this.pendingAction=null,s==="donate"&&setTimeout(()=>this.donate(),0)}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}render(){return this.config?de`
1305
1305
  <div class="icpay-card icpay-section icpay-widget-base" style="text-align:center;">
1306
1306
  ${this.config?.progressBar?.enabled!==!1?de`
1307
1307
  <icpay-progress-bar
@@ -1380,7 +1380,7 @@ import{a as n}from"./chunk-LTEQ7OUJ.js";import{css as De}from"lit";var U=De`
1380
1380
  border-color: rgba(239, 68, 68, 0.3);
1381
1381
  color: #ef4444;
1382
1382
  }
1383
- `],n([ft({type:Object})],b.prototype,"config",2),n([M()],b.prototype,"selectedAmount",2),n([M()],b.prototype,"selectedSymbol",2),n([M()],b.prototype,"raised",2),n([M()],b.prototype,"processing",2),n([M()],b.prototype,"succeeded",2),n([M()],b.prototype,"availableLedgers",2),n([M()],b.prototype,"errorMessage",2),n([M()],b.prototype,"errorSeverity",2),n([M()],b.prototype,"errorAction",2),n([M()],b.prototype,"walletConnected",2),n([M()],b.prototype,"pendingAction",2),n([M()],b.prototype,"showWalletModal",2),n([M()],b.prototype,"showOnrampModal",2),n([M()],b.prototype,"onrampSessionId",2),n([M()],b.prototype,"onrampPaymentIntentId",2),n([M()],b.prototype,"onrampErrorMessage",2),b=n([mt("icpay-donation-thermometer")],b);import{LitElement as yt,html as he,css as bt}from"lit";import{customElement as vt,property as wt,state as z}from"lit/decorators.js";var Oe=typeof window<"u",Le=null;function ye(a,l,e){a&&(e!==void 0?console.log(`[ICPay Widget] ${l}`,e):console.log(`[ICPay Widget] ${l}`))}var S=class extends yt{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.onrampPollTimer=null;this.transakMessageHandlerBound=null;this.pnp=null;this.sdk=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.onSwitchAccount=async e=>{try{if(!this.pnp)return;if(await this.pnp.disconnect(),(e?.detail?.walletType||"").toLowerCase()==="ii")try{window.open("https://identity.ic0.app/","_blank","noopener,noreferrer")}catch{}this.pendingAction="pay",this.walletConnected=!1,this.showWalletModal=!0,this.requestUpdate()}catch{}}}getSdk(){return this.sdk||(this.sdk=h(this.config)),this.sdk}get cryptoOptions(){return this.config?.cryptoOptions?.length?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){if(super.connectedCallback(),!!Oe){ye(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{}}}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(!(!Oe||!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{Le||(Le=(await import("@windoge98/plug-n-play")).PNP);let e={...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:i}=await import("./origin-44ZEXSX4.js");e.derivationOrigin=this.config?.derivationOrigin||i()}}catch{}this.pnp=new Le(e);let t=this.pnp.getEnabledWallets();if(ye(this.config?.debug||!1,"Available wallets",t),!t?.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}async connectWithWallet(e){if(this.pnp)try{if(ye(this.config?.debug||!1,"Connecting to wallet",{walletId:e}),!e)throw new Error("No wallet ID provided");let t=await this.pnp.connect(e);if(ye(this.config?.debug||!1,"Wallet connect result",t),!!!(t&&(t.connected===!0||t.principal||t.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{}this.config={...this.config,connectedWallet:t,actorProvider:(r,o)=>this.pnp.getActor({canisterId:r,idl:o,requiresSigning:!0,anon:!1})},this.showWalletModal=!1;let s=this.pendingAction;this.pendingAction=null,s==="pay"&&setTimeout(()=>this.pay(),0)}catch(t){ye(this.config?.debug||!1,"Wallet connection error",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(p=>({id:this.getWalletId(p),label:this.getWalletLabel(p),icon:this.getWalletIcon(p)})),i=this.config?.onramp?.enabled!==!1&&this.config?.onrampDisabled!==!0,s=5,r=Number(this.config?.amountUsd??0),o=i&&r>0&&r<s,c=Math.max(0,s-r),d=o?`Note: Minimum card amount is $${s}. You will pay about $${c.toFixed(2)} more.`:null;return B({visible:this.showWalletModal,wallets:t,isConnecting:!1,onSelect:p=>this.connectWithWallet(p),onClose:()=>{this.showWalletModal=!1},onCreditCard:i?()=>this.startOnramp():void 0,creditCardLabel:this.config?.onramp?.creditCardLabel||"Pay with credit card",showCreditCard:i,creditCardTooltip:d})}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",r=this.cryptoOptions.find(k=>k.symbol===i)?.canisterId||await t.client.getLedgerCanisterIdBySymbol(i),o=await t.startOnrampUsd(e,r,{context:"pay-button:onramp"}),c=o?.metadata?.onramp?.sessionId||o?.metadata?.onramp?.session_id||null,d=o?.metadata?.onramp?.errorMessage||null;this.onrampErrorMessage=d||null;let p=o?.metadata?.paymentIntentId||o?.paymentIntentId||null;this.onrampPaymentIntentId=p,c?(this.onrampSessionId=c,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.showOnrampModal=!0)}catch(e){this.onrampSessionId=null,this.onrampErrorMessage=e?.message||null,this.showOnrampModal=!0,C(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),L(t)&&(this.errorMessage=O(t),this.errorSeverity=A(t),this.errorAction=W(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},r=o=>{s()};try{window.addEventListener("icpay-sdk-transaction-completed",r,{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=i.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}async pay(){if(!(!Oe||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(!await this.ensureWallet())return;let t=this.getSdk();this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||"ICP");let i=this.selectedSymbol||"ICP",r=this.cryptoOptions.find(p=>p.symbol===i)?.canisterId||await t.client.getLedgerCanisterIdBySymbol(i),o=Number(this.config?.amountUsd??0),c={context:"pay-button"},d=await t.sendUsd(o,r,c);this.config.onSuccess&&this.config.onSuccess({id:d.transactionId,status:d.status}),this.succeeded=!0,this.dispatchEvent(new CustomEvent("icpay-pay",{detail:{amount:o,tx:d},bubbles:!0}))}catch(e){C(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),L(t)&&(this.errorMessage=O(t),this.errorSeverity=A(t),this.errorAction=W(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 he`<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",r=s!=="none"&&(t||s==="dropdown"),o=s==="dropdown"?"dropdown":t?"buttons":"none",c=this.selectedSymbol||this.config?.defaultSymbol||"ICP",d=typeof this.config?.amountUsd=="number"?`${Number(this.config.amountUsd).toFixed(2)}`:"",k=(this.config?.buttonLabel||(typeof this.config?.amountUsd=="number"?"Pay ${amount} with {symbol}":"Pay with {symbol}")).replace("{amount}",d||"$0.00").replace("{symbol}",c),be=this.config?.progressBar?.enabled!==!1;return he`
1383
+ `],n([ft({type:Object})],b.prototype,"config",2),n([M()],b.prototype,"selectedAmount",2),n([M()],b.prototype,"selectedSymbol",2),n([M()],b.prototype,"raised",2),n([M()],b.prototype,"processing",2),n([M()],b.prototype,"succeeded",2),n([M()],b.prototype,"availableLedgers",2),n([M()],b.prototype,"errorMessage",2),n([M()],b.prototype,"errorSeverity",2),n([M()],b.prototype,"errorAction",2),n([M()],b.prototype,"walletConnected",2),n([M()],b.prototype,"pendingAction",2),n([M()],b.prototype,"showWalletModal",2),n([M()],b.prototype,"showOnrampModal",2),n([M()],b.prototype,"onrampSessionId",2),n([M()],b.prototype,"onrampPaymentIntentId",2),n([M()],b.prototype,"onrampErrorMessage",2),b=n([mt("icpay-donation-thermometer")],b);import{LitElement as yt,html as he,css as bt}from"lit";import{customElement as vt,property as wt,state as z}from"lit/decorators.js";var Oe=typeof window<"u",Le=null;function ye(a,l,e){a&&(e!==void 0?console.log(`[ICPay Widget] ${l}`,e):console.log(`[ICPay Widget] ${l}`))}var k=class extends yt{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.onrampPollTimer=null;this.transakMessageHandlerBound=null;this.pnp=null;this.sdk=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.onSwitchAccount=async e=>{try{if(!this.pnp)return;if(await this.pnp.disconnect(),(e?.detail?.walletType||"").toLowerCase()==="ii")try{window.open("https://identity.ic0.app/","_blank","noopener,noreferrer")}catch{}this.pendingAction="pay",this.walletConnected=!1,this.showWalletModal=!0,this.requestUpdate()}catch{}}}getSdk(){return this.sdk||(this.sdk=h(this.config)),this.sdk}get cryptoOptions(){return this.config?.cryptoOptions?.length?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){if(super.connectedCallback(),!!Oe){ye(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{}}}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(!(!Oe||!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{Le||(Le=(await import("@windoge98/plug-n-play")).PNP);let e={...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:i}=await import("./origin-44ZEXSX4.js");e.derivationOrigin=this.config?.derivationOrigin||i()}}catch{}this.pnp=new Le(e);let t=this.pnp.getEnabledWallets();if(ye(this.config?.debug||!1,"Available wallets",t),!t?.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}async connectWithWallet(e){if(this.pnp)try{if(ye(this.config?.debug||!1,"Connecting to wallet",{walletId:e}),!e)throw new Error("No wallet ID provided");let t=await this.pnp.connect(e);if(ye(this.config?.debug||!1,"Wallet connect result",t),!!!(t&&(t.connected===!0||t.principal||t.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{}this.config={...this.config,connectedWallet:t,actorProvider:(r,o)=>this.pnp.getActor({canisterId:r,idl:o,requiresSigning:!0,anon:!1})},this.showWalletModal=!1;let s=this.pendingAction;this.pendingAction=null,s==="pay"&&setTimeout(()=>this.pay(),0)}catch(t){ye(this.config?.debug||!1,"Wallet connection error",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(p=>({id:this.getWalletId(p),label:this.getWalletLabel(p),icon:this.getWalletIcon(p)})),i=this.config?.onramp?.enabled!==!1&&this.config?.onrampDisabled!==!0,s=5,r=Number(this.config?.amountUsd??0),o=i&&r>0&&r<s,c=Math.max(0,s-r),d=o?`Note: Minimum card amount is $${s}. You will pay about $${c.toFixed(2)} more.`:null;return B({visible:this.showWalletModal,wallets:t,isConnecting:!1,onSelect:p=>this.connectWithWallet(p),onClose:()=>{this.showWalletModal=!1},onCreditCard:i?()=>this.startOnramp():void 0,creditCardLabel:this.config?.onramp?.creditCardLabel||"Pay with credit card",showCreditCard:i,creditCardTooltip:d})}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",r=this.cryptoOptions.find(w=>w.symbol===i)?.canisterId||await t.client.getLedgerCanisterIdBySymbol(i),o=await t.startOnrampUsd(e,r,{context:"pay-button:onramp"}),c=o?.metadata?.onramp?.sessionId||o?.metadata?.onramp?.session_id||null,d=o?.metadata?.onramp?.errorMessage||null;this.onrampErrorMessage=d||null;let p=o?.metadata?.paymentIntentId||o?.paymentIntentId||null;this.onrampPaymentIntentId=p,c?(this.onrampSessionId=c,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.showOnrampModal=!0)}catch(e){this.onrampSessionId=null,this.onrampErrorMessage=e?.message||null,this.showOnrampModal=!0,C(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),L(t)&&(this.errorMessage=O(t),this.errorSeverity=A(t),this.errorAction=W(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},r=o=>{s()};try{window.addEventListener("icpay-sdk-transaction-completed",r,{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=i.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}async pay(){if(!(!Oe||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(!await this.ensureWallet())return;let t=this.getSdk();this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||"ICP");let i=this.selectedSymbol||"ICP",r=this.cryptoOptions.find(p=>p.symbol===i)?.canisterId||await t.client.getLedgerCanisterIdBySymbol(i),o=Number(this.config?.amountUsd??0),c={context:"pay-button"},d=await t.sendUsd(o,r,c);this.config.onSuccess&&this.config.onSuccess({id:d.transactionId,status:d.status}),this.succeeded=!0,this.dispatchEvent(new CustomEvent("icpay-pay",{detail:{amount:o,tx:d},bubbles:!0}))}catch(e){C(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),L(t)&&(this.errorMessage=O(t),this.errorSeverity=A(t),this.errorAction=W(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 he`<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",r=s!=="none"&&(t||s==="dropdown"),o=s==="dropdown"?"dropdown":t?"buttons":"none",c=this.selectedSymbol||this.config?.defaultSymbol||"ICP",d=typeof this.config?.amountUsd=="number"?`${Number(this.config.amountUsd).toFixed(2)}`:"",w=(this.config?.buttonLabel||(typeof this.config?.amountUsd=="number"?"Pay ${amount} with {symbol}":"Pay with {symbol}")).replace("{amount}",d||"$0.00").replace("{symbol}",c),be=this.config?.progressBar?.enabled!==!1;return he`
1384
1384
  <div class="icpay-card icpay-section icpay-widget-base">
1385
1385
  ${be?he`
1386
1386
  <icpay-progress-bar
@@ -1404,7 +1404,7 @@ import{a as n}from"./chunk-LTEQ7OUJ.js";import{css as De}from"lit";var U=De`
1404
1404
  <button class="pay-button ${this.processing?"processing":""}"
1405
1405
  ?disabled=${this.processing||this.config?.disablePaymentButton===!0||this.succeeded&&this.config?.disableAfterSuccess===!0}
1406
1406
  @click=${()=>this.pay()}>
1407
- ${this.succeeded&&this.config?.disableAfterSuccess?"Paid":this.processing?"Processing\u2026":k}
1407
+ ${this.succeeded&&this.config?.disableAfterSuccess?"Paid":this.processing?"Processing\u2026":w}
1408
1408
  </button>
1409
1409
  </div>
1410
1410
 
@@ -1417,7 +1417,7 @@ import{a as n}from"./chunk-LTEQ7OUJ.js";import{css as De}from"lit";var U=De`
1417
1417
  ${this.renderWalletModal()}
1418
1418
  ${this.showOnrampModal?$({visible:this.showOnrampModal,sessionId:this.onrampSessionId,errorMessage:this.onrampErrorMessage,apiKey:this.config?.onramp?.apiKey,apiUrl:this.config?.apiUrl,paymentIntentId:this.onrampPaymentIntentId,environment:this.config?.onramp?.environment||"STAGING",width:this.config?.onramp?.width,height:this.config?.onramp?.height,onClose:()=>{this.showOnrampModal=!1},onBack:()=>{this.showOnrampModal=!1,this.showWalletModal=!0}}):null}
1419
1419
  </div>
1420
- `}};S.styles=[U,bt`
1420
+ `}};k.styles=[U,bt`
1421
1421
  .row { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; }
1422
1422
  .row.single { grid-template-columns: 1fr; }
1423
1423
  select { background: var(--icpay-surface-alt); border: 1px solid var(--icpay-border); color: var(--icpay-text); border-radius: 8px; padding: 10px; font-weight: 600; }
@@ -1425,7 +1425,7 @@ import{a as n}from"./chunk-LTEQ7OUJ.js";import{css as De}from"lit";var U=De`
1425
1425
  .error-message.info { background: rgba(59,130,246,0.1); border-color: rgba(59,130,246,0.3); color: #3b82f6; }
1426
1426
  .error-message.warning { background: rgba(245,158,11,0.1); border-color: rgba(245,158,11,0.3); color: #f59e0b; }
1427
1427
  .error-message.error { background: rgba(239,68,68,0.1); border-color: rgba(239,68,68,0.3); color: #ef4444; }
1428
- `],n([wt({type:Object})],S.prototype,"config",2),n([z()],S.prototype,"selectedSymbol",2),n([z()],S.prototype,"processing",2),n([z()],S.prototype,"succeeded",2),n([z()],S.prototype,"availableLedgers",2),n([z()],S.prototype,"errorMessage",2),n([z()],S.prototype,"errorSeverity",2),n([z()],S.prototype,"errorAction",2),n([z()],S.prototype,"walletConnected",2),n([z()],S.prototype,"pendingAction",2),n([z()],S.prototype,"showWalletModal",2),n([z()],S.prototype,"showOnrampModal",2),n([z()],S.prototype,"onrampSessionId",2),n([z()],S.prototype,"onrampPaymentIntentId",2),n([z()],S.prototype,"onrampErrorMessage",2),S=n([vt("icpay-pay-button")],S);import{LitElement as xt,html as ge,css as St}from"lit";import{customElement as kt,property as Et,state as I}from"lit/decorators.js";var We=typeof window<"u",Ae=null;function Mt(a,l,e){a&&(e!==void 0?console.log(`[ICPay Widget] ${l}`,e):console.log(`[ICPay Widget] ${l}`))}var v=class extends xt{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.pnp=null;this.transakMessageHandlerBound=null;this.onrampPollTimer=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.onSwitchAccount=async e=>{try{if(!this.pnp)return;if(await this.pnp.disconnect(),(e?.detail?.walletType||"").toLowerCase()==="ii")try{window.open("https://identity.ic0.app/","_blank","noopener,noreferrer")}catch{}this.pendingAction="pay",this.walletConnected=!1,this.showWalletModal=!0,this.requestUpdate()}catch{}}}get cryptoOptions(){return this.config?.cryptoOptions?.length?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){if(super.connectedCallback(),!!We){Mt(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(!(!We||!this.config?.publishableKey))try{let t=await h(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{Ae||(Ae=(await import("@windoge98/plug-n-play")).PNP);let e={...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:i}=await import("./origin-44ZEXSX4.js");e.derivationOrigin=this.config?.derivationOrigin||i()}}catch{}if(this.pnp=new Ae(e),!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}async connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");let t=await this.pnp.connect(e);if(!!!(t&&(t.connected===!0||t.principal||t.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{}this.config={...this.config,connectedWallet:t,actorProvider:(r,o)=>this.pnp.getActor({canisterId:r,idl:o,requiresSigning:!0,anon:!1})},this.showWalletModal=!1;let s=this.pendingAction;this.pendingAction=null,s==="pay"&&setTimeout(()=>this.pay(),0)}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=h(this.config),t=this.selectedSymbol||this.config?.defaultSymbol||"ICP",s=this.cryptoOptions.find(k=>k.symbol===t)?.canisterId||await e.client.getLedgerCanisterIdBySymbol(t),r=Number(this.amountUsd),o=await e.startOnrampUsd(r,s,{context:"amount-input:onramp"}),c=o?.metadata?.onramp?.sessionId||o?.metadata?.onramp?.session_id||null,d=o?.metadata?.paymentIntentId||o?.paymentIntentId||null,p=o?.metadata?.onramp?.errorMessage||null;this.onrampPaymentIntentId=d,c?(this.onrampSessionId=c,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=h(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(!(!We||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=h(this.config),i=this.selectedSymbol||this.config?.defaultSymbol||"ICP",r=this.cryptoOptions.find(p=>p.symbol===i)?.canisterId||await t.client.getLedgerCanisterIdBySymbol(i),o=Number(this.amountUsd),c={context:"amount-input"},d=await t.sendUsd(o,r,c);this.config.onSuccess&&this.config.onSuccess({id:d.transactionId,status:d.status,amountUsd:o}),this.succeeded=!0,this.dispatchEvent(new CustomEvent("icpay-amount-pay",{detail:{amount:o,tx:d},bubbles:!0}))}catch(e){C(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),L(t)&&(this.errorMessage=O(t),this.errorSeverity=A(t),this.errorAction=W(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 ge`<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(K=>K.symbol===(this.selectedSymbol||""))?.label||this.cryptoOptions[0]?.label||this.config?.defaultSymbol||"ICP",r=this.config?.progressBar?.mode||"modal",o=this.config?.showLedgerDropdown,c=o==="buttons"?"buttons":o==="none"?"none":"dropdown",p=(this.cryptoOptions?.length||0)>1,k=c!=="none"&&(p||c==="dropdown"),ue=c==="dropdown"?"dropdown":p?"buttons":"none",me=this.config?.progressBar?.enabled!==!1&&(r==="modal"?!0:this.processing);return ge`
1428
+ `],n([wt({type:Object})],k.prototype,"config",2),n([z()],k.prototype,"selectedSymbol",2),n([z()],k.prototype,"processing",2),n([z()],k.prototype,"succeeded",2),n([z()],k.prototype,"availableLedgers",2),n([z()],k.prototype,"errorMessage",2),n([z()],k.prototype,"errorSeverity",2),n([z()],k.prototype,"errorAction",2),n([z()],k.prototype,"walletConnected",2),n([z()],k.prototype,"pendingAction",2),n([z()],k.prototype,"showWalletModal",2),n([z()],k.prototype,"showOnrampModal",2),n([z()],k.prototype,"onrampSessionId",2),n([z()],k.prototype,"onrampPaymentIntentId",2),n([z()],k.prototype,"onrampErrorMessage",2),k=n([vt("icpay-pay-button")],k);import{LitElement as xt,html as ge,css as St}from"lit";import{customElement as kt,property as Et,state as I}from"lit/decorators.js";var We=typeof window<"u",Ae=null;function Mt(a,l,e){a&&(e!==void 0?console.log(`[ICPay Widget] ${l}`,e):console.log(`[ICPay Widget] ${l}`))}var v=class extends xt{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.pnp=null;this.transakMessageHandlerBound=null;this.onrampPollTimer=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.onSwitchAccount=async e=>{try{if(!this.pnp)return;if(await this.pnp.disconnect(),(e?.detail?.walletType||"").toLowerCase()==="ii")try{window.open("https://identity.ic0.app/","_blank","noopener,noreferrer")}catch{}this.pendingAction="pay",this.walletConnected=!1,this.showWalletModal=!0,this.requestUpdate()}catch{}}}get cryptoOptions(){return this.config?.cryptoOptions?.length?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){if(super.connectedCallback(),!!We){Mt(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(!(!We||!this.config?.publishableKey))try{let t=await h(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{Ae||(Ae=(await import("@windoge98/plug-n-play")).PNP);let e={...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:i}=await import("./origin-44ZEXSX4.js");e.derivationOrigin=this.config?.derivationOrigin||i()}}catch{}if(this.pnp=new Ae(e),!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}async connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");let t=await this.pnp.connect(e);if(!!!(t&&(t.connected===!0||t.principal||t.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{}this.config={...this.config,connectedWallet:t,actorProvider:(r,o)=>this.pnp.getActor({canisterId:r,idl:o,requiresSigning:!0,anon:!1})},this.showWalletModal=!1;let s=this.pendingAction;this.pendingAction=null,s==="pay"&&setTimeout(()=>this.pay(),0)}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=h(this.config),t=this.selectedSymbol||this.config?.defaultSymbol||"ICP",s=this.cryptoOptions.find(w=>w.symbol===t)?.canisterId||await e.client.getLedgerCanisterIdBySymbol(t),r=Number(this.amountUsd),o=await e.startOnrampUsd(r,s,{context:"amount-input:onramp"}),c=o?.metadata?.onramp?.sessionId||o?.metadata?.onramp?.session_id||null,d=o?.metadata?.paymentIntentId||o?.paymentIntentId||null,p=o?.metadata?.onramp?.errorMessage||null;this.onrampPaymentIntentId=d,c?(this.onrampSessionId=c,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=h(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(!(!We||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=h(this.config),i=this.selectedSymbol||this.config?.defaultSymbol||"ICP",r=this.cryptoOptions.find(p=>p.symbol===i)?.canisterId||await t.client.getLedgerCanisterIdBySymbol(i),o=Number(this.amountUsd),c={context:"amount-input"},d=await t.sendUsd(o,r,c);this.config.onSuccess&&this.config.onSuccess({id:d.transactionId,status:d.status,amountUsd:o}),this.succeeded=!0,this.dispatchEvent(new CustomEvent("icpay-amount-pay",{detail:{amount:o,tx:d},bubbles:!0}))}catch(e){C(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),L(t)&&(this.errorMessage=O(t),this.errorSeverity=A(t),this.errorAction=W(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 ge`<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(K=>K.symbol===(this.selectedSymbol||""))?.label||this.cryptoOptions[0]?.label||this.config?.defaultSymbol||"ICP",r=this.config?.progressBar?.mode||"modal",o=this.config?.showLedgerDropdown,c=o==="buttons"?"buttons":o==="none"?"none":"dropdown",p=(this.cryptoOptions?.length||0)>1,w=c!=="none"&&(p||c==="dropdown"),ue=c==="dropdown"?"dropdown":p?"buttons":"none",me=this.config?.progressBar?.enabled!==!1&&(r==="modal"?!0:this.processing);return ge`
1429
1429
  <div class="icpay-card icpay-section icpay-widget-base">
1430
1430
  ${me?ge`
1431
1431
  <icpay-progress-bar
@@ -1437,12 +1437,12 @@ import{a as n}from"./chunk-LTEQ7OUJ.js";import{css as De}from"lit";var U=De`
1437
1437
  `:null}
1438
1438
 
1439
1439
  <div class="row">
1440
- <div class="top-row ${k?"with-selector":""}">
1440
+ <div class="top-row ${w?"with-selector":""}">
1441
1441
  <div class="amount-field">
1442
1442
  <span class="currency-prefix">$</span>
1443
1443
  <input type="number" min="0" step="${Number(this.config?.stepUsd??.5)}" .value=${String(this.amountUsd||"")} placeholder="${e}" @input=${K=>this.onInputChange(K)} />
1444
1444
  </div>
1445
- ${k?ge`
1445
+ ${w?ge`
1446
1446
  <icpay-token-selector
1447
1447
  .options=${this.cryptoOptions}
1448
1448
  .value=${this.selectedSymbol||""}
@@ -1491,5 +1491,5 @@ import{a as n}from"./chunk-LTEQ7OUJ.js";import{css as De}from"lit";var U=De`
1491
1491
  @media (max-width: 520px) {
1492
1492
  .top-row { grid-template-columns: 1fr; }
1493
1493
  }
1494
- `],n([Et({type:Object})],v.prototype,"config",2),n([I()],v.prototype,"amountUsd",2),n([I()],v.prototype,"hasUserAmount",2),n([I()],v.prototype,"selectedSymbol",2),n([I()],v.prototype,"processing",2),n([I()],v.prototype,"succeeded",2),n([I()],v.prototype,"availableLedgers",2),n([I()],v.prototype,"errorMessage",2),n([I()],v.prototype,"errorSeverity",2),n([I()],v.prototype,"errorAction",2),n([I()],v.prototype,"walletConnected",2),n([I()],v.prototype,"pendingAction",2),n([I()],v.prototype,"showWalletModal",2),n([I()],v.prototype,"showOnrampModal",2),n([I()],v.prototype,"onrampSessionId",2),n([I()],v.prototype,"onrampPaymentIntentId",2),n([I()],v.prototype,"onrampErrorMessage",2),v=n([kt("icpay-amount-input")],v);export{U as a,ie as b,h as c,$ as d,w as e,y as f,m as g,x as h,b as i,S as j,v as k};
1495
- //# sourceMappingURL=chunk-CEWWQAJL.js.map
1494
+ `],n([Et({type:Object})],v.prototype,"config",2),n([I()],v.prototype,"amountUsd",2),n([I()],v.prototype,"hasUserAmount",2),n([I()],v.prototype,"selectedSymbol",2),n([I()],v.prototype,"processing",2),n([I()],v.prototype,"succeeded",2),n([I()],v.prototype,"availableLedgers",2),n([I()],v.prototype,"errorMessage",2),n([I()],v.prototype,"errorSeverity",2),n([I()],v.prototype,"errorAction",2),n([I()],v.prototype,"walletConnected",2),n([I()],v.prototype,"pendingAction",2),n([I()],v.prototype,"showWalletModal",2),n([I()],v.prototype,"showOnrampModal",2),n([I()],v.prototype,"onrampSessionId",2),n([I()],v.prototype,"onrampPaymentIntentId",2),n([I()],v.prototype,"onrampErrorMessage",2),v=n([kt("icpay-amount-input")],v);export{U as a,ie as b,h as c,$ as d,x as e,y as f,m as g,S as h,b as i,k as j,v as k};
1495
+ //# sourceMappingURL=chunk-LUCWBAAL.js.map