@ic-pay/icpay-widget 1.2.19 → 1.2.51

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.
@@ -56,7 +56,7 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var H=Xe`
56
56
  0%, 100% { opacity: 1; }
57
57
  50% { opacity: 0.7; }
58
58
  }
59
- `;function Ie(i,l){if(!i||!l)return;let e=l.primaryColor||void 0,t=l.secondaryColor||void 0,n=(C,B)=>{B&&i.style.setProperty(C,B)};n("--icpay-primary",e),n("--icpay-secondary",t);let a=C=>{if(!C)return null;let B=C.replace("#",""),me=B.length===3?B.split("").map($e=>$e+$e).join(""):B,ye=parseInt(me,16),fe=ye>>16&255,Ve=ye>>8&255,Ye=ye&255;return{r:fe,g:Ve,b:Ye}},c=(C=>{let B=a(C);if(!B)return 0;let me=ye=>{let fe=ye/255;return fe<=.03928?fe/12.92:Math.pow((fe+.055)/1.055,2.4)};return .2126*me(B.r)+.7152*me(B.g)+.0722*me(B.b)})(e||t)>.6,d=l.surfaceColor||(c?"#f3f4f6":"#1f2937"),h=l.surfaceAltColor||(c?"#e5e7eb":"#374151"),p=l.borderColor||(c?"#d1d5db":"#4b5563"),O=l.textColor||(c?"#111827":"#f9fafb"),K=l.accentColor||t||e||(c?"#6b7280":"#9ca3af"),ee=l.mutedTextColor||(c?"#6b7280":"#9ca3af");n("--icpay-accent",K),n("--icpay-text",O),n("--icpay-muted",ee),n("--icpay-surface",d),n("--icpay-surface-alt",h),n("--icpay-border",p)}import{Icpay as Be}from"@ic-pay/icpay-sdk";var Re=typeof window<"u";function ie(i,l,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${l}`,e):console.log(`[ICPay Widget] ${l}`))}function g(i){if(!Re)return{client:{},quoteUsd:async()=>({tokenAmountDecimals:"0"}),sendUsd:async()=>({transactionId:"0",status:"pending"}),startOnrampUsd:async()=>({transactionId:"0",status:"pending",metadata:{onramp:{sessionId:null}}}),notifyIntentUntilComplete:()=>({stop:()=>{}})};ie(i.debug||!1,"Creating SDK with config:",i);let l={publishableKey:i.publishableKey};i.enableEvents!==void 0?l.enableEvents=i.enableEvents:l.enableEvents=!0,i.apiUrl&&(l.apiUrl=i.apiUrl),i.icHost&&(l.icHost=i.icHost),i.actorProvider&&(l.actorProvider=i.actorProvider),i.connectedWallet&&(l.connectedWallet=i.connectedWallet),i.evmProvider&&(l.evmProvider=i.evmProvider),i.onrampDisabled!==void 0&&(l.onrampDisabled=i.onrampDisabled),i.debug!==void 0&&(l.debug=i.debug),ie(i.debug||!1,"Filtered SDK config:",l);try{let o=function(c,d,h){return t.notifyPaymentIntentOnRamp({paymentIntentId:c,intervalMs:d,orderId:h})};var e=o;ie(i.debug||!1,"typeof Icpay:",typeof Be);let t=new Be(l);if(Re){let c=t,d=h=>{c.addEventListener(h,p=>{window.dispatchEvent(new CustomEvent(h,{detail:p?.detail??p}))})};["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 n(c,d,h){if(typeof d=="string"&&d.trim().length>0)return t.calculateTokenAmountFromUSD({usdAmount:c,tokenShortcode:d.toLowerCase()});if(typeof h=="string"&&h.trim().length>0)return t.calculateTokenAmountFromUSD({usdAmount:c,ledgerCanisterId:h});throw new Error("quoteUsd requires tokenShortcode or ledgerCanisterId")}async function a(c,d,h,p){let O={...i.metadata,...h||{}},K=`Pay ${c} with crypto`,ee=i.description||O.__description||O.description||K,C={usdAmount:c,metadata:O,description:ee};if(typeof d=="string"&&d.trim().length>0&&(C.tokenShortcode=d.toLowerCase()),typeof p=="string"&&p.trim().length>0&&(C.ledgerCanisterId=p),!C.tokenShortcode&&!C.ledgerCanisterId)throw new Error("sendUsd requires tokenShortcode or ledgerCanisterId");return ie(!!i.debug,"Calling createPaymentUsd (flow decision handled by components)",C),t.createPaymentUsd(C)}async function r(c,d,h){let p={...i.metadata,...h||{}},O=`Pay ${c} with crypto`,K=i.description||p.__description||p.description||O;return ie(!!i.debug,"Calling onramp createPaymentUsd",{usdAmount:c,ledgerCanisterId:d,description:K}),t.createPaymentUsd({usdAmount:c,ledgerCanisterId:d,metadata:p,onrampPayment:!0,description:K})}return{client:t,quoteUsd:n,sendUsd:a,startOnrampUsd:r,notifyIntentUntilComplete:o}}catch(t){throw ie(i.debug||!1,"Error creating SDK:",t),t}}import{LitElement as Qe,html as N,css as Ze}from"lit";import{customElement as Je,property as ne,state as j}from"lit/decorators.js";function m(i,l,e){i&&(e!==void 0?console.log(l,e):console.log(l))}var et=[{key:"wallet",label:"Connect wallet",tooltip:"Awaiting wallet connection",status:"pending"},{key:"await",label:"Awaiting confirmation",tooltip:"Awaiting wallet signature",status:"pending"},{key:"transfer",label:"Transferring funds",tooltip:"Awaiting transfer to merchant",status:"pending"},{key:"verify",label:"Verifying payment",tooltip:"Please wait while we verify",status:"pending"}],f=class extends Qe{constructor(){super(...arguments);this.open=!1;this.suspended=!1;this.steps=et;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||"",n=e?.detail?.type||"";if(m(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(a=>({...a,status:"pending"})),n==="onramp"){let a=this.getStepIndexByKey("wallet");a>=0&&(this.currentSteps[a]={...this.currentSteps[a],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,m(this.debug,"ICPay Progress: Amount updated to:",e.detail.amount)),e?.detail?.currency&&(this.currentCurrency=e.detail.currency,this.currency=e.detail.currency,m(this.debug,"ICPay Progress: Currency updated to:",e.detail.currency)),e?.detail?.ledgerSymbol&&(this.currentLedgerSymbol=e.detail.ledgerSymbol,this.ledgerSymbol=e.detail.ledgerSymbol,m(this.debug,"ICPay Progress: Current state after method start:",{activeIndex:this.activeIndex,currentAmount:this.currentAmount,currentCurrency:this.currentCurrency,currentLedgerSymbol:this.currentLedgerSymbol})),m(this.debug,"ICPay Progress: Waiting for wallet confirmation before starting progression"),this.requestUpdate()}!this.failed&&!this.completed&&(t==="createPaymentX402Usd"?(this.completeByKey("wallet"),this.setLoadingByKey("await")):t==="sendFundsToLedger"?(this.completeByKey("wallet"),this.completeByKey("await"),this.setLoadingByKey("transfer")):t==="notifyLedgerTransaction"&&(this.completeByKey("wallet"),this.completeByKey("await"),this.setLoadingByKey("transfer")))};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.setLoadingByKey("await")):t==="sendFundsToLedger"?(this.completeByKey("wallet"),this.completeByKey("await"),this.completeByKey("transfer"),this.setLoadingByKey("verify")):t==="notifyLedgerTransaction"&&(this.completeByKey("wallet"),this.completeByKey("await"),this.completeByKey("transfer"),this.setLoadingByKey("verify")))};this.onTransactionCreated=e=>{let t=e?.detail?.transactionId||e?.detail?.id;m(this.debug,"ICPay Progress: Transaction created event received:",e.detail),!this.failed&&!this.completed&&(this.completeByKey("wallet"),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",n=e?.detail?.transactionId||e?.detail?.id;m(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:n,step:this.activeIndex},bubbles:!0}))};this.onTransactionCompleted=e=>{let t=e?.detail?.transactionId||e?.detail?.id,n=e?.detail?.status||"completed";m(this.debug,"ICPay Progress: Transaction completed event received:",e.detail),m(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("verify"),this.completed=!0,this.showSuccess=!0,this.showConfetti=!0,this.dispatchEvent(new CustomEvent("icpay-progress-completed",{detail:{transactionId:t,status:n,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",n=e?.detail?.error?.code||e?.detail?.code||"UNKNOWN_ERROR",a=e?.detail?.transactionId||e?.detail?.id;m(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:n,transactionId:a,step:this.activeIndex},bubbles:!0}))};this.onTransactionMismatched=e=>{let t=e?.detail?.requestedAmount,n=e?.detail?.paidAmount,a=e?.detail?.transactionId||e?.detail?.id;this.failed=!0;let r=t!=null?String(t):"unknown",o=n!=null?String(n):"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:a,step:this.activeIndex,requestedAmount:t,paidAmount:n},bubbles:!0}))};this.onMethodError=e=>{let t=e?.detail?.name||"",n=e?.detail?.error?.message||e?.detail?.message||"An error occurred",a=e?.detail?.error?.code||e?.detail?.code||"METHOD_ERROR";m(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(n),this.showSuccess=!1,this.updateStepStatus(this.activeIndex,"error",n),this.stopAutomaticProgression(),this.open=!0,this.dispatchEvent(new CustomEvent("icpay-progress-error",{detail:{methodName:t,errorMessage:n,errorCode:a,step:this.activeIndex},bubbles:!0})))};this.onSDKError=e=>{let t=e?.detail?.message||"SDK error occurred",n=e?.detail?.code||"SDK_ERROR";m(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:n,step:this.activeIndex},bubbles:!0}))};this.onWalletConnected=e=>{let t=e?.detail?.walletType||"unknown";m(this.debug,"ICPay Progress: Wallet connected event received:",e.detail),this.completeByKey("wallet"),this.setLoadingByKey("await"),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";m(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,n=e?.detail?.balance||0;m(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:n,required:this.currentAmount||this.amount,step:this.activeIndex},bubbles:!0})))};this.onLedgerVerified=e=>{let t=e?.detail?.ledgerId||e?.detail?.canisterId,n=e?.detail?.symbol||"unknown";m(this.debug,"ICPay Progress: Ledger verified event received:",e.detail),n&&n!=="unknown"&&(this.currentLedgerSymbol=n,this.ledgerSymbol=n),this.dispatchEvent(new CustomEvent("icpay-progress-ledger-verified",{detail:{ledgerId:t,symbol:n,step:this.activeIndex},bubbles:!0}))};this.onWidgetPayment=e=>{let t=e?.detail?.amount,n=e?.detail?.currency,a=e?.detail?.ledgerSymbol;if(m(this.debug,"ICPay Progress: Widget payment event received:",e.detail),t!==void 0&&(this.currentAmount=t,this.amount=t),n&&(this.currentCurrency=n,this.currency=n),a&&(this.currentLedgerSymbol=a,this.ledgerSymbol=a),!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:n,ledgerSymbol:a,step:this.activeIndex},bubbles:!0}))};this.onWidgetError=e=>{let t=e?.detail?.message||"Widget error occurred",n=e?.detail?.code||"WIDGET_ERROR";m(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:n,step:this.activeIndex},bubbles:!0}))};this.onWidgetUnlock=e=>{let t=e?.detail?.amount,n=e?.detail?.currency;if(m(this.debug,"ICPay Progress: Widget unlock event received:",e.detail),!this.failed){for(let a=this.activeIndex;a<this.currentSteps.length;a++)this.updateStepStatus(a,"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:n,step:this.activeIndex},bubbles:!0}))};this.onWidgetTip=e=>{let t=e?.detail?.amount,n=e?.detail?.currency;if(m(this.debug,"ICPay Progress: Widget tip event received:",e.detail),!this.failed){for(let a=this.activeIndex;a<this.currentSteps.length;a++)this.updateStepStatus(a,"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:n,step:this.activeIndex},bubbles:!0}))};this.onWidgetDonation=e=>{let t=e?.detail?.amount,n=e?.detail?.currency;if(m(this.debug,"ICPay Progress: Widget donation event received:",e.detail),!this.failed){for(let a=this.activeIndex;a<this.currentSteps.length;a++)this.updateStepStatus(a,"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:n,step:this.activeIndex},bubbles:!0}))};this.onWidgetCoffee=e=>{let t=e?.detail?.amount,n=e?.detail?.currency;if(m(this.debug,"ICPay Progress: Widget coffee event received:",e.detail),!this.failed){for(let a=this.activeIndex;a<this.currentSteps.length;a++)this.updateStepStatus(a,"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:n,step:this.activeIndex},bubbles:!0}))};this.onWalletCancelled=e=>{try{this.open=!0;let t=this.getStepIndexByKey("wallet");t>=0&&(this.activeIndex=t,this.currentSteps[t]={...this.currentSteps[t],tooltip:"Wallet connection cancelled",status:"error"},this.requestUpdate())}catch{}};this.onWalletError=e=>{try{let t=e?.detail?.message||"Wallet error",n=this.transformErrorMessage(t);this.open=!0;let a=this.getStepIndexByKey("wallet");a>=0&&(this.activeIndex=a,this.currentSteps[a]={...this.currentSteps[a],tooltip:"Wallet connection failed",status:"error",errorMessage:n},this.requestUpdate())}catch{}}}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-wallet-cancelled",this.onWalletCancelled),window.addEventListener("icpay-sdk-wallet-error",this.onWalletError),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-wallet-cancelled",this.onWalletCancelled),window.removeEventListener("icpay-sdk-wallet-error",this.onWalletError),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"),m(this.debug,"ICPay Progress: Starting automatic progression from step:",this.activeIndex),this.progressionTimer=setInterval(()=>{if(this.failed||this.completed){this.stopAutomaticProgression();return}m(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"),m(this.debug,"ICPay Progress: Auto-progressed to step:",this.activeIndex)):(this.stopAutomaticProgression(),m(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,n){if(e>=0&&e<this.currentSteps.length){let a=this.currentSteps[e],r=a.status;a.status=t,t==="completed"&&(a.timestamp=this.getCurrentTime()),t==="error"&&n&&(a.errorMessage=this.transformErrorMessage(n)),r!==t&&m(this.debug,`ICPay Progress: Step ${e} (${a.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){return e.status==="error"?N`<div class="error-x">✕</div>`:N`<div class="spinner"></div>`}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==="verify"&&(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},(n,a)=>a),t=["#0066FF","#ef4444","#10b981","#f59e0b","#8b5cf6"];return N`
59
+ `;function Oe(i,l){if(!i||!l)return;let e=l.primaryColor||void 0,t=l.secondaryColor||void 0,n=(C,B)=>{B&&i.style.setProperty(C,B)};n("--icpay-primary",e),n("--icpay-secondary",t);let a=C=>{if(!C)return null;let B=C.replace("#",""),me=B.length===3?B.split("").map($e=>$e+$e).join(""):B,ye=parseInt(me,16),fe=ye>>16&255,Ve=ye>>8&255,Ye=ye&255;return{r:fe,g:Ve,b:Ye}},c=(C=>{let B=a(C);if(!B)return 0;let me=ye=>{let fe=ye/255;return fe<=.03928?fe/12.92:Math.pow((fe+.055)/1.055,2.4)};return .2126*me(B.r)+.7152*me(B.g)+.0722*me(B.b)})(e||t)>.6,d=l.surfaceColor||(c?"#f3f4f6":"#1f2937"),h=l.surfaceAltColor||(c?"#e5e7eb":"#374151"),p=l.borderColor||(c?"#d1d5db":"#4b5563"),L=l.textColor||(c?"#111827":"#f9fafb"),K=l.accentColor||t||e||(c?"#6b7280":"#9ca3af"),ee=l.mutedTextColor||(c?"#6b7280":"#9ca3af");n("--icpay-accent",K),n("--icpay-text",L),n("--icpay-muted",ee),n("--icpay-surface",d),n("--icpay-surface-alt",h),n("--icpay-border",p)}import{Icpay as Be}from"@ic-pay/icpay-sdk";var Re=typeof window<"u";function ie(i,l,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${l}`,e):console.log(`[ICPay Widget] ${l}`))}function g(i){if(!Re)return{client:{},quoteUsd:async()=>({tokenAmountDecimals:"0"}),sendUsd:async()=>({transactionId:"0",status:"pending"}),startOnrampUsd:async()=>({transactionId:"0",status:"pending",metadata:{icpay_onramp:{sessionId:null}}}),notifyIntentUntilComplete:()=>({stop:()=>{}})};ie(i.debug||!1,"Creating SDK with config:",i);let l={publishableKey:i.publishableKey};i.enableEvents!==void 0?l.enableEvents=i.enableEvents:l.enableEvents=!0,i.apiUrl&&(l.apiUrl=i.apiUrl),i.icHost&&(l.icHost=i.icHost),i.actorProvider&&(l.actorProvider=i.actorProvider),i.connectedWallet&&(l.connectedWallet=i.connectedWallet),i.evmProvider&&(l.evmProvider=i.evmProvider),i.onrampDisabled!==void 0&&(l.onrampDisabled=i.onrampDisabled),i.debug!==void 0&&(l.debug=i.debug),ie(i.debug||!1,"Filtered SDK config:",l);try{let o=function(c,d,h){return t.notifyPaymentIntentOnRamp({paymentIntentId:c,intervalMs:d,orderId:h})};var e=o;ie(i.debug||!1,"typeof Icpay:",typeof Be);let t=new Be(l);if(Re){let c=t,d=h=>{c.addEventListener(h,p=>{window.dispatchEvent(new CustomEvent(h,{detail:p?.detail??p}))})};["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 n(c,d,h){if(typeof d=="string"&&d.trim().length>0)return t.calculateTokenAmountFromUSD({usdAmount:c,tokenShortcode:d.toLowerCase()});if(typeof h=="string"&&h.trim().length>0)return t.calculateTokenAmountFromUSD({usdAmount:c,ledgerCanisterId:h});throw new Error("quoteUsd requires tokenShortcode or ledgerCanisterId")}async function a(c,d,h,p){let L={...i.metadata,...h||{}},K=`Pay ${c} with crypto`,ee=i.description||L.__description||L.description||K,C={usdAmount:c,metadata:L,description:ee};if(typeof d=="string"&&d.trim().length>0&&(C.tokenShortcode=d.toLowerCase()),typeof p=="string"&&p.trim().length>0&&(C.ledgerCanisterId=p),!C.tokenShortcode&&!C.ledgerCanisterId)throw new Error("sendUsd requires tokenShortcode or ledgerCanisterId");return ie(!!i.debug,"Calling createPaymentUsd (flow decision handled by components)",C),t.createPaymentUsd(C)}async function r(c,d,h){let p={...i.metadata,...h||{}},L=`Pay ${c} with crypto`,K=i.description||p.__description||p.description||L;return ie(!!i.debug,"Calling onramp createPaymentUsd",{usdAmount:c,ledgerCanisterId:d,description:K}),t.createPaymentUsd({usdAmount:c,ledgerCanisterId:d,metadata:p,onrampPayment:!0,description:K})}return{client:t,quoteUsd:n,sendUsd:a,startOnrampUsd:r,notifyIntentUntilComplete:o}}catch(t){throw ie(i.debug||!1,"Error creating SDK:",t),t}}import{LitElement as Qe,html as N,css as Ze}from"lit";import{customElement as Je,property as ne,state as j}from"lit/decorators.js";function m(i,l,e){i&&(e!==void 0?console.log(l,e):console.log(l))}var et=[{key:"wallet",label:"Connect wallet",tooltip:"Awaiting wallet connection",status:"pending"},{key:"await",label:"Awaiting confirmation",tooltip:"Awaiting wallet signature",status:"pending"},{key:"transfer",label:"Transferring funds",tooltip:"Awaiting transfer to merchant",status:"pending"},{key:"verify",label:"Verifying payment",tooltip:"Please wait while we verify",status:"pending"}],f=class extends Qe{constructor(){super(...arguments);this.open=!1;this.suspended=!1;this.steps=et;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||"",n=e?.detail?.type||"";if(m(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(a=>({...a,status:"pending"})),n==="onramp"){let a=this.getStepIndexByKey("wallet");a>=0&&(this.currentSteps[a]={...this.currentSteps[a],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,m(this.debug,"ICPay Progress: Amount updated to:",e.detail.amount)),e?.detail?.currency&&(this.currentCurrency=e.detail.currency,this.currency=e.detail.currency,m(this.debug,"ICPay Progress: Currency updated to:",e.detail.currency)),e?.detail?.ledgerSymbol&&(this.currentLedgerSymbol=e.detail.ledgerSymbol,this.ledgerSymbol=e.detail.ledgerSymbol,m(this.debug,"ICPay Progress: Current state after method start:",{activeIndex:this.activeIndex,currentAmount:this.currentAmount,currentCurrency:this.currentCurrency,currentLedgerSymbol:this.currentLedgerSymbol})),m(this.debug,"ICPay Progress: Waiting for wallet confirmation before starting progression"),this.requestUpdate()}!this.failed&&!this.completed&&(t==="createPaymentX402Usd"?(this.completeByKey("wallet"),this.setLoadingByKey("await")):t==="sendFundsToLedger"?(this.completeByKey("wallet"),this.completeByKey("await"),this.setLoadingByKey("transfer")):t==="notifyLedgerTransaction"&&(this.completeByKey("wallet"),this.completeByKey("await"),this.setLoadingByKey("transfer")))};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.setLoadingByKey("await")):t==="sendFundsToLedger"?(this.completeByKey("wallet"),this.completeByKey("await"),this.completeByKey("transfer"),this.setLoadingByKey("verify")):t==="notifyLedgerTransaction"&&(this.completeByKey("wallet"),this.completeByKey("await"),this.completeByKey("transfer"),this.setLoadingByKey("verify")))};this.onTransactionCreated=e=>{let t=e?.detail?.transactionId||e?.detail?.id;m(this.debug,"ICPay Progress: Transaction created event received:",e.detail),!this.failed&&!this.completed&&(this.completeByKey("wallet"),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",n=e?.detail?.transactionId||e?.detail?.id;m(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:n,step:this.activeIndex},bubbles:!0}))};this.onTransactionCompleted=e=>{let t=e?.detail?.transactionId||e?.detail?.id,n=e?.detail?.status||"completed";m(this.debug,"ICPay Progress: Transaction completed event received:",e.detail),m(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("verify"),this.completed=!0,this.showSuccess=!0,this.showConfetti=!0,this.dispatchEvent(new CustomEvent("icpay-progress-completed",{detail:{transactionId:t,status:n,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",n=e?.detail?.error?.code||e?.detail?.code||"UNKNOWN_ERROR",a=e?.detail?.transactionId||e?.detail?.id;m(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:n,transactionId:a,step:this.activeIndex},bubbles:!0}))};this.onTransactionMismatched=e=>{let t=e?.detail?.requestedAmount,n=e?.detail?.paidAmount,a=e?.detail?.transactionId||e?.detail?.id;this.failed=!0;let r=t!=null?String(t):"unknown",o=n!=null?String(n):"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:a,step:this.activeIndex,requestedAmount:t,paidAmount:n},bubbles:!0}))};this.onMethodError=e=>{let t=e?.detail?.name||"",n=e?.detail?.error?.message||e?.detail?.message||"An error occurred",a=e?.detail?.error?.code||e?.detail?.code||"METHOD_ERROR";m(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(n),this.showSuccess=!1,this.updateStepStatus(this.activeIndex,"error",n),this.stopAutomaticProgression(),this.open=!0,this.dispatchEvent(new CustomEvent("icpay-progress-error",{detail:{methodName:t,errorMessage:n,errorCode:a,step:this.activeIndex},bubbles:!0})))};this.onSDKError=e=>{let t=e?.detail?.message||"SDK error occurred",n=e?.detail?.code||"SDK_ERROR";m(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:n,step:this.activeIndex},bubbles:!0}))};this.onWalletConnected=e=>{let t=e?.detail?.walletType||"unknown";m(this.debug,"ICPay Progress: Wallet connected event received:",e.detail),this.completeByKey("wallet"),this.setLoadingByKey("await"),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";m(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,n=e?.detail?.balance||0;m(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:n,required:this.currentAmount||this.amount,step:this.activeIndex},bubbles:!0})))};this.onLedgerVerified=e=>{let t=e?.detail?.ledgerId||e?.detail?.canisterId,n=e?.detail?.symbol||"unknown";m(this.debug,"ICPay Progress: Ledger verified event received:",e.detail),n&&n!=="unknown"&&(this.currentLedgerSymbol=n,this.ledgerSymbol=n),this.dispatchEvent(new CustomEvent("icpay-progress-ledger-verified",{detail:{ledgerId:t,symbol:n,step:this.activeIndex},bubbles:!0}))};this.onWidgetPayment=e=>{let t=e?.detail?.amount,n=e?.detail?.currency,a=e?.detail?.ledgerSymbol;if(m(this.debug,"ICPay Progress: Widget payment event received:",e.detail),t!==void 0&&(this.currentAmount=t,this.amount=t),n&&(this.currentCurrency=n,this.currency=n),a&&(this.currentLedgerSymbol=a,this.ledgerSymbol=a),!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:n,ledgerSymbol:a,step:this.activeIndex},bubbles:!0}))};this.onWidgetError=e=>{let t=e?.detail?.message||"Widget error occurred",n=e?.detail?.code||"WIDGET_ERROR";m(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:n,step:this.activeIndex},bubbles:!0}))};this.onWidgetUnlock=e=>{let t=e?.detail?.amount,n=e?.detail?.currency;if(m(this.debug,"ICPay Progress: Widget unlock event received:",e.detail),!this.failed){for(let a=this.activeIndex;a<this.currentSteps.length;a++)this.updateStepStatus(a,"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:n,step:this.activeIndex},bubbles:!0}))};this.onWidgetTip=e=>{let t=e?.detail?.amount,n=e?.detail?.currency;if(m(this.debug,"ICPay Progress: Widget tip event received:",e.detail),!this.failed){for(let a=this.activeIndex;a<this.currentSteps.length;a++)this.updateStepStatus(a,"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:n,step:this.activeIndex},bubbles:!0}))};this.onWidgetDonation=e=>{let t=e?.detail?.amount,n=e?.detail?.currency;if(m(this.debug,"ICPay Progress: Widget donation event received:",e.detail),!this.failed){for(let a=this.activeIndex;a<this.currentSteps.length;a++)this.updateStepStatus(a,"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:n,step:this.activeIndex},bubbles:!0}))};this.onWidgetCoffee=e=>{let t=e?.detail?.amount,n=e?.detail?.currency;if(m(this.debug,"ICPay Progress: Widget coffee event received:",e.detail),!this.failed){for(let a=this.activeIndex;a<this.currentSteps.length;a++)this.updateStepStatus(a,"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:n,step:this.activeIndex},bubbles:!0}))};this.onWalletCancelled=e=>{try{this.open=!0;let t=this.getStepIndexByKey("wallet");t>=0&&(this.activeIndex=t,this.currentSteps[t]={...this.currentSteps[t],tooltip:"Wallet connection cancelled",status:"error"},this.requestUpdate())}catch{}};this.onWalletError=e=>{try{let t=e?.detail?.message||"Wallet error",n=this.transformErrorMessage(t);this.open=!0;let a=this.getStepIndexByKey("wallet");a>=0&&(this.activeIndex=a,this.currentSteps[a]={...this.currentSteps[a],tooltip:"Wallet connection failed",status:"error",errorMessage:n},this.requestUpdate())}catch{}}}connectedCallback(){super.connectedCallback();try{Oe(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{Oe(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-wallet-cancelled",this.onWalletCancelled),window.addEventListener("icpay-sdk-wallet-error",this.onWalletError),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-wallet-cancelled",this.onWalletCancelled),window.removeEventListener("icpay-sdk-wallet-error",this.onWalletError),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"),m(this.debug,"ICPay Progress: Starting automatic progression from step:",this.activeIndex),this.progressionTimer=setInterval(()=>{if(this.failed||this.completed){this.stopAutomaticProgression();return}m(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"),m(this.debug,"ICPay Progress: Auto-progressed to step:",this.activeIndex)):(this.stopAutomaticProgression(),m(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,n){if(e>=0&&e<this.currentSteps.length){let a=this.currentSteps[e],r=a.status;a.status=t,t==="completed"&&(a.timestamp=this.getCurrentTime()),t==="error"&&n&&(a.errorMessage=this.transformErrorMessage(n)),r!==t&&m(this.debug,`ICPay Progress: Step ${e} (${a.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){return e.status==="error"?N`<div class="error-x">✕</div>`:N`<div class="spinner"></div>`}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==="verify"&&(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},(n,a)=>a),t=["#0066FF","#ef4444","#10b981","#f59e0b","#8b5cf6"];return N`
60
60
  <div class="confetti">
61
61
  ${e.map(n=>N`
62
62
  <div
@@ -863,12 +863,12 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var H=Xe`
863
863
  opacity: 0;
864
864
  }
865
865
  }
866
- `,s([ne({type:Boolean})],f.prototype,"open",2),s([ne({type:Boolean})],f.prototype,"suspended",2),s([ne({type:Array})],f.prototype,"steps",2),s([ne({type:Number})],f.prototype,"amount",2),s([ne({type:String})],f.prototype,"currency",2),s([ne({type:String})],f.prototype,"ledgerSymbol",2),s([ne({type:Boolean})],f.prototype,"debug",2),s([j()],f.prototype,"activeIndex",2),s([j()],f.prototype,"completed",2),s([j()],f.prototype,"failed",2),s([j()],f.prototype,"errorMessage",2),s([j()],f.prototype,"showSuccess",2),s([j()],f.prototype,"showConfetti",2),s([j()],f.prototype,"currentSteps",2),s([j()],f.prototype,"currentAmount",2),s([j()],f.prototype,"currentCurrency",2),s([j()],f.prototype,"currentLedgerSymbol",2),s([j()],f.prototype,"confirmLoadingStartedAt",2),s([j()],f.prototype,"currentWalletType",2),s([j()],f.prototype,"showWalletSelector",2),s([j()],f.prototype,"isTransitioning",2),s([ne({type:Object})],f.prototype,"theme",2),f=s([Je("icpay-progress-bar")],f);import{html as Oe}from"lit";function q(i){if(!i.visible)return null;let l=i.environment??"STAGING",e=i.width??420,t=i.height??680,n="";return i.sessionId&&(n=`${l==="PRODUCTION"?"https://global.transak.com":"https://global-stg.transak.com"}?sessionId=${encodeURIComponent(i.sessionId)}`),Oe`
866
+ `,s([ne({type:Boolean})],f.prototype,"open",2),s([ne({type:Boolean})],f.prototype,"suspended",2),s([ne({type:Array})],f.prototype,"steps",2),s([ne({type:Number})],f.prototype,"amount",2),s([ne({type:String})],f.prototype,"currency",2),s([ne({type:String})],f.prototype,"ledgerSymbol",2),s([ne({type:Boolean})],f.prototype,"debug",2),s([j()],f.prototype,"activeIndex",2),s([j()],f.prototype,"completed",2),s([j()],f.prototype,"failed",2),s([j()],f.prototype,"errorMessage",2),s([j()],f.prototype,"showSuccess",2),s([j()],f.prototype,"showConfetti",2),s([j()],f.prototype,"currentSteps",2),s([j()],f.prototype,"currentAmount",2),s([j()],f.prototype,"currentCurrency",2),s([j()],f.prototype,"currentLedgerSymbol",2),s([j()],f.prototype,"confirmLoadingStartedAt",2),s([j()],f.prototype,"currentWalletType",2),s([j()],f.prototype,"showWalletSelector",2),s([j()],f.prototype,"isTransitioning",2),s([ne({type:Object})],f.prototype,"theme",2),f=s([Je("icpay-progress-bar")],f);import{html as Le}from"lit";function q(i){if(!i.visible)return null;let l=i.environment??"STAGING",e=i.width??420,t=i.height??680,n="";return i.sessionId&&(n=`${l==="PRODUCTION"?"https://global.transak.com":"https://global-stg.transak.com"}?sessionId=${encodeURIComponent(i.sessionId)}`),Le`
867
867
  <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">
868
868
  <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)">
869
869
  <button @click=${i.onClose} aria-label="Close" title="Close"
870
870
  style="position:absolute;top:10px;right:10px;background:transparent;border:none;color:#9ca3af;cursor:pointer;font-size:20px">✕</button>
871
- ${i.sessionId?Oe`
871
+ ${i.sessionId?Le`
872
872
  <iframe
873
873
  id="transak-iframe"
874
874
  style="border:none;border-radius:12px;background:#111"
@@ -877,7 +877,7 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var H=Xe`
877
877
  src="${n}"
878
878
  allow="camera;microphone;payment"
879
879
  ></iframe>
880
- `:Oe`
880
+ `:Le`
881
881
  <div style="width:${String(e)}px;max-width:90vw;padding:12px">
882
882
  <div style="background:#1a1f2e;border:1px solid rgba(255,255,255,0.1);border-radius:12px;padding:24px;color:#e5e7eb;text-align:center">
883
883
  <div style="font-size:18px;font-weight:600;margin-bottom:8px">Service unavailable</div>
@@ -892,7 +892,7 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var H=Xe`
892
892
  `}
893
893
  </div>
894
894
  </div>
895
- `}import{LitElement as ct,html as se,css as dt}from"lit";import{customElement as pt,property as ht,state as A}from"lit/decorators.js";import{IcpayError as Pe}from"@ic-pay/icpay-sdk";var J={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"},tt={onError:i=>{console.error("[ICPay Widget] Error:",i)},onUserCancelled:()=>{console.log("[ICPay Widget] User cancelled the action")},onInsufficientBalance:i=>{console.warn("[ICPay Widget] Insufficient balance:",i.message)},onWalletError:i=>{console.warn("[ICPay Widget] Wallet error:",i.message)},onNetworkError:i=>{console.error("[ICPay Widget] Network error:",i.message)}};function P(i,l=tt){i instanceof Pe?(l.onError(i),i.isUserCancelled()?l.onUserCancelled?.():i.isBalanceError()?l.onInsufficientBalance?.(i):i.isWalletError()?l.onWalletError?.(i):i.isNetworkError()&&l.onNetworkError?.(i)):(console.error("[ICPay Widget] Unknown error:",i),l.onError(new Pe({code:J.UNKNOWN_ERROR,message:i instanceof Error?i.message:"An unknown error occurred",details:i})))}var nt={[J.WALLET_NOT_CONNECTED]:"Please connect your wallet to continue",[J.WALLET_USER_CANCELLED]:"User have rejected the transfer",[J.WALLET_SIGNATURE_REJECTED]:"User have rejected the transfer",[J.INSUFFICIENT_BALANCE]:"Insufficient balance for this transaction",[J.NETWORK_ERROR]:"Network error. Please try again",[J.API_ERROR]:"Service temporarily unavailable",[J.LEDGER_NOT_FOUND]:"Selected token is not supported",[J.TRANSACTION_FAILED]:"Transaction failed. Please try again",[J.TRANSACTION_TIMEOUT]:"Transaction timed out. Please try again",[J.UNKNOWN_ERROR]:"Something went wrong. Please try again"};function _(i){return nt[i.code]||i.message||"An error occurred"}function D(i){return!i.isUserCancelled()}function z(i){return null}function F(i){return i.isUserCancelled()?"info":i.isBalanceError()||i.isWalletError()?"warning":"error"}import{html as ae}from"lit";var _e=new Set(["metamask","coinbase","brave","rainbow","rabby","phantom","okx"]);function R(i){return i?_e.has(String(i).toLowerCase()):!1}function at(i){return i&&(i.id||i.provider||i.key)||""}function it(i){return i&&(i.label||i.name||i.title||i.id)||"Wallet"}function st(i){return i&&(i.icon||i.logo||i.image)||null}function G(i){return(i||[]).map(l=>({id:at(l),label:it(l),icon:st(l)}))}async function V(i,l){try{if(!window.ethereum||i===void 0||i===null)return!0;let e=typeof i=="number"?i:String(i).startsWith("0x")?parseInt(String(i),16):parseInt(String(i),10);if(!Number.isFinite(e))return!0;let t=await window.ethereum.request({method:"eth_chainId"});if(parseInt(t,16)===e)return!0;let a="0x"+e.toString(16);return await window.ethereum.request({method:"wallet_switchEthereumChain",params:[{chainId:a}]}),!0}catch{try{if(!window.ethereum||i===void 0||i===null)return!1;let t=typeof i=="number"?i:String(i).startsWith("0x")?parseInt(String(i),16):parseInt(String(i),10),n="0x"+t.toString(16),a=l?.chainName||`Network ${t}`,r=(l?.rpcUrlPublic?[l.rpcUrlPublic]:[]).filter(Boolean),o={name:l?.nativeSymbol||"ETH",symbol:l?.nativeSymbol||"ETH",decimals:typeof l?.decimals=="number"&&isFinite(l.decimals)?l.decimals:18};return await window.ethereum.request({method:"wallet_addEthereumChain",params:[{chainId:n,chainName:a,rpcUrls:r,nativeCurrency:o}]}),!0}catch{return!1}}}async function Y(i){let{sdk:l,lastWalletId:e,connectedWallet:t,amountUsd:n,chainShortcodes:a,tokenShortcodes:r}=i,o,c=(e||"").toLowerCase(),d=(t?.owner||t?.principal||"").toString();try{c&&_e.has(c)?o=await l?.client?.getExternalWalletBalances?.({network:"evm",address:d,amountUsd:n,chainShortcodes:a,tokenShortcodes:r}):o=await l?.client?.getExternalWalletBalances?.({network:"ic",principal:d,amountUsd:n,chainShortcodes:a,tokenShortcodes:r})}catch{o={balances:[],totalBalancesUSD:0,lastUpdated:new Date}}return{balances:(o?.balances||[]).map(p=>({ledgerId:p.ledgerId,ledgerName:p.ledgerName,ledgerSymbol:p.ledgerSymbol,tokenShortcode:p.tokenShortcode??p.shortcode??null,canisterId:p.canisterId,eip3009Version:p?.eip3009Version??null,x402Accepts:p?.x402Accepts!=null?!!p.x402Accepts:void 0,balance:p.balance,formattedBalance:p.formattedBalance,decimals:p.decimals,currentPrice:p.currentPrice,lastPriceUpdate:p.lastPriceUpdate?new Date(p.lastPriceUpdate):void 0,lastUpdated:p.lastUpdated?new Date(p.lastUpdated):new Date,chainId:typeof p.chainId=="string"?p.chainId:typeof p.chainId=="number"?String(p.chainId):void 0,chainName:p.chainName||p.chain&&(p.chain.name||p.chain.chainName)||p.networkName||void 0,rpcUrlPublic:p.rpcUrlPublic,chainUuid:p.chainUuid,requiredAmount:p.requiredAmount,requiredAmountFormatted:p.requiredAmountFormatted,hasSufficientBalance:p.hasSufficientBalance,logoUrl:p.logoUrl??null})),totalBalancesUSD:o?.totalBalancesUSD,lastUpdated:o?.lastUpdated?new Date(o.lastUpdated):new Date}}function We(i){let l=Number(i);if(!isFinite(l)||l===0)return"0";if(Math.abs(l)<1e-5)return"< 0.00001";let t=1e5;return(Math.trunc(l*t)/t).toFixed(5).replace(/\.0+$/,"").replace(/(\.[0-9]*?)0+$/,"$1")}import{html as X}from"lit";function Le(i){let l=parseFloat(String(i.formattedBalance||"0")),e=Number(i.currentPrice??0),t=(isFinite(l)?l:0)*(isFinite(e)?e:0);return isFinite(t)?t:0}var De=(i,l)=>Le(l)-Le(i);function Ce(){return X`<style>
895
+ `}import{LitElement as ct,html as se,css as dt}from"lit";import{customElement as pt,property as ht,state as A}from"lit/decorators.js";import{IcpayError as Pe}from"@ic-pay/icpay-sdk";var J={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"},tt={onError:i=>{console.error("[ICPay Widget] Error:",i)},onUserCancelled:()=>{console.log("[ICPay Widget] User cancelled the action")},onInsufficientBalance:i=>{console.warn("[ICPay Widget] Insufficient balance:",i.message)},onWalletError:i=>{console.warn("[ICPay Widget] Wallet error:",i.message)},onNetworkError:i=>{console.error("[ICPay Widget] Network error:",i.message)}};function P(i,l=tt){i instanceof Pe?(l.onError(i),i.isUserCancelled()?l.onUserCancelled?.():i.isBalanceError()?l.onInsufficientBalance?.(i):i.isWalletError()?l.onWalletError?.(i):i.isNetworkError()&&l.onNetworkError?.(i)):(console.error("[ICPay Widget] Unknown error:",i),l.onError(new Pe({code:J.UNKNOWN_ERROR,message:i instanceof Error?i.message:"An unknown error occurred",details:i})))}var nt={[J.WALLET_NOT_CONNECTED]:"Please connect your wallet to continue",[J.WALLET_USER_CANCELLED]:"User have rejected the transfer",[J.WALLET_SIGNATURE_REJECTED]:"User have rejected the transfer",[J.INSUFFICIENT_BALANCE]:"Insufficient balance for this transaction",[J.NETWORK_ERROR]:"Network error. Please try again",[J.API_ERROR]:"Service temporarily unavailable",[J.LEDGER_NOT_FOUND]:"Selected token is not supported",[J.TRANSACTION_FAILED]:"Transaction failed. Please try again",[J.TRANSACTION_TIMEOUT]:"Transaction timed out. Please try again",[J.UNKNOWN_ERROR]:"Something went wrong. Please try again"};function _(i){return nt[i.code]||i.message||"An error occurred"}function D(i){return!i.isUserCancelled()}function z(i){return null}function F(i){return i.isUserCancelled()?"info":i.isBalanceError()||i.isWalletError()?"warning":"error"}import{html as ae}from"lit";var _e=new Set(["metamask","walletconnect","coinbase","brave","rainbow","rabby","phantom","okx"]);function R(i){return i?_e.has(String(i).toLowerCase()):!1}function at(i){return i&&(i.id||i.provider||i.key)||""}function it(i){return i&&(i.label||i.name||i.title||i.id)||"Wallet"}function st(i){return i&&(i.icon||i.logo||i.image)||null}function G(i){return(i||[]).map(l=>({id:at(l),label:it(l),icon:st(l)}))}async function V(i,l){try{let e=l?.provider||(typeof window<"u"?window.ethereum:null);if(!e||i===void 0||i===null)return!0;let t=typeof i=="number"?i:String(i).startsWith("0x")?parseInt(String(i),16):parseInt(String(i),10);if(!Number.isFinite(t))return!0;let n=await e.request({method:"eth_chainId"});if(parseInt(n,16)===t)return!0;let r="0x"+t.toString(16);return await e.request({method:"wallet_switchEthereumChain",params:[{chainId:r}]}),!0}catch{try{let t=l?.provider||(typeof window<"u"?window.ethereum:null);if(!t||i===void 0||i===null)return!1;let n=typeof i=="number"?i:String(i).startsWith("0x")?parseInt(String(i),16):parseInt(String(i),10),a="0x"+n.toString(16),r=l?.chainName||`Network ${n}`,o=(l?.rpcUrlPublic?[l.rpcUrlPublic]:[]).filter(Boolean),c={name:l?.nativeSymbol||"ETH",symbol:l?.nativeSymbol||"ETH",decimals:typeof l?.decimals=="number"&&isFinite(l.decimals)?l.decimals:18};return await t.request({method:"wallet_addEthereumChain",params:[{chainId:a,chainName:r,rpcUrls:o,nativeCurrency:c}]}),!0}catch{return!1}}}async function Y(i){let{sdk:l,lastWalletId:e,connectedWallet:t,amountUsd:n,chainShortcodes:a,tokenShortcodes:r}=i,o,c=(e||"").toLowerCase(),d=(t?.owner||t?.principal||"").toString();try{c&&_e.has(c)?o=await l?.client?.getExternalWalletBalances?.({network:"evm",address:d,amountUsd:n,chainShortcodes:a,tokenShortcodes:r}):o=await l?.client?.getExternalWalletBalances?.({network:"ic",principal:d,amountUsd:n,chainShortcodes:a,tokenShortcodes:r})}catch{o={balances:[],totalBalancesUSD:0,lastUpdated:new Date}}return{balances:(o?.balances||[]).map(p=>({ledgerId:p.ledgerId,ledgerName:p.ledgerName,ledgerSymbol:p.ledgerSymbol,tokenShortcode:p.tokenShortcode??p.shortcode??null,canisterId:p.canisterId,eip3009Version:p?.eip3009Version??null,x402Accepts:p?.x402Accepts!=null?!!p.x402Accepts:void 0,balance:p.balance,formattedBalance:p.formattedBalance,decimals:p.decimals,currentPrice:p.currentPrice,lastPriceUpdate:p.lastPriceUpdate?new Date(p.lastPriceUpdate):void 0,lastUpdated:p.lastUpdated?new Date(p.lastUpdated):new Date,chainId:typeof p.chainId=="string"?p.chainId:typeof p.chainId=="number"?String(p.chainId):void 0,chainName:p.chainName||p.chain&&(p.chain.name||p.chain.chainName)||p.networkName||void 0,rpcUrlPublic:p.rpcUrlPublic,chainUuid:p.chainUuid,requiredAmount:p.requiredAmount,requiredAmountFormatted:p.requiredAmountFormatted,hasSufficientBalance:p.hasSufficientBalance,logoUrl:p.logoUrl??null})),totalBalancesUSD:o?.totalBalancesUSD,lastUpdated:o?.lastUpdated?new Date(o.lastUpdated):new Date}}function We(i){let l=Number(i);if(!isFinite(l)||l===0)return"0";if(Math.abs(l)<1e-5)return"< 0.00001";let t=1e5;return(Math.trunc(l*t)/t).toFixed(5).replace(/\.0+$/,"").replace(/(\.[0-9]*?)0+$/,"$1")}import{html as X}from"lit";function Ie(i){let l=parseFloat(String(i.formattedBalance||"0")),e=Number(i.currentPrice??0),t=(isFinite(l)?l:0)*(isFinite(e)?e:0);return isFinite(t)?t:0}var De=(i,l)=>Ie(l)-Ie(i);function Ce(){return X`<style>
896
896
  .modal { background-color:#1a1a1a; border-radius:24px; width:100%; max-width:420px; padding:24px; color:#fff; display:flex; flex-direction:column; border:1px solid #333; height:460px; }
897
897
  .header { display:flex; align-items:center; margin-bottom:20px; padding-bottom:20px; border-bottom:1px solid #333; flex-shrink:0; }
898
898
  .back-button { background:none; border:none; color:#fff; font-size:24px; cursor:pointer; padding:0; margin-right:16px; }
@@ -939,11 +939,11 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var H=Xe`
939
939
  </div>
940
940
  <div class="currency-balance">
941
941
  <div class="balance-amount">${l(t.formattedBalance)} ${n}</div>
942
- <div class="balance-available">$${Le(t).toFixed(2)}</div>
942
+ <div class="balance-available">$${Ie(t).toFixed(2)}</div>
943
943
  </div>
944
944
  </div>
945
945
  `})}
946
- `:X`<div class="muted" style="margin-bottom:8px">You have no balances on verified ledgers.</div>`})()}
946
+ `:X`<div class="muted" style="margin-bottom:8px">You have no balances on verified tokens.</div>`})()}
947
947
 
948
948
  ${(()=>{let e=(i.balances||[]).filter(t=>t.hasSufficientBalance===!1).sort(De);return e.length>0?X`
949
949
  ${e.map(t=>{let n=(t.ledgerSymbol||"").toUpperCase(),a=t.logoUrl?"":n==="ETH"?"eth-icon":n==="USDC"?"usdc-icon":n==="USDT"?"usdt-icon":"";return X`
@@ -968,7 +968,7 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var H=Xe`
968
968
  <span class="need-wallet">Need a wallet?</span>
969
969
  <button class="get-started" @click=${()=>{try{window.open("https://internetcomputer.org/wallets","_blank","noopener,noreferrer")}catch{}}}>Get started</button>
970
970
  </div>
971
- `}function rt(i){return!i||!i.startsWith("data:")?i:i.replace(/\s+/g,"")}function ot(i,l){let e=(i||"").toLowerCase();return e==="ii"?"Internet Identity":e==="nfid"?"NFID":e==="plug"?"Plug":e==="oisy"?"Oisy":l&&l.trim()?l:i?i.charAt(0).toUpperCase()+i.slice(1):"Wallet"}function Q(i){if(!i.visible)return null;let{wallets:l,onSelect:e,onClose:t,isConnecting:n}=i,a=d=>We(d),r=d=>{let h=parseFloat(String(d.formattedBalance||"0")),p=Number(d.currentPrice??0),O=(isFinite(h)?h:0)*(isFinite(p)?p:0);return isFinite(O)?O:0},o=(d,h)=>r(h)-r(d),c=l.map(d=>{let h=(d.id||"").toLowerCase();return{...d,icon:d.icon??null}});return ae`
971
+ `}function rt(i){return!i||!i.startsWith("data:")?i:i.replace(/\s+/g,"")}function ot(i,l){let e=(i||"").toLowerCase();return e==="ii"?"Internet Identity":e==="nfid"?"NFID":e==="plug"?"Plug":e==="oisy"?"Oisy":l&&l.trim()?l:i?i.charAt(0).toUpperCase()+i.slice(1):"Wallet"}function Q(i){if(!i.visible)return null;let{wallets:l,onSelect:e,onClose:t,isConnecting:n}=i,a=d=>We(d),r=d=>{let h=parseFloat(String(d.formattedBalance||"0")),p=Number(d.currentPrice??0),L=(isFinite(h)?h:0)*(isFinite(p)?p:0);return isFinite(L)?L:0},o=(d,h)=>r(h)-r(d),c=l.map(d=>{let h=(d.id||"").toLowerCase();return{...d,icon:d.icon??null}});return ae`
972
972
  <div style="position:fixed;inset:0;display:flex;align-items:center;justify-content:center;background:rgba(0,0,0,0.5);z-index:10000">
973
973
  <style>
974
974
  .icpay-w-8 { width: 2rem; }
@@ -1003,10 +1003,10 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var H=Xe`
1003
1003
  <h1 class="title">Connect</h1>
1004
1004
  </div>
1005
1005
  <div class="wallet-list">
1006
- ${(()=>{let d=[],h=!1,p=null;return c.forEach(O=>{let K=(O.id||"").toLowerCase(),ee=ot(O.id,O.label),C=R(K);p===null?p=C:!h&&p===!0&&C===!1&&(d.push(ae`<div class="divider"></div>`),h=!0);let B=K==="oisy"||K==="plug"||K==="nfid"||K==="ii"?"Internet Computer":C?"Ethereum-compatible":"";d.push(ae`
1007
- <div class="wallet-item" style="opacity:${n?.6:1}" @click=${()=>e(O.id)}>
1006
+ ${(()=>{let d=[],h=!1,p=null;return c.forEach(L=>{let K=(L.id||"").toLowerCase(),ee=ot(L.id,L.label),C=R(K);p===null?p=C:!h&&p===!0&&C===!1&&(d.push(ae`<div class="divider"></div>`),h=!0);let B=K==="oisy"||K==="plug"||K==="nfid"||K==="ii"?"Internet Computer":C?"Ethereum-compatible":"";d.push(ae`
1007
+ <div class="wallet-item" style="opacity:${n?.6:1}" @click=${()=>e(L.id)}>
1008
1008
  <div class="wallet-icon">
1009
- ${O.icon?ae`<img src="${rt(O.icon)}" alt="${ee} logo" class="icpay-w-8 icpay-h-8" style="object-fit:contain" />`:ae`<span>${ee.charAt(0)}</span>`}
1009
+ ${L.icon?ae`<img src="${rt(L.icon)}" alt="${ee} logo" class="icpay-w-8 icpay-h-8" style="object-fit:contain" />`:ae`<span>${ee.charAt(0)}</span>`}
1010
1010
  </div>
1011
1011
  <div class="wallet-info">
1012
1012
  <div class="wallet-name">${ee}</div>
@@ -1029,7 +1029,7 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var H=Xe`
1029
1029
  ${Te({isLoading:i.isLoading,error:i.error,balances:i.balances,onBack:i.onClose,onSelect:i.onSelect})}
1030
1030
  </div>
1031
1031
  </div>
1032
- `:null}function U(i){try{let l=i||{};l.adapters=l.adapters||{};let e=l.adapters.oisy||{},t=e.config||{},n={...t.transport||{},windowOpenerFeatures:"",detectNonClickEstablishment:!1};return l.adapters.oisy={...e,config:{...t,transport:n}},l}catch{return i}}function T(i,l){try{let e=l&&(l.owner||l.principal)||null,t=i&&i.account&&(i.account.owner||i.account.principal)||null,n=r=>typeof r=="string"?r:r&&typeof r.toString=="function"?r.toString():null,a=n(e)||n(t)||null;return a?{owner:a,principal:a}:l||{owner:null}}catch{return l||{owner:null}}}async function te(i){try{let l=typeof i?.getEnabledWallets=="function"?i.getEnabledWallets.bind(i):null;if(!l)return null;let t=(l()||[]).find(c=>(c?.id||"").toLowerCase()==="oisy");if(!t||!t.adapter)return null;let n=t.adapter,a=new n({config:i?.config||{}});if(!await a.isConnected())return null;let o=await a.getPrincipal();return o&&o!=="2vxsx-fae"?o:null}catch{return null}}var ze=typeof window<"u",re=null;function ve(i,l,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${l}`,e):console.log(`[ICPay Widget] ${l}`))}var E=class extends ct{constructor(){super(...arguments);this.selectedSymbol=null;this.unlocked=!1;this.succeeded=!1;this.processing=!1;this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.showOnrampModal=!1;this.onrampSessionId=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.transakMessageHandlerBound=null;this.onrampPollTimer=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.showBalanceModal=!1;this.balancesLoading=!1;this.balancesError=null;this.walletBalances=[];this.sdk=null;this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="pay",this.showWalletModal=!0,this.requestUpdate();try{let t=Number(this.config?.priceUsd||0),n=this.selectedSymbol||"ICP";window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"pay",type:"sendUsd",amount:t,currency:n}}))}catch{}}catch{}};this.onSelectBalanceSymbol=e=>{let t=(this.walletBalances||[]).find(a=>a?.tokenShortcode===e);if(t?.ledgerSymbol&&(this.selectedSymbol=t.ledgerSymbol),R(this.lastWalletId)){let a=(this.walletBalances||[]).find(o=>o?.tokenShortcode===e),r=a?.chainId;this.showBalanceModal=!1,this.showWalletModal=!1,V(r,{chainName:a?.chainName,rpcUrlPublic:a?.rpcUrlPublic,nativeSymbol:a?.ledgerSymbol,decimals:a?.decimals}).then(async()=>{try{let o=g(this.config),c=Number(this.config?.priceUsd??0);if(a?.x402Accepts)try{await o.client.createPaymentX402Usd({usdAmount:c,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,network:"evm",ledgerId:a?.ledgerId,chainId:a?.chainUuid||a?.chainId,context:"premium:x402"}});return}catch{}await o.client.createPaymentUsd({usdAmount:c,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,network:"evm",ledgerId:a?.ledgerId}})}catch{}});return}this.showBalanceModal=!1,this.showWalletModal=!1;let n=this.pendingAction;this.pendingAction=null,n==="pay"&&setTimeout(()=>this.onPay(),0)}}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("./wallet-select-M5KY6N6N.js")).WalletSelect);let n={...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:r}=await import("./origin-44ZEXSX4.js");n.derivationOrigin=this.config?.derivationOrigin||r()}}catch{}let a=new re(n);this.walletConnected=!1,this.config={...this.config,connectedWallet:{owner:t.principal,principal:t.principal,connected:!1}}}catch{}}connectedCallback(){if(super.connectedCallback(),!!ze){ve(this.config?.debug||!1,"Premium content connected",{config:this.config}),this.tryAutoConnectPNP();try{window.addEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}try{window.addEventListener("icpay-sdk-transaction-created",(()=>{this.showWalletModal=!1,this.showBalanceModal=!1,this.requestUpdate()}))}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.onPay()},0)}}async onPay(){if(ze&&!(this.processing||this.unlocked)){ve(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||"ICP"}}))}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){ve(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{re||(re=(await import("./wallet-select-M5KY6N6N.js")).WalletSelect);let t=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab)?U({...this.config?.plugNPlay||{}}):{...this.config?.plugNPlay||{}};this.config?.chainTypes&&(t.chainTypes=this.config.chainTypes);try{if(typeof window<"u"){let{resolveDerivationOrigin:a}=await import("./origin-44ZEXSX4.js");t.derivationOrigin=this.config?.derivationOrigin||a()}}catch{}this.pnp=new re(t);try{let a=await te(this.pnp);if(a){this.walletConnected=!0;let r=T(this.pnp,{owner:a,principal:a,connected:!0}),o=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(c,d)=>this.pnp.getActor({canisterId:c,idl:d,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{}},this.sdk=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"oisy"}}))}catch{}this.onPay();return}}catch{}let n=this.pnp.getEnabledWallets();if(ve(this.config?.debug||!1,"Available wallets",n),!n?.length)throw new Error("No wallets available");this.pendingAction="pay",this.showWalletModal=!0;return}catch(e){ve(this.config?.debug||!1,"Wallet connection error:",e),this.errorMessage=e instanceof Error?e.message:"Wallet connection failed",this.errorSeverity="error";return}}this.showWalletModal=!1,await this.fetchAndShowBalances("pay");return}catch(e){P(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),D(t)&&(this.errorMessage=_(t),this.errorSeverity=F(t),this.errorAction=z(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,n=t?.event_id||t?.eventId||t?.id;if(!(!n||typeof n!="string")&&n==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let a=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(a||void 0)}}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1,setTimeout(()=>this.createOnrampIntent(),0)}async createOnrampIntent(){try{let e=g(this.config),t=this.selectedSymbol||"ICP",n=await e.startOnrampUsd(this.config.priceUsd,t,{context:"premium:onramp"}),a=n?.metadata?.onramp?.sessionId||n?.metadata?.onramp?.session_id||null,r=n?.metadata?.paymentIntentId||n?.paymentIntentId||null,o=n?.metadata?.onramp?.errorMessage||null;this.onrampPaymentIntentId=r,a?(this.onrampSessionId=a,this.onrampErrorMessage=null,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.onrampErrorMessage=o||"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 n=g(this.config),a=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>a()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=n.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}select(e){this.selectedSymbol=e}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");this.lastWalletId=(e||"").toLowerCase(),this.pnp.connect(e).then(n=>{if(!!!(n&&(n.connected===!0||n.principal||n.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}let r=T(this.pnp,n),o=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(d,h)=>this.pnp.getActor({canisterId:d,idl:h,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{}},this.sdk=null,this.lastWalletId==="oisy"?this.oisyReadyToPay=!0:(this.showWalletModal=!1,this.fetchAndShowBalances("pay"))}).catch(n=>{this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}})}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}}}async fetchAndShowBalances(e){try{this.balancesLoading=!0,this.balancesError=null,this.showBalanceModal=!0;let t=g(this.config),{balances:n}=await Y({sdk:t,lastWalletId:this.lastWalletId,connectedWallet:this.config?.connectedWallet,amountUsd:Number(this.config?.priceUsd??0)});this.walletBalances=n,this.pendingAction=e}catch(t){this.walletBalances=[],this.balancesError=t&&(t.message||String(t))||"Failed to load balances"}finally{this.balancesLoading=!1}}render(){return this.config?se`
1032
+ `:null}function U(i){try{let l=i||{};l.adapters=l.adapters||{};let e=l.adapters.oisy||{},t=e.config||{},n={...t.transport||{},windowOpenerFeatures:"",detectNonClickEstablishment:!1};return l.adapters.oisy={...e,config:{...t,transport:n}},l}catch{return i}}function T(i,l){try{let e=l&&(l.owner||l.principal)||null,t=i&&i.account&&(i.account.owner||i.account.principal)||null,n=r=>typeof r=="string"?r:r&&typeof r.toString=="function"?r.toString():null,a=n(e)||n(t)||null;return a?{owner:a,principal:a}:l||{owner:null}}catch{return l||{owner:null}}}async function te(i){try{let l=typeof i?.getEnabledWallets=="function"?i.getEnabledWallets.bind(i):null;if(!l)return null;let t=(l()||[]).find(c=>(c?.id||"").toLowerCase()==="oisy");if(!t||!t.adapter)return null;let n=t.adapter,a=new n({config:i?.config||{}});if(!await a.isConnected())return null;let o=await a.getPrincipal();return o&&o!=="2vxsx-fae"?o:null}catch{return null}}var ze=typeof window<"u",re=null;function ve(i,l,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${l}`,e):console.log(`[ICPay Widget] ${l}`))}var E=class extends ct{constructor(){super(...arguments);this.selectedSymbol=null;this.unlocked=!1;this.succeeded=!1;this.processing=!1;this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.showOnrampModal=!1;this.onrampSessionId=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.transakMessageHandlerBound=null;this.onrampPollTimer=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.showBalanceModal=!1;this.balancesLoading=!1;this.balancesError=null;this.walletBalances=[];this.sdk=null;this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="pay",this.showWalletModal=!0,this.requestUpdate();try{let t=Number(this.config?.priceUsd||0),n=this.selectedSymbol||"ICP";window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"pay",type:"sendUsd",amount:t,currency:n}}))}catch{}}catch{}};this.onSelectBalanceSymbol=e=>{let t=(this.walletBalances||[]).find(a=>a?.tokenShortcode===e);if(t?.ledgerSymbol&&(this.selectedSymbol=t.ledgerSymbol),R(this.lastWalletId)){let a=(this.walletBalances||[]).find(o=>o?.tokenShortcode===e),r=a?.chainId;this.showBalanceModal=!1,this.showWalletModal=!1,V(r,{provider:this.pnp?.getEvmProvider?.()||this.config?.evmProvider,chainName:a?.chainName,rpcUrlPublic:a?.rpcUrlPublic,nativeSymbol:a?.ledgerSymbol,decimals:a?.decimals}).then(async()=>{try{let o=g(this.config),c=Number(this.config?.priceUsd??0);if(a?.x402Accepts)try{await o.client.createPaymentX402Usd({usdAmount:c,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,icpay_network:"evm",icpay_ledger_id:a?.ledgerId,icpay_context:"premium:x402"}});return}catch{}await o.client.createPaymentUsd({usdAmount:c,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,icpay_network:"evm",icpay_ledger_id:a?.ledgerId}})}catch{}});return}this.showBalanceModal=!1,this.showWalletModal=!1;let n=this.pendingAction;this.pendingAction=null,n==="pay"&&setTimeout(()=>this.onPay(),0)}}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("./wallet-select-YKQSWA6J.js")).WalletSelect);let n={...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:r}=await import("./origin-44ZEXSX4.js");n.derivationOrigin=this.config?.derivationOrigin||r()}}catch{}let a=new re(n);this.walletConnected=!1,this.config={...this.config,connectedWallet:{owner:t.principal,principal:t.principal,connected:!1}}}catch{}}connectedCallback(){if(super.connectedCallback(),!!ze){ve(this.config?.debug||!1,"Premium content connected",{config:this.config}),this.tryAutoConnectPNP();try{window.addEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}try{window.addEventListener("icpay-sdk-transaction-created",(()=>{this.showWalletModal=!1,this.showBalanceModal=!1,this.requestUpdate()}))}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.onPay()},0)}}async onPay(){if(ze&&!(this.processing||this.unlocked)){ve(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||"ICP"}}))}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){ve(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{re||(re=(await import("./wallet-select-YKQSWA6J.js")).WalletSelect);let t=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab)?U({...this.config?.plugNPlay||{}}):{...this.config?.plugNPlay||{}};this.config?.chainTypes&&(t.chainTypes=this.config.chainTypes);try{if(typeof window<"u"){let{resolveDerivationOrigin:a}=await import("./origin-44ZEXSX4.js");t.derivationOrigin=this.config?.derivationOrigin||a()}}catch{}this.pnp=new re(t);try{let a=await te(this.pnp);if(a){this.walletConnected=!0;let r=T(this.pnp,{owner:a,principal:a,connected:!0}),o=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(c,d)=>this.pnp.getActor({canisterId:c,idl:d,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{}},this.sdk=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"oisy"}}))}catch{}this.onPay();return}}catch{}let n=this.pnp.getEnabledWallets();if(ve(this.config?.debug||!1,"Available wallets",n),!n?.length)throw new Error("No wallets available");this.pendingAction="pay",this.showWalletModal=!0;return}catch(e){ve(this.config?.debug||!1,"Wallet connection error:",e),this.errorMessage=e instanceof Error?e.message:"Wallet connection failed",this.errorSeverity="error";return}}this.showWalletModal=!1,await this.fetchAndShowBalances("pay");return}catch(e){P(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),D(t)&&(this.errorMessage=_(t),this.errorSeverity=F(t),this.errorAction=z(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,n=t?.event_id||t?.eventId||t?.id;if(!(!n||typeof n!="string")&&n==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let a=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(a||void 0)}}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1,setTimeout(()=>this.createOnrampIntent(),0)}async createOnrampIntent(){try{let e=g(this.config),t=this.selectedSymbol||"ICP",n=await e.startOnrampUsd(this.config.priceUsd,t,{context:"premium:onramp"}),a=n?.metadata?.icpay_onramp?.sessionId||n?.metadata?.icpay_onramp?.session_id||n?.metadata?.onramp?.sessionId||n?.metadata?.onramp?.session_id||null,r=n?.metadata?.icpay_payment_intent_id||n?.metadata?.paymentIntentId||n?.paymentIntentId||null,o=n?.metadata?.icpay_onramp?.errorMessage||n?.metadata?.onramp?.errorMessage||null;this.onrampPaymentIntentId=r,a?(this.onrampSessionId=a,this.onrampErrorMessage=null,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.onrampErrorMessage=o||"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 n=g(this.config),a=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>a()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=n.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}select(e){this.selectedSymbol=e}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");this.lastWalletId=(e||"").toLowerCase(),this.pnp.connect(e).then(n=>{if(!!!(n&&(n.connected===!0||n.principal||n.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}let r=T(this.pnp,n),o=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(d,h)=>this.pnp.getActor({canisterId:d,idl:h,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{}},this.sdk=null,this.lastWalletId==="oisy"?this.oisyReadyToPay=!0:(this.showWalletModal=!1,this.fetchAndShowBalances("pay"))}).catch(n=>{this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}})}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}}}async fetchAndShowBalances(e){try{this.balancesLoading=!0,this.balancesError=null,this.showBalanceModal=!0;let t=g(this.config),{balances:n}=await Y({sdk:t,lastWalletId:this.lastWalletId,connectedWallet:this.config?.connectedWallet,amountUsd:Number(this.config?.priceUsd??0)});this.walletBalances=n,this.pendingAction=e}catch(t){this.walletBalances=[],this.balancesError=t&&(t.message||String(t))||"Failed to load balances"}finally{this.balancesLoading=!1}}render(){return this.config?se`
1033
1033
  <div class="icpay-card icpay-section icpay-widget-base">
1034
1034
  ${this.config?.progressBar?.enabled!==!1?se`
1035
1035
  <icpay-progress-bar
@@ -1122,7 +1122,7 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var H=Xe`
1122
1122
  border-color: rgba(239, 68, 68, 0.3);
1123
1123
  color: #ef4444;
1124
1124
  }
1125
- `],s([ht({type:Object})],E.prototype,"config",2),s([A()],E.prototype,"selectedSymbol",2),s([A()],E.prototype,"unlocked",2),s([A()],E.prototype,"succeeded",2),s([A()],E.prototype,"processing",2),s([A()],E.prototype,"errorMessage",2),s([A()],E.prototype,"errorSeverity",2),s([A()],E.prototype,"errorAction",2),s([A()],E.prototype,"walletConnected",2),s([A()],E.prototype,"pendingAction",2),s([A()],E.prototype,"showWalletModal",2),s([A()],E.prototype,"oisyReadyToPay",2),s([A()],E.prototype,"lastWalletId",2),s([A()],E.prototype,"showOnrampModal",2),s([A()],E.prototype,"onrampSessionId",2),s([A()],E.prototype,"onrampPaymentIntentId",2),s([A()],E.prototype,"onrampErrorMessage",2),s([A()],E.prototype,"showBalanceModal",2),s([A()],E.prototype,"balancesLoading",2),s([A()],E.prototype,"balancesError",2),s([A()],E.prototype,"walletBalances",2),E=s([pt("icpay-premium-content")],E);import{LitElement as gt,html as le,css as ut}from"lit";import{customElement as mt,property as yt,state as k}from"lit/decorators.js";var Fe=typeof window<"u",ce=null;function be(i,l,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${l}`,e):console.log(`[ICPay Widget] ${l}`))}var v=class extends gt{constructor(){super(...arguments);this.selectedAmount=1;this.selectedSymbol=null;this.total=0;this.processing=!1;this.succeeded=!1;this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.showOnrampModal=!1;this.onrampSessionId=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.transakMessageHandlerBound=null;this.onrampPollTimer=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.sdk=null;this.showBalanceModal=!1;this.balancesLoading=!1;this.balancesError=null;this.walletBalances=[];this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="tip",this.showWalletModal=!0,this.requestUpdate();try{let t=Number(this.selectedAmount||0),n=this.selectedSymbol||"ICP";window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"tip",type:"sendUsd",amount:t,currency:n}}))}catch{}}catch{}};this.onSelectBalanceSymbol=async e=>{let t=(this.walletBalances||[]).find(a=>a?.tokenShortcode===e);if(t?.ledgerSymbol&&(this.selectedSymbol=t.ledgerSymbol),R(this.lastWalletId)){let a=(this.walletBalances||[]).find(o=>o?.tokenShortcode===e),r=a?.chainId;V(r,{chainName:a?.chainName,rpcUrlPublic:a?.rpcUrlPublic,nativeSymbol:a?.ledgerSymbol,decimals:a?.decimals}).then(async()=>{try{let o=g(this.config),c=Number(this.selectedAmount||0);if(a?.x402Accepts)try{await o.client.createPaymentX402Usd({usdAmount:c,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,network:"evm",ledgerId:a?.ledgerId,chainId:a?.chainUuid,context:"tip:x402"}}),this.showBalanceModal=!1;return}catch{}await o.client.createPaymentUsd({usdAmount:c,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,network:"evm",ledgerId:a?.ledgerId}})}catch{}this.showBalanceModal=!1});return}this.showBalanceModal=!1;let n=this.pendingAction;if(this.pendingAction=null,n==="tip")try{let a=(this.walletBalances||[]).find(c=>c?.tokenShortcode===e),r=g(this.config),o=Number(this.selectedAmount||0);await r.client.createPaymentUsd({usdAmount:o,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,network:"ic",ledgerId:a?.ledgerId}})}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;ce||(ce=(await import("./wallet-select-M5KY6N6N.js")).WalletSelect);let n=U({...this.config?.plugNPlay||{}});try{if(typeof window<"u"){let{resolveDerivationOrigin:r}=await import("./origin-44ZEXSX4.js");n.derivationOrigin=this.config?.derivationOrigin||r()}}catch{}let a=new ce(n);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]}connectedCallback(){if(super.connectedCallback(),!!Fe){be(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{}try{window.addEventListener("icpay-sdk-transaction-created",(()=>{this.showWalletModal=!1,this.requestUpdate()}))}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==="tip"&&this.tip()},0)}}selectAmount(e){this.selectedAmount=e}selectSymbol(e){this.selectedSymbol=e}get fillPercentage(){return Math.min(this.total/50*100,100)}async tip(){if(Fe&&(be(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||"ICP"}}))}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){be(this.config?.debug||!1,"Connecting to wallet via wallet");try{ce||(ce=(await import("./wallet-select-M5KY6N6N.js")).WalletSelect);let t=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab)?U({...this.config?.plugNPlay||{}}):{...this.config?.plugNPlay||{}};this.config?.chainTypes&&(t.chainTypes=this.config.chainTypes);try{if(typeof window<"u"){let{resolveDerivationOrigin:a}=await import("./origin-44ZEXSX4.js");t.derivationOrigin=this.config?.derivationOrigin||a()}}catch{}this.pnp=new ce(t);try{let a=await te(this.pnp);if(a){this.walletConnected=!0;let r=T(this.pnp,{owner:a,principal:a,connected:!0}),o=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(c,d)=>this.pnp.getActor({canisterId:c,idl:d,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{}},this.sdk=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"oisy"}}))}catch{}this.tip();return}}catch{}let n=this.pnp.getEnabledWallets();if(be(this.config?.debug||!1,"Available wallets",n),!n?.length)throw new Error("No wallets available");this.pendingAction="tip",this.showWalletModal=!0;return}catch(e){be(this.config?.debug||!1,"Wallet connection error:",e),this.errorMessage=e instanceof Error?e.message:"Wallet connection failed",this.errorSeverity="error";return}}this.showWalletModal=!0,await this.fetchAndShowBalances();return}catch(e){P(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),D(t)&&(this.errorMessage=_(t),this.errorSeverity=F(t),this.errorAction=z(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,n=t?.event_id||t?.eventId||t?.id;if(!(!n||typeof n!="string")&&n==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let a=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(a||void 0)}}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1,setTimeout(()=>this.createOnrampIntent(),0)}async createOnrampIntent(){try{let e=g(this.config),t=this.selectedSymbol||"ICP",n=await e.startOnrampUsd(this.selectedAmount,t,{context:"tip:onramp"}),a=n?.metadata?.onramp?.sessionId||n?.metadata?.onramp?.session_id||null,r=n?.metadata?.paymentIntentId||n?.paymentIntentId||null,o=n?.metadata?.onramp?.errorMessage||null;this.onrampPaymentIntentId=r,a?(this.onrampSessionId=a,this.onrampErrorMessage=null,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.onrampErrorMessage=o||"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 n=g(this.config),a=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>a()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=n.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");this.lastWalletId=(e||"").toLowerCase(),this.pnp.connect(e).then(n=>{if(!!!(n&&(n.connected===!0||n.principal||n.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}let r=T(this.pnp,n),o=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(d,h)=>this.pnp.getActor({canisterId:d,idl:h,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{}},this.sdk=null,this.lastWalletId==="oisy"?this.oisyReadyToPay=!0:(this.showWalletModal=!1,this.fetchAndShowBalances())}).catch(n=>{this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}})}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}}}async fetchAndShowBalances(){try{this.balancesLoading=!0,this.balancesError=null,this.showBalanceModal=!0;let e=g(this.config),{balances:t}=await Y({sdk:e,lastWalletId:this.lastWalletId,connectedWallet:this.config?.connectedWallet,amountUsd:Number(this.selectedAmount||0),chainShortcodes:this.config?.chainShortcodes,tokenShortcodes:this.config?.tokenShortcodes});this.walletBalances=t}catch(e){this.walletBalances=[],this.balancesError=e&&(e.message||String(e))||"Failed to load balances"}finally{this.balancesLoading=!1}}render(){return this.config?le`
1125
+ `],s([ht({type:Object})],E.prototype,"config",2),s([A()],E.prototype,"selectedSymbol",2),s([A()],E.prototype,"unlocked",2),s([A()],E.prototype,"succeeded",2),s([A()],E.prototype,"processing",2),s([A()],E.prototype,"errorMessage",2),s([A()],E.prototype,"errorSeverity",2),s([A()],E.prototype,"errorAction",2),s([A()],E.prototype,"walletConnected",2),s([A()],E.prototype,"pendingAction",2),s([A()],E.prototype,"showWalletModal",2),s([A()],E.prototype,"oisyReadyToPay",2),s([A()],E.prototype,"lastWalletId",2),s([A()],E.prototype,"showOnrampModal",2),s([A()],E.prototype,"onrampSessionId",2),s([A()],E.prototype,"onrampPaymentIntentId",2),s([A()],E.prototype,"onrampErrorMessage",2),s([A()],E.prototype,"showBalanceModal",2),s([A()],E.prototype,"balancesLoading",2),s([A()],E.prototype,"balancesError",2),s([A()],E.prototype,"walletBalances",2),E=s([pt("icpay-premium-content")],E);import{LitElement as gt,html as le,css as ut}from"lit";import{customElement as mt,property as yt,state as k}from"lit/decorators.js";var Fe=typeof window<"u",ce=null;function be(i,l,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${l}`,e):console.log(`[ICPay Widget] ${l}`))}var v=class extends gt{constructor(){super(...arguments);this.selectedAmount=1;this.selectedSymbol=null;this.total=0;this.processing=!1;this.succeeded=!1;this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.showOnrampModal=!1;this.onrampSessionId=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.transakMessageHandlerBound=null;this.onrampPollTimer=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.sdk=null;this.showBalanceModal=!1;this.balancesLoading=!1;this.balancesError=null;this.walletBalances=[];this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="tip",this.showWalletModal=!0,this.requestUpdate();try{let t=Number(this.selectedAmount||0),n=this.selectedSymbol||"ICP";window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"tip",type:"sendUsd",amount:t,currency:n}}))}catch{}}catch{}};this.onSelectBalanceSymbol=async e=>{let t=(this.walletBalances||[]).find(a=>a?.tokenShortcode===e);if(t?.ledgerSymbol&&(this.selectedSymbol=t.ledgerSymbol),R(this.lastWalletId)){let a=(this.walletBalances||[]).find(o=>o?.tokenShortcode===e),r=a?.chainId;V(r,{provider:this.pnp?.getEvmProvider?.()||this.config?.evmProvider,chainName:a?.chainName,rpcUrlPublic:a?.rpcUrlPublic,nativeSymbol:a?.ledgerSymbol,decimals:a?.decimals}).then(async()=>{try{let o=g(this.config),c=Number(this.selectedAmount||0);if(a?.x402Accepts)try{await o.client.createPaymentX402Usd({usdAmount:c,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,icpay_network:"evm",icpay_ledger_id:a?.ledgerId,icpay_context:"tip:x402"}}),this.showBalanceModal=!1;return}catch{}await o.client.createPaymentUsd({usdAmount:c,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,icpay_network:"evm",icpay_ledger_id:a?.ledgerId}})}catch{}this.showBalanceModal=!1});return}this.showBalanceModal=!1;let n=this.pendingAction;if(this.pendingAction=null,n==="tip")try{let a=(this.walletBalances||[]).find(c=>c?.tokenShortcode===e),r=g(this.config),o=Number(this.selectedAmount||0);await r.client.createPaymentUsd({usdAmount:o,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,icpay_network:"ic",icpay_ledger_id:a?.ledgerId}})}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;ce||(ce=(await import("./wallet-select-YKQSWA6J.js")).WalletSelect);let n=U({...this.config?.plugNPlay||{}});try{if(typeof window<"u"){let{resolveDerivationOrigin:r}=await import("./origin-44ZEXSX4.js");n.derivationOrigin=this.config?.derivationOrigin||r()}}catch{}let a=new ce(n);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]}connectedCallback(){if(super.connectedCallback(),!!Fe){be(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{}try{window.addEventListener("icpay-sdk-transaction-created",(()=>{this.showWalletModal=!1,this.requestUpdate()}))}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==="tip"&&this.tip()},0)}}selectAmount(e){this.selectedAmount=e}selectSymbol(e){this.selectedSymbol=e}get fillPercentage(){return Math.min(this.total/50*100,100)}async tip(){if(Fe&&(be(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||"ICP"}}))}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){be(this.config?.debug||!1,"Connecting to wallet via wallet");try{ce||(ce=(await import("./wallet-select-YKQSWA6J.js")).WalletSelect);let t=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab)?U({...this.config?.plugNPlay||{}}):{...this.config?.plugNPlay||{}};this.config?.chainTypes&&(t.chainTypes=this.config.chainTypes);try{if(typeof window<"u"){let{resolveDerivationOrigin:a}=await import("./origin-44ZEXSX4.js");t.derivationOrigin=this.config?.derivationOrigin||a()}}catch{}this.pnp=new ce(t);try{let a=await te(this.pnp);if(a){this.walletConnected=!0;let r=T(this.pnp,{owner:a,principal:a,connected:!0}),o=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(c,d)=>this.pnp.getActor({canisterId:c,idl:d,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{}},this.sdk=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"oisy"}}))}catch{}this.tip();return}}catch{}let n=this.pnp.getEnabledWallets();if(be(this.config?.debug||!1,"Available wallets",n),!n?.length)throw new Error("No wallets available");this.pendingAction="tip",this.showWalletModal=!0;return}catch(e){be(this.config?.debug||!1,"Wallet connection error:",e),this.errorMessage=e instanceof Error?e.message:"Wallet connection failed",this.errorSeverity="error";return}}this.showWalletModal=!0,await this.fetchAndShowBalances();return}catch(e){P(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),D(t)&&(this.errorMessage=_(t),this.errorSeverity=F(t),this.errorAction=z(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,n=t?.event_id||t?.eventId||t?.id;if(!(!n||typeof n!="string")&&n==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let a=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(a||void 0)}}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1,setTimeout(()=>this.createOnrampIntent(),0)}async createOnrampIntent(){try{let e=g(this.config),t=this.selectedSymbol||"ICP",n=await e.startOnrampUsd(this.selectedAmount,t,{context:"tip:onramp"}),a=n?.metadata?.icpay_onramp?.sessionId||n?.metadata?.icpay_onramp?.session_id||n?.metadata?.onramp?.sessionId||n?.metadata?.onramp?.session_id||null,r=n?.metadata?.icpay_payment_intent_id||n?.metadata?.paymentIntentId||n?.paymentIntentId||null,o=n?.metadata?.icpay_onramp?.errorMessage||n?.metadata?.onramp?.errorMessage||null;this.onrampPaymentIntentId=r,a?(this.onrampSessionId=a,this.onrampErrorMessage=null,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.onrampErrorMessage=o||"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 n=g(this.config),a=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>a()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=n.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");this.lastWalletId=(e||"").toLowerCase(),this.pnp.connect(e).then(n=>{if(!!!(n&&(n.connected===!0||n.principal||n.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}let r=T(this.pnp,n),o=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(d,h)=>this.pnp.getActor({canisterId:d,idl:h,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{}},this.sdk=null,this.lastWalletId==="oisy"?this.oisyReadyToPay=!0:(this.showWalletModal=!1,this.fetchAndShowBalances())}).catch(n=>{this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}})}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}}}async fetchAndShowBalances(){try{this.balancesLoading=!0,this.balancesError=null,this.showBalanceModal=!0;let e=g(this.config),{balances:t}=await Y({sdk:e,lastWalletId:this.lastWalletId,connectedWallet:this.config?.connectedWallet,amountUsd:Number(this.selectedAmount||0),chainShortcodes:this.config?.chainShortcodes,tokenShortcodes:this.config?.tokenShortcodes});this.walletBalances=t}catch(e){this.walletBalances=[],this.balancesError=e&&(e.message||String(e))||"Failed to load balances"}finally{this.balancesLoading=!1}}render(){return this.config?le`
1126
1126
  <div class="icpay-card icpay-section icpay-widget-base" style="text-align:center;">
1127
1127
  ${this.config?.progressBar?.enabled!==!1?le`
1128
1128
  <icpay-progress-bar
@@ -1195,7 +1195,7 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var H=Xe`
1195
1195
  border-color: rgba(239, 68, 68, 0.3);
1196
1196
  color: #ef4444;
1197
1197
  }
1198
- `],s([yt({type:Object})],v.prototype,"config",2),s([k()],v.prototype,"selectedAmount",2),s([k()],v.prototype,"selectedSymbol",2),s([k()],v.prototype,"total",2),s([k()],v.prototype,"processing",2),s([k()],v.prototype,"succeeded",2),s([k()],v.prototype,"errorMessage",2),s([k()],v.prototype,"errorSeverity",2),s([k()],v.prototype,"errorAction",2),s([k()],v.prototype,"walletConnected",2),s([k()],v.prototype,"pendingAction",2),s([k()],v.prototype,"showWalletModal",2),s([k()],v.prototype,"oisyReadyToPay",2),s([k()],v.prototype,"lastWalletId",2),s([k()],v.prototype,"showOnrampModal",2),s([k()],v.prototype,"onrampSessionId",2),s([k()],v.prototype,"onrampPaymentIntentId",2),s([k()],v.prototype,"onrampErrorMessage",2),s([k()],v.prototype,"showBalanceModal",2),s([k()],v.prototype,"balancesLoading",2),s([k()],v.prototype,"balancesError",2),s([k()],v.prototype,"walletBalances",2),v=s([mt("icpay-tip-jar")],v);import{LitElement as ft,html as we,css as vt}from"lit";import{customElement as bt,property as Ae,state as I}from"lit/decorators.js";var Ke=typeof window<"u",de=null;function Ee(i,l,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${l}`,e):console.log(`[ICPay Widget] ${l}`))}var u=class extends ft{constructor(){super(...arguments);this.title="Article Title";this.preview="";this.lockedContent="";this.selectedSymbol=null;this.unlocked=!1;this.succeeded=!1;this.processing=!1;this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.showOnrampModal=!1;this.onrampSessionId=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.transakMessageHandlerBound=null;this.onrampPollTimer=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.showBalanceModal=!1;this.balancesLoading=!1;this.balancesError=null;this.walletBalances=[];this.sdk=null;this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="unlock",this.showWalletModal=!0,this.requestUpdate();try{let t=Number(this.config?.priceUsd||0),n=this.selectedSymbol||"ICP";window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"unlock",type:"sendUsd",amount:t,currency:n}}))}catch{}}catch{}};this.onSelectBalanceSymbol=async e=>{let t=(this.walletBalances||[]).find(a=>a?.tokenShortcode===e);if(t?.ledgerSymbol&&(this.selectedSymbol=t.ledgerSymbol),R(this.lastWalletId)){let a=(this.walletBalances||[]).find(o=>o?.tokenShortcode===e),r=a?.chainId;this.showBalanceModal=!1,this.showWalletModal=!1,V(r,{chainName:a?.chainName,rpcUrlPublic:a?.rpcUrlPublic,nativeSymbol:a?.ledgerSymbol,decimals:a?.decimals}).then(async()=>{try{let o=g(this.config),c=Number(this.config?.priceUsd??0);if(a?.x402Accepts)try{await o.client.createPaymentX402Usd({usdAmount:c,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,network:"evm",ledgerId:a?.ledgerId,chainId:a?.chainUuid,context:"article:x402"}});return}catch{}await o.client.createPaymentUsd({usdAmount:c,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,network:"evm",ledgerId:a?.ledgerId}})}catch{}});return}this.showBalanceModal=!1,this.showWalletModal=!1;let n=this.pendingAction;if(this.pendingAction=null,n==="unlock")try{let a=(this.walletBalances||[]).find(c=>c?.tokenShortcode===e),r=g(this.config),o=Number(this.config?.priceUsd??0);await r.client.createPaymentUsd({usdAmount:o,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,network:"ic",ledgerId:a?.ledgerId}})}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;de||(de=(await import("./wallet-select-M5KY6N6N.js")).WalletSelect);let n={...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:r}=await import("./origin-44ZEXSX4.js");n.derivationOrigin=this.config?.derivationOrigin||r()}}catch{}let a=new de(n);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,n=t?.event_id||t?.eventId||t?.id;if(!(!n||typeof n!="string")&&n==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let a=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(a||void 0)}}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1,setTimeout(()=>this.createOnrampIntent(),0)}async createOnrampIntent(){try{let e=g(this.config),t=this.selectedSymbol||"ICP",n=await e.startOnrampUsd(this.config.priceUsd,t,{context:"article:onramp"}),a=n?.metadata?.onramp?.sessionId||n?.metadata?.onramp?.session_id||null,r=n?.metadata?.paymentIntentId||n?.paymentIntentId||null,o=n?.metadata?.onramp?.errorMessage||null;this.onrampPaymentIntentId=r,a?(this.onrampSessionId=a,this.onrampErrorMessage=null,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.onrampErrorMessage=o||"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 n=g(this.config),a=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>a()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=n.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}connectedCallback(){if(super.connectedCallback(),!!Ke){Ee(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{}}}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)}}selectSymbol(e){this.selectedSymbol=e}async unlock(){if(Ke&&!(this.processing||this.unlocked)){Ee(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||"ICP"}}))}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){Ee(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{de||(de=(await import("./wallet-select-M5KY6N6N.js")).WalletSelect);let t=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab)?U({...this.config?.plugNPlay||{}}):{...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:a}=await import("./origin-44ZEXSX4.js");t.derivationOrigin=this.config?.derivationOrigin||a()}}catch{}this.pnp=new de(t);try{let a=await te(this.pnp);if(a){this.walletConnected=!0;let r=T(this.pnp,{owner:a,principal:a,connected:!0}),o=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(c,d)=>this.pnp.getActor({canisterId:c,idl:d,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{}},this.sdk=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"oisy"}}))}catch{}this.unlock();return}}catch{}let n=this.pnp.getEnabledWallets();if(Ee(this.config?.debug||!1,"Available wallets",n),!n?.length)throw new Error("No wallets available");this.pendingAction="unlock",this.showWalletModal=!0;return}catch(e){Ee(this.config?.debug||!1,"Wallet connection error:",e),this.errorMessage=e instanceof Error?e.message:"Wallet connection failed",this.errorSeverity="error";return}}this.showWalletModal=!1,await this.fetchAndShowBalances();return}catch(e){P(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),D(t)&&(this.errorMessage=_(t),this.errorSeverity=F(t),this.errorAction=z(t))}});try{!this.config.useOwnWallet&&this.pnp&&(await this.pnp.disconnect?.(),this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0})}catch{}}finally{this.processing=!1}}}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");this.lastWalletId=(e||"").toLowerCase(),this.pnp.connect(e).then(n=>{if(!!!(n&&(n.connected===!0||n.principal||n.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}let r=T(this.pnp,n),o=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(d,h)=>this.pnp.getActor({canisterId:d,idl:h,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{}},this.sdk=null,this.lastWalletId==="oisy"?this.oisyReadyToPay=!0:(this.showWalletModal=!1,this.fetchAndShowBalances())}).catch(n=>{this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}})}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}}}async fetchAndShowBalances(){try{this.balancesLoading=!0,this.balancesError=null,this.showBalanceModal=!0;let e=g(this.config),{balances:t}=await Y({sdk:e,lastWalletId:this.lastWalletId,connectedWallet:this.config?.connectedWallet,amountUsd:Number(this.config?.priceUsd??0),chainShortcodes:this.config?.chainShortcodes,tokenShortcodes:this.config?.tokenShortcodes});this.walletBalances=t}catch(e){this.walletBalances=[],this.balancesError=e&&(e.message||String(e))||"Failed to load balances"}finally{this.balancesLoading=!1}}render(){return this.config?we`
1198
+ `],s([yt({type:Object})],v.prototype,"config",2),s([k()],v.prototype,"selectedAmount",2),s([k()],v.prototype,"selectedSymbol",2),s([k()],v.prototype,"total",2),s([k()],v.prototype,"processing",2),s([k()],v.prototype,"succeeded",2),s([k()],v.prototype,"errorMessage",2),s([k()],v.prototype,"errorSeverity",2),s([k()],v.prototype,"errorAction",2),s([k()],v.prototype,"walletConnected",2),s([k()],v.prototype,"pendingAction",2),s([k()],v.prototype,"showWalletModal",2),s([k()],v.prototype,"oisyReadyToPay",2),s([k()],v.prototype,"lastWalletId",2),s([k()],v.prototype,"showOnrampModal",2),s([k()],v.prototype,"onrampSessionId",2),s([k()],v.prototype,"onrampPaymentIntentId",2),s([k()],v.prototype,"onrampErrorMessage",2),s([k()],v.prototype,"showBalanceModal",2),s([k()],v.prototype,"balancesLoading",2),s([k()],v.prototype,"balancesError",2),s([k()],v.prototype,"walletBalances",2),v=s([mt("icpay-tip-jar")],v);import{LitElement as ft,html as we,css as vt}from"lit";import{customElement as bt,property as Ae,state as O}from"lit/decorators.js";var Ke=typeof window<"u",de=null;function Ee(i,l,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${l}`,e):console.log(`[ICPay Widget] ${l}`))}var u=class extends ft{constructor(){super(...arguments);this.title="Article Title";this.preview="";this.lockedContent="";this.selectedSymbol=null;this.unlocked=!1;this.succeeded=!1;this.processing=!1;this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.showOnrampModal=!1;this.onrampSessionId=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.transakMessageHandlerBound=null;this.onrampPollTimer=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.showBalanceModal=!1;this.balancesLoading=!1;this.balancesError=null;this.walletBalances=[];this.sdk=null;this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="unlock",this.showWalletModal=!0,this.requestUpdate();try{let t=Number(this.config?.priceUsd||0),n=this.selectedSymbol||"ICP";window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"unlock",type:"sendUsd",amount:t,currency:n}}))}catch{}}catch{}};this.onSelectBalanceSymbol=async e=>{let t=(this.walletBalances||[]).find(a=>a?.tokenShortcode===e);if(t?.ledgerSymbol&&(this.selectedSymbol=t.ledgerSymbol),R(this.lastWalletId)){let a=(this.walletBalances||[]).find(o=>o?.tokenShortcode===e),r=a?.chainId;this.showBalanceModal=!1,this.showWalletModal=!1,V(r,{provider:this.pnp?.getEvmProvider?.()||this.config?.evmProvider,chainName:a?.chainName,rpcUrlPublic:a?.rpcUrlPublic,nativeSymbol:a?.ledgerSymbol,decimals:a?.decimals}).then(async()=>{try{let o=g(this.config),c=Number(this.config?.priceUsd??0);if(a?.x402Accepts)try{await o.client.createPaymentX402Usd({usdAmount:c,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,icpay_network:"evm",icpay_ledger_id:a?.ledgerId,icpay_context:"article:x402"}});return}catch{}await o.client.createPaymentUsd({usdAmount:c,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,icpay_network:"evm",icpay_ledger_id:a?.ledgerId}})}catch{}});return}this.showBalanceModal=!1,this.showWalletModal=!1;let n=this.pendingAction;if(this.pendingAction=null,n==="unlock")try{let a=(this.walletBalances||[]).find(c=>c?.tokenShortcode===e),r=g(this.config),o=Number(this.config?.priceUsd??0);await r.client.createPaymentUsd({usdAmount:o,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,icpay_network:"ic",icpay_ledger_id:a?.ledgerId}})}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;de||(de=(await import("./wallet-select-YKQSWA6J.js")).WalletSelect);let n={...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:r}=await import("./origin-44ZEXSX4.js");n.derivationOrigin=this.config?.derivationOrigin||r()}}catch{}let a=new de(n);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,n=t?.event_id||t?.eventId||t?.id;if(!(!n||typeof n!="string")&&n==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let a=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(a||void 0)}}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1,setTimeout(()=>this.createOnrampIntent(),0)}async createOnrampIntent(){try{let e=g(this.config),t=this.selectedSymbol||"ICP",n=await e.startOnrampUsd(this.config.priceUsd,t,{context:"article:onramp"}),a=n?.metadata?.icpay_onramp?.sessionId||n?.metadata?.icpay_onramp?.session_id||n?.metadata?.onramp?.sessionId||n?.metadata?.onramp?.session_id||null,r=n?.metadata?.icpay_payment_intent_id||n?.metadata?.paymentIntentId||n?.paymentIntentId||null,o=n?.metadata?.icpay_onramp?.errorMessage||n?.metadata?.onramp?.errorMessage||null;this.onrampPaymentIntentId=r,a?(this.onrampSessionId=a,this.onrampErrorMessage=null,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.onrampErrorMessage=o||"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 n=g(this.config),a=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>a()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=n.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}connectedCallback(){if(super.connectedCallback(),!!Ke){Ee(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{}}}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)}}selectSymbol(e){this.selectedSymbol=e}async unlock(){if(Ke&&!(this.processing||this.unlocked)){Ee(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||"ICP"}}))}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){Ee(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{de||(de=(await import("./wallet-select-YKQSWA6J.js")).WalletSelect);let t=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab)?U({...this.config?.plugNPlay||{}}):{...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:a}=await import("./origin-44ZEXSX4.js");t.derivationOrigin=this.config?.derivationOrigin||a()}}catch{}this.pnp=new de(t);try{let a=await te(this.pnp);if(a){this.walletConnected=!0;let r=T(this.pnp,{owner:a,principal:a,connected:!0}),o=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(c,d)=>this.pnp.getActor({canisterId:c,idl:d,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{}},this.sdk=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"oisy"}}))}catch{}this.unlock();return}}catch{}let n=this.pnp.getEnabledWallets();if(Ee(this.config?.debug||!1,"Available wallets",n),!n?.length)throw new Error("No wallets available");this.pendingAction="unlock",this.showWalletModal=!0;return}catch(e){Ee(this.config?.debug||!1,"Wallet connection error:",e),this.errorMessage=e instanceof Error?e.message:"Wallet connection failed",this.errorSeverity="error";return}}this.showWalletModal=!1,await this.fetchAndShowBalances();return}catch(e){P(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),D(t)&&(this.errorMessage=_(t),this.errorSeverity=F(t),this.errorAction=z(t))}});try{!this.config.useOwnWallet&&this.pnp&&(await this.pnp.disconnect?.(),this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0})}catch{}}finally{this.processing=!1}}}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");this.lastWalletId=(e||"").toLowerCase(),this.pnp.connect(e).then(n=>{if(!!!(n&&(n.connected===!0||n.principal||n.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}let r=T(this.pnp,n),o=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(d,h)=>this.pnp.getActor({canisterId:d,idl:h,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{}},this.sdk=null,this.lastWalletId==="oisy"?this.oisyReadyToPay=!0:(this.showWalletModal=!1,this.fetchAndShowBalances())}).catch(n=>{this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}})}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}}}async fetchAndShowBalances(){try{this.balancesLoading=!0,this.balancesError=null,this.showBalanceModal=!0;let e=g(this.config),{balances:t}=await Y({sdk:e,lastWalletId:this.lastWalletId,connectedWallet:this.config?.connectedWallet,amountUsd:Number(this.config?.priceUsd??0),chainShortcodes:this.config?.chainShortcodes,tokenShortcodes:this.config?.tokenShortcodes});this.walletBalances=t}catch(e){this.walletBalances=[],this.balancesError=e&&(e.message||String(e))||"Failed to load balances"}finally{this.balancesLoading=!1}}render(){return this.config?we`
1199
1199
  <div class="icpay-card icpay-section icpay-widget-base">
1200
1200
  ${this.config?.progressBar?.enabled!==!1?we`
1201
1201
  <icpay-progress-bar
@@ -1263,7 +1263,7 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var H=Xe`
1263
1263
  border-color: rgba(239, 68, 68, 0.3);
1264
1264
  color: #ef4444;
1265
1265
  }
1266
- `],s([Ae({type:Object})],u.prototype,"config",2),s([Ae({type:String})],u.prototype,"title",2),s([Ae({type:String})],u.prototype,"preview",2),s([Ae({type:String})],u.prototype,"lockedContent",2),s([I()],u.prototype,"selectedSymbol",2),s([I()],u.prototype,"unlocked",2),s([I()],u.prototype,"succeeded",2),s([I()],u.prototype,"processing",2),s([I()],u.prototype,"errorMessage",2),s([I()],u.prototype,"errorSeverity",2),s([I()],u.prototype,"errorAction",2),s([I()],u.prototype,"walletConnected",2),s([I()],u.prototype,"pendingAction",2),s([I()],u.prototype,"showWalletModal",2),s([I()],u.prototype,"oisyReadyToPay",2),s([I()],u.prototype,"lastWalletId",2),s([I()],u.prototype,"showOnrampModal",2),s([I()],u.prototype,"onrampSessionId",2),s([I()],u.prototype,"onrampPaymentIntentId",2),s([I()],u.prototype,"onrampErrorMessage",2),s([I()],u.prototype,"showBalanceModal",2),s([I()],u.prototype,"balancesLoading",2),s([I()],u.prototype,"balancesError",2),s([I()],u.prototype,"walletBalances",2),u=s([bt("icpay-article-paywall")],u);import{LitElement as wt,html as pe,css as Et}from"lit";import{customElement as xt,property as St,state as L}from"lit/decorators.js";var He=typeof window<"u",Ne=null;function xe(i,l,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${l}`,e):console.log(`[ICPay Widget] ${l}`))}var x=class extends wt{constructor(){super(...arguments);this.selectedIndex=0;this.selectedSymbol=null;this.processing=!1;this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.showOnrampModal=!1;this.onrampSessionId=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.transakMessageHandlerBound=null;this.onrampPollTimer=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.sdk=null;this.showBalanceModal=!1;this.balancesLoading=!1;this.balancesError=null;this.walletBalances=[];this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="order",this.showWalletModal=!0,this.requestUpdate();try{let t=Number(this.selectedItem?.priceUsd||0),n=this.selectedSymbol||"ICP";window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"order",type:"sendUsd",amount:t,currency:n}}))}catch{}}catch{}};this.onSelectBalanceSymbol=async e=>{let t=(this.walletBalances||[]).find(a=>a?.tokenShortcode===e);if(t?.ledgerSymbol&&(this.selectedSymbol=t.ledgerSymbol),R(this.lastWalletId)){let a=(this.walletBalances||[]).find(o=>o?.tokenShortcode===e),r=a?.chainId;V(r,{chainName:a?.chainName,rpcUrlPublic:a?.rpcUrlPublic,nativeSymbol:a?.ledgerSymbol,decimals:a?.decimals}).then(async()=>{try{let o=g(this.config),c=Number(this.selectedItem?.priceUsd||0);if(a?.x402Accepts)try{await o.client.createPaymentX402Usd({usdAmount:c,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,network:"evm",ledgerId:a?.ledgerId,chainId:a?.chainUuid,context:"coffee:x402",item:this.selectedItem?.name}}),this.showBalanceModal=!1;return}catch{}await o.client.createPaymentUsd({usdAmount:c,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,network:"evm",ledgerId:a?.ledgerId,item:this.selectedItem?.name}})}catch{}this.showBalanceModal=!1});return}this.showBalanceModal=!1;let n=this.pendingAction;if(this.pendingAction=null,n==="order")try{let a=(this.walletBalances||[]).find(c=>c?.tokenShortcode===e),r=g(this.config),o=Number(this.selectedItem?.priceUsd||0);await r.client.createPaymentUsd({usdAmount:o,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,network:"ic",ledgerId:a?.ledgerId,item:this.selectedItem?.name}})}catch{}}}connectedCallback(){if(super.connectedCallback(),!!He){xe(this.config?.debug||!1,"Coffee shop connected",{config:this.config}),this.config&&typeof this.config.defaultItemIndex=="number"&&(this.selectedIndex=this.config.defaultItemIndex);try{window.addEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}try{window.addEventListener("icpay-sdk-transaction-created",(()=>{this.showWalletModal=!1,this.requestUpdate()}))}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)}}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(He&&!this.processing){xe(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||"ICP"}}))}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){xe(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{Ne||(Ne=(await import("./wallet-select-M5KY6N6N.js")).WalletSelect);let t=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab)?U({...this.config?.plugNPlay||{}}):{...this.config?.plugNPlay||{}};this.config?.chainTypes&&(t.chainTypes=this.config.chainTypes);try{if(typeof window<"u"){let{resolveDerivationOrigin:a}=await import("./origin-44ZEXSX4.js");t.derivationOrigin=this.config?.derivationOrigin||a()}}catch{}this.pnp=new Ne(t);try{let a=await te(this.pnp);if(a){this.walletConnected=!0;let r=T(this.pnp,{owner:a,principal:a,connected:!0}),o=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(c,d)=>this.pnp.getActor({canisterId:c,idl:d,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{}},this.sdk=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"oisy"}}))}catch{}this.order();return}}catch{}let n=this.pnp.getEnabledWallets();if(xe(this.config?.debug||!1,"Available wallets",n),!n?.length)throw new Error("No wallets available");this.pendingAction="order",this.showWalletModal=!0;return}catch(e){xe(this.config?.debug||!1,"Wallet connection error:",e),this.errorMessage=e instanceof Error?e.message:"Wallet connection failed",this.errorSeverity="error";return}}this.pendingAction="order",this.showWalletModal=!0,await this.fetchAndShowBalances();return}catch(e){P(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),D(t)&&(this.errorMessage=_(t),this.errorSeverity=F(t),this.errorAction=z(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,n=t?.event_id||t?.eventId||t?.id;if(!(!n||typeof n!="string")&&n==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let a=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(a||void 0)}}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1,setTimeout(()=>this.createOnrampIntent(),0)}async createOnrampIntent(){try{let e=g(this.config),t=this.selectedSymbol||"ICP",n=await e.startOnrampUsd(this.selectedItem.priceUsd,t,{context:"coffee:onramp",item:this.selectedItem.name}),a=n?.metadata?.onramp?.sessionId||n?.metadata?.onramp?.session_id||null,r=n?.metadata?.paymentIntentId||n?.paymentIntentId||null,o=n?.metadata?.onramp?.errorMessage||null;this.onrampPaymentIntentId=r,a?(this.onrampSessionId=a,this.onrampErrorMessage=null,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.onrampErrorMessage=o||"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 n=g(this.config),a=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>a()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=n.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");this.lastWalletId=(e||"").toLowerCase(),this.pnp.connect(e).then(n=>{if(!!!(n&&(n.connected===!0||n.principal||n.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}let r=T(this.pnp,n),o=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(d,h)=>this.pnp.getActor({canisterId:d,idl:h,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{}},this.sdk=null,this.lastWalletId==="oisy"?this.oisyReadyToPay=!0:(this.showWalletModal=!1,this.fetchAndShowBalances())}).catch(n=>{this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}})}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}}}async fetchAndShowBalances(){try{this.balancesLoading=!0,this.balancesError=null,this.showBalanceModal=!0;let e=g(this.config),{balances:t}=await Y({sdk:e,lastWalletId:this.lastWalletId,connectedWallet:this.config?.connectedWallet,amountUsd:Number(this.selectedItem?.priceUsd??0),chainShortcodes:this.config?.chainShortcodes,tokenShortcodes:this.config?.tokenShortcodes});this.walletBalances=t}catch(e){this.walletBalances=[],this.balancesError=e&&(e.message||String(e))||"Failed to load balances"}finally{this.balancesLoading=!1}}render(){return this.config?pe`
1266
+ `],s([Ae({type:Object})],u.prototype,"config",2),s([Ae({type:String})],u.prototype,"title",2),s([Ae({type:String})],u.prototype,"preview",2),s([Ae({type:String})],u.prototype,"lockedContent",2),s([O()],u.prototype,"selectedSymbol",2),s([O()],u.prototype,"unlocked",2),s([O()],u.prototype,"succeeded",2),s([O()],u.prototype,"processing",2),s([O()],u.prototype,"errorMessage",2),s([O()],u.prototype,"errorSeverity",2),s([O()],u.prototype,"errorAction",2),s([O()],u.prototype,"walletConnected",2),s([O()],u.prototype,"pendingAction",2),s([O()],u.prototype,"showWalletModal",2),s([O()],u.prototype,"oisyReadyToPay",2),s([O()],u.prototype,"lastWalletId",2),s([O()],u.prototype,"showOnrampModal",2),s([O()],u.prototype,"onrampSessionId",2),s([O()],u.prototype,"onrampPaymentIntentId",2),s([O()],u.prototype,"onrampErrorMessage",2),s([O()],u.prototype,"showBalanceModal",2),s([O()],u.prototype,"balancesLoading",2),s([O()],u.prototype,"balancesError",2),s([O()],u.prototype,"walletBalances",2),u=s([bt("icpay-article-paywall")],u);import{LitElement as wt,html as pe,css as Et}from"lit";import{customElement as xt,property as St,state as I}from"lit/decorators.js";var He=typeof window<"u",Ne=null;function xe(i,l,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${l}`,e):console.log(`[ICPay Widget] ${l}`))}var x=class extends wt{constructor(){super(...arguments);this.selectedIndex=0;this.selectedSymbol=null;this.processing=!1;this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.showOnrampModal=!1;this.onrampSessionId=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.transakMessageHandlerBound=null;this.onrampPollTimer=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.sdk=null;this.showBalanceModal=!1;this.balancesLoading=!1;this.balancesError=null;this.walletBalances=[];this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="order",this.showWalletModal=!0,this.requestUpdate();try{let t=Number(this.selectedItem?.priceUsd||0),n=this.selectedSymbol||"ICP";window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"order",type:"sendUsd",amount:t,currency:n}}))}catch{}}catch{}};this.onSelectBalanceSymbol=async e=>{let t=(this.walletBalances||[]).find(a=>a?.tokenShortcode===e);if(t?.ledgerSymbol&&(this.selectedSymbol=t.ledgerSymbol),R(this.lastWalletId)){let a=(this.walletBalances||[]).find(o=>o?.tokenShortcode===e),r=a?.chainId;V(r,{provider:this.pnp?.getEvmProvider?.()||this.config?.evmProvider,chainName:a?.chainName,rpcUrlPublic:a?.rpcUrlPublic,nativeSymbol:a?.ledgerSymbol,decimals:a?.decimals}).then(async()=>{try{let o=g(this.config),c=Number(this.selectedItem?.priceUsd||0);if(a?.x402Accepts)try{await o.client.createPaymentX402Usd({usdAmount:c,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,icpay_network:"evm",icpay_ledger_id:a?.ledgerId,icpay_context:"coffee:x402",item:this.selectedItem?.name}}),this.showBalanceModal=!1;return}catch{}await o.client.createPaymentUsd({usdAmount:c,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,icpay_network:"evm",icpay_ledger_id:a?.ledgerId,item:this.selectedItem?.name}})}catch{}this.showBalanceModal=!1});return}this.showBalanceModal=!1;let n=this.pendingAction;if(this.pendingAction=null,n==="order")try{let a=(this.walletBalances||[]).find(c=>c?.tokenShortcode===e),r=g(this.config),o=Number(this.selectedItem?.priceUsd||0);await r.client.createPaymentUsd({usdAmount:o,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,icpay_network:"ic",icpay_ledger_id:a?.ledgerId,item:this.selectedItem?.name}})}catch{}}}connectedCallback(){if(super.connectedCallback(),!!He){xe(this.config?.debug||!1,"Coffee shop connected",{config:this.config}),this.config&&typeof this.config.defaultItemIndex=="number"&&(this.selectedIndex=this.config.defaultItemIndex);try{window.addEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}try{window.addEventListener("icpay-sdk-transaction-created",(()=>{this.showWalletModal=!1,this.requestUpdate()}))}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)}}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(He&&!this.processing){xe(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||"ICP"}}))}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){xe(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{Ne||(Ne=(await import("./wallet-select-YKQSWA6J.js")).WalletSelect);let t=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab)?U({...this.config?.plugNPlay||{}}):{...this.config?.plugNPlay||{}};this.config?.chainTypes&&(t.chainTypes=this.config.chainTypes);try{if(typeof window<"u"){let{resolveDerivationOrigin:a}=await import("./origin-44ZEXSX4.js");t.derivationOrigin=this.config?.derivationOrigin||a()}}catch{}this.pnp=new Ne(t);try{let a=await te(this.pnp);if(a){this.walletConnected=!0;let r=T(this.pnp,{owner:a,principal:a,connected:!0}),o=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(c,d)=>this.pnp.getActor({canisterId:c,idl:d,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{}},this.sdk=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"oisy"}}))}catch{}this.order();return}}catch{}let n=this.pnp.getEnabledWallets();if(xe(this.config?.debug||!1,"Available wallets",n),!n?.length)throw new Error("No wallets available");this.pendingAction="order",this.showWalletModal=!0;return}catch(e){xe(this.config?.debug||!1,"Wallet connection error:",e),this.errorMessage=e instanceof Error?e.message:"Wallet connection failed",this.errorSeverity="error";return}}this.pendingAction="order",this.showWalletModal=!0,await this.fetchAndShowBalances();return}catch(e){P(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),D(t)&&(this.errorMessage=_(t),this.errorSeverity=F(t),this.errorAction=z(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,n=t?.event_id||t?.eventId||t?.id;if(!(!n||typeof n!="string")&&n==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let a=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(a||void 0)}}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1,setTimeout(()=>this.createOnrampIntent(),0)}async createOnrampIntent(){try{let e=g(this.config),t=this.selectedSymbol||"ICP",n=await e.startOnrampUsd(this.selectedItem.priceUsd,t,{context:"coffee:onramp",item:this.selectedItem.name}),a=n?.metadata?.icpay_onramp?.sessionId||n?.metadata?.icpay_onramp?.session_id||n?.metadata?.onramp?.sessionId||n?.metadata?.onramp?.session_id||null,r=n?.metadata?.icpay_payment_intent_id||n?.metadata?.paymentIntentId||n?.paymentIntentId||null,o=n?.metadata?.icpay_onramp?.errorMessage||n?.metadata?.onramp?.errorMessage||null;this.onrampPaymentIntentId=r,a?(this.onrampSessionId=a,this.onrampErrorMessage=null,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.onrampErrorMessage=o||"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 n=g(this.config),a=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>a()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=n.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");this.lastWalletId=(e||"").toLowerCase(),this.pnp.connect(e).then(n=>{if(!!!(n&&(n.connected===!0||n.principal||n.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}let r=T(this.pnp,n),o=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(d,h)=>this.pnp.getActor({canisterId:d,idl:h,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{}},this.sdk=null,this.lastWalletId==="oisy"?this.oisyReadyToPay=!0:(this.showWalletModal=!1,this.fetchAndShowBalances())}).catch(n=>{this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}})}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}}}async fetchAndShowBalances(){try{this.balancesLoading=!0,this.balancesError=null,this.showBalanceModal=!0;let e=g(this.config),{balances:t}=await Y({sdk:e,lastWalletId:this.lastWalletId,connectedWallet:this.config?.connectedWallet,amountUsd:Number(this.selectedItem?.priceUsd??0),chainShortcodes:this.config?.chainShortcodes,tokenShortcodes:this.config?.tokenShortcodes});this.walletBalances=t}catch(e){this.walletBalances=[],this.balancesError=e&&(e.message||String(e))||"Failed to load balances"}finally{this.balancesLoading=!1}}render(){return this.config?pe`
1267
1267
  <div class="icpay-card icpay-section icpay-widget-base">
1268
1268
  ${this.config?.progressBar?.enabled!==!1?pe`
1269
1269
  <icpay-progress-bar
@@ -1337,7 +1337,7 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var H=Xe`
1337
1337
  border-color: rgba(239, 68, 68, 0.3);
1338
1338
  color: #ef4444;
1339
1339
  }
1340
- `],s([St({type:Object})],x.prototype,"config",2),s([L()],x.prototype,"selectedIndex",2),s([L()],x.prototype,"selectedSymbol",2),s([L()],x.prototype,"processing",2),s([L()],x.prototype,"errorMessage",2),s([L()],x.prototype,"errorSeverity",2),s([L()],x.prototype,"errorAction",2),s([L()],x.prototype,"walletConnected",2),s([L()],x.prototype,"pendingAction",2),s([L()],x.prototype,"showWalletModal",2),s([L()],x.prototype,"oisyReadyToPay",2),s([L()],x.prototype,"lastWalletId",2),s([L()],x.prototype,"showOnrampModal",2),s([L()],x.prototype,"onrampSessionId",2),s([L()],x.prototype,"onrampPaymentIntentId",2),s([L()],x.prototype,"onrampErrorMessage",2),s([L()],x.prototype,"showBalanceModal",2),s([L()],x.prototype,"balancesLoading",2),s([L()],x.prototype,"balancesError",2),s([L()],x.prototype,"walletBalances",2),x=s([xt("icpay-coffee-shop")],x);import{LitElement as kt,html as he,css as Mt}from"lit";import{customElement as Wt,property as Ct,state as M}from"lit/decorators.js";var je=typeof window<"u",ge=null;function Se(i,l,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${l}`,e):console.log(`[ICPay Widget] ${l}`))}var b=class extends kt{constructor(){super(...arguments);this.selectedAmount=10;this.selectedSymbol=null;this.raised=0;this.processing=!1;this.succeeded=!1;this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.showOnrampModal=!1;this.onrampSessionId=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.transakMessageHandlerBound=null;this.onrampPollTimer=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.sdk=null;this.showBalanceModal=!1;this.balancesLoading=!1;this.balancesError=null;this.walletBalances=[];this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="donate",this.showWalletModal=!0,this.requestUpdate();try{let t=Number(this.selectedAmount||0),n=this.selectedSymbol||"ICP";window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"donate",type:"sendUsd",amount:t,currency:n}}))}catch{}}catch{}};this.onSelectBalanceSymbol=async e=>{let t=(this.walletBalances||[]).find(a=>a?.tokenShortcode===e);if(t?.ledgerSymbol&&(this.selectedSymbol=t.ledgerSymbol),R(this.lastWalletId)){let a=(this.walletBalances||[]).find(o=>o?.tokenShortcode===e),r=a?.chainId;V(r,{chainName:a?.chainName,rpcUrlPublic:a?.rpcUrlPublic,nativeSymbol:a?.ledgerSymbol,decimals:a?.decimals}).then(async()=>{try{let o=g(this.config),c=Number(this.selectedAmount||0);if(a?.x402Accepts)try{await o.client.createPaymentX402Usd({usdAmount:c,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,network:"evm",ledgerId:a?.ledgerId,chainId:a?.chainUuid,context:"donation:x402"}}),this.showBalanceModal=!1;return}catch{}await o.client.createPaymentUsd({usdAmount:c,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,network:"evm",ledgerId:a?.ledgerId}})}catch{}this.showBalanceModal=!1});return}this.showBalanceModal=!1;let n=this.pendingAction;if(this.pendingAction=null,n==="donate")try{let a=(this.walletBalances||[]).find(c=>c?.tokenShortcode===e),r=g(this.config),o=Number(this.selectedAmount||0);await r.client.createPaymentUsd({usdAmount:o,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,network:"ic",ledgerId:a?.ledgerId}})}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;ge||(ge=(await import("./wallet-select-M5KY6N6N.js")).WalletSelect);let n=U({...this.config?.plugNPlay||{}});try{if(typeof window<"u"){let{resolveDerivationOrigin:r}=await import("./origin-44ZEXSX4.js");n.derivationOrigin=this.config?.derivationOrigin||r()}}catch{}let a=new ge(n);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]}connectedCallback(){if(super.connectedCallback(),!!je){Se(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{}try{window.addEventListener("icpay-sdk-transaction-created",(()=>{this.showWalletModal=!1,this.requestUpdate()}))}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==="donate"&&this.donate()},0)}}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(je&&!this.processing){Se(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||"ICP"}}))}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){Se(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{ge||(ge=(await import("./wallet-select-M5KY6N6N.js")).WalletSelect);let t=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab)?U({...this.config?.plugNPlay||{}}):{...this.config?.plugNPlay||{}};this.config?.chainTypes&&(t.chainTypes=this.config.chainTypes);try{if(typeof window<"u"){let{resolveDerivationOrigin:a}=await import("./origin-44ZEXSX4.js");t.derivationOrigin=this.config?.derivationOrigin||a()}}catch{}this.pnp=new ge(t);try{let a=await te(this.pnp);if(a){this.walletConnected=!0;let r=T(this.pnp,{owner:a,principal:a,connected:!0}),o=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(c,d)=>this.pnp.getActor({canisterId:c,idl:d,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{}},this.sdk=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"oisy"}}))}catch{}this.donate();return}}catch{}let n=this.pnp.getEnabledWallets();if(Se(this.config?.debug||!1,"Available wallets",n),!n?.length)throw new Error("No wallets available");this.pendingAction="donate",this.showWalletModal=!0;return}catch(e){Se(this.config?.debug||!1,"Wallet connection error:",e),this.errorMessage=e instanceof Error?e.message:"Wallet connection failed",this.errorSeverity="error";return}}this.showWalletModal=!0,await this.fetchAndShowBalances();return}catch(e){P(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),D(t)&&(this.errorMessage=_(t),this.errorSeverity=F(t),this.errorAction=z(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,n=t?.event_id||t?.eventId||t?.id;if(!(!n||typeof n!="string")&&n==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let a=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(a||void 0)}}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1,setTimeout(()=>this.createOnrampIntent(),0)}async createOnrampIntent(){try{let e=g(this.config),t=this.selectedSymbol||"ICP",n=await e.startOnrampUsd(this.selectedAmount,t,{context:"donation:onramp"}),a=n?.metadata?.onramp?.sessionId||n?.metadata?.onramp?.session_id||null,r=n?.metadata?.paymentIntentId||n?.paymentIntentId||null,o=n?.metadata?.onramp?.errorMessage||null;this.onrampPaymentIntentId=r,a?(this.onrampSessionId=a,this.onrampErrorMessage=null,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.onrampErrorMessage=o||"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 n=g(this.config),a=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>a()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=n.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");this.lastWalletId=(e||"").toLowerCase(),this.pnp.connect(e).then(n=>{if(!!!(n&&(n.connected===!0||n.principal||n.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}let r=T(this.pnp,n),o=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(d,h)=>this.pnp.getActor({canisterId:d,idl:h,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{}},this.sdk=null,this.lastWalletId==="oisy"?this.oisyReadyToPay=!0:(this.showWalletModal=!1,this.fetchAndShowBalances())}).catch(n=>{this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}})}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}}}async fetchAndShowBalances(){try{this.balancesLoading=!0,this.balancesError=null,this.showBalanceModal=!0;let e=g(this.config),{balances:t}=await Y({sdk:e,lastWalletId:this.lastWalletId,connectedWallet:this.config?.connectedWallet,amountUsd:Number(this.selectedAmount||0),chainShortcodes:this.config?.chainShortcodes,tokenShortcodes:this.config?.tokenShortcodes});this.walletBalances=t}catch(e){this.walletBalances=[],this.balancesError=e&&(e.message||String(e))||"Failed to load balances"}finally{this.balancesLoading=!1}}render(){return this.config?he`
1340
+ `],s([St({type:Object})],x.prototype,"config",2),s([I()],x.prototype,"selectedIndex",2),s([I()],x.prototype,"selectedSymbol",2),s([I()],x.prototype,"processing",2),s([I()],x.prototype,"errorMessage",2),s([I()],x.prototype,"errorSeverity",2),s([I()],x.prototype,"errorAction",2),s([I()],x.prototype,"walletConnected",2),s([I()],x.prototype,"pendingAction",2),s([I()],x.prototype,"showWalletModal",2),s([I()],x.prototype,"oisyReadyToPay",2),s([I()],x.prototype,"lastWalletId",2),s([I()],x.prototype,"showOnrampModal",2),s([I()],x.prototype,"onrampSessionId",2),s([I()],x.prototype,"onrampPaymentIntentId",2),s([I()],x.prototype,"onrampErrorMessage",2),s([I()],x.prototype,"showBalanceModal",2),s([I()],x.prototype,"balancesLoading",2),s([I()],x.prototype,"balancesError",2),s([I()],x.prototype,"walletBalances",2),x=s([xt("icpay-coffee-shop")],x);import{LitElement as kt,html as he,css as Mt}from"lit";import{customElement as Wt,property as Ct,state as M}from"lit/decorators.js";var je=typeof window<"u",ge=null;function Se(i,l,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${l}`,e):console.log(`[ICPay Widget] ${l}`))}var b=class extends kt{constructor(){super(...arguments);this.selectedAmount=10;this.selectedSymbol=null;this.raised=0;this.processing=!1;this.succeeded=!1;this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.showOnrampModal=!1;this.onrampSessionId=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.transakMessageHandlerBound=null;this.onrampPollTimer=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.sdk=null;this.showBalanceModal=!1;this.balancesLoading=!1;this.balancesError=null;this.walletBalances=[];this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="donate",this.showWalletModal=!0,this.requestUpdate();try{let t=Number(this.selectedAmount||0),n=this.selectedSymbol||"ICP";window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"donate",type:"sendUsd",amount:t,currency:n}}))}catch{}}catch{}};this.onSelectBalanceSymbol=async e=>{let t=(this.walletBalances||[]).find(a=>a?.tokenShortcode===e);if(t?.ledgerSymbol&&(this.selectedSymbol=t.ledgerSymbol),R(this.lastWalletId)){let a=(this.walletBalances||[]).find(o=>o?.tokenShortcode===e),r=a?.chainId;V(r,{provider:this.pnp?.getEvmProvider?.()||this.config?.evmProvider,chainName:a?.chainName,rpcUrlPublic:a?.rpcUrlPublic,nativeSymbol:a?.ledgerSymbol,decimals:a?.decimals}).then(async()=>{try{let o=g(this.config),c=Number(this.selectedAmount||0);if(a?.x402Accepts)try{await o.client.createPaymentX402Usd({usdAmount:c,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,icpay_network:"evm",icpay_ledger_id:a?.ledgerId,icpay_context:"donation:x402"}}),this.showBalanceModal=!1;return}catch{}await o.client.createPaymentUsd({usdAmount:c,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,icpay_network:"evm",icpay_ledger_id:a?.ledgerId}})}catch{}this.showBalanceModal=!1});return}this.showBalanceModal=!1;let n=this.pendingAction;if(this.pendingAction=null,n==="donate")try{let a=(this.walletBalances||[]).find(c=>c?.tokenShortcode===e),r=g(this.config),o=Number(this.selectedAmount||0);await r.client.createPaymentUsd({usdAmount:o,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,icpay_network:"ic",icpay_ledger_id:a?.ledgerId}})}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;ge||(ge=(await import("./wallet-select-YKQSWA6J.js")).WalletSelect);let n=U({...this.config?.plugNPlay||{}});try{if(typeof window<"u"){let{resolveDerivationOrigin:r}=await import("./origin-44ZEXSX4.js");n.derivationOrigin=this.config?.derivationOrigin||r()}}catch{}let a=new ge(n);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]}connectedCallback(){if(super.connectedCallback(),!!je){Se(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{}try{window.addEventListener("icpay-sdk-transaction-created",(()=>{this.showWalletModal=!1,this.requestUpdate()}))}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==="donate"&&this.donate()},0)}}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(je&&!this.processing){Se(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||"ICP"}}))}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){Se(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{ge||(ge=(await import("./wallet-select-YKQSWA6J.js")).WalletSelect);let t=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab)?U({...this.config?.plugNPlay||{}}):{...this.config?.plugNPlay||{}};this.config?.chainTypes&&(t.chainTypes=this.config.chainTypes);try{if(typeof window<"u"){let{resolveDerivationOrigin:a}=await import("./origin-44ZEXSX4.js");t.derivationOrigin=this.config?.derivationOrigin||a()}}catch{}this.pnp=new ge(t);try{let a=await te(this.pnp);if(a){this.walletConnected=!0;let r=T(this.pnp,{owner:a,principal:a,connected:!0}),o=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(c,d)=>this.pnp.getActor({canisterId:c,idl:d,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{}},this.sdk=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"oisy"}}))}catch{}this.donate();return}}catch{}let n=this.pnp.getEnabledWallets();if(Se(this.config?.debug||!1,"Available wallets",n),!n?.length)throw new Error("No wallets available");this.pendingAction="donate",this.showWalletModal=!0;return}catch(e){Se(this.config?.debug||!1,"Wallet connection error:",e),this.errorMessage=e instanceof Error?e.message:"Wallet connection failed",this.errorSeverity="error";return}}this.showWalletModal=!0,await this.fetchAndShowBalances();return}catch(e){P(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),D(t)&&(this.errorMessage=_(t),this.errorSeverity=F(t),this.errorAction=z(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,n=t?.event_id||t?.eventId||t?.id;if(!(!n||typeof n!="string")&&n==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let a=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(a||void 0)}}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1,setTimeout(()=>this.createOnrampIntent(),0)}async createOnrampIntent(){try{let e=g(this.config),t=this.selectedSymbol||"ICP",n=await e.startOnrampUsd(this.selectedAmount,t,{context:"donation:onramp"}),a=n?.metadata?.icpay_onramp?.sessionId||n?.metadata?.icpay_onramp?.session_id||n?.metadata?.onramp?.sessionId||n?.metadata?.onramp?.session_id||null,r=n?.metadata?.icpay_payment_intent_id||n?.metadata?.paymentIntentId||n?.paymentIntentId||null,o=n?.metadata?.icpay_onramp?.errorMessage||n?.metadata?.onramp?.errorMessage||null;this.onrampPaymentIntentId=r,a?(this.onrampSessionId=a,this.onrampErrorMessage=null,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.onrampErrorMessage=o||"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 n=g(this.config),a=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>a()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=n.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");this.lastWalletId=(e||"").toLowerCase(),this.pnp.connect(e).then(n=>{if(!!!(n&&(n.connected===!0||n.principal||n.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}let r=T(this.pnp,n),o=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(d,h)=>this.pnp.getActor({canisterId:d,idl:h,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{}},this.sdk=null,this.lastWalletId==="oisy"?this.oisyReadyToPay=!0:(this.showWalletModal=!1,this.fetchAndShowBalances())}).catch(n=>{this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}})}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}}}async fetchAndShowBalances(){try{this.balancesLoading=!0,this.balancesError=null,this.showBalanceModal=!0;let e=g(this.config),{balances:t}=await Y({sdk:e,lastWalletId:this.lastWalletId,connectedWallet:this.config?.connectedWallet,amountUsd:Number(this.selectedAmount||0),chainShortcodes:this.config?.chainShortcodes,tokenShortcodes:this.config?.tokenShortcodes});this.walletBalances=t}catch(e){this.walletBalances=[],this.balancesError=e&&(e.message||String(e))||"Failed to load balances"}finally{this.balancesLoading=!1}}render(){return this.config?he`
1341
1341
  <div class="icpay-card icpay-section icpay-widget-base" style="text-align:center;">
1342
1342
  ${this.config?.progressBar?.enabled!==!1?he`
1343
1343
  <icpay-progress-bar
@@ -1410,7 +1410,7 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var H=Xe`
1410
1410
  border-color: rgba(239, 68, 68, 0.3);
1411
1411
  color: #ef4444;
1412
1412
  }
1413
- `],s([Ct({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,"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,"oisyReadyToPay",2),s([M()],b.prototype,"lastWalletId",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),s([M()],b.prototype,"showBalanceModal",2),s([M()],b.prototype,"balancesLoading",2),s([M()],b.prototype,"balancesError",2),s([M()],b.prototype,"walletBalances",2),b=s([Wt("icpay-donation-thermometer")],b);import{LitElement as Tt,html as ke,css as At}from"lit";import{customElement as It,property as Ot,state as S}from"lit/decorators.js";var qe=typeof window<"u",ue=null;function $(i,l,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${l}`,e):console.log(`[ICPay Widget] ${l}`))}var y=class extends Tt{constructor(){super(...arguments);this.selectedSymbol=null;this.processing=!1;this.succeeded=!1;this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.walletModalStep="connect";this.showOnrampModal=!1;this.onrampSessionId=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.oisyReadyToPay=!1;this.oisySignerPreopened=!1;this.skipDisconnectOnce=!1;this.lastWalletId=null;this.showBalanceModal=!1;this.balancesLoading=!1;this.balancesError=null;this.walletBalances=[];this.onrampPollTimer=null;this.transakMessageHandlerBound=null;this.pnp=null;this.oisyConnectRetriedNewTab=!1;this.sdk=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="pay",this.walletModalStep="connect",this.showWalletModal=!0,this.oisyReadyToPay=!1,this.lastWalletId=null,this.requestUpdate();try{let t=Number(this.config?.amountUsd||0),n=this.selectedSymbol||"ICP";window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"pay",type:"sendUsd",amount:t,currency:n}}))}catch{}}catch{}};this.onSelectBalanceSymbol=async e=>{let t=(this.walletBalances||[]).find(a=>a?.tokenShortcode===e);if(t?.ledgerSymbol&&(this.selectedSymbol=t.ledgerSymbol),this.showBalanceModal=!1,this.showWalletModal=!1,R(this.lastWalletId)){$(this.config?.debug||!1,"EVM selection made",{selectedSymbol:this.selectedSymbol,selPresent:!!t,selSnapshot:t?{ledgerId:t?.ledgerId,ledgerSymbol:t?.ledgerSymbol,ledgerName:t?.ledgerName,chainUuid:t?.chainUuid,chainId:t?.chainId,chainName:t?.chainName,x402Accepts:t?.x402Accepts,requiredAmount:t?.requiredAmount,hasSufficientBalance:t?.hasSufficientBalance}:null});let a=t?.chainId;V(a,{chainName:t?.chainName,rpcUrlPublic:t?.rpcUrlPublic,nativeSymbol:t?.ledgerSymbol,decimals:t?.decimals}).then(async()=>{try{let r=this.getSdk(),o=Number(this.config?.amountUsd??0),c=t?.ledgerSymbol,d=!!(t&&t.x402Accepts);if($(this.config?.debug||!1,"EVM post-ensure chain snapshot",{targetChain:a,amountUsd:o,symbolNow:c,tryX402:d,x402Accepts:t?.x402Accepts}),d)try{let h={...this.config?.metadata,network:"evm",ledgerId:t?.ledgerId,chainId:t?.chainUuid,context:"pay-button:x402"};$(this.config?.debug||!1,"Attempting X402 flow (EVM selection)",{amountUsd:o,tokenShortcode:t?.tokenShortcode,x402Accepts:t?.x402Accepts}),await r.client.createPaymentX402Usd({usdAmount:o,tokenShortcode:t?.tokenShortcode,metadata:h});return}catch(h){$(this.config?.debug||!1,"X402 payment failed (EVM selection), falling back",{message:h?.message,code:h?.code,data:h?.details||h?.data})}else $(this.config?.debug||!1,"Skipping X402 path",{reason:t?t.x402Accepts?"unknown":"x402Accepts false":"no selection",selPresent:!!t,x402Accepts:t?.x402Accepts});$(this.config?.debug||!1,"Falling back to normal EVM wallet flow",{amountUsd:o,tokenShortcode:t?.tokenShortcode}),await r.client.createPaymentUsd({usdAmount:o,tokenShortcode:t?.tokenShortcode,metadata:{...this.config?.metadata,network:"evm",ledgerId:t?.ledgerId}})}catch{}});return}let n=this.pendingAction;if(this.pendingAction=null,n==="pay")try{let a=(this.walletBalances||[]).find(c=>c?.tokenShortcode===e),r=this.getSdk(),o=Number(this.config?.amountUsd??0);$(this.config?.debug||!1,"IC selection made",{selectedSymbol:this.selectedSymbol,selPresent:!!a,selSnapshot:a?{ledgerId:a?.ledgerId,ledgerSymbol:a?.ledgerSymbol,ledgerName:a?.ledgerName,requiredAmount:a?.requiredAmount,hasSufficientBalance:a?.hasSufficientBalance,tokenShortcode:a?.tokenShortcode}:null}),await r.client.createPaymentUsd({usdAmount:o,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,network:"ic",ledgerId:a?.ledgerId}})}catch{}}}getSdk(){return this.sdk||(this.sdk=g(this.config)),this.sdk}connectedCallback(){if(super.connectedCallback(),!!qe){$(this.config?.debug||!1,"Pay button connected",{config:this.config});try{window.addEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}try{window.addEventListener("icpay-sdk-transaction-created",(e=>{$(this.config?.debug||!1,"SDK transaction created",{detail:e?.detail}),this.showWalletModal=!1,this.showBalanceModal=!1,this.requestUpdate()}))}catch{}}}updated(e){if(e.has("config")&&this.pendingAction&&this.config?.actorProvider){let t=this.pendingAction;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}this.walletModalStep!=="balances"&&!this.oisyReadyToPay&&(this.pendingAction=null,setTimeout(()=>{t==="pay"&&this.pay()},0))}e.has("config")&&(this.sdk=null)}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{ue||(ue=(await import("./wallet-select-M5KY6N6N.js")).WalletSelect);let e=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab),t={...this.config?.plugNPlay||{}};this.config?.chainTypes&&(t.chainTypes=this.config.chainTypes);let n=e?U(t):t;try{if(typeof window<"u"){let{resolveDerivationOrigin:r}=await import("./origin-44ZEXSX4.js");n.derivationOrigin=this.config?.derivationOrigin||r()}}catch{}this.pnp=new ue(n);let a=this.pnp.getEnabledWallets();if($(this.config?.debug||!1,"Available wallets",a),!a?.length)throw new Error("No wallets available");return this.pendingAction="pay",this.showWalletModal=!0,!1}catch(e){return this.errorMessage=e instanceof Error?e.message:"Wallet connection failed",this.errorSeverity="error",!1}}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");this.lastWalletId=(e||"").toLowerCase(),this.lastWalletId==="oisy"&&(this.oisyConnectRetriedNewTab=!1),this.pnp.connect(e).then(n=>{if($(this.config?.debug||!1,"Wallet connect result",n),!!!(n&&(n.connected===!0||n.principal||n.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}let r=T(this.pnp,n),o=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(d,h)=>this.pnp.getActor({canisterId:d,idl:h,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{}},this.sdk=null,(e||"").toLowerCase()==="oisy"?(this.oisyReadyToPay=!0,this.pendingAction=null):(this.walletModalStep="balances",this.fetchAndShowBalances("pay"))}).catch(n=>{$(this.config?.debug||!1,"Wallet connection error",n);let a=(e||"").toLowerCase()==="oisy",r=n&&(n.message||String(n))||"";if(a&&!this.oisyConnectRetriedNewTab&&(r.includes("Signer window could not be opened")||r.includes("Communication channel could not be established"))){this.oisyConnectRetriedNewTab=!0,(async()=>{try{ue||(ue=(await import("./wallet-select-M5KY6N6N.js")).WalletSelect);let c={...this.config?.plugNPlay||{}};this.config?.chainTypes&&(c.chainTypes=this.config.chainTypes);let d=U(c);try{if(typeof window<"u"){let{resolveDerivationOrigin:p}=await import("./origin-44ZEXSX4.js");d.derivationOrigin=this.config?.derivationOrigin||p()}}catch{}this.pnp=new ue(d),this.pnp.connect("oisy").then(p=>{if(!!!(p&&(p.connected===!0||p.principal||p.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"oisy"}}))}catch{}let K=T(this.pnp,p),ee=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:K,actorProvider:(C,B)=>this.pnp.getActor({canisterId:C,idl:B,requiresSigning:!0,anon:!1}),...ee?{evmProvider:ee}:{}},this.sdk=null,this.oisyReadyToPay=!0,this.pendingAction=null}).catch(p=>{$(this.config?.debug||!1,"Oisy retry connect (new tab) failed",p),this.errorMessage=p instanceof Error?p.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}})}catch(c){$(this.config?.debug||!1,"Oisy new-tab init failed",c),this.errorMessage=c instanceof Error?c.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}}})();return}this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}})}catch(t){$(this.config?.debug||!1,"Wallet connection error (sync)",t),this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}}}async fetchAndShowBalances(e){try{this.balancesLoading=!0,this.balancesError=null,this.walletModalStep="balances",this.showBalanceModal=!1;let t=this.getSdk(),{balances:n}=await Y({sdk:t,lastWalletId:this.lastWalletId,connectedWallet:this.config?.connectedWallet,amountUsd:Number(this.config?.amountUsd??0),chainShortcodes:this.config?.chainShortcodes,tokenShortcodes:this.config?.tokenShortcodes});this.walletBalances=n,this.pendingAction=e}catch(t){this.walletBalances=[],this.balancesError=t&&(t.message||String(t))||"Failed to load balances"}finally{this.balancesLoading=!1}}renderWalletModal(){if(!this.showWalletModal||!this.pnp)return null;let e=this.pnp.getEnabledWallets()||[],t=G(e),n=this.config?.onramp?.enabled!==!1&&this.config?.onrampDisabled!==!0,a=5,r=Number(this.config?.amountUsd??0),o=n&&r>0&&r<a,c=Math.max(0,a-r),d=o?`Note: Minimum card amount is $${a}. You will pay about $${c.toFixed(2)} more.`:null;return Q({visible:this.showWalletModal,wallets:t,isConnecting:!1,onSwitchAccount:()=>this.onSwitchAccount(null),step:this.walletModalStep,balances:this.walletModalStep==="balances"?this.walletBalances||[]:[],balancesLoading:this.walletModalStep==="balances"?this.balancesLoading:!1,balancesError:this.walletModalStep==="balances"?this.balancesError:null,onSelectBalance:h=>this.onSelectBalanceSymbol(h),onBack:()=>{this.walletModalStep="connect"},onSelect:h=>{this.connectWithWallet(h)},onClose:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-cancelled",{detail:{reason:"user_cancelled"}}))}catch{}},onCreditCard:n?()=>this.startOnramp():void 0,creditCardLabel:this.config?.onramp?.creditCardLabel||"Pay with credit card",showCreditCard:n,creditCardTooltip:d,oisyReadyToPay:this.oisyReadyToPay,onOisyPay:()=>{this.showWalletModal=!1,this.skipDisconnectOnce=!0,this.oisyReadyToPay=!1,this.pay()}})}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1,setTimeout(()=>this.createOnrampIntent(),0)}async createOnrampIntent(){try{let e=Number(this.config?.amountUsd??0),t=this.getSdk();this.selectedSymbol||(this.selectedSymbol="ICP");let n=this.selectedSymbol||"ICP",a=await t.startOnrampUsd(e,n,{context:"pay-button:onramp"}),r=a?.metadata?.onramp?.sessionId||a?.metadata?.onramp?.session_id||null,o=a?.metadata?.onramp?.errorMessage||null;this.onrampErrorMessage=o||null;let c=a?.metadata?.paymentIntentId||a?.paymentIntentId||null;this.onrampPaymentIntentId=c,r?(this.onrampSessionId=r,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.showOnrampModal=!0)}catch(e){this.onrampSessionId=null,this.onrampErrorMessage=e?.message||null,this.showOnrampModal=!0,P(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),D(t)&&(this.errorMessage=_(t),this.errorSeverity=F(t),this.errorAction=z(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,n=t?.event_id||t?.eventId||t?.id;if(!(!n||typeof n!="string")&&n==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;let a=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(a||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 n=this.getSdk(),a=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1},r=o=>{a()};try{window.addEventListener("icpay-sdk-transaction-completed",r,{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=n.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}async pay(){if(!(!qe||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||"ICP"}}))}catch{}this.processing=!0;try{if(this.skipDisconnectOnce)this.skipDisconnectOnce=!1;else try{!this.config.useOwnWallet&&this.pnp&&(await this.pnp.disconnect?.(),this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0})}catch{}if(!await this.ensureWallet())return;let t=this.getSdk();try{let n=this.config?.connectedWallet,a=this?.pnp?.account;$(this.config?.debug||!1,"Wallet state before payment",{connectedWallet:n,pnpAccount:a,principal:n?.owner||n?.principal||a?.owner||a?.principal||null})}catch{}this.walletModalStep="balances",this.showWalletModal=!0,await this.fetchAndShowBalances("pay");return}catch(e){$(this.config?.debug||!1,"Payment error",{message:e?.message,code:e?.code,details:e?.details,stack:e?.stack}),P(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),D(t)&&(this.errorMessage=_(t),this.errorSeverity=F(t),this.errorAction=z(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 ke`<div class="icpay-card icpay-section">Loading...</div>`;let e=this.selectedSymbol||"ICP",t=typeof this.config?.amountUsd=="number"?`${Number(this.config.amountUsd).toFixed(2)}`:"",a=(this.config?.buttonLabel||(typeof this.config?.amountUsd=="number"?"Pay ${amount} with crypto":"Pay with {symbol}")).replace("{amount}",t||"$0.00").replace("{symbol}",e),o=this.config?.progressBar?.enabled!==!1,c=this.showWalletModal||this.showBalanceModal;return ke`
1413
+ `],s([Ct({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,"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,"oisyReadyToPay",2),s([M()],b.prototype,"lastWalletId",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),s([M()],b.prototype,"showBalanceModal",2),s([M()],b.prototype,"balancesLoading",2),s([M()],b.prototype,"balancesError",2),s([M()],b.prototype,"walletBalances",2),b=s([Wt("icpay-donation-thermometer")],b);import{LitElement as Tt,html as ke,css as At}from"lit";import{customElement as Ot,property as Lt,state as S}from"lit/decorators.js";var qe=typeof window<"u",ue=null;function $(i,l,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${l}`,e):console.log(`[ICPay Widget] ${l}`))}var y=class extends Tt{constructor(){super(...arguments);this.selectedSymbol=null;this.processing=!1;this.succeeded=!1;this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.walletModalStep="connect";this.showOnrampModal=!1;this.onrampSessionId=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.oisyReadyToPay=!1;this.oisySignerPreopened=!1;this.skipDisconnectOnce=!1;this.lastWalletId=null;this.showBalanceModal=!1;this.balancesLoading=!1;this.balancesError=null;this.walletBalances=[];this.onrampPollTimer=null;this.transakMessageHandlerBound=null;this.pnp=null;this.oisyConnectRetriedNewTab=!1;this.sdk=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="pay",this.walletModalStep="connect",this.showWalletModal=!0,this.oisyReadyToPay=!1,this.lastWalletId=null,this.requestUpdate();try{let t=Number(this.config?.amountUsd||0),n=this.selectedSymbol||"ICP";window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"pay",type:"sendUsd",amount:t,currency:n}}))}catch{}}catch{}};this.onSelectBalanceSymbol=async e=>{let t=(this.walletBalances||[]).find(a=>a?.tokenShortcode===e);if(t?.ledgerSymbol&&(this.selectedSymbol=t.ledgerSymbol),this.showBalanceModal=!1,this.showWalletModal=!1,R(this.lastWalletId)){$(this.config?.debug||!1,"EVM selection made",{selectedSymbol:this.selectedSymbol,selPresent:!!t,selSnapshot:t?{ledgerId:t?.ledgerId,ledgerSymbol:t?.ledgerSymbol,ledgerName:t?.ledgerName,chainUuid:t?.chainUuid,chainId:t?.chainId,chainName:t?.chainName,x402Accepts:t?.x402Accepts,requiredAmount:t?.requiredAmount,hasSufficientBalance:t?.hasSufficientBalance}:null});let a=t?.chainId;V(a,{provider:this.pnp?.getEvmProvider?.()||this.config?.evmProvider,chainName:t?.chainName,rpcUrlPublic:t?.rpcUrlPublic,nativeSymbol:t?.ledgerSymbol,decimals:t?.decimals}).then(async()=>{try{let r=this.getSdk(),o=Number(this.config?.amountUsd??0),c=t?.ledgerSymbol,d=!!(t&&t.x402Accepts);if($(this.config?.debug||!1,"EVM post-ensure chain snapshot",{targetChain:a,amountUsd:o,symbolNow:c,tryX402:d,x402Accepts:t?.x402Accepts}),d)try{let h={...this.config?.metadata,icpay_network:"evm",icpay_ledger_id:t?.ledgerId,icpay_context:"pay-button:x402"};$(this.config?.debug||!1,"Attempting X402 flow (EVM selection)",{amountUsd:o,tokenShortcode:t?.tokenShortcode,x402Accepts:t?.x402Accepts}),await r.client.createPaymentX402Usd({usdAmount:o,tokenShortcode:t?.tokenShortcode,metadata:h});return}catch(h){$(this.config?.debug||!1,"X402 payment failed (EVM selection), falling back",{message:h?.message,code:h?.code,data:h?.details||h?.data})}else $(this.config?.debug||!1,"Skipping X402 path",{reason:t?t.x402Accepts?"unknown":"x402Accepts false":"no selection",selPresent:!!t,x402Accepts:t?.x402Accepts});$(this.config?.debug||!1,"Falling back to normal EVM wallet flow",{amountUsd:o,tokenShortcode:t?.tokenShortcode}),await r.client.createPaymentUsd({usdAmount:o,tokenShortcode:t?.tokenShortcode,metadata:{...this.config?.metadata,icpay_network:"evm",icpay_ledger_id:t?.ledgerId}})}catch{}});return}let n=this.pendingAction;if(this.pendingAction=null,n==="pay")try{let a=(this.walletBalances||[]).find(c=>c?.tokenShortcode===e),r=this.getSdk(),o=Number(this.config?.amountUsd??0);$(this.config?.debug||!1,"IC selection made",{selectedSymbol:this.selectedSymbol,selPresent:!!a,selSnapshot:a?{ledgerId:a?.ledgerId,ledgerSymbol:a?.ledgerSymbol,ledgerName:a?.ledgerName,requiredAmount:a?.requiredAmount,hasSufficientBalance:a?.hasSufficientBalance,tokenShortcode:a?.tokenShortcode}:null}),await r.client.createPaymentUsd({usdAmount:o,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,icpay_network:"ic",icpay_ledger_id:a?.ledgerId}})}catch{}}}getSdk(){return this.sdk||(this.sdk=g(this.config)),this.sdk}connectedCallback(){if(super.connectedCallback(),!!qe){$(this.config?.debug||!1,"Pay button connected",{config:this.config});try{window.addEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}try{window.addEventListener("icpay-sdk-transaction-created",(e=>{$(this.config?.debug||!1,"SDK transaction created",{detail:e?.detail}),this.showWalletModal=!1,this.showBalanceModal=!1,this.requestUpdate()}))}catch{}}}updated(e){if(e.has("config")&&this.pendingAction&&this.config?.actorProvider){let t=this.pendingAction;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}this.walletModalStep!=="balances"&&!this.oisyReadyToPay&&(this.pendingAction=null,setTimeout(()=>{t==="pay"&&this.pay()},0))}e.has("config")&&(this.sdk=null)}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{ue||(ue=(await import("./wallet-select-YKQSWA6J.js")).WalletSelect);let e=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab),t={...this.config?.plugNPlay||{}};this.config?.chainTypes&&(t.chainTypes=this.config.chainTypes);let n=e?U(t):t;try{if(typeof window<"u"){let{resolveDerivationOrigin:r}=await import("./origin-44ZEXSX4.js");n.derivationOrigin=this.config?.derivationOrigin||r()}}catch{}this.pnp=new ue(n);let a=this.pnp.getEnabledWallets();if($(this.config?.debug||!1,"Available wallets",a),!a?.length)throw new Error("No wallets available");return this.pendingAction="pay",this.showWalletModal=!0,!1}catch(e){return this.errorMessage=e instanceof Error?e.message:"Wallet connection failed",this.errorSeverity="error",!1}}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");this.lastWalletId=(e||"").toLowerCase(),this.lastWalletId==="oisy"&&(this.oisyConnectRetriedNewTab=!1),this.pnp.connect(e).then(n=>{if($(this.config?.debug||!1,"Wallet connect result",n),!!!(n&&(n.connected===!0||n.principal||n.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}let r=T(this.pnp,n),o=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(d,h)=>this.pnp.getActor({canisterId:d,idl:h,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{}},this.sdk=null,(e||"").toLowerCase()==="oisy"?(this.oisyReadyToPay=!0,this.pendingAction=null):(this.walletModalStep="balances",this.fetchAndShowBalances("pay"))}).catch(n=>{$(this.config?.debug||!1,"Wallet connection error",n);let a=(e||"").toLowerCase()==="oisy",r=n&&(n.message||String(n))||"";if(a&&!this.oisyConnectRetriedNewTab&&(r.includes("Signer window could not be opened")||r.includes("Communication channel could not be established"))){this.oisyConnectRetriedNewTab=!0,(async()=>{try{ue||(ue=(await import("./wallet-select-YKQSWA6J.js")).WalletSelect);let c={...this.config?.plugNPlay||{}};this.config?.chainTypes&&(c.chainTypes=this.config.chainTypes);let d=U(c);try{if(typeof window<"u"){let{resolveDerivationOrigin:p}=await import("./origin-44ZEXSX4.js");d.derivationOrigin=this.config?.derivationOrigin||p()}}catch{}this.pnp=new ue(d),this.pnp.connect("oisy").then(p=>{if(!!!(p&&(p.connected===!0||p.principal||p.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"oisy"}}))}catch{}let K=T(this.pnp,p),ee=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:K,actorProvider:(C,B)=>this.pnp.getActor({canisterId:C,idl:B,requiresSigning:!0,anon:!1}),...ee?{evmProvider:ee}:{}},this.sdk=null,this.oisyReadyToPay=!0,this.pendingAction=null}).catch(p=>{$(this.config?.debug||!1,"Oisy retry connect (new tab) failed",p),this.errorMessage=p instanceof Error?p.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}})}catch(c){$(this.config?.debug||!1,"Oisy new-tab init failed",c),this.errorMessage=c instanceof Error?c.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}}})();return}this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}})}catch(t){$(this.config?.debug||!1,"Wallet connection error (sync)",t),this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}}}async fetchAndShowBalances(e){try{this.balancesLoading=!0,this.balancesError=null,this.walletModalStep="balances",this.showBalanceModal=!1;let t=this.getSdk(),{balances:n}=await Y({sdk:t,lastWalletId:this.lastWalletId,connectedWallet:this.config?.connectedWallet,amountUsd:Number(this.config?.amountUsd??0),chainShortcodes:this.config?.chainShortcodes,tokenShortcodes:this.config?.tokenShortcodes});this.walletBalances=n,this.pendingAction=e}catch(t){this.walletBalances=[],this.balancesError=t&&(t.message||String(t))||"Failed to load balances"}finally{this.balancesLoading=!1}}renderWalletModal(){if(!this.showWalletModal||!this.pnp)return null;let e=this.pnp.getEnabledWallets()||[],t=G(e),n=this.config?.onramp?.enabled!==!1&&this.config?.onrampDisabled!==!0,a=5,r=Number(this.config?.amountUsd??0),o=n&&r>0&&r<a,c=Math.max(0,a-r),d=o?`Note: Minimum card amount is $${a}. You will pay about $${c.toFixed(2)} more.`:null;return Q({visible:this.showWalletModal,wallets:t,isConnecting:!1,onSwitchAccount:()=>this.onSwitchAccount(null),step:this.walletModalStep,balances:this.walletModalStep==="balances"?this.walletBalances||[]:[],balancesLoading:this.walletModalStep==="balances"?this.balancesLoading:!1,balancesError:this.walletModalStep==="balances"?this.balancesError:null,onSelectBalance:h=>this.onSelectBalanceSymbol(h),onBack:()=>{this.walletModalStep="connect"},onSelect:h=>{this.connectWithWallet(h)},onClose:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-cancelled",{detail:{reason:"user_cancelled"}}))}catch{}},onCreditCard:n?()=>this.startOnramp():void 0,creditCardLabel:this.config?.onramp?.creditCardLabel||"Pay with credit card",showCreditCard:n,creditCardTooltip:d,oisyReadyToPay:this.oisyReadyToPay,onOisyPay:()=>{this.showWalletModal=!1,this.skipDisconnectOnce=!0,this.oisyReadyToPay=!1,this.pay()}})}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1,setTimeout(()=>this.createOnrampIntent(),0)}async createOnrampIntent(){try{let e=Number(this.config?.amountUsd??0),t=this.getSdk();this.selectedSymbol||(this.selectedSymbol="ICP");let n=this.selectedSymbol||"ICP",a=await t.startOnrampUsd(e,n,{context:"pay-button:onramp"}),r=a?.metadata?.icpay_onramp?.sessionId||a?.metadata?.icpay_onramp?.session_id||a?.metadata?.onramp?.sessionId||a?.metadata?.onramp?.session_id||null,o=a?.metadata?.icpay_onramp?.errorMessage||a?.metadata?.onramp?.errorMessage||null;this.onrampErrorMessage=o||null;let c=a?.metadata?.icpay_payment_intent_id||a?.metadata?.paymentIntentId||a?.paymentIntentId||null;this.onrampPaymentIntentId=c,r?(this.onrampSessionId=r,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.showOnrampModal=!0)}catch(e){this.onrampSessionId=null,this.onrampErrorMessage=e?.message||null,this.showOnrampModal=!0,P(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),D(t)&&(this.errorMessage=_(t),this.errorSeverity=F(t),this.errorAction=z(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,n=t?.event_id||t?.eventId||t?.id;if(!(!n||typeof n!="string")&&n==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;let a=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(a||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 n=this.getSdk(),a=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1},r=o=>{a()};try{window.addEventListener("icpay-sdk-transaction-completed",r,{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=n.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}async pay(){if(!(!qe||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||"ICP"}}))}catch{}this.processing=!0;try{if(this.skipDisconnectOnce)this.skipDisconnectOnce=!1;else try{!this.config.useOwnWallet&&this.pnp&&(await this.pnp.disconnect?.(),this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0})}catch{}if(!await this.ensureWallet())return;let t=this.getSdk();try{let n=this.config?.connectedWallet,a=this?.pnp?.account;$(this.config?.debug||!1,"Wallet state before payment",{connectedWallet:n,pnpAccount:a,principal:n?.owner||n?.principal||a?.owner||a?.principal||null})}catch{}this.walletModalStep="balances",this.showWalletModal=!0,await this.fetchAndShowBalances("pay");return}catch(e){$(this.config?.debug||!1,"Payment error",{message:e?.message,code:e?.code,details:e?.details,stack:e?.stack}),P(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),D(t)&&(this.errorMessage=_(t),this.errorSeverity=F(t),this.errorAction=z(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 ke`<div class="icpay-card icpay-section">Loading...</div>`;let e=this.selectedSymbol||"ICP",t=typeof this.config?.amountUsd=="number"?`${Number(this.config.amountUsd).toFixed(2)}`:"",a=(this.config?.buttonLabel||(typeof this.config?.amountUsd=="number"?"Pay ${amount} with crypto":"Pay with {symbol}")).replace("{amount}",t||"$0.00").replace("{symbol}",e),o=this.config?.progressBar?.enabled!==!1,c=this.showWalletModal||this.showBalanceModal;return ke`
1414
1414
  <div class="icpay-card icpay-section icpay-widget-base">
1415
1415
  ${o?ke`
1416
1416
  <icpay-progress-bar
@@ -1448,7 +1448,7 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var H=Xe`
1448
1448
  .error-message.info { background: rgba(59,130,246,0.1); border-color: rgba(59,130,246,0.3); color: #3b82f6; }
1449
1449
  .error-message.warning { background: rgba(245,158,11,0.1); border-color: rgba(245,158,11,0.3); color: #f59e0b; }
1450
1450
  .error-message.error { background: rgba(239,68,68,0.1); border-color: rgba(239,68,68,0.3); color: #ef4444; }
1451
- `],s([Ot({type:Object})],y.prototype,"config",2),s([S()],y.prototype,"selectedSymbol",2),s([S()],y.prototype,"processing",2),s([S()],y.prototype,"succeeded",2),s([S()],y.prototype,"errorMessage",2),s([S()],y.prototype,"errorSeverity",2),s([S()],y.prototype,"errorAction",2),s([S()],y.prototype,"walletConnected",2),s([S()],y.prototype,"pendingAction",2),s([S()],y.prototype,"showWalletModal",2),s([S()],y.prototype,"walletModalStep",2),s([S()],y.prototype,"showOnrampModal",2),s([S()],y.prototype,"onrampSessionId",2),s([S()],y.prototype,"onrampPaymentIntentId",2),s([S()],y.prototype,"onrampErrorMessage",2),s([S()],y.prototype,"oisyReadyToPay",2),s([S()],y.prototype,"oisySignerPreopened",2),s([S()],y.prototype,"skipDisconnectOnce",2),s([S()],y.prototype,"lastWalletId",2),s([S()],y.prototype,"showBalanceModal",2),s([S()],y.prototype,"balancesLoading",2),s([S()],y.prototype,"balancesError",2),s([S()],y.prototype,"walletBalances",2),y=s([It("icpay-pay-button")],y);import{LitElement as Lt,html as Me,css as Nt}from"lit";import{customElement as Ut,property as $t,state as W}from"lit/decorators.js";var Ge=typeof window<"u",Ue=null;function Bt(i,l,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${l}`,e):console.log(`[ICPay Widget] ${l}`))}var w=class extends Lt{constructor(){super(...arguments);this.amountUsd=0;this.hasUserAmount=!1;this.selectedSymbol=null;this.processing=!1;this.succeeded=!1;this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.showOnrampModal=!1;this.onrampSessionId=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.transakMessageHandlerBound=null;this.onrampPollTimer=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.showBalanceModal=!1;this.balancesLoading=!1;this.balancesError=null;this.walletBalances=[];this.sdk=null;this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="pay",this.showWalletModal=!0,this.requestUpdate();try{let t=Number(this.amountUsd||0),n=this.selectedSymbol||"ICP";window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"pay",type:"sendUsd",amount:t,currency:n}}))}catch{}}catch{}};this.onSelectBalanceSymbol=async e=>{let t=(this.walletBalances||[]).find(a=>a?.tokenShortcode===e);if(t?.ledgerSymbol&&(this.selectedSymbol=t.ledgerSymbol),R(this.lastWalletId)){let a=(this.walletBalances||[]).find(o=>o?.tokenShortcode===e),r=a?.chainId;V(r,{chainName:a?.chainName,rpcUrlPublic:a?.rpcUrlPublic,nativeSymbol:a?.ledgerSymbol,decimals:a?.decimals}).then(async()=>{try{let o=g(this.config),c=Number(this.amountUsd||0);if(a?.x402Accepts)try{await o.client.createPaymentX402Usd({usdAmount:c,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,network:"evm",ledgerId:a?.ledgerId,chainId:a?.chainUuid,context:"amount-input:x402"}}),this.showBalanceModal=!1;return}catch{}await o.client.createPaymentUsd({usdAmount:c,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,network:"evm",ledgerId:a?.ledgerId}})}catch{}this.showBalanceModal=!1});return}this.showBalanceModal=!1;let n=this.pendingAction;if(this.pendingAction=null,n==="pay")try{let a=(this.walletBalances||[]).find(c=>c?.tokenShortcode===e),r=g(this.config),o=Number(this.amountUsd||0);await r.client.createPaymentUsd({usdAmount:o,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,network:"ic",ledgerId:a?.ledgerId}})}catch{}}}connectedCallback(){if(super.connectedCallback(),!!Ge){Bt(this.config?.debug||!1,"Amount input connected",{config:this.config}),this.amountUsd=Number(this.config?.defaultAmountUsd??0),this.hasUserAmount=!1;try{window.addEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}try{window.addEventListener("icpay-sdk-transaction-created",(()=>{this.showWalletModal=!1,this.requestUpdate()}))}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.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)}}onInputChange(e){let t=Number(this.config?.stepUsd??.5),n=Math.max(0,Number(e.target.value||0)),a=Math.round(n/t)*t;this.amountUsd=Number(a.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{Ue||(Ue=(await import("./wallet-select-M5KY6N6N.js")).WalletSelect);let e=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab),t={...this.config?.plugNPlay||{}};this.config?.chainTypes&&(t.chainTypes=this.config.chainTypes);let n=e?U(t):t;try{if(typeof window<"u"){let{resolveDerivationOrigin:r}=await import("./origin-44ZEXSX4.js");n.derivationOrigin=this.config?.derivationOrigin||r()}}catch{}if(this.pnp=new Ue(n),!this.pnp.getEnabledWallets()?.length)throw new Error("No wallets available");return this.pendingAction="pay",this.showWalletModal=!0,!1}catch(e){return this.errorMessage=e instanceof Error?e.message:"Wallet connection failed",this.errorSeverity="error",!1}}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");this.lastWalletId=(e||"").toLowerCase(),this.pnp.connect(e).then(n=>{if(!!!(n&&(n.connected===!0||n.principal||n.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}let r=T(this.pnp,n),o=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(d,h)=>this.pnp.getActor({canisterId:d,idl:h,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{}},this.sdk=null,this.lastWalletId==="oisy"?this.oisyReadyToPay=!0:(this.showWalletModal=!1,this.fetchAndShowBalances())}).catch(n=>{this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}})}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}}}async fetchAndShowBalances(){try{this.balancesLoading=!0,this.balancesError=null,this.showBalanceModal=!0;let e=g(this.config),{balances:t}=await Y({sdk:e,lastWalletId:this.lastWalletId,connectedWallet:this.config?.connectedWallet,amountUsd:Number(this.amountUsd??0),chainShortcodes:this.config?.chainShortcodes,tokenShortcodes:this.config?.tokenShortcodes});this.walletBalances=t}catch(e){this.walletBalances=[],this.balancesError=e&&(e.message||String(e))||"Failed to load balances"}finally{this.balancesLoading=!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,n=t?.event_id||t?.eventId||t?.id;if(!(!n||typeof n!="string")&&n==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let a=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(a||void 0)}}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1,setTimeout(()=>this.createOnrampIntent(),0)}async createOnrampIntent(){try{let e=g(this.config),t=this.selectedSymbol||"ICP",n=Number(this.amountUsd),a=await e.startOnrampUsd(n,t,{context:"amount-input:onramp"}),r=a?.metadata?.onramp?.sessionId||a?.metadata?.onramp?.session_id||null,o=a?.metadata?.paymentIntentId||a?.paymentIntentId||null,c=a?.metadata?.onramp?.errorMessage||null;this.onrampPaymentIntentId=o,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 n=g(this.config),a=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>a()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=n.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}async pay(){if(!(!Ge||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||"ICP"}}))}catch{}this.processing=!0;try{if(!await this.ensureWallet())return;this.showWalletModal=!0,await this.fetchAndShowBalances();return}catch(e){P(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),D(t)&&(this.errorMessage=_(t),this.errorSeverity=F(t),this.errorAction=z(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 Me`<div class="icpay-card icpay-section">Loading...</div>`;let e=this.config?.placeholder||"Enter amount in USD",n=(this.config?.buttonLabel||"Pay ${amount} with crypto").replace("{amount}",this.amountUsd?`${Number(this.amountUsd).toFixed(2)}`:"$0.00").replace("{symbol}",this.selectedSymbol||"ICP"),a=this.selectedSymbol||"ICP",o=this.config?.progressBar?.enabled!==!1;return Me`
1451
+ `],s([Lt({type:Object})],y.prototype,"config",2),s([S()],y.prototype,"selectedSymbol",2),s([S()],y.prototype,"processing",2),s([S()],y.prototype,"succeeded",2),s([S()],y.prototype,"errorMessage",2),s([S()],y.prototype,"errorSeverity",2),s([S()],y.prototype,"errorAction",2),s([S()],y.prototype,"walletConnected",2),s([S()],y.prototype,"pendingAction",2),s([S()],y.prototype,"showWalletModal",2),s([S()],y.prototype,"walletModalStep",2),s([S()],y.prototype,"showOnrampModal",2),s([S()],y.prototype,"onrampSessionId",2),s([S()],y.prototype,"onrampPaymentIntentId",2),s([S()],y.prototype,"onrampErrorMessage",2),s([S()],y.prototype,"oisyReadyToPay",2),s([S()],y.prototype,"oisySignerPreopened",2),s([S()],y.prototype,"skipDisconnectOnce",2),s([S()],y.prototype,"lastWalletId",2),s([S()],y.prototype,"showBalanceModal",2),s([S()],y.prototype,"balancesLoading",2),s([S()],y.prototype,"balancesError",2),s([S()],y.prototype,"walletBalances",2),y=s([Ot("icpay-pay-button")],y);import{LitElement as It,html as Me,css as Nt}from"lit";import{customElement as Ut,property as $t,state as W}from"lit/decorators.js";var Ge=typeof window<"u",Ue=null;function Bt(i,l,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${l}`,e):console.log(`[ICPay Widget] ${l}`))}var w=class extends It{constructor(){super(...arguments);this.amountUsd=0;this.hasUserAmount=!1;this.selectedSymbol=null;this.processing=!1;this.succeeded=!1;this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.showOnrampModal=!1;this.onrampSessionId=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.transakMessageHandlerBound=null;this.onrampPollTimer=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.showBalanceModal=!1;this.balancesLoading=!1;this.balancesError=null;this.walletBalances=[];this.sdk=null;this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="pay",this.showWalletModal=!0,this.requestUpdate();try{let t=Number(this.amountUsd||0),n=this.selectedSymbol||"ICP";window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"pay",type:"sendUsd",amount:t,currency:n}}))}catch{}}catch{}};this.onSelectBalanceSymbol=async e=>{let t=(this.walletBalances||[]).find(a=>a?.tokenShortcode===e);if(t?.ledgerSymbol&&(this.selectedSymbol=t.ledgerSymbol),R(this.lastWalletId)){let a=(this.walletBalances||[]).find(o=>o?.tokenShortcode===e),r=a?.chainId;V(r,{provider:this.pnp?.getEvmProvider?.()||this.config?.evmProvider,chainName:a?.chainName,rpcUrlPublic:a?.rpcUrlPublic,nativeSymbol:a?.ledgerSymbol,decimals:a?.decimals}).then(async()=>{try{let o=g(this.config),c=Number(this.amountUsd||0);if(a?.x402Accepts)try{await o.client.createPaymentX402Usd({usdAmount:c,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,icpay_network:"evm",icpay_ledger_id:a?.ledgerId,icpay_context:"amount-input:x402"}}),this.showBalanceModal=!1;return}catch{}await o.client.createPaymentUsd({usdAmount:c,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,icpay_network:"evm",icpay_ledger_id:a?.ledgerId}})}catch{}this.showBalanceModal=!1});return}this.showBalanceModal=!1;let n=this.pendingAction;if(this.pendingAction=null,n==="pay")try{let a=(this.walletBalances||[]).find(c=>c?.tokenShortcode===e),r=g(this.config),o=Number(this.amountUsd||0);await r.client.createPaymentUsd({usdAmount:o,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,icpay_network:"ic",icpay_ledger_id:a?.ledgerId}})}catch{}}}connectedCallback(){if(super.connectedCallback(),!!Ge){Bt(this.config?.debug||!1,"Amount input connected",{config:this.config}),this.amountUsd=Number(this.config?.defaultAmountUsd??0),this.hasUserAmount=!1;try{window.addEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}try{window.addEventListener("icpay-sdk-transaction-created",(()=>{this.showWalletModal=!1,this.requestUpdate()}))}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.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)}}onInputChange(e){let t=Number(this.config?.stepUsd??.5),n=Math.max(0,Number(e.target.value||0)),a=Math.round(n/t)*t;this.amountUsd=Number(a.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{Ue||(Ue=(await import("./wallet-select-YKQSWA6J.js")).WalletSelect);let e=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab),t={...this.config?.plugNPlay||{}};this.config?.chainTypes&&(t.chainTypes=this.config.chainTypes);let n=e?U(t):t;try{if(typeof window<"u"){let{resolveDerivationOrigin:r}=await import("./origin-44ZEXSX4.js");n.derivationOrigin=this.config?.derivationOrigin||r()}}catch{}if(this.pnp=new Ue(n),!this.pnp.getEnabledWallets()?.length)throw new Error("No wallets available");return this.pendingAction="pay",this.showWalletModal=!0,!1}catch(e){return this.errorMessage=e instanceof Error?e.message:"Wallet connection failed",this.errorSeverity="error",!1}}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");this.lastWalletId=(e||"").toLowerCase(),this.pnp.connect(e).then(n=>{if(!!!(n&&(n.connected===!0||n.principal||n.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}let r=T(this.pnp,n),o=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(d,h)=>this.pnp.getActor({canisterId:d,idl:h,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{}},this.sdk=null,this.lastWalletId==="oisy"?this.oisyReadyToPay=!0:(this.showWalletModal=!1,this.fetchAndShowBalances())}).catch(n=>{this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}})}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}}}async fetchAndShowBalances(){try{this.balancesLoading=!0,this.balancesError=null,this.showBalanceModal=!0;let e=g(this.config),{balances:t}=await Y({sdk:e,lastWalletId:this.lastWalletId,connectedWallet:this.config?.connectedWallet,amountUsd:Number(this.amountUsd??0),chainShortcodes:this.config?.chainShortcodes,tokenShortcodes:this.config?.tokenShortcodes});this.walletBalances=t}catch(e){this.walletBalances=[],this.balancesError=e&&(e.message||String(e))||"Failed to load balances"}finally{this.balancesLoading=!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,n=t?.event_id||t?.eventId||t?.id;if(!(!n||typeof n!="string")&&n==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let a=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(a||void 0)}}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1,setTimeout(()=>this.createOnrampIntent(),0)}async createOnrampIntent(){try{let e=g(this.config),t=this.selectedSymbol||"ICP",n=Number(this.amountUsd),a=await e.startOnrampUsd(n,t,{context:"amount-input:onramp"}),r=a?.metadata?.icpay_onramp?.sessionId||a?.metadata?.icpay_onramp?.session_id||a?.metadata?.onramp?.sessionId||a?.metadata?.onramp?.session_id||null,o=a?.metadata?.icpay_payment_intent_id||a?.metadata?.paymentIntentId||a?.paymentIntentId||null,c=a?.metadata?.icpay_onramp?.errorMessage||a?.metadata?.onramp?.errorMessage||null;this.onrampPaymentIntentId=o,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 n=g(this.config),a=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>a()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=n.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}async pay(){if(!(!Ge||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||"ICP"}}))}catch{}this.processing=!0;try{if(!await this.ensureWallet())return;this.showWalletModal=!0,await this.fetchAndShowBalances();return}catch(e){P(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),D(t)&&(this.errorMessage=_(t),this.errorSeverity=F(t),this.errorAction=z(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 Me`<div class="icpay-card icpay-section">Loading...</div>`;let e=this.config?.placeholder||"Enter amount in USD",n=(this.config?.buttonLabel||"Pay ${amount} with crypto").replace("{amount}",this.amountUsd?`${Number(this.amountUsd).toFixed(2)}`:"$0.00").replace("{symbol}",this.selectedSymbol||"ICP"),a=this.selectedSymbol||"ICP",o=this.config?.progressBar?.enabled!==!1;return Me`
1452
1452
  <div class="icpay-card icpay-section icpay-widget-base">
1453
1453
  ${o?Me`
1454
1454
  <icpay-progress-bar
@@ -1507,5 +1507,5 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var H=Xe`
1507
1507
  @media (max-width: 520px) {
1508
1508
  .top-row { grid-template-columns: 1fr; }
1509
1509
  }
1510
- `],s([$t({type:Object})],w.prototype,"config",2),s([W()],w.prototype,"amountUsd",2),s([W()],w.prototype,"hasUserAmount",2),s([W()],w.prototype,"selectedSymbol",2),s([W()],w.prototype,"processing",2),s([W()],w.prototype,"succeeded",2),s([W()],w.prototype,"errorMessage",2),s([W()],w.prototype,"errorSeverity",2),s([W()],w.prototype,"errorAction",2),s([W()],w.prototype,"walletConnected",2),s([W()],w.prototype,"pendingAction",2),s([W()],w.prototype,"showWalletModal",2),s([W()],w.prototype,"showOnrampModal",2),s([W()],w.prototype,"onrampSessionId",2),s([W()],w.prototype,"onrampPaymentIntentId",2),s([W()],w.prototype,"onrampErrorMessage",2),s([W()],w.prototype,"oisyReadyToPay",2),s([W()],w.prototype,"lastWalletId",2),s([W()],w.prototype,"showBalanceModal",2),s([W()],w.prototype,"balancesLoading",2),s([W()],w.prototype,"balancesError",2),s([W()],w.prototype,"walletBalances",2),w=s([Ut("icpay-amount-input")],w);export{H as a,Ie as b,g as c,q as d,E as e,v as f,u as g,x as h,b as i,y as j,w as k};
1511
- //# sourceMappingURL=chunk-OCJP7SJM.js.map
1510
+ `],s([$t({type:Object})],w.prototype,"config",2),s([W()],w.prototype,"amountUsd",2),s([W()],w.prototype,"hasUserAmount",2),s([W()],w.prototype,"selectedSymbol",2),s([W()],w.prototype,"processing",2),s([W()],w.prototype,"succeeded",2),s([W()],w.prototype,"errorMessage",2),s([W()],w.prototype,"errorSeverity",2),s([W()],w.prototype,"errorAction",2),s([W()],w.prototype,"walletConnected",2),s([W()],w.prototype,"pendingAction",2),s([W()],w.prototype,"showWalletModal",2),s([W()],w.prototype,"showOnrampModal",2),s([W()],w.prototype,"onrampSessionId",2),s([W()],w.prototype,"onrampPaymentIntentId",2),s([W()],w.prototype,"onrampErrorMessage",2),s([W()],w.prototype,"oisyReadyToPay",2),s([W()],w.prototype,"lastWalletId",2),s([W()],w.prototype,"showBalanceModal",2),s([W()],w.prototype,"balancesLoading",2),s([W()],w.prototype,"balancesError",2),s([W()],w.prototype,"walletBalances",2),w=s([Ut("icpay-amount-input")],w);export{H as a,Oe as b,g as c,q as d,E as e,v as f,u as g,x as h,b as i,y as j,w as k};
1511
+ //# sourceMappingURL=chunk-YO43OKCJ.js.map