@ic-pay/icpay-widget 0.1.79 → 0.1.81

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -217,6 +217,9 @@ declare class ICPayProgressBar extends LitElement {
217
217
  private progressPercent;
218
218
  private verticalPercent;
219
219
  private getStepIcon;
220
+ private getStepIndexByKey;
221
+ private setLoadingByKey;
222
+ private completeByKey;
220
223
  private transformErrorMessage;
221
224
  private renderConfetti;
222
225
  private renderSuccessState;
@@ -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:"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.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;if(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.failed){for(let o=this.activeIndex;o<this.currentSteps.length;o++)this.updateStepStatus(o,"completed");this.activeIndex=this.currentSteps.length-1,this.completed=!0,this.showSuccess=!0,this.showConfetti=!0}this.dispatchEvent(new CustomEvent("icpay-progress-widget-payment",{detail:{amount: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;if(console.log("ICPay Progress: Widget unlock event received:",t.detail),!this.failed){for(let s=this.activeIndex;s<this.currentSteps.length;s++)this.updateStepStatus(s,"completed");this.activeIndex=this.currentSteps.length-1,this.completed=!0,this.showSuccess=!0,this.showConfetti=!0}this.dispatchEvent(new CustomEvent("icpay-progress-widget-unlock",{detail:{amount:n,currency:i,step:this.activeIndex},bubbles:!0}))};this.onWidgetTip=t=>{let n=t?.detail?.amount,i=t?.detail?.currency;if(console.log("ICPay Progress: Widget tip event received:",t.detail),!this.failed){for(let s=this.activeIndex;s<this.currentSteps.length;s++)this.updateStepStatus(s,"completed");this.activeIndex=this.currentSteps.length-1,this.completed=!0,this.showSuccess=!0,this.showConfetti=!0}this.dispatchEvent(new CustomEvent("icpay-progress-widget-tip",{detail:{amount:n,currency:i,step:this.activeIndex},bubbles:!0}))};this.onWidgetDonation=t=>{let n=t?.detail?.amount,i=t?.detail?.currency;if(console.log("ICPay Progress: Widget donation event received:",t.detail),!this.failed){for(let s=this.activeIndex;s<this.currentSteps.length;s++)this.updateStepStatus(s,"completed");this.activeIndex=this.currentSteps.length-1,this.completed=!0,this.showSuccess=!0,this.showConfetti=!0}this.dispatchEvent(new CustomEvent("icpay-progress-widget-donation",{detail:{amount:n,currency:i,step:this.activeIndex},bubbles:!0}))};this.onWidgetCoffee=t=>{let n=t?.detail?.amount,i=t?.detail?.currency;if(console.log("ICPay Progress: Widget coffee event received:",t.detail),!this.failed){for(let s=this.activeIndex;s<this.currentSteps.length;s++)this.updateStepStatus(s,"completed");this.activeIndex=this.currentSteps.length-1,this.completed=!0,this.showSuccess=!0,this.showConfetti=!0}this.dispatchEvent(new CustomEvent("icpay-progress-widget-coffee",{detail:{amount: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.setLoadingByKey("wallet"),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.failed&&!this.completed&&(n==="sendFundsToLedger"?this.setLoadingByKey("transfer"):n==="notifyLedgerTransaction"&&this.setLoadingByKey("verify"))};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&&(n==="getLedgerBalance"?(this.completeByKey("init"),this.setLoadingByKey("await")):n==="sendFundsToLedger"?(this.completeByKey("transfer"),this.setLoadingByKey("verify")):n==="notifyLedgerTransaction"&&(this.completeByKey("verify"),this.setLoadingByKey("confirm"))))};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.completeByKey("await"),this.setLoadingByKey("transfer")),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.completeByKey("transfer"),this.completeByKey("await"),this.completeByKey("init"),this.completeByKey("verify"),this.completeByKey("confirm"),this.completed=!0,this.showSuccess=!0,this.showConfetti=!0,this.dispatchEvent(new CustomEvent("icpay-progress-completed",{detail:{transactionId: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.completeByKey("wallet"),this.setLoadingByKey("init"),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;if(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.failed){for(let o=this.activeIndex;o<this.currentSteps.length;o++)this.updateStepStatus(o,"completed");this.activeIndex=this.currentSteps.length-1,this.completed=!0,this.showSuccess=!0,this.showConfetti=!0}this.dispatchEvent(new CustomEvent("icpay-progress-widget-payment",{detail:{amount: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;if(console.log("ICPay Progress: Widget unlock event received:",t.detail),!this.failed){for(let s=this.activeIndex;s<this.currentSteps.length;s++)this.updateStepStatus(s,"completed");this.activeIndex=this.currentSteps.length-1,this.completed=!0,this.showSuccess=!0,this.showConfetti=!0}this.dispatchEvent(new CustomEvent("icpay-progress-widget-unlock",{detail:{amount:n,currency:i,step:this.activeIndex},bubbles:!0}))};this.onWidgetTip=t=>{let n=t?.detail?.amount,i=t?.detail?.currency;if(console.log("ICPay Progress: Widget tip event received:",t.detail),!this.failed){for(let s=this.activeIndex;s<this.currentSteps.length;s++)this.updateStepStatus(s,"completed");this.activeIndex=this.currentSteps.length-1,this.completed=!0,this.showSuccess=!0,this.showConfetti=!0}this.dispatchEvent(new CustomEvent("icpay-progress-widget-tip",{detail:{amount:n,currency:i,step:this.activeIndex},bubbles:!0}))};this.onWidgetDonation=t=>{let n=t?.detail?.amount,i=t?.detail?.currency;if(console.log("ICPay Progress: Widget donation event received:",t.detail),!this.failed){for(let s=this.activeIndex;s<this.currentSteps.length;s++)this.updateStepStatus(s,"completed");this.activeIndex=this.currentSteps.length-1,this.completed=!0,this.showSuccess=!0,this.showConfetti=!0}this.dispatchEvent(new CustomEvent("icpay-progress-widget-donation",{detail:{amount:n,currency:i,step:this.activeIndex},bubbles:!0}))};this.onWidgetCoffee=t=>{let n=t?.detail?.amount,i=t?.detail?.currency;if(console.log("ICPay Progress: Widget coffee event received:",t.detail),!this.failed){for(let s=this.activeIndex;s<this.currentSteps.length;s++)this.updateStepStatus(s,"completed");this.activeIndex=this.currentSteps.length-1,this.completed=!0,this.showSuccess=!0,this.showConfetti=!0}this.dispatchEvent(new CustomEvent("icpay-progress-widget-coffee",{detail:{amount: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"}}getStepIndexByKey(t){return this.currentSteps.findIndex(n=>n.key===t)}setLoadingByKey(t){let n=this.getStepIndexByKey(t);n>=0&&(this.activeIndex=n,this.updateStepStatus(n,"loading"))}completeByKey(t){let n=this.getStepIndexByKey(t);n>=0&&(this.updateStepStatus(n,"completed"),this.activeIndex=n)}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
@@ -5347,24 +5347,24 @@ 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;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`
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(){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";return ke`
5351
5351
  <div class="card section" style="text-align:center;">
5352
- ${this.config?.progressBar?.enabled!==!1?ke`<icpay-progress-bar mode="${this.config?.progressBar?.mode||"modal"}"></icpay-progress-bar>`:null}
5352
+ ${this.config?.progressBar?.enabled!==!1?ke`<icpay-progress-bar></icpay-progress-bar>`:null}
5353
5353
  <div class="jar"><div class="fill" style="height:${this.fillPercentage}%"></div></div>
5354
5354
  <div class="label">Total Tips: $${this.total}</div>
5355
5355
 
5356
5356
  <div class="amounts">
5357
- ${this.amounts.map(t=>ke`<div class="chip ${this.selectedAmount===t?"selected":""}" @click=${()=>this.selectAmount(t)}>$${t}</div>`)}
5357
+ ${this.amounts.map(c=>ke`<div class="chip ${this.selectedAmount===c?"selected":""}" @click=${()=>this.selectAmount(c)}>$${c}</div>`)}
5358
5358
  </div>
5359
5359
 
5360
- ${this.config?.showLedgerDropdown===!0?ke`
5360
+ ${o?ke`
5361
5361
  <div>
5362
5362
  <icpay-token-selector
5363
5363
  .options=${this.cryptoOptions}
5364
5364
  .value=${this.selectedSymbol||""}
5365
5365
  .defaultSymbol=${this.config?.defaultSymbol||"ICP"}
5366
- mode=${this.config?.showLedgerDropdown||"buttons"}
5367
- @icpay-token-change=${t=>this.selectSymbol(t.detail.symbol)}
5366
+ mode=${a}
5367
+ @icpay-token-change=${c=>this.selectSymbol(c.detail.symbol)}
5368
5368
  ></icpay-token-selector>
5369
5369
  </div>
5370
5370
  `:null}
@@ -5385,15 +5385,15 @@ Make sure to test your application with a production build as repeat registratio
5385
5385
  `:""}
5386
5386
  </div>
5387
5387
  `:""}
5388
- ${(()=>{let t=this.pnp?.getEnabledWallets?.()||[];return this.showWalletModal&&this.pnp?ke`
5388
+ ${(()=>{let c=this.pnp?.getEnabledWallets?.()||[];return this.showWalletModal&&this.pnp?ke`
5389
5389
  <div style="position:fixed;inset:0;display:flex;align-items:center;justify-content:center;background:rgba(0,0,0,0.55);z-index:9999">
5390
5390
  <div class="card section" style="width:380px;border-radius:12px">
5391
5391
  <div class="label" style="font-weight:700;margin-bottom:12px;text-align:center">Choose Wallet</div>
5392
5392
  <div style="display:grid;grid-template-columns:1fr;gap:10px;margin-bottom:12px">
5393
- ${t.map(n=>{let i=this.getWalletId(n),s=this.getWalletLabel(n),o=this.getWalletIcon(n);return ke`
5394
- <button class="pay-button" style="display:flex;align-items:center;gap:10px;justify-content:center;padding:12px" @click=${()=>this.connectWithWallet(i)}>
5395
- ${o?ke`<img src="${o}" alt="${s}" style="width:20px;height:20px;border-radius:4px;object-fit:contain;background:transparent" />`:""}
5396
- <span>${s}</span>
5393
+ ${c.map(l=>{let u=this.getWalletId(l),d=this.getWalletLabel(l),f=this.getWalletIcon(l);return ke`
5394
+ <button class="pay-button" style="display:flex;align-items:center;gap:10px;justify-content:center;padding:12px" @click=${()=>this.connectWithWallet(u)}>
5395
+ ${f?ke`<img src="${f}" alt="${d}" style="width:20px;height:20px;border-radius:4px;object-fit:contain;background:transparent" />`:""}
5396
+ <span>${d}</span>
5397
5397
  </button>`})}
5398
5398
  </div>
5399
5399
  <button class="pay-button" style="background:#6b7280;color:#f9fafb" @click=${()=>{this.showWalletModal=!1}}>
@@ -5403,7 +5403,7 @@ Make sure to test your application with a production build as repeat registratio
5403
5403
  </div>
5404
5404
  `:null})()}
5405
5405
  </div>
5406
- `:ke`<div class="card section">Loading...</div>`}};Ci.styles=[to,Hn`
5406
+ `}};Ci.styles=[to,Hn`
5407
5407
  .jar { width: 120px; height: 160px; margin: 0 auto 12px; position: relative; background: linear-gradient(135deg, #374151 0%, #4b5563 100%); border-radius: 0 0 60px 60px; border: 3px solid #6b7280; border-top: 8px solid #6b7280; overflow: hidden; }
5408
5408
  .fill { position: absolute; bottom: 0; left: 0; right: 0; background: linear-gradient(135deg, #d1d5db 0%, #9ca3af 100%); transition: height 0.8s ease; height: 0%; }
5409
5409
  .amounts { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; margin: 12px 0; }