@ic-pay/icpay-widget 0.1.78 → 0.1.80
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 +3 -0
- package/dist/index.global.js +1 -1
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +47 -47
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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;
|
package/dist/index.global.js
CHANGED
|
@@ -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.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.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.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.setLoadingByKey("transfer"):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.setLoadingByKey("verify"),this.completeByKey("verify"),this.setLoadingByKey("confirm"),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
|