@ic-pay/icpay-widget 0.1.77 → 0.1.78

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.
@@ -4939,7 +4939,7 @@ Make sure to test your application with a production build as repeat registratio
4939
4939
  0%, 100% { opacity: 1; }
4940
4940
  50% { opacity: 0.7; }
4941
4941
  }
4942
- `;function Ef(r,e){if(!r||!e)return;let t=e.primaryColor||void 0,n=e.secondaryColor||void 0,i=(y,A)=>{A&&r.style.setProperty(y,A)};i("--icpay-primary",t),i("--icpay-secondary",n);let s=y=>{if(!y)return null;let A=y.replace("#",""),T=A.length===3?A.split("").map(D=>D+D).join(""):A,O=parseInt(T,16),k=O>>16&255,j=O>>8&255,z=O&255;return{r:k,g:j,b:z}},c=(y=>{let A=s(y);if(!A)return 0;let T=O=>{let k=O/255;return k<=.03928?k/12.92:Math.pow((k+.055)/1.055,2.4)};return .2126*T(A.r)+.7152*T(A.g)+.0722*T(A.b)})(t||n)>.6,l=e.surfaceColor||(c?"#f3f4f6":"#1f2937"),u=e.surfaceAltColor||(c?"#e5e7eb":"#374151"),d=e.borderColor||(c?"#d1d5db":"#4b5563"),f=e.textColor||(c?"#111827":"#f9fafb"),m=e.accentColor||n||t||(c?"#6b7280":"#9ca3af"),g=e.mutedTextColor||(c?"#6b7280":"#9ca3af");i("--icpay-accent",m),i("--icpay-text",f),i("--icpay-muted",g),i("--icpay-surface",l),i("--icpay-surface-alt",u),i("--icpay-border",d)}var hS=vc(dS(),1),Hq=typeof window<"u";function v5(r,e,t){r&&(t!==void 0?console.log(`[ICPay Widget] ${e}`,t):console.log(`[ICPay Widget] ${e}`))}function Ln(r){if(!Hq)return{client:{},quoteUsd:async()=>({tokenAmountDecimals:"0"}),sendUsd:async()=>({transactionId:"0",status:"pending"})};v5(r.debug||!1,"Creating SDK with config:",r);let e={publishableKey:r.publishableKey};r.enableEvents!==void 0?e.enableEvents=r.enableEvents:e.enableEvents=!0,r.apiUrl&&(e.apiUrl=r.apiUrl),r.icHost&&(e.icHost=r.icHost),r.actorProvider&&(e.actorProvider=r.actorProvider),r.connectedWallet&&(e.connectedWallet=r.connectedWallet),r.debug!==void 0&&(e.debug=r.debug),v5(r.debug||!1,"Filtered SDK config:",e);try{v5(r.debug||!1,"typeof Icpay:",typeof hS.Icpay);let t=new hS.Icpay(e);if(Hq){let s=t,o=a=>{s.addEventListener(a,c=>{window.dispatchEvent(new CustomEvent(a,{detail:c?.detail??c}))})};["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(o)}async function n(s,o){return t.calculateTokenAmountFromUSD({usdAmount:s,ledgerCanisterId:o})}async function i(s,o,a){return t.sendFundsUsd({usdAmount:s,ledgerCanisterId:o,metadata:a})}return{client:t,quoteUsd:n,sendUsd:i}}catch(t){throw v5(r.debug||!1,"Error creating SDK:",t),t}}var Ui=r=>(e,t)=>{t!==void 0?t.addInitializer((()=>{customElements.define(r,e)})):customElements.define(r,e)};var Hpe={attribute:!0,type:String,converter:Bw,reflect:!1,hasChanged:lA},$pe=(r=Hpe,e,t)=>{let{kind:n,metadata:i}=t,s=globalThis.litPropertyMetadata.get(i);if(s===void 0&&globalThis.litPropertyMetadata.set(i,s=new Map),n==="setter"&&((r=Object.create(r)).wrapped=!0),s.set(t.name,r),n==="accessor"){let{name:o}=t;return{set(a){let c=e.get.call(this);e.set.call(this,a),this.requestUpdate(o,c,r)},init(a){return a!==void 0&&this.C(o,void 0,r,a),a}}}if(n==="setter"){let{name:o}=t;return function(a){let c=this[o];e.call(this,a),this.requestUpdate(o,c,r)}}throw Error("Unsupported decorator location: "+n)};function ur(r){return(e,t)=>typeof t=="object"?$pe(r,e,t):((n,i,s)=>{let o=i.hasOwnProperty(s);return i.constructor.createProperty(s,n),o?Object.getOwnPropertyDescriptor(i,s):void 0})(r,e,t)}function Re(r){return ur({...r,state:!0,attribute:!1})}var fS=vc(dS(),1),lo={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"},Wpe={onError:r=>{console.error("[ICPay Widget] Error:",r)},onUserCancelled:()=>{console.log("[ICPay Widget] User cancelled the action")},onInsufficientBalance:r=>{console.warn("[ICPay Widget] Insufficient balance:",r.message)},onWalletError:r=>{console.warn("[ICPay Widget] Wallet error:",r.message)},onNetworkError:r=>{console.error("[ICPay Widget] Network error:",r.message)}};function Bo(r,e=Wpe){r instanceof fS.IcpayError?(e.onError(r),r.isUserCancelled()?e.onUserCancelled?.():r.isBalanceError()?e.onInsufficientBalance?.(r):r.isWalletError()?e.onWalletError?.(r):r.isNetworkError()&&e.onNetworkError?.(r)):(console.error("[ICPay Widget] Unknown error:",r),e.onError(new fS.IcpayError({code:lo.UNKNOWN_ERROR,message:r instanceof Error?r.message:"An unknown error occurred",details:r})))}var Vpe={[lo.WALLET_NOT_CONNECTED]:"Please connect your wallet to continue",[lo.WALLET_USER_CANCELLED]:"User have rejected the transfer",[lo.WALLET_SIGNATURE_REJECTED]:"User have rejected the transfer",[lo.INSUFFICIENT_BALANCE]:"Insufficient balance for this transaction",[lo.NETWORK_ERROR]:"Network error. Please try again",[lo.API_ERROR]:"Service temporarily unavailable",[lo.LEDGER_NOT_FOUND]:"Selected token is not supported",[lo.TRANSACTION_FAILED]:"Transaction failed. Please try again",[lo.TRANSACTION_TIMEOUT]:"Transaction timed out. Please try again",[lo.UNKNOWN_ERROR]:"Something went wrong. Please try again"};function Po(r){return Vpe[r.code]||r.message||"An error occurred"}function Mo(r){return!r.isUserCancelled()}function Ro(r){if(r.userAction)return r.userAction;switch(r.code){case lo.WALLET_NOT_CONNECTED:return"Connect Wallet";case lo.INSUFFICIENT_BALANCE:return"Add Funds";case lo.NETWORK_ERROR:case lo.API_ERROR:return"Try Again";default:return null}}function ko(r){return r.isUserCancelled()?"info":r.isBalanceError()||r.isWalletError()?"warning":"error"}var Kpe=[{key:"init",label:"Initialising icpay SDK",tooltip:"Initializing payment",status:"pending"},{key:"await",label:"Awaiting payment confirmation",tooltip:"Preparing payment",status:"pending"},{key:"transfer",label:"Transferring funds",tooltip:"Submitting payment",status:"pending"},{key:"verify",label:"Verifying payment",tooltip:"Confirming payment",status:"pending"},{key:"confirm",label:"Payment confirmed",tooltip:"Payment completed",status:"pending"}],Kn=class extends mn{constructor(){super(...arguments);this.open=!1;this.steps=Kpe;this.amount=0;this.currency="";this.ledgerSymbol="";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.progressionTimer=null;this.onMethodStart=t=>{let n=t?.detail?.name||"",i=t?.detail?.type||"";console.log("ICPay Progress: Method start event received:",t.detail),(n==="sendFunds"||n==="sendFundsUsd"||n==="sendUsd"||n==="pay"||n==="unlock"||n==="tip"||n==="donate"||n==="order")&&(this.open=!0,this.activeIndex=0,this.completed=!1,this.failed=!1,this.errorMessage=null,this.showSuccess=!1,this.showConfetti=!1,this.currentSteps=this.currentSteps.map(s=>({...s,status:"pending"})),this.updateStepStatus(0,"loading"),t?.detail?.amount!==void 0&&(this.currentAmount=t.detail.amount,this.amount=t.detail.amount,console.log("ICPay Progress: Amount updated to:",t.detail.amount)),t?.detail?.currency&&(this.currentCurrency=t.detail.currency,this.currency=t.detail.currency,console.log("ICPay Progress: Currency updated to:",t.detail.currency)),t?.detail?.ledgerSymbol&&(this.currentLedgerSymbol=t.detail.ledgerSymbol,this.ledgerSymbol=t.detail.ledgerSymbol,console.log("ICPay Progress: Current state after method start:",{activeIndex:this.activeIndex,currentAmount:this.currentAmount,currentCurrency:this.currentCurrency,currentLedgerSymbol:this.currentLedgerSymbol})),console.log("ICPay Progress: Waiting for wallet confirmation before starting progression"),this.requestUpdate())};this.onMethodSuccess=t=>{let n=t?.detail?.name||"";(n==="sendFunds"||n==="sendFundsUsd"||n==="sendUsd"||n==="pay"||n==="unlock"||n==="tip"||n==="donate"||n==="order")&&this.dispatchEvent(new CustomEvent("icpay-progress-method-success",{detail:{methodName:n,step:this.activeIndex},bubbles:!0}))};this.onTransactionCreated=t=>{let n=t?.detail?.transactionId||t?.detail?.id;console.log("ICPay Progress: Transaction created event received:",t.detail),this.dispatchEvent(new CustomEvent("icpay-progress-transaction-created",{detail:{transactionId:n,step:this.activeIndex},bubbles:!0}))};this.onTransactionUpdated=t=>{let n=t?.detail?.status||"pending",i=t?.detail?.transactionId||t?.detail?.id;console.log("ICPay Progress: Transaction updated event received:",t.detail),this.dispatchEvent(new CustomEvent("icpay-progress-transaction-updated",{detail:{status:n,transactionId:i,step:this.activeIndex},bubbles:!0}))};this.onTransactionCompleted=t=>{let n=t?.detail?.transactionId||t?.detail?.id,i=t?.detail?.status||"completed";console.log("ICPay Progress: Transaction completed event received:",t.detail),console.log("ICPay Progress: Current state when transaction completed:",{activeIndex:this.activeIndex,completed:this.completed,failed:this.failed,showSuccess:this.showSuccess}),this.stopAutomaticProgression();for(let s=this.activeIndex;s<this.currentSteps.length;s++)this.updateStepStatus(s,"completed");this.activeIndex=this.currentSteps.length-1,this.completed=!0,this.showSuccess=!0,this.showConfetti=!0,this.dispatchEvent(new CustomEvent("icpay-progress-completed",{detail:{transactionId:n,status:i,amount:this.currentAmount||this.amount,currency:this.currentCurrency||this.currency,ledgerSymbol:this.currentLedgerSymbol||this.ledgerSymbol},bubbles:!0})),setTimeout(()=>{this.open&&this.showSuccess&&!this.failed&&(this.open=!1)},2e3),setTimeout(()=>{this.showConfetti=!1},3e3)};this.onTransactionFailed=t=>{let n=t?.detail?.message||t?.detail?.error?.message||"Transaction failed",i=t?.detail?.error?.code||t?.detail?.code||"UNKNOWN_ERROR",s=t?.detail?.transactionId||t?.detail?.id;console.log("ICPay Progress: Transaction failed event received:",t.detail),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-failed",{detail:{errorMessage:n,errorCode:i,transactionId:s,step:this.activeIndex},bubbles:!0}))};this.onMethodError=t=>{let n=t?.detail?.name||"",i=t?.detail?.error?.message||t?.detail?.message||"An error occurred",s=t?.detail?.error?.code||t?.detail?.code||"METHOD_ERROR";console.log("ICPay Progress: Method error event received:",t.detail),(n?.startsWith("sendFunds")||n==="sendUsd"||n==="pay"||n==="unlock"||n==="tip"||n==="donate"||n==="order")&&(this.failed=!0,this.errorMessage=this.transformErrorMessage(i),this.showSuccess=!1,this.updateStepStatus(this.activeIndex,"error",i),this.stopAutomaticProgression(),this.open=!0,this.dispatchEvent(new CustomEvent("icpay-progress-error",{detail:{methodName:n,errorMessage:i,errorCode:s,step:this.activeIndex},bubbles:!0})))};this.onSDKError=t=>{let n=t?.detail?.message||"SDK error occurred",i=t?.detail?.code||"SDK_ERROR";console.log("ICPay Progress: SDK error event received:",t.detail),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-sdk-error",{detail:{errorMessage:n,errorCode:i,step:this.activeIndex},bubbles:!0}))};this.onWalletConnected=t=>{let n=t?.detail?.walletType||"unknown";console.log("ICPay Progress: Wallet connected event received:",t.detail),this.updateStepStatus(0,"completed"),this.startAutomaticProgression(),this.dispatchEvent(new CustomEvent("icpay-progress-wallet-connected",{detail:{walletType:n,step:this.activeIndex},bubbles:!0}))};this.onWalletDisconnected=t=>{let n=t?.detail?.walletType||"unknown";console.log("ICPay Progress: Wallet disconnected event received:",t.detail),this.dispatchEvent(new CustomEvent("icpay-progress-wallet-disconnected",{detail:{walletType:n,step:this.activeIndex},bubbles:!0}))};this.onBalanceCheck=t=>{let n=t?.detail?.hasBalance||!1,i=t?.detail?.balance||0;console.log("ICPay Progress: Balance check event received:",t.detail),n||(this.failed=!0,this.errorMessage="Insufficient balance for transaction",this.updateStepStatus(this.activeIndex,"error","Insufficient balance for transaction"),this.stopAutomaticProgression(),this.dispatchEvent(new CustomEvent("icpay-progress-insufficient-balance",{detail:{balance:i,required:this.currentAmount||this.amount,step:this.activeIndex},bubbles:!0})))};this.onLedgerVerified=t=>{let n=t?.detail?.ledgerId||t?.detail?.canisterId,i=t?.detail?.symbol||"unknown";console.log("ICPay Progress: Ledger verified event received:",t.detail),i&&i!=="unknown"&&(this.currentLedgerSymbol=i,this.ledgerSymbol=i),this.dispatchEvent(new CustomEvent("icpay-progress-ledger-verified",{detail:{ledgerId:n,symbol:i,step:this.activeIndex},bubbles:!0}))};this.onWidgetPayment=t=>{let n=t?.detail?.amount,i=t?.detail?.currency,s=t?.detail?.ledgerSymbol;console.log("ICPay Progress: Widget payment event received:",t.detail),n!==void 0&&(this.currentAmount=n,this.amount=n),i&&(this.currentCurrency=i,this.currency=i),s&&(this.currentLedgerSymbol=s,this.ledgerSymbol=s),this.dispatchEvent(new CustomEvent("icpay-progress-widget-payment",{detail:{amount:n,currency:i,ledgerSymbol:s,step:this.activeIndex},bubbles:!0}))};this.onWidgetError=t=>{let n=t?.detail?.message||"Widget error occurred",i=t?.detail?.code||"WIDGET_ERROR";console.log("ICPay Progress: Widget error event received:",t.detail),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-widget-error",{detail:{errorMessage:n,errorCode:i,step:this.activeIndex},bubbles:!0}))};this.onWidgetUnlock=t=>{let n=t?.detail?.amount,i=t?.detail?.currency;console.log("ICPay Progress: Widget unlock event received:",t.detail),this.dispatchEvent(new CustomEvent("icpay-progress-widget-unlock",{detail:{amount:n,currency:i,step:this.activeIndex},bubbles:!0}))};this.onWidgetTip=t=>{let n=t?.detail?.amount,i=t?.detail?.currency;console.log("ICPay Progress: Widget tip event received:",t.detail),this.dispatchEvent(new CustomEvent("icpay-progress-widget-tip",{detail:{amount:n,currency:i,step:this.activeIndex},bubbles:!0}))};this.onWidgetDonation=t=>{let n=t?.detail?.amount,i=t?.detail?.currency;console.log("ICPay Progress: Widget donation event received:",t.detail),this.dispatchEvent(new CustomEvent("icpay-progress-widget-donation",{detail:{amount:n,currency:i,step:this.activeIndex},bubbles:!0}))};this.onWidgetCoffee=t=>{let n=t?.detail?.amount,i=t?.detail?.currency;console.log("ICPay Progress: Widget coffee event received:",t.detail),this.dispatchEvent(new CustomEvent("icpay-progress-widget-coffee",{detail:{amount:n,currency:i,step:this.activeIndex},bubbles:!0}))}}connectedCallback(){super.connectedCallback();try{Ef(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(t){if(t.has("theme"))try{Ef(this,this.theme)}catch{}}attachSDKEventListeners(){window.addEventListener("icpay-sdk-method-start",this.onMethodStart),window.addEventListener("icpay-sdk-method-success",this.onMethodSuccess),window.addEventListener("icpay-sdk-method-error",this.onMethodError),window.addEventListener("icpay-sdk-transaction-created",this.onTransactionCreated),window.addEventListener("icpay-sdk-transaction-updated",this.onTransactionUpdated),window.addEventListener("icpay-sdk-transaction-completed",this.onTransactionCompleted),window.addEventListener("icpay-sdk-transaction-failed",this.onTransactionFailed),window.addEventListener("icpay-sdk-error",this.onSDKError),window.addEventListener("icpay-sdk-wallet-connected",this.onWalletConnected),window.addEventListener("icpay-sdk-wallet-disconnected",this.onWalletDisconnected),window.addEventListener("icpay-sdk-balance-check",this.onBalanceCheck),window.addEventListener("icpay-sdk-ledger-verified",this.onLedgerVerified),window.addEventListener("icpay-pay",this.onWidgetPayment),window.addEventListener("icpay-error",this.onWidgetError),window.addEventListener("icpay-unlock",this.onWidgetUnlock),window.addEventListener("icpay-tip",this.onWidgetTip),window.addEventListener("icpay-donation",this.onWidgetDonation),window.addEventListener("icpay-coffee",this.onWidgetCoffee)}detachSDKEventListeners(){window.removeEventListener("icpay-sdk-method-start",this.onMethodStart),window.removeEventListener("icpay-sdk-method-success",this.onMethodSuccess),window.removeEventListener("icpay-sdk-method-error",this.onMethodError),window.removeEventListener("icpay-sdk-transaction-created",this.onTransactionCreated),window.removeEventListener("icpay-sdk-transaction-updated",this.onTransactionUpdated),window.removeEventListener("icpay-sdk-transaction-completed",this.onTransactionCompleted),window.removeEventListener("icpay-sdk-transaction-failed",this.onTransactionFailed),window.removeEventListener("icpay-sdk-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"),console.log("ICPay Progress: Starting automatic progression from step:",this.activeIndex),this.progressionTimer=setInterval(()=>{if(this.failed||this.completed){this.stopAutomaticProgression();return}console.log("ICPay Progress: Processing step:",this.activeIndex),this.updateStepStatus(this.activeIndex,"completed"),this.activeIndex<this.currentSteps.length-1?(this.activeIndex++,this.updateStepStatus(this.activeIndex,"loading"),console.log("ICPay Progress: Auto-progressed to step:",this.activeIndex)):(this.stopAutomaticProgression(),console.log("ICPay Progress: All steps completed, waiting for transaction completion")),this.requestUpdate()},3e3)}stopAutomaticProgression(){this.progressionTimer&&(clearInterval(this.progressionTimer),this.progressionTimer=null)}updateStepStatus(t,n,i){if(t>=0&&t<this.currentSteps.length){let s=this.currentSteps[t],o=s.status;s.status=n,n==="completed"&&(s.timestamp=this.getCurrentTime()),n==="error"&&i&&(s.errorMessage=this.transformErrorMessage(i)),console.log(`ICPay Progress: Step ${t} (${s.label}) status changed from ${o} to ${n}`),this.requestUpdate()}}getCurrentTime(){return new Date().toLocaleTimeString("en-US",{hour12:!1,hour:"2-digit",minute:"2-digit",second:"2-digit"})}progressPercent(){if(this.failed)return 0;if(this.showSuccess)return 100;let n=this.currentSteps.filter(i=>i.status==="completed").length/this.currentSteps.length*100;return Math.max(0,Math.min(100,n))}verticalPercent(){if(this.failed)return 0;if(this.showSuccess)return 100;let n=this.currentSteps.filter(i=>i.status==="completed").length/this.currentSteps.length*100;return Math.max(0,Math.min(100,n))}getStepIcon(t){switch(t.status){case"loading":return ke`<div class="spinner"></div>`;case"completed":return"\u2713";case"error":return"\u2717";default:return"\u25CB"}}transformErrorMessage(t){let n=String(t||"").toLowerCase();return n.includes("user rejected")||n.includes("user cancelled")||n.includes("user canceled")||n.includes("signature rejected")?"User have rejected the transfer":t}renderConfetti(){if(!this.showConfetti)return"";let t=Array.from({length:50},(i,s)=>s),n=["#0066FF","#ef4444","#10b981","#f59e0b","#8b5cf6"];return ke`
4942
+ `;function Ef(r,e){if(!r||!e)return;let t=e.primaryColor||void 0,n=e.secondaryColor||void 0,i=(y,A)=>{A&&r.style.setProperty(y,A)};i("--icpay-primary",t),i("--icpay-secondary",n);let s=y=>{if(!y)return null;let A=y.replace("#",""),T=A.length===3?A.split("").map(D=>D+D).join(""):A,O=parseInt(T,16),k=O>>16&255,j=O>>8&255,z=O&255;return{r:k,g:j,b:z}},c=(y=>{let A=s(y);if(!A)return 0;let T=O=>{let k=O/255;return k<=.03928?k/12.92:Math.pow((k+.055)/1.055,2.4)};return .2126*T(A.r)+.7152*T(A.g)+.0722*T(A.b)})(t||n)>.6,l=e.surfaceColor||(c?"#f3f4f6":"#1f2937"),u=e.surfaceAltColor||(c?"#e5e7eb":"#374151"),d=e.borderColor||(c?"#d1d5db":"#4b5563"),f=e.textColor||(c?"#111827":"#f9fafb"),m=e.accentColor||n||t||(c?"#6b7280":"#9ca3af"),g=e.mutedTextColor||(c?"#6b7280":"#9ca3af");i("--icpay-accent",m),i("--icpay-text",f),i("--icpay-muted",g),i("--icpay-surface",l),i("--icpay-surface-alt",u),i("--icpay-border",d)}var hS=vc(dS(),1),Hq=typeof window<"u";function v5(r,e,t){r&&(t!==void 0?console.log(`[ICPay Widget] ${e}`,t):console.log(`[ICPay Widget] ${e}`))}function Ln(r){if(!Hq)return{client:{},quoteUsd:async()=>({tokenAmountDecimals:"0"}),sendUsd:async()=>({transactionId:"0",status:"pending"})};v5(r.debug||!1,"Creating SDK with config:",r);let e={publishableKey:r.publishableKey};r.enableEvents!==void 0?e.enableEvents=r.enableEvents:e.enableEvents=!0,r.apiUrl&&(e.apiUrl=r.apiUrl),r.icHost&&(e.icHost=r.icHost),r.actorProvider&&(e.actorProvider=r.actorProvider),r.connectedWallet&&(e.connectedWallet=r.connectedWallet),r.debug!==void 0&&(e.debug=r.debug),v5(r.debug||!1,"Filtered SDK config:",e);try{v5(r.debug||!1,"typeof Icpay:",typeof hS.Icpay);let t=new hS.Icpay(e);if(Hq){let s=t,o=a=>{s.addEventListener(a,c=>{window.dispatchEvent(new CustomEvent(a,{detail:c?.detail??c}))})};["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(o)}async function n(s,o){return t.calculateTokenAmountFromUSD({usdAmount:s,ledgerCanisterId:o})}async function i(s,o,a){return t.sendFundsUsd({usdAmount:s,ledgerCanisterId:o,metadata:a})}return{client:t,quoteUsd:n,sendUsd:i}}catch(t){throw v5(r.debug||!1,"Error creating SDK:",t),t}}var Ui=r=>(e,t)=>{t!==void 0?t.addInitializer((()=>{customElements.define(r,e)})):customElements.define(r,e)};var Hpe={attribute:!0,type:String,converter:Bw,reflect:!1,hasChanged:lA},$pe=(r=Hpe,e,t)=>{let{kind:n,metadata:i}=t,s=globalThis.litPropertyMetadata.get(i);if(s===void 0&&globalThis.litPropertyMetadata.set(i,s=new Map),n==="setter"&&((r=Object.create(r)).wrapped=!0),s.set(t.name,r),n==="accessor"){let{name:o}=t;return{set(a){let c=e.get.call(this);e.set.call(this,a),this.requestUpdate(o,c,r)},init(a){return a!==void 0&&this.C(o,void 0,r,a),a}}}if(n==="setter"){let{name:o}=t;return function(a){let c=this[o];e.call(this,a),this.requestUpdate(o,c,r)}}throw Error("Unsupported decorator location: "+n)};function ur(r){return(e,t)=>typeof t=="object"?$pe(r,e,t):((n,i,s)=>{let o=i.hasOwnProperty(s);return i.constructor.createProperty(s,n),o?Object.getOwnPropertyDescriptor(i,s):void 0})(r,e,t)}function Re(r){return ur({...r,state:!0,attribute:!1})}var fS=vc(dS(),1),lo={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"},Wpe={onError:r=>{console.error("[ICPay Widget] Error:",r)},onUserCancelled:()=>{console.log("[ICPay Widget] User cancelled the action")},onInsufficientBalance:r=>{console.warn("[ICPay Widget] Insufficient balance:",r.message)},onWalletError:r=>{console.warn("[ICPay Widget] Wallet error:",r.message)},onNetworkError:r=>{console.error("[ICPay Widget] Network error:",r.message)}};function Bo(r,e=Wpe){r instanceof fS.IcpayError?(e.onError(r),r.isUserCancelled()?e.onUserCancelled?.():r.isBalanceError()?e.onInsufficientBalance?.(r):r.isWalletError()?e.onWalletError?.(r):r.isNetworkError()&&e.onNetworkError?.(r)):(console.error("[ICPay Widget] Unknown error:",r),e.onError(new fS.IcpayError({code:lo.UNKNOWN_ERROR,message:r instanceof Error?r.message:"An unknown error occurred",details:r})))}var Vpe={[lo.WALLET_NOT_CONNECTED]:"Please connect your wallet to continue",[lo.WALLET_USER_CANCELLED]:"User have rejected the transfer",[lo.WALLET_SIGNATURE_REJECTED]:"User have rejected the transfer",[lo.INSUFFICIENT_BALANCE]:"Insufficient balance for this transaction",[lo.NETWORK_ERROR]:"Network error. Please try again",[lo.API_ERROR]:"Service temporarily unavailable",[lo.LEDGER_NOT_FOUND]:"Selected token is not supported",[lo.TRANSACTION_FAILED]:"Transaction failed. Please try again",[lo.TRANSACTION_TIMEOUT]:"Transaction timed out. Please try again",[lo.UNKNOWN_ERROR]:"Something went wrong. Please try again"};function Po(r){return Vpe[r.code]||r.message||"An error occurred"}function Mo(r){return!r.isUserCancelled()}function Ro(r){if(r.userAction)return r.userAction;switch(r.code){case lo.WALLET_NOT_CONNECTED:return"Connect Wallet";case lo.INSUFFICIENT_BALANCE:return"Add Funds";case lo.NETWORK_ERROR:case lo.API_ERROR:return"Try Again";default:return null}}function ko(r){return r.isUserCancelled()?"info":r.isBalanceError()||r.isWalletError()?"warning":"error"}var Kpe=[{key:"wallet",label:"Connect Wallet",tooltip:"Awaiting wallet connection",status:"pending"},{key:"init",label:"Initialising ICPay",tooltip:"Initializing payment",status:"pending"},{key:"await",label:"Awaiting payment confirmation",tooltip:"Preparing payment",status:"pending"},{key:"transfer",label:"Transferring funds",tooltip:"Submitting payment",status:"pending"},{key:"verify",label:"Verifying payment",tooltip:"Confirming payment",status:"pending"},{key:"confirm",label:"Payment confirmed",tooltip:"Payment completed",status:"pending"}],Kn=class extends mn{constructor(){super(...arguments);this.open=!1;this.steps=Kpe;this.amount=0;this.currency="";this.ledgerSymbol="";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.progressionTimer=null;this.onMethodStart=t=>{let n=t?.detail?.name||"",i=t?.detail?.type||"";console.log("ICPay Progress: Method start event received:",t.detail),(n==="sendFunds"||n==="sendFundsUsd"||n==="sendUsd"||n==="pay"||n==="unlock"||n==="tip"||n==="donate"||n==="order")&&(this.open=!0,this.activeIndex=0,this.completed=!1,this.failed=!1,this.errorMessage=null,this.showSuccess=!1,this.showConfetti=!1,this.currentSteps=this.currentSteps.map(s=>({...s,status:"pending"})),this.updateStepStatus(0,"loading"),t?.detail?.amount!==void 0&&(this.currentAmount=t.detail.amount,this.amount=t.detail.amount,console.log("ICPay Progress: Amount updated to:",t.detail.amount)),t?.detail?.currency&&(this.currentCurrency=t.detail.currency,this.currency=t.detail.currency,console.log("ICPay Progress: Currency updated to:",t.detail.currency)),t?.detail?.ledgerSymbol&&(this.currentLedgerSymbol=t.detail.ledgerSymbol,this.ledgerSymbol=t.detail.ledgerSymbol,console.log("ICPay Progress: Current state after method start:",{activeIndex:this.activeIndex,currentAmount:this.currentAmount,currentCurrency:this.currentCurrency,currentLedgerSymbol:this.currentLedgerSymbol})),console.log("ICPay Progress: Waiting for wallet confirmation before starting progression"),this.requestUpdate())};this.onMethodSuccess=t=>{let n=t?.detail?.name||"";(n==="sendFunds"||n==="sendFundsUsd"||n==="sendUsd"||n==="pay"||n==="unlock"||n==="tip"||n==="donate"||n==="order")&&(this.dispatchEvent(new CustomEvent("icpay-progress-method-success",{detail:{methodName:n,step:this.activeIndex},bubbles:!0})),!this.failed&&!this.completed&&this.currentSteps[this.activeIndex]?.status==="loading"&&(this.updateStepStatus(this.activeIndex,"completed"),this.activeIndex<this.currentSteps.length-1&&(this.activeIndex++,this.updateStepStatus(this.activeIndex,"loading"))))};this.onTransactionCreated=t=>{let n=t?.detail?.transactionId||t?.detail?.id;console.log("ICPay Progress: Transaction created event received:",t.detail),!this.failed&&!this.completed&&this.activeIndex<this.currentSteps.length-1&&(this.updateStepStatus(this.activeIndex,"completed"),this.activeIndex++,this.updateStepStatus(this.activeIndex,"loading")),this.dispatchEvent(new CustomEvent("icpay-progress-transaction-created",{detail:{transactionId:n,step:this.activeIndex},bubbles:!0}))};this.onTransactionUpdated=t=>{let n=t?.detail?.status||"pending",i=t?.detail?.transactionId||t?.detail?.id;console.log("ICPay Progress: Transaction updated event received:",t.detail),!this.failed&&this.completed,this.dispatchEvent(new CustomEvent("icpay-progress-transaction-updated",{detail:{status:n,transactionId:i,step:this.activeIndex},bubbles:!0}))};this.onTransactionCompleted=t=>{let n=t?.detail?.transactionId||t?.detail?.id,i=t?.detail?.status||"completed";console.log("ICPay Progress: Transaction completed event received:",t.detail),console.log("ICPay Progress: Current state when transaction completed:",{activeIndex:this.activeIndex,completed:this.completed,failed:this.failed,showSuccess:this.showSuccess}),this.stopAutomaticProgression();for(let s=this.activeIndex;s<this.currentSteps.length;s++)this.updateStepStatus(s,"completed");this.activeIndex=this.currentSteps.length-1,this.completed=!0,this.showSuccess=!0,this.showConfetti=!0,this.dispatchEvent(new CustomEvent("icpay-progress-completed",{detail:{transactionId:n,status:i,amount:this.currentAmount||this.amount,currency:this.currentCurrency||this.currency,ledgerSymbol:this.currentLedgerSymbol||this.ledgerSymbol},bubbles:!0})),setTimeout(()=>{this.open&&this.showSuccess&&!this.failed&&(this.open=!1)},2e3),setTimeout(()=>{this.showConfetti=!1},3e3)};this.onTransactionFailed=t=>{let n=t?.detail?.message||t?.detail?.error?.message||"Transaction failed",i=t?.detail?.error?.code||t?.detail?.code||"UNKNOWN_ERROR",s=t?.detail?.transactionId||t?.detail?.id;console.log("ICPay Progress: Transaction failed event received:",t.detail),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-failed",{detail:{errorMessage:n,errorCode:i,transactionId:s,step:this.activeIndex},bubbles:!0}))};this.onMethodError=t=>{let n=t?.detail?.name||"",i=t?.detail?.error?.message||t?.detail?.message||"An error occurred",s=t?.detail?.error?.code||t?.detail?.code||"METHOD_ERROR";console.log("ICPay Progress: Method error event received:",t.detail),(n?.startsWith("sendFunds")||n==="sendUsd"||n==="pay"||n==="unlock"||n==="tip"||n==="donate"||n==="order")&&(this.failed=!0,this.errorMessage=this.transformErrorMessage(i),this.showSuccess=!1,this.updateStepStatus(this.activeIndex,"error",i),this.stopAutomaticProgression(),this.open=!0,this.dispatchEvent(new CustomEvent("icpay-progress-error",{detail:{methodName:n,errorMessage:i,errorCode:s,step:this.activeIndex},bubbles:!0})))};this.onSDKError=t=>{let n=t?.detail?.message||"SDK error occurred",i=t?.detail?.code||"SDK_ERROR";console.log("ICPay Progress: SDK error event received:",t.detail),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-sdk-error",{detail:{errorMessage:n,errorCode:i,step:this.activeIndex},bubbles:!0}))};this.onWalletConnected=t=>{let n=t?.detail?.walletType||"unknown";console.log("ICPay Progress: Wallet connected event received:",t.detail),this.updateStepStatus(0,"completed"),this.currentSteps[1]&&(this.activeIndex=1,this.updateStepStatus(1,"loading")),this.startAutomaticProgression(),this.dispatchEvent(new CustomEvent("icpay-progress-wallet-connected",{detail:{walletType:n,step:this.activeIndex},bubbles:!0}))};this.onWalletDisconnected=t=>{let n=t?.detail?.walletType||"unknown";console.log("ICPay Progress: Wallet disconnected event received:",t.detail),this.dispatchEvent(new CustomEvent("icpay-progress-wallet-disconnected",{detail:{walletType:n,step:this.activeIndex},bubbles:!0}))};this.onBalanceCheck=t=>{let n=t?.detail?.hasBalance||!1,i=t?.detail?.balance||0;console.log("ICPay Progress: Balance check event received:",t.detail),n||(this.failed=!0,this.errorMessage="Insufficient balance for transaction",this.updateStepStatus(this.activeIndex,"error","Insufficient balance for transaction"),this.stopAutomaticProgression(),this.dispatchEvent(new CustomEvent("icpay-progress-insufficient-balance",{detail:{balance:i,required:this.currentAmount||this.amount,step:this.activeIndex},bubbles:!0})))};this.onLedgerVerified=t=>{let n=t?.detail?.ledgerId||t?.detail?.canisterId,i=t?.detail?.symbol||"unknown";console.log("ICPay Progress: Ledger verified event received:",t.detail),i&&i!=="unknown"&&(this.currentLedgerSymbol=i,this.ledgerSymbol=i),this.dispatchEvent(new CustomEvent("icpay-progress-ledger-verified",{detail:{ledgerId:n,symbol:i,step:this.activeIndex},bubbles:!0}))};this.onWidgetPayment=t=>{let n=t?.detail?.amount,i=t?.detail?.currency,s=t?.detail?.ledgerSymbol;console.log("ICPay Progress: Widget payment event received:",t.detail),n!==void 0&&(this.currentAmount=n,this.amount=n),i&&(this.currentCurrency=i,this.currency=i),s&&(this.currentLedgerSymbol=s,this.ledgerSymbol=s),this.dispatchEvent(new CustomEvent("icpay-progress-widget-payment",{detail:{amount:n,currency:i,ledgerSymbol:s,step:this.activeIndex},bubbles:!0}))};this.onWidgetError=t=>{let n=t?.detail?.message||"Widget error occurred",i=t?.detail?.code||"WIDGET_ERROR";console.log("ICPay Progress: Widget error event received:",t.detail),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-widget-error",{detail:{errorMessage:n,errorCode:i,step:this.activeIndex},bubbles:!0}))};this.onWidgetUnlock=t=>{let n=t?.detail?.amount,i=t?.detail?.currency;console.log("ICPay Progress: Widget unlock event received:",t.detail),this.dispatchEvent(new CustomEvent("icpay-progress-widget-unlock",{detail:{amount:n,currency:i,step:this.activeIndex},bubbles:!0}))};this.onWidgetTip=t=>{let n=t?.detail?.amount,i=t?.detail?.currency;console.log("ICPay Progress: Widget tip event received:",t.detail),this.dispatchEvent(new CustomEvent("icpay-progress-widget-tip",{detail:{amount:n,currency:i,step:this.activeIndex},bubbles:!0}))};this.onWidgetDonation=t=>{let n=t?.detail?.amount,i=t?.detail?.currency;console.log("ICPay Progress: Widget donation event received:",t.detail),this.dispatchEvent(new CustomEvent("icpay-progress-widget-donation",{detail:{amount:n,currency:i,step:this.activeIndex},bubbles:!0}))};this.onWidgetCoffee=t=>{let n=t?.detail?.amount,i=t?.detail?.currency;console.log("ICPay Progress: Widget coffee event received:",t.detail),this.dispatchEvent(new CustomEvent("icpay-progress-widget-coffee",{detail:{amount:n,currency:i,step:this.activeIndex},bubbles:!0}))}}connectedCallback(){super.connectedCallback();try{Ef(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(t){if(t.has("theme"))try{Ef(this,this.theme)}catch{}}attachSDKEventListeners(){window.addEventListener("icpay-sdk-method-start",this.onMethodStart),window.addEventListener("icpay-sdk-method-success",this.onMethodSuccess),window.addEventListener("icpay-sdk-method-error",this.onMethodError),window.addEventListener("icpay-sdk-transaction-created",this.onTransactionCreated),window.addEventListener("icpay-sdk-transaction-updated",this.onTransactionUpdated),window.addEventListener("icpay-sdk-transaction-completed",this.onTransactionCompleted),window.addEventListener("icpay-sdk-transaction-failed",this.onTransactionFailed),window.addEventListener("icpay-sdk-error",this.onSDKError),window.addEventListener("icpay-sdk-wallet-connected",this.onWalletConnected),window.addEventListener("icpay-sdk-wallet-disconnected",this.onWalletDisconnected),window.addEventListener("icpay-sdk-balance-check",this.onBalanceCheck),window.addEventListener("icpay-sdk-ledger-verified",this.onLedgerVerified),window.addEventListener("icpay-pay",this.onWidgetPayment),window.addEventListener("icpay-error",this.onWidgetError),window.addEventListener("icpay-unlock",this.onWidgetUnlock),window.addEventListener("icpay-tip",this.onWidgetTip),window.addEventListener("icpay-donation",this.onWidgetDonation),window.addEventListener("icpay-coffee",this.onWidgetCoffee)}detachSDKEventListeners(){window.removeEventListener("icpay-sdk-method-start",this.onMethodStart),window.removeEventListener("icpay-sdk-method-success",this.onMethodSuccess),window.removeEventListener("icpay-sdk-method-error",this.onMethodError),window.removeEventListener("icpay-sdk-transaction-created",this.onTransactionCreated),window.removeEventListener("icpay-sdk-transaction-updated",this.onTransactionUpdated),window.removeEventListener("icpay-sdk-transaction-completed",this.onTransactionCompleted),window.removeEventListener("icpay-sdk-transaction-failed",this.onTransactionFailed),window.removeEventListener("icpay-sdk-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"),console.log("ICPay Progress: Starting automatic progression from step:",this.activeIndex),this.progressionTimer=setInterval(()=>{if(this.failed||this.completed){this.stopAutomaticProgression();return}console.log("ICPay Progress: Processing step:",this.activeIndex),this.updateStepStatus(this.activeIndex,"completed"),this.activeIndex<this.currentSteps.length-1?(this.activeIndex++,this.updateStepStatus(this.activeIndex,"loading"),console.log("ICPay Progress: Auto-progressed to step:",this.activeIndex)):(this.stopAutomaticProgression(),console.log("ICPay Progress: All steps completed, waiting for transaction completion")),this.requestUpdate()},3e3)}stopAutomaticProgression(){this.progressionTimer&&(clearInterval(this.progressionTimer),this.progressionTimer=null)}updateStepStatus(t,n,i){if(t>=0&&t<this.currentSteps.length){let s=this.currentSteps[t],o=s.status;s.status=n,n==="completed"&&(s.timestamp=this.getCurrentTime()),n==="error"&&i&&(s.errorMessage=this.transformErrorMessage(i)),console.log(`ICPay Progress: Step ${t} (${s.label}) status changed from ${o} to ${n}`),this.requestUpdate()}}getCurrentTime(){return new Date().toLocaleTimeString("en-US",{hour12:!1,hour:"2-digit",minute:"2-digit",second:"2-digit"})}progressPercent(){if(this.failed)return 0;if(this.showSuccess)return 100;let n=this.currentSteps.filter(i=>i.status==="completed").length/this.currentSteps.length*100;return Math.max(0,Math.min(100,n))}verticalPercent(){if(this.failed)return 0;if(this.showSuccess)return 100;let n=this.currentSteps.filter(i=>i.status==="completed").length/this.currentSteps.length*100;return Math.max(0,Math.min(100,n))}getStepIcon(t){switch(t.status){case"loading":return ke`<div class="spinner"></div>`;case"completed":return"\u2713";case"error":return"\u2717";default:return"\u25CB"}}transformErrorMessage(t){let n=String(t||"").toLowerCase();return n.includes("user rejected")||n.includes("user cancelled")||n.includes("user canceled")||n.includes("signature rejected")?"User have rejected the transfer":t}renderConfetti(){if(!this.showConfetti)return"";let t=Array.from({length:50},(i,s)=>s),n=["#0066FF","#ef4444","#10b981","#f59e0b","#8b5cf6"];return ke`
4943
4943
  <div class="confetti">
4944
4944
  ${t.map(i=>ke`
4945
4945
  <div
@@ -5241,7 +5241,7 @@ Make sure to test your application with a production build as repeat registratio
5241
5241
  .crypto-option { background: var(--icpay-surface-alt); border: 2px solid var(--icpay-border); border-radius: 12px; padding: 12px 8px; text-align: center; cursor: pointer; color: var(--icpay-text); font-weight: 600; font-size: 12px; }
5242
5242
  .crypto-option.selected { background: var(--icpay-primary); color: #111827; border-color: var(--icpay-primary); }
5243
5243
  select { background: var(--icpay-surface-alt); border: 1px solid var(--icpay-border); color: var(--icpay-text); border-radius: 8px; padding: 10px; font-weight: 600; }
5244
- `,Se([ur({type:Array})],Nl.prototype,"options",2),Se([ur({type:String})],Nl.prototype,"value",2),Se([ur({type:String})],Nl.prototype,"defaultSymbol",2),Se([ur({type:String})],Nl.prototype,"mode",2),Se([ur({type:Object})],Nl.prototype,"theme",2),Nl=Se([Ui("icpay-token-selector")],Nl);var NM=typeof window<"u",pw=null;function uf(r,e,t){r&&(t!==void 0?console.log(`[ICPay Widget] ${e}`,t):console.log(`[ICPay Widget] ${e}`))}var Xi=class extends mn{constructor(){super(...arguments);this.selectedSymbol="ICP";this.unlocked=!1;this.succeeded=!1;this.processing=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.pnp=null}async tryAutoConnectPNP(){try{if(!this.config||this.config?.useOwnWallet)return;let t=localStorage.getItem("icpay:pnp");if(!t)return;let n=JSON.parse(t);if(!n?.provider||!n?.principal)return;pw||(pw=(await Promise.resolve().then(()=>(pc(),fc))).PNP);let i=new pw(this.config?.plugNPlay||{});this.walletConnected=!1,this.config={...this.config,connectedWallet:{owner:n.principal,principal:n.principal,connected:!1}}}catch{}}get cryptoOptions(){return this.config.cryptoOptions?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){super.connectedCallback(),NM&&(uf(this.config?.debug||!1,"Premium content connected",{config:this.config}),this.tryAutoConnectPNP(),this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers())}updated(t){if(t.has("config")&&this.pendingAction&&this.config?.actorProvider){let n=this.pendingAction;this.pendingAction=null,setTimeout(()=>{n==="pay"&&this.onPay()},0)}}async loadVerifiedLedgers(){if(!(!NM||!this.config?.publishableKey))try{let n=await Ln(this.config).client.getVerifiedLedgers();this.availableLedgers=n.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||this.availableLedgers[0]?.symbol||"ICP")}catch(t){console.warn("Failed to load verified ledgers:",t),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol="ICP")}}async onPay(){if(NM&&!(this.processing||this.unlocked)){uf(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,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){uf(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{pw||(pw=(await Promise.resolve().then(()=>(pc(),fc))).PNP),this.pnp=new pw(this.config?.plugNPlay||{});let o=this.pnp.getEnabledWallets();if(uf(this.config?.debug||!1,"Available wallets",o),!o?.length)throw new Error("No wallets available");this.pendingAction="pay",this.showWalletModal=!0;return}catch(o){uf(this.config?.debug||!1,"Wallet connection error:",o),this.errorMessage=o instanceof Error?o.message:"Wallet connection failed",this.errorSeverity="error";return}}uf(this.config?.debug||!1,"Creating SDK for payment");let t=Ln(this.config),i=this.cryptoOptions.find(o=>o.symbol===this.selectedSymbol).canisterId||await t.client.getLedgerCanisterIdBySymbol(this.selectedSymbol);uf(this.config?.debug||!1,"Payment details",{priceUsd:this.config.priceUsd,selectedSymbol:this.selectedSymbol,canisterId:i});let s=await t.sendUsd(this.config.priceUsd,i,{context:"premium-content"});uf(this.config?.debug||!1,"Payment completed",{resp:s}),this.unlocked=!0,this.succeeded=!0,this.config.onSuccess&&this.config.onSuccess({id:s.transactionId,status:s.status}),this.dispatchEvent(new CustomEvent("icpay-unlock",{detail:{amount:this.config.priceUsd,tx:s},bubbles:!0}))}catch(t){Bo(t,{onError:n=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:n,bubbles:!0})),Mo(n)&&(this.errorMessage=Po(n),this.errorSeverity=ko(n),this.errorAction=Ro(n))}})}finally{this.processing=!1}}}select(t){this.selectedSymbol=t}getWalletId(t){return t&&(t.id||t.provider||t.key)||""}getWalletLabel(t){return t&&(t.label||t.name||t.title||t.id)||"Wallet"}getWalletIcon(t){return t&&(t.icon||t.logo||t.image)||null}async connectWithWallet(t){if(this.pnp)try{if(!t)throw new Error("No wallet ID provided");let n=await this.pnp.connect(t);if(!!!(n&&(n.connected===!0||n.principal||n.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0,this.config={...this.config,connectedWallet:n,actorProvider:(o,a)=>this.pnp.getActor({canisterId:o,idl:a,requiresSigning:!0,anon:!1})},this.showWalletModal=!1;let s=this.pendingAction;this.pendingAction=null,s==="pay"&&setTimeout(()=>this.onPay(),0)}catch(n){this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}render(){return this.config?ke`
5244
+ `,Se([ur({type:Array})],Nl.prototype,"options",2),Se([ur({type:String})],Nl.prototype,"value",2),Se([ur({type:String})],Nl.prototype,"defaultSymbol",2),Se([ur({type:String})],Nl.prototype,"mode",2),Se([ur({type:Object})],Nl.prototype,"theme",2),Nl=Se([Ui("icpay-token-selector")],Nl);var NM=typeof window<"u",pw=null;function uf(r,e,t){r&&(t!==void 0?console.log(`[ICPay Widget] ${e}`,t):console.log(`[ICPay Widget] ${e}`))}var Xi=class extends mn{constructor(){super(...arguments);this.selectedSymbol="ICP";this.unlocked=!1;this.succeeded=!1;this.processing=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.pnp=null}async tryAutoConnectPNP(){try{if(!this.config||this.config?.useOwnWallet)return;let t=localStorage.getItem("icpay:pnp");if(!t)return;let n=JSON.parse(t);if(!n?.provider||!n?.principal)return;pw||(pw=(await Promise.resolve().then(()=>(pc(),fc))).PNP);let i=new pw(this.config?.plugNPlay||{});this.walletConnected=!1,this.config={...this.config,connectedWallet:{owner:n.principal,principal:n.principal,connected:!1}}}catch{}}get cryptoOptions(){return this.config.cryptoOptions?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){super.connectedCallback(),NM&&(uf(this.config?.debug||!1,"Premium content connected",{config:this.config}),this.tryAutoConnectPNP(),this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers())}updated(t){if(t.has("config")&&this.pendingAction&&this.config?.actorProvider){let n=this.pendingAction;this.pendingAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}setTimeout(()=>{n==="pay"&&this.onPay()},0)}}async loadVerifiedLedgers(){if(!(!NM||!this.config?.publishableKey))try{let n=await Ln(this.config).client.getVerifiedLedgers();this.availableLedgers=n.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||this.availableLedgers[0]?.symbol||"ICP")}catch(t){console.warn("Failed to load verified ledgers:",t),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol="ICP")}}async onPay(){if(NM&&!(this.processing||this.unlocked)){uf(this.config?.debug||!1,"Premium content payment started",{priceUsd:this.config.priceUsd,selectedSymbol:this.selectedSymbol,useOwnWallet:this.config.useOwnWallet}),this.errorMessage=null,this.errorSeverity=null,this.errorAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"pay",type:"sendUsd",amount:this.config.priceUsd,currency:this.selectedSymbol}}))}catch{}this.processing=!0;try{if(this.config.useOwnWallet){if(!this.config.actorProvider){this.pendingAction="pay",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0}));return}}else if(!this.walletConnected){uf(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{pw||(pw=(await Promise.resolve().then(()=>(pc(),fc))).PNP),this.pnp=new pw(this.config?.plugNPlay||{});let o=this.pnp.getEnabledWallets();if(uf(this.config?.debug||!1,"Available wallets",o),!o?.length)throw new Error("No wallets available");this.pendingAction="pay",this.showWalletModal=!0;return}catch(o){uf(this.config?.debug||!1,"Wallet connection error:",o),this.errorMessage=o instanceof Error?o.message:"Wallet connection failed",this.errorSeverity="error";return}}uf(this.config?.debug||!1,"Creating SDK for payment");let t=Ln(this.config),i=this.cryptoOptions.find(o=>o.symbol===this.selectedSymbol).canisterId||await t.client.getLedgerCanisterIdBySymbol(this.selectedSymbol);uf(this.config?.debug||!1,"Payment details",{priceUsd:this.config.priceUsd,selectedSymbol:this.selectedSymbol,canisterId:i});let s=await t.sendUsd(this.config.priceUsd,i,{context:"premium-content"});uf(this.config?.debug||!1,"Payment completed",{resp:s}),this.unlocked=!0,this.succeeded=!0,this.config.onSuccess&&this.config.onSuccess({id:s.transactionId,status:s.status}),this.dispatchEvent(new CustomEvent("icpay-unlock",{detail:{amount:this.config.priceUsd,tx:s},bubbles:!0}))}catch(t){Bo(t,{onError:n=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:n,bubbles:!0})),Mo(n)&&(this.errorMessage=Po(n),this.errorSeverity=ko(n),this.errorAction=Ro(n))}})}finally{this.processing=!1}}}select(t){this.selectedSymbol=t}getWalletId(t){return t&&(t.id||t.provider||t.key)||""}getWalletLabel(t){return t&&(t.label||t.name||t.title||t.id)||"Wallet"}getWalletIcon(t){return t&&(t.icon||t.logo||t.image)||null}async connectWithWallet(t){if(this.pnp)try{if(!t)throw new Error("No wallet ID provided");let n=await this.pnp.connect(t);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:t}}))}catch{}this.config={...this.config,connectedWallet:n,actorProvider:(o,a)=>this.pnp.getActor({canisterId:o,idl:a,requiresSigning:!0,anon:!1})},this.showWalletModal=!1;let s=this.pendingAction;this.pendingAction=null,s==="pay"&&setTimeout(()=>this.onPay(),0)}catch(n){this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}render(){return this.config?ke`
5245
5245
  <div class="card section">
5246
5246
  ${this.config?.progressBar?.enabled!==!1?ke`<icpay-progress-bar mode="${this.config?.progressBar?.mode||"modal"}"></icpay-progress-bar>`:null}
5247
5247
  <div class="image-container">
@@ -5347,7 +5347,7 @@ Make sure to test your application with a production build as repeat registratio
5347
5347
  border-color: rgba(239, 68, 68, 0.3);
5348
5348
  color: #ef4444;
5349
5349
  }
5350
- `],Se([ur({type:Object})],Xi.prototype,"config",2),Se([Re()],Xi.prototype,"selectedSymbol",2),Se([Re()],Xi.prototype,"unlocked",2),Se([Re()],Xi.prototype,"succeeded",2),Se([Re()],Xi.prototype,"processing",2),Se([Re()],Xi.prototype,"availableLedgers",2),Se([Re()],Xi.prototype,"errorMessage",2),Se([Re()],Xi.prototype,"errorSeverity",2),Se([Re()],Xi.prototype,"errorAction",2),Se([Re()],Xi.prototype,"walletConnected",2),Se([Re()],Xi.prototype,"pendingAction",2),Se([Re()],Xi.prototype,"showWalletModal",2),Xi=Se([Ui("icpay-premium-content")],Xi);var TM=typeof window<"u",mw=null;function df(r,e,t){r&&(t!==void 0?console.log(`[ICPay Widget] ${e}`,t):console.log(`[ICPay Widget] ${e}`))}var Ci=class extends mn{constructor(){super(...arguments);this.selectedAmount=1;this.selectedSymbol="ICP";this.total=0;this.processing=!1;this.succeeded=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.pnp=null}async tryAutoConnectPNP(){try{if(!this.config||this.config?.useOwnWallet)return;let t=localStorage.getItem("icpay:pnp");if(!t)return;let n=JSON.parse(t);if(!n?.provider||!n?.principal)return;mw||(mw=(await Promise.resolve().then(()=>(pc(),fc))).PNP);let i=new mw(this.config?.plugNPlay||{});this.walletConnected=!1,this.config={...this.config,connectedWallet:{owner:n.principal,principal:n.principal,connected:!1}}}catch{}}get amounts(){return this.config?.amountsUsd||[1,5,10]}get cryptoOptions(){return this.config.cryptoOptions?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){super.connectedCallback(),TM&&(df(this.config?.debug||!1,"Tip jar connected",{config:this.config}),this.config&&this.config.defaultAmountUsd&&(this.selectedAmount=this.config.defaultAmountUsd),this.tryAutoConnectPNP(),this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers(),this.config?.defaultSymbol&&(this.selectedSymbol=this.config.defaultSymbol))}updated(t){if(t.has("config")&&this.pendingAction&&this.config?.actorProvider){let n=this.pendingAction;this.pendingAction=null,setTimeout(()=>{n==="tip"&&this.tip()},0)}}async loadVerifiedLedgers(){if(!(!TM||!this.config?.publishableKey))try{let n=await Ln(this.config).client.getVerifiedLedgers();this.availableLedgers=n.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.config?.cryptoOptions&&this.config.cryptoOptions.length===1&&(this.selectedSymbol=this.config.cryptoOptions[0].symbol),!this.selectedSymbol&&this.availableLedgers.length>0&&(this.selectedSymbol=this.config?.defaultSymbol||this.availableLedgers[0].symbol)}catch(t){console.warn("Failed to load verified ledgers:",t),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol="ICP")}}selectAmount(t){this.selectedAmount=t}selectSymbol(t){this.selectedSymbol=t}get fillPercentage(){return Math.min(this.total/50*100,100)}async tip(){if(TM&&(df(this.config?.debug||!1,"Tip button clicked!",{config:this.config,processing:this.processing}),!this.processing)){this.errorMessage=null,this.errorSeverity=null,this.errorAction=null,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){df(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{mw||(mw=(await Promise.resolve().then(()=>(pc(),fc))).PNP),this.pnp=new mw(this.config?.plugNPlay||{});let o=this.pnp.getEnabledWallets();if(df(this.config?.debug||!1,"Available wallets",o),!o?.length)throw new Error("No wallets available");this.pendingAction="tip",this.showWalletModal=!0;return}catch(o){df(this.config?.debug||!1,"Wallet connection error:",o),this.errorMessage=o instanceof Error?o.message:"Wallet connection failed",this.errorSeverity="error";return}}df(this.config?.debug||!1,"Creating SDK for payment");let t=Ln(this.config),i=this.cryptoOptions.find(o=>o.symbol===this.selectedSymbol).canisterId||await t.client.getLedgerCanisterIdBySymbol(this.selectedSymbol);df(this.config?.debug||!1,"Tip payment details",{amount:this.selectedAmount,selectedSymbol:this.selectedSymbol,canisterId:i});let s=await t.sendUsd(this.selectedAmount,i,{context:"tip-jar"});df(this.config?.debug||!1,"Tip payment completed",{resp:s}),this.total+=this.selectedAmount,this.succeeded=!0,this.config.onSuccess&&this.config.onSuccess({id:s.transactionId,status:s.status,total:this.total}),this.dispatchEvent(new CustomEvent("icpay-tip",{detail:{amount:this.selectedAmount,tx:s},bubbles:!0}))}catch(t){Bo(t,{onError:n=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:n,bubbles:!0})),Mo(n)&&(this.errorMessage=Po(n),this.errorSeverity=ko(n),this.errorAction=Ro(n))}})}finally{this.processing=!1}}}getWalletId(t){return t&&(t.id||t.provider||t.key)||""}getWalletLabel(t){return t&&(t.label||t.name||t.title||t.id)||"Wallet"}getWalletIcon(t){return t&&(t.icon||t.logo||t.image)||null}async connectWithWallet(t){if(this.pnp)try{if(!t)throw new Error("No wallet ID provided");let n=await this.pnp.connect(t);if(!!!(n&&(n.connected===!0||n.principal||n.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0,this.config={...this.config,connectedWallet:n,actorProvider:(o,a)=>this.pnp.getActor({canisterId:o,idl:a,requiresSigning:!0,anon:!1})},this.showWalletModal=!1;let s=this.pendingAction;this.pendingAction=null,s==="tip"&&setTimeout(()=>this.tip(),0)}catch(n){this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}render(){return this.config?ke`
5350
+ `],Se([ur({type:Object})],Xi.prototype,"config",2),Se([Re()],Xi.prototype,"selectedSymbol",2),Se([Re()],Xi.prototype,"unlocked",2),Se([Re()],Xi.prototype,"succeeded",2),Se([Re()],Xi.prototype,"processing",2),Se([Re()],Xi.prototype,"availableLedgers",2),Se([Re()],Xi.prototype,"errorMessage",2),Se([Re()],Xi.prototype,"errorSeverity",2),Se([Re()],Xi.prototype,"errorAction",2),Se([Re()],Xi.prototype,"walletConnected",2),Se([Re()],Xi.prototype,"pendingAction",2),Se([Re()],Xi.prototype,"showWalletModal",2),Xi=Se([Ui("icpay-premium-content")],Xi);var TM=typeof window<"u",mw=null;function df(r,e,t){r&&(t!==void 0?console.log(`[ICPay Widget] ${e}`,t):console.log(`[ICPay Widget] ${e}`))}var Ci=class extends mn{constructor(){super(...arguments);this.selectedAmount=1;this.selectedSymbol="ICP";this.total=0;this.processing=!1;this.succeeded=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.pnp=null}async tryAutoConnectPNP(){try{if(!this.config||this.config?.useOwnWallet)return;let t=localStorage.getItem("icpay:pnp");if(!t)return;let n=JSON.parse(t);if(!n?.provider||!n?.principal)return;mw||(mw=(await Promise.resolve().then(()=>(pc(),fc))).PNP);let i=new mw(this.config?.plugNPlay||{});this.walletConnected=!1,this.config={...this.config,connectedWallet:{owner:n.principal,principal:n.principal,connected:!1}}}catch{}}get amounts(){return this.config?.amountsUsd||[1,5,10]}get cryptoOptions(){return this.config.cryptoOptions?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){super.connectedCallback(),TM&&(df(this.config?.debug||!1,"Tip jar connected",{config:this.config}),this.config&&this.config.defaultAmountUsd&&(this.selectedAmount=this.config.defaultAmountUsd),this.tryAutoConnectPNP(),this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers(),this.config?.defaultSymbol&&(this.selectedSymbol=this.config.defaultSymbol))}updated(t){if(t.has("config")&&this.pendingAction&&this.config?.actorProvider){let n=this.pendingAction;this.pendingAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}setTimeout(()=>{n==="tip"&&this.tip()},0)}}async loadVerifiedLedgers(){if(!(!TM||!this.config?.publishableKey))try{let n=await Ln(this.config).client.getVerifiedLedgers();this.availableLedgers=n.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.config?.cryptoOptions&&this.config.cryptoOptions.length===1&&(this.selectedSymbol=this.config.cryptoOptions[0].symbol),!this.selectedSymbol&&this.availableLedgers.length>0&&(this.selectedSymbol=this.config?.defaultSymbol||this.availableLedgers[0].symbol)}catch(t){console.warn("Failed to load verified ledgers:",t),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol="ICP")}}selectAmount(t){this.selectedAmount=t}selectSymbol(t){this.selectedSymbol=t}get fillPercentage(){return Math.min(this.total/50*100,100)}async tip(){if(TM&&(df(this.config?.debug||!1,"Tip button clicked!",{config:this.config,processing:this.processing}),!this.processing)){this.errorMessage=null,this.errorSeverity=null,this.errorAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"tip",type:"sendUsd",amount:this.selectedAmount,currency:this.selectedSymbol}}))}catch{}this.processing=!0;try{if(this.config.useOwnWallet){if(!this.config.actorProvider){this.pendingAction="tip",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0}));return}}else if(!this.walletConnected){df(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{mw||(mw=(await Promise.resolve().then(()=>(pc(),fc))).PNP),this.pnp=new mw(this.config?.plugNPlay||{});let o=this.pnp.getEnabledWallets();if(df(this.config?.debug||!1,"Available wallets",o),!o?.length)throw new Error("No wallets available");this.pendingAction="tip",this.showWalletModal=!0;return}catch(o){df(this.config?.debug||!1,"Wallet connection error:",o),this.errorMessage=o instanceof Error?o.message:"Wallet connection failed",this.errorSeverity="error";return}}df(this.config?.debug||!1,"Creating SDK for payment");let t=Ln(this.config),i=this.cryptoOptions.find(o=>o.symbol===this.selectedSymbol).canisterId||await t.client.getLedgerCanisterIdBySymbol(this.selectedSymbol);df(this.config?.debug||!1,"Tip payment details",{amount:this.selectedAmount,selectedSymbol:this.selectedSymbol,canisterId:i});let s=await t.sendUsd(this.selectedAmount,i,{context:"tip-jar"});df(this.config?.debug||!1,"Tip payment completed",{resp:s}),this.total+=this.selectedAmount,this.succeeded=!0,this.config.onSuccess&&this.config.onSuccess({id:s.transactionId,status:s.status,total:this.total}),this.dispatchEvent(new CustomEvent("icpay-tip",{detail:{amount:this.selectedAmount,tx:s},bubbles:!0}))}catch(t){Bo(t,{onError:n=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:n,bubbles:!0})),Mo(n)&&(this.errorMessage=Po(n),this.errorSeverity=ko(n),this.errorAction=Ro(n))}})}finally{this.processing=!1}}}getWalletId(t){return t&&(t.id||t.provider||t.key)||""}getWalletLabel(t){return t&&(t.label||t.name||t.title||t.id)||"Wallet"}getWalletIcon(t){return t&&(t.icon||t.logo||t.image)||null}async connectWithWallet(t){if(this.pnp)try{if(!t)throw new Error("No wallet ID provided");let n=await this.pnp.connect(t);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:t}}))}catch{}this.config={...this.config,connectedWallet:n,actorProvider:(o,a)=>this.pnp.getActor({canisterId:o,idl:a,requiresSigning:!0,anon:!1})},this.showWalletModal=!1;let s=this.pendingAction;this.pendingAction=null,s==="tip"&&setTimeout(()=>this.tip(),0)}catch(n){this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}render(){return this.config?ke`
5351
5351
  <div class="card section" style="text-align:center;">
5352
5352
  ${this.config?.progressBar?.enabled!==!1?ke`<icpay-progress-bar mode="${this.config?.progressBar?.mode||"modal"}"></icpay-progress-bar>`:null}
5353
5353
  <div class="jar"><div class="fill" style="height:${this.fillPercentage}%"></div></div>
@@ -5435,7 +5435,7 @@ Make sure to test your application with a production build as repeat registratio
5435
5435
  border-color: rgba(239, 68, 68, 0.3);
5436
5436
  color: #ef4444;
5437
5437
  }
5438
- `],Se([ur({type:Object})],Ci.prototype,"config",2),Se([Re()],Ci.prototype,"selectedAmount",2),Se([Re()],Ci.prototype,"selectedSymbol",2),Se([Re()],Ci.prototype,"total",2),Se([Re()],Ci.prototype,"processing",2),Se([Re()],Ci.prototype,"succeeded",2),Se([Re()],Ci.prototype,"availableLedgers",2),Se([Re()],Ci.prototype,"errorMessage",2),Se([Re()],Ci.prototype,"errorSeverity",2),Se([Re()],Ci.prototype,"errorAction",2),Se([Re()],Ci.prototype,"walletConnected",2),Se([Re()],Ci.prototype,"pendingAction",2),Se([Re()],Ci.prototype,"showWalletModal",2),Ci=Se([Ui("icpay-tip-jar")],Ci);var OM=typeof window<"u",ww=null;function hf(r,e,t){r&&(t!==void 0?console.log(`[ICPay Widget] ${e}`,t):console.log(`[ICPay Widget] ${e}`))}var ni=class extends mn{constructor(){super(...arguments);this.title="Article Title";this.preview="";this.lockedContent="";this.selectedSymbol="ICP";this.unlocked=!1;this.succeeded=!1;this.processing=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.pnp=null}async tryAutoConnectPNP(){try{if(!this.config||this.config?.useOwnWallet)return;let t=localStorage.getItem("icpay:pnp");if(!t)return;let n=JSON.parse(t);if(!n?.provider||!n?.principal)return;ww||(ww=(await Promise.resolve().then(()=>(pc(),fc))).PNP);let i=new ww(this.config?.plugNPlay||{});this.walletConnected=!1,this.config={...this.config,connectedWallet:{owner:n.principal,principal:n.principal,connected:!1}}}catch{}}get cryptoOptions(){return this.config.cryptoOptions?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){super.connectedCallback(),OM&&(hf(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(),this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers())}updated(t){if(t.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)),t.has("config")&&this.pendingAction&&this.config?.actorProvider){let n=this.pendingAction;this.pendingAction=null,setTimeout(()=>{n==="unlock"&&this.unlock()},0)}}async loadVerifiedLedgers(){if(!(!OM||!this.config?.publishableKey))try{let n=await Ln(this.config).client.getVerifiedLedgers();this.availableLedgers=n.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||this.availableLedgers[0]?.symbol||"ICP")}catch(t){console.warn("Failed to load verified ledgers:",t),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol="ICP")}}selectSymbol(t){this.selectedSymbol=t}async unlock(){if(OM&&!(this.processing||this.unlocked)){hf(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,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){hf(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{ww||(ww=(await Promise.resolve().then(()=>(pc(),fc))).PNP),this.pnp=new ww(this.config?.plugNPlay||{});let o=this.pnp.getEnabledWallets();if(hf(this.config?.debug||!1,"Available wallets",o),!o?.length)throw new Error("No wallets available");this.pendingAction="unlock",this.showWalletModal=!0;return}catch(o){hf(this.config?.debug||!1,"Wallet connection error:",o),this.errorMessage=o instanceof Error?o.message:"Wallet connection failed",this.errorSeverity="error";return}}hf(this.config?.debug||!1,"Creating SDK for payment");let t=Ln(this.config),i=this.cryptoOptions.find(o=>o.symbol===this.selectedSymbol).canisterId||await t.client.getLedgerCanisterIdBySymbol(this.selectedSymbol);hf(this.config?.debug||!1,"Article payment details",{priceUsd:this.config.priceUsd,selectedSymbol:this.selectedSymbol,canisterId:i});let s=await t.sendUsd(this.config.priceUsd,i,{context:"article"});hf(this.config?.debug||!1,"Article payment completed",{resp:s}),this.unlocked=!0,this.succeeded=!0,this.config.onSuccess&&this.config.onSuccess({id:s.transactionId,status:s.status}),this.dispatchEvent(new CustomEvent("icpay-unlock",{detail:{amount:this.config.priceUsd,tx:s},bubbles:!0}))}catch(t){Bo(t,{onError:n=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:n,bubbles:!0})),Mo(n)&&(this.errorMessage=Po(n),this.errorSeverity=ko(n),this.errorAction=Ro(n))}})}finally{this.processing=!1}}}getWalletId(t){return t&&(t.id||t.provider||t.key)||""}getWalletLabel(t){return t&&(t.label||t.name||t.title||t.id)||"Wallet"}getWalletIcon(t){return t&&(t.icon||t.logo||t.image)||null}async connectWithWallet(t){if(this.pnp)try{if(!t)throw new Error("No wallet ID provided");let n=await this.pnp.connect(t);if(!!!(n&&(n.connected===!0||n.principal||n.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0,this.config={...this.config,connectedWallet:n,actorProvider:(o,a)=>this.pnp.getActor({canisterId:o,idl:a,requiresSigning:!0,anon:!1})},this.showWalletModal=!1;let s=this.pendingAction;this.pendingAction=null,s==="unlock"&&setTimeout(()=>this.unlock(),0)}catch(n){this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}render(){return this.config?ke`
5438
+ `],Se([ur({type:Object})],Ci.prototype,"config",2),Se([Re()],Ci.prototype,"selectedAmount",2),Se([Re()],Ci.prototype,"selectedSymbol",2),Se([Re()],Ci.prototype,"total",2),Se([Re()],Ci.prototype,"processing",2),Se([Re()],Ci.prototype,"succeeded",2),Se([Re()],Ci.prototype,"availableLedgers",2),Se([Re()],Ci.prototype,"errorMessage",2),Se([Re()],Ci.prototype,"errorSeverity",2),Se([Re()],Ci.prototype,"errorAction",2),Se([Re()],Ci.prototype,"walletConnected",2),Se([Re()],Ci.prototype,"pendingAction",2),Se([Re()],Ci.prototype,"showWalletModal",2),Ci=Se([Ui("icpay-tip-jar")],Ci);var OM=typeof window<"u",ww=null;function hf(r,e,t){r&&(t!==void 0?console.log(`[ICPay Widget] ${e}`,t):console.log(`[ICPay Widget] ${e}`))}var ni=class extends mn{constructor(){super(...arguments);this.title="Article Title";this.preview="";this.lockedContent="";this.selectedSymbol="ICP";this.unlocked=!1;this.succeeded=!1;this.processing=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.pnp=null}async tryAutoConnectPNP(){try{if(!this.config||this.config?.useOwnWallet)return;let t=localStorage.getItem("icpay:pnp");if(!t)return;let n=JSON.parse(t);if(!n?.provider||!n?.principal)return;ww||(ww=(await Promise.resolve().then(()=>(pc(),fc))).PNP);let i=new ww(this.config?.plugNPlay||{});this.walletConnected=!1,this.config={...this.config,connectedWallet:{owner:n.principal,principal:n.principal,connected:!1}}}catch{}}get cryptoOptions(){return this.config.cryptoOptions?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){super.connectedCallback(),OM&&(hf(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(),this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers())}updated(t){if(t.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)),t.has("config")&&this.pendingAction&&this.config?.actorProvider){let n=this.pendingAction;this.pendingAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}setTimeout(()=>{n==="unlock"&&this.unlock()},0)}}async loadVerifiedLedgers(){if(!(!OM||!this.config?.publishableKey))try{let n=await Ln(this.config).client.getVerifiedLedgers();this.availableLedgers=n.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||this.availableLedgers[0]?.symbol||"ICP")}catch(t){console.warn("Failed to load verified ledgers:",t),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol="ICP")}}selectSymbol(t){this.selectedSymbol=t}async unlock(){if(OM&&!(this.processing||this.unlocked)){hf(this.config?.debug||!1,"Article paywall unlock started",{priceUsd:this.config.priceUsd,selectedSymbol:this.selectedSymbol,useOwnWallet:this.config.useOwnWallet}),this.errorMessage=null,this.errorSeverity=null,this.errorAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"unlock",type:"sendUsd",amount:this.config.priceUsd,currency:this.selectedSymbol}}))}catch{}this.processing=!0;try{if(this.config.useOwnWallet){if(!this.config.actorProvider){this.pendingAction="unlock",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0}));return}}else if(!this.walletConnected){hf(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{ww||(ww=(await Promise.resolve().then(()=>(pc(),fc))).PNP),this.pnp=new ww(this.config?.plugNPlay||{});let o=this.pnp.getEnabledWallets();if(hf(this.config?.debug||!1,"Available wallets",o),!o?.length)throw new Error("No wallets available");this.pendingAction="unlock",this.showWalletModal=!0;return}catch(o){hf(this.config?.debug||!1,"Wallet connection error:",o),this.errorMessage=o instanceof Error?o.message:"Wallet connection failed",this.errorSeverity="error";return}}hf(this.config?.debug||!1,"Creating SDK for payment");let t=Ln(this.config),i=this.cryptoOptions.find(o=>o.symbol===this.selectedSymbol).canisterId||await t.client.getLedgerCanisterIdBySymbol(this.selectedSymbol);hf(this.config?.debug||!1,"Article payment details",{priceUsd:this.config.priceUsd,selectedSymbol:this.selectedSymbol,canisterId:i});let s=await t.sendUsd(this.config.priceUsd,i,{context:"article"});hf(this.config?.debug||!1,"Article payment completed",{resp:s}),this.unlocked=!0,this.succeeded=!0,this.config.onSuccess&&this.config.onSuccess({id:s.transactionId,status:s.status}),this.dispatchEvent(new CustomEvent("icpay-unlock",{detail:{amount:this.config.priceUsd,tx:s},bubbles:!0}))}catch(t){Bo(t,{onError:n=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:n,bubbles:!0})),Mo(n)&&(this.errorMessage=Po(n),this.errorSeverity=ko(n),this.errorAction=Ro(n))}})}finally{this.processing=!1}}}getWalletId(t){return t&&(t.id||t.provider||t.key)||""}getWalletLabel(t){return t&&(t.label||t.name||t.title||t.id)||"Wallet"}getWalletIcon(t){return t&&(t.icon||t.logo||t.image)||null}async connectWithWallet(t){if(this.pnp)try{if(!t)throw new Error("No wallet ID provided");let n=await this.pnp.connect(t);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:t}}))}catch{}this.config={...this.config,connectedWallet:n,actorProvider:(o,a)=>this.pnp.getActor({canisterId:o,idl:a,requiresSigning:!0,anon:!1})},this.showWalletModal=!1;let s=this.pendingAction;this.pendingAction=null,s==="unlock"&&setTimeout(()=>this.unlock(),0)}catch(n){this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}render(){return this.config?ke`
5439
5439
  <div class="card section">
5440
5440
  ${this.config?.progressBar?.enabled!==!1?ke`<icpay-progress-bar mode="${this.config?.progressBar?.mode||"modal"}"></icpay-progress-bar>`:null}
5441
5441
  <div class="container">
@@ -5520,7 +5520,7 @@ Make sure to test your application with a production build as repeat registratio
5520
5520
  border-color: rgba(239, 68, 68, 0.3);
5521
5521
  color: #ef4444;
5522
5522
  }
5523
- `],Se([ur({type:Object})],ni.prototype,"config",2),Se([ur({type:String})],ni.prototype,"title",2),Se([ur({type:String})],ni.prototype,"preview",2),Se([ur({type:String})],ni.prototype,"lockedContent",2),Se([Re()],ni.prototype,"selectedSymbol",2),Se([Re()],ni.prototype,"unlocked",2),Se([Re()],ni.prototype,"succeeded",2),Se([Re()],ni.prototype,"processing",2),Se([Re()],ni.prototype,"availableLedgers",2),Se([Re()],ni.prototype,"errorMessage",2),Se([Re()],ni.prototype,"errorSeverity",2),Se([Re()],ni.prototype,"errorAction",2),Se([Re()],ni.prototype,"walletConnected",2),Se([Re()],ni.prototype,"pendingAction",2),Se([Re()],ni.prototype,"showWalletModal",2),ni=Se([Ui("icpay-article-paywall")],ni);var BM=typeof window<"u",PM=null;function ff(r,e,t){r&&(t!==void 0?console.log(`[ICPay Widget] ${e}`,t):console.log(`[ICPay Widget] ${e}`))}var Ns=class extends mn{constructor(){super(...arguments);this.selectedIndex=0;this.selectedSymbol="ICP";this.processing=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.pnp=null}get cryptoOptions(){return this.config.cryptoOptions?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){super.connectedCallback(),BM&&(ff(this.config?.debug||!1,"Coffee shop connected",{config:this.config}),this.config&&typeof this.config.defaultItemIndex=="number"&&(this.selectedIndex=this.config.defaultItemIndex),this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers())}updated(t){if(t.has("config")&&this.pendingAction&&this.config?.actorProvider){let n=this.pendingAction;this.pendingAction=null,setTimeout(()=>{n==="order"&&this.order()},0)}}async loadVerifiedLedgers(){if(!(!BM||!this.config?.publishableKey))try{let n=await Ln(this.config).client.getVerifiedLedgers();this.availableLedgers=n.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.availableLedgers.length>0&&!this.selectedSymbol&&(this.selectedSymbol=this.availableLedgers[0].symbol)}catch(t){console.warn("Failed to load verified ledgers:",t),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol="ICP")}}selectItem(t){this.selectedIndex=t}selectSymbol(t){this.selectedSymbol=t}get selectedItem(){return this.config?.items?.[this.selectedIndex]||{name:"Loading...",priceUsd:0}}async order(){if(BM&&!this.processing){ff(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,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){ff(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{PM||(PM=(await Promise.resolve().then(()=>(pc(),fc))).PNP),this.pnp=new PM(this.config?.plugNPlay||{});let o=this.pnp.getEnabledWallets();if(ff(this.config?.debug||!1,"Available wallets",o),!o?.length)throw new Error("No wallets available");this.pendingAction="order",this.showWalletModal=!0;return}catch(o){ff(this.config?.debug||!1,"Wallet connection error:",o),this.errorMessage=o instanceof Error?o.message:"Wallet connection failed",this.errorSeverity="error";return}}ff(this.config?.debug||!1,"Creating SDK for payment");let t=Ln(this.config),i=this.cryptoOptions.find(o=>o.symbol===this.selectedSymbol).canisterId||await t.client.getLedgerCanisterIdBySymbol(this.selectedSymbol);ff(this.config?.debug||!1,"Coffee order payment details",{item:this.selectedItem.name,priceUsd:this.selectedItem.priceUsd,selectedSymbol:this.selectedSymbol,canisterId:i});let s=await t.sendUsd(this.selectedItem.priceUsd,i,{context:"coffee",item:this.selectedItem.name});ff(this.config?.debug||!1,"Coffee order payment completed",{resp:s}),this.config.onSuccess&&this.config.onSuccess({id:s.transactionId,status:s.status,item:this.selectedItem.name}),this.dispatchEvent(new CustomEvent("icpay-coffee",{detail:{item:this.selectedItem,tx:s},bubbles:!0}))}catch(t){Bo(t,{onError:n=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:n,bubbles:!0})),Mo(n)&&(this.errorMessage=Po(n),this.errorSeverity=ko(n),this.errorAction=Ro(n))}})}finally{this.processing=!1}}}getWalletId(t){return t&&(t.id||t.provider||t.key)||""}getWalletLabel(t){return t&&(t.label||t.name||t.title||t.id)||"Wallet"}getWalletIcon(t){return t&&(t.icon||t.logo||t.image)||null}async connectWithWallet(t){if(this.pnp)try{if(!t)throw new Error("No wallet ID provided");let n=await this.pnp.connect(t);if(!!!(n&&(n.connected===!0||n.principal||n.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0,this.config={...this.config,connectedWallet:n,actorProvider:(o,a)=>this.pnp.getActor({canisterId:o,idl:a,requiresSigning:!0,anon:!1})},this.showWalletModal=!1;let s=this.pendingAction;this.pendingAction=null,s==="order"&&setTimeout(()=>this.order(),0)}catch(n){this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}render(){return this.config?ke`
5523
+ `],Se([ur({type:Object})],ni.prototype,"config",2),Se([ur({type:String})],ni.prototype,"title",2),Se([ur({type:String})],ni.prototype,"preview",2),Se([ur({type:String})],ni.prototype,"lockedContent",2),Se([Re()],ni.prototype,"selectedSymbol",2),Se([Re()],ni.prototype,"unlocked",2),Se([Re()],ni.prototype,"succeeded",2),Se([Re()],ni.prototype,"processing",2),Se([Re()],ni.prototype,"availableLedgers",2),Se([Re()],ni.prototype,"errorMessage",2),Se([Re()],ni.prototype,"errorSeverity",2),Se([Re()],ni.prototype,"errorAction",2),Se([Re()],ni.prototype,"walletConnected",2),Se([Re()],ni.prototype,"pendingAction",2),Se([Re()],ni.prototype,"showWalletModal",2),ni=Se([Ui("icpay-article-paywall")],ni);var BM=typeof window<"u",PM=null;function ff(r,e,t){r&&(t!==void 0?console.log(`[ICPay Widget] ${e}`,t):console.log(`[ICPay Widget] ${e}`))}var Ns=class extends mn{constructor(){super(...arguments);this.selectedIndex=0;this.selectedSymbol="ICP";this.processing=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.pnp=null}get cryptoOptions(){return this.config.cryptoOptions?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){super.connectedCallback(),BM&&(ff(this.config?.debug||!1,"Coffee shop connected",{config:this.config}),this.config&&typeof this.config.defaultItemIndex=="number"&&(this.selectedIndex=this.config.defaultItemIndex),this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers())}updated(t){if(t.has("config")&&this.pendingAction&&this.config?.actorProvider){let n=this.pendingAction;this.pendingAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}setTimeout(()=>{n==="order"&&this.order()},0)}}async loadVerifiedLedgers(){if(!(!BM||!this.config?.publishableKey))try{let n=await Ln(this.config).client.getVerifiedLedgers();this.availableLedgers=n.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.availableLedgers.length>0&&!this.selectedSymbol&&(this.selectedSymbol=this.availableLedgers[0].symbol)}catch(t){console.warn("Failed to load verified ledgers:",t),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol="ICP")}}selectItem(t){this.selectedIndex=t}selectSymbol(t){this.selectedSymbol=t}get selectedItem(){return this.config?.items?.[this.selectedIndex]||{name:"Loading...",priceUsd:0}}async order(){if(BM&&!this.processing){ff(this.config?.debug||!1,"Coffee order started",{selectedItem:this.selectedItem,selectedSymbol:this.selectedSymbol,useOwnWallet:this.config.useOwnWallet}),this.errorMessage=null,this.errorSeverity=null,this.errorAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"order",type:"sendUsd",amount:this.selectedItem.priceUsd,currency:this.selectedSymbol}}))}catch{}this.processing=!0;try{if(this.config.useOwnWallet){if(!this.config.actorProvider){this.pendingAction="order",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0}));return}}else if(!this.walletConnected){ff(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{PM||(PM=(await Promise.resolve().then(()=>(pc(),fc))).PNP),this.pnp=new PM(this.config?.plugNPlay||{});let o=this.pnp.getEnabledWallets();if(ff(this.config?.debug||!1,"Available wallets",o),!o?.length)throw new Error("No wallets available");this.pendingAction="order",this.showWalletModal=!0;return}catch(o){ff(this.config?.debug||!1,"Wallet connection error:",o),this.errorMessage=o instanceof Error?o.message:"Wallet connection failed",this.errorSeverity="error";return}}ff(this.config?.debug||!1,"Creating SDK for payment");let t=Ln(this.config),i=this.cryptoOptions.find(o=>o.symbol===this.selectedSymbol).canisterId||await t.client.getLedgerCanisterIdBySymbol(this.selectedSymbol);ff(this.config?.debug||!1,"Coffee order payment details",{item:this.selectedItem.name,priceUsd:this.selectedItem.priceUsd,selectedSymbol:this.selectedSymbol,canisterId:i});let s=await t.sendUsd(this.selectedItem.priceUsd,i,{context:"coffee",item:this.selectedItem.name});ff(this.config?.debug||!1,"Coffee order payment completed",{resp:s}),this.config.onSuccess&&this.config.onSuccess({id:s.transactionId,status:s.status,item:this.selectedItem.name}),this.dispatchEvent(new CustomEvent("icpay-coffee",{detail:{item:this.selectedItem,tx:s},bubbles:!0}))}catch(t){Bo(t,{onError:n=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:n,bubbles:!0})),Mo(n)&&(this.errorMessage=Po(n),this.errorSeverity=ko(n),this.errorAction=Ro(n))}})}finally{this.processing=!1}}}getWalletId(t){return t&&(t.id||t.provider||t.key)||""}getWalletLabel(t){return t&&(t.label||t.name||t.title||t.id)||"Wallet"}getWalletIcon(t){return t&&(t.icon||t.logo||t.image)||null}async connectWithWallet(t){if(this.pnp)try{if(!t)throw new Error("No wallet ID provided");let n=await this.pnp.connect(t);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:t}}))}catch{}this.config={...this.config,connectedWallet:n,actorProvider:(o,a)=>this.pnp.getActor({canisterId:o,idl:a,requiresSigning:!0,anon:!1})},this.showWalletModal=!1;let s=this.pendingAction;this.pendingAction=null,s==="order"&&setTimeout(()=>this.order(),0)}catch(n){this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}render(){return this.config?ke`
5524
5524
  <div class="card section">
5525
5525
  ${this.config?.progressBar?.enabled!==!1?ke`<icpay-progress-bar mode="${this.config?.progressBar?.mode||"modal"}"></icpay-progress-bar>`:null}
5526
5526
  <div class="menu">
@@ -5607,7 +5607,7 @@ Make sure to test your application with a production build as repeat registratio
5607
5607
  border-color: rgba(239, 68, 68, 0.3);
5608
5608
  color: #ef4444;
5609
5609
  }
5610
- `],Se([ur({type:Object})],Ns.prototype,"config",2),Se([Re()],Ns.prototype,"selectedIndex",2),Se([Re()],Ns.prototype,"selectedSymbol",2),Se([Re()],Ns.prototype,"processing",2),Se([Re()],Ns.prototype,"availableLedgers",2),Se([Re()],Ns.prototype,"errorMessage",2),Se([Re()],Ns.prototype,"errorSeverity",2),Se([Re()],Ns.prototype,"errorAction",2),Se([Re()],Ns.prototype,"walletConnected",2),Se([Re()],Ns.prototype,"pendingAction",2),Se([Re()],Ns.prototype,"showWalletModal",2),Ns=Se([Ui("icpay-coffee-shop")],Ns);var MM=typeof window<"u",yw=null;function pf(r,e,t){r&&(t!==void 0?console.log(`[ICPay Widget] ${e}`,t):console.log(`[ICPay Widget] ${e}`))}var Ii=class extends mn{constructor(){super(...arguments);this.selectedAmount=10;this.selectedSymbol="ICP";this.raised=0;this.processing=!1;this.succeeded=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.pnp=null}async tryAutoConnectPNP(){try{if(!this.config||this.config?.useOwnWallet)return;let t=localStorage.getItem("icpay:pnp");if(!t)return;let n=JSON.parse(t);if(!n?.provider||!n?.principal)return;yw||(yw=(await Promise.resolve().then(()=>(pc(),fc))).PNP);let i=new yw(this.config?.plugNPlay||{});this.walletConnected=!1,this.config={...this.config,connectedWallet:{owner:n.principal,principal:n.principal,connected:!1}}}catch{}}get amounts(){return this.config?.amountsUsd||[10,25,50,100,250,500]}get cryptoOptions(){return this.config.cryptoOptions?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){super.connectedCallback(),MM&&(pf(this.config?.debug||!1,"Donation thermometer connected",{config:this.config}),this.config&&typeof this.config.defaultAmountUsd=="number"&&(this.selectedAmount=this.config.defaultAmountUsd),this.tryAutoConnectPNP(),this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers())}updated(t){if(t.has("config")&&this.pendingAction&&this.config?.actorProvider){let n=this.pendingAction;this.pendingAction=null,setTimeout(()=>{n==="donate"&&this.donate()},0)}}async loadVerifiedLedgers(){if(!(!MM||!this.config?.publishableKey))try{let n=await Ln(this.config).client.getVerifiedLedgers();this.availableLedgers=n.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.availableLedgers.length>0&&!this.selectedSymbol&&(this.selectedSymbol=this.availableLedgers[0].symbol)}catch(t){console.warn("Failed to load verified ledgers:",t),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol="ICP")}}selectAmount(t){this.selectedAmount=t}selectSymbol(t){this.selectedSymbol=t}get fillPercentage(){let t=Number(this.config?.goalUsd??1e3),n=t>0?t:1e3;return Math.min(this.raised/n*100,100)}async donate(){if(MM&&!this.processing){pf(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,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){pf(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{yw||(yw=(await Promise.resolve().then(()=>(pc(),fc))).PNP),this.pnp=new yw(this.config?.plugNPlay||{});let o=this.pnp.getEnabledWallets();if(pf(this.config?.debug||!1,"Available wallets",o),!o?.length)throw new Error("No wallets available");this.pendingAction="donate",this.showWalletModal=!0;return}catch(o){pf(this.config?.debug||!1,"Wallet connection error:",o),this.errorMessage=o instanceof Error?o.message:"Wallet connection failed",this.errorSeverity="error";return}}pf(this.config?.debug||!1,"Creating SDK for payment");let t=Ln(this.config),i=this.cryptoOptions.find(o=>o.symbol===this.selectedSymbol).canisterId||await t.client.getLedgerCanisterIdBySymbol(this.selectedSymbol);pf(this.config?.debug||!1,"Donation payment details",{amount:this.selectedAmount,selectedSymbol:this.selectedSymbol,canisterId:i});let s=await t.sendUsd(this.selectedAmount,i,{context:"donation"});pf(this.config?.debug||!1,"Donation payment completed",{resp:s}),this.raised+=this.selectedAmount,this.succeeded=!0,this.config.onSuccess&&this.config.onSuccess({id:s.transactionId,status:s.status,raised:this.raised}),this.dispatchEvent(new CustomEvent("icpay-donation",{detail:{amount:this.selectedAmount,tx:s},bubbles:!0}))}catch(t){Bo(t,{onError:n=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:n,bubbles:!0})),Mo(n)&&(this.errorMessage=Po(n),this.errorSeverity=ko(n),this.errorAction=Ro(n))}})}finally{this.processing=!1}}}getWalletId(t){return t&&(t.id||t.provider||t.key)||""}getWalletLabel(t){return t&&(t.label||t.name||t.title||t.id)||"Wallet"}getWalletIcon(t){return t&&(t.icon||t.logo||t.image)||null}async connectWithWallet(t){if(this.pnp)try{if(!t)throw new Error("No wallet ID provided");let n=await this.pnp.connect(t);if(!!!(n&&(n.connected===!0||n.principal||n.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0,this.config={...this.config,connectedWallet:n,actorProvider:(o,a)=>this.pnp.getActor({canisterId:o,idl:a,requiresSigning:!0,anon:!1})},this.showWalletModal=!1;let s=this.pendingAction;this.pendingAction=null,s==="donate"&&setTimeout(()=>this.donate(),0)}catch(n){this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}render(){return this.config?ke`
5610
+ `],Se([ur({type:Object})],Ns.prototype,"config",2),Se([Re()],Ns.prototype,"selectedIndex",2),Se([Re()],Ns.prototype,"selectedSymbol",2),Se([Re()],Ns.prototype,"processing",2),Se([Re()],Ns.prototype,"availableLedgers",2),Se([Re()],Ns.prototype,"errorMessage",2),Se([Re()],Ns.prototype,"errorSeverity",2),Se([Re()],Ns.prototype,"errorAction",2),Se([Re()],Ns.prototype,"walletConnected",2),Se([Re()],Ns.prototype,"pendingAction",2),Se([Re()],Ns.prototype,"showWalletModal",2),Ns=Se([Ui("icpay-coffee-shop")],Ns);var MM=typeof window<"u",yw=null;function pf(r,e,t){r&&(t!==void 0?console.log(`[ICPay Widget] ${e}`,t):console.log(`[ICPay Widget] ${e}`))}var Ii=class extends mn{constructor(){super(...arguments);this.selectedAmount=10;this.selectedSymbol="ICP";this.raised=0;this.processing=!1;this.succeeded=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.pnp=null}async tryAutoConnectPNP(){try{if(!this.config||this.config?.useOwnWallet)return;let t=localStorage.getItem("icpay:pnp");if(!t)return;let n=JSON.parse(t);if(!n?.provider||!n?.principal)return;yw||(yw=(await Promise.resolve().then(()=>(pc(),fc))).PNP);let i=new yw(this.config?.plugNPlay||{});this.walletConnected=!1,this.config={...this.config,connectedWallet:{owner:n.principal,principal:n.principal,connected:!1}}}catch{}}get amounts(){return this.config?.amountsUsd||[10,25,50,100,250,500]}get cryptoOptions(){return this.config.cryptoOptions?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){super.connectedCallback(),MM&&(pf(this.config?.debug||!1,"Donation thermometer connected",{config:this.config}),this.config&&typeof this.config.defaultAmountUsd=="number"&&(this.selectedAmount=this.config.defaultAmountUsd),this.tryAutoConnectPNP(),this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers())}updated(t){if(t.has("config")&&this.pendingAction&&this.config?.actorProvider){let n=this.pendingAction;this.pendingAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}setTimeout(()=>{n==="donate"&&this.donate()},0)}}async loadVerifiedLedgers(){if(!(!MM||!this.config?.publishableKey))try{let n=await Ln(this.config).client.getVerifiedLedgers();this.availableLedgers=n.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.availableLedgers.length>0&&!this.selectedSymbol&&(this.selectedSymbol=this.availableLedgers[0].symbol)}catch(t){console.warn("Failed to load verified ledgers:",t),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol="ICP")}}selectAmount(t){this.selectedAmount=t}selectSymbol(t){this.selectedSymbol=t}get fillPercentage(){let t=Number(this.config?.goalUsd??1e3),n=t>0?t:1e3;return Math.min(this.raised/n*100,100)}async donate(){if(MM&&!this.processing){pf(this.config?.debug||!1,"Donation started",{amount:this.selectedAmount,selectedSymbol:this.selectedSymbol,useOwnWallet:this.config.useOwnWallet}),this.errorMessage=null,this.errorSeverity=null,this.errorAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"donate",type:"sendUsd",amount:this.selectedAmount,currency:this.selectedSymbol}}))}catch{}this.processing=!0;try{if(this.config.useOwnWallet){if(!this.config.actorProvider){this.pendingAction="donate",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0}));return}}else if(!this.walletConnected){pf(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{yw||(yw=(await Promise.resolve().then(()=>(pc(),fc))).PNP),this.pnp=new yw(this.config?.plugNPlay||{});let o=this.pnp.getEnabledWallets();if(pf(this.config?.debug||!1,"Available wallets",o),!o?.length)throw new Error("No wallets available");this.pendingAction="donate",this.showWalletModal=!0;return}catch(o){pf(this.config?.debug||!1,"Wallet connection error:",o),this.errorMessage=o instanceof Error?o.message:"Wallet connection failed",this.errorSeverity="error";return}}pf(this.config?.debug||!1,"Creating SDK for payment");let t=Ln(this.config),i=this.cryptoOptions.find(o=>o.symbol===this.selectedSymbol).canisterId||await t.client.getLedgerCanisterIdBySymbol(this.selectedSymbol);pf(this.config?.debug||!1,"Donation payment details",{amount:this.selectedAmount,selectedSymbol:this.selectedSymbol,canisterId:i});let s=await t.sendUsd(this.selectedAmount,i,{context:"donation"});pf(this.config?.debug||!1,"Donation payment completed",{resp:s}),this.raised+=this.selectedAmount,this.succeeded=!0,this.config.onSuccess&&this.config.onSuccess({id:s.transactionId,status:s.status,raised:this.raised}),this.dispatchEvent(new CustomEvent("icpay-donation",{detail:{amount:this.selectedAmount,tx:s},bubbles:!0}))}catch(t){Bo(t,{onError:n=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:n,bubbles:!0})),Mo(n)&&(this.errorMessage=Po(n),this.errorSeverity=ko(n),this.errorAction=Ro(n))}})}finally{this.processing=!1}}}getWalletId(t){return t&&(t.id||t.provider||t.key)||""}getWalletLabel(t){return t&&(t.label||t.name||t.title||t.id)||"Wallet"}getWalletIcon(t){return t&&(t.icon||t.logo||t.image)||null}async connectWithWallet(t){if(this.pnp)try{if(!t)throw new Error("No wallet ID provided");let n=await this.pnp.connect(t);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:t}}))}catch{}this.config={...this.config,connectedWallet:n,actorProvider:(o,a)=>this.pnp.getActor({canisterId:o,idl:a,requiresSigning:!0,anon:!1})},this.showWalletModal=!1;let s=this.pendingAction;this.pendingAction=null,s==="donate"&&setTimeout(()=>this.donate(),0)}catch(n){this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}render(){return this.config?ke`
5611
5611
  <div class="card section" style="text-align:center;">
5612
5612
  ${this.config?.progressBar?.enabled!==!1?ke`<icpay-progress-bar mode="${this.config?.progressBar?.mode||"modal"}"></icpay-progress-bar>`:null}
5613
5613
  <div class="thermo"><div class="fill" style="height:${this.fillPercentage}%"></div></div>
@@ -5693,7 +5693,7 @@ Make sure to test your application with a production build as repeat registratio
5693
5693
  border-color: rgba(239, 68, 68, 0.3);
5694
5694
  color: #ef4444;
5695
5695
  }
5696
- `],Se([ur({type:Object})],Ii.prototype,"config",2),Se([Re()],Ii.prototype,"selectedAmount",2),Se([Re()],Ii.prototype,"selectedSymbol",2),Se([Re()],Ii.prototype,"raised",2),Se([Re()],Ii.prototype,"processing",2),Se([Re()],Ii.prototype,"succeeded",2),Se([Re()],Ii.prototype,"availableLedgers",2),Se([Re()],Ii.prototype,"errorMessage",2),Se([Re()],Ii.prototype,"errorSeverity",2),Se([Re()],Ii.prototype,"errorAction",2),Se([Re()],Ii.prototype,"walletConnected",2),Se([Re()],Ii.prototype,"pendingAction",2),Se([Re()],Ii.prototype,"showWalletModal",2),Ii=Se([Ui("icpay-donation-thermometer")],Ii);var RM=typeof window<"u",kM=null;function X2(r,e,t){r&&(t!==void 0?console.log(`[ICPay Widget] ${e}`,t):console.log(`[ICPay Widget] ${e}`))}var Ts=class extends mn{constructor(){super(...arguments);this.selectedSymbol=null;this.processing=!1;this.succeeded=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.pnp=null}get cryptoOptions(){return this.config?.cryptoOptions?.length?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){super.connectedCallback(),RM&&(X2(this.config?.debug||!1,"Pay button connected",{config:this.config}),this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers(),this.config?.defaultSymbol&&(this.selectedSymbol=this.config.defaultSymbol))}updated(t){if(t.has("config")&&this.pendingAction&&this.config?.actorProvider){let n=this.pendingAction;this.pendingAction=null,setTimeout(()=>{n==="pay"&&this.pay()},0)}}async loadVerifiedLedgers(){if(!(!RM||!this.config?.publishableKey))try{let n=await Ln(this.config).client.getVerifiedLedgers();this.availableLedgers=n.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||(this.availableLedgers[0]?.symbol??"ICP"))}catch(t){this.dispatchEvent(new CustomEvent("icpay-error",{detail:{message:"Failed to load verified ledgers",cause:t},bubbles:!0})),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||"ICP")}}selectSymbol(t){this.selectedSymbol=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{kM||(kM=(await Promise.resolve().then(()=>(pc(),fc))).PNP),this.pnp=new kM(this.config?.plugNPlay||{});let t=this.pnp.getEnabledWallets();if(X2(this.config?.debug||!1,"Available wallets",t),!t?.length)throw new Error("No wallets available");return this.pendingAction="pay",this.showWalletModal=!0,!1}catch(t){return this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",!1}}getWalletId(t){return t&&(t.id||t.provider||t.key)||""}getWalletLabel(t){return t&&(t.label||t.name||t.title||t.id)||"Wallet"}getWalletIcon(t){return t&&(t.icon||t.logo||t.image)||null}async connectWithWallet(t){if(this.pnp)try{if(X2(this.config?.debug||!1,"Connecting to wallet",{walletId:t}),!t)throw new Error("No wallet ID provided");let n=await this.pnp.connect(t);if(X2(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,this.config={...this.config,connectedWallet:n,actorProvider:(o,a)=>this.pnp.getActor({canisterId:o,idl:a,requiresSigning:!0,anon:!1})},this.showWalletModal=!1;let s=this.pendingAction;this.pendingAction=null,s==="pay"&&setTimeout(()=>this.pay(),0)}catch(n){X2(this.config?.debug||!1,"Wallet connection error",n),this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}renderWalletModal(){if(!this.showWalletModal||!this.pnp)return null;let t=this.pnp.getEnabledWallets()||[];return ke`
5696
+ `],Se([ur({type:Object})],Ii.prototype,"config",2),Se([Re()],Ii.prototype,"selectedAmount",2),Se([Re()],Ii.prototype,"selectedSymbol",2),Se([Re()],Ii.prototype,"raised",2),Se([Re()],Ii.prototype,"processing",2),Se([Re()],Ii.prototype,"succeeded",2),Se([Re()],Ii.prototype,"availableLedgers",2),Se([Re()],Ii.prototype,"errorMessage",2),Se([Re()],Ii.prototype,"errorSeverity",2),Se([Re()],Ii.prototype,"errorAction",2),Se([Re()],Ii.prototype,"walletConnected",2),Se([Re()],Ii.prototype,"pendingAction",2),Se([Re()],Ii.prototype,"showWalletModal",2),Ii=Se([Ui("icpay-donation-thermometer")],Ii);var RM=typeof window<"u",kM=null;function X2(r,e,t){r&&(t!==void 0?console.log(`[ICPay Widget] ${e}`,t):console.log(`[ICPay Widget] ${e}`))}var Ts=class extends mn{constructor(){super(...arguments);this.selectedSymbol=null;this.processing=!1;this.succeeded=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.pnp=null}get cryptoOptions(){return this.config?.cryptoOptions?.length?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){super.connectedCallback(),RM&&(X2(this.config?.debug||!1,"Pay button connected",{config:this.config}),this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers(),this.config?.defaultSymbol&&(this.selectedSymbol=this.config.defaultSymbol))}updated(t){if(t.has("config")&&this.pendingAction&&this.config?.actorProvider){let n=this.pendingAction;this.pendingAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}setTimeout(()=>{n==="pay"&&this.pay()},0)}}async loadVerifiedLedgers(){if(!(!RM||!this.config?.publishableKey))try{let n=await Ln(this.config).client.getVerifiedLedgers();this.availableLedgers=n.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||(this.availableLedgers[0]?.symbol??"ICP"))}catch(t){this.dispatchEvent(new CustomEvent("icpay-error",{detail:{message:"Failed to load verified ledgers",cause:t},bubbles:!0})),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||"ICP")}}selectSymbol(t){this.selectedSymbol=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{kM||(kM=(await Promise.resolve().then(()=>(pc(),fc))).PNP),this.pnp=new kM(this.config?.plugNPlay||{});let t=this.pnp.getEnabledWallets();if(X2(this.config?.debug||!1,"Available wallets",t),!t?.length)throw new Error("No wallets available");return this.pendingAction="pay",this.showWalletModal=!0,!1}catch(t){return this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",!1}}getWalletId(t){return t&&(t.id||t.provider||t.key)||""}getWalletLabel(t){return t&&(t.label||t.name||t.title||t.id)||"Wallet"}getWalletIcon(t){return t&&(t.icon||t.logo||t.image)||null}async connectWithWallet(t){if(this.pnp)try{if(X2(this.config?.debug||!1,"Connecting to wallet",{walletId:t}),!t)throw new Error("No wallet ID provided");let n=await this.pnp.connect(t);if(X2(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:t}}))}catch{}this.config={...this.config,connectedWallet:n,actorProvider:(o,a)=>this.pnp.getActor({canisterId:o,idl:a,requiresSigning:!0,anon:!1})},this.showWalletModal=!1;let s=this.pendingAction;this.pendingAction=null,s==="pay"&&setTimeout(()=>this.pay(),0)}catch(n){X2(this.config?.debug||!1,"Wallet connection error",n),this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}renderWalletModal(){if(!this.showWalletModal||!this.pnp)return null;let t=this.pnp.getEnabledWallets()||[];return ke`
5697
5697
  <div style="position:fixed;inset:0;display:flex;align-items:center;justify-content:center;background:rgba(0,0,0,0.55);z-index:9999">
5698
5698
  <div class="card" style="width:380px;padding:16px;border-radius:12px">
5699
5699
  <div class="label" style="font-weight:700;margin-bottom:12px;text-align:center">Choose Wallet</div>
@@ -5709,7 +5709,7 @@ Make sure to test your application with a production build as repeat registratio
5709
5709
  </button>
5710
5710
  </div>
5711
5711
  </div>
5712
- `}async pay(){if(!(!RM||this.processing)){this.errorMessage=null,this.errorSeverity=null,this.errorAction=null,this.processing=!0;try{if(!await this.ensureWallet())return;let n=Ln(this.config),i=this.selectedSymbol||"ICP",o=this.cryptoOptions.find(u=>u.symbol===i)?.canisterId||await n.client.getLedgerCanisterIdBySymbol(i),a=Number(this.config?.amountUsd??0),c={context:"pay-button"},l=await n.sendUsd(a,o,c);this.config.onSuccess&&this.config.onSuccess({id:l.transactionId,status:l.status}),this.succeeded=!0,this.dispatchEvent(new CustomEvent("icpay-pay",{detail:{amount:a,tx:l},bubbles:!0}))}catch(t){Bo(t,{onError:n=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:n,bubbles:!0})),Mo(n)&&(this.errorMessage=Po(n),this.errorSeverity=ko(n),this.errorAction=Ro(n))}})}finally{this.processing=!1}}}render(){if(!this.config)return ke`<div class="card section">Loading...</div>`;let n=(this.cryptoOptions?.length||0)>1,i=this.config?.showLedgerDropdown,s=i==="dropdown"?"dropdown":"none",o=s!=="none"&&(n||s==="dropdown"),a=s==="dropdown"?"dropdown":n?"buttons":"none",c=this.selectedSymbol||this.config?.defaultSymbol||"ICP",l=typeof this.config?.amountUsd=="number"?`${Number(this.config.amountUsd).toFixed(2)}`:"",d=(this.config?.buttonLabel||(typeof this.config?.amountUsd=="number"?"Pay ${amount} with {symbol}":"Pay with {symbol}")).replace("{amount}",l||"$0.00").replace("{symbol}",c),m=this.config?.progressBar?.enabled!==!1;return ke`
5712
+ `}async pay(){if(!(!RM||this.processing)){this.errorMessage=null,this.errorSeverity=null,this.errorAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"pay",type:"sendUsd",amount:this.config?.amountUsd,currency:this.selectedSymbol||this.config?.defaultSymbol}}))}catch{}this.processing=!0;try{if(!await this.ensureWallet())return;let n=Ln(this.config),i=this.selectedSymbol||"ICP",o=this.cryptoOptions.find(u=>u.symbol===i)?.canisterId||await n.client.getLedgerCanisterIdBySymbol(i),a=Number(this.config?.amountUsd??0),c={context:"pay-button"},l=await n.sendUsd(a,o,c);this.config.onSuccess&&this.config.onSuccess({id:l.transactionId,status:l.status}),this.succeeded=!0,this.dispatchEvent(new CustomEvent("icpay-pay",{detail:{amount:a,tx:l},bubbles:!0}))}catch(t){Bo(t,{onError:n=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:n,bubbles:!0})),Mo(n)&&(this.errorMessage=Po(n),this.errorSeverity=ko(n),this.errorAction=Ro(n))}})}finally{this.processing=!1}}}render(){if(!this.config)return ke`<div class="card section">Loading...</div>`;let n=(this.cryptoOptions?.length||0)>1,i=this.config?.showLedgerDropdown,s=i==="dropdown"?"dropdown":i==="none"?"none":"buttons",o=s!=="none"&&(n||s==="dropdown"),a=s==="dropdown"?"dropdown":n?"buttons":"none",c=this.selectedSymbol||this.config?.defaultSymbol||"ICP",l=typeof this.config?.amountUsd=="number"?`${Number(this.config.amountUsd).toFixed(2)}`:"",d=(this.config?.buttonLabel||(typeof this.config?.amountUsd=="number"?"Pay ${amount} with {symbol}":"Pay with {symbol}")).replace("{amount}",l||"$0.00").replace("{symbol}",c),m=this.config?.progressBar?.enabled!==!1;return ke`
5713
5713
  <div class="card section">
5714
5714
  ${m?ke`
5715
5715
  <icpay-progress-bar></icpay-progress-bar>
@@ -5748,7 +5748,7 @@ Make sure to test your application with a production build as repeat registratio
5748
5748
  .error-message.info { background: rgba(59,130,246,0.1); border-color: rgba(59,130,246,0.3); color: #3b82f6; }
5749
5749
  .error-message.warning { background: rgba(245,158,11,0.1); border-color: rgba(245,158,11,0.3); color: #f59e0b; }
5750
5750
  .error-message.error { background: rgba(239,68,68,0.1); border-color: rgba(239,68,68,0.3); color: #ef4444; }
5751
- `],Se([ur({type:Object})],Ts.prototype,"config",2),Se([Re()],Ts.prototype,"selectedSymbol",2),Se([Re()],Ts.prototype,"processing",2),Se([Re()],Ts.prototype,"succeeded",2),Se([Re()],Ts.prototype,"availableLedgers",2),Se([Re()],Ts.prototype,"errorMessage",2),Se([Re()],Ts.prototype,"errorSeverity",2),Se([Re()],Ts.prototype,"errorAction",2),Se([Re()],Ts.prototype,"walletConnected",2),Se([Re()],Ts.prototype,"pendingAction",2),Se([Re()],Ts.prototype,"showWalletModal",2),Ts=Se([Ui("icpay-pay-button")],Ts);var UM=typeof window<"u",LM=null;function ZKe(r,e,t){r&&(t!==void 0?console.log(`[ICPay Widget] ${e}`,t):console.log(`[ICPay Widget] ${e}`))}var _i=class extends mn{constructor(){super(...arguments);this.amountUsd=0;this.hasUserAmount=!1;this.selectedSymbol=null;this.processing=!1;this.succeeded=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.pnp=null}get cryptoOptions(){return this.config?.cryptoOptions?.length?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){super.connectedCallback(),UM&&(ZKe(this.config?.debug||!1,"Amount input connected",{config:this.config}),this.amountUsd=Number(this.config?.defaultAmountUsd??0),this.hasUserAmount=!1,this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers(),this.config?.defaultSymbol&&(this.selectedSymbol=this.config.defaultSymbol))}updated(t){if(t.has("config")&&(!this.hasUserAmount&&typeof this.config?.defaultAmountUsd=="number"&&(this.amountUsd===0||this.amountUsd==null||Number.isNaN(this.amountUsd))&&(this.amountUsd=Number(this.config.defaultAmountUsd)),!this.selectedSymbol&&this.config?.defaultSymbol&&(this.selectedSymbol=this.config.defaultSymbol),!(this.config?.cryptoOptions&&this.config.cryptoOptions.length>0)&&this.availableLedgers.length===0&&this.loadVerifiedLedgers(),this.pendingAction&&this.config?.actorProvider)){let n=this.pendingAction;this.pendingAction=null,setTimeout(()=>{n==="pay"&&this.pay()},0)}}async loadVerifiedLedgers(){if(!(!UM||!this.config?.publishableKey))try{let n=await Ln(this.config).client.getVerifiedLedgers();this.availableLedgers=n.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||(this.availableLedgers[0]?.symbol??"ICP"))}catch(t){this.dispatchEvent(new CustomEvent("icpay-error",{detail:{message:"Failed to load verified ledgers",cause:t},bubbles:!0})),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||"ICP")}}onInputChange(t){let n=Number(this.config?.stepUsd??.5),i=Math.max(0,Number(t.target.value||0)),s=Math.round(i/n)*n;this.amountUsd=Number(s.toFixed(2)),this.hasUserAmount=!0}selectSymbol(t){this.selectedSymbol=t}isValidAmount(){let t=Number(this.config?.minUsd??.5),n=this.config?.maxUsd!==void 0?Number(this.config.maxUsd):1/0;return this.amountUsd>=t&&this.amountUsd<=n}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{if(LM||(LM=(await Promise.resolve().then(()=>(pc(),fc))).PNP),this.pnp=new LM(this.config?.plugNPlay||{}),!this.pnp.getEnabledWallets()?.length)throw new Error("No wallets available");return this.pendingAction="pay",this.showWalletModal=!0,!1}catch(t){return this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",!1}}getWalletId(t){return t&&(t.id||t.provider||t.key)||""}getWalletLabel(t){return t&&(t.label||t.name||t.title||t.id)||"Wallet"}getWalletIcon(t){return t&&(t.icon||t.logo||t.image)||null}async connectWithWallet(t){if(this.pnp)try{if(!t)throw new Error("No wallet ID provided");let n=await this.pnp.connect(t);if(!!!(n&&(n.connected===!0||n.principal||n.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0,this.config={...this.config,connectedWallet:n,actorProvider:(o,a)=>this.pnp.getActor({canisterId:o,idl:a,requiresSigning:!0,anon:!1})},this.showWalletModal=!1;let s=this.pendingAction;this.pendingAction=null,s==="pay"&&setTimeout(()=>this.pay(),0)}catch(n){this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}async pay(){if(!(!UM||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}this.processing=!0;try{if(!await this.ensureWallet())return;let n=Ln(this.config),i=this.selectedSymbol||"ICP",o=this.cryptoOptions.find(u=>u.symbol===i)?.canisterId||await n.client.getLedgerCanisterIdBySymbol(i),a=Number(this.amountUsd),c={context:"amount-input"},l=await n.sendUsd(a,o,c);this.config.onSuccess&&this.config.onSuccess({id:l.transactionId,status:l.status,amountUsd:a}),this.succeeded=!0,this.dispatchEvent(new CustomEvent("icpay-amount-pay",{detail:{amount:a,tx:l},bubbles:!0}))}catch(t){Bo(t,{onError:n=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:n,bubbles:!0})),Mo(n)&&(this.errorMessage=Po(n),this.errorSeverity=ko(n),this.errorAction=Ro(n))}})}finally{this.processing=!1}}}render(){if(!this.config)return ke`<div class="card section">Loading...</div>`;let t=this.config?.placeholder||"Enter amount in USD",i=(this.config?.buttonLabel||"Pay ${amount} with {symbol}").replace("{amount}",this.amountUsd?`${Number(this.amountUsd).toFixed(2)}`:"$0.00").replace("{symbol}",this.selectedSymbol||this.config?.defaultSymbol||"ICP"),s=this.config?.showLedgerDropdown===!0,o=this.cryptoOptions.find(f=>f.symbol===(this.selectedSymbol||""))?.label||this.cryptoOptions[0]?.label||this.config?.defaultSymbol||"ICP",a=this.config?.progressBar?.mode||"modal",c=this.config?.showLedgerDropdown,l=c==="buttons"?"buttons":c==="none"?"none":"dropdown",d=this.config?.progressBar?.enabled!==!1&&(a==="modal"?!0:this.processing);return ke`
5751
+ `],Se([ur({type:Object})],Ts.prototype,"config",2),Se([Re()],Ts.prototype,"selectedSymbol",2),Se([Re()],Ts.prototype,"processing",2),Se([Re()],Ts.prototype,"succeeded",2),Se([Re()],Ts.prototype,"availableLedgers",2),Se([Re()],Ts.prototype,"errorMessage",2),Se([Re()],Ts.prototype,"errorSeverity",2),Se([Re()],Ts.prototype,"errorAction",2),Se([Re()],Ts.prototype,"walletConnected",2),Se([Re()],Ts.prototype,"pendingAction",2),Se([Re()],Ts.prototype,"showWalletModal",2),Ts=Se([Ui("icpay-pay-button")],Ts);var UM=typeof window<"u",LM=null;function ZKe(r,e,t){r&&(t!==void 0?console.log(`[ICPay Widget] ${e}`,t):console.log(`[ICPay Widget] ${e}`))}var _i=class extends mn{constructor(){super(...arguments);this.amountUsd=0;this.hasUserAmount=!1;this.selectedSymbol=null;this.processing=!1;this.succeeded=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.pnp=null}get cryptoOptions(){return this.config?.cryptoOptions?.length?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){super.connectedCallback(),UM&&(ZKe(this.config?.debug||!1,"Amount input connected",{config:this.config}),this.amountUsd=Number(this.config?.defaultAmountUsd??0),this.hasUserAmount=!1,this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers(),this.config?.defaultSymbol&&(this.selectedSymbol=this.config.defaultSymbol))}updated(t){if(t.has("config")&&(!this.hasUserAmount&&typeof this.config?.defaultAmountUsd=="number"&&(this.amountUsd===0||this.amountUsd==null||Number.isNaN(this.amountUsd))&&(this.amountUsd=Number(this.config.defaultAmountUsd)),!this.selectedSymbol&&this.config?.defaultSymbol&&(this.selectedSymbol=this.config.defaultSymbol),!(this.config?.cryptoOptions&&this.config.cryptoOptions.length>0)&&this.availableLedgers.length===0&&this.loadVerifiedLedgers(),this.pendingAction&&this.config?.actorProvider)){let n=this.pendingAction;this.pendingAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}setTimeout(()=>{n==="pay"&&this.pay()},0)}}async loadVerifiedLedgers(){if(!(!UM||!this.config?.publishableKey))try{let n=await Ln(this.config).client.getVerifiedLedgers();this.availableLedgers=n.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||(this.availableLedgers[0]?.symbol??"ICP"))}catch(t){this.dispatchEvent(new CustomEvent("icpay-error",{detail:{message:"Failed to load verified ledgers",cause:t},bubbles:!0})),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||"ICP")}}onInputChange(t){let n=Number(this.config?.stepUsd??.5),i=Math.max(0,Number(t.target.value||0)),s=Math.round(i/n)*n;this.amountUsd=Number(s.toFixed(2)),this.hasUserAmount=!0}selectSymbol(t){this.selectedSymbol=t}isValidAmount(){let t=Number(this.config?.minUsd??.5),n=this.config?.maxUsd!==void 0?Number(this.config.maxUsd):1/0;return this.amountUsd>=t&&this.amountUsd<=n}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{if(LM||(LM=(await Promise.resolve().then(()=>(pc(),fc))).PNP),this.pnp=new LM(this.config?.plugNPlay||{}),!this.pnp.getEnabledWallets()?.length)throw new Error("No wallets available");return this.pendingAction="pay",this.showWalletModal=!0,!1}catch(t){return this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",!1}}getWalletId(t){return t&&(t.id||t.provider||t.key)||""}getWalletLabel(t){return t&&(t.label||t.name||t.title||t.id)||"Wallet"}getWalletIcon(t){return t&&(t.icon||t.logo||t.image)||null}async connectWithWallet(t){if(this.pnp)try{if(!t)throw new Error("No wallet ID provided");let n=await this.pnp.connect(t);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:t}}))}catch{}this.config={...this.config,connectedWallet:n,actorProvider:(o,a)=>this.pnp.getActor({canisterId:o,idl:a,requiresSigning:!0,anon:!1})},this.showWalletModal=!1;let s=this.pendingAction;this.pendingAction=null,s==="pay"&&setTimeout(()=>this.pay(),0)}catch(n){this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}async pay(){if(!(!UM||this.processing)){if(this.errorMessage=null,this.errorSeverity=null,this.errorAction=null,!this.isValidAmount()){this.errorMessage="Please enter a valid amount",this.errorSeverity="warning";return}try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"pay",type:"sendUsd",amount:this.amountUsd,currency:this.selectedSymbol||this.config?.defaultSymbol}}))}catch{}this.processing=!0;try{if(!await this.ensureWallet())return;let n=Ln(this.config),i=this.selectedSymbol||"ICP",o=this.cryptoOptions.find(u=>u.symbol===i)?.canisterId||await n.client.getLedgerCanisterIdBySymbol(i),a=Number(this.amountUsd),c={context:"amount-input"},l=await n.sendUsd(a,o,c);this.config.onSuccess&&this.config.onSuccess({id:l.transactionId,status:l.status,amountUsd:a}),this.succeeded=!0,this.dispatchEvent(new CustomEvent("icpay-amount-pay",{detail:{amount:a,tx:l},bubbles:!0}))}catch(t){Bo(t,{onError:n=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:n,bubbles:!0})),Mo(n)&&(this.errorMessage=Po(n),this.errorSeverity=ko(n),this.errorAction=Ro(n))}})}finally{this.processing=!1}}}render(){if(!this.config)return ke`<div class="card section">Loading...</div>`;let t=this.config?.placeholder||"Enter amount in USD",i=(this.config?.buttonLabel||"Pay ${amount} with {symbol}").replace("{amount}",this.amountUsd?`${Number(this.amountUsd).toFixed(2)}`:"$0.00").replace("{symbol}",this.selectedSymbol||this.config?.defaultSymbol||"ICP"),s=this.config?.showLedgerDropdown===!0,o=this.cryptoOptions.find(f=>f.symbol===(this.selectedSymbol||""))?.label||this.cryptoOptions[0]?.label||this.config?.defaultSymbol||"ICP",a=this.config?.progressBar?.mode||"modal",c=this.config?.showLedgerDropdown,l=c==="buttons"?"buttons":c==="none"?"none":"dropdown",d=this.config?.progressBar?.enabled!==!1&&(a==="modal"?!0:this.processing);return ke`
5752
5752
  <div class="card section">
5753
5753
  ${d?ke`<icpay-progress-bar mode="${a}"></icpay-progress-bar>`:null}
5754
5754