@ic-pay/icpay-widget 1.1.15 → 1.1.20

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.
@@ -1,4 +1,4 @@
1
- import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as De}from"lit";var P=De`
1
+ import{a as n}from"./chunk-LTEQ7OUJ.js";import{css as De}from"lit";var P=De`
2
2
  :host {
3
3
  --icpay-primary: #f9fafb;
4
4
  --icpay-secondary: #e5e7eb;
@@ -56,15 +56,15 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as De}from"lit";var P=De`
56
56
  0%, 100% { opacity: 1; }
57
57
  50% { opacity: 0.7; }
58
58
  }
59
- `;function ie(o,l){if(!o||!l)return;let e=l.primaryColor||void 0,t=l.secondaryColor||void 0,i=(K,j)=>{j&&o.style.setProperty(K,j)};i("--icpay-primary",e),i("--icpay-secondary",t);let n=K=>{if(!K)return null;let j=K.replace("#",""),H=j.length===3?j.split("").map(Te=>Te+Te).join(""):j,V=parseInt(H,16),te=V>>16&255,Re=V>>8&255,Be=V&255;return{r:te,g:Re,b:Be}},c=(K=>{let j=n(K);if(!j)return 0;let H=V=>{let te=V/255;return te<=.03928?te/12.92:Math.pow((te+.055)/1.055,2.4)};return .2126*H(j.r)+.7152*H(j.g)+.0722*H(j.b)})(e||t)>.6,d=l.surfaceColor||(c?"#f3f4f6":"#1f2937"),p=l.surfaceAltColor||(c?"#e5e7eb":"#374151"),E=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",E)}import{Icpay as Ne}from"@ic-pay/icpay-sdk";var Ue=typeof window<"u";function ve(o,l,e){o&&(e!==void 0?console.log(`[ICPay Widget] ${l}`,e):console.log(`[ICPay Widget] ${l}`))}function h(o){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(o.debug||!1,"Creating SDK with config:",o);let l={publishableKey:o.publishableKey};o.enableEvents!==void 0?l.enableEvents=o.enableEvents:l.enableEvents=!0,o.apiUrl&&(l.apiUrl=o.apiUrl),o.icHost&&(l.icHost=o.icHost),o.actorProvider&&(l.actorProvider=o.actorProvider),o.connectedWallet&&(l.connectedWallet=o.connectedWallet),o.onrampDisabled!==void 0&&(l.onrampDisabled=o.onrampDisabled),o.debug!==void 0&&(l.debug=o.debug),ve(o.debug||!1,"Filtered SDK config:",l);try{let a=function(c,d,p){return t.notifyPaymentIntentOnRamp({paymentIntentId:c,intervalMs:d,orderId:p})};var e=a;ve(o.debug||!1,"typeof Icpay:",typeof Ne);let t=new Ne(l);if(Ue){let c=t,d=p=>{c.addEventListener(p,E=>{window.dispatchEvent(new CustomEvent(p,{detail:E?.detail??E}))})};["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 n(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:n,startOnrampUsd:r,notifyIntentUntilComplete:a}}catch(t){throw ve(o.debug||!1,"Error creating SDK:",t),t}}import{LitElement as ze,html as u,css as Fe}from"lit";import{customElement as Ke,property as X,state as $}from"lit/decorators.js";function g(o,l,e){o&&(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"}],m=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=!0,this.isTransitioning=!1,this.currentSteps=this.currentSteps.map(n=>({...n,status:"pending"})),i==="onramp"){let n=this.getStepIndexByKey("wallet");n>=0&&(this.currentSteps[n]={...this.currentSteps[n],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",n=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:n,step:this.activeIndex},bubbles:!0}))};this.onTransactionMismatched=e=>{let t=e?.detail?.requestedAmount,i=e?.detail?.paidAmount,n=e?.detail?.transactionId||e?.detail?.id;this.failed=!0;let r=t!=null?String(t):"unknown",a=i!=null?String(i):"unknown";this.errorMessage=`Amount mismatch. Requested ${r}, paid ${a}.`,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:n,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",n=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:n,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,n=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),n&&(this.currentLedgerSymbol=n,this.ledgerSymbol=n),!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:n,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 n=this.activeIndex;n<this.currentSteps.length;n++)this.updateStepStatus(n,"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 n=this.activeIndex;n<this.currentSteps.length;n++)this.updateStepStatus(n,"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 n=this.activeIndex;n<this.currentSteps.length;n++)this.updateStepStatus(n,"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 n=this.activeIndex;n<this.currentSteps.length;n++)this.updateStepStatus(n,"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 n=this.currentSteps[e],r=n.status;n.status=t,t==="completed"&&(n.timestamp=this.getCurrentTime()),t==="error"&&i&&(n.errorMessage=this.transformErrorMessage(i)),g(this.debug,`ICPay Progress: Step ${e} (${n.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"})}progressPercent(){if(this.failed)return 0;if(this.showSuccess)return 100;let t=this.currentSteps.filter(i=>i.status==="completed").length/this.currentSteps.length*100;return Math.max(0,Math.min(100,t))}verticalPercent(){if(this.failed)return 0;if(this.showSuccess)return 100;let t=this.currentSteps.filter(i=>i.status==="completed").length/this.currentSteps.length*100;return Math.max(0,Math.min(100,t))}getStepIcon(e){switch(e.status){case"loading":return u`<div class="loading-spinner"></div>`;case"completed":return u`<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,j)=>{j&&a.style.setProperty(K,j)};i("--icpay-primary",e),i("--icpay-secondary",t);let s=K=>{if(!K)return null;let j=K.replace("#",""),H=j.length===3?j.split("").map(Te=>Te+Te).join(""):j,V=parseInt(H,16),te=V>>16&255,Re=V>>8&255,Be=V&255;return{r:te,g:Re,b:Be}},c=(K=>{let j=s(K);if(!j)return 0;let H=V=>{let te=V/255;return te<=.03928?te/12.92:Math.pow((te+.055)/1.055,2.4)};return .2126*H(j.r)+.7152*H(j.g)+.0722*H(j.b)})(e||t)>.6,d=l.surfaceColor||(c?"#f3f4f6":"#1f2937"),p=l.surfaceAltColor||(c?"#e5e7eb":"#374151"),E=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",E)}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,E=>{window.dispatchEvent(new CustomEvent(p,{detail:E?.detail??E}))})};["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 Fe}from"lit";import{customElement as Ke,property as X,state as $}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
- </svg>`;case"error":return u`<svg fill="none" viewBox="0 0 24 24" stroke="currentColor">
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" />
63
- </svg>`;default:return u`<svg fill="none" viewBox="0 0 24 24" stroke="currentColor">
63
+ </svg>`;default:return f`<svg fill="none" viewBox="0 0 24 24" stroke="currentColor">
64
64
  <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 3v2m6-2v2M9 19v2m6-2v2M5 9H3m2 6H3m18-6h-2m2 6h-2M7 19h10a2 2 0 002-2V7a2 2 0 00-2-2H7a2 2 0 00-2 2v10a2 2 0 002 2zM9 9h6v6H9V9z" />
65
- </svg>`}}getStepIndexByKey(e){return this.currentSteps.findIndex(t=>t.key===e)}setLoadingByKey(e){let t=this.getStepIndexByKey(e);t>=0&&(this.activeIndex=t,this.updateStepStatus(t,"loading"),e==="confirm"&&(this.confirmLoadingStartedAt=Date.now()))}completeByKey(e){let t=this.getStepIndexByKey(e);t>=0&&(this.updateStepStatus(t,"completed"),this.activeIndex=t)}transformErrorMessage(e){let t=String(e||"").toLowerCase();return t.includes("user rejected")||t.includes("user cancelled")||t.includes("user canceled")||t.includes("signature rejected")?"User have rejected the transfer":e}renderConfetti(){if(!this.showConfetti)return"";let e=Array.from({length:50},(i,n)=>n),t=["#0066FF","#ef4444","#10b981","#f59e0b","#8b5cf6"];return u`
65
+ </svg>`}}getStepIndexByKey(e){return this.currentSteps.findIndex(t=>t.key===e)}setLoadingByKey(e){let t=this.getStepIndexByKey(e);t>=0&&(this.activeIndex=t,this.updateStepStatus(t,"loading"),e==="confirm"&&(this.confirmLoadingStartedAt=Date.now()))}completeByKey(e){let t=this.getStepIndexByKey(e);t>=0&&(this.updateStepStatus(t,"completed"),this.activeIndex=t)}transformErrorMessage(e){let t=String(e||"").toLowerCase();return t.includes("user rejected")||t.includes("user cancelled")||t.includes("user canceled")||t.includes("signature rejected")?"User have rejected the transfer":e}renderConfetti(){if(!this.showConfetti)return"";let e=Array.from({length:50},(i,s)=>s),t=["#0066FF","#ef4444","#10b981","#f59e0b","#8b5cf6"];return f`
66
66
  <div class="confetti">
67
- ${e.map(i=>u`
67
+ ${e.map(i=>f`
68
68
  <div
69
69
  class="confetti-piece"
70
70
  style="
@@ -77,7 +77,7 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as De}from"lit";var P=De`
77
77
  ></div>
78
78
  `)}
79
79
  </div>
80
- `}renderSuccessState(){let e=this.currentAmount||this.amount,t=this.currentLedgerSymbol||this.currentCurrency||this.currency;return g(this.debug,"ICPay Progress: Rendering success state with:",{displayAmount:e,displayCurrency:t,currentAmount:this.currentAmount,amount:this.amount,currentCurrency:this.currentCurrency,currency:this.currency,currentLedgerSymbol:this.currentLedgerSymbol,ledgerSymbol:this.ledgerSymbol}),u`
80
+ `}renderSuccessState(){let e=this.currentAmount||this.amount,t=this.currentLedgerSymbol||this.currentCurrency||this.currency;return g(this.debug,"ICPay Progress: Rendering success state with:",{displayAmount:e,displayCurrency:t,currentAmount:this.currentAmount,amount:this.amount,currentCurrency:this.currentCurrency,currency:this.currency,currentLedgerSymbol:this.currentLedgerSymbol,ledgerSymbol:this.ledgerSymbol}),f`
81
81
  <div class="success-container">
82
82
  <div class="success-icon">
83
83
  <svg fill="none" viewBox="0 0 24 24" stroke="currentColor">
@@ -90,12 +90,12 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as De}from"lit";var P=De`
90
90
  <button class="btn btn-primary" @click=${()=>{this.open=!1}}>Close</button>
91
91
  </div>
92
92
  </div>
93
- `}renderErrorState(){return this.errorMessage?.includes("Insufficient balance")||!1?this.renderInsufficientFundsError():this.renderGenericError()}renderInsufficientFundsError(){let e=this.currentAmount||this.amount,t=this.currentLedgerSymbol||this.currentCurrency||this.currency;return u`
93
+ `}renderErrorState(){return this.errorMessage?.includes("Insufficient balance")||!1?this.renderInsufficientFundsError():this.renderGenericError()}renderInsufficientFundsError(){let e=this.currentAmount||this.amount,t=this.currentLedgerSymbol||this.currentCurrency||this.currency;return f`
94
94
  <div class="insufficient-funds-container">
95
95
  <div class="payment-summary">
96
96
  <div class="payment-amount">Pay $${e} with ${t}</div>
97
97
  </div>
98
-
98
+
99
99
  <div class="error-notification">
100
100
  <div class="error-content">
101
101
  <div class="error-icon-small">
@@ -109,7 +109,7 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as De}from"lit";var P=De`
109
109
  Add Funds
110
110
  </button>
111
111
  </div>
112
-
112
+
113
113
  <div class="error-actions">
114
114
  <button class="btn btn-secondary" @click=${()=>this.requestSwitchAccount()} title="Switch to a different account">
115
115
  <svg fill="none" viewBox="0 0 24 24" stroke="currentColor" style="width: 16px; height: 16px;">
@@ -125,7 +125,7 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as De}from"lit";var P=De`
125
125
  </button>
126
126
  </div>
127
127
  </div>
128
- `}renderGenericError(){return u`
128
+ `}renderGenericError(){return f`
129
129
  <div class="error-container">
130
130
  <div class="error-icon-large">
131
131
  <svg fill="none" viewBox="0 0 24 24" stroke="currentColor">
@@ -149,28 +149,7 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as De}from"lit";var P=De`
149
149
  </button>
150
150
  </div>
151
151
  </div>
152
- `}requestSwitchAccount(){try{let e=this.currentWalletType||"unknown";window.dispatchEvent(new CustomEvent("icpay-switch-account",{detail:{walletType:e}}))}catch{}}handleAddFunds(){try{window.dispatchEvent(new CustomEvent("icpay-add-funds",{detail:{amount:this.currentAmount||this.amount,currency:this.currentLedgerSymbol||this.currentCurrency||this.currency}})),this.open=!1}catch(e){console.error("Error handling add funds:",e)}}startTransitionToProgress(){this.isTransitioning=!0,this.requestUpdate(),setTimeout(()=>{this.showWalletSelector=!1,this.isTransitioning=!1,this.requestUpdate()},400)}showWalletSelectorModal(){this.showWalletSelector=!0,this.isTransitioning=!1,this.requestUpdate()}hideWalletSelectorModal(){this.showWalletSelector=!1,this.requestUpdate()}renderWalletSelector(){return u`
153
- <div class="wallet-selector-container">
154
- <h3 class="wallet-selector-title">Choose Wallet</h3>
155
- <div class="wallet-options">
156
- ${[{id:"ii",label:"Internet Identity",icon:null},{id:"nfid",label:"NFID",icon:null},{id:"plug",label:"Plug",icon:null},{id:"oisy",label:"Oisy",icon:null}].map(t=>u`
157
- <button
158
- class="wallet-option"
159
- @click=${()=>this.handleWalletSelection(t.id)}
160
- >
161
- <div class="wallet-icon">
162
- ${t.icon?u`
163
- <img src="${t.icon}" alt="${t.label} logo" />
164
- `:u`
165
- <div class="wallet-icon-placeholder">${t.label.charAt(0)}</div>
166
- `}
167
- </div>
168
- <div class="wallet-label">${t.label}</div>
169
- </button>
170
- `)}
171
- </div>
172
- </div>
173
- `}handleWalletSelection(e){window.dispatchEvent(new CustomEvent("icpay-wallet-selected",{detail:{walletId:e}})),this.startTransitionToProgress()}renderProgressContent(){return this.showSuccess?this.renderSuccessState():this.failed?this.renderErrorState():u`
152
+ `}requestSwitchAccount(){try{let e=this.currentWalletType||"unknown";window.dispatchEvent(new CustomEvent("icpay-switch-account",{detail:{walletType:e}}))}catch{}}handleAddFunds(){try{window.dispatchEvent(new CustomEvent("icpay-add-funds",{detail:{amount:this.currentAmount||this.amount,currency:this.currentLedgerSymbol||this.currentCurrency||this.currency}})),this.open=!1}catch(e){console.error("Error handling add funds:",e)}}startTransitionToProgress(){this.isTransitioning=!0,this.requestUpdate(),setTimeout(()=>{this.showWalletSelector=!1,this.isTransitioning=!1,this.requestUpdate()},400)}renderProgressContent(){return this.showSuccess?this.renderSuccessState():this.failed?this.renderErrorState():f`
174
153
  <div class="progress-container">
175
154
  <div class="progress-header">
176
155
  <h3 class="progress-title">Processing Payment</h3>
@@ -178,19 +157,19 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as De}from"lit";var P=De`
178
157
  ${this.renderConfirmTip()}
179
158
  </div>
180
159
  <div class="progress-steps">
181
- ${this.currentSteps.map((e,t)=>u`
160
+ ${this.currentSteps.map((e,t)=>f`
182
161
  <div class="step ${t===this.activeIndex?"active":""} ${e.status==="completed"?"completed":""} ${e.status==="error"?"error":""}">
183
162
  <div class="step-icon">
184
- ${e.status==="loading"?u`<div class="loading-spinner"></div>`:""}
185
- ${e.status==="completed"?u`
163
+ ${e.status==="loading"?f`<div class="loading-spinner"></div>`:""}
164
+ ${e.status==="completed"?f`
186
165
  <svg fill="none" viewBox="0 0 24 24" stroke="currentColor">
187
166
  <path stroke-linecap="round" stroke-linejoin="round" d="M5 13l4 4L19 7" />
188
167
  </svg>
189
- `:e.status==="error"?u`
168
+ `:e.status==="error"?f`
190
169
  <svg fill="none" viewBox="0 0 24 24" stroke="currentColor">
191
170
  <path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />
192
171
  </svg>
193
- `:u`
172
+ `:f`
194
173
  <svg fill="none" viewBox="0 0 24 24" stroke="currentColor">
195
174
  <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 3v2m6-2v2M9 19v2m6-2v2M5 9H3m2 6H3m18-6h-2m2 6h-2M7 19h10a2 2 0 002-2V7a2 2 0 00-2-2H7a2 2 0 00-2 2v10a2 2 0 002 2zM9 9h6v6H9V9z" />
196
175
  </svg>
@@ -199,7 +178,7 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as De}from"lit";var P=De`
199
178
  <div class="step-content">
200
179
  <div class="step-title">${e.label}</div>
201
180
  <div class="step-description">${e.tooltip}</div>
202
- ${e.status==="error"&&e.errorMessage?u`
181
+ ${e.status==="error"&&e.errorMessage?f`
203
182
  <div class="step-error-message">${e.errorMessage}</div>
204
183
  `:""}
205
184
  </div>
@@ -207,7 +186,7 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as De}from"lit";var P=De`
207
186
  `)}
208
187
  </div>
209
188
  </div>
210
- `}renderConfirmTip(){try{let e=this.getStepIndexByKey("confirm");if(e<0||!(this.activeIndex===e&&this.currentSteps[e]?.status==="loading"))return null;let i=this.confirmLoadingStartedAt||0;return(i?Date.now()-i:0)<3e4?null:u`<p class="progress-subtitle" style="margin-top:8px;color:#60a5fa">Verification can take from 30 seconds up to 10 minutes depending on the amount. Please wait…</p>`}catch{return null}}retryTransaction(){this.activeIndex=0,this.completed=!1,this.failed=!1,this.errorMessage=null,this.showSuccess=!1,this.showConfetti=!1,this.currentSteps=this.currentSteps.map(e=>({...e,status:"pending"})),this.updateStepStatus(0,"loading"),this.startAutomaticProgression(),this.requestUpdate()}closeProgress(){this.open=!1,this.showWalletSelector=!1,this.isTransitioning=!1}renderStep(e,t){return u`
189
+ `}renderConfirmTip(){try{let e=this.getStepIndexByKey("confirm");if(e<0||!(this.activeIndex===e&&this.currentSteps[e]?.status==="loading"))return null;let i=this.confirmLoadingStartedAt||0;return(i?Date.now()-i:0)<3e4?null:f`<p class="progress-subtitle" style="margin-top:8px;color:#60a5fa">Verification can take from 30 seconds up to 10 minutes depending on the amount. Please wait…</p>`}catch{return null}}retryTransaction(){this.activeIndex=0,this.completed=!1,this.failed=!1,this.errorMessage=null,this.showSuccess=!1,this.showConfetti=!1,this.currentSteps=this.currentSteps.map(e=>({...e,status:"pending"})),this.updateStepStatus(0,"loading"),this.startAutomaticProgression(),this.requestUpdate()}closeProgress(){this.open=!1,this.showWalletSelector=!1,this.isTransitioning=!1}renderStep(e,t){return f`
211
190
  <div class="step-item ${e.status}">
212
191
  <div class="step-icon">
213
192
  ${this.getStepIcon(e)}
@@ -216,65 +195,65 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as De}from"lit";var P=De`
216
195
  <div class="step-title">
217
196
  ${e.status==="completed"?"COMPLETED":e.label}
218
197
  </div>
219
- ${e.status==="completed"?u`
198
+ ${e.status==="completed"?f`
220
199
  <div class="step-subtitle">
221
200
  ${e.timestamp} - ${e.tooltip}
222
201
  </div>
223
- `:e.status==="error"&&e.errorMessage?u`
202
+ `:e.status==="error"&&e.errorMessage?f`
224
203
  <div class="step-error">${e.errorMessage}</div>
225
- `:u`
204
+ `:f`
226
205
  <div class="step-subtitle">${e.tooltip}</div>
227
206
  `}
228
207
  </div>
229
208
  </div>
230
- `}get isWalletConnectLoading(){try{let e=this.currentSteps.findIndex(t=>t.key==="wallet");return e<0?!1:this.currentSteps[e].status==="loading"&&!this.failed&&!this.showSuccess}catch{return!1}}render(){return u`
231
- ${this.open?u`
209
+ `}get isWalletConnectLoading(){try{let e=this.currentSteps.findIndex(t=>t.key==="wallet");return e<0?!1:this.currentSteps[e].status==="loading"&&!this.failed&&!this.showSuccess}catch{return!1}}render(){return f`
210
+ ${this.open?f`
232
211
  ${this.renderConfetti()}
233
212
  <div class="modal-overlay active">
234
213
  <div class="modal-container">
235
214
  <button class="close-button" @click=${()=>this.closeProgress()} aria-label="Close" title="Close">✕</button>
236
215
  <div class="modal-content ${this.isTransitioning?"transitioning":""}">
237
- ${this.showWalletSelector?this.renderWalletSelector():this.renderProgressContent()}
216
+ ${this.renderProgressContent()}
238
217
  </div>
239
218
  </div>
240
219
  </div>
241
220
  `:null}
242
- `}};m.styles=Fe`
221
+ `}};u.styles=Fe`
243
222
  :host {
244
223
  display: block;
245
224
  font-family: var(--icpay-font, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif);
246
225
  color: var(--icpay-text-primary, #ffffff);
247
-
226
+
248
227
  /* Theme variables for better composability */
249
228
  --icpay-bg-primary: #1f2937;
250
229
  --icpay-bg-secondary: rgba(255, 255, 255, 0.05);
251
230
  --icpay-bg-secondary-hover: rgba(255, 255, 255, 0.08);
252
231
  --icpay-bg-success: rgba(16, 185, 129, 0.1);
253
232
  --icpay-bg-error: rgba(239, 68, 68, 0.1);
254
-
233
+
255
234
  --icpay-text-primary: #ffffff;
256
235
  --icpay-text-secondary: #9ca3af;
257
236
  --icpay-text-muted: #6b7280;
258
-
237
+
259
238
  --icpay-border-primary: rgba(255, 255, 255, 0.1);
260
239
  --icpay-border-secondary: rgba(255, 255, 255, 0.2);
261
240
  --icpay-border-success: rgba(16, 185, 129, 0.3);
262
241
  --icpay-border-error: rgba(239, 68, 68, 0.3);
263
-
242
+
264
243
  --icpay-accent-primary: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
265
244
  --icpay-accent-success: linear-gradient(135deg, #10b981 0%, #059669 100%);
266
245
  --icpay-accent-error: #ef4444;
267
-
246
+
268
247
  --icpay-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
269
248
  --icpay-shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
270
249
  --icpay-shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
271
250
  --icpay-shadow-xl: 0 20px 25px rgba(0, 0, 0, 0.1);
272
-
251
+
273
252
  --icpay-radius-sm: 6px;
274
253
  --icpay-radius-md: 8px;
275
254
  --icpay-radius-lg: 12px;
276
255
  --icpay-radius-xl: 16px;
277
-
256
+
278
257
  --icpay-spacing-xs: 4px;
279
258
  --icpay-spacing-sm: 8px;
280
259
  --icpay-spacing-md: 12px;
@@ -427,90 +406,90 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as De}from"lit";var P=De`
427
406
  color: var(--icpay-text-primary);
428
407
  }
429
408
  .progress-subtitle { color: var(--icpay-text-secondary); font-size: 14px; }
430
- .progress-steps {
431
- margin-bottom: var(--icpay-spacing-xl);
432
- display: flex;
433
- flex-direction: column;
409
+ .progress-steps {
410
+ margin-bottom: var(--icpay-spacing-xl);
411
+ display: flex;
412
+ flex-direction: column;
434
413
  gap: var(--icpay-spacing-sm);
435
414
  }
436
- .step {
437
- width: 100%;
438
- padding: 12px 16px;
439
- background: rgba(255, 255, 255, 0.05);
440
- border: 1px solid rgba(255, 255, 255, 0.1);
441
- border-radius: 8px;
442
- display: flex;
443
- align-items: center;
444
- gap: 12px;
445
- opacity: 0.3;
446
- transition: all 0.3s ease;
415
+ .step {
416
+ width: 100%;
417
+ padding: 12px 16px;
418
+ background: rgba(255, 255, 255, 0.05);
419
+ border: 1px solid rgba(255, 255, 255, 0.1);
420
+ border-radius: 8px;
421
+ display: flex;
422
+ align-items: center;
423
+ gap: 12px;
424
+ opacity: 0.3;
425
+ transition: all 0.3s ease;
447
426
  cursor: default;
448
427
  box-sizing: border-box;
449
428
  }
450
- .step.active {
451
- opacity: 1;
429
+ .step.active {
430
+ opacity: 1;
452
431
  background: rgba(255, 255, 255, 0.05);
453
432
  border-color: rgba(255, 255, 255, 0.1);
454
433
  }
455
- .step.completed {
456
- opacity: 0.7;
434
+ .step.completed {
435
+ opacity: 0.7;
457
436
  background: rgba(16, 185, 129, 0.1);
458
437
  border-color: rgba(16, 185, 129, 0.3);
459
438
  }
460
-
461
- .step.error {
462
- opacity: 1;
439
+
440
+ .step.error {
441
+ opacity: 1;
463
442
  background: rgba(239, 68, 68, 0.1);
464
443
  border-color: rgba(239, 68, 68, 0.3);
465
444
  }
466
- .step-icon {
467
- width: 48px;
468
- height: 48px;
469
- border-radius: 12px;
470
- background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
471
- display: flex;
472
- align-items: center;
473
- justify-content: center;
474
- transition: all 0.3s ease;
475
- position: relative;
445
+ .step-icon {
446
+ width: 48px;
447
+ height: 48px;
448
+ border-radius: 12px;
449
+ background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
450
+ display: flex;
451
+ align-items: center;
452
+ justify-content: center;
453
+ transition: all 0.3s ease;
454
+ position: relative;
476
455
  flex-shrink: 0;
477
456
  }
478
- .step.active .step-icon {
479
- background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
457
+ .step.active .step-icon {
458
+ background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
480
459
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.3);
481
460
  }
482
- .step.completed .step-icon {
483
- background: linear-gradient(135deg, #10b981 0%, #059669 100%);
461
+ .step.completed .step-icon {
462
+ background: linear-gradient(135deg, #10b981 0%, #059669 100%);
484
463
  }
485
-
486
- .step.error .step-icon {
487
- background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
464
+
465
+ .step.error .step-icon {
466
+ background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
488
467
  }
489
- .step-icon svg {
490
- width: 20px;
491
- height: 20px;
492
- stroke: var(--icpay-text-primary);
493
- transition: stroke 0.3s ease;
468
+ .step-icon svg {
469
+ width: 20px;
470
+ height: 20px;
471
+ stroke: var(--icpay-text-primary);
472
+ transition: stroke 0.3s ease;
494
473
  }
495
- .step-content {
496
- flex: 1;
474
+ .step-content {
475
+ flex: 1;
497
476
  display: flex;
498
477
  flex-direction: column;
499
478
  gap: 0;
500
479
  }
501
- .step-title {
502
- font-weight: 500;
503
- font-size: 14px;
504
- color: #ffffff;
505
- transition: color 0.3s ease;
480
+ .step-title {
481
+ font-weight: 500;
482
+ font-size: 14px;
483
+ color: #ffffff;
484
+ transition: color 0.3s ease;
506
485
  margin: 0;
507
486
  }
508
- .step-description {
509
- font-size: 12px;
510
- color: #9ca3af;
487
+ .step-description {
488
+ font-size: 12px;
489
+ color: #9ca3af;
511
490
  margin: 0;
512
491
  }
513
-
492
+
514
493
  .step-error-message {
515
494
  font-size: 11px;
516
495
  color: #fca5a5;
@@ -520,53 +499,53 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as De}from"lit";var P=De`
520
499
  border-radius: 4px;
521
500
  border-left: 3px solid #ef4444;
522
501
  }
523
- .loading-spinner {
524
- display: none;
525
- width: 20px;
526
- height: 20px;
527
- border: 2px solid rgba(255, 255, 255, 0.2);
528
- border-top-color: var(--icpay-text-primary);
529
- border-radius: 50%;
530
- animation: spin 1s linear infinite;
531
- position: absolute;
502
+ .loading-spinner {
503
+ display: none;
504
+ width: 20px;
505
+ height: 20px;
506
+ border: 2px solid rgba(255, 255, 255, 0.2);
507
+ border-top-color: var(--icpay-text-primary);
508
+ border-radius: 50%;
509
+ animation: spin 1s linear infinite;
510
+ position: absolute;
532
511
  }
533
512
  .step.active .loading-spinner { display: block; }
534
513
 
535
- .error-container {
536
- text-align: center;
537
- }
538
-
539
- .error-icon-large {
540
- width: 64px;
541
- height: 64px;
542
- margin: 0 auto var(--icpay-spacing-lg);
543
- background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
544
- border-radius: var(--icpay-radius-xl);
545
- display: flex;
546
- align-items: center;
547
- justify-content: center;
548
- }
549
-
550
- .error-icon-large svg {
551
- width: 32px;
552
- height: 32px;
553
- stroke: var(--icpay-text-primary);
554
- stroke-width: 2;
555
- }
556
-
557
- .error-title {
558
- font-size: 20px;
559
- font-weight: 600;
560
- margin-bottom: var(--icpay-spacing-sm);
561
- color: var(--icpay-text-primary);
562
- }
563
-
564
- .error-message-text {
565
- color: var(--icpay-text-secondary);
566
- margin-bottom: var(--icpay-spacing-xl);
567
- font-size: 14px;
568
- }
569
-
514
+ .error-container {
515
+ text-align: center;
516
+ }
517
+
518
+ .error-icon-large {
519
+ width: 64px;
520
+ height: 64px;
521
+ margin: 0 auto var(--icpay-spacing-lg);
522
+ background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
523
+ border-radius: var(--icpay-radius-xl);
524
+ display: flex;
525
+ align-items: center;
526
+ justify-content: center;
527
+ }
528
+
529
+ .error-icon-large svg {
530
+ width: 32px;
531
+ height: 32px;
532
+ stroke: var(--icpay-text-primary);
533
+ stroke-width: 2;
534
+ }
535
+
536
+ .error-title {
537
+ font-size: 20px;
538
+ font-weight: 600;
539
+ margin-bottom: var(--icpay-spacing-sm);
540
+ color: var(--icpay-text-primary);
541
+ }
542
+
543
+ .error-message-text {
544
+ color: var(--icpay-text-secondary);
545
+ margin-bottom: var(--icpay-spacing-xl);
546
+ font-size: 14px;
547
+ }
548
+
570
549
  .error-details {
571
550
  background: rgba(239, 68, 68, 0.1);
572
551
  border: 1px solid rgba(239, 68, 68, 0.3);
@@ -575,34 +554,34 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as De}from"lit";var P=De`
575
554
  margin-bottom: var(--icpay-spacing-xl);
576
555
  text-align: left;
577
556
  }
578
-
557
+
579
558
  .error-detail-item {
580
559
  display: flex;
581
560
  justify-content: space-between;
582
561
  align-items: center;
583
562
  margin-bottom: var(--icpay-spacing-sm);
584
563
  }
585
-
564
+
586
565
  .error-detail-item:last-child {
587
566
  margin-bottom: 0;
588
567
  }
589
-
568
+
590
569
  .error-detail-label {
591
570
  font-size: 14px;
592
571
  color: var(--icpay-text-secondary);
593
572
  font-weight: 500;
594
573
  }
595
-
574
+
596
575
  .error-detail-value {
597
576
  font-size: 14px;
598
577
  color: var(--icpay-text-primary);
599
578
  font-weight: 600;
600
579
  }
601
-
602
- .error-actions {
603
- display: flex;
604
- gap: var(--icpay-spacing-sm);
605
- justify-content: center;
580
+
581
+ .error-actions {
582
+ display: flex;
583
+ gap: var(--icpay-spacing-sm);
584
+ justify-content: center;
606
585
  }
607
586
 
608
587
  .insufficient-funds-container {
@@ -718,68 +697,68 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as De}from"lit";var P=De`
718
697
  }
719
698
 
720
699
  .success-container { text-align: center; }
721
- .success-icon {
722
- width: 64px;
723
- height: 64px;
724
- margin: 0 auto var(--icpay-spacing-lg);
725
- background: var(--icpay-accent-success);
726
- border-radius: var(--icpay-radius-xl);
727
- display: flex;
728
- align-items: center;
729
- justify-content: center;
730
- }
731
- .success-icon svg {
732
- width: 32px;
733
- height: 32px;
734
- stroke: var(--icpay-text-primary);
735
- stroke-width: 2;
736
- }
737
- .success-title {
738
- font-size: 20px;
739
- font-weight: 600;
740
- margin-bottom: var(--icpay-spacing-sm);
741
- color: var(--icpay-text-primary);
742
- }
743
- .success-message {
744
- color: var(--icpay-text-secondary);
745
- margin-bottom: 20px;
746
- font-size: 14px;
747
- }
748
- .success-actions {
749
- display: flex;
750
- gap: var(--icpay-spacing-sm);
751
- justify-content: center;
752
- }
753
- .btn {
754
- padding: 10px 20px;
755
- border-radius: var(--icpay-radius-md);
756
- font-size: 14px;
757
- font-weight: 500;
758
- cursor: pointer;
759
- transition: all 0.3s ease;
760
- text-decoration: none;
761
- display: inline-flex;
762
- align-items: center;
763
- gap: var(--icpay-spacing-sm);
764
- }
765
- .btn-primary {
766
- background: var(--icpay-accent-primary);
767
- color: var(--icpay-text-primary);
768
- border: none;
769
- }
770
- .btn-primary:hover {
771
- transform: translateY(-1px);
772
- box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
773
- }
774
- .btn-secondary {
775
- background: transparent;
776
- color: var(--icpay-text-secondary);
777
- border: 1px solid var(--icpay-border-primary);
778
- }
779
- .btn-secondary:hover {
780
- background: var(--icpay-bg-secondary);
781
- border-color: var(--icpay-border-secondary);
782
- color: var(--icpay-text-primary);
700
+ .success-icon {
701
+ width: 64px;
702
+ height: 64px;
703
+ margin: 0 auto var(--icpay-spacing-lg);
704
+ background: var(--icpay-accent-success);
705
+ border-radius: var(--icpay-radius-xl);
706
+ display: flex;
707
+ align-items: center;
708
+ justify-content: center;
709
+ }
710
+ .success-icon svg {
711
+ width: 32px;
712
+ height: 32px;
713
+ stroke: var(--icpay-text-primary);
714
+ stroke-width: 2;
715
+ }
716
+ .success-title {
717
+ font-size: 20px;
718
+ font-weight: 600;
719
+ margin-bottom: var(--icpay-spacing-sm);
720
+ color: var(--icpay-text-primary);
721
+ }
722
+ .success-message {
723
+ color: var(--icpay-text-secondary);
724
+ margin-bottom: 20px;
725
+ font-size: 14px;
726
+ }
727
+ .success-actions {
728
+ display: flex;
729
+ gap: var(--icpay-spacing-sm);
730
+ justify-content: center;
731
+ }
732
+ .btn {
733
+ padding: 10px 20px;
734
+ border-radius: var(--icpay-radius-md);
735
+ font-size: 14px;
736
+ font-weight: 500;
737
+ cursor: pointer;
738
+ transition: all 0.3s ease;
739
+ text-decoration: none;
740
+ display: inline-flex;
741
+ align-items: center;
742
+ gap: var(--icpay-spacing-sm);
743
+ }
744
+ .btn-primary {
745
+ background: var(--icpay-accent-primary);
746
+ color: var(--icpay-text-primary);
747
+ border: none;
748
+ }
749
+ .btn-primary:hover {
750
+ transform: translateY(-1px);
751
+ box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
752
+ }
753
+ .btn-secondary {
754
+ background: transparent;
755
+ color: var(--icpay-text-secondary);
756
+ border: 1px solid var(--icpay-border-primary);
757
+ }
758
+ .btn-secondary:hover {
759
+ background: var(--icpay-bg-secondary);
760
+ border-color: var(--icpay-border-secondary);
761
+ color: var(--icpay-text-primary);
783
762
  }
784
763
 
785
764
  .confetti {
@@ -824,12 +803,12 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as De}from"lit";var P=De`
824
803
  opacity: 0;
825
804
  }
826
805
  }
827
- `,s([X({type:Boolean})],m.prototype,"open",2),s([X({type:Array})],m.prototype,"steps",2),s([X({type:Number})],m.prototype,"amount",2),s([X({type:String})],m.prototype,"currency",2),s([X({type:String})],m.prototype,"ledgerSymbol",2),s([X({type:Boolean})],m.prototype,"debug",2),s([$()],m.prototype,"activeIndex",2),s([$()],m.prototype,"completed",2),s([$()],m.prototype,"failed",2),s([$()],m.prototype,"errorMessage",2),s([$()],m.prototype,"showSuccess",2),s([$()],m.prototype,"showConfetti",2),s([$()],m.prototype,"currentSteps",2),s([$()],m.prototype,"currentAmount",2),s([$()],m.prototype,"currentCurrency",2),s([$()],m.prototype,"currentLedgerSymbol",2),s([$()],m.prototype,"confirmLoadingStartedAt",2),s([$()],m.prototype,"currentWalletType",2),s([$()],m.prototype,"showWalletSelector",2),s([$()],m.prototype,"isTransitioning",2),s([X({type:Object})],m.prototype,"theme",2),m=s([Ke("icpay-progress-bar")],m);import{html as xe}from"lit";function R(o){if(!o.visible)return null;let l=o.environment??"STAGING",e=o.width??420,t=o.height??680,i="";return o.sessionId&&(i=`${l==="PRODUCTION"?"https://global.transak.com":"https://global-stg.transak.com"}?sessionId=${encodeURIComponent(o.sessionId)}`),xe`
806
+ `,n([X({type:Boolean})],u.prototype,"open",2),n([X({type:Array})],u.prototype,"steps",2),n([X({type:Number})],u.prototype,"amount",2),n([X({type:String})],u.prototype,"currency",2),n([X({type:String})],u.prototype,"ledgerSymbol",2),n([X({type:Boolean})],u.prototype,"debug",2),n([$()],u.prototype,"activeIndex",2),n([$()],u.prototype,"completed",2),n([$()],u.prototype,"failed",2),n([$()],u.prototype,"errorMessage",2),n([$()],u.prototype,"showSuccess",2),n([$()],u.prototype,"showConfetti",2),n([$()],u.prototype,"currentSteps",2),n([$()],u.prototype,"currentAmount",2),n([$()],u.prototype,"currentCurrency",2),n([$()],u.prototype,"currentLedgerSymbol",2),n([$()],u.prototype,"confirmLoadingStartedAt",2),n([$()],u.prototype,"currentWalletType",2),n([$()],u.prototype,"showWalletSelector",2),n([$()],u.prototype,"isTransitioning",2),n([X({type:Object})],u.prototype,"theme",2),u=n([Ke("icpay-progress-bar")],u);import{html as xe}from"lit";function R(a){if(!a.visible)return null;let l=a.environment??"STAGING",e=a.width??420,t=a.height??680,i="";return a.sessionId&&(i=`${l==="PRODUCTION"?"https://global.transak.com":"https://global-stg.transak.com"}?sessionId=${encodeURIComponent(a.sessionId)}`),xe`
828
807
  <div style="position:fixed;inset:0;display:flex;align-items:center;justify-content:center;background:rgba(0,0,0,0.85);backdrop-filter:blur(10px);z-index:10000">
829
808
  <div style="position:relative;background:#0f1115;border:1px solid rgba(255,255,255,0.1);border-radius:16px;padding:16px;box-shadow:0 20px 60px rgba(0,0,0,0.5)">
830
- <button @click=${o.onClose} aria-label="Close" title="Close"
809
+ <button @click=${a.onClose} aria-label="Close" title="Close"
831
810
  style="position:absolute;top:10px;right:10px;background:transparent;border:none;color:#9ca3af;cursor:pointer;font-size:20px">✕</button>
832
- ${o.sessionId?xe`
811
+ ${a.sessionId?xe`
833
812
  <iframe
834
813
  id="transak-iframe"
835
814
  style="border:none;border-radius:12px;background:#111"
@@ -842,9 +821,9 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as De}from"lit";var P=De`
842
821
  <div style="width:${String(e)}px;max-width:90vw;padding:12px">
843
822
  <div style="background:#1a1f2e;border:1px solid rgba(255,255,255,0.1);border-radius:12px;padding:24px;color:#e5e7eb;text-align:center">
844
823
  <div style="font-size:18px;font-weight:600;margin-bottom:8px">Service unavailable</div>
845
- <div style="font-size:14px;opacity:0.85;margin-bottom:16px">${o.errorMessage||"The service is currently unavailable, please try again later."}</div>
824
+ <div style="font-size:14px;opacity:0.85;margin-bottom:16px">${a.errorMessage||"The service is currently unavailable, please try again later."}</div>
846
825
  <button
847
- @click=${()=>{o.onBack?o.onBack():o.onClose()}}
826
+ @click=${()=>{a.onBack?a.onBack():a.onClose()}}
848
827
  style="padding:10px 16px;border-radius:10px;border:1px solid rgba(255,255,255,0.15);background:linear-gradient(135deg,#3b82f6 0%,#10b981 100%);color:#fff;cursor:pointer;font-weight:600">
849
828
  Go back to wallet selection
850
829
  </button>
@@ -853,15 +832,15 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as De}from"lit";var P=De`
853
832
  `}
854
833
  </div>
855
834
  </div>
856
- `}import{LitElement as Qe,html as se,css as _e}from"lit";import{customElement as et,property as tt,state as N}from"lit/decorators.js";import{IcpayError as Pe}from"@ic-pay/icpay-sdk";var C={WALLET_NOT_CONNECTED:"WALLET_NOT_CONNECTED",WALLET_USER_CANCELLED:"WALLET_USER_CANCELLED",WALLET_SIGNATURE_REJECTED:"WALLET_SIGNATURE_REJECTED",INSUFFICIENT_BALANCE:"INSUFFICIENT_BALANCE",NETWORK_ERROR:"NETWORK_ERROR",API_ERROR:"API_ERROR",LEDGER_NOT_FOUND:"LEDGER_NOT_FOUND",TRANSACTION_FAILED:"TRANSACTION_FAILED",TRANSACTION_TIMEOUT:"TRANSACTION_TIMEOUT",UNKNOWN_ERROR:"UNKNOWN_ERROR"},He={onError:o=>{console.error("[ICPay Widget] Error:",o)},onUserCancelled:()=>{console.log("[ICPay Widget] User cancelled the action")},onInsufficientBalance:o=>{console.warn("[ICPay Widget] Insufficient balance:",o.message)},onWalletError:o=>{console.warn("[ICPay Widget] Wallet error:",o.message)},onNetworkError:o=>{console.error("[ICPay Widget] Network error:",o.message)}};function L(o,l=He){o instanceof Pe?(l.onError(o),o.isUserCancelled()?l.onUserCancelled?.():o.isBalanceError()?l.onInsufficientBalance?.(o):o.isWalletError()?l.onWalletError?.(o):o.isNetworkError()&&l.onNetworkError?.(o)):(console.error("[ICPay Widget] Unknown error:",o),l.onError(new Pe({code:C.UNKNOWN_ERROR,message:o instanceof Error?o.message:"An unknown error occurred",details:o})))}var Ve={[C.WALLET_NOT_CONNECTED]:"Please connect your wallet to continue",[C.WALLET_USER_CANCELLED]:"User have rejected the transfer",[C.WALLET_SIGNATURE_REJECTED]:"User have rejected the transfer",[C.INSUFFICIENT_BALANCE]:"Insufficient balance for this transaction",[C.NETWORK_ERROR]:"Network error. Please try again",[C.API_ERROR]:"Service temporarily unavailable",[C.LEDGER_NOT_FOUND]:"Selected token is not supported",[C.TRANSACTION_FAILED]:"Transaction failed. Please try again",[C.TRANSACTION_TIMEOUT]:"Transaction timed out. Please try again",[C.UNKNOWN_ERROR]:"Something went wrong. Please try again"};function O(o){return Ve[o.code]||o.message||"An error occurred"}function A(o){return!o.isUserCancelled()}function W(o){if(o.userAction)return o.userAction;switch(o.code){case C.WALLET_NOT_CONNECTED:return"Connect Wallet";case C.INSUFFICIENT_BALANCE:return"Add Funds";case C.NETWORK_ERROR:case C.API_ERROR:return"Try Again";default:return null}}function T(o){return o.isUserCancelled()?"info":o.isBalanceError()||o.isWalletError()?"warning":"error"}import{LitElement as Ge,html as Q,css as Ye}from"lit";import{customElement as Ze,property as _}from"lit/decorators.js";import{query as $e}from"lit/decorators.js";var B=class extends Ge{constructor(){super(...arguments);this.options=[];this.value=null;this.defaultSymbol="ICP";this.mode="buttons";this.open=!1;this.showLabel=!0;this.menuPos={left:0,top:0,width:0}}connectedCallback(){super.connectedCallback();try{ie(this,this.theme)}catch{}}updated(e){if(e.has("theme"))try{ie(this,this.theme)}catch{}}firstUpdated(){let e=i=>{if(!this.open)return;i.composedPath().includes(this)||this.closeDropdown()},t=i=>{i.key==="Escape"&&this.open&&this.closeDropdown()};this._onDocClick=e,this._onKey=t,window.addEventListener("click",e),window.addEventListener("keydown",t)}disconnectedCallback(){super.disconnectedCallback();let e=this._onDocClick,t=this._onKey;e&&window.removeEventListener("click",e),t&&window.removeEventListener("keydown",t)}get effectiveSymbol(){if(this.value)return this.value;let e=this.options?.[0]?.symbol;return this.defaultSymbol||e||"ICP"}getOptionBySymbol(e){return(this.options||[]).find(t=>t.symbol===e)}getLogoUrl(e){return`https://widget.icpay.org/ledger/${String(e||"").toLowerCase()}.svg`}onSelect(e){this.value=e,this.requestUpdate("value"),this.open=!1,this.dispatchEvent(new CustomEvent("icpay-token-change",{detail:{symbol:e},bubbles:!0,composed:!0}))}toggleDropdown(){this.open=!this.open}closeDropdown(){this.open=!1}render(){let e=this.options||[];if(this.mode==="none"||e.length<=1){let i=e.length===1?e[0].symbol:this.effectiveSymbol;return this.value!==i&&queueMicrotask(()=>this.onSelect(i)),Q``}if(this.mode==="dropdown"){let i=this.effectiveSymbol,n=this.getOptionBySymbol(i)||{symbol:i,label:i};return Q`
835
+ `}import{LitElement as Qe,html as se,css as _e}from"lit";import{customElement as et,property as tt,state as N}from"lit/decorators.js";import{IcpayError as Pe}from"@ic-pay/icpay-sdk";var I={WALLET_NOT_CONNECTED:"WALLET_NOT_CONNECTED",WALLET_USER_CANCELLED:"WALLET_USER_CANCELLED",WALLET_SIGNATURE_REJECTED:"WALLET_SIGNATURE_REJECTED",INSUFFICIENT_BALANCE:"INSUFFICIENT_BALANCE",NETWORK_ERROR:"NETWORK_ERROR",API_ERROR:"API_ERROR",LEDGER_NOT_FOUND:"LEDGER_NOT_FOUND",TRANSACTION_FAILED:"TRANSACTION_FAILED",TRANSACTION_TIMEOUT:"TRANSACTION_TIMEOUT",UNKNOWN_ERROR:"UNKNOWN_ERROR"},He={onError:a=>{console.error("[ICPay Widget] Error:",a)},onUserCancelled:()=>{console.log("[ICPay Widget] User cancelled the action")},onInsufficientBalance:a=>{console.warn("[ICPay Widget] Insufficient balance:",a.message)},onWalletError:a=>{console.warn("[ICPay Widget] Wallet error:",a.message)},onNetworkError:a=>{console.error("[ICPay Widget] Network error:",a.message)}};function O(a,l=He){a instanceof Pe?(l.onError(a),a.isUserCancelled()?l.onUserCancelled?.():a.isBalanceError()?l.onInsufficientBalance?.(a):a.isWalletError()?l.onWalletError?.(a):a.isNetworkError()&&l.onNetworkError?.(a)):(console.error("[ICPay Widget] Unknown error:",a),l.onError(new Pe({code:I.UNKNOWN_ERROR,message:a instanceof Error?a.message:"An unknown error occurred",details:a})))}var Ve={[I.WALLET_NOT_CONNECTED]:"Please connect your wallet to continue",[I.WALLET_USER_CANCELLED]:"User have rejected the transfer",[I.WALLET_SIGNATURE_REJECTED]:"User have rejected the transfer",[I.INSUFFICIENT_BALANCE]:"Insufficient balance for this transaction",[I.NETWORK_ERROR]:"Network error. Please try again",[I.API_ERROR]:"Service temporarily unavailable",[I.LEDGER_NOT_FOUND]:"Selected token is not supported",[I.TRANSACTION_FAILED]:"Transaction failed. Please try again",[I.TRANSACTION_TIMEOUT]:"Transaction timed out. Please try again",[I.UNKNOWN_ERROR]:"Something went wrong. Please try again"};function L(a){return Ve[a.code]||a.message||"An error occurred"}function A(a){return!a.isUserCancelled()}function W(a){if(a.userAction)return a.userAction;switch(a.code){case I.WALLET_NOT_CONNECTED:return"Connect Wallet";case I.INSUFFICIENT_BALANCE:return"Add Funds";case I.NETWORK_ERROR:case I.API_ERROR:return"Try Again";default:return null}}function T(a){return a.isUserCancelled()?"info":a.isBalanceError()||a.isWalletError()?"warning":"error"}import{LitElement as Ge,html as Q,css as Ye}from"lit";import{customElement as Ze,property as _}from"lit/decorators.js";import{query as $e}from"lit/decorators.js";var B=class extends Ge{constructor(){super(...arguments);this.options=[];this.value=null;this.defaultSymbol="ICP";this.mode="buttons";this.open=!1;this.showLabel=!0;this.menuPos={left:0,top:0,width:0}}connectedCallback(){super.connectedCallback();try{ie(this,this.theme)}catch{}}updated(e){if(e.has("theme"))try{ie(this,this.theme)}catch{}}firstUpdated(){let e=i=>{if(!this.open)return;i.composedPath().includes(this)||this.closeDropdown()},t=i=>{i.key==="Escape"&&this.open&&this.closeDropdown()};this._onDocClick=e,this._onKey=t,window.addEventListener("click",e),window.addEventListener("keydown",t)}disconnectedCallback(){super.disconnectedCallback();let e=this._onDocClick,t=this._onKey;e&&window.removeEventListener("click",e),t&&window.removeEventListener("keydown",t)}get effectiveSymbol(){if(this.value)return this.value;let e=this.options?.[0]?.symbol;return this.defaultSymbol||e||"ICP"}getOptionBySymbol(e){return(this.options||[]).find(t=>t.symbol===e)}getLogoUrl(e){return`https://widget.icpay.org/ledger/${String(e||"").toLowerCase()}.svg`}onSelect(e){this.value=e,this.requestUpdate("value"),this.open=!1,this.dispatchEvent(new CustomEvent("icpay-token-change",{detail:{symbol:e},bubbles:!0,composed:!0}))}toggleDropdown(){this.open=!this.open}closeDropdown(){this.open=!1}render(){let e=this.options||[];if(this.mode==="none"||e.length<=1){let i=e.length===1?e[0].symbol:this.effectiveSymbol;return this.value!==i&&queueMicrotask(()=>this.onSelect(i)),Q``}if(this.mode==="dropdown"){let i=this.effectiveSymbol,s=this.getOptionBySymbol(i)||{symbol:i,label:i};return Q`
857
836
  ${this.showLabel?Q`<label class="icpay-dropdown-label">Payment method</label>`:null}
858
837
  <div class="dropdown-wrapper">
859
838
  <div class="dropdown-trigger ${this.open?"open":""}" @click=${()=>this.toggleDropdown()}>
860
839
  <div class="selected-option">
861
- <img class="dropdown-selected-icon" src="${this.getLogoUrl(n.symbol)}" alt="${n.symbol}" />
840
+ <img class="dropdown-selected-icon" src="${this.getLogoUrl(s.symbol)}" alt="${s.symbol}" />
862
841
  <div class="crypto-info">
863
- <div class="dropdown-crypto-name">${n.label}</div>
864
- <div class="dropdown-crypto-symbol">${n.symbol}</div>
842
+ <div class="dropdown-crypto-name">${s.label}</div>
843
+ <div class="dropdown-crypto-symbol">${s.symbol}</div>
865
844
  </div>
866
845
  </div>
867
846
  <svg class="dropdown-arrow" fill="none" viewBox="0 0 24 24" stroke="currentColor" aria-hidden="true">
@@ -952,19 +931,19 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as De}from"lit";var P=De`
952
931
  .dropdown-option { padding: 10px 12px; }
953
932
  .dropdown-selected-icon { width: 28px; height: 28px; }
954
933
  }
955
- `,s([_({type:Array})],B.prototype,"options",2),s([_({type:String})],B.prototype,"value",2),s([_({type:String})],B.prototype,"defaultSymbol",2),s([_({type:String})],B.prototype,"mode",2),s([_({type:Object})],B.prototype,"theme",2),s([_({type:Boolean})],B.prototype,"open",2),s([_({type:Boolean})],B.prototype,"showLabel",2),s([$e(".dropdown-trigger")],B.prototype,"triggerEl",2),s([$e(".dropdown-wrapper")],B.prototype,"wrapperEl",2),B=s([Ze("icpay-token-selector")],B);import{html as ne}from"lit";var Je="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAACXBIWXMAAAsTAAALEwEAmpwYAAAE9GlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPD94cGFja2V0IGJlZ2luPSLvu78i iglkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4gPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iQWRvYmUgWE1QIENvcmUgOS4xLWMwMDIgNzkuZGJhM2RhM2I1LCAyMDIzLzEyLzE1LTEwOjQyOjM3ICAgICAgICAiPiA8cmRmOlJERiB4bWxuczpypmY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPiA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtbG5zOmRjPSJodHRwOi8vcHVybC5vcmcvZGMvZWxlbWVudHMvMS4xLyIgeG1sbnM6cGhvdG9zaG9wPSJodHRwOi8vbnMuYWRvYmUuY29tL3Bob3Rvc2hvcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RFdnQ9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS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Jq6TCZDn+GZqyTKC8ZzcT5GeDpFPdFH9YJH/vQsqJKvIQayO8pmgxFpV+Uiqcx7qWiTz/VPqb20ojD7OzMkbbH+S0tJL5SnZ3W1b1ldW8SfIfUWmt8PJ3U03edpI3eUkR9sesNFFpLD5XGKRCotgNjjGbNE9Ykx1eiuessjympBZI1cKS5Var1DaVDLU+qxHKpt6TpeBmJptOishnjKWpdpIT52O/lak9UvVB5ANMODxNL5VJmxMkyyTJqQhVqjiy+ou5rPQcYWjJrSgzITTl8CY6Q0Mwng0ckCUWZpzHeDuHkEeoSGNxYxJm3n4klXaoabuGLN84XTdk/AbjvcMZaNx2vokARjHPJEgZG2JTiaFFK89xguMTgiiFZEtecnaoJfPTyf0tQCSzg9XWirR5ZNJua5ETREhqV98GKymgRDBcQop4kCE5q0z2lzoeV6PWaimbp5TDNjdJ2TobHrPZJjaFPnrvmofoZaA2yeEb+OBoSVX+Fptxu1zMt08mM3l/okz0A2RNJ8+UyKHnJvucRt7fYo7G52n/P922iheCzzh8AAAAAElFTkSuQmCC";function qe(o){return!o||!o.startsWith("data:")?o:o.replace(/\s+/g,"")}function Xe(o,l){let e=(o||"").toLowerCase();return e==="ii"?"Internet Identity":e==="nfid"?"NFID":e==="plug"?"Plug":e==="oisy"?"Oisy":l&&l.trim()?l:o?o.charAt(0).toUpperCase()+o.slice(1):"Wallet"}function D(o){if(!o.visible)return null;let{wallets:l,onSelect:e,onClose:t,isConnecting:i}=o,n=l.map(a=>{let c=(a.id||"").toLowerCase();return{...a,icon:c==="nfid"?Je:a.icon??null}});return ne`
934
+ `,n([_({type:Array})],B.prototype,"options",2),n([_({type:String})],B.prototype,"value",2),n([_({type:String})],B.prototype,"defaultSymbol",2),n([_({type:String})],B.prototype,"mode",2),n([_({type:Object})],B.prototype,"theme",2),n([_({type:Boolean})],B.prototype,"open",2),n([_({type:Boolean})],B.prototype,"showLabel",2),n([$e(".dropdown-trigger")],B.prototype,"triggerEl",2),n([$e(".dropdown-wrapper")],B.prototype,"wrapperEl",2),B=n([Ze("icpay-token-selector")],B);import{html as ne}from"lit";var Je="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAACXBIWXMAAAsTAAALEwEAmpwYAAAE9GlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPD94cGFja2V0IGJlZ2luPSLvu78i iglkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4gPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iQWRvYmUgWE1QIENvcmUgOS4xLWMwMDIgNzkuZGJhM2RhM2I1LCAyMDIzLzEyLzE1LTEwOjQyOjM3ICAgICAgICAiPiA8cmRmOlJERiB4bWxuczpypmY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPiA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtbG5zOmRjPSJodHRwOi8vcHVybC5vcmcvZGMvZWxlbWVudHMvMS4xLyIgeG1sbnM6cGhvdG9zaG9wPSJodHRwOi8vbnMuYWRvYmUuY29tL3Bob3Rvc2hvcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RFdnQ9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZUV2ZW50IyIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgMjUuNyAoTWFjaW50b3NoKSIgeG1wOkNyZWF0ZURhdGU9IjIwMjUtMDktMDRUMTc6MTk6NDErMDI6MDAiIHhtcDpNb2RpZnlEYXRlPSIyMDI1LTA5LTA0VDE3OjIzOjU5KzAyOjAwIiB4bXA6TWV0YWRhdGFEYXRlPSIyMDI1LTA5LT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TJqQhVqjiy+ou5rPQcYWjJrSgzITTl8CY6Q0Mwng0ckCUWZpzHeDuHkEeoSGNxYxJm3n4klXaoabuGLN84XTdk/AbjvcMZaNx2vokARjHPJEgZG2JTiaFFK89xguMTgiiFZEtecnaoJfPTyf0tQCSzg9XWirR5ZNJua5ETREhqV98GKymgRDBcQop4kCE5q0z2lzoeV6PWaimbp5TDNjdJ2TobHrPZJjaFPnrvmofoZaA2yeEb+OBoSVX+Fptxu1zMt08mM3l/okz0A2RNJ8+UyKHnJvucRt7fYo7G52n/P922iheCzzh8AAAAAElFTkSuQmCC";function qe(a){return!a||!a.startsWith("data:")?a:a.replace(/\s+/g,"")}function Xe(a,l){let e=(a||"").toLowerCase();return e==="ii"?"Internet Identity":e==="nfid"?"NFID":e==="plug"?"Plug":e==="oisy"?"Oisy":l&&l.trim()?l:a?a.charAt(0).toUpperCase()+a.slice(1):"Wallet"}function D(a){if(!a.visible)return null;let{wallets:l,onSelect:e,onClose:t,isConnecting:i}=a,s=l.map(o=>{let c=(o.id||"").toLowerCase();return{...o,icon:c==="nfid"?Je:o.icon??null}});return ne`
956
935
  <div style="position:fixed;inset:0;display:flex;align-items:center;justify-content:center;background:rgba(0,0,0,0.5);z-index:10000">
957
936
  <div style="background:#1f2937;border-radius:12px;padding:24px;max-width:400px;width:90%;border:1px solid rgba(255,255,255,0.1);position:relative">
958
937
  <button @click=${t} style="position:absolute;top:16px;right:16px;width:32px;height:32px;display:flex;align-items:center;justify-content:center;color:#9ca3af;cursor:pointer;border:none;background:transparent;font-size:20px">✕</button>
959
938
  <h3 style="color:#fff;margin:0 48px 16px 0;font-size:18px;font-weight:600">Choose Wallet</h3>
960
939
  <div style="display:flex;flex-direction:column;gap:8px">
961
- ${n.map(a=>{let c=(a.id||"").toLowerCase(),d=Xe(a.id,a.label),p=ne`
940
+ ${s.map(o=>{let c=(o.id||"").toLowerCase(),d=Xe(o.id,o.label),p=ne`
962
941
  <button
963
- @click=${()=>e(a.id)}
942
+ @click=${()=>e(o.id)}
964
943
  style="width:100%;padding:12px 16px;background:rgba(255,255,255,0.05);border:1px solid rgba(255,255,255,0.1);border-radius:8px;color:#fff;text-align:left;cursor:pointer;font-size:14px;opacity:${i?.5:1};display:flex;align-items:center;gap:12px">
965
- ${a.icon?ne`
944
+ ${o.icon?ne`
966
945
  <div style="width:48px;height:48px;display:flex;align-items:center;justify-content:center">
967
- <img src="${qe(a.icon)}" alt="${d} logo" style="width:40px;height:40px;object-fit:cover;border-radius:12px" />
946
+ <img src="${qe(o.icon)}" alt="${d} logo" style="width:40px;height:40px;object-fit:cover;border-radius:12px" />
968
947
  </div>
969
948
  `:ne`
970
949
  <div style="width:48px;height:48px;background:linear-gradient(135deg,#3b82f6 0%,#8b5cf6 100%);border-radius:12px;display:flex;align-items:center;justify-content:center;font-size:12px;font-weight:bold">
@@ -987,8 +966,8 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as De}from"lit";var P=De`
987
966
  ${null}
988
967
  </div>
989
968
  </div>
990
- `}var Se=typeof window<"u",re=null;function G(o,l,e){o&&(e!==void 0?console.log(`[ICPay Widget] ${l}`,e):console.log(`[ICPay Widget] ${l}`))}var w=class extends Qe{constructor(){super(...arguments);this.selectedSymbol="ICP";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 n=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="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}}))}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 r={...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:c}=await import("./origin-44ZEXSX4.js");r.derivationOrigin=this.config?.derivationOrigin||c()}}catch{}this.pnp=new re(r);let a=this.pnp.getEnabledWallets();if(G(this.config?.debug||!1,"Available wallets",a),!a?.length)throw new Error("No wallets available");this.pendingAction="pay",this.showWalletModal=!0;return}catch(r){G(this.config?.debug||!1,"Wallet connection error:",r),this.errorMessage=r instanceof Error?r.message:"Wallet connection failed",this.errorSeverity="error";return}}G(this.config?.debug||!1,"Creating SDK for payment");let e=h(this.config),i=this.cryptoOptions.find(r=>r.symbol===this.selectedSymbol).canisterId||await e.client.getLedgerCanisterIdBySymbol(this.selectedSymbol);G(this.config?.debug||!1,"Payment details",{priceUsd:this.config.priceUsd,selectedSymbol:this.selectedSymbol,canisterId:i});let n=await e.sendUsd(this.config.priceUsd,i,{context:"premium-content"});G(this.config?.debug||!1,"Payment completed",{resp:n}),this.unlocked=!0,this.succeeded=!0,this.config.onSuccess&&this.config.onSuccess({id:n.transactionId,status:n.status}),this.dispatchEvent(new CustomEvent("icpay-unlock",{detail:{amount:this.config.priceUsd,tx:n},bubbles:!0}))}catch(e){L(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),A(t)&&(this.errorMessage=O(t),this.errorSeverity=T(t),this.errorAction=W(t))}})}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 n=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(n||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),i=this.cryptoOptions.find(d=>d.symbol===this.selectedSymbol).canisterId||await e.client.getLedgerCanisterIdBySymbol(this.selectedSymbol),n=await e.startOnrampUsd(this.config.priceUsd,i,{context:"premium:onramp"}),r=n?.metadata?.onramp?.sessionId||n?.metadata?.onramp?.session_id||null,a=n?.metadata?.paymentIntentId||n?.paymentIntentId||null,c=n?.metadata?.onramp?.errorMessage||null;this.onrampPaymentIntentId=a,r?(this.onrampSessionId=r,this.onrampErrorMessage=null,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.onrampErrorMessage=c||"Failed to obtain onramp sessionId",this.showOnrampModal=!0)}catch(e){this.onrampSessionId=null,this.onrampErrorMessage=e?.message||"Failed to obtain onramp sessionId",this.showOnrampModal=!0}}startOnrampPolling(e){if(this.onrampPollTimer){try{clearInterval(this.onrampPollTimer)}catch{}this.onrampPollTimer=null}if(this.onrampNotifyController){try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null}let t=this.onrampPaymentIntentId;if(!t)return;let i=h(this.config),n=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>n()),{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,a)=>this.pnp.getActor({canisterId:r,idl:a,requiresSigning:!0,anon:!1})},this.showWalletModal=!1;let n=this.pendingAction;this.pendingAction=null,n==="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`
991
- <div class="icpay-card icpay-section">
969
+ `}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){O(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),A(t)&&(this.errorMessage=L(t),this.errorSeverity=T(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`
970
+ <div class="icpay-card icpay-section icpay-widget-base">
992
971
  ${this.config?.progressBar?.enabled!==!1?se`
993
972
  <icpay-progress-bar
994
973
  .debug=${!!this.config?.debug}
@@ -1018,7 +997,7 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as De}from"lit";var P=De`
1018
997
  </div>
1019
998
 
1020
999
  <button class="pay-button ${this.processing?"processing":""}" ?disabled=${this.processing||this.unlocked||this.config?.disablePaymentButton===!0||this.succeeded&&this.config?.disableAfterSuccess===!0} @click=${()=>this.onPay()}>
1021
- ${this.unlocked?"Unlocked":this.processing?"Processing\u2026":(this.config?.buttonLabel||"Pay ${amount} with {symbol}").replace("{amount}",`${Number(this.config?.priceUsd??0).toFixed(2)}`).replace("{symbol}",this.selectedSymbol)}
1000
+ ${this.unlocked?"Unlocked":this.processing?"Processing\u2026":(this.config?.buttonLabel||"Pay ${amount} with {symbol}").replace("{amount}",`${Number(this.config?.priceUsd??0).toFixed(2)}`).replace("{symbol}",this.selectedSymbol||this.config?.defaultSymbol||"ICP")}
1022
1001
  </button>
1023
1002
 
1024
1003
  ${this.errorMessage?se`
@@ -1031,7 +1010,7 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as De}from"lit";var P=De`
1031
1010
  `:""}
1032
1011
  </div>
1033
1012
  `:""}
1034
- ${(()=>{let t=(this.pnp?.getEnabledWallets?.()||[]).map(i=>({id:this.getWalletId(i),label:this.getWalletLabel(i),icon:this.getWalletIcon(i)}));return D({visible:!!(this.showWalletModal&&this.pnp),wallets:t,isConnecting:!1,onSelect:i=>this.connectWithWallet(i),onClose:()=>{this.showWalletModal=!1},onCreditCard:this.config?.onramp?.enabled!==!1&&this.config?.onrampDisabled!==!0?()=>this.startOnramp():void 0,creditCardLabel:this.config?.onramp?.creditCardLabel||"Pay with credit card",showCreditCard:this.config?.onramp?.enabled!==!1&&this.config?.onrampDisabled!==!0,creditCardTooltip:(()=>{let n=Number(this.config?.priceUsd||0);return n>0&&n<5&&this.config?.onramp?.enabled!==!1&&this.config?.onrampDisabled!==!0?`Note: Minimum card amount is $5. You will pay about $${(5-n).toFixed(2)} more.`:null})()})})()}
1013
+ ${(()=>{let t=(this.pnp?.getEnabledWallets?.()||[]).map(i=>({id:this.getWalletId(i),label:this.getWalletLabel(i),icon:this.getWalletIcon(i)}));return D({visible:!!(this.showWalletModal&&this.pnp),wallets:t,isConnecting:!1,onSelect:i=>this.connectWithWallet(i),onClose:()=>{this.showWalletModal=!1},onCreditCard:this.config?.onramp?.enabled!==!1&&this.config?.onrampDisabled!==!0?()=>this.startOnramp():void 0,creditCardLabel:this.config?.onramp?.creditCardLabel||"Pay with credit card",showCreditCard:this.config?.onramp?.enabled!==!1&&this.config?.onrampDisabled!==!0,creditCardTooltip:(()=>{let s=Number(this.config?.priceUsd||0);return s>0&&s<5&&this.config?.onramp?.enabled!==!1&&this.config?.onrampDisabled!==!0?`Note: Minimum card amount is $5. You will pay about $${(5-s).toFixed(2)} more.`:null})()})})()}
1035
1014
 
1036
1015
  ${this.showOnrampModal?R({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}
1037
1016
  </div>
@@ -1086,8 +1065,8 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as De}from"lit";var P=De`
1086
1065
  border-color: rgba(239, 68, 68, 0.3);
1087
1066
  color: #ef4444;
1088
1067
  }
1089
- `],s([tt({type:Object})],w.prototype,"config",2),s([N()],w.prototype,"selectedSymbol",2),s([N()],w.prototype,"unlocked",2),s([N()],w.prototype,"succeeded",2),s([N()],w.prototype,"processing",2),s([N()],w.prototype,"availableLedgers",2),s([N()],w.prototype,"errorMessage",2),s([N()],w.prototype,"errorSeverity",2),s([N()],w.prototype,"errorAction",2),s([N()],w.prototype,"walletConnected",2),s([N()],w.prototype,"pendingAction",2),s([N()],w.prototype,"showWalletModal",2),s([N()],w.prototype,"showOnrampModal",2),s([N()],w.prototype,"onrampSessionId",2),s([N()],w.prototype,"onrampPaymentIntentId",2),s([N()],w.prototype,"onrampErrorMessage",2),w=s([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 k}from"lit/decorators.js";var Ee=typeof window<"u",ae=null;function Y(o,l,e){o&&(e!==void 0?console.log(`[ICPay Widget] ${l}`,e):console.log(`[ICPay Widget] ${l}`))}var f=class extends it{constructor(){super(...arguments);this.selectedAmount=1;this.selectedSymbol="ICP";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 n=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(),!!Ee){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(!(!Ee||!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="ICP")}}selectAmount(e){this.selectedAmount=e}selectSymbol(e){this.selectedSymbol=e}get fillPercentage(){return Math.min(this.total/50*100,100)}async tip(){if(Ee&&(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}}))}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 r={...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:c}=await import("./origin-44ZEXSX4.js");r.derivationOrigin=this.config?.derivationOrigin||c()}}catch{}this.pnp=new ae(r);let a=this.pnp.getEnabledWallets();if(Y(this.config?.debug||!1,"Available wallets",a),!a?.length)throw new Error("No wallets available");this.pendingAction="tip",this.showWalletModal=!0;return}catch(r){Y(this.config?.debug||!1,"Wallet connection error:",r),this.errorMessage=r instanceof Error?r.message:"Wallet connection failed",this.errorSeverity="error";return}}Y(this.config?.debug||!1,"Creating SDK for payment");let e=h(this.config),i=this.cryptoOptions.find(r=>r.symbol===this.selectedSymbol).canisterId||await e.client.getLedgerCanisterIdBySymbol(this.selectedSymbol);Y(this.config?.debug||!1,"Tip payment details",{amount:this.selectedAmount,selectedSymbol:this.selectedSymbol,canisterId:i});let n=await e.sendUsd(this.selectedAmount,i,{context:"tip-jar"});Y(this.config?.debug||!1,"Tip payment completed",{resp:n}),this.total+=this.selectedAmount,this.succeeded=!0,this.config.onSuccess&&this.config.onSuccess({id:n.transactionId,status:n.status,total:this.total}),this.dispatchEvent(new CustomEvent("icpay-tip",{detail:{amount:this.selectedAmount,tx:n},bubbles:!0}))}catch(e){L(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),A(t)&&(this.errorMessage=O(t),this.errorSeverity=T(t),this.errorAction=W(t))}})}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 n=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(n||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),i=this.cryptoOptions.find(d=>d.symbol===this.selectedSymbol).canisterId||await e.client.getLedgerCanisterIdBySymbol(this.selectedSymbol),n=await e.startOnrampUsd(this.selectedAmount,i,{context:"tip:onramp"}),r=n?.metadata?.onramp?.sessionId||n?.metadata?.onramp?.session_id||null,a=n?.metadata?.paymentIntentId||n?.paymentIntentId||null,c=n?.metadata?.onramp?.errorMessage||null;this.onrampPaymentIntentId=a,r?(this.onrampSessionId=r,this.onrampErrorMessage=null,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.onrampErrorMessage=c||"Failed to obtain onramp sessionId",this.showOnrampModal=!0)}catch(e){this.onrampSessionId=null,this.onrampErrorMessage=e?.message||"Failed to obtain onramp sessionId",this.showOnrampModal=!0}}startOnrampPolling(e){if(this.onrampPollTimer){try{clearInterval(this.onrampPollTimer)}catch{}this.onrampPollTimer=null}if(this.onrampNotifyController){try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null}let t=this.onrampPaymentIntentId;if(!t)return;let i=h(this.config),n=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>n()),{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,a)=>this.pnp.getActor({canisterId:r,idl:a,requiresSigning:!0,anon:!1})},this.showWalletModal=!1;let n=this.pendingAction;this.pendingAction=null,n==="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,n=i==="dropdown"?"dropdown":i==="none"?"none":"buttons",r=n!=="none"&&(t||n==="dropdown"),a=n==="dropdown"?"dropdown":t?"buttons":"none";return ee`
1090
- <div class="icpay-card icpay-section" style="text-align:center;">
1068
+ `],n([tt({type:Object})],w.prototype,"config",2),n([N()],w.prototype,"selectedSymbol",2),n([N()],w.prototype,"unlocked",2),n([N()],w.prototype,"succeeded",2),n([N()],w.prototype,"processing",2),n([N()],w.prototype,"availableLedgers",2),n([N()],w.prototype,"errorMessage",2),n([N()],w.prototype,"errorSeverity",2),n([N()],w.prototype,"errorAction",2),n([N()],w.prototype,"walletConnected",2),n([N()],w.prototype,"pendingAction",2),n([N()],w.prototype,"showWalletModal",2),n([N()],w.prototype,"showOnrampModal",2),n([N()],w.prototype,"onrampSessionId",2),n([N()],w.prototype,"onrampPaymentIntentId",2),n([N()],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 k}from"lit/decorators.js";var Ee=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(),!!Ee){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(!(!Ee||!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(Ee&&(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){O(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),A(t)&&(this.errorMessage=L(t),this.errorSeverity=T(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`
1069
+ <div class="icpay-card icpay-section icpay-widget-base" style="text-align:center;">
1091
1070
  ${this.config?.progressBar?.enabled!==!1?ee`
1092
1071
  <icpay-progress-bar
1093
1072
  .debug=${!!this.config?.debug}
@@ -1109,7 +1088,7 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as De}from"lit";var P=De`
1109
1088
  .options=${this.cryptoOptions}
1110
1089
  .value=${this.selectedSymbol||""}
1111
1090
  .defaultSymbol=${this.config?.defaultSymbol||"ICP"}
1112
- mode=${a}
1091
+ mode=${o}
1113
1092
  @icpay-token-change=${c=>this.selectSymbol(c.detail.symbol)}
1114
1093
  ></icpay-token-selector>
1115
1094
  </div>
@@ -1118,7 +1097,7 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as De}from"lit";var P=De`
1118
1097
  <button class="pay-button ${this.processing?"processing":""}"
1119
1098
  ?disabled=${this.processing||this.config?.disablePaymentButton===!0||this.succeeded&&this.config?.disableAfterSuccess===!0}
1120
1099
  @click=${()=>this.tip()}>
1121
- ${this.succeeded&&this.config?.disableAfterSuccess?"Paid":this.processing?"Processing\u2026":this.config?.buttonLabel?this.config.buttonLabel.replace("{amount}",String(this.selectedAmount)).replace("{symbol}",this.selectedSymbol):`Tip $${this.selectedAmount} with ${this.selectedSymbol}`}
1100
+ ${this.succeeded&&this.config?.disableAfterSuccess?"Paid":this.processing?"Processing\u2026":this.config?.buttonLabel?this.config.buttonLabel.replace("{amount}",String(this.selectedAmount)).replace("{symbol}",this.selectedSymbol||this.config?.defaultSymbol||"ICP"):`Tip $${this.selectedAmount} with ${this.selectedSymbol||this.config?.defaultSymbol||"ICP"}`}
1122
1101
  </button>
1123
1102
 
1124
1103
  ${this.errorMessage?ee`
@@ -1135,7 +1114,7 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as De}from"lit";var P=De`
1135
1114
 
1136
1115
  ${this.showOnrampModal?R({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}
1137
1116
  </div>
1138
- `}};f.styles=[P,nt`
1117
+ `}};y.styles=[P,nt`
1139
1118
  .jar { width: 120px; height: 160px; margin: 0 auto 12px; position: relative; background: linear-gradient(135deg, #374151 0%, #4b5563 100%); border-radius: 0 0 60px 60px; border: 3px solid #6b7280; border-top: 8px solid #6b7280; overflow: hidden; }
1140
1119
  .fill { position: absolute; bottom: 0; left: 0; right: 0; background: linear-gradient(135deg, #d1d5db 0%, #9ca3af 100%); transition: height 0.8s ease; height: 0%; }
1141
1120
  .amounts { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; margin: 12px 0; }
@@ -1167,9 +1146,9 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as De}from"lit";var P=De`
1167
1146
  border-color: rgba(239, 68, 68, 0.3);
1168
1147
  color: #ef4444;
1169
1148
  }
1170
- `],s([rt({type:Object})],f.prototype,"config",2),s([k()],f.prototype,"selectedAmount",2),s([k()],f.prototype,"selectedSymbol",2),s([k()],f.prototype,"total",2),s([k()],f.prototype,"processing",2),s([k()],f.prototype,"succeeded",2),s([k()],f.prototype,"availableLedgers",2),s([k()],f.prototype,"errorMessage",2),s([k()],f.prototype,"errorSeverity",2),s([k()],f.prototype,"errorAction",2),s([k()],f.prototype,"walletConnected",2),s([k()],f.prototype,"pendingAction",2),s([k()],f.prototype,"showWalletModal",2),s([k()],f.prototype,"showOnrampModal",2),s([k()],f.prototype,"onrampSessionId",2),s([k()],f.prototype,"onrampPaymentIntentId",2),s([k()],f.prototype,"onrampErrorMessage",2),f=s([st("icpay-tip-jar")],f);import{LitElement as ot,html as ye,css as at}from"lit";import{customElement as lt,property as we,state as U}from"lit/decorators.js";var ke=typeof window<"u",le=null;function Z(o,l,e){o&&(e!==void 0?console.log(`[ICPay Widget] ${l}`,e):console.log(`[ICPay Widget] ${l}`))}var y=class extends ot{constructor(){super(...arguments);this.title="Article Title";this.preview="";this.lockedContent="";this.selectedSymbol="ICP";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="unlock",this.walletConnected=!1,this.showWalletModal=!0,this.requestUpdate()}catch{}}}get obfuscatedLockedContent(){try{return(this.lockedContent||"").replace(/[^\s]/g,"x")}catch{return"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}}async tryAutoConnectPNP(){try{if(!this.config||this.config?.useOwnWallet)return;let e=localStorage.getItem("icpay:pnp");if(!e)return;let t=JSON.parse(e);if(!t?.provider||!t?.principal)return;le||(le=(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 n=new le(i);this.walletConnected=!1,this.config={...this.config,connectedWallet:{owner:t.principal,principal:t.principal,connected:!1}}}catch{}}attachTransakMessageListener(){if(!this.transakMessageHandlerBound){this.transakMessageHandlerBound=e=>this.onTransakMessage(e);try{window.addEventListener("message",this.transakMessageHandlerBound)}catch{}}}detachTransakMessageListener(){if(this.transakMessageHandlerBound){try{window.removeEventListener("message",this.transakMessageHandlerBound)}catch{}this.transakMessageHandlerBound=null}}onTransakMessage(e){let t=e?.data,i=t?.event_id||t?.eventId||t?.id;if(!(!i||typeof i!="string")&&i==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let n=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(n||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),i=this.cryptoOptions.find(d=>d.symbol===this.selectedSymbol).canisterId||await e.client.getLedgerCanisterIdBySymbol(this.selectedSymbol),n=await e.startOnrampUsd(this.config.priceUsd,i,{context:"article:onramp"}),r=n?.metadata?.onramp?.sessionId||n?.metadata?.onramp?.session_id||null,a=n?.metadata?.paymentIntentId||n?.paymentIntentId||null,c=n?.metadata?.onramp?.errorMessage||null;this.onrampPaymentIntentId=a,r?(this.onrampSessionId=r,this.onrampErrorMessage=null,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.onrampErrorMessage=c||"Failed to obtain onramp sessionId",this.showOnrampModal=!0)}catch(e){this.onrampSessionId=null,this.onrampErrorMessage=e?.message||"Failed to obtain onramp sessionId",this.showOnrampModal=!0}}startOnrampPolling(e){if(this.onrampPollTimer){try{clearInterval(this.onrampPollTimer)}catch{}this.onrampPollTimer=null}if(this.onrampNotifyController){try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null}let t=this.onrampPaymentIntentId;if(!t)return;let i=h(this.config),n=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>n()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=i.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}get cryptoOptions(){return this.config.cryptoOptions?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){if(super.connectedCallback(),!!ke){Z(this.config?.debug||!1,"Article paywall connected",{config:this.config}),this.config&&(typeof this.config.title=="string"&&(this.title=this.config.title),typeof this.config.preview=="string"&&(this.preview=this.config.preview),typeof this.config.lockedContent=="string"&&(this.lockedContent=this.config.lockedContent)),this.tryAutoConnectPNP();try{window.addEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers()}}updated(e){if(e.has("config")&&this.config&&(typeof this.config.title=="string"&&(this.title=this.config.title),typeof this.config.preview=="string"&&(this.preview=this.config.preview),typeof this.config.lockedContent=="string"&&(this.lockedContent=this.config.lockedContent)),e.has("config")&&this.pendingAction&&this.config?.actorProvider){let t=this.pendingAction;this.pendingAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}setTimeout(()=>{t==="unlock"&&this.unlock()},0)}}async loadVerifiedLedgers(){if(!(!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.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="ICP")}}selectSymbol(e){this.selectedSymbol=e}async unlock(){if(ke&&!(this.processing||this.unlocked)){Z(this.config?.debug||!1,"Article paywall unlock started",{priceUsd:this.config.priceUsd,selectedSymbol:this.selectedSymbol,useOwnWallet:this.config.useOwnWallet}),this.errorMessage=null,this.errorSeverity=null,this.errorAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"unlock",type:"sendUsd",amount:this.config.priceUsd,currency:this.selectedSymbol}}))}catch{}this.processing=!0;try{if(this.config.useOwnWallet){if(!this.config.actorProvider){this.pendingAction="unlock",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0}));return}}else if(!this.walletConnected){Z(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{le||(le=(await import("@windoge98/plug-n-play")).PNP);let r={...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:c}=await import("./origin-44ZEXSX4.js");r.derivationOrigin=this.config?.derivationOrigin||c()}}catch{}this.pnp=new le(r);let a=this.pnp.getEnabledWallets();if(Z(this.config?.debug||!1,"Available wallets",a),!a?.length)throw new Error("No wallets available");this.pendingAction="unlock",this.showWalletModal=!0;return}catch(r){Z(this.config?.debug||!1,"Wallet connection error:",r),this.errorMessage=r instanceof Error?r.message:"Wallet connection failed",this.errorSeverity="error";return}}Z(this.config?.debug||!1,"Creating SDK for payment");let e=h(this.config),i=this.cryptoOptions.find(r=>r.symbol===this.selectedSymbol).canisterId||await e.client.getLedgerCanisterIdBySymbol(this.selectedSymbol);Z(this.config?.debug||!1,"Article payment details",{priceUsd:this.config.priceUsd,selectedSymbol:this.selectedSymbol,canisterId:i});let n=await e.sendUsd(this.config.priceUsd,i,{context:"article"});Z(this.config?.debug||!1,"Article payment completed",{resp:n}),this.unlocked=!0,this.succeeded=!0,this.config.onSuccess&&this.config.onSuccess({id:n.transactionId,status:n.status}),this.dispatchEvent(new CustomEvent("icpay-unlock",{detail:{amount:this.config.priceUsd,tx:n},bubbles:!0}))}catch(e){L(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),A(t)&&(this.errorMessage=O(t),this.errorSeverity=T(t),this.errorAction=W(t))}})}finally{this.processing=!1}}}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}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,a)=>this.pnp.getActor({canisterId:r,idl:a,requiresSigning:!0,anon:!1})},this.showWalletModal=!1;let n=this.pendingAction;this.pendingAction=null,n==="unlock"&&setTimeout(()=>this.unlock(),0)}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}render(){return this.config?ye`
1171
- <div class="icpay-card icpay-section">
1172
- ${this.config?.progressBar?.enabled!==!1?ye`
1149
+ `],n([rt({type:Object})],y.prototype,"config",2),n([k()],y.prototype,"selectedAmount",2),n([k()],y.prototype,"selectedSymbol",2),n([k()],y.prototype,"total",2),n([k()],y.prototype,"processing",2),n([k()],y.prototype,"succeeded",2),n([k()],y.prototype,"availableLedgers",2),n([k()],y.prototype,"errorMessage",2),n([k()],y.prototype,"errorSeverity",2),n([k()],y.prototype,"errorAction",2),n([k()],y.prototype,"walletConnected",2),n([k()],y.prototype,"pendingAction",2),n([k()],y.prototype,"showWalletModal",2),n([k()],y.prototype,"showOnrampModal",2),n([k()],y.prototype,"onrampSessionId",2),n([k()],y.prototype,"onrampPaymentIntentId",2),n([k()],y.prototype,"onrampErrorMessage",2),y=n([st("icpay-tip-jar")],y);import{LitElement as ot,html as fe,css as at}from"lit";import{customElement as lt,property as we,state as U}from"lit/decorators.js";var ke=typeof window<"u",le=null;function Z(a,l,e){a&&(e!==void 0?console.log(`[ICPay Widget] ${l}`,e):console.log(`[ICPay Widget] ${l}`))}var m=class extends ot{constructor(){super(...arguments);this.title="Article Title";this.preview="";this.lockedContent="";this.selectedSymbol=null;this.unlocked=!1;this.succeeded=!1;this.processing=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.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="unlock",this.walletConnected=!1,this.showWalletModal=!0,this.requestUpdate()}catch{}}}get obfuscatedLockedContent(){try{return(this.lockedContent||"").replace(/[^\s]/g,"x")}catch{return"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}}async tryAutoConnectPNP(){try{if(!this.config||this.config?.useOwnWallet)return;let e=localStorage.getItem("icpay:pnp");if(!e)return;let t=JSON.parse(e);if(!t?.provider||!t?.principal)return;le||(le=(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 le(i);this.walletConnected=!1,this.config={...this.config,connectedWallet:{owner:t.principal,principal:t.principal,connected:!1}}}catch{}}attachTransakMessageListener(){if(!this.transakMessageHandlerBound){this.transakMessageHandlerBound=e=>this.onTransakMessage(e);try{window.addEventListener("message",this.transakMessageHandlerBound)}catch{}}}detachTransakMessageListener(){if(this.transakMessageHandlerBound){try{window.removeEventListener("message",this.transakMessageHandlerBound)}catch{}this.transakMessageHandlerBound=null}}onTransakMessage(e){let t=e?.data,i=t?.event_id||t?.eventId||t?.id;if(!(!i||typeof i!="string")&&i==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let s=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(s||void 0)}}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1,setTimeout(()=>this.createOnrampIntent(),0)}async createOnrampIntent(){try{let e=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:"article: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}get cryptoOptions(){return this.config.cryptoOptions?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){if(super.connectedCallback(),!!ke){Z(this.config?.debug||!1,"Article paywall connected",{config:this.config}),this.config&&(typeof this.config.title=="string"&&(this.title=this.config.title),typeof this.config.preview=="string"&&(this.preview=this.config.preview),typeof this.config.lockedContent=="string"&&(this.lockedContent=this.config.lockedContent)),this.tryAutoConnectPNP();try{window.addEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers()}}updated(e){if(e.has("config")&&this.config&&(typeof this.config.title=="string"&&(this.title=this.config.title),typeof this.config.preview=="string"&&(this.preview=this.config.preview),typeof this.config.lockedContent=="string"&&(this.lockedContent=this.config.lockedContent)),e.has("config")&&this.pendingAction&&this.config?.actorProvider){let t=this.pendingAction;this.pendingAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}setTimeout(()=>{t==="unlock"&&this.unlock()},0)}}async loadVerifiedLedgers(){if(!(!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.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||this.availableLedgers[0]?.symbol||"ICP")}catch(e){console.warn("Failed to load verified ledgers:",e),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||"ICP")}}selectSymbol(e){this.selectedSymbol=e}async unlock(){if(ke&&!(this.processing||this.unlocked)){Z(this.config?.debug||!1,"Article paywall unlock started",{priceUsd:this.config.priceUsd,selectedSymbol:this.selectedSymbol,useOwnWallet:this.config.useOwnWallet}),this.errorMessage=null,this.errorSeverity=null,this.errorAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"unlock",type:"sendUsd",amount:this.config.priceUsd,currency:this.selectedSymbol||this.config?.defaultSymbol}}))}catch{}this.processing=!0;try{if(this.config.useOwnWallet){if(!this.config.actorProvider){this.pendingAction="unlock",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0}));return}}else if(!this.walletConnected){Z(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{le||(le=(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 le(o);let c=this.pnp.getEnabledWallets();if(Z(this.config?.debug||!1,"Available wallets",c),!c?.length)throw new Error("No wallets available");this.pendingAction="unlock",this.showWalletModal=!0;return}catch(o){Z(this.config?.debug||!1,"Wallet connection error:",o),this.errorMessage=o instanceof Error?o.message:"Wallet connection failed",this.errorSeverity="error";return}}Z(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);Z(this.config?.debug||!1,"Article payment details",{priceUsd:this.config.priceUsd,selectedSymbol:t,canisterId:s});let r=await e.sendUsd(this.config.priceUsd,s,{context:"article"});Z(this.config?.debug||!1,"Article 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){O(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),A(t)&&(this.errorMessage=L(t),this.errorSeverity=T(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}}}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==="unlock"&&setTimeout(()=>this.unlock(),0)}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}render(){return this.config?fe`
1150
+ <div class="icpay-card icpay-section icpay-widget-base">
1151
+ ${this.config?.progressBar?.enabled!==!1?fe`
1173
1152
  <icpay-progress-bar
1174
1153
  .debug=${!!this.config?.debug}
1175
1154
  .theme=${this.config?.theme}
@@ -1196,24 +1175,24 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as De}from"lit";var P=De`
1196
1175
  ></icpay-token-selector>
1197
1176
  </div>
1198
1177
  <button class="pay-button ${this.processing?"processing":""}" ?disabled=${this.processing||this.unlocked||this.config?.disablePaymentButton===!0||this.succeeded&&this.config?.disableAfterSuccess===!0} @click=${()=>this.unlock()}>
1199
- ${this.unlocked?"Unlocked":this.processing?"Processing\u2026":(this.config?.buttonLabel||"Pay ${amount} with {symbol}").replace("{amount}",`${Number(this.config?.priceUsd??0).toFixed(2)}`).replace("{symbol}",this.selectedSymbol)}
1178
+ ${this.unlocked?"Unlocked":this.processing?"Processing\u2026":(this.config?.buttonLabel||"Pay ${amount} with {symbol}").replace("{amount}",`${Number(this.config?.priceUsd??0).toFixed(2)}`).replace("{symbol}",this.selectedSymbol||this.config?.defaultSymbol||"ICP")}
1200
1179
  </button>
1201
1180
 
1202
- ${this.errorMessage?ye`
1181
+ ${this.errorMessage?fe`
1203
1182
  <div class="error-message ${this.errorSeverity}" style="margin-top: 12px; padding: 8px 12px; border-radius: 6px; font-size: 14px; text-align: center;">
1204
1183
  ${this.errorMessage}
1205
- ${this.errorAction?ye`
1184
+ ${this.errorAction?fe`
1206
1185
  <button style="margin-left: 8px; padding: 4px 8px; background: transparent; border: 1px solid currentColor; border-radius: 4px; font-size: 12px; cursor: pointer;">
1207
1186
  ${this.errorAction}
1208
1187
  </button>
1209
1188
  `:""}
1210
1189
  </div>
1211
1190
  `:""}
1212
- ${(()=>{let t=(this.pnp?.getEnabledWallets?.()||[]).map(i=>({id:this.getWalletId(i),label:this.getWalletLabel(i),icon:this.getWalletIcon(i)}));return D({visible:!!(this.showWalletModal&&this.pnp),wallets:t,isConnecting:!1,onSelect:i=>this.connectWithWallet(i),onClose:()=>{this.showWalletModal=!1},onCreditCard:this.config?.onramp?.enabled!==!1&&this.config?.onrampDisabled!==!0?()=>this.startOnramp():void 0,creditCardLabel:this.config?.onramp?.creditCardLabel||"Pay with credit card",showCreditCard:this.config?.onramp?.enabled!==!1&&this.config?.onrampDisabled!==!0,creditCardTooltip:(()=>{let n=Number(this.config?.priceUsd||0);return n>0&&n<5&&this.config?.onramp?.enabled!==!1&&this.config?.onrampDisabled!==!0?`Note: Minimum card amount is $5. You will pay about $${(5-n).toFixed(2)} more.`:null})()})})()}
1191
+ ${(()=>{let t=(this.pnp?.getEnabledWallets?.()||[]).map(i=>({id:this.getWalletId(i),label:this.getWalletLabel(i),icon:this.getWalletIcon(i)}));return D({visible:!!(this.showWalletModal&&this.pnp),wallets:t,isConnecting:!1,onSelect:i=>this.connectWithWallet(i),onClose:()=>{this.showWalletModal=!1},onCreditCard:this.config?.onramp?.enabled!==!1&&this.config?.onrampDisabled!==!0?()=>this.startOnramp():void 0,creditCardLabel:this.config?.onramp?.creditCardLabel||"Pay with credit card",showCreditCard:this.config?.onramp?.enabled!==!1&&this.config?.onrampDisabled!==!0,creditCardTooltip:(()=>{let s=Number(this.config?.priceUsd||0);return s>0&&s<5&&this.config?.onramp?.enabled!==!1&&this.config?.onrampDisabled!==!0?`Note: Minimum card amount is $5. You will pay about $${(5-s).toFixed(2)} more.`:null})()})})()}
1213
1192
 
1214
1193
  ${this.showOnrampModal?R({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}
1215
1194
  </div>
1216
- `:ye`<div class="icpay-card icpay-section">Loading...</div>`}};y.styles=[P,at`
1195
+ `:fe`<div class="icpay-card icpay-section">Loading...</div>`}};m.styles=[P,at`
1217
1196
  .container { background: var(--icpay-surface-alt); border: 1px solid var(--icpay-border); border-radius: 16px; padding: 16px; margin-bottom: 16px; }
1218
1197
  .title { color: var(--icpay-text); font-weight: 700; margin-bottom: 8px; }
1219
1198
  .preview { color: var(--icpay-muted); margin-bottom: 12px; line-height: 1.6; }
@@ -1245,8 +1224,8 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as De}from"lit";var P=De`
1245
1224
  border-color: rgba(239, 68, 68, 0.3);
1246
1225
  color: #ef4444;
1247
1226
  }
1248
- `],s([we({type:Object})],y.prototype,"config",2),s([we({type:String})],y.prototype,"title",2),s([we({type:String})],y.prototype,"preview",2),s([we({type:String})],y.prototype,"lockedContent",2),s([U()],y.prototype,"selectedSymbol",2),s([U()],y.prototype,"unlocked",2),s([U()],y.prototype,"succeeded",2),s([U()],y.prototype,"processing",2),s([U()],y.prototype,"availableLedgers",2),s([U()],y.prototype,"errorMessage",2),s([U()],y.prototype,"errorSeverity",2),s([U()],y.prototype,"errorAction",2),s([U()],y.prototype,"walletConnected",2),s([U()],y.prototype,"pendingAction",2),s([U()],y.prototype,"showWalletModal",2),s([U()],y.prototype,"showOnrampModal",2),s([U()],y.prototype,"onrampSessionId",2),s([U()],y.prototype,"onrampPaymentIntentId",2),s([U()],y.prototype,"onrampErrorMessage",2),y=s([lt("icpay-article-paywall")],y);import{LitElement as ct,html as ce,css as dt}from"lit";import{customElement as pt,property as ht,state as z}from"lit/decorators.js";var Me=typeof window<"u",Ie=null;function J(o,l,e){o&&(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="ICP";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.availableLedgers.length>0&&!this.selectedSymbol&&(this.selectedSymbol=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="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}}))}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 r={...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:c}=await import("./origin-44ZEXSX4.js");r.derivationOrigin=this.config?.derivationOrigin||c()}}catch{}this.pnp=new Ie(r);let a=this.pnp.getEnabledWallets();if(J(this.config?.debug||!1,"Available wallets",a),!a?.length)throw new Error("No wallets available");this.pendingAction="order",this.showWalletModal=!0;return}catch(r){J(this.config?.debug||!1,"Wallet connection error:",r),this.errorMessage=r instanceof Error?r.message:"Wallet connection failed",this.errorSeverity="error";return}}J(this.config?.debug||!1,"Creating SDK for payment");let e=h(this.config),i=this.cryptoOptions.find(r=>r.symbol===this.selectedSymbol).canisterId||await e.client.getLedgerCanisterIdBySymbol(this.selectedSymbol);J(this.config?.debug||!1,"Coffee order payment details",{item:this.selectedItem.name,priceUsd:this.selectedItem.priceUsd,selectedSymbol:this.selectedSymbol,canisterId:i});let n=await e.sendUsd(this.selectedItem.priceUsd,i,{context:"coffee",item:this.selectedItem.name});J(this.config?.debug||!1,"Coffee order payment completed",{resp:n}),this.config.onSuccess&&this.config.onSuccess({id:n.transactionId,status:n.status,item:this.selectedItem.name}),this.dispatchEvent(new CustomEvent("icpay-coffee",{detail:{item:this.selectedItem,tx:n},bubbles:!0}))}catch(e){L(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),A(t)&&(this.errorMessage=O(t),this.errorSeverity=T(t),this.errorAction=W(t))}})}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 n=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(n||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),i=this.cryptoOptions.find(d=>d.symbol===this.selectedSymbol).canisterId||await e.client.getLedgerCanisterIdBySymbol(this.selectedSymbol),n=await e.startOnrampUsd(this.selectedItem.priceUsd,i,{context:"coffee:onramp",item:this.selectedItem.name}),r=n?.metadata?.onramp?.sessionId||n?.metadata?.onramp?.session_id||null,a=n?.metadata?.paymentIntentId||n?.paymentIntentId||null,c=n?.metadata?.onramp?.errorMessage||null;this.onrampPaymentIntentId=a,r?(this.onrampSessionId=r,this.onrampErrorMessage=null,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.onrampErrorMessage=c||"Failed to obtain onramp sessionId",this.showOnrampModal=!0)}catch(e){this.onrampSessionId=null,this.onrampErrorMessage=e?.message||"Failed to obtain onramp sessionId",this.showOnrampModal=!0}}startOnrampPolling(e){if(this.onrampPollTimer){try{clearInterval(this.onrampPollTimer)}catch{}this.onrampPollTimer=null}if(this.onrampNotifyController){try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null}let t=this.onrampPaymentIntentId;if(!t)return;let i=h(this.config),n=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>n()),{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,a)=>this.pnp.getActor({canisterId:r,idl:a,requiresSigning:!0,anon:!1})},this.showWalletModal=!1;let n=this.pendingAction;this.pendingAction=null,n==="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`
1249
- <div class="icpay-card icpay-section">
1227
+ `],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([U()],m.prototype,"selectedSymbol",2),n([U()],m.prototype,"unlocked",2),n([U()],m.prototype,"succeeded",2),n([U()],m.prototype,"processing",2),n([U()],m.prototype,"availableLedgers",2),n([U()],m.prototype,"errorMessage",2),n([U()],m.prototype,"errorSeverity",2),n([U()],m.prototype,"errorAction",2),n([U()],m.prototype,"walletConnected",2),n([U()],m.prototype,"pendingAction",2),n([U()],m.prototype,"showWalletModal",2),n([U()],m.prototype,"showOnrampModal",2),n([U()],m.prototype,"onrampSessionId",2),n([U()],m.prototype,"onrampPaymentIntentId",2),n([U()],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 z}from"lit/decorators.js";var Me=typeof window<"u",Ce=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{Ce||(Ce=(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 Ce(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){O(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),A(t)&&(this.errorMessage=L(t),this.errorSeverity=T(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`
1228
+ <div class="icpay-card icpay-section icpay-widget-base">
1250
1229
  ${this.config?.progressBar?.enabled!==!1?ce`
1251
1230
  <icpay-progress-bar
1252
1231
  .debug=${!!this.config?.debug}
@@ -1290,7 +1269,7 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as De}from"lit";var P=De`
1290
1269
  `:""}
1291
1270
  </div>
1292
1271
  `:""}
1293
- ${(()=>{let t=(this.pnp?.getEnabledWallets?.()||[]).map(i=>({id:this.getWalletId(i),label:this.getWalletLabel(i),icon:this.getWalletIcon(i)}));return D({visible:!!(this.showWalletModal&&this.pnp),wallets:t,isConnecting:!1,onSelect:i=>this.connectWithWallet(i),onClose:()=>{this.showWalletModal=!1},onCreditCard:this.config?.onramp?.enabled!==!1&&this.config?.onrampDisabled!==!0?()=>this.startOnramp():void 0,creditCardLabel:this.config?.onramp?.creditCardLabel||"Pay with credit card",showCreditCard:this.config?.onramp?.enabled!==!1&&this.config?.onrampDisabled!==!0,creditCardTooltip:(()=>{let n=this.config?.defaultItemIndex??0,r=Number(this.config?.items?.[n]?.priceUsd||0);return r>0&&r<5&&this.config?.onramp?.enabled!==!1&&this.config?.onrampDisabled!==!0?`Note: Minimum card amount is $5. You will pay about $${(5-r).toFixed(2)} more.`:null})()})})()}
1272
+ ${(()=>{let t=(this.pnp?.getEnabledWallets?.()||[]).map(i=>({id:this.getWalletId(i),label:this.getWalletLabel(i),icon:this.getWalletIcon(i)}));return D({visible:!!(this.showWalletModal&&this.pnp),wallets:t,isConnecting:!1,onSelect:i=>this.connectWithWallet(i),onClose:()=>{this.showWalletModal=!1},onCreditCard:this.config?.onramp?.enabled!==!1&&this.config?.onrampDisabled!==!0?()=>this.startOnramp():void 0,creditCardLabel:this.config?.onramp?.creditCardLabel||"Pay with credit card",showCreditCard:this.config?.onramp?.enabled!==!1&&this.config?.onrampDisabled!==!0,creditCardTooltip:(()=>{let s=this.config?.defaultItemIndex??0,r=Number(this.config?.items?.[s]?.priceUsd||0);return r>0&&r<5&&this.config?.onramp?.enabled!==!1&&this.config?.onrampDisabled!==!0?`Note: Minimum card amount is $5. You will pay about $${(5-r).toFixed(2)} more.`:null})()})})()}
1294
1273
 
1295
1274
  ${this.showOnrampModal?R({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}
1296
1275
  </div>
@@ -1325,8 +1304,8 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as De}from"lit";var P=De`
1325
1304
  border-color: rgba(239, 68, 68, 0.3);
1326
1305
  color: #ef4444;
1327
1306
  }
1328
- `],s([ht({type:Object})],x.prototype,"config",2),s([z()],x.prototype,"selectedIndex",2),s([z()],x.prototype,"selectedSymbol",2),s([z()],x.prototype,"processing",2),s([z()],x.prototype,"availableLedgers",2),s([z()],x.prototype,"errorMessage",2),s([z()],x.prototype,"errorSeverity",2),s([z()],x.prototype,"errorAction",2),s([z()],x.prototype,"walletConnected",2),s([z()],x.prototype,"pendingAction",2),s([z()],x.prototype,"showWalletModal",2),s([z()],x.prototype,"showOnrampModal",2),s([z()],x.prototype,"onrampSessionId",2),s([z()],x.prototype,"onrampPaymentIntentId",2),s([z()],x.prototype,"onrampErrorMessage",2),x=s([pt("icpay-coffee-shop")],x);import{LitElement as gt,html as de,css as ut}from"lit";import{customElement as mt,property as yt,state as M}from"lit/decorators.js";var Ce=typeof window<"u",pe=null;function q(o,l,e){o&&(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="ICP";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 n=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.availableLedgers.length>0&&!this.selectedSymbol&&(this.selectedSymbol=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="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}}))}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 r={...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:c}=await import("./origin-44ZEXSX4.js");r.derivationOrigin=this.config?.derivationOrigin||c()}}catch{}this.pnp=new pe(r);let a=this.pnp.getEnabledWallets();if(q(this.config?.debug||!1,"Available wallets",a),!a?.length)throw new Error("No wallets available");this.pendingAction="donate",this.showWalletModal=!0;return}catch(r){q(this.config?.debug||!1,"Wallet connection error:",r),this.errorMessage=r instanceof Error?r.message:"Wallet connection failed",this.errorSeverity="error";return}}q(this.config?.debug||!1,"Creating SDK for payment");let e=h(this.config),i=this.cryptoOptions.find(r=>r.symbol===this.selectedSymbol).canisterId||await e.client.getLedgerCanisterIdBySymbol(this.selectedSymbol);q(this.config?.debug||!1,"Donation payment details",{amount:this.selectedAmount,selectedSymbol:this.selectedSymbol,canisterId:i});let n=await e.sendUsd(this.selectedAmount,i,{context:"donation"});q(this.config?.debug||!1,"Donation payment completed",{resp:n}),this.raised+=this.selectedAmount,this.succeeded=!0,this.config.onSuccess&&this.config.onSuccess({id:n.transactionId,status:n.status,raised:this.raised}),this.dispatchEvent(new CustomEvent("icpay-donation",{detail:{amount:this.selectedAmount,tx:n},bubbles:!0}))}catch(e){L(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),A(t)&&(this.errorMessage=O(t),this.errorSeverity=T(t),this.errorAction=W(t))}})}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 n=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(n||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),i=this.cryptoOptions.find(d=>d.symbol===this.selectedSymbol).canisterId||await e.client.getLedgerCanisterIdBySymbol(this.selectedSymbol),n=await e.startOnrampUsd(this.selectedAmount,i,{context:"donation:onramp"}),r=n?.metadata?.onramp?.sessionId||n?.metadata?.onramp?.session_id||null,a=n?.metadata?.paymentIntentId||n?.paymentIntentId||null,c=n?.metadata?.onramp?.errorMessage||null;this.onrampPaymentIntentId=a,r?(this.onrampSessionId=r,this.onrampErrorMessage=null,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.onrampErrorMessage=c||"Failed to obtain onramp sessionId",this.showOnrampModal=!0)}catch(e){this.onrampSessionId=null,this.onrampErrorMessage=e?.message||"Failed to obtain onramp sessionId",this.showOnrampModal=!0}}startOnrampPolling(e){if(this.onrampPollTimer){try{clearInterval(this.onrampPollTimer)}catch{}this.onrampPollTimer=null}if(this.onrampNotifyController){try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null}let t=this.onrampPaymentIntentId;if(!t)return;let i=h(this.config),n=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>n()),{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,a)=>this.pnp.getActor({canisterId:r,idl:a,requiresSigning:!0,anon:!1})},this.showWalletModal=!1;let n=this.pendingAction;this.pendingAction=null,n==="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`
1329
- <div class="icpay-card icpay-section" style="text-align:center;">
1307
+ `],n([ht({type:Object})],x.prototype,"config",2),n([z()],x.prototype,"selectedIndex",2),n([z()],x.prototype,"selectedSymbol",2),n([z()],x.prototype,"processing",2),n([z()],x.prototype,"availableLedgers",2),n([z()],x.prototype,"errorMessage",2),n([z()],x.prototype,"errorSeverity",2),n([z()],x.prototype,"errorAction",2),n([z()],x.prototype,"walletConnected",2),n([z()],x.prototype,"pendingAction",2),n([z()],x.prototype,"showWalletModal",2),n([z()],x.prototype,"showOnrampModal",2),n([z()],x.prototype,"onrampSessionId",2),n([z()],x.prototype,"onrampPaymentIntentId",2),n([z()],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 Ie=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(),!!Ie){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(!(!Ie||!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(Ie&&!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){O(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),A(t)&&(this.errorMessage=L(t),this.errorSeverity=T(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`
1308
+ <div class="icpay-card icpay-section icpay-widget-base" style="text-align:center;">
1330
1309
  ${this.config?.progressBar?.enabled!==!1?de`
1331
1310
  <icpay-progress-bar
1332
1311
  .debug=${!!this.config?.debug}
@@ -1355,7 +1334,7 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as De}from"lit";var P=De`
1355
1334
  <button class="pay-button ${this.processing?"processing":""}"
1356
1335
  ?disabled=${this.processing||this.config?.disablePaymentButton===!0||this.succeeded&&this.config?.disableAfterSuccess===!0}
1357
1336
  @click=${()=>this.donate()}>
1358
- ${this.succeeded&&this.config?.disableAfterSuccess?"Donated":this.processing?"Processing\u2026":(this.config?.buttonLabel||"Donate {amount} with {symbol}").replace("{amount}",`${this.selectedAmount}`).replace("{symbol}",this.selectedSymbol)}
1337
+ ${this.succeeded&&this.config?.disableAfterSuccess?"Donated":this.processing?"Processing\u2026":(this.config?.buttonLabel||"Donate {amount} with {symbol}").replace("{amount}",`${this.selectedAmount}`).replace("{symbol}",this.selectedSymbol||this.config?.defaultSymbol||"ICP")}
1359
1338
  </button>
1360
1339
 
1361
1340
  ${this.errorMessage?de`
@@ -1368,7 +1347,7 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as De}from"lit";var P=De`
1368
1347
  `:""}
1369
1348
  </div>
1370
1349
  `:""}
1371
- ${(()=>{let t=(this.pnp?.getEnabledWallets?.()||[]).map(i=>({id:this.getWalletId(i),label:this.getWalletLabel(i),icon:this.getWalletIcon(i)}));return D({visible:!!(this.showWalletModal&&this.pnp),wallets:t,isConnecting:!1,onSelect:i=>this.connectWithWallet(i),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 n=Number(this.selectedAmount||this.config?.defaultAmountUsd||0);return n>0&&n<5&&this.config?.onramp?.enabled!==!1?`Note: Minimum card amount is $5. You will pay about $${(5-n).toFixed(2)} more.`:null})()})})()}
1350
+ ${(()=>{let t=(this.pnp?.getEnabledWallets?.()||[]).map(i=>({id:this.getWalletId(i),label:this.getWalletLabel(i),icon:this.getWalletIcon(i)}));return D({visible:!!(this.showWalletModal&&this.pnp),wallets:t,isConnecting:!1,onSelect:i=>this.connectWithWallet(i),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 s=Number(this.selectedAmount||this.config?.defaultAmountUsd||0);return s>0&&s<5&&this.config?.onramp?.enabled!==!1?`Note: Minimum card amount is $5. You will pay about $${(5-s).toFixed(2)} more.`:null})()})})()}
1372
1351
 
1373
1352
  ${this.showOnrampModal?R({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}
1374
1353
  </div>
@@ -1404,8 +1383,8 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as De}from"lit";var P=De`
1404
1383
  border-color: rgba(239, 68, 68, 0.3);
1405
1384
  color: #ef4444;
1406
1385
  }
1407
- `],s([yt({type:Object})],b.prototype,"config",2),s([M()],b.prototype,"selectedAmount",2),s([M()],b.prototype,"selectedSymbol",2),s([M()],b.prototype,"raised",2),s([M()],b.prototype,"processing",2),s([M()],b.prototype,"succeeded",2),s([M()],b.prototype,"availableLedgers",2),s([M()],b.prototype,"errorMessage",2),s([M()],b.prototype,"errorSeverity",2),s([M()],b.prototype,"errorAction",2),s([M()],b.prototype,"walletConnected",2),s([M()],b.prototype,"pendingAction",2),s([M()],b.prototype,"showWalletModal",2),s([M()],b.prototype,"showOnrampModal",2),s([M()],b.prototype,"onrampSessionId",2),s([M()],b.prototype,"onrampPaymentIntentId",2),s([M()],b.prototype,"onrampErrorMessage",2),b=s([mt("icpay-donation-thermometer")],b);import{LitElement as ft,html as he,css as bt}from"lit";import{customElement as vt,property as wt,state as F}from"lit/decorators.js";var Le=typeof window<"u",Oe=null;function fe(o,l,e){o&&(e!==void 0?console.log(`[ICPay Widget] ${l}`,e):console.log(`[ICPay Widget] ${l}`))}var S=class extends ft{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(),!!Le){fe(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)}async loadVerifiedLedgers(){if(!(!Le||!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{Oe||(Oe=(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 Oe(e);let t=this.pnp.getEnabledWallets();if(fe(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(fe(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(fe(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,a)=>this.pnp.getActor({canisterId:r,idl:a,requiresSigning:!0,anon:!1})},this.showWalletModal=!1;let n=this.pendingAction;this.pendingAction=null,n==="pay"&&setTimeout(()=>this.pay(),0)}catch(t){fe(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,n=5,r=Number(this.config?.amountUsd??0),a=i&&r>0&&r<n,c=Math.max(0,n-r),d=a?`Note: Minimum card amount is $${n}. You will pay about $${c.toFixed(2)} more.`:null;return D({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(),i=this.selectedSymbol||"ICP",r=this.cryptoOptions.find(E=>E.symbol===i)?.canisterId||await t.client.getLedgerCanisterIdBySymbol(i),a=await t.startOnrampUsd(e,r,{context:"pay-button:onramp"}),c=a?.metadata?.onramp?.sessionId||a?.metadata?.onramp?.session_id||null,d=a?.metadata?.onramp?.errorMessage||null;this.onrampErrorMessage=d||null;let p=a?.metadata?.paymentIntentId||a?.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,L(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),A(t)&&(this.errorMessage=O(t),this.errorSeverity=T(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 n=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(n||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(),n=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1},r=a=>{n()};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(!(!Le||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(),i=this.selectedSymbol||"ICP",r=this.cryptoOptions.find(p=>p.symbol===i)?.canisterId||await t.client.getLedgerCanisterIdBySymbol(i),a=Number(this.config?.amountUsd??0),c={context:"pay-button"},d=await t.sendUsd(a,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:a,tx:d},bubbles:!0}))}catch(e){L(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),A(t)&&(this.errorMessage=O(t),this.errorSeverity=T(t),this.errorAction=W(t))}})}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,n=i==="dropdown"?"dropdown":i==="none"?"none":"buttons",r=n!=="none"&&(t||n==="dropdown"),a=n==="dropdown"?"dropdown":t?"buttons":"none",c=this.selectedSymbol||this.config?.defaultSymbol||"ICP",d=typeof this.config?.amountUsd=="number"?`${Number(this.config.amountUsd).toFixed(2)}`:"",E=(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`
1408
- <div class="icpay-card icpay-section">
1386
+ `],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 F}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 D({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(E=>E.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,O(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),A(t)&&(this.errorMessage=L(t),this.errorSeverity=T(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){O(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),A(t)&&(this.errorMessage=L(t),this.errorSeverity=T(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)}`:"",E=(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`
1387
+ <div class="icpay-card icpay-section icpay-widget-base">
1409
1388
  ${be?he`
1410
1389
  <icpay-progress-bar
1411
1390
  .debug=${!!this.config?.debug}
@@ -1421,7 +1400,7 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as De}from"lit";var P=De`
1421
1400
  .options=${this.cryptoOptions}
1422
1401
  .value=${this.selectedSymbol||""}
1423
1402
  .defaultSymbol=${this.config?.defaultSymbol||"ICP"}
1424
- mode=${a}
1403
+ mode=${o}
1425
1404
  @icpay-token-change=${me=>this.selectSymbol(me.detail.symbol)}
1426
1405
  ></icpay-token-selector>
1427
1406
  `:null}
@@ -1449,8 +1428,8 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as De}from"lit";var P=De`
1449
1428
  .error-message.info { background: rgba(59,130,246,0.1); border-color: rgba(59,130,246,0.3); color: #3b82f6; }
1450
1429
  .error-message.warning { background: rgba(245,158,11,0.1); border-color: rgba(245,158,11,0.3); color: #f59e0b; }
1451
1430
  .error-message.error { background: rgba(239,68,68,0.1); border-color: rgba(239,68,68,0.3); color: #ef4444; }
1452
- `],s([wt({type:Object})],S.prototype,"config",2),s([F()],S.prototype,"selectedSymbol",2),s([F()],S.prototype,"processing",2),s([F()],S.prototype,"succeeded",2),s([F()],S.prototype,"availableLedgers",2),s([F()],S.prototype,"errorMessage",2),s([F()],S.prototype,"errorSeverity",2),s([F()],S.prototype,"errorAction",2),s([F()],S.prototype,"walletConnected",2),s([F()],S.prototype,"pendingAction",2),s([F()],S.prototype,"showWalletModal",2),s([F()],S.prototype,"showOnrampModal",2),s([F()],S.prototype,"onrampSessionId",2),s([F()],S.prototype,"onrampPaymentIntentId",2),s([F()],S.prototype,"onrampErrorMessage",2),S=s([vt("icpay-pay-button")],S);import{LitElement as xt,html as ge,css as St}from"lit";import{customElement as Et,property as kt,state as I}from"lit/decorators.js";var Ae=typeof window<"u",We=null;function Mt(o,l,e){o&&(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(),!!Ae){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(!(!Ae||!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)),n=Math.round(i/t)*t;this.amountUsd=Number(n.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{We||(We=(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 We(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,a)=>this.pnp.getActor({canisterId:r,idl:a,requiresSigning:!0,anon:!1})},this.showWalletModal=!1;let n=this.pendingAction;this.pendingAction=null,n==="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 n=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(n||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||"ICP",n=this.cryptoOptions.find(E=>E.symbol===t)?.canisterId||await e.client.getLedgerCanisterIdBySymbol(t),r=Number(this.amountUsd),a=await e.startOnrampUsd(r,n,{context:"amount-input:onramp"}),c=a?.metadata?.onramp?.sessionId||a?.metadata?.onramp?.session_id||null,d=a?.metadata?.paymentIntentId||a?.paymentIntentId||null,p=a?.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),n=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>n()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=i.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}async pay(){if(!(!Ae||this.processing)){if(this.errorMessage=null,this.errorSeverity=null,this.errorAction=null,!this.isValidAmount()){this.errorMessage="Please enter a valid amount",this.errorSeverity="warning";return}try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"pay",type:"sendUsd",amount:this.amountUsd,currency:this.selectedSymbol||this.config?.defaultSymbol}}))}catch{}this.processing=!0;try{if(!await this.ensureWallet())return;let t=h(this.config),i=this.selectedSymbol||"ICP",r=this.cryptoOptions.find(p=>p.symbol===i)?.canisterId||await t.client.getLedgerCanisterIdBySymbol(i),a=Number(this.amountUsd),c={context:"amount-input"},d=await t.sendUsd(a,r,c);this.config.onSuccess&&this.config.onSuccess({id:d.transactionId,status:d.status,amountUsd:a}),this.succeeded=!0,this.dispatchEvent(new CustomEvent("icpay-amount-pay",{detail:{amount:a,tx:d},bubbles:!0}))}catch(e){L(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),A(t)&&(this.errorMessage=O(t),this.errorSeverity=T(t),this.errorAction=W(t))}})}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"),n=this.cryptoOptions.find(K=>K.symbol===(this.selectedSymbol||""))?.label||this.cryptoOptions[0]?.label||this.config?.defaultSymbol||"ICP",r=this.config?.progressBar?.mode||"modal",a=this.config?.showLedgerDropdown,c=a==="buttons"?"buttons":a==="none"?"none":"dropdown",p=(this.cryptoOptions?.length||0)>1,E=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`
1453
- <div class="icpay-card icpay-section">
1431
+ `],n([wt({type:Object})],S.prototype,"config",2),n([F()],S.prototype,"selectedSymbol",2),n([F()],S.prototype,"processing",2),n([F()],S.prototype,"succeeded",2),n([F()],S.prototype,"availableLedgers",2),n([F()],S.prototype,"errorMessage",2),n([F()],S.prototype,"errorSeverity",2),n([F()],S.prototype,"errorAction",2),n([F()],S.prototype,"walletConnected",2),n([F()],S.prototype,"pendingAction",2),n([F()],S.prototype,"showWalletModal",2),n([F()],S.prototype,"showOnrampModal",2),n([F()],S.prototype,"onrampSessionId",2),n([F()],S.prototype,"onrampPaymentIntentId",2),n([F()],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 Et,property as kt,state as C}from"lit/decorators.js";var Ae=typeof window<"u",We=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(),!!Ae){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(!(!Ae||!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{We||(We=(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 We(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(E=>E.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(!(!Ae||this.processing)){if(this.errorMessage=null,this.errorSeverity=null,this.errorAction=null,!this.isValidAmount()){this.errorMessage="Please enter a valid amount",this.errorSeverity="warning";return}try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"pay",type:"sendUsd",amount:this.amountUsd,currency:this.selectedSymbol||this.config?.defaultSymbol}}))}catch{}this.processing=!0;try{if(!await this.ensureWallet())return;let t=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){O(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),A(t)&&(this.errorMessage=L(t),this.errorSeverity=T(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,E=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`
1432
+ <div class="icpay-card icpay-section icpay-widget-base">
1454
1433
  ${me?ge`
1455
1434
  <icpay-progress-bar
1456
1435
  .debug=${!!this.config?.debug}
@@ -1515,5 +1494,5 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as De}from"lit";var P=De`
1515
1494
  @media (max-width: 520px) {
1516
1495
  .top-row { grid-template-columns: 1fr; }
1517
1496
  }
1518
- `],s([kt({type:Object})],v.prototype,"config",2),s([I()],v.prototype,"amountUsd",2),s([I()],v.prototype,"hasUserAmount",2),s([I()],v.prototype,"selectedSymbol",2),s([I()],v.prototype,"processing",2),s([I()],v.prototype,"succeeded",2),s([I()],v.prototype,"availableLedgers",2),s([I()],v.prototype,"errorMessage",2),s([I()],v.prototype,"errorSeverity",2),s([I()],v.prototype,"errorAction",2),s([I()],v.prototype,"walletConnected",2),s([I()],v.prototype,"pendingAction",2),s([I()],v.prototype,"showWalletModal",2),s([I()],v.prototype,"showOnrampModal",2),s([I()],v.prototype,"onrampSessionId",2),s([I()],v.prototype,"onrampPaymentIntentId",2),s([I()],v.prototype,"onrampErrorMessage",2),v=s([Et("icpay-amount-input")],v);export{P as a,ie as b,h as c,R as d,w as e,f,y as g,x as h,b as i,S as j,v as k};
1519
- //# sourceMappingURL=chunk-7BODKC5B.js.map
1497
+ `],n([kt({type:Object})],v.prototype,"config",2),n([C()],v.prototype,"amountUsd",2),n([C()],v.prototype,"hasUserAmount",2),n([C()],v.prototype,"selectedSymbol",2),n([C()],v.prototype,"processing",2),n([C()],v.prototype,"succeeded",2),n([C()],v.prototype,"availableLedgers",2),n([C()],v.prototype,"errorMessage",2),n([C()],v.prototype,"errorSeverity",2),n([C()],v.prototype,"errorAction",2),n([C()],v.prototype,"walletConnected",2),n([C()],v.prototype,"pendingAction",2),n([C()],v.prototype,"showWalletModal",2),n([C()],v.prototype,"showOnrampModal",2),n([C()],v.prototype,"onrampSessionId",2),n([C()],v.prototype,"onrampPaymentIntentId",2),n([C()],v.prototype,"onrampErrorMessage",2),v=n([Et("icpay-amount-input")],v);export{P as a,ie as b,h as c,R as d,w as e,y as f,m as g,x as h,b as i,S as j,v as k};
1498
+ //# sourceMappingURL=chunk-NTH3U5KL.js.map