@ic-pay/icpay-widget 1.1.56 → 1.2.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,1502 +0,0 @@
1
- import{a as n}from"./chunk-LTEQ7OUJ.js";import{css as _e}from"lit";var K=_e`
2
- :host {
3
- --icpay-primary: #f9fafb;
4
- --icpay-secondary: #e5e7eb;
5
- --icpay-accent: #9ca3af;
6
- --icpay-text: #f9fafb;
7
- --icpay-muted: #9ca3af;
8
- --icpay-surface: #1f2937;
9
- --icpay-surface-alt: #374151;
10
- --icpay-border: #4b5563;
11
- --icpay-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
12
- display: block;
13
- font-family: var(--icpay-font);
14
- }
15
-
16
- .icpay-card {
17
- background: var(--icpay-surface);
18
- border: 1px solid var(--icpay-border);
19
- border-radius: 16px;
20
- box-shadow: 0 25px 50px rgba(0, 0, 0, 0.35);
21
- }
22
-
23
- .icpay-section {
24
- padding: 20px;
25
- }
26
-
27
- .pay-button {
28
- width: 100%;
29
- background: linear-gradient(135deg, var(--icpay-primary) 0%, var(--icpay-secondary) 100%);
30
- color: #111827;
31
- border: 1px solid #d1d5db;
32
- border-radius: 16px;
33
- padding: 16px;
34
- font-size: 16px;
35
- font-weight: 600;
36
- cursor: pointer;
37
- transition: all 0.3s ease;
38
- box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
39
- }
40
-
41
- .pay-button:hover {
42
- transform: translateY(-2px);
43
- box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
44
- background: linear-gradient(135deg, #ffffff 0%, #f3f4f6 100%);
45
- }
46
-
47
- .pay-button.processing {
48
- background: #6b7280;
49
- color: #f9fafb;
50
- border-color: #6b7280;
51
- cursor: not-allowed;
52
- animation: pulse 2s infinite;
53
- }
54
-
55
- @keyframes pulse {
56
- 0%, 100% { opacity: 1; }
57
- 50% { opacity: 0.7; }
58
- }
59
- `;function de(r,d){if(!r||!d)return;let e=d.primaryColor||void 0,t=d.secondaryColor||void 0,i=(P,V)=>{V&&r.style.setProperty(P,V)};i("--icpay-primary",e),i("--icpay-secondary",t);let s=P=>{if(!P)return null;let V=P.replace("#",""),G=V.length===3?V.split("").map(Pe=>Pe+Pe).join(""):V,X=parseInt(G,16),ce=X>>16&255,ze=X>>8&255,Ke=X&255;return{r:ce,g:ze,b:Ke}},l=(P=>{let V=s(P);if(!V)return 0;let G=X=>{let ce=X/255;return ce<=.03928?ce/12.92:Math.pow((ce+.055)/1.055,2.4)};return .2126*G(V.r)+.7152*G(V.g)+.0722*G(V.b)})(e||t)>.6,p=d.surfaceColor||(l?"#f3f4f6":"#1f2937"),c=d.surfaceAltColor||(l?"#e5e7eb":"#374151"),h=d.borderColor||(l?"#d1d5db":"#4b5563"),$=d.textColor||(l?"#111827":"#f9fafb"),A=d.accentColor||t||e||(l?"#6b7280":"#9ca3af"),se=d.mutedTextColor||(l?"#6b7280":"#9ca3af");i("--icpay-accent",A),i("--icpay-text",$),i("--icpay-muted",se),i("--icpay-surface",p),i("--icpay-surface-alt",c),i("--icpay-border",h)}import{Icpay as Ue}from"@ic-pay/icpay-sdk";var Re=typeof window<"u";function Ee(r,d,e){r&&(e!==void 0?console.log(`[ICPay Widget] ${d}`,e):console.log(`[ICPay Widget] ${d}`))}function g(r){if(!Re)return{client:{},quoteUsd:async()=>({tokenAmountDecimals:"0"}),sendUsd:async()=>({transactionId:"0",status:"pending"}),startOnrampUsd:async()=>({transactionId:"0",status:"pending",metadata:{onramp:{sessionId:null}}}),notifyIntentUntilComplete:()=>({stop:()=>{}})};Ee(r.debug||!1,"Creating SDK with config:",r);let d={publishableKey:r.publishableKey};r.enableEvents!==void 0?d.enableEvents=r.enableEvents:d.enableEvents=!0,r.apiUrl&&(d.apiUrl=r.apiUrl),r.icHost&&(d.icHost=r.icHost),r.actorProvider&&(d.actorProvider=r.actorProvider),r.connectedWallet&&(d.connectedWallet=r.connectedWallet),r.onrampDisabled!==void 0&&(d.onrampDisabled=r.onrampDisabled),r.debug!==void 0&&(d.debug=r.debug),Ee(r.debug||!1,"Filtered SDK config:",d);try{let a=function(l,p,c){return t.notifyPaymentIntentOnRamp({paymentIntentId:l,intervalMs:p,orderId:c})};var e=a;Ee(r.debug||!1,"typeof Icpay:",typeof Ue);let t=new Ue(d);if(Re){let l=t,p=c=>{l.addEventListener(c,h=>{window.dispatchEvent(new CustomEvent(c,{detail:h?.detail??h}))})};["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(p)}async function i(l,p){return t.calculateTokenAmountFromUSD({usdAmount:l,ledgerCanisterId:p})}async function s(l,p,c){let h={...r.metadata,...c||{}};return t.createPaymentUsd({usdAmount:l,ledgerCanisterId:p,metadata:h})}async function o(l,p,c){let h={...r.metadata,...c||{}};return t.createPaymentUsd({usdAmount:l,ledgerCanisterId:p,metadata:h,onrampPayment:!0})}return{client:t,quoteUsd:i,sendUsd:s,startOnrampUsd:o,notifyIntentUntilComplete:a}}catch(t){throw Ee(r.debug||!1,"Error creating SDK:",t),t}}import{LitElement as Fe,html as x,css as je}from"lit";import{customElement as He,property as oe,state as _}from"lit/decorators.js";function u(r,d,e){r&&(e!==void 0?console.log(d,e):console.log(d))}var Ve=[{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"}],y=class extends Fe{constructor(){super(...arguments);this.open=!1;this.steps=Ve;this.amount=0;this.currency="";this.ledgerSymbol="";this.debug=!1;this.activeIndex=0;this.completed=!1;this.failed=!1;this.errorMessage=null;this.showSuccess=!1;this.showConfetti=!1;this.currentSteps=[];this.currentAmount=0;this.currentCurrency="";this.currentLedgerSymbol="";this.confirmLoadingStartedAt=null;this.progressionTimer=null;this.currentWalletType=null;this.showWalletSelector=!1;this.isTransitioning=!1;this.onMethodStart=e=>{let t=e?.detail?.name||"",i=e?.detail?.type||"";if(u(this.debug,"ICPay Progress: Method start event received:",e.detail),t==="createPayment"||t==="createPaymentUsd"||t==="sendUsd"||t==="pay"||t==="unlock"||t==="tip"||t==="donate"||t==="order"){if(this.open=!0,this.activeIndex=0,this.completed=!1,this.failed=!1,this.errorMessage=null,this.showSuccess=!1,this.showConfetti=!1,this.showWalletSelector=!1,this.isTransitioning=!1,this.currentSteps=this.currentSteps.map(s=>({...s,status:"pending"})),i==="onramp"){let s=this.getStepIndexByKey("wallet");s>=0&&(this.currentSteps[s]={...this.currentSteps[s],label:"Transak Started",tooltip:"Awaiting Transak information"})}this.setLoadingByKey("wallet"),e?.detail?.amount!==void 0&&(this.currentAmount=e.detail.amount,this.amount=e.detail.amount,u(this.debug,"ICPay Progress: Amount updated to:",e.detail.amount)),e?.detail?.currency&&(this.currentCurrency=e.detail.currency,this.currency=e.detail.currency,u(this.debug,"ICPay Progress: Currency updated to:",e.detail.currency)),e?.detail?.ledgerSymbol&&(this.currentLedgerSymbol=e.detail.ledgerSymbol,this.ledgerSymbol=e.detail.ledgerSymbol,u(this.debug,"ICPay Progress: Current state after method start:",{activeIndex:this.activeIndex,currentAmount:this.currentAmount,currentCurrency:this.currentCurrency,currentLedgerSymbol:this.currentLedgerSymbol})),u(this.debug,"ICPay Progress: Waiting for wallet confirmation before starting progression"),this.requestUpdate()}!this.failed&&!this.completed&&(t==="sendFundsToLedger"?(this.completeByKey("wallet"),this.completeByKey("init"),this.completeByKey("await"),this.setLoadingByKey("transfer")):t==="notifyLedgerTransaction"&&(this.completeByKey("wallet"),this.completeByKey("init"),this.completeByKey("await"),this.completeByKey("transfer"),this.setLoadingByKey("verify")))};this.onMethodSuccess=e=>{let t=e?.detail?.name||"";(t==="createPayment"||t==="createPaymentUsd"||t==="sendUsd"||t==="pay"||t==="unlock"||t==="tip"||t==="donate"||t==="order")&&this.dispatchEvent(new CustomEvent("icpay-progress-method-success",{detail:{methodName:t,step:this.activeIndex},bubbles:!0})),!this.failed&&!this.completed&&(t==="getLedgerBalance"?(this.completeByKey("wallet"),this.completeByKey("init"),this.setLoadingByKey("await")):t==="sendFundsToLedger"?(this.completeByKey("wallet"),this.completeByKey("init"),this.completeByKey("await"),this.completeByKey("transfer"),this.setLoadingByKey("verify")):t==="notifyLedgerTransaction"&&(this.completeByKey("wallet"),this.completeByKey("init"),this.completeByKey("await"),this.completeByKey("transfer"),this.completeByKey("verify"),this.setLoadingByKey("confirm")))};this.onTransactionCreated=e=>{let t=e?.detail?.transactionId||e?.detail?.id;u(this.debug,"ICPay Progress: Transaction created event received:",e.detail),!this.failed&&!this.completed&&(this.completeByKey("wallet"),this.completeByKey("init"),this.completeByKey("await"),this.setLoadingByKey("transfer")),this.dispatchEvent(new CustomEvent("icpay-progress-transaction-created",{detail:{transactionId:t,step:this.activeIndex},bubbles:!0}))};this.onTransactionUpdated=e=>{let t=e?.detail?.status||"pending",i=e?.detail?.transactionId||e?.detail?.id;u(this.debug,"ICPay Progress: Transaction updated event received:",e.detail),!this.failed&&this.completed,this.dispatchEvent(new CustomEvent("icpay-progress-transaction-updated",{detail:{status:t,transactionId:i,step:this.activeIndex},bubbles:!0}))};this.onTransactionCompleted=e=>{let t=e?.detail?.transactionId||e?.detail?.id,i=e?.detail?.status||"completed";u(this.debug,"ICPay Progress: Transaction completed event received:",e.detail),u(this.debug,"ICPay Progress: Current state when transaction completed:",{activeIndex:this.activeIndex,completed:this.completed,failed:this.failed,showSuccess:this.showSuccess}),this.completeByKey("transfer"),this.completeByKey("await"),this.completeByKey("init"),this.completeByKey("verify"),this.completeByKey("confirm"),this.completed=!0,this.showSuccess=!0,this.showConfetti=!0,this.dispatchEvent(new CustomEvent("icpay-progress-completed",{detail:{transactionId:t,status:i,amount:this.currentAmount||this.amount,currency:this.currentCurrency||this.currency,ledgerSymbol:this.currentLedgerSymbol||this.ledgerSymbol},bubbles:!0})),setTimeout(()=>{this.showConfetti=!1},3e3)};this.onTransactionFailed=e=>{let t=e?.detail?.message||e?.detail?.error?.message||"Transaction failed",i=e?.detail?.error?.code||e?.detail?.code||"UNKNOWN_ERROR",s=e?.detail?.transactionId||e?.detail?.id;u(this.debug,"ICPay Progress: Transaction failed event received:",e.detail),this.failed=!0,this.errorMessage=this.transformErrorMessage(t),this.showSuccess=!1,this.updateStepStatus(this.activeIndex,"error",t),this.stopAutomaticProgression(),this.open=!0,this.dispatchEvent(new CustomEvent("icpay-progress-failed",{detail:{errorMessage:t,errorCode:i,transactionId:s,step:this.activeIndex},bubbles:!0}))};this.onTransactionMismatched=e=>{let t=e?.detail?.requestedAmount,i=e?.detail?.paidAmount,s=e?.detail?.transactionId||e?.detail?.id;this.failed=!0;let o=t!=null?String(t):"unknown",a=i!=null?String(i):"unknown";this.errorMessage=`Amount mismatch. Requested ${o}, paid ${a}.`,this.showSuccess=!1,this.updateStepStatus(this.activeIndex,"error",this.errorMessage),this.stopAutomaticProgression(),this.open=!0,this.dispatchEvent(new CustomEvent("icpay-progress-failed",{detail:{errorMessage:this.errorMessage,errorCode:"MISMATCHED_AMOUNT",transactionId:s,step:this.activeIndex,requestedAmount:t,paidAmount:i},bubbles:!0}))};this.onMethodError=e=>{let t=e?.detail?.name||"",i=e?.detail?.error?.message||e?.detail?.message||"An error occurred",s=e?.detail?.error?.code||e?.detail?.code||"METHOD_ERROR";u(this.debug,"ICPay Progress: Method error event received:",e.detail),(t?.startsWith("createPayment")||t==="sendUsd"||t==="pay"||t==="unlock"||t==="tip"||t==="donate"||t==="order")&&(this.failed=!0,this.errorMessage=this.transformErrorMessage(i),this.showSuccess=!1,this.updateStepStatus(this.activeIndex,"error",i),this.stopAutomaticProgression(),this.open=!0,this.dispatchEvent(new CustomEvent("icpay-progress-error",{detail:{methodName:t,errorMessage:i,errorCode:s,step:this.activeIndex},bubbles:!0})))};this.onSDKError=e=>{let t=e?.detail?.message||"SDK error occurred",i=e?.detail?.code||"SDK_ERROR";u(this.debug,"ICPay Progress: SDK error event received:",e.detail),this.failed=!0,this.errorMessage=this.transformErrorMessage(t),this.showSuccess=!1,this.updateStepStatus(this.activeIndex,"error",t),this.stopAutomaticProgression(),this.open=!0,this.dispatchEvent(new CustomEvent("icpay-progress-sdk-error",{detail:{errorMessage:t,errorCode:i,step:this.activeIndex},bubbles:!0}))};this.onWalletConnected=e=>{let t=e?.detail?.walletType||"unknown";u(this.debug,"ICPay Progress: Wallet connected event received:",e.detail),this.completeByKey("wallet"),this.setLoadingByKey("init"),this.startTransitionToProgress(),this.dispatchEvent(new CustomEvent("icpay-progress-wallet-connected",{detail:{walletType:t,step:this.activeIndex},bubbles:!0})),this.currentWalletType=t};this.onWalletDisconnected=e=>{let t=e?.detail?.walletType||"unknown";u(this.debug,"ICPay Progress: Wallet disconnected event received:",e.detail),this.dispatchEvent(new CustomEvent("icpay-progress-wallet-disconnected",{detail:{walletType:t,step:this.activeIndex},bubbles:!0})),this.currentWalletType=null};this.onBalanceCheck=e=>{let t=e?.detail?.hasBalance||!1,i=e?.detail?.balance||0;u(this.debug,"ICPay Progress: Balance check event received:",e.detail),t||(this.failed=!0,this.errorMessage="Insufficient balance for transaction",this.updateStepStatus(this.activeIndex,"error","Insufficient balance for transaction"),this.stopAutomaticProgression(),this.showWalletSelector=!1,this.dispatchEvent(new CustomEvent("icpay-progress-insufficient-balance",{detail:{balance:i,required:this.currentAmount||this.amount,step:this.activeIndex},bubbles:!0})))};this.onLedgerVerified=e=>{let t=e?.detail?.ledgerId||e?.detail?.canisterId,i=e?.detail?.symbol||"unknown";u(this.debug,"ICPay Progress: Ledger verified event received:",e.detail),i&&i!=="unknown"&&(this.currentLedgerSymbol=i,this.ledgerSymbol=i),this.dispatchEvent(new CustomEvent("icpay-progress-ledger-verified",{detail:{ledgerId:t,symbol:i,step:this.activeIndex},bubbles:!0}))};this.onWidgetPayment=e=>{let t=e?.detail?.amount,i=e?.detail?.currency,s=e?.detail?.ledgerSymbol;if(u(this.debug,"ICPay Progress: Widget payment event received:",e.detail),t!==void 0&&(this.currentAmount=t,this.amount=t),i&&(this.currentCurrency=i,this.currency=i),s&&(this.currentLedgerSymbol=s,this.ledgerSymbol=s),!this.failed){for(let 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:t,currency:i,ledgerSymbol:s,step:this.activeIndex},bubbles:!0}))};this.onWidgetError=e=>{let t=e?.detail?.message||"Widget error occurred",i=e?.detail?.code||"WIDGET_ERROR";u(this.debug,"ICPay Progress: Widget error event received:",e.detail),this.failed=!0,this.errorMessage=this.transformErrorMessage(t),this.showSuccess=!1,this.updateStepStatus(this.activeIndex,"error",t),this.stopAutomaticProgression(),this.open=!0,this.dispatchEvent(new CustomEvent("icpay-progress-widget-error",{detail:{errorMessage:t,errorCode:i,step:this.activeIndex},bubbles:!0}))};this.onWidgetUnlock=e=>{let t=e?.detail?.amount,i=e?.detail?.currency;if(u(this.debug,"ICPay Progress: Widget unlock event received:",e.detail),!this.failed){for(let s=this.activeIndex;s<this.currentSteps.length;s++)this.updateStepStatus(s,"completed");this.activeIndex=this.currentSteps.length-1,this.completed=!0,this.showSuccess=!0,this.showConfetti=!0}this.dispatchEvent(new CustomEvent("icpay-progress-widget-unlock",{detail:{amount:t,currency:i,step:this.activeIndex},bubbles:!0}))};this.onWidgetTip=e=>{let t=e?.detail?.amount,i=e?.detail?.currency;if(u(this.debug,"ICPay Progress: Widget tip event received:",e.detail),!this.failed){for(let s=this.activeIndex;s<this.currentSteps.length;s++)this.updateStepStatus(s,"completed");this.activeIndex=this.currentSteps.length-1,this.completed=!0,this.showSuccess=!0,this.showConfetti=!0}this.dispatchEvent(new CustomEvent("icpay-progress-widget-tip",{detail:{amount:t,currency:i,step:this.activeIndex},bubbles:!0}))};this.onWidgetDonation=e=>{let t=e?.detail?.amount,i=e?.detail?.currency;if(u(this.debug,"ICPay Progress: Widget donation event received:",e.detail),!this.failed){for(let s=this.activeIndex;s<this.currentSteps.length;s++)this.updateStepStatus(s,"completed");this.activeIndex=this.currentSteps.length-1,this.completed=!0,this.showSuccess=!0,this.showConfetti=!0}this.dispatchEvent(new CustomEvent("icpay-progress-widget-donation",{detail:{amount:t,currency:i,step:this.activeIndex},bubbles:!0}))};this.onWidgetCoffee=e=>{let t=e?.detail?.amount,i=e?.detail?.currency;if(u(this.debug,"ICPay Progress: Widget coffee event received:",e.detail),!this.failed){for(let s=this.activeIndex;s<this.currentSteps.length;s++)this.updateStepStatus(s,"completed");this.activeIndex=this.currentSteps.length-1,this.completed=!0,this.showSuccess=!0,this.showConfetti=!0}this.dispatchEvent(new CustomEvent("icpay-progress-widget-coffee",{detail:{amount:t,currency:i,step:this.activeIndex},bubbles:!0}))}}connectedCallback(){super.connectedCallback();try{de(this,this.theme)}catch{}this.currentSteps=[...this.steps],this.currentAmount=this.amount,this.currentCurrency=this.currency,this.currentLedgerSymbol=this.ledgerSymbol,this.attachSDKEventListeners()}disconnectedCallback(){super.disconnectedCallback(),this.detachSDKEventListeners(),this.stopAutomaticProgression()}updated(e){if(e.has("theme"))try{de(this,this.theme)}catch{}}attachSDKEventListeners(){window.addEventListener("icpay-sdk-method-start",this.onMethodStart),window.addEventListener("icpay-sdk-method-success",this.onMethodSuccess),window.addEventListener("icpay-sdk-method-error",this.onMethodError),window.addEventListener("icpay-sdk-transaction-created",this.onTransactionCreated),window.addEventListener("icpay-sdk-transaction-updated",this.onTransactionUpdated),window.addEventListener("icpay-sdk-transaction-completed",this.onTransactionCompleted),window.addEventListener("icpay-sdk-transaction-failed",this.onTransactionFailed),window.addEventListener("icpay-sdk-transaction-mismatched",this.onTransactionMismatched),window.addEventListener("icpay-sdk-error",this.onSDKError),window.addEventListener("icpay-sdk-wallet-connected",this.onWalletConnected),window.addEventListener("icpay-sdk-wallet-disconnected",this.onWalletDisconnected),window.addEventListener("icpay-sdk-balance-check",this.onBalanceCheck),window.addEventListener("icpay-sdk-ledger-verified",this.onLedgerVerified),window.addEventListener("icpay-pay",this.onWidgetPayment),window.addEventListener("icpay-error",this.onWidgetError),window.addEventListener("icpay-unlock",this.onWidgetUnlock),window.addEventListener("icpay-tip",this.onWidgetTip),window.addEventListener("icpay-donation",this.onWidgetDonation),window.addEventListener("icpay-coffee",this.onWidgetCoffee)}detachSDKEventListeners(){window.removeEventListener("icpay-sdk-method-start",this.onMethodStart),window.removeEventListener("icpay-sdk-method-success",this.onMethodSuccess),window.removeEventListener("icpay-sdk-method-error",this.onMethodError),window.removeEventListener("icpay-sdk-transaction-created",this.onTransactionCreated),window.removeEventListener("icpay-sdk-transaction-updated",this.onTransactionUpdated),window.removeEventListener("icpay-sdk-transaction-completed",this.onTransactionCompleted),window.removeEventListener("icpay-sdk-transaction-failed",this.onTransactionFailed),window.removeEventListener("icpay-sdk-transaction-mismatched",this.onTransactionMismatched),window.removeEventListener("icpay-sdk-error",this.onSDKError),window.removeEventListener("icpay-sdk-wallet-connected",this.onWalletConnected),window.removeEventListener("icpay-sdk-wallet-disconnected",this.onWalletDisconnected),window.removeEventListener("icpay-sdk-balance-check",this.onBalanceCheck),window.removeEventListener("icpay-sdk-ledger-verified",this.onLedgerVerified),window.removeEventListener("icpay-pay",this.onWidgetPayment),window.removeEventListener("icpay-error",this.onWidgetError),window.removeEventListener("icpay-unlock",this.onWidgetUnlock),window.removeEventListener("icpay-tip",this.onWidgetTip),window.removeEventListener("icpay-donation",this.onWidgetDonation),window.removeEventListener("icpay-coffee",this.onWidgetCoffee)}startAutomaticProgression(){this.progressionTimer&&clearInterval(this.progressionTimer),this.activeIndex=1,this.updateStepStatus(this.activeIndex,"loading"),u(this.debug,"ICPay Progress: Starting automatic progression from step:",this.activeIndex),this.progressionTimer=setInterval(()=>{if(this.failed||this.completed){this.stopAutomaticProgression();return}u(this.debug,"ICPay Progress: Processing step:",this.activeIndex),this.updateStepStatus(this.activeIndex,"completed"),this.activeIndex<this.currentSteps.length-1?(this.activeIndex++,this.updateStepStatus(this.activeIndex,"loading"),u(this.debug,"ICPay Progress: Auto-progressed to step:",this.activeIndex)):(this.stopAutomaticProgression(),u(this.debug,"ICPay Progress: All steps completed, waiting for transaction completion")),this.requestUpdate()},3e3)}stopAutomaticProgression(){this.progressionTimer&&(clearInterval(this.progressionTimer),this.progressionTimer=null)}updateStepStatus(e,t,i){if(e>=0&&e<this.currentSteps.length){let s=this.currentSteps[e],o=s.status;s.status=t,t==="completed"&&(s.timestamp=this.getCurrentTime()),t==="error"&&i&&(s.errorMessage=this.transformErrorMessage(i)),u(this.debug,`ICPay Progress: Step ${e} (${s.label}) status changed from ${o} to ${t}`),this.requestUpdate()}}getCurrentTime(){return new Date().toLocaleTimeString("en-US",{hour12:!1,hour:"2-digit",minute:"2-digit",second:"2-digit"})}getStepIcon(e){switch(e.status){case"loading":return x`<div class="loading-spinner"></div>`;case"completed":return x`<svg fill="none" viewBox="0 0 24 24" stroke="currentColor">
60
- <path stroke-linecap="round" stroke-linejoin="round" d="M5 13l4 4L19 7" />
61
- </svg>`;case"error":return x`<svg fill="none" viewBox="0 0 24 24" stroke="currentColor">
62
- <path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />
63
- </svg>`;default:return x`<svg fill="none" viewBox="0 0 24 24" stroke="currentColor">
64
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 3v2m6-2v2M9 19v2m6-2v2M5 9H3m2 6H3m18-6h-2m2 6h-2M7 19h10a2 2 0 002-2V7a2 2 0 00-2-2H7a2 2 0 00-2 2v10a2 2 0 002 2zM9 9h6v6H9V9z" />
65
- </svg>`}}getStepIndexByKey(e){return this.currentSteps.findIndex(t=>t.key===e)}setLoadingByKey(e){let t=this.getStepIndexByKey(e);t>=0&&(this.activeIndex=t,this.updateStepStatus(t,"loading"),e==="confirm"&&(this.confirmLoadingStartedAt=Date.now()))}completeByKey(e){let t=this.getStepIndexByKey(e);t>=0&&(this.updateStepStatus(t,"completed"),this.activeIndex=t)}transformErrorMessage(e){let t=String(e||"").toLowerCase();return t.includes("user rejected")||t.includes("user cancelled")||t.includes("user canceled")||t.includes("signature rejected")?"User have rejected the transfer":e}renderConfetti(){if(!this.showConfetti)return"";let e=Array.from({length:50},(i,s)=>s),t=["#0066FF","#ef4444","#10b981","#f59e0b","#8b5cf6"];return x`
66
- <div class="confetti">
67
- ${e.map(i=>x`
68
- <div
69
- class="confetti-piece"
70
- style="
71
- left: ${Math.random()*100}%;
72
- top: ${Math.random()*100}%;
73
- background-color: ${t[Math.floor(Math.random()*t.length)]};
74
- animation-delay: ${Math.random()*2}s;
75
- animation-duration: ${2+Math.random()*2}s;
76
- "
77
- ></div>
78
- `)}
79
- </div>
80
- `}renderSuccessState(){let e=this.currentAmount||this.amount,t=this.currentLedgerSymbol||this.currentCurrency||this.currency;return u(this.debug,"ICPay Progress: Rendering success state with:",{displayAmount:e,displayCurrency:t,currentAmount:this.currentAmount,amount:this.amount,currentCurrency:this.currentCurrency,currency:this.currency,currentLedgerSymbol:this.currentLedgerSymbol,ledgerSymbol:this.ledgerSymbol}),x`
81
- <div class="success-container">
82
- <div class="success-icon">
83
- <svg fill="none" viewBox="0 0 24 24" stroke="currentColor">
84
- <path stroke-linecap="round" stroke-linejoin="round" d="M5 13l4 4L19 7" />
85
- </svg>
86
- </div>
87
- <h2 class="success-title">Payment Complete!</h2>
88
- <p class="success-message">Your payment of ${e} USD has been successfully processed.</p>
89
- <div class="success-actions">
90
- <button class="btn btn-primary" @click=${()=>{this.open=!1}}>Close</button>
91
- </div>
92
- </div>
93
- `}renderErrorState(){return this.errorMessage?.includes("Insufficient balance")||!1?this.renderInsufficientFundsError():this.renderGenericError()}renderInsufficientFundsError(){let e=this.currentAmount||this.amount,t=this.currentLedgerSymbol||this.currentCurrency||this.currency;return x`
94
- <div class="insufficient-funds-container">
95
- <div class="payment-summary">
96
- <div class="payment-amount">Pay $${e} with ${t}</div>
97
- </div>
98
-
99
- <div class="error-notification">
100
- <div class="error-content">
101
- <div class="error-icon-small">
102
- <svg fill="none" viewBox="0 0 24 24" stroke="currentColor">
103
- <path stroke-linecap="round" stroke-linejoin="round" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-1.732-.833-2.5 0L4.268 16.5c-.77.833.192 2.5 1.732 2.5z" />
104
- </svg>
105
- </div>
106
- <div class="error-text">Insufficient balance for this transaction</div>
107
- </div>
108
- </div>
109
-
110
- <div class="error-actions">
111
- <button class="btn btn-secondary" @click=${()=>this.requestSwitchAccount()} title="Switch to a different account">
112
- <svg fill="none" viewBox="0 0 24 24" stroke="currentColor" style="width: 16px; height: 16px;">
113
- <path stroke-linecap="round" stroke-linejoin="round" d="M8 7h12m0 0l-4-4m4 4l-4 4m0 6H4m0 0l4 4m-4-4l4-4" />
114
- </svg>
115
- Switch Account
116
- </button>
117
- <button class="btn btn-primary" @click=${()=>{this.open=!1}}>
118
- <svg fill="none" viewBox="0 0 24 24" stroke="currentColor" style="width: 16px; height: 16px;">
119
- <path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />
120
- </svg>
121
- Close
122
- </button>
123
- </div>
124
- </div>
125
- `}renderGenericError(){return x`
126
- <div class="error-container">
127
- <div class="error-icon-large">
128
- <svg fill="none" viewBox="0 0 24 24" stroke="currentColor">
129
- <path stroke-linecap="round" stroke-linejoin="round" d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
130
- </svg>
131
- </div>
132
- <h2 class="error-title">Transaction Failed</h2>
133
- <p class="error-message-text">${this.errorMessage}</p>
134
- <div class="error-actions">
135
- <button class="btn btn-secondary" @click=${()=>this.requestSwitchAccount()} title="Switch to a different account">
136
- <svg fill="none" viewBox="0 0 24 24" stroke="currentColor" style="width: 16px; height: 16px;">
137
- <path stroke-linecap="round" stroke-linejoin="round" d="M8 7h12m0 0l-4-4m4 4l-4 4m0 6H4m0 0l4 4m-4-4l4-4" />
138
- </svg>
139
- Switch Account
140
- </button>
141
- <button class="btn btn-primary" @click=${()=>{this.open=!1}}>
142
- <svg fill="none" viewBox="0 0 24 24" stroke="currentColor" style="width: 16px; height: 16px;">
143
- <path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />
144
- </svg>
145
- Close
146
- </button>
147
- </div>
148
- </div>
149
- `}requestSwitchAccount(){try{this.open=!1;let e=this.currentWalletType||"unknown";window.dispatchEvent(new CustomEvent("icpay-switch-account",{detail:{walletType:e}}))}catch{}}handleAddFunds(){try{window.dispatchEvent(new CustomEvent("icpay-add-funds",{detail:{amount:this.currentAmount||this.amount,currency:this.currentLedgerSymbol||this.currentCurrency||this.currency}})),this.open=!1}catch(e){console.error("Error handling add funds:",e)}}startTransitionToProgress(){this.isTransitioning=!0,this.requestUpdate(),setTimeout(()=>{this.showWalletSelector=!1,this.isTransitioning=!1,this.requestUpdate()},400)}renderProgressContent(){return this.showSuccess?this.renderSuccessState():this.failed?this.renderErrorState():x`
150
- <div class="progress-container">
151
- <div class="progress-header">
152
- <h3 class="progress-title">Processing Payment</h3>
153
- <p class="progress-subtitle">Please wait while we process your transaction</p>
154
- ${this.renderConfirmTip()}
155
- </div>
156
- <div class="progress-steps">
157
- ${this.currentSteps.map((e,t)=>x`
158
- <div class="step ${t===this.activeIndex?"active":""} ${e.status==="completed"?"completed":""} ${e.status==="error"?"error":""}">
159
- <div class="step-icon">
160
- ${e.status==="loading"?x`<div class="loading-spinner"></div>`:""}
161
- ${e.status==="completed"?x`
162
- <svg fill="none" viewBox="0 0 24 24" stroke="currentColor">
163
- <path stroke-linecap="round" stroke-linejoin="round" d="M5 13l4 4L19 7" />
164
- </svg>
165
- `:e.status==="error"?x`
166
- <svg fill="none" viewBox="0 0 24 24" stroke="currentColor">
167
- <path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />
168
- </svg>
169
- `:x`
170
- <svg fill="none" viewBox="0 0 24 24" stroke="currentColor">
171
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 3v2m6-2v2M9 19v2m6-2v2M5 9H3m2 6H3m18-6h-2m2 6h-2M7 19h10a2 2 0 002-2V7a2 2 0 00-2-2H7a2 2 0 00-2 2v10a2 2 0 002 2zM9 9h6v6H9V9z" />
172
- </svg>
173
- `}
174
- </div>
175
- <div class="step-content">
176
- <div class="step-title">${e.label}</div>
177
- <div class="step-description">${e.tooltip}</div>
178
- ${e.status==="error"&&e.errorMessage?x`
179
- <div class="step-error-message">${e.errorMessage}</div>
180
- `:""}
181
- </div>
182
- </div>
183
- `)}
184
- </div>
185
- </div>
186
- `}renderConfirmTip(){try{let e=this.getStepIndexByKey("confirm");if(e<0||!(this.activeIndex===e&&this.currentSteps[e]?.status==="loading"))return null;let i=this.confirmLoadingStartedAt||0;return(i?Date.now()-i:0)<3e4?null:x`<p class="progress-subtitle" style="margin-top:8px;color:#60a5fa">Verification can take from 30 seconds up to 10 minutes depending on the amount. Please wait…</p>`}catch{return null}}retryTransaction(){this.activeIndex=0,this.completed=!1,this.failed=!1,this.errorMessage=null,this.showSuccess=!1,this.showConfetti=!1,this.currentSteps=this.currentSteps.map(e=>({...e,status:"pending"})),this.updateStepStatus(0,"loading"),this.startAutomaticProgression(),this.requestUpdate()}closeProgress(){this.open=!1,this.showWalletSelector=!1,this.isTransitioning=!1}renderStep(e,t){return x`
187
- <div class="step-item ${e.status}">
188
- <div class="step-icon">
189
- ${this.getStepIcon(e)}
190
- </div>
191
- <div class="step-content">
192
- <div class="step-title">
193
- ${e.status==="completed"?"COMPLETED":e.label}
194
- </div>
195
- ${e.status==="completed"?x`
196
- <div class="step-subtitle">
197
- ${e.timestamp} - ${e.tooltip}
198
- </div>
199
- `:e.status==="error"&&e.errorMessage?x`
200
- <div class="step-error">${e.errorMessage}</div>
201
- `:x`
202
- <div class="step-subtitle">${e.tooltip}</div>
203
- `}
204
- </div>
205
- </div>
206
- `}get isWalletConnectLoading(){try{let e=this.currentSteps.findIndex(t=>t.key==="wallet");return e<0?!1:this.currentSteps[e].status==="loading"&&!this.failed&&!this.showSuccess}catch{return!1}}render(){return x`
207
- ${this.open?x`
208
- ${this.renderConfetti()}
209
- <div class="modal-overlay active">
210
- <div class="modal-container">
211
- <button class="close-button" @click=${()=>this.closeProgress()} aria-label="Close" title="Close">✕</button>
212
- <div class="modal-content ${this.isTransitioning?"transitioning":""}">
213
- ${this.renderProgressContent()}
214
- </div>
215
- </div>
216
- </div>
217
- `:null}
218
- `}};y.styles=je`
219
- :host {
220
- display: block;
221
- font-family: var(--icpay-font, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif);
222
- color: var(--icpay-text-primary, #ffffff);
223
-
224
- /* Theme variables for better composability */
225
- --icpay-bg-primary: #1f2937;
226
- --icpay-bg-secondary: rgba(255, 255, 255, 0.05);
227
- --icpay-bg-secondary-hover: rgba(255, 255, 255, 0.08);
228
- --icpay-bg-success: rgba(16, 185, 129, 0.1);
229
- --icpay-bg-error: rgba(239, 68, 68, 0.1);
230
-
231
- --icpay-text-primary: #ffffff;
232
- --icpay-text-secondary: #9ca3af;
233
- --icpay-text-muted: #6b7280;
234
-
235
- --icpay-border-primary: rgba(255, 255, 255, 0.1);
236
- --icpay-border-secondary: rgba(255, 255, 255, 0.2);
237
- --icpay-border-success: rgba(16, 185, 129, 0.3);
238
- --icpay-border-error: rgba(239, 68, 68, 0.3);
239
-
240
- --icpay-accent-primary: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
241
- --icpay-accent-success: linear-gradient(135deg, #10b981 0%, #059669 100%);
242
- --icpay-accent-error: #ef4444;
243
-
244
- --icpay-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
245
- --icpay-shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
246
- --icpay-shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
247
- --icpay-shadow-xl: 0 20px 25px rgba(0, 0, 0, 0.1);
248
-
249
- --icpay-radius-sm: 6px;
250
- --icpay-radius-md: 8px;
251
- --icpay-radius-lg: 12px;
252
- --icpay-radius-xl: 16px;
253
-
254
- --icpay-spacing-xs: 4px;
255
- --icpay-spacing-sm: 8px;
256
- --icpay-spacing-md: 12px;
257
- --icpay-spacing-lg: 16px;
258
- --icpay-spacing-xl: 24px;
259
- }
260
-
261
- .modal-overlay {
262
- position: fixed;
263
- top: 0;
264
- left: 0;
265
- right: 0;
266
- bottom: 0;
267
- background: rgba(0, 0, 0, 0.5);
268
- backdrop-filter: blur(8px);
269
- display: flex;
270
- align-items: center;
271
- justify-content: center;
272
- z-index: 1000;
273
- opacity: 0;
274
- visibility: hidden;
275
- transition: opacity 0.3s ease, visibility 0.3s ease;
276
- }
277
-
278
- .modal-content {
279
- transition: opacity 0.4s ease, transform 0.4s ease;
280
- opacity: 1;
281
- transform: translateY(0);
282
- }
283
-
284
- .modal-content.transitioning {
285
- opacity: 0;
286
- transform: translateY(20px);
287
- }
288
-
289
- .wallet-selector-container {
290
- width: 100%;
291
- }
292
-
293
- .wallet-selector-title {
294
- color: var(--icpay-text-primary);
295
- margin: 0 48px var(--icpay-spacing-lg) 0;
296
- font-size: 18px;
297
- font-weight: 600;
298
- }
299
-
300
- .wallet-options {
301
- display: flex;
302
- flex-direction: column;
303
- gap: var(--icpay-spacing-sm);
304
- }
305
-
306
- .wallet-option {
307
- width: 100%;
308
- padding: 12px 16px;
309
- background: rgba(255, 255, 255, 0.05);
310
- border: 1px solid rgba(255, 255, 255, 0.1);
311
- border-radius: 8px;
312
- display: flex;
313
- align-items: center;
314
- gap: 12px;
315
- cursor: pointer;
316
- transition: all 0.3s ease;
317
- box-sizing: border-box;
318
- }
319
-
320
- .wallet-option:hover {
321
- background: rgba(255, 255, 255, 0.08);
322
- border-color: rgba(255, 255, 255, 0.2);
323
- }
324
-
325
- .wallet-icon {
326
- width: 48px;
327
- height: 48px;
328
- border-radius: 12px;
329
- background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
330
- display: flex;
331
- align-items: center;
332
- justify-content: center;
333
- flex-shrink: 0;
334
- }
335
-
336
- .wallet-icon img {
337
- width: 40px;
338
- height: 40px;
339
- object-fit: cover;
340
- border-radius: 12px;
341
- }
342
-
343
- .wallet-icon-placeholder {
344
- color: #ffffff;
345
- font-size: 12px;
346
- font-weight: bold;
347
- }
348
-
349
- .wallet-label {
350
- font-weight: 500;
351
- font-size: 14px;
352
- color: #ffffff;
353
- }
354
-
355
- .modal-overlay.active {
356
- opacity: 1;
357
- visibility: visible;
358
- }
359
-
360
- .modal-container {
361
- background: var(--icpay-bg-primary);
362
- border: 1px solid var(--icpay-border-primary);
363
- border-radius: var(--icpay-radius-lg);
364
- padding: var(--icpay-spacing-xl);
365
- max-width: 400px;
366
- width: 90%;
367
- box-shadow: var(--icpay-shadow-xl);
368
- transform: translateY(20px);
369
- transition: transform 0.3s ease;
370
- position: relative;
371
- }
372
-
373
- .modal-overlay.active .modal-container {
374
- transform: translateY(0);
375
- }
376
-
377
- .close-button {
378
- position: absolute;
379
- top: var(--icpay-spacing-lg);
380
- right: var(--icpay-spacing-lg);
381
- width: 32px;
382
- height: 32px;
383
- display: flex;
384
- align-items: center;
385
- justify-content: center;
386
- color: var(--icpay-text-secondary);
387
- cursor: pointer;
388
- border: none;
389
- background: transparent;
390
- font-size: 20px;
391
- transition: all 0.2s;
392
- z-index: 10;
393
- }
394
-
395
- .close-button:hover {
396
- color: var(--icpay-text-primary);
397
- }
398
-
399
- .progress-header { text-align: left; margin-bottom: var(--icpay-spacing-lg); }
400
- .progress-title {
401
- font-size: 18px;
402
- font-weight: 600;
403
- margin: 0 48px var(--icpay-spacing-sm) 0;
404
- color: var(--icpay-text-primary);
405
- }
406
- .progress-subtitle { color: var(--icpay-text-secondary); font-size: 14px; }
407
- .progress-steps {
408
- margin-bottom: var(--icpay-spacing-xl);
409
- display: flex;
410
- flex-direction: column;
411
- gap: var(--icpay-spacing-sm);
412
- }
413
- .step {
414
- width: 100%;
415
- padding: 12px 16px;
416
- background: rgba(255, 255, 255, 0.05);
417
- border: 1px solid rgba(255, 255, 255, 0.1);
418
- border-radius: 8px;
419
- display: flex;
420
- align-items: center;
421
- gap: 12px;
422
- opacity: 0.3;
423
- transition: all 0.3s ease;
424
- cursor: default;
425
- box-sizing: border-box;
426
- }
427
- .step.active {
428
- opacity: 1;
429
- background: rgba(255, 255, 255, 0.05);
430
- border-color: rgba(255, 255, 255, 0.1);
431
- }
432
- .step.completed {
433
- opacity: 0.7;
434
- background: rgba(16, 185, 129, 0.1);
435
- border-color: rgba(16, 185, 129, 0.3);
436
- }
437
-
438
- .step.error {
439
- opacity: 1;
440
- background: rgba(239, 68, 68, 0.1);
441
- border-color: rgba(239, 68, 68, 0.3);
442
- }
443
- .step-icon {
444
- width: 48px;
445
- height: 48px;
446
- border-radius: 12px;
447
- background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
448
- display: flex;
449
- align-items: center;
450
- justify-content: center;
451
- transition: all 0.3s ease;
452
- position: relative;
453
- flex-shrink: 0;
454
- }
455
- .step.active .step-icon {
456
- background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
457
- box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.3);
458
- }
459
- .step.completed .step-icon {
460
- background: linear-gradient(135deg, #10b981 0%, #059669 100%);
461
- }
462
-
463
- .step.error .step-icon {
464
- background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
465
- }
466
- .step-icon svg {
467
- width: 20px;
468
- height: 20px;
469
- stroke: var(--icpay-text-primary);
470
- transition: stroke 0.3s ease;
471
- }
472
- .step-content {
473
- flex: 1;
474
- display: flex;
475
- flex-direction: column;
476
- gap: 0;
477
- }
478
- .step-title {
479
- font-weight: 500;
480
- font-size: 14px;
481
- color: #ffffff;
482
- transition: color 0.3s ease;
483
- margin: 0;
484
- }
485
- .step-description {
486
- font-size: 12px;
487
- color: #9ca3af;
488
- margin: 0;
489
- }
490
-
491
- .step-error-message {
492
- font-size: 11px;
493
- color: #fca5a5;
494
- margin-top: 4px;
495
- padding: 4px 8px;
496
- background: rgba(239, 68, 68, 0.1);
497
- border-radius: 4px;
498
- border-left: 3px solid #ef4444;
499
- }
500
- .loading-spinner {
501
- display: none;
502
- width: 20px;
503
- height: 20px;
504
- border: 2px solid rgba(255, 255, 255, 0.2);
505
- border-top-color: var(--icpay-text-primary);
506
- border-radius: 50%;
507
- animation: spin 1s linear infinite;
508
- position: absolute;
509
- }
510
- .step.active .loading-spinner { display: block; }
511
-
512
- .error-container {
513
- text-align: center;
514
- }
515
-
516
- .error-icon-large {
517
- width: 64px;
518
- height: 64px;
519
- margin: 0 auto var(--icpay-spacing-lg);
520
- background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
521
- border-radius: var(--icpay-radius-xl);
522
- display: flex;
523
- align-items: center;
524
- justify-content: center;
525
- }
526
-
527
- .error-icon-large svg {
528
- width: 32px;
529
- height: 32px;
530
- stroke: var(--icpay-text-primary);
531
- stroke-width: 2;
532
- }
533
-
534
- .error-title {
535
- font-size: 20px;
536
- font-weight: 600;
537
- margin-bottom: var(--icpay-spacing-sm);
538
- color: var(--icpay-text-primary);
539
- }
540
-
541
- .error-message-text {
542
- color: var(--icpay-text-secondary);
543
- margin-bottom: var(--icpay-spacing-xl);
544
- font-size: 14px;
545
- }
546
-
547
- .error-details {
548
- background: rgba(239, 68, 68, 0.1);
549
- border: 1px solid rgba(239, 68, 68, 0.3);
550
- border-radius: var(--icpay-radius-md);
551
- padding: var(--icpay-spacing-lg);
552
- margin-bottom: var(--icpay-spacing-xl);
553
- text-align: left;
554
- }
555
-
556
- .error-detail-item {
557
- display: flex;
558
- justify-content: space-between;
559
- align-items: center;
560
- margin-bottom: var(--icpay-spacing-sm);
561
- }
562
-
563
- .error-detail-item:last-child {
564
- margin-bottom: 0;
565
- }
566
-
567
- .error-detail-label {
568
- font-size: 14px;
569
- color: var(--icpay-text-secondary);
570
- font-weight: 500;
571
- }
572
-
573
- .error-detail-value {
574
- font-size: 14px;
575
- color: var(--icpay-text-primary);
576
- font-weight: 600;
577
- }
578
-
579
- .error-actions {
580
- display: flex;
581
- gap: var(--icpay-spacing-sm);
582
- justify-content: center;
583
- }
584
-
585
- .insufficient-funds-container {
586
- width: 100%;
587
- }
588
-
589
- .payment-summary {
590
- background: rgba(255, 255, 255, 0.1);
591
- border-radius: var(--icpay-radius-md);
592
- padding: var(--icpay-spacing-lg);
593
- margin-bottom: var(--icpay-spacing-lg);
594
- text-align: center;
595
- }
596
-
597
- .payment-amount {
598
- font-size: 16px;
599
- font-weight: 600;
600
- color: var(--icpay-text-primary);
601
- }
602
-
603
- .error-notification {
604
- background: rgba(255, 255, 255, 0.05);
605
- border: 1px solid #f59e0b;
606
- border-radius: var(--icpay-radius-md);
607
- padding: var(--icpay-spacing-lg);
608
- margin-bottom: var(--icpay-spacing-xl);
609
- display: flex;
610
- align-items: center;
611
- justify-content: space-between;
612
- gap: var(--icpay-spacing-lg);
613
- }
614
-
615
- .error-content {
616
- display: flex;
617
- align-items: center;
618
- gap: var(--icpay-spacing-md);
619
- flex: 1;
620
- }
621
-
622
- .error-icon-small {
623
- width: 20px;
624
- height: 20px;
625
- color: #f59e0b;
626
- flex-shrink: 0;
627
- }
628
-
629
- .error-icon-small svg {
630
- width: 100%;
631
- height: 100%;
632
- }
633
-
634
- .error-text {
635
- font-size: 14px;
636
- font-weight: 500;
637
- color: #f59e0b;
638
- }
639
-
640
- .add-funds-btn {
641
- background: rgba(255, 255, 255, 0.1);
642
- border: 1px solid rgba(255, 255, 255, 0.2);
643
- border-radius: var(--icpay-radius-sm);
644
- padding: 8px 16px;
645
- color: var(--icpay-text-primary);
646
- font-size: 14px;
647
- font-weight: 500;
648
- cursor: pointer;
649
- transition: all 0.3s ease;
650
- flex-shrink: 0;
651
- }
652
-
653
- .add-funds-btn:hover {
654
- background: rgba(255, 255, 255, 0.15);
655
- border-color: rgba(255, 255, 255, 0.3);
656
- }
657
-
658
- .error-message {
659
- display: flex;
660
- align-items: flex-start;
661
- gap: var(--icpay-spacing-md);
662
- padding: var(--icpay-spacing-lg);
663
- background: var(--icpay-bg-error);
664
- border: 1px solid var(--icpay-border-error);
665
- border-radius: var(--icpay-radius-md);
666
- margin-top: var(--icpay-spacing-sm);
667
- }
668
-
669
- .error-icon {
670
- flex-shrink: 0;
671
- width: 20px;
672
- height: 20px;
673
- background: var(--icpay-accent-error);
674
- border-radius: 50%;
675
- display: flex;
676
- align-items: center;
677
- justify-content: center;
678
- color: var(--icpay-text-primary);
679
- font-size: 12px;
680
- font-weight: bold;
681
- }
682
-
683
- .error-content h4 {
684
- margin: 0 0 4px 0;
685
- font-size: 14px;
686
- font-weight: 600;
687
- color: var(--icpay-text-primary);
688
- }
689
-
690
- .error-content p {
691
- margin: 0;
692
- font-size: 12px;
693
- color: #fca5a5;
694
- line-height: 1.4;
695
- }
696
-
697
- .success-container { text-align: center; }
698
- .success-icon {
699
- width: 64px;
700
- height: 64px;
701
- margin: 0 auto var(--icpay-spacing-lg);
702
- background: var(--icpay-accent-success);
703
- border-radius: var(--icpay-radius-xl);
704
- display: flex;
705
- align-items: center;
706
- justify-content: center;
707
- }
708
- .success-icon svg {
709
- width: 32px;
710
- height: 32px;
711
- stroke: var(--icpay-text-primary);
712
- stroke-width: 2;
713
- }
714
- .success-title {
715
- font-size: 20px;
716
- font-weight: 600;
717
- margin-bottom: var(--icpay-spacing-sm);
718
- color: var(--icpay-text-primary);
719
- }
720
- .success-message {
721
- color: var(--icpay-text-secondary);
722
- margin-bottom: 20px;
723
- font-size: 14px;
724
- }
725
- .success-actions {
726
- display: flex;
727
- gap: var(--icpay-spacing-sm);
728
- justify-content: center;
729
- }
730
- .btn {
731
- padding: 10px 20px;
732
- border-radius: var(--icpay-radius-md);
733
- font-size: 14px;
734
- font-weight: 500;
735
- cursor: pointer;
736
- transition: all 0.3s ease;
737
- text-decoration: none;
738
- display: inline-flex;
739
- align-items: center;
740
- gap: var(--icpay-spacing-sm);
741
- }
742
- .btn-primary {
743
- background: var(--icpay-accent-primary);
744
- color: var(--icpay-text-primary);
745
- border: none;
746
- }
747
- .btn-primary:hover {
748
- transform: translateY(-1px);
749
- box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
750
- }
751
- .btn-secondary {
752
- background: transparent;
753
- color: var(--icpay-text-secondary);
754
- border: 1px solid var(--icpay-border-primary);
755
- }
756
- .btn-secondary:hover {
757
- background: var(--icpay-bg-secondary);
758
- border-color: var(--icpay-border-secondary);
759
- color: var(--icpay-text-primary);
760
- }
761
-
762
- .confetti {
763
- position: fixed;
764
- top: 0;
765
- left: 0;
766
- width: 100%;
767
- height: 100%;
768
- pointer-events: none;
769
- z-index: 1001;
770
- }
771
-
772
- .confetti-piece {
773
- position: absolute;
774
- width: 8px;
775
- height: 8px;
776
- background: #0066FF;
777
- animation: confetti-fall 3s linear forwards;
778
- }
779
-
780
- @keyframes spin {
781
- from { transform: rotate(0deg); }
782
- to { transform: rotate(360deg); }
783
- }
784
-
785
- .spinner {
786
- width: 16px;
787
- height: 16px;
788
- border: 2px solid transparent;
789
- border-top: 2px solid #ffffff;
790
- border-radius: 50%;
791
- animation: spin 1s linear infinite;
792
- }
793
-
794
- @keyframes confetti-fall {
795
- 0% {
796
- transform: translateY(-100vh) rotate(0deg);
797
- opacity: 1;
798
- }
799
- 100% {
800
- transform: translateY(100vh) rotate(720deg);
801
- opacity: 0;
802
- }
803
- }
804
- `,n([oe({type:Boolean})],y.prototype,"open",2),n([oe({type:Array})],y.prototype,"steps",2),n([oe({type:Number})],y.prototype,"amount",2),n([oe({type:String})],y.prototype,"currency",2),n([oe({type:String})],y.prototype,"ledgerSymbol",2),n([oe({type:Boolean})],y.prototype,"debug",2),n([_()],y.prototype,"activeIndex",2),n([_()],y.prototype,"completed",2),n([_()],y.prototype,"failed",2),n([_()],y.prototype,"errorMessage",2),n([_()],y.prototype,"showSuccess",2),n([_()],y.prototype,"showConfetti",2),n([_()],y.prototype,"currentSteps",2),n([_()],y.prototype,"currentAmount",2),n([_()],y.prototype,"currentCurrency",2),n([_()],y.prototype,"currentLedgerSymbol",2),n([_()],y.prototype,"confirmLoadingStartedAt",2),n([_()],y.prototype,"currentWalletType",2),n([_()],y.prototype,"showWalletSelector",2),n([_()],y.prototype,"isTransitioning",2),n([oe({type:Object})],y.prototype,"theme",2),y=n([He("icpay-progress-bar")],y);import{html as Me}from"lit";function F(r){if(!r.visible)return null;let d=r.environment??"STAGING",e=r.width??420,t=r.height??680,i="";return r.sessionId&&(i=`${d==="PRODUCTION"?"https://global.transak.com":"https://global-stg.transak.com"}?sessionId=${encodeURIComponent(r.sessionId)}`),Me`
805
- <div style="position:fixed;inset:0;display:flex;align-items:center;justify-content:center;background:rgba(0,0,0,0.85);backdrop-filter:blur(10px);z-index:10000">
806
- <div style="position:relative;background:#0f1115;border:1px solid rgba(255,255,255,0.1);border-radius:16px;padding:16px;box-shadow:0 20px 60px rgba(0,0,0,0.5)">
807
- <button @click=${r.onClose} aria-label="Close" title="Close"
808
- style="position:absolute;top:10px;right:10px;background:transparent;border:none;color:#9ca3af;cursor:pointer;font-size:20px">✕</button>
809
- ${r.sessionId?Me`
810
- <iframe
811
- id="transak-iframe"
812
- style="border:none;border-radius:12px;background:#111"
813
- width="${String(e)}"
814
- height="${String(t)}"
815
- src="${i}"
816
- allow="camera;microphone;payment"
817
- ></iframe>
818
- `:Me`
819
- <div style="width:${String(e)}px;max-width:90vw;padding:12px">
820
- <div style="background:#1a1f2e;border:1px solid rgba(255,255,255,0.1);border-radius:12px;padding:24px;color:#e5e7eb;text-align:center">
821
- <div style="font-size:18px;font-weight:600;margin-bottom:8px">Service unavailable</div>
822
- <div style="font-size:14px;opacity:0.85;margin-bottom:16px">${r.errorMessage||"The service is currently unavailable, please try again later."}</div>
823
- <button
824
- @click=${()=>{r.onBack?r.onBack():r.onClose()}}
825
- style="padding:10px 16px;border-radius:10px;border:1px solid rgba(255,255,255,0.15);background:linear-gradient(135deg,#3b82f6 0%,#10b981 100%);color:#fff;cursor:pointer;font-weight:600">
826
- Go back to wallet selection
827
- </button>
828
- </div>
829
- </div>
830
- `}
831
- </div>
832
- </div>
833
- `}import{LitElement as et,html as pe,css as tt}from"lit";import{customElement as it,property as nt,state as L}from"lit/decorators.js";import{IcpayError as Be}from"@ic-pay/icpay-sdk";var Y={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"},qe={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 U(r,d=qe){r instanceof Be?(d.onError(r),r.isUserCancelled()?d.onUserCancelled?.():r.isBalanceError()?d.onInsufficientBalance?.(r):r.isWalletError()?d.onWalletError?.(r):r.isNetworkError()&&d.onNetworkError?.(r)):(console.error("[ICPay Widget] Unknown error:",r),d.onError(new Be({code:Y.UNKNOWN_ERROR,message:r instanceof Error?r.message:"An unknown error occurred",details:r})))}var Ge={[Y.WALLET_NOT_CONNECTED]:"Please connect your wallet to continue",[Y.WALLET_USER_CANCELLED]:"User have rejected the transfer",[Y.WALLET_SIGNATURE_REJECTED]:"User have rejected the transfer",[Y.INSUFFICIENT_BALANCE]:"Insufficient balance for this transaction",[Y.NETWORK_ERROR]:"Network error. Please try again",[Y.API_ERROR]:"Service temporarily unavailable",[Y.LEDGER_NOT_FOUND]:"Selected token is not supported",[Y.TRANSACTION_FAILED]:"Transaction failed. Please try again",[Y.TRANSACTION_TIMEOUT]:"Transaction timed out. Please try again",[Y.UNKNOWN_ERROR]:"Something went wrong. Please try again"};function R(r){return Ge[r.code]||r.message||"An error occurred"}function B(r){return!r.isUserCancelled()}function D(r){return null}function z(r){return r.isUserCancelled()?"info":r.isBalanceError()||r.isWalletError()?"warning":"error"}import{LitElement as Ye,html as re,css as Qe}from"lit";import{customElement as Xe,property as ae}from"lit/decorators.js";import{query as De}from"lit/decorators.js";var j=class extends Ye{constructor(){super(...arguments);this.options=[];this.value=null;this.defaultSymbol="ICP";this.mode="buttons";this.open=!1;this.showLabel=!0;this.menuPos={left:0,top:0,width:0}}connectedCallback(){super.connectedCallback();try{de(this,this.theme)}catch{}}updated(e){if(e.has("theme"))try{de(this,this.theme)}catch{}}firstUpdated(){let e=i=>{if(!this.open)return;i.composedPath().includes(this)||this.closeDropdown()},t=i=>{i.key==="Escape"&&this.open&&this.closeDropdown()};this._onDocClick=e,this._onKey=t,window.addEventListener("click",e),window.addEventListener("keydown",t)}disconnectedCallback(){super.disconnectedCallback();let e=this._onDocClick,t=this._onKey;e&&window.removeEventListener("click",e),t&&window.removeEventListener("keydown",t)}get effectiveSymbol(){if(this.value)return this.value;let e=this.options?.[0]?.symbol;return this.defaultSymbol||e||"ICP"}getOptionBySymbol(e){return(this.options||[]).find(t=>t.symbol===e)}getLogoUrl(e){let t=String(e||"").toLowerCase(),i=(this.getAttribute("chain-name")||window?.ICPay?.config?.chainName||"IC").toLowerCase();return`${window?.ICPay?.config?.widgetBaseUrl||"https://widget.icpay.org"}/img/tokens/${i}/${t}.svg`}onSelect(e){this.value=e,this.requestUpdate("value"),this.open=!1,this.dispatchEvent(new CustomEvent("icpay-token-change",{detail:{symbol:e},bubbles:!0,composed:!0}))}toggleDropdown(){this.open=!this.open}closeDropdown(){this.open=!1}render(){let e=this.options||[];if(this.mode==="none"||e.length<=1){let i=e.length===1?e[0].symbol:this.effectiveSymbol;return this.value!==i&&queueMicrotask(()=>this.onSelect(i)),re``}if(this.mode==="dropdown"){let i=this.effectiveSymbol,s=this.getOptionBySymbol(i)||{symbol:i,label:i};return re`
834
- ${this.showLabel?re`<label class="icpay-dropdown-label">Payment method</label>`:null}
835
- <div class="dropdown-wrapper">
836
- <div class="dropdown-trigger ${this.open?"open":""}" @click=${()=>this.toggleDropdown()}>
837
- <div class="selected-option">
838
- <img class="dropdown-selected-icon" src="${this.getLogoUrl(s.symbol)}" alt="${s.symbol}" />
839
- <div class="crypto-info">
840
- <div class="dropdown-crypto-name">${s.label}</div>
841
- <div class="dropdown-crypto-symbol">${s.symbol}</div>
842
- </div>
843
- </div>
844
- <svg class="dropdown-arrow" fill="none" viewBox="0 0 24 24" stroke="currentColor" aria-hidden="true">
845
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7" />
846
- </svg>
847
- </div>
848
-
849
- <div class="dropdown-menu ${this.open?"open":""}">
850
- ${e.map(o=>re`
851
- <div class="dropdown-option ${this.value===o.symbol||i===o.symbol?"selected":""}" @click=${()=>this.onSelect(o.symbol)}>
852
- <img class="dropdown-selected-icon" src="${this.getLogoUrl(o.symbol)}" alt="${o.symbol}" />
853
- <div class="crypto-info">
854
- <div class="dropdown-crypto-name">${o.label}</div>
855
- <div class="dropdown-crypto-symbol">${o.symbol}</div>
856
- </div>
857
- </div>
858
- `)}
859
- </div>
860
- </div>
861
- <div class="dropdown-backdrop ${this.open?"open":""}" @click=${()=>this.closeDropdown()}></div>
862
- `}let t=this.effectiveSymbol;return re`
863
- <div class="icpay-token-selector" style="width:100%;box-sizing:border-box;">
864
- ${this.showLabel?re`<label class="label">Payment method</label>`:null}
865
- <div class="crypto-grid">
866
- ${e.map(i=>re`
867
- <div class="crypto-option ${t===i.symbol?"selected":""}" @click=${()=>this.onSelect(i.symbol)}>
868
- <img class="crypto-icon" src="${this.getLogoUrl(i.symbol)}" alt="${i.symbol}" />
869
- <div class="crypto-name">${i.label}</div>
870
- <div class="crypto-symbol">${i.symbol}</div>
871
- </div>
872
- `)}
873
- </div>
874
- </div>
875
- `}};j.styles=Qe`
876
- :host { display: block; width: 100%; box-sizing: border-box; }
877
-
878
- /* Common */
879
- .label,
880
- .icpay-dropdown-label { font-size: 14px; font-weight: 600; color: var(--icpay-text, #fff); margin-bottom: 8px; display: block; }
881
-
882
- /* Buttons grid (from crypto-payment-selector) */
883
- .crypto-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; width: 100%; margin: 12px 0 16px; box-sizing: border-box; }
884
- .crypto-option { background: var(--icpay-surface-alt, #2a3142); border: 1px solid var(--icpay-border, #3a4154); border-radius: 8px; padding: 8px 4px; cursor: pointer; transition: all 0.15s ease; position: relative; overflow: hidden; display: flex; flex-direction: column; align-items: center; gap: 4px; min-height: 60px; }
885
- .crypto-option:active { transform: scale(0.95); }
886
- .crypto-option.selected { background: #f7f7f7; border-color: #ffffff; }
887
- .crypto-option.selected .crypto-name { color: #1a1f2e; }
888
- .crypto-option.selected .crypto-symbol { color: #4a5568; }
889
- .crypto-option.selected::after { content: "✓"; position: absolute; top: 4px; right: 4px; width: 16px; height: 16px; background-color: #22C55E; color: white; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 10px; font-weight: bold; }
890
-
891
- /* Icon as external SVG image with constraints */
892
- .crypto-icon { width: 24px; height: 24px; border-radius: 50%; object-fit: contain; background: transparent; flex-shrink: 0; }
893
- .crypto-name { font-size: 11px; font-weight: 600; color: var(--icpay-text, #ffffff); text-align: center; line-height: 1.1; }
894
- .crypto-symbol { font-size: 9px; color: var(--icpay-muted-text, #888); text-align: center; line-height: 1; }
895
-
896
- /* Dropdown (from crypto-dropdown-selector) */
897
- .dropdown-wrapper { position: relative; width: 100%; box-sizing: border-box; }
898
- .dropdown-trigger { position: relative; width: 100%; box-sizing: border-box; background: var(--icpay-surface, #0a0a0a); border: 1px solid var(--icpay-border, #262626); border-radius: 12px; padding: 10px 40px 10px 16px; cursor: pointer; transition: all 0.2s ease; display: flex; align-items: center; gap: 12px; min-height: 44px; }
899
- .dropdown-trigger:hover { border-color: #404040; background: #171717; }
900
- .dropdown-trigger:active { transform: scale(0.99); }
901
- .dropdown-trigger.open { border-color: #525252; background: #171717; border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
902
- .selected-option { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }
903
- .dropdown-selected-icon { width: 32px; height: 32px; border-radius: 50%; object-fit: contain; flex-shrink: 0; }
904
- .dropdown-crypto-name { font-size: 14px; font-weight: 600; color: var(--icpay-text, #ffffff); line-height: 1.2; }
905
- .dropdown-crypto-symbol { font-size: 12px; color: var(--icpay-muted-text, #a3a3a3); line-height: 1.2; }
906
- .dropdown-arrow { width: 20px; height: 20px; color: #a3a3a3; transition: transform 0.2s ease; position: absolute; right: 12px; top: 50%; transform: translateY(-50%); pointer-events: none; }
907
- .dropdown-trigger.open .dropdown-arrow { transform: translateY(-50%) rotate(180deg); color: #ffffff; }
908
- /* Render menu as absolute under wrapper to align within widget */
909
- .dropdown-wrapper { position: relative; }
910
- .dropdown-menu { position: absolute; left: 0; top: 100%; background: var(--icpay-surface, #0a0a0a); border: 1px solid var(--icpay-border, #262626); border-top: none; border-radius: 0 0 12px 12px; overflow: hidden; opacity: 0; visibility: hidden; transform: translateY(-10px); transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s ease; z-index: 1000; box-shadow: 0 8px 24px rgba(0,0,0,0.5); max-height: 280px; overflow-y: auto; width: 100%; box-sizing: border-box; }
911
- .dropdown-menu.open { opacity: 1; visibility: visible; transform: translateY(0); }
912
- .dropdown-option { display: flex; align-items: center; gap: 12px; padding: 12px 16px; cursor: pointer; transition: background 0.15s ease; border-bottom: 1px solid #171717; }
913
- .dropdown-option:last-child { border-bottom: none; }
914
- .dropdown-option:hover { background: #171717; }
915
- .dropdown-option:active { background: #262626; }
916
- .dropdown-option.selected { background: #171717; }
917
- .dropdown-menu::-webkit-scrollbar { width: 4px; }
918
- .dropdown-menu::-webkit-scrollbar-track { background: #171717; }
919
- .dropdown-menu::-webkit-scrollbar-thumb { background: #404040; border-radius: 2px; }
920
- .dropdown-menu::-webkit-scrollbar-thumb:hover { background: #525252; }
921
- .dropdown-backdrop { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.2); opacity: 0; visibility: hidden; transition: all 0.2s ease; z-index: 500; }
922
- .dropdown-backdrop.open { opacity: 1; visibility: visible; }
923
-
924
- /* Small screens */
925
- @media (max-width: 320px) {
926
- .crypto-grid { gap: 4px; }
927
- .crypto-option { padding: 6px 2px; min-height: 54px; }
928
- .dropdown-trigger { padding: 10px 12px; min-height: 48px; }
929
- .dropdown-option { padding: 10px 12px; }
930
- .dropdown-selected-icon { width: 28px; height: 28px; }
931
- }
932
- `,n([ae({type:Array})],j.prototype,"options",2),n([ae({type:String})],j.prototype,"value",2),n([ae({type:String})],j.prototype,"defaultSymbol",2),n([ae({type:String})],j.prototype,"mode",2),n([ae({type:Object})],j.prototype,"theme",2),n([ae({type:Boolean})],j.prototype,"open",2),n([ae({type:Boolean})],j.prototype,"showLabel",2),n([De(".dropdown-trigger")],j.prototype,"triggerEl",2),n([De(".dropdown-wrapper")],j.prototype,"wrapperEl",2),j=n([Xe("icpay-token-selector")],j);import{html as Z}from"lit";function Ze(r){return!r||!r.startsWith("data:")?r:r.replace(/\s+/g,"")}function Je(r,d){let e=(r||"").toLowerCase();return e==="ii"?"Internet Identity":e==="nfid"?"NFID":e==="plug"?"Plug":e==="oisy"?"Oisy":d&&d.trim()?d:r?r.charAt(0).toUpperCase()+r.slice(1):"Wallet"}function H(r){if(!r.visible)return null;let{wallets:d,onSelect:e,onClose:t,isConnecting:i}=r,s=d.map(a=>{let l=(a.id||"").toLowerCase();return{...a,icon:a.icon??null}});return Z`
933
- <div style="position:fixed;inset:0;display:flex;align-items:center;justify-content:center;background:rgba(0,0,0,0.5);z-index:10000">
934
- <style>
935
- .icpay-w-8 { width: 2rem; }
936
- .icpay-h-8 { height: 2rem; }
937
- </style>
938
- <div style="background:#1f2937;border-radius:12px;padding:24px;max-width:400px;width:90%;border:1px solid rgba(255,255,255,0.1);position:relative">
939
- <button @click=${t} style="position:absolute;top:16px;right:16px;width:32px;height:32px;display:flex;align-items:center;justify-content:center;color:#9ca3af;cursor:pointer;border:none;background:transparent;font-size:20px">✕</button>
940
- ${r.oisyReadyToPay?null:Z`<h3 style="color:#fff;margin:0 48px 16px 0;font-size:18px;font-weight:600">Choose Wallet</h3>`}
941
- <div style="display:flex;flex-direction:column;gap:8px">
942
- ${r.oisyReadyToPay?Z`
943
- <button
944
- @click=${()=>{r.onOisyPay&&r.onOisyPay()}}
945
- style="width:100%;padding:12px 16px;background:rgba(255,255,255,0.05);border:1px solid rgba(255,255,255,0.1);border-radius:8px;color:#fff;text-align:left;cursor:pointer;font-size:14px;display:flex;align-items:center;gap:12px;justify-content:center">
946
- Pay with OISY
947
- </button>
948
- `:s.map(a=>{let l=(a.id||"").toLowerCase(),p=Je(a.id,a.label),c=Z`
949
- <button
950
- @click=${()=>e(a.id)}
951
- style="width:100%;padding:12px 16px;background:rgba(255,255,255,0.05);border:1px solid rgba(255,255,255,0.1);border-radius:8px;color:#fff;text-align:left;cursor:pointer;font-size:14px;opacity:${i?.5:1};display:flex;align-items:center;gap:12px">
952
- ${a.icon?Z`
953
- <div style="width:48px;height:48px;display:flex;align-items:center;justify-content:center">
954
- <img src="${Ze(a.icon)}" alt="${p} logo" class="icpay-w-8 icpay-h-8" style="object-fit:contain" />
955
- </div>
956
- `:Z`
957
- <div style="width:48px;height:48px;background:linear-gradient(135deg,#3b82f6 0%,#8b5cf6 100%);border-radius:12px;display:flex;align-items:center;justify-content:center;font-size:12px;font-weight:bold">
958
- ${p}
959
- </div>
960
- `}
961
- <div><div style="font-weight:500">${p}</div></div>
962
- </button>`;return l==="ii"?Z`
963
- <div style="display:flex;gap:8px;align-items:center;width:100%">
964
- ${c}
965
- <button
966
- @click=${()=>{try{window.open("https://identity.ic0.app/","_blank","noopener,noreferrer")}catch{}}}
967
- title="Use a different Internet Identity"
968
- aria-label="Use a different Internet Identity"
969
- style="width:56px;height:72px;display:flex;align-items:center;justify-content:center;background:rgba(255,255,255,0.05);border:1px solid rgba(255,255,255,0.15);border-radius:8px;color:#9ca3af;cursor:pointer;">
970
- <span style="font-size:20px" aria-hidden="true">🔄</span>
971
- </button>
972
- </div>`:Z`<div style="width:100%">${c}</div>`})}
973
- </div>
974
- ${null}
975
- </div>
976
- </div>
977
- `}function W(r){try{let d=r||{};d.adapters=d.adapters||{};let e=d.adapters.oisy||{},t=e.config||{},i={...t.transport||{},windowOpenerFeatures:"",detectNonClickEstablishment:!1};return d.adapters.oisy={...e,config:{...t,transport:i}},d}catch{return r}}function k(r,d){try{let e=d&&(d.owner||d.principal)||null,t=r&&r.account&&(r.account.owner||r.account.principal)||null,i=o=>typeof o=="string"?o:o&&typeof o.toString=="function"?o.toString():null,s=i(e)||i(t)||null;return s?{owner:s,principal:s}:d||{owner:null}}catch{return d||{owner:null}}}async function Q(r){try{let d=typeof r?.getEnabledWallets=="function"?r.getEnabledWallets.bind(r):null;if(!d)return null;let t=(d()||[]).find(l=>(l?.id||"").toLowerCase()==="oisy");if(!t||!t.adapter)return null;let i=t.adapter,s=new i({config:r?.config||{}});if(!await s.isConnected())return null;let a=await s.getPrincipal();return a&&a!=="2vxsx-fae"?a:null}catch{return null}}var Ce=typeof window<"u",he=null;function J(r,d,e){r&&(e!==void 0?console.log(`[ICPay Widget] ${d}`,e):console.log(`[ICPay Widget] ${d}`))}var S=class extends et{constructor(){super(...arguments);this.selectedSymbol=null;this.unlocked=!1;this.succeeded=!1;this.processing=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.showOnrampModal=!1;this.onrampSessionId=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.transakMessageHandlerBound=null;this.onrampPollTimer=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="pay",this.showWalletModal=!0,this.requestUpdate();try{let t=Number(this.config?.priceUsd||0),i=this.selectedSymbol||this.config?.defaultSymbol;window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"pay",type:"sendUsd",amount:t,currency:i}}))}catch{}}catch{}}}async tryAutoConnectPNP(){try{if(!this.config||this.config?.useOwnWallet)return;let e=localStorage.getItem("icpay:pnp");if(!e)return;let t=JSON.parse(e);if(!t?.provider||!t?.principal)return;he||(he=(await import("./wallet-select-X3Y5ORRN.js")).WalletSelect);let i={...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:o}=await import("./origin-44ZEXSX4.js");i.derivationOrigin=this.config?.derivationOrigin||o()}}catch{}let s=new he(i);this.walletConnected=!1,this.config={...this.config,connectedWallet:{owner:t.principal,principal:t.principal,connected:!1}}}catch{}}get cryptoOptions(){return this.config.cryptoOptions?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){if(super.connectedCallback(),!!Ce){J(this.config?.debug||!1,"Premium content connected",{config:this.config}),this.tryAutoConnectPNP();try{window.addEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers()}}updated(e){if(e.has("config")&&this.pendingAction&&this.config?.actorProvider){let t=this.pendingAction;this.pendingAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}setTimeout(()=>{t==="pay"&&this.onPay()},0)}}async loadVerifiedLedgers(){if(!(!Ce||!this.config?.publishableKey))try{let t=await g(this.config).client.getVerifiedLedgers();this.availableLedgers=t.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||this.availableLedgers[0]?.symbol||"ICP")}catch(e){console.warn("Failed to load verified ledgers:",e),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||"ICP")}}async onPay(){if(Ce&&!(this.processing||this.unlocked)){J(this.config?.debug||!1,"Premium content payment started",{priceUsd:this.config.priceUsd,selectedSymbol:this.selectedSymbol,useOwnWallet:this.config.useOwnWallet}),this.errorMessage=null,this.errorSeverity=null,this.errorAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"pay",type:"sendUsd",amount:this.config.priceUsd,currency:this.selectedSymbol||this.config?.defaultSymbol}}))}catch{}this.processing=!0;try{if(this.config.useOwnWallet){if(!this.config.actorProvider){this.pendingAction="pay",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0}));return}}else if(!this.walletConnected){J(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{he||(he=(await import("./wallet-select-X3Y5ORRN.js")).WalletSelect);let l=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab)?W({...this.config?.plugNPlay||{}}):{...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:c}=await import("./origin-44ZEXSX4.js");l.derivationOrigin=this.config?.derivationOrigin||c()}}catch{}this.pnp=new he(l);try{let c=await Q(this.pnp);if(c){this.walletConnected=!0;let h=k(this.pnp,{owner:c,principal:c,connected:!0});this.config={...this.config,connectedWallet:h,actorProvider:($,A)=>this.pnp.getActor({canisterId:$,idl:A,requiresSigning:!0,anon:!1})};try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"oisy"}}))}catch{}this.onPay();return}}catch{}let p=this.pnp.getEnabledWallets();if(J(this.config?.debug||!1,"Available wallets",p),!p?.length)throw new Error("No wallets available");this.pendingAction="pay",this.showWalletModal=!0;return}catch(a){J(this.config?.debug||!1,"Wallet connection error:",a),this.errorMessage=a instanceof Error?a.message:"Wallet connection failed",this.errorSeverity="error";return}}J(this.config?.debug||!1,"Creating SDK for payment");let e=g(this.config),t=this.selectedSymbol||this.config?.defaultSymbol||"ICP",s=this.cryptoOptions.find(a=>a.symbol===t).canisterId||await e.client.getLedgerCanisterIdBySymbol(t);J(this.config?.debug||!1,"Payment details",{priceUsd:this.config.priceUsd,selectedSymbol:t,canisterId:s});let o=await e.sendUsd(this.config.priceUsd,s,{context:"premium-content"});J(this.config?.debug||!1,"Payment completed",{resp:o}),this.unlocked=!0,this.succeeded=!0,this.config.onSuccess&&this.config.onSuccess({id:o.transactionId,status:o.status}),this.dispatchEvent(new CustomEvent("icpay-unlock",{detail:{amount:this.config.priceUsd,tx:o},bubbles:!0}))}catch(e){U(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),B(t)&&(this.errorMessage=R(t),this.errorSeverity=z(t),this.errorAction=D(t))}});try{!this.config.useOwnWallet&&this.pnp&&(await this.pnp.disconnect?.(),this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0})}catch{}}finally{this.processing=!1}}}attachTransakMessageListener(){if(!this.transakMessageHandlerBound){this.transakMessageHandlerBound=e=>this.onTransakMessage(e);try{window.addEventListener("message",this.transakMessageHandlerBound)}catch{}}}detachTransakMessageListener(){if(this.transakMessageHandlerBound){try{window.removeEventListener("message",this.transakMessageHandlerBound)}catch{}this.transakMessageHandlerBound=null}}onTransakMessage(e){let t=e?.data,i=t?.event_id||t?.eventId||t?.id;if(!(!i||typeof i!="string")&&i==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let s=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(s||void 0)}}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1,setTimeout(()=>this.createOnrampIntent(),0)}async createOnrampIntent(){try{let e=g(this.config),t=this.selectedSymbol||this.config?.defaultSymbol||"ICP",s=this.cryptoOptions.find(c=>c.symbol===t).canisterId||await e.client.getLedgerCanisterIdBySymbol(t),o=await e.startOnrampUsd(this.config.priceUsd,s,{context:"premium:onramp"}),a=o?.metadata?.onramp?.sessionId||o?.metadata?.onramp?.session_id||null,l=o?.metadata?.paymentIntentId||o?.paymentIntentId||null,p=o?.metadata?.onramp?.errorMessage||null;this.onrampPaymentIntentId=l,a?(this.onrampSessionId=a,this.onrampErrorMessage=null,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.onrampErrorMessage=p||"Failed to obtain onramp sessionId",this.showOnrampModal=!0)}catch(e){this.onrampSessionId=null,this.onrampErrorMessage=e?.message||"Failed to obtain onramp sessionId",this.showOnrampModal=!0}}startOnrampPolling(e){if(this.onrampPollTimer){try{clearInterval(this.onrampPollTimer)}catch{}this.onrampPollTimer=null}if(this.onrampNotifyController){try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null}let t=this.onrampPaymentIntentId;if(!t)return;let i=g(this.config),s=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>s()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=i.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}select(e){this.selectedSymbol=e}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");this.lastWalletId=(e||"").toLowerCase(),this.pnp.connect(e).then(i=>{if(!!!(i&&(i.connected===!0||i.principal||i.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}let o=k(this.pnp,i);if(this.config={...this.config,connectedWallet:o,actorProvider:(l,p)=>this.pnp.getActor({canisterId:l,idl:p,requiresSigning:!0,anon:!1})},this.lastWalletId==="oisy")this.oisyReadyToPay=!0;else{this.showWalletModal=!1;let l=this.pendingAction;this.pendingAction=null,l==="pay"&&setTimeout(()=>this.onPay(),0)}}).catch(i=>{this.errorMessage=i instanceof Error?i.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1})}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}render(){return this.config?pe`
978
- <div class="icpay-card icpay-section icpay-widget-base">
979
- ${this.config?.progressBar?.enabled!==!1?pe`
980
- <icpay-progress-bar
981
- .debug=${!!this.config?.debug}
982
- .theme=${this.config?.theme}
983
- .amount=${Number(this.config?.priceUsd||0)}
984
- .ledgerSymbol=${this.selectedSymbol||this.config?.defaultSymbol||"ICP"}
985
- ></icpay-progress-bar>
986
- `:null}
987
- <div class="image-container">
988
- <div class="locked-image ${this.unlocked?"unlocked":""}" style="background-image:url('${this.config.imageUrl||""}')"></div>
989
- ${this.unlocked?null:pe`<div class="lock-overlay">🔒</div>`}
990
- </div>
991
-
992
- <div class="pricing">
993
- <div class="price">$${Number(this.config?.priceUsd??0).toFixed(2)}</div>
994
- <div class="label">One-time unlock</div>
995
- </div>
996
-
997
- <div>
998
- <icpay-token-selector
999
- .options=${this.cryptoOptions}
1000
- .value=${this.selectedSymbol||""}
1001
- .defaultSymbol=${this.config?.defaultSymbol||"ICP"}
1002
- mode=${this.config?.showLedgerDropdown||"buttons"}
1003
- @icpay-token-change=${e=>this.select(e.detail.symbol)}
1004
- ></icpay-token-selector>
1005
- </div>
1006
-
1007
- <button class="pay-button ${this.processing?"processing":""}" ?disabled=${this.processing||this.unlocked||this.config?.disablePaymentButton===!0||this.succeeded&&this.config?.disableAfterSuccess===!0} @click=${()=>this.onPay()}>
1008
- ${this.unlocked?"Unlocked":this.processing?"Processing\u2026":(this.config?.buttonLabel||"Pay ${amount} with {symbol}").replace("{amount}",`${Number(this.config?.priceUsd??0).toFixed(2)}`).replace("{symbol}",this.selectedSymbol||this.config?.defaultSymbol||"ICP")}
1009
- </button>
1010
-
1011
- ${this.errorMessage?pe`
1012
- <div class="error-message ${this.errorSeverity}" style="margin-top: 12px; padding: 8px 12px; border-radius: 6px; font-size: 14px; text-align: center;">
1013
- ${this.errorMessage}
1014
- ${this.errorAction?pe`
1015
- <button style="margin-left: 8px; padding: 4px 8px; background: transparent; border: 1px solid currentColor; border-radius: 4px; font-size: 12px; cursor: pointer;">
1016
- ${this.errorAction}
1017
- </button>
1018
- `:""}
1019
- </div>
1020
- `:""}
1021
- ${(()=>{let t=(this.pnp?.getEnabledWallets?.()||[]).map(i=>({id:this.getWalletId(i),label:this.getWalletLabel(i),icon:this.getWalletIcon(i)}));return H({visible:!!(this.showWalletModal&&this.pnp),wallets:t,isConnecting:!1,onSelect:i=>this.connectWithWallet(i),onClose:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1},onCreditCard:this.config?.onramp?.enabled!==!1&&this.config?.onrampDisabled!==!0?()=>this.startOnramp():void 0,creditCardLabel:this.config?.onramp?.creditCardLabel||"Pay with credit card",showCreditCard:this.config?.onramp?.enabled!==!1&&this.config?.onrampDisabled!==!0,creditCardTooltip:(()=>{let s=Number(this.config?.priceUsd||0);return s>0&&s<5&&this.config?.onramp?.enabled!==!1&&this.config?.onrampDisabled!==!0?`Note: Minimum card amount is $5. You will pay about $${(5-s).toFixed(2)} more.`:null})(),oisyReadyToPay:this.oisyReadyToPay,onOisyPay:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1,this.onPay()}})})()}
1022
-
1023
- ${this.showOnrampModal?F({visible:this.showOnrampModal,sessionId:this.onrampSessionId,errorMessage:this.onrampErrorMessage,apiKey:this.config?.onramp?.apiKey,environment:this.config?.onramp?.environment||"STAGING",width:this.config?.onramp?.width,height:this.config?.onramp?.height,onClose:()=>{this.showOnrampModal=!1},onBack:()=>{this.showOnrampModal=!1,this.showWalletModal=!0}}):null}
1024
- </div>
1025
- `:pe`<div class="icpay-card icpay-section">Loading...</div>`}};S.styles=[K,tt`
1026
- .image-container {
1027
- position: relative;
1028
- border-radius: 16px;
1029
- overflow: hidden;
1030
- margin-bottom: 16px;
1031
- background: #111827;
1032
- border: 1px solid var(--icpay-border);
1033
- aspect-ratio: 16/10;
1034
- }
1035
- .locked-image {
1036
- width: 100%;
1037
- height: 100%;
1038
- background-size: cover;
1039
- background-position: center;
1040
- background-repeat: no-repeat;
1041
- filter: blur(8px) grayscale(1);
1042
- transition: all 0.6s ease;
1043
- min-height: 200px;
1044
- }
1045
- .locked-image.unlocked { filter: blur(0px) grayscale(1); }
1046
- .lock-overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
1047
- .pricing { text-align: center; margin: 16px 0; }
1048
- .price { font-size: 28px; font-weight: 800; color: var(--icpay-text); }
1049
- .label { color: var(--icpay-muted); font-size: 14px; }
1050
- .crypto-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0 16px; }
1051
- .crypto-option { background: var(--icpay-surface-alt); border: 2px solid var(--icpay-border); border-radius: 12px; padding: 12px 8px; text-align: center; cursor: pointer; color: var(--icpay-text); font-weight: 600; font-size: 12px; }
1052
- .crypto-option.selected { background: var(--icpay-primary); color: #111827; border-color: var(--icpay-primary); }
1053
-
1054
- .error-message {
1055
- border: 1px solid;
1056
- font-weight: 500;
1057
- }
1058
-
1059
- .error-message.info {
1060
- background: rgba(59, 130, 246, 0.1);
1061
- border-color: rgba(59, 130, 246, 0.3);
1062
- color: #3b82f6;
1063
- }
1064
-
1065
- .error-message.warning {
1066
- background: rgba(245, 158, 11, 0.1);
1067
- border-color: rgba(245, 158, 11, 0.3);
1068
- color: #f59e0b;
1069
- }
1070
-
1071
- .error-message.error {
1072
- background: rgba(239, 68, 68, 0.1);
1073
- border-color: rgba(239, 68, 68, 0.3);
1074
- color: #ef4444;
1075
- }
1076
- `],n([nt({type:Object})],S.prototype,"config",2),n([L()],S.prototype,"selectedSymbol",2),n([L()],S.prototype,"unlocked",2),n([L()],S.prototype,"succeeded",2),n([L()],S.prototype,"processing",2),n([L()],S.prototype,"availableLedgers",2),n([L()],S.prototype,"errorMessage",2),n([L()],S.prototype,"errorSeverity",2),n([L()],S.prototype,"errorAction",2),n([L()],S.prototype,"walletConnected",2),n([L()],S.prototype,"pendingAction",2),n([L()],S.prototype,"showWalletModal",2),n([L()],S.prototype,"oisyReadyToPay",2),n([L()],S.prototype,"lastWalletId",2),n([L()],S.prototype,"showOnrampModal",2),n([L()],S.prototype,"onrampSessionId",2),n([L()],S.prototype,"onrampPaymentIntentId",2),n([L()],S.prototype,"onrampErrorMessage",2),S=n([it("icpay-premium-content")],S);import{LitElement as st,html as le,css as ot}from"lit";import{customElement as rt,property as at,state as M}from"lit/decorators.js";var Oe=typeof window<"u",ue=null;function ee(r,d,e){r&&(e!==void 0?console.log(`[ICPay Widget] ${d}`,e):console.log(`[ICPay Widget] ${d}`))}var f=class extends st{constructor(){super(...arguments);this.selectedAmount=1;this.selectedSymbol=null;this.total=0;this.processing=!1;this.succeeded=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.showOnrampModal=!1;this.onrampSessionId=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.transakMessageHandlerBound=null;this.onrampPollTimer=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="tip",this.showWalletModal=!0,this.requestUpdate();try{let t=Number(this.selectedAmount||0),i=this.selectedSymbol||this.config?.defaultSymbol;window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"tip",type:"sendUsd",amount:t,currency:i}}))}catch{}}catch{}}}async tryAutoConnectPNP(){try{if(!this.config||this.config?.useOwnWallet)return;let e=localStorage.getItem("icpay:pnp");if(!e)return;let t=JSON.parse(e);if(!t?.provider||!t?.principal)return;ue||(ue=(await import("./wallet-select-X3Y5ORRN.js")).WalletSelect);let i=W({...this.config?.plugNPlay||{}});try{if(typeof window<"u"){let{resolveDerivationOrigin:o}=await import("./origin-44ZEXSX4.js");i.derivationOrigin=this.config?.derivationOrigin||o()}}catch{}let s=new ue(i);this.walletConnected=!1,this.config={...this.config,connectedWallet:{owner:t.principal,principal:t.principal,connected:!1}}}catch{}}get amounts(){return this.config?.amountsUsd||[1,5,10]}get cryptoOptions(){return this.config.cryptoOptions?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){if(super.connectedCallback(),!!Oe){ee(this.config?.debug||!1,"Tip jar connected",{config:this.config}),this.config&&this.config.defaultAmountUsd&&(this.selectedAmount=this.config.defaultAmountUsd),this.tryAutoConnectPNP();try{window.addEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers(),this.config?.defaultSymbol&&(this.selectedSymbol=this.config.defaultSymbol)}}updated(e){if(e.has("config")&&this.pendingAction&&this.config?.actorProvider){let t=this.pendingAction;this.pendingAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}setTimeout(()=>{t==="tip"&&this.tip()},0)}}async loadVerifiedLedgers(){if(!(!Oe||!this.config?.publishableKey))try{let t=await g(this.config).client.getVerifiedLedgers();this.availableLedgers=t.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.config?.cryptoOptions&&this.config.cryptoOptions.length===1&&(this.selectedSymbol=this.config.cryptoOptions[0].symbol),!this.selectedSymbol&&this.availableLedgers.length>0&&(this.selectedSymbol=this.config?.defaultSymbol||this.availableLedgers[0].symbol)}catch(e){console.warn("Failed to load verified ledgers:",e),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||"ICP")}}selectAmount(e){this.selectedAmount=e}selectSymbol(e){this.selectedSymbol=e}get fillPercentage(){return Math.min(this.total/50*100,100)}async tip(){if(Oe&&(ee(this.config?.debug||!1,"Tip button clicked!",{config:this.config,processing:this.processing}),!this.processing)){this.errorMessage=null,this.errorSeverity=null,this.errorAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"tip",type:"sendUsd",amount:this.selectedAmount,currency:this.selectedSymbol||this.config?.defaultSymbol}}))}catch{}this.processing=!0;try{if(this.config.useOwnWallet){if(!this.config.actorProvider){this.pendingAction="tip",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0}));return}}else if(!this.walletConnected){ee(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{ue||(ue=(await import("./wallet-select-X3Y5ORRN.js")).WalletSelect);let l=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab)?W({...this.config?.plugNPlay||{}}):{...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:c}=await import("./origin-44ZEXSX4.js");l.derivationOrigin=this.config?.derivationOrigin||c()}}catch{}this.pnp=new ue(l);try{let c=await Q(this.pnp);if(c){this.walletConnected=!0;let h=k(this.pnp,{owner:c,principal:c,connected:!0});this.config={...this.config,connectedWallet:h,actorProvider:($,A)=>this.pnp.getActor({canisterId:$,idl:A,requiresSigning:!0,anon:!1})};try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"oisy"}}))}catch{}this.tip();return}}catch{}let p=this.pnp.getEnabledWallets();if(ee(this.config?.debug||!1,"Available wallets",p),!p?.length)throw new Error("No wallets available");this.pendingAction="tip",this.showWalletModal=!0;return}catch(a){ee(this.config?.debug||!1,"Wallet connection error:",a),this.errorMessage=a instanceof Error?a.message:"Wallet connection failed",this.errorSeverity="error";return}}ee(this.config?.debug||!1,"Creating SDK for payment");let e=g(this.config),t=this.selectedSymbol||this.config?.defaultSymbol||"ICP",s=this.cryptoOptions.find(a=>a.symbol===t).canisterId||await e.client.getLedgerCanisterIdBySymbol(t);ee(this.config?.debug||!1,"Tip payment details",{amount:this.selectedAmount,selectedSymbol:t,canisterId:s});let o=await e.sendUsd(this.selectedAmount,s,{context:"tip-jar"});ee(this.config?.debug||!1,"Tip payment completed",{resp:o}),this.total+=this.selectedAmount,this.succeeded=!0,this.config.onSuccess&&this.config.onSuccess({id:o.transactionId,status:o.status,total:this.total}),this.dispatchEvent(new CustomEvent("icpay-tip",{detail:{amount:this.selectedAmount,tx:o},bubbles:!0}))}catch(e){U(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),B(t)&&(this.errorMessage=R(t),this.errorSeverity=z(t),this.errorAction=D(t))}});try{!this.config.useOwnWallet&&this.pnp&&(await this.pnp.disconnect?.(),this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0})}catch{}}finally{this.processing=!1}}}attachTransakMessageListener(){if(!this.transakMessageHandlerBound){this.transakMessageHandlerBound=e=>this.onTransakMessage(e);try{window.addEventListener("message",this.transakMessageHandlerBound)}catch{}}}detachTransakMessageListener(){if(this.transakMessageHandlerBound){try{window.removeEventListener("message",this.transakMessageHandlerBound)}catch{}this.transakMessageHandlerBound=null}}onTransakMessage(e){let t=e?.data,i=t?.event_id||t?.eventId||t?.id;if(!(!i||typeof i!="string")&&i==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let s=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(s||void 0)}}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1,setTimeout(()=>this.createOnrampIntent(),0)}async createOnrampIntent(){try{let e=g(this.config),t=this.selectedSymbol||this.config?.defaultSymbol||"ICP",s=this.cryptoOptions.find(c=>c.symbol===t).canisterId||await e.client.getLedgerCanisterIdBySymbol(t),o=await e.startOnrampUsd(this.selectedAmount,s,{context:"tip:onramp"}),a=o?.metadata?.onramp?.sessionId||o?.metadata?.onramp?.session_id||null,l=o?.metadata?.paymentIntentId||o?.paymentIntentId||null,p=o?.metadata?.onramp?.errorMessage||null;this.onrampPaymentIntentId=l,a?(this.onrampSessionId=a,this.onrampErrorMessage=null,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.onrampErrorMessage=p||"Failed to obtain onramp sessionId",this.showOnrampModal=!0)}catch(e){this.onrampSessionId=null,this.onrampErrorMessage=e?.message||"Failed to obtain onramp sessionId",this.showOnrampModal=!0}}startOnrampPolling(e){if(this.onrampPollTimer){try{clearInterval(this.onrampPollTimer)}catch{}this.onrampPollTimer=null}if(this.onrampNotifyController){try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null}let t=this.onrampPaymentIntentId;if(!t)return;let i=g(this.config),s=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>s()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=i.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");this.lastWalletId=(e||"").toLowerCase(),this.pnp.connect(e).then(i=>{if(!!!(i&&(i.connected===!0||i.principal||i.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}let o=k(this.pnp,i);if(this.config={...this.config,connectedWallet:o,actorProvider:(l,p)=>this.pnp.getActor({canisterId:l,idl:p,requiresSigning:!0,anon:!1})},this.lastWalletId==="oisy")this.oisyReadyToPay=!0;else{this.showWalletModal=!1;let l=this.pendingAction;this.pendingAction=null,l==="tip"&&setTimeout(()=>this.tip(),0)}}).catch(i=>{this.errorMessage=i instanceof Error?i.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1})}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}render(){if(!this.config)return le`<div class="icpay-card icpay-section">Loading...</div>`;let t=(this.cryptoOptions?.length||0)>1,i=this.config?.showLedgerDropdown,s=i==="dropdown"?"dropdown":i==="none"?"none":"buttons",o=s!=="none"&&(t||s==="dropdown"),a=s==="dropdown"?"dropdown":t?"buttons":"none";return le`
1077
- <div class="icpay-card icpay-section icpay-widget-base" style="text-align:center;">
1078
- ${this.config?.progressBar?.enabled!==!1?le`
1079
- <icpay-progress-bar
1080
- .debug=${!!this.config?.debug}
1081
- .theme=${this.config?.theme}
1082
- .amount=${Number(this.selectedAmount||0)}
1083
- .ledgerSymbol=${this.selectedSymbol||this.config?.defaultSymbol||"ICP"}
1084
- ></icpay-progress-bar>
1085
- `:null}
1086
- <div class="jar"><div class="fill" style="height:${this.fillPercentage}%"></div></div>
1087
- <div class="label">Total Tips: $${this.total}</div>
1088
-
1089
- <div class="amounts">
1090
- ${this.amounts.map(l=>le`<div class="chip ${this.selectedAmount===l?"selected":""}" @click=${()=>this.selectAmount(l)}>$${l}</div>`)}
1091
- </div>
1092
-
1093
- ${o?le`
1094
- <div>
1095
- <icpay-token-selector
1096
- .options=${this.cryptoOptions}
1097
- .value=${this.selectedSymbol||""}
1098
- .defaultSymbol=${this.config?.defaultSymbol||"ICP"}
1099
- mode=${a}
1100
- @icpay-token-change=${l=>this.selectSymbol(l.detail.symbol)}
1101
- ></icpay-token-selector>
1102
- </div>
1103
- `:null}
1104
-
1105
- <button class="pay-button ${this.processing?"processing":""}"
1106
- ?disabled=${this.processing||this.config?.disablePaymentButton===!0||this.succeeded&&this.config?.disableAfterSuccess===!0}
1107
- @click=${()=>this.tip()}>
1108
- ${this.succeeded&&this.config?.disableAfterSuccess?"Paid":this.processing?"Processing\u2026":this.config?.buttonLabel?this.config.buttonLabel.replace("{amount}",String(this.selectedAmount)).replace("{symbol}",this.selectedSymbol||this.config?.defaultSymbol||"ICP"):`Tip $${this.selectedAmount} with ${this.selectedSymbol||this.config?.defaultSymbol||"ICP"}`}
1109
- </button>
1110
-
1111
- ${this.errorMessage?le`
1112
- <div class="error-message ${this.errorSeverity}" style="margin-top: 12px; padding: 8px 12px; border-radius: 6px; font-size: 14px; text-align: center;">
1113
- ${this.errorMessage}
1114
- ${this.errorAction?le`
1115
- <button style="margin-left: 8px; padding: 4px 8px; background: transparent; border: 1px solid currentColor; border-radius: 4px; font-size: 12px; cursor: pointer;">
1116
- ${this.errorAction}
1117
- </button>
1118
- `:""}
1119
- </div>
1120
- `:""}
1121
- ${(()=>{let p=(this.pnp?.getEnabledWallets?.()||[]).map(c=>({id:this.getWalletId(c),label:this.getWalletLabel(c),icon:this.getWalletIcon(c)}));return H({visible:!!(this.showWalletModal&&this.pnp),wallets:p,isConnecting:!1,onSelect:c=>this.connectWithWallet(c),onClose:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1},onCreditCard:this.config?.onramp?.enabled!==!1?()=>this.startOnramp():void 0,creditCardLabel:this.config?.onramp?.creditCardLabel||"Pay with credit card",showCreditCard:this.config?.onramp?.enabled!==!1,creditCardTooltip:(()=>{let h=Number(this.selectedAmount||this.config?.defaultAmountUsd||0);return h>0&&h<5&&this.config?.onramp?.enabled!==!1?`Note: Minimum card amount is $5. You will pay about $${(5-h).toFixed(2)} more.`:null})(),oisyReadyToPay:this.oisyReadyToPay,onOisyPay:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1,this.tip()}})})()}
1122
-
1123
- ${this.showOnrampModal?F({visible:this.showOnrampModal,sessionId:this.onrampSessionId,errorMessage:this.onrampErrorMessage,apiKey:this.config?.onramp?.apiKey,environment:this.config?.onramp?.environment||"STAGING",width:this.config?.onramp?.width,height:this.config?.onramp?.height,onClose:()=>{this.showOnrampModal=!1},onBack:()=>{this.showOnrampModal=!1,this.showWalletModal=!0}}):null}
1124
- </div>
1125
- `}};f.styles=[K,ot`
1126
- .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; }
1127
- .fill { position: absolute; bottom: 0; left: 0; right: 0; background: linear-gradient(135deg, #d1d5db 0%, #9ca3af 100%); transition: height 0.8s ease; height: 0%; }
1128
- .amounts { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; margin: 12px 0; }
1129
- .chip { background: var(--icpay-surface-alt); border: 2px solid var(--icpay-border); border-radius: 12px; padding: 12px; text-align: center; cursor: pointer; color: var(--icpay-text); font-weight: 600; }
1130
- .chip.selected { background: var(--icpay-primary); color: #111827; border-color: var(--icpay-primary); }
1131
- .crypto-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0 16px; }
1132
- .crypto-option { background: var(--icpay-surface-alt); border: 2px solid var(--icpay-border); border-radius: 12px; padding: 12px 8px; text-align: center; cursor: pointer; color: var(--icpay-text); font-weight: 600; font-size: 12px; }
1133
- .crypto-option.selected { background: var(--icpay-primary); color: #111827; border-color: var(--icpay-primary); }
1134
-
1135
- .error-message {
1136
- border: 1px solid;
1137
- font-weight: 500;
1138
- }
1139
-
1140
- .error-message.info {
1141
- background: rgba(59, 130, 246, 0.1);
1142
- border-color: rgba(59, 130, 246, 0.3);
1143
- color: #3b82f6;
1144
- }
1145
-
1146
- .error-message.warning {
1147
- background: rgba(245, 158, 11, 0.1);
1148
- border-color: rgba(245, 158, 11, 0.3);
1149
- color: #f59e0b;
1150
- }
1151
-
1152
- .error-message.error {
1153
- background: rgba(239, 68, 68, 0.1);
1154
- border-color: rgba(239, 68, 68, 0.3);
1155
- color: #ef4444;
1156
- }
1157
- `],n([at({type:Object})],f.prototype,"config",2),n([M()],f.prototype,"selectedAmount",2),n([M()],f.prototype,"selectedSymbol",2),n([M()],f.prototype,"total",2),n([M()],f.prototype,"processing",2),n([M()],f.prototype,"succeeded",2),n([M()],f.prototype,"availableLedgers",2),n([M()],f.prototype,"errorMessage",2),n([M()],f.prototype,"errorSeverity",2),n([M()],f.prototype,"errorAction",2),n([M()],f.prototype,"walletConnected",2),n([M()],f.prototype,"pendingAction",2),n([M()],f.prototype,"showWalletModal",2),n([M()],f.prototype,"oisyReadyToPay",2),n([M()],f.prototype,"lastWalletId",2),n([M()],f.prototype,"showOnrampModal",2),n([M()],f.prototype,"onrampSessionId",2),n([M()],f.prototype,"onrampPaymentIntentId",2),n([M()],f.prototype,"onrampErrorMessage",2),f=n([rt("icpay-tip-jar")],f);import{LitElement as lt,html as Se,css as ct}from"lit";import{customElement as dt,property as ke,state as T}from"lit/decorators.js";var Ie=typeof window<"u",ye=null;function te(r,d,e){r&&(e!==void 0?console.log(`[ICPay Widget] ${d}`,e):console.log(`[ICPay Widget] ${d}`))}var m=class extends lt{constructor(){super(...arguments);this.title="Article Title";this.preview="";this.lockedContent="";this.selectedSymbol=null;this.unlocked=!1;this.succeeded=!1;this.processing=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.showOnrampModal=!1;this.onrampSessionId=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.transakMessageHandlerBound=null;this.onrampPollTimer=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="unlock",this.showWalletModal=!0,this.requestUpdate();try{let t=Number(this.config?.priceUsd||0),i=this.selectedSymbol||this.config?.defaultSymbol;window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"unlock",type:"sendUsd",amount:t,currency:i}}))}catch{}}catch{}}}get obfuscatedLockedContent(){try{return(this.lockedContent||"").replace(/[^\s]/g,"x")}catch{return"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}}async tryAutoConnectPNP(){try{if(!this.config||this.config?.useOwnWallet)return;let e=localStorage.getItem("icpay:pnp");if(!e)return;let t=JSON.parse(e);if(!t?.provider||!t?.principal)return;ye||(ye=(await import("./wallet-select-X3Y5ORRN.js")).WalletSelect);let i={...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:o}=await import("./origin-44ZEXSX4.js");i.derivationOrigin=this.config?.derivationOrigin||o()}}catch{}let s=new ye(i);this.walletConnected=!1,this.config={...this.config,connectedWallet:{owner:t.principal,principal:t.principal,connected:!1}}}catch{}}attachTransakMessageListener(){if(!this.transakMessageHandlerBound){this.transakMessageHandlerBound=e=>this.onTransakMessage(e);try{window.addEventListener("message",this.transakMessageHandlerBound)}catch{}}}detachTransakMessageListener(){if(this.transakMessageHandlerBound){try{window.removeEventListener("message",this.transakMessageHandlerBound)}catch{}this.transakMessageHandlerBound=null}}onTransakMessage(e){let t=e?.data,i=t?.event_id||t?.eventId||t?.id;if(!(!i||typeof i!="string")&&i==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let s=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(s||void 0)}}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1,setTimeout(()=>this.createOnrampIntent(),0)}async createOnrampIntent(){try{let e=g(this.config),t=this.selectedSymbol||this.config?.defaultSymbol||"ICP",s=this.cryptoOptions.find(c=>c.symbol===t).canisterId||await e.client.getLedgerCanisterIdBySymbol(t),o=await e.startOnrampUsd(this.config.priceUsd,s,{context:"article:onramp"}),a=o?.metadata?.onramp?.sessionId||o?.metadata?.onramp?.session_id||null,l=o?.metadata?.paymentIntentId||o?.paymentIntentId||null,p=o?.metadata?.onramp?.errorMessage||null;this.onrampPaymentIntentId=l,a?(this.onrampSessionId=a,this.onrampErrorMessage=null,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.onrampErrorMessage=p||"Failed to obtain onramp sessionId",this.showOnrampModal=!0)}catch(e){this.onrampSessionId=null,this.onrampErrorMessage=e?.message||"Failed to obtain onramp sessionId",this.showOnrampModal=!0}}startOnrampPolling(e){if(this.onrampPollTimer){try{clearInterval(this.onrampPollTimer)}catch{}this.onrampPollTimer=null}if(this.onrampNotifyController){try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null}let t=this.onrampPaymentIntentId;if(!t)return;let i=g(this.config),s=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>s()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=i.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}get cryptoOptions(){return this.config.cryptoOptions?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){if(super.connectedCallback(),!!Ie){te(this.config?.debug||!1,"Article paywall connected",{config:this.config}),this.config&&(typeof this.config.title=="string"&&(this.title=this.config.title),typeof this.config.preview=="string"&&(this.preview=this.config.preview),typeof this.config.lockedContent=="string"&&(this.lockedContent=this.config.lockedContent)),this.tryAutoConnectPNP();try{window.addEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers()}}updated(e){if(e.has("config")&&this.config&&(typeof this.config.title=="string"&&(this.title=this.config.title),typeof this.config.preview=="string"&&(this.preview=this.config.preview),typeof this.config.lockedContent=="string"&&(this.lockedContent=this.config.lockedContent)),e.has("config")&&this.pendingAction&&this.config?.actorProvider){let t=this.pendingAction;this.pendingAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}setTimeout(()=>{t==="unlock"&&this.unlock()},0)}}async loadVerifiedLedgers(){if(!(!Ie||!this.config?.publishableKey))try{let t=await g(this.config).client.getVerifiedLedgers();this.availableLedgers=t.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||this.availableLedgers[0]?.symbol||"ICP")}catch(e){console.warn("Failed to load verified ledgers:",e),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||"ICP")}}selectSymbol(e){this.selectedSymbol=e}async unlock(){if(Ie&&!(this.processing||this.unlocked)){te(this.config?.debug||!1,"Article paywall unlock started",{priceUsd:this.config.priceUsd,selectedSymbol:this.selectedSymbol,useOwnWallet:this.config.useOwnWallet}),this.errorMessage=null,this.errorSeverity=null,this.errorAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"unlock",type:"sendUsd",amount:this.config.priceUsd,currency:this.selectedSymbol||this.config?.defaultSymbol}}))}catch{}this.processing=!0;try{if(this.config.useOwnWallet){if(!this.config.actorProvider){this.pendingAction="unlock",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0}));return}}else if(!this.walletConnected){te(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{ye||(ye=(await import("./wallet-select-X3Y5ORRN.js")).WalletSelect);let l=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab)?W({...this.config?.plugNPlay||{}}):{...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:c}=await import("./origin-44ZEXSX4.js");l.derivationOrigin=this.config?.derivationOrigin||c()}}catch{}this.pnp=new ye(l);try{let c=await Q(this.pnp);if(c){this.walletConnected=!0;let h=k(this.pnp,{owner:c,principal:c,connected:!0});this.config={...this.config,connectedWallet:h,actorProvider:($,A)=>this.pnp.getActor({canisterId:$,idl:A,requiresSigning:!0,anon:!1})};try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"oisy"}}))}catch{}this.unlock();return}}catch{}let p=this.pnp.getEnabledWallets();if(te(this.config?.debug||!1,"Available wallets",p),!p?.length)throw new Error("No wallets available");this.pendingAction="unlock",this.showWalletModal=!0;return}catch(a){te(this.config?.debug||!1,"Wallet connection error:",a),this.errorMessage=a instanceof Error?a.message:"Wallet connection failed",this.errorSeverity="error";return}}te(this.config?.debug||!1,"Creating SDK for payment");let e=g(this.config),t=this.selectedSymbol||this.config?.defaultSymbol||"ICP",s=this.cryptoOptions.find(a=>a.symbol===t).canisterId||await e.client.getLedgerCanisterIdBySymbol(t);te(this.config?.debug||!1,"Article payment details",{priceUsd:this.config.priceUsd,selectedSymbol:t,canisterId:s});let o=await e.sendUsd(this.config.priceUsd,s,{context:"article"});te(this.config?.debug||!1,"Article payment completed",{resp:o}),this.unlocked=!0,this.succeeded=!0,this.config.onSuccess&&this.config.onSuccess({id:o.transactionId,status:o.status}),this.dispatchEvent(new CustomEvent("icpay-unlock",{detail:{amount:this.config.priceUsd,tx:o},bubbles:!0}))}catch(e){U(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),B(t)&&(this.errorMessage=R(t),this.errorSeverity=z(t),this.errorAction=D(t))}});try{!this.config.useOwnWallet&&this.pnp&&(await this.pnp.disconnect?.(),this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0})}catch{}}finally{this.processing=!1}}}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");this.lastWalletId=(e||"").toLowerCase(),this.pnp.connect(e).then(i=>{if(!!!(i&&(i.connected===!0||i.principal||i.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}let o=k(this.pnp,i);if(this.config={...this.config,connectedWallet:o,actorProvider:(l,p)=>this.pnp.getActor({canisterId:l,idl:p,requiresSigning:!0,anon:!1})},this.lastWalletId==="oisy")this.oisyReadyToPay=!0;else{this.showWalletModal=!1;let l=this.pendingAction;this.pendingAction=null,l==="unlock"&&setTimeout(()=>this.unlock(),0)}}).catch(i=>{this.errorMessage=i instanceof Error?i.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1})}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}render(){return this.config?Se`
1158
- <div class="icpay-card icpay-section icpay-widget-base">
1159
- ${this.config?.progressBar?.enabled!==!1?Se`
1160
- <icpay-progress-bar
1161
- .debug=${!!this.config?.debug}
1162
- .theme=${this.config?.theme}
1163
- .amount=${Number(this.config?.priceUsd||0)}
1164
- .ledgerSymbol=${this.selectedSymbol||this.config?.defaultSymbol||"ICP"}
1165
- ></icpay-progress-bar>
1166
- `:null}
1167
- <div class="container">
1168
- <div class="title">${this.title}</div>
1169
- <div class="preview">${this.preview}</div>
1170
- <div class="${this.unlocked?"unlocked":"locked"}">${this.unlocked?this.lockedContent:this.obfuscatedLockedContent}</div>
1171
- </div>
1172
- <div>
1173
- <icpay-token-selector
1174
- .options=${this.cryptoOptions}
1175
- .value=${this.selectedSymbol||""}
1176
- .defaultSymbol=${this.config?.defaultSymbol||"ICP"}
1177
- mode=${this.config?.showLedgerDropdown||"buttons"}
1178
- @icpay-token-change=${e=>this.selectSymbol(e.detail.symbol)}
1179
- ></icpay-token-selector>
1180
- </div>
1181
- <button class="pay-button ${this.processing?"processing":""}" ?disabled=${this.processing||this.unlocked||this.config?.disablePaymentButton===!0||this.succeeded&&this.config?.disableAfterSuccess===!0} @click=${()=>this.unlock()}>
1182
- ${this.unlocked?"Unlocked":this.processing?"Processing\u2026":(this.config?.buttonLabel||"Pay ${amount} with {symbol}").replace("{amount}",`${Number(this.config?.priceUsd??0).toFixed(2)}`).replace("{symbol}",this.selectedSymbol||this.config?.defaultSymbol||"ICP")}
1183
- </button>
1184
-
1185
- ${this.errorMessage?Se`
1186
- <div class="error-message ${this.errorSeverity}" style="margin-top: 12px; padding: 8px 12px; border-radius: 6px; font-size: 14px; text-align: center;">
1187
- ${this.errorMessage}
1188
- ${this.errorAction?Se`
1189
- <button style="margin-left: 8px; padding: 4px 8px; background: transparent; border: 1px solid currentColor; border-radius: 4px; font-size: 12px; cursor: pointer;">
1190
- ${this.errorAction}
1191
- </button>
1192
- `:""}
1193
- </div>
1194
- `:""}
1195
- ${(()=>{let t=(this.pnp?.getEnabledWallets?.()||[]).map(i=>({id:this.getWalletId(i),label:this.getWalletLabel(i),icon:this.getWalletIcon(i)}));return H({visible:!!(this.showWalletModal&&this.pnp),wallets:t,isConnecting:!1,onSelect:i=>this.connectWithWallet(i),onClose:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1},onCreditCard:this.config?.onramp?.enabled!==!1&&this.config?.onrampDisabled!==!0?()=>this.startOnramp():void 0,creditCardLabel:this.config?.onramp?.creditCardLabel||"Pay with credit card",showCreditCard:this.config?.onramp?.enabled!==!1&&this.config?.onrampDisabled!==!0,creditCardTooltip:(()=>{let s=Number(this.config?.priceUsd||0);return s>0&&s<5&&this.config?.onramp?.enabled!==!1&&this.config?.onrampDisabled!==!0?`Note: Minimum card amount is $5. You will pay about $${(5-s).toFixed(2)} more.`:null})(),oisyReadyToPay:this.oisyReadyToPay,onOisyPay:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1,this.unlock()}})})()}
1196
-
1197
- ${this.showOnrampModal?F({visible:this.showOnrampModal,sessionId:this.onrampSessionId,errorMessage:this.onrampErrorMessage,apiKey:this.config?.onramp?.apiKey,environment:this.config?.onramp?.environment||"STAGING",width:this.config?.onramp?.width,height:this.config?.onramp?.height,onClose:()=>{this.showOnrampModal=!1},onBack:()=>{this.showOnrampModal=!1,this.showWalletModal=!0}}):null}
1198
- </div>
1199
- `:Se`<div class="icpay-card icpay-section">Loading...</div>`}};m.styles=[K,ct`
1200
- .container { background: var(--icpay-surface-alt); border: 1px solid var(--icpay-border); border-radius: 16px; padding: 16px; margin-bottom: 16px; }
1201
- .title { color: var(--icpay-text); font-weight: 700; margin-bottom: 8px; }
1202
- .preview { color: var(--icpay-muted); margin-bottom: 12px; line-height: 1.6; }
1203
- .locked { filter: blur(3px); color: #6b7280; margin-bottom: 12px; }
1204
- .unlocked { filter: blur(0); color: var(--icpay-text); }
1205
- .crypto-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0 16px; }
1206
- .crypto-option { background: var(--icpay-surface-alt); border: 2px solid var(--icpay-border); border-radius: 12px; padding: 12px 8px; text-align: center; cursor: pointer; color: var(--icpay-text); font-weight: 600; font-size: 12px; }
1207
- .crypto-option.selected { background: var(--icpay-primary); color: #111827; border-color: var(--icpay-primary); }
1208
-
1209
- .error-message {
1210
- border: 1px solid;
1211
- font-weight: 500;
1212
- }
1213
-
1214
- .error-message.info {
1215
- background: rgba(59, 130, 246, 0.1);
1216
- border-color: rgba(59, 130, 246, 0.3);
1217
- color: #3b82f6;
1218
- }
1219
-
1220
- .error-message.warning {
1221
- background: rgba(245, 158, 11, 0.1);
1222
- border-color: rgba(245, 158, 11, 0.3);
1223
- color: #f59e0b;
1224
- }
1225
-
1226
- .error-message.error {
1227
- background: rgba(239, 68, 68, 0.1);
1228
- border-color: rgba(239, 68, 68, 0.3);
1229
- color: #ef4444;
1230
- }
1231
- `],n([ke({type:Object})],m.prototype,"config",2),n([ke({type:String})],m.prototype,"title",2),n([ke({type:String})],m.prototype,"preview",2),n([ke({type:String})],m.prototype,"lockedContent",2),n([T()],m.prototype,"selectedSymbol",2),n([T()],m.prototype,"unlocked",2),n([T()],m.prototype,"succeeded",2),n([T()],m.prototype,"processing",2),n([T()],m.prototype,"availableLedgers",2),n([T()],m.prototype,"errorMessage",2),n([T()],m.prototype,"errorSeverity",2),n([T()],m.prototype,"errorAction",2),n([T()],m.prototype,"walletConnected",2),n([T()],m.prototype,"pendingAction",2),n([T()],m.prototype,"showWalletModal",2),n([T()],m.prototype,"oisyReadyToPay",2),n([T()],m.prototype,"lastWalletId",2),n([T()],m.prototype,"showOnrampModal",2),n([T()],m.prototype,"onrampSessionId",2),n([T()],m.prototype,"onrampPaymentIntentId",2),n([T()],m.prototype,"onrampErrorMessage",2),m=n([dt("icpay-article-paywall")],m);import{LitElement as pt,html as me,css as ht}from"lit";import{customElement as gt,property as ut,state as N}from"lit/decorators.js";var We=typeof window<"u",Le=null;function ie(r,d,e){r&&(e!==void 0?console.log(`[ICPay Widget] ${d}`,e):console.log(`[ICPay Widget] ${d}`))}var E=class extends pt{constructor(){super(...arguments);this.selectedIndex=0;this.selectedSymbol=null;this.processing=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.showOnrampModal=!1;this.onrampSessionId=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.transakMessageHandlerBound=null;this.onrampPollTimer=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="order",this.showWalletModal=!0,this.requestUpdate();try{let t=Number(this.selectedItem?.priceUsd||0),i=this.selectedSymbol||this.config?.defaultSymbol;window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"order",type:"sendUsd",amount:t,currency:i}}))}catch{}}catch{}}}get cryptoOptions(){return this.config.cryptoOptions?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){if(super.connectedCallback(),!!We){ie(this.config?.debug||!1,"Coffee shop connected",{config:this.config}),this.config&&typeof this.config.defaultItemIndex=="number"&&(this.selectedIndex=this.config.defaultItemIndex),this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers();try{window.addEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}}}updated(e){if(e.has("config")&&this.pendingAction&&this.config?.actorProvider){let t=this.pendingAction;this.pendingAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}setTimeout(()=>{t==="order"&&this.order()},0)}}async loadVerifiedLedgers(){if(!(!We||!this.config?.publishableKey))try{let t=await g(this.config).client.getVerifiedLedgers();this.availableLedgers=t.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||this.availableLedgers[0]?.symbol||"ICP")}catch(e){console.warn("Failed to load verified ledgers:",e),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||"ICP")}}selectItem(e){this.selectedIndex=e}selectSymbol(e){this.selectedSymbol=e}get selectedItem(){return this.config?.items?.[this.selectedIndex]||{name:"Loading...",priceUsd:0}}async order(){if(We&&!this.processing){ie(this.config?.debug||!1,"Coffee order started",{selectedItem:this.selectedItem,selectedSymbol:this.selectedSymbol,useOwnWallet:this.config.useOwnWallet}),this.errorMessage=null,this.errorSeverity=null,this.errorAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"order",type:"sendUsd",amount:this.selectedItem.priceUsd,currency:this.selectedSymbol||this.config?.defaultSymbol}}))}catch{}this.processing=!0;try{if(this.config.useOwnWallet){if(!this.config.actorProvider){this.pendingAction="order",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0}));return}}else if(!this.walletConnected){ie(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{Le||(Le=(await import("./wallet-select-X3Y5ORRN.js")).WalletSelect);let l=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab)?W({...this.config?.plugNPlay||{}}):{...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:c}=await import("./origin-44ZEXSX4.js");l.derivationOrigin=this.config?.derivationOrigin||c()}}catch{}this.pnp=new Le(l);try{let c=await Q(this.pnp);if(c){this.walletConnected=!0;let h=k(this.pnp,{owner:c,principal:c,connected:!0});this.config={...this.config,connectedWallet:h,actorProvider:($,A)=>this.pnp.getActor({canisterId:$,idl:A,requiresSigning:!0,anon:!1})};try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"oisy"}}))}catch{}this.order();return}}catch{}let p=this.pnp.getEnabledWallets();if(ie(this.config?.debug||!1,"Available wallets",p),!p?.length)throw new Error("No wallets available");this.pendingAction="order",this.showWalletModal=!0;return}catch(a){ie(this.config?.debug||!1,"Wallet connection error:",a),this.errorMessage=a instanceof Error?a.message:"Wallet connection failed",this.errorSeverity="error";return}}ie(this.config?.debug||!1,"Creating SDK for payment");let e=g(this.config),t=this.selectedSymbol||this.config?.defaultSymbol||"ICP",s=this.cryptoOptions.find(a=>a.symbol===t).canisterId||await e.client.getLedgerCanisterIdBySymbol(t);ie(this.config?.debug||!1,"Coffee order payment details",{item:this.selectedItem.name,priceUsd:this.selectedItem.priceUsd,selectedSymbol:t,canisterId:s});let o=await e.sendUsd(this.selectedItem.priceUsd,s,{context:"coffee",item:this.selectedItem.name});ie(this.config?.debug||!1,"Coffee order payment completed",{resp:o}),this.config.onSuccess&&this.config.onSuccess({id:o.transactionId,status:o.status,item:this.selectedItem.name}),this.dispatchEvent(new CustomEvent("icpay-coffee",{detail:{item:this.selectedItem,tx:o},bubbles:!0}))}catch(e){U(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),B(t)&&(this.errorMessage=R(t),this.errorSeverity=z(t),this.errorAction=D(t))}});try{!this.config.useOwnWallet&&this.pnp&&(await this.pnp.disconnect?.(),this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0})}catch{}}finally{this.processing=!1}}}attachTransakMessageListener(){if(!this.transakMessageHandlerBound){this.transakMessageHandlerBound=e=>this.onTransakMessage(e);try{window.addEventListener("message",this.transakMessageHandlerBound)}catch{}}}detachTransakMessageListener(){if(this.transakMessageHandlerBound){try{window.removeEventListener("message",this.transakMessageHandlerBound)}catch{}this.transakMessageHandlerBound=null}}onTransakMessage(e){let t=e?.data,i=t?.event_id||t?.eventId||t?.id;if(!(!i||typeof i!="string")&&i==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let s=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(s||void 0)}}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1,setTimeout(()=>this.createOnrampIntent(),0)}async createOnrampIntent(){try{let e=g(this.config),t=this.selectedSymbol||this.config?.defaultSymbol||"ICP",s=this.cryptoOptions.find(c=>c.symbol===t).canisterId||await e.client.getLedgerCanisterIdBySymbol(t),o=await e.startOnrampUsd(this.selectedItem.priceUsd,s,{context:"coffee:onramp",item:this.selectedItem.name}),a=o?.metadata?.onramp?.sessionId||o?.metadata?.onramp?.session_id||null,l=o?.metadata?.paymentIntentId||o?.paymentIntentId||null,p=o?.metadata?.onramp?.errorMessage||null;this.onrampPaymentIntentId=l,a?(this.onrampSessionId=a,this.onrampErrorMessage=null,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.onrampErrorMessage=p||"Failed to obtain onramp sessionId",this.showOnrampModal=!0)}catch(e){this.onrampSessionId=null,this.onrampErrorMessage=e?.message||"Failed to obtain onramp sessionId",this.showOnrampModal=!0}}startOnrampPolling(e){if(this.onrampPollTimer){try{clearInterval(this.onrampPollTimer)}catch{}this.onrampPollTimer=null}if(this.onrampNotifyController){try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null}let t=this.onrampPaymentIntentId;if(!t)return;let i=g(this.config),s=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>s()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=i.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");this.lastWalletId=(e||"").toLowerCase(),this.pnp.connect(e).then(i=>{if(!!!(i&&(i.connected===!0||i.principal||i.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}let o=k(this.pnp,i);if(this.config={...this.config,connectedWallet:o,actorProvider:(l,p)=>this.pnp.getActor({canisterId:l,idl:p,requiresSigning:!0,anon:!1})},this.lastWalletId==="oisy")this.oisyReadyToPay=!0;else{this.showWalletModal=!1;let l=this.pendingAction;this.pendingAction=null,l==="order"&&setTimeout(()=>this.order(),0)}}).catch(i=>{this.errorMessage=i instanceof Error?i.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1})}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}render(){return this.config?me`
1232
- <div class="icpay-card icpay-section icpay-widget-base">
1233
- ${this.config?.progressBar?.enabled!==!1?me`
1234
- <icpay-progress-bar
1235
- .debug=${!!this.config?.debug}
1236
- .theme=${this.config?.theme}
1237
- .amount=${Number(this.selectedItem?.priceUsd||0)}
1238
- .ledgerSymbol=${this.selectedSymbol||this.config?.defaultSymbol||"ICP"}
1239
- ></icpay-progress-bar>
1240
- `:null}
1241
- <div class="menu">
1242
- ${this.config.items.map((e,t)=>me`
1243
- <div class="item ${this.selectedIndex===t?"selected":""}" @click=${()=>this.selectItem(t)}>
1244
- <span>${e.name}</span>
1245
- <span>$${Number(e?.priceUsd??0).toFixed(2)}</span>
1246
- </div>
1247
- `)}
1248
- </div>
1249
-
1250
- <div class="total">Order Total: $${Number(this.selectedItem?.priceUsd??0).toFixed(2)}</div>
1251
-
1252
- <div>
1253
- <icpay-token-selector
1254
- .options=${this.cryptoOptions}
1255
- .value=${this.selectedSymbol||""}
1256
- .defaultSymbol=${this.config?.defaultSymbol||"ICP"}
1257
- mode=${this.config?.showLedgerDropdown||"buttons"}
1258
- @icpay-token-change=${e=>this.selectSymbol(e.detail.symbol)}
1259
- ></icpay-token-selector>
1260
- </div>
1261
-
1262
- <button class="pay-button ${this.processing?"processing":""}" ?disabled=${this.processing} @click=${()=>this.order()}>
1263
- ${this.processing?"Processing\u2026":`Order ${this.selectedItem.name}`}
1264
- </button>
1265
-
1266
- ${this.errorMessage?me`
1267
- <div class="error-message ${this.errorSeverity}" style="margin-top: 12px; padding: 8px 12px; border-radius: 6px; font-size: 14px; text-align: center;">
1268
- ${this.errorMessage}
1269
- ${this.errorAction?me`
1270
- <button style="margin-left: 8px; padding: 4px 8px; background: transparent; border: 1px solid currentColor; border-radius: 4px; font-size: 12px; cursor: pointer;">
1271
- ${this.errorAction}
1272
- </button>
1273
- `:""}
1274
- </div>
1275
- `:""}
1276
- ${(()=>{let t=(this.pnp?.getEnabledWallets?.()||[]).map(i=>({id:this.getWalletId(i),label:this.getWalletLabel(i),icon:this.getWalletIcon(i)}));return H({visible:!!(this.showWalletModal&&this.pnp),wallets:t,isConnecting:!1,onSelect:i=>this.connectWithWallet(i),onClose:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1},onCreditCard:this.config?.onramp?.enabled!==!1&&this.config?.onrampDisabled!==!0?()=>this.startOnramp():void 0,creditCardLabel:this.config?.onramp?.creditCardLabel||"Pay with credit card",showCreditCard:this.config?.onramp?.enabled!==!1&&this.config?.onrampDisabled!==!0,creditCardTooltip:(()=>{let s=this.config?.defaultItemIndex??0,o=Number(this.config?.items?.[s]?.priceUsd||0);return o>0&&o<5&&this.config?.onramp?.enabled!==!1&&this.config?.onrampDisabled!==!0?`Note: Minimum card amount is $5. You will pay about $${(5-o).toFixed(2)} more.`:null})(),oisyReadyToPay:this.oisyReadyToPay,onOisyPay:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1,this.order()}})})()}
1277
-
1278
- ${this.showOnrampModal?F({visible:this.showOnrampModal,sessionId:this.onrampSessionId,errorMessage:this.onrampErrorMessage,apiKey:this.config?.onramp?.apiKey,environment:this.config?.onramp?.environment||"STAGING",width:this.config?.onramp?.width,height:this.config?.onramp?.height,onClose:()=>{this.showOnrampModal=!1},onBack:()=>{this.showOnrampModal=!1,this.showWalletModal=!0}}):null}
1279
- </div>
1280
- `:me`<div class="icpay-card icpay-section">Loading...</div>`}};E.styles=[K,ht`
1281
- .menu { display: grid; gap: 8px; margin-bottom: 12px; }
1282
- .item { background: var(--icpay-surface-alt); border: 2px solid var(--icpay-border); border-radius: 12px; padding: 16px; display:flex; justify-content: space-between; align-items:center; cursor: pointer; color: var(--icpay-text); font-weight: 600; }
1283
- .item.selected { background: var(--icpay-primary); color: #111827; border-color: var(--icpay-primary); }
1284
- .total { background: var(--icpay-surface-alt); border: 1px solid var(--icpay-border); border-radius: 12px; padding: 12px; text-align: center; margin-bottom: 12px; color: var(--icpay-text); }
1285
- .crypto-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0 16px; }
1286
- .crypto-option { background: var(--icpay-surface-alt); border: 2px solid var(--icpay-border); border-radius: 12px; padding: 12px 8px; text-align: center; cursor: pointer; color: var(--icpay-text); font-weight: 600; font-size: 12px; }
1287
- .crypto-option.selected { background: var(--icpay-primary); color: #111827; border-color: var(--icpay-primary); }
1288
-
1289
- .error-message {
1290
- border: 1px solid;
1291
- font-weight: 500;
1292
- }
1293
-
1294
- .error-message.info {
1295
- background: rgba(59, 130, 246, 0.1);
1296
- border-color: rgba(59, 130, 246, 0.3);
1297
- color: #3b82f6;
1298
- }
1299
-
1300
- .error-message.warning {
1301
- background: rgba(245, 158, 11, 0.1);
1302
- border-color: rgba(245, 158, 11, 0.3);
1303
- color: #f59e0b;
1304
- }
1305
-
1306
- .error-message.error {
1307
- background: rgba(239, 68, 68, 0.1);
1308
- border-color: rgba(239, 68, 68, 0.3);
1309
- color: #ef4444;
1310
- }
1311
- `],n([ut({type:Object})],E.prototype,"config",2),n([N()],E.prototype,"selectedIndex",2),n([N()],E.prototype,"selectedSymbol",2),n([N()],E.prototype,"processing",2),n([N()],E.prototype,"availableLedgers",2),n([N()],E.prototype,"errorMessage",2),n([N()],E.prototype,"errorSeverity",2),n([N()],E.prototype,"errorAction",2),n([N()],E.prototype,"walletConnected",2),n([N()],E.prototype,"pendingAction",2),n([N()],E.prototype,"showWalletModal",2),n([N()],E.prototype,"oisyReadyToPay",2),n([N()],E.prototype,"lastWalletId",2),n([N()],E.prototype,"showOnrampModal",2),n([N()],E.prototype,"onrampSessionId",2),n([N()],E.prototype,"onrampPaymentIntentId",2),n([N()],E.prototype,"onrampErrorMessage",2),E=n([gt("icpay-coffee-shop")],E);import{LitElement as yt,html as fe,css as mt}from"lit";import{customElement as ft,property as bt,state as C}from"lit/decorators.js";var Te=typeof window<"u",be=null;function ne(r,d,e){r&&(e!==void 0?console.log(`[ICPay Widget] ${d}`,e):console.log(`[ICPay Widget] ${d}`))}var b=class extends yt{constructor(){super(...arguments);this.selectedAmount=10;this.selectedSymbol=null;this.raised=0;this.processing=!1;this.succeeded=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.showOnrampModal=!1;this.onrampSessionId=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.transakMessageHandlerBound=null;this.onrampPollTimer=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="donate",this.showWalletModal=!0,this.requestUpdate();try{let t=Number(this.selectedAmount||0),i=this.selectedSymbol||this.config?.defaultSymbol;window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"donate",type:"sendUsd",amount:t,currency:i}}))}catch{}}catch{}}}async tryAutoConnectPNP(){try{if(!this.config||this.config?.useOwnWallet)return;let e=localStorage.getItem("icpay:pnp");if(!e)return;let t=JSON.parse(e);if(!t?.provider||!t?.principal)return;be||(be=(await import("./wallet-select-X3Y5ORRN.js")).WalletSelect);let i=W({...this.config?.plugNPlay||{}});try{if(typeof window<"u"){let{resolveDerivationOrigin:o}=await import("./origin-44ZEXSX4.js");i.derivationOrigin=this.config?.derivationOrigin||o()}}catch{}let s=new be(i);this.walletConnected=!1,this.config={...this.config,connectedWallet:{owner:t.principal,principal:t.principal,connected:!1}}}catch{}}get amounts(){return this.config?.amountsUsd||[10,25,50,100,250,500]}get cryptoOptions(){return this.config.cryptoOptions?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){if(super.connectedCallback(),!!Te){ne(this.config?.debug||!1,"Donation thermometer connected",{config:this.config}),this.config&&typeof this.config.defaultAmountUsd=="number"&&(this.selectedAmount=this.config.defaultAmountUsd),this.tryAutoConnectPNP();try{window.addEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers()}}updated(e){if(e.has("config")&&this.pendingAction&&this.config?.actorProvider){let t=this.pendingAction;this.pendingAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}setTimeout(()=>{t==="donate"&&this.donate()},0)}}async loadVerifiedLedgers(){if(!(!Te||!this.config?.publishableKey))try{let t=await g(this.config).client.getVerifiedLedgers();this.availableLedgers=t.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||this.availableLedgers[0]?.symbol||"ICP")}catch(e){console.warn("Failed to load verified ledgers:",e),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||"ICP")}}selectAmount(e){this.selectedAmount=e}selectSymbol(e){this.selectedSymbol=e}get fillPercentage(){let e=Number(this.config?.goalUsd??1e3),t=e>0?e:1e3;return Math.min(this.raised/t*100,100)}async donate(){if(Te&&!this.processing){ne(this.config?.debug||!1,"Donation started",{amount:this.selectedAmount,selectedSymbol:this.selectedSymbol,useOwnWallet:this.config.useOwnWallet}),this.errorMessage=null,this.errorSeverity=null,this.errorAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"donate",type:"sendUsd",amount:this.selectedAmount,currency:this.selectedSymbol||this.config?.defaultSymbol}}))}catch{}this.processing=!0;try{if(this.config.useOwnWallet){if(!this.config.actorProvider){this.pendingAction="donate",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0}));return}}else if(!this.walletConnected){ne(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{be||(be=(await import("./wallet-select-X3Y5ORRN.js")).WalletSelect);let l=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab)?W({...this.config?.plugNPlay||{}}):{...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:c}=await import("./origin-44ZEXSX4.js");l.derivationOrigin=this.config?.derivationOrigin||c()}}catch{}this.pnp=new be(l);try{let c=await Q(this.pnp);if(c){this.walletConnected=!0;let h=k(this.pnp,{owner:c,principal:c,connected:!0});this.config={...this.config,connectedWallet:h,actorProvider:($,A)=>this.pnp.getActor({canisterId:$,idl:A,requiresSigning:!0,anon:!1})};try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"oisy"}}))}catch{}this.donate();return}}catch{}let p=this.pnp.getEnabledWallets();if(ne(this.config?.debug||!1,"Available wallets",p),!p?.length)throw new Error("No wallets available");this.pendingAction="donate",this.showWalletModal=!0;return}catch(a){ne(this.config?.debug||!1,"Wallet connection error:",a),this.errorMessage=a instanceof Error?a.message:"Wallet connection failed",this.errorSeverity="error";return}}ne(this.config?.debug||!1,"Creating SDK for payment");let e=g(this.config),t=this.selectedSymbol||this.config?.defaultSymbol||"ICP",s=this.cryptoOptions.find(a=>a.symbol===t).canisterId||await e.client.getLedgerCanisterIdBySymbol(t);ne(this.config?.debug||!1,"Donation payment details",{amount:this.selectedAmount,selectedSymbol:t,canisterId:s});let o=await e.sendUsd(this.selectedAmount,s,{context:"donation"});ne(this.config?.debug||!1,"Donation payment completed",{resp:o}),this.raised+=this.selectedAmount,this.succeeded=!0,this.config.onSuccess&&this.config.onSuccess({id:o.transactionId,status:o.status,raised:this.raised}),this.dispatchEvent(new CustomEvent("icpay-donation",{detail:{amount:this.selectedAmount,tx:o},bubbles:!0}))}catch(e){U(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),B(t)&&(this.errorMessage=R(t),this.errorSeverity=z(t),this.errorAction=D(t))}});try{!this.config.useOwnWallet&&this.pnp&&(await this.pnp.disconnect?.(),this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0})}catch{}}finally{this.processing=!1}}}attachTransakMessageListener(){if(!this.transakMessageHandlerBound){this.transakMessageHandlerBound=e=>this.onTransakMessage(e);try{window.addEventListener("message",this.transakMessageHandlerBound)}catch{}}}detachTransakMessageListener(){if(this.transakMessageHandlerBound){try{window.removeEventListener("message",this.transakMessageHandlerBound)}catch{}this.transakMessageHandlerBound=null}}onTransakMessage(e){let t=e?.data,i=t?.event_id||t?.eventId||t?.id;if(!(!i||typeof i!="string")&&i==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let s=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(s||void 0)}}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1,setTimeout(()=>this.createOnrampIntent(),0)}async createOnrampIntent(){try{let e=g(this.config),t=this.selectedSymbol||this.config?.defaultSymbol||"ICP",s=this.cryptoOptions.find(c=>c.symbol===t).canisterId||await e.client.getLedgerCanisterIdBySymbol(t),o=await e.startOnrampUsd(this.selectedAmount,s,{context:"donation:onramp"}),a=o?.metadata?.onramp?.sessionId||o?.metadata?.onramp?.session_id||null,l=o?.metadata?.paymentIntentId||o?.paymentIntentId||null,p=o?.metadata?.onramp?.errorMessage||null;this.onrampPaymentIntentId=l,a?(this.onrampSessionId=a,this.onrampErrorMessage=null,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.onrampErrorMessage=p||"Failed to obtain onramp sessionId",this.showOnrampModal=!0)}catch(e){this.onrampSessionId=null,this.onrampErrorMessage=e?.message||"Failed to obtain onramp sessionId",this.showOnrampModal=!0}}startOnrampPolling(e){if(this.onrampPollTimer){try{clearInterval(this.onrampPollTimer)}catch{}this.onrampPollTimer=null}if(this.onrampNotifyController){try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null}let t=this.onrampPaymentIntentId;if(!t)return;let i=g(this.config),s=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>s()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=i.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");this.lastWalletId=(e||"").toLowerCase(),this.pnp.connect(e).then(i=>{if(!!!(i&&(i.connected===!0||i.principal||i.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}let o=k(this.pnp,i);if(this.config={...this.config,connectedWallet:o,actorProvider:(l,p)=>this.pnp.getActor({canisterId:l,idl:p,requiresSigning:!0,anon:!1})},this.lastWalletId==="oisy")this.oisyReadyToPay=!0;else{this.showWalletModal=!1;let l=this.pendingAction;this.pendingAction=null,l==="donate"&&setTimeout(()=>this.donate(),0)}}).catch(i=>{this.errorMessage=i instanceof Error?i.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1})}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}render(){return this.config?fe`
1312
- <div class="icpay-card icpay-section icpay-widget-base" style="text-align:center;">
1313
- ${this.config?.progressBar?.enabled!==!1?fe`
1314
- <icpay-progress-bar
1315
- .debug=${!!this.config?.debug}
1316
- .theme=${this.config?.theme}
1317
- .amount=${Number(this.selectedAmount||0)}
1318
- .ledgerSymbol=${this.selectedSymbol||this.config?.defaultSymbol||"ICP"}
1319
- ></icpay-progress-bar>
1320
- `:null}
1321
- <div class="thermo"><div class="fill" style="height:${this.fillPercentage}%"></div></div>
1322
- <div class="total">$${Number(this.raised).toFixed(0)} / $${Number(this.config?.goalUsd??0).toFixed(2)}</div>
1323
-
1324
- <div class="amounts">
1325
- ${this.amounts.map(e=>fe`<div class="chip ${this.selectedAmount===e?"selected":""}" @click=${()=>this.selectAmount(e)}>$${e}</div>`)}
1326
- </div>
1327
-
1328
- <div>
1329
- <icpay-token-selector
1330
- .options=${this.cryptoOptions}
1331
- .value=${this.selectedSymbol||""}
1332
- .defaultSymbol=${this.config?.defaultSymbol||"ICP"}
1333
- mode=${this.config?.showLedgerDropdown||"buttons"}
1334
- @icpay-token-change=${e=>this.selectSymbol(e.detail.symbol)}
1335
- ></icpay-token-selector>
1336
- </div>
1337
-
1338
- <button class="pay-button ${this.processing?"processing":""}"
1339
- ?disabled=${this.processing||this.config?.disablePaymentButton===!0||this.succeeded&&this.config?.disableAfterSuccess===!0}
1340
- @click=${()=>this.donate()}>
1341
- ${this.succeeded&&this.config?.disableAfterSuccess?"Donated":this.processing?"Processing\u2026":(this.config?.buttonLabel||"Donate {amount} with {symbol}").replace("{amount}",`${this.selectedAmount}`).replace("{symbol}",this.selectedSymbol||this.config?.defaultSymbol||"ICP")}
1342
- </button>
1343
-
1344
- ${this.errorMessage?fe`
1345
- <div class="error-message ${this.errorSeverity}" style="margin-top: 12px; padding: 8px 12px; border-radius: 6px; font-size: 14px; text-align: center;">
1346
- ${this.errorMessage}
1347
- ${this.errorAction?fe`
1348
- <button style="margin-left: 8px; padding: 4px 8px; background: transparent; border: 1px solid currentColor; border-radius: 4px; font-size: 12px; cursor: pointer;">
1349
- ${this.errorAction}
1350
- </button>
1351
- `:""}
1352
- </div>
1353
- `:""}
1354
- ${(()=>{let t=(this.pnp?.getEnabledWallets?.()||[]).map(i=>({id:this.getWalletId(i),label:this.getWalletLabel(i),icon:this.getWalletIcon(i)}));return H({visible:!!(this.showWalletModal&&this.pnp),wallets:t,isConnecting:!1,onSelect:i=>this.connectWithWallet(i),onClose:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1},onCreditCard:this.config?.onramp?.enabled!==!1?()=>this.startOnramp():void 0,creditCardLabel:this.config?.onramp?.creditCardLabel||"Pay with credit card",showCreditCard:this.config?.onramp?.enabled!==!1,creditCardTooltip:(()=>{let s=Number(this.selectedAmount||this.config?.defaultAmountUsd||0);return s>0&&s<5&&this.config?.onramp?.enabled!==!1?`Note: Minimum card amount is $5. You will pay about $${(5-s).toFixed(2)} more.`:null})(),oisyReadyToPay:this.oisyReadyToPay,onOisyPay:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1,this.donate()}})})()}
1355
-
1356
- ${this.showOnrampModal?F({visible:this.showOnrampModal,sessionId:this.onrampSessionId,errorMessage:this.onrampErrorMessage,apiKey:this.config?.onramp?.apiKey,environment:this.config?.onramp?.environment||"STAGING",width:this.config?.onramp?.width,height:this.config?.onramp?.height,onClose:()=>{this.showOnrampModal=!1},onBack:()=>{this.showOnrampModal=!1,this.showWalletModal=!0}}):null}
1357
- </div>
1358
- `:fe`<div class="icpay-card icpay-section">Loading...</div>`}};b.styles=[K,mt`
1359
- .thermo { width: 60px; height: 200px; background: var(--icpay-surface-alt); border: 3px solid #6b7280; border-radius: 30px; margin: 0 auto 12px; position: relative; overflow: hidden; }
1360
- .fill { position: absolute; bottom: 0; left: 0; right: 0; background: linear-gradient(135deg, #d1d5db 0%, #9ca3af 100%); transition: height 0.8s ease; height: 0%; border-radius: 0 0 27px 27px; }
1361
- .amounts { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; margin: 12px 0; }
1362
- .chip { background: var(--icpay-surface-alt); border: 2px solid var(--icpay-border); border-radius: 12px; padding: 12px; text-align: center; cursor: pointer; color: var(--icpay-text); font-weight: 600; }
1363
- .chip.selected { background: var(--icpay-primary); color: #111827; border-color: var(--icpay-primary); }
1364
- .crypto-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0 16px; }
1365
- .crypto-option { background: var(--icpay-surface-alt); border: 2px solid var(--icpay-border); border-radius: 12px; padding: 12px 8px; text-align: center; cursor: pointer; color: var(--icpay-text); font-weight: 600; font-size: 12px; }
1366
- .crypto-option.selected { background: var(--icpay-primary); color: #111827; border-color: var(--icpay-primary); }
1367
-
1368
- .error-message {
1369
- border: 1px solid;
1370
- font-weight: 500;
1371
- }
1372
-
1373
- .error-message.info {
1374
- background: rgba(59, 130, 246, 0.1);
1375
- border-color: rgba(59, 130, 246, 0.3);
1376
- color: #3b82f6;
1377
- }
1378
-
1379
- .error-message.warning {
1380
- background: rgba(245, 158, 11, 0.1);
1381
- border-color: rgba(245, 158, 11, 0.3);
1382
- color: #f59e0b;
1383
- }
1384
-
1385
- .error-message.error {
1386
- background: rgba(239, 68, 68, 0.1);
1387
- border-color: rgba(239, 68, 68, 0.3);
1388
- color: #ef4444;
1389
- }
1390
- `],n([bt({type:Object})],b.prototype,"config",2),n([C()],b.prototype,"selectedAmount",2),n([C()],b.prototype,"selectedSymbol",2),n([C()],b.prototype,"raised",2),n([C()],b.prototype,"processing",2),n([C()],b.prototype,"succeeded",2),n([C()],b.prototype,"availableLedgers",2),n([C()],b.prototype,"errorMessage",2),n([C()],b.prototype,"errorSeverity",2),n([C()],b.prototype,"errorAction",2),n([C()],b.prototype,"walletConnected",2),n([C()],b.prototype,"pendingAction",2),n([C()],b.prototype,"showWalletModal",2),n([C()],b.prototype,"oisyReadyToPay",2),n([C()],b.prototype,"lastWalletId",2),n([C()],b.prototype,"showOnrampModal",2),n([C()],b.prototype,"onrampSessionId",2),n([C()],b.prototype,"onrampPaymentIntentId",2),n([C()],b.prototype,"onrampErrorMessage",2),b=n([ft("icpay-donation-thermometer")],b);import{LitElement as vt,html as ve,css as wt}from"lit";import{customElement as xt,property as St,state as O}from"lit/decorators.js";var $e=typeof window<"u",we=null;function q(r,d,e){r&&(e!==void 0?console.log(`[ICPay Widget] ${d}`,e):console.log(`[ICPay Widget] ${d}`))}var v=class extends vt{constructor(){super(...arguments);this.selectedSymbol=null;this.processing=!1;this.succeeded=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.showOnrampModal=!1;this.onrampSessionId=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.oisyReadyToPay=!1;this.oisySignerPreopened=!1;this.skipDisconnectOnce=!1;this.lastWalletId=null;this.onrampPollTimer=null;this.transakMessageHandlerBound=null;this.pnp=null;this.oisyConnectRetriedNewTab=!1;this.sdk=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="pay",this.showWalletModal=!0,this.requestUpdate();try{let t=Number(this.config?.amountUsd||0),i=this.selectedSymbol||this.config?.defaultSymbol;window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"pay",type:"sendUsd",amount:t,currency:i}}))}catch{}}catch{}}}getSdk(){return this.sdk||(this.sdk=g(this.config)),this.sdk}get cryptoOptions(){return this.config?.cryptoOptions?.length?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){if(super.connectedCallback(),!!$e){q(this.config?.debug||!1,"Pay button connected",{config:this.config}),this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers(),this.config?.defaultSymbol&&(this.selectedSymbol=this.config.defaultSymbol);try{window.addEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}try{window.addEventListener("icpay-sdk-transaction-created",(e=>{q(this.config?.debug||!1,"SDK transaction created",{detail:e?.detail})}))}catch{}}}updated(e){if(e.has("config")&&this.pendingAction&&this.config?.actorProvider){let t=this.pendingAction;this.pendingAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}setTimeout(()=>{t==="pay"&&this.pay()},0)}e.has("config")&&(this.sdk=null,!this.selectedSymbol&&this.config?.defaultSymbol&&(this.selectedSymbol=this.config.defaultSymbol))}async loadVerifiedLedgers(){if(!(!$e||!this.config?.publishableKey))try{let t=await this.getSdk().client.getVerifiedLedgers();this.availableLedgers=t.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||(this.availableLedgers[0]?.symbol??"ICP"))}catch(e){this.dispatchEvent(new CustomEvent("icpay-error",{detail:{message:"Failed to load verified ledgers",cause:e},bubbles:!0})),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||"ICP")}}selectSymbol(e){this.selectedSymbol=e}async ensureWallet(){if(this.config.useOwnWallet)return this.config.actorProvider?!0:(this.pendingAction="pay",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0})),!1);if(this.walletConnected)return!0;try{we||(we=(await import("./wallet-select-X3Y5ORRN.js")).WalletSelect);let e=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab),t={...this.config?.plugNPlay||{}},i=e?W(t):t;try{if(typeof window<"u"){let{resolveDerivationOrigin:o}=await import("./origin-44ZEXSX4.js");i.derivationOrigin=this.config?.derivationOrigin||o()}}catch{}this.pnp=new we(i);let s=this.pnp.getEnabledWallets();if(q(this.config?.debug||!1,"Available wallets",s),!s?.length)throw new Error("No wallets available");return this.pendingAction="pay",this.showWalletModal=!0,!1}catch(e){return this.errorMessage=e instanceof Error?e.message:"Wallet connection failed",this.errorSeverity="error",!1}}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");this.lastWalletId=(e||"").toLowerCase(),this.lastWalletId==="oisy"&&(this.oisyConnectRetriedNewTab=!1),this.pnp.connect(e).then(i=>{if(q(this.config?.debug||!1,"Wallet connect result",i),!!!(i&&(i.connected===!0||i.principal||i.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}let o=k(this.pnp,i);if(this.config={...this.config,connectedWallet:o,actorProvider:(l,p)=>this.pnp.getActor({canisterId:l,idl:p,requiresSigning:!0,anon:!1})},(e||"").toLowerCase()==="oisy")this.oisyReadyToPay=!0,this.pendingAction=null;else{this.showWalletModal=!1;let l=this.pendingAction;this.pendingAction=null,l==="pay"&&(this.skipDisconnectOnce=!0,this.pay())}}).catch(i=>{q(this.config?.debug||!1,"Wallet connection error",i);let s=(e||"").toLowerCase()==="oisy",o=i&&(i.message||String(i))||"";if(s&&!this.oisyConnectRetriedNewTab&&(o.includes("Signer window could not be opened")||o.includes("Communication channel could not be established"))){this.oisyConnectRetriedNewTab=!0,(async()=>{try{we||(we=(await import("./wallet-select-X3Y5ORRN.js")).WalletSelect);let l={...this.config?.plugNPlay||{}},p=W(l);try{if(typeof window<"u"){let{resolveDerivationOrigin:h}=await import("./origin-44ZEXSX4.js");p.derivationOrigin=this.config?.derivationOrigin||h()}}catch{}this.pnp=new we(p),this.pnp.connect("oisy").then(h=>{if(!!!(h&&(h.connected===!0||h.principal||h.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"oisy"}}))}catch{}let A=k(this.pnp,h);this.config={...this.config,connectedWallet:A,actorProvider:(se,P)=>this.pnp.getActor({canisterId:se,idl:P,requiresSigning:!0,anon:!1})},this.oisyReadyToPay=!0,this.pendingAction=null}).catch(h=>{q(this.config?.debug||!1,"Oisy retry connect (new tab) failed",h),this.errorMessage=h instanceof Error?h.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1})}catch(l){q(this.config?.debug||!1,"Oisy new-tab init failed",l),this.errorMessage=l instanceof Error?l.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}})();return}this.errorMessage=i instanceof Error?i.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1})}catch(t){q(this.config?.debug||!1,"Wallet connection error (sync)",t),this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}renderWalletModal(){if(!this.showWalletModal||!this.pnp)return null;let t=(this.pnp.getEnabledWallets()||[]).map(c=>({id:this.getWalletId(c),label:this.getWalletLabel(c),icon:this.getWalletIcon(c)})),i=this.config?.onramp?.enabled!==!1&&this.config?.onrampDisabled!==!0,s=5,o=Number(this.config?.amountUsd??0),a=i&&o>0&&o<s,l=Math.max(0,s-o),p=a?`Note: Minimum card amount is $${s}. You will pay about $${l.toFixed(2)} more.`:null;return H({visible:this.showWalletModal,wallets:t,isConnecting:!1,onSelect:c=>{this.connectWithWallet(c)},onClose:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1},onCreditCard:i?()=>this.startOnramp():void 0,creditCardLabel:this.config?.onramp?.creditCardLabel||"Pay with credit card",showCreditCard:i,creditCardTooltip:p,oisyReadyToPay:this.oisyReadyToPay,onOisyPay:()=>{this.showWalletModal=!1,this.skipDisconnectOnce=!0,this.oisyReadyToPay=!1,this.pay()}})}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1,setTimeout(()=>this.createOnrampIntent(),0)}async createOnrampIntent(){try{let e=Number(this.config?.amountUsd??0),t=this.getSdk();this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||"ICP");let i=this.selectedSymbol||"ICP",o=this.cryptoOptions.find(h=>h.symbol===i)?.canisterId||await t.client.getLedgerCanisterIdBySymbol(i),a=await t.startOnrampUsd(e,o,{context:"pay-button:onramp"}),l=a?.metadata?.onramp?.sessionId||a?.metadata?.onramp?.session_id||null,p=a?.metadata?.onramp?.errorMessage||null;this.onrampErrorMessage=p||null;let c=a?.metadata?.paymentIntentId||a?.paymentIntentId||null;this.onrampPaymentIntentId=c,l?(this.onrampSessionId=l,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.showOnrampModal=!0)}catch(e){this.onrampSessionId=null,this.onrampErrorMessage=e?.message||null,this.showOnrampModal=!0,U(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),B(t)&&(this.errorMessage=R(t),this.errorSeverity=z(t),this.errorAction=D(t))}})}}attachTransakMessageListener(){if(!this.transakMessageHandlerBound){this.transakMessageHandlerBound=e=>this.onTransakMessage(e);try{window.addEventListener("message",this.transakMessageHandlerBound)}catch{}}}detachTransakMessageListener(){if(this.transakMessageHandlerBound){try{window.removeEventListener("message",this.transakMessageHandlerBound)}catch{}this.transakMessageHandlerBound=null}}onTransakMessage(e){let t=e?.data,i=t?.event_id||t?.eventId||t?.id;if(!(!i||typeof i!="string")&&i==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;let s=t?.data?.id||t?.id||t?.webhookData?.id||null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-success",{detail:{name:"getLedgerBalance"}}))}catch{}try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-success",{detail:{name:"sendFundsToLedger"}}))}catch{}try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-success",{detail:{name:"notifyLedgerTransaction"}}))}catch{}this.showOnrampModal=!1,this.startOnrampPolling(s||void 0)}}startOnrampPolling(e){if(this.onrampPollTimer){try{clearInterval(this.onrampPollTimer)}catch{}this.onrampPollTimer=null}if(this.onrampNotifyController){try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null}let t=this.onrampPaymentIntentId;if(!t)return;let i=this.getSdk(),s=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1},o=a=>{s()};try{window.addEventListener("icpay-sdk-transaction-completed",o,{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=i.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}async pay(){if(!(!$e||this.processing)){this.errorMessage=null,this.errorSeverity=null,this.errorAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"pay",type:"sendUsd",amount:this.config?.amountUsd,currency:this.selectedSymbol||this.config?.defaultSymbol}}))}catch{}this.processing=!0;try{if(this.skipDisconnectOnce)this.skipDisconnectOnce=!1;else try{!this.config.useOwnWallet&&this.pnp&&(await this.pnp.disconnect?.(),this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0})}catch{}if(!await this.ensureWallet())return;let t=this.getSdk();try{let c=this.config?.connectedWallet,h=this?.pnp?.account;q(this.config?.debug||!1,"Wallet state before payment",{connectedWallet:c,pnpAccount:h,principal:c?.owner||c?.principal||h?.owner||h?.principal||null})}catch{}this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||"ICP");let i=this.selectedSymbol||"ICP",o=this.cryptoOptions.find(c=>c.symbol===i)?.canisterId||await t.client.getLedgerCanisterIdBySymbol(i);q(this.config?.debug||!1,"Resolved ledger details",{symbol:i,canisterId:o});let a=Number(this.config?.amountUsd??0),l={context:"pay-button"};q(this.config?.debug||!1,"Calling sdk.sendUsd",{amountUsd:a,canisterId:o,meta:l});let p=await t.sendUsd(a,o,l);q(this.config?.debug||!1,"sdk.sendUsd response",p),this.config.onSuccess&&this.config.onSuccess({id:p.transactionId,status:p.status}),this.succeeded=!0,this.dispatchEvent(new CustomEvent("icpay-pay",{detail:{amount:a,tx:p},bubbles:!0}))}catch(e){q(this.config?.debug||!1,"Payment error",{message:e?.message,code:e?.code,details:e?.details,stack:e?.stack}),U(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),B(t)&&(this.errorMessage=R(t),this.errorSeverity=z(t),this.errorAction=D(t))}});try{!this.config.useOwnWallet&&this.pnp&&(await this.pnp.disconnect?.(),this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0})}catch{}}finally{this.processing=!1}}}render(){if(!this.config)return ve`<div class="icpay-card icpay-section">Loading...</div>`;let t=(this.cryptoOptions?.length||0)>1,i=this.config?.showLedgerDropdown,s=i==="dropdown"?"dropdown":i==="none"?"none":"buttons",o=s!=="none"&&(t||s==="dropdown"),a=s==="dropdown"?"dropdown":t?"buttons":"none",l=this.selectedSymbol||this.config?.defaultSymbol||"ICP",p=typeof this.config?.amountUsd=="number"?`${Number(this.config.amountUsd).toFixed(2)}`:"",h=(this.config?.buttonLabel||(typeof this.config?.amountUsd=="number"?"Pay ${amount} with {symbol}":"Pay with {symbol}")).replace("{amount}",p||"$0.00").replace("{symbol}",l),A=this.config?.progressBar?.enabled!==!1;return ve`
1391
- <div class="icpay-card icpay-section icpay-widget-base">
1392
- ${A?ve`
1393
- <icpay-progress-bar
1394
- .debug=${!!this.config?.debug}
1395
- .theme=${this.config?.theme}
1396
- .amount=${Number(this.config?.amountUsd||0)}
1397
- .ledgerSymbol=${l}
1398
- ></icpay-progress-bar>
1399
- `:null}
1400
-
1401
- <div class="row ${o?"":"single"}">
1402
- ${o?ve`
1403
- <icpay-token-selector
1404
- .options=${this.cryptoOptions}
1405
- .value=${this.selectedSymbol||""}
1406
- .defaultSymbol=${this.config?.defaultSymbol||"ICP"}
1407
- mode=${a}
1408
- @icpay-token-change=${se=>this.selectSymbol(se.detail.symbol)}
1409
- ></icpay-token-selector>
1410
- `:null}
1411
- <button class="pay-button ${this.processing?"processing":""}"
1412
- ?disabled=${this.processing||this.config?.disablePaymentButton===!0||this.succeeded&&this.config?.disableAfterSuccess===!0}
1413
- @click=${()=>this.pay()}>
1414
- ${this.succeeded&&this.config?.disableAfterSuccess?"Paid":this.processing?"Processing\u2026":h}
1415
- </button>
1416
- </div>
1417
-
1418
- ${this.errorMessage?ve`
1419
- <div class="error-message ${this.errorSeverity}" style="margin-top: 12px; padding: 8px 12px; border-radius: 6px; font-size: 14px; text-align: center;">
1420
- ${this.errorMessage}
1421
- ${this.errorAction?ve`<button style="margin-left: 8px; padding: 4px 8px; background: transparent; border: 1px solid currentColor; border-radius: 4px; font-size: 12px; cursor: pointer;">${this.errorAction}</button>`:""}
1422
- </div>
1423
- `:""}
1424
- ${this.renderWalletModal()}
1425
- ${this.showOnrampModal?F({visible:this.showOnrampModal,sessionId:this.onrampSessionId,errorMessage:this.onrampErrorMessage,apiKey:this.config?.onramp?.apiKey,apiUrl:this.config?.apiUrl,paymentIntentId:this.onrampPaymentIntentId,environment:this.config?.onramp?.environment||"STAGING",width:this.config?.onramp?.width,height:this.config?.onramp?.height,onClose:()=>{this.showOnrampModal=!1},onBack:()=>{this.showOnrampModal=!1,this.showWalletModal=!0}}):null}
1426
- </div>
1427
- `}};v.styles=[K,wt`
1428
- .row { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; }
1429
- .row.single { grid-template-columns: 1fr; }
1430
- select { background: var(--icpay-surface-alt); border: 1px solid var(--icpay-border); color: var(--icpay-text); border-radius: 8px; padding: 10px; font-weight: 600; }
1431
- .error-message { border: 1px solid; font-weight: 500; }
1432
- .error-message.info { background: rgba(59,130,246,0.1); border-color: rgba(59,130,246,0.3); color: #3b82f6; }
1433
- .error-message.warning { background: rgba(245,158,11,0.1); border-color: rgba(245,158,11,0.3); color: #f59e0b; }
1434
- .error-message.error { background: rgba(239,68,68,0.1); border-color: rgba(239,68,68,0.3); color: #ef4444; }
1435
- `],n([St({type:Object})],v.prototype,"config",2),n([O()],v.prototype,"selectedSymbol",2),n([O()],v.prototype,"processing",2),n([O()],v.prototype,"succeeded",2),n([O()],v.prototype,"availableLedgers",2),n([O()],v.prototype,"errorMessage",2),n([O()],v.prototype,"errorSeverity",2),n([O()],v.prototype,"errorAction",2),n([O()],v.prototype,"walletConnected",2),n([O()],v.prototype,"pendingAction",2),n([O()],v.prototype,"showWalletModal",2),n([O()],v.prototype,"showOnrampModal",2),n([O()],v.prototype,"onrampSessionId",2),n([O()],v.prototype,"onrampPaymentIntentId",2),n([O()],v.prototype,"onrampErrorMessage",2),n([O()],v.prototype,"oisyReadyToPay",2),n([O()],v.prototype,"oisySignerPreopened",2),n([O()],v.prototype,"skipDisconnectOnce",2),n([O()],v.prototype,"lastWalletId",2),v=n([xt("icpay-pay-button")],v);import{LitElement as Et,html as xe,css as kt}from"lit";import{customElement as Mt,property as Ct,state as I}from"lit/decorators.js";var Ae=typeof window<"u",Ne=null;function Ot(r,d,e){r&&(e!==void 0?console.log(`[ICPay Widget] ${d}`,e):console.log(`[ICPay Widget] ${d}`))}var w=class extends Et{constructor(){super(...arguments);this.amountUsd=0;this.hasUserAmount=!1;this.selectedSymbol=null;this.processing=!1;this.succeeded=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.showOnrampModal=!1;this.onrampSessionId=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.transakMessageHandlerBound=null;this.onrampPollTimer=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="pay",this.showWalletModal=!0,this.requestUpdate();try{let t=Number(this.amountUsd||0),i=this.selectedSymbol||this.config?.defaultSymbol;window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"pay",type:"sendUsd",amount:t,currency:i}}))}catch{}}catch{}}}get cryptoOptions(){return this.config?.cryptoOptions?.length?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){if(super.connectedCallback(),!!Ae){Ot(this.config?.debug||!1,"Amount input connected",{config:this.config}),this.amountUsd=Number(this.config?.defaultAmountUsd??0),this.hasUserAmount=!1,this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers(),this.config?.defaultSymbol&&(this.selectedSymbol=this.config.defaultSymbol);try{window.addEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}}}updated(e){if(e.has("config")&&(!this.hasUserAmount&&typeof this.config?.defaultAmountUsd=="number"&&(this.amountUsd===0||this.amountUsd==null||Number.isNaN(this.amountUsd))&&(this.amountUsd=Number(this.config.defaultAmountUsd)),!this.selectedSymbol&&this.config?.defaultSymbol&&(this.selectedSymbol=this.config.defaultSymbol),!(this.config?.cryptoOptions&&this.config.cryptoOptions.length>0)&&this.availableLedgers.length===0&&this.loadVerifiedLedgers(),this.pendingAction&&this.config?.actorProvider)){let t=this.pendingAction;this.pendingAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}setTimeout(()=>{t==="pay"&&this.pay()},0)}}async loadVerifiedLedgers(){if(!(!Ae||!this.config?.publishableKey))try{let t=await g(this.config).client.getVerifiedLedgers();this.availableLedgers=t.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||(this.availableLedgers[0]?.symbol??"ICP"))}catch(e){this.dispatchEvent(new CustomEvent("icpay-error",{detail:{message:"Failed to load verified ledgers",cause:e},bubbles:!0})),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||"ICP")}}onInputChange(e){let t=Number(this.config?.stepUsd??.5),i=Math.max(0,Number(e.target.value||0)),s=Math.round(i/t)*t;this.amountUsd=Number(s.toFixed(2)),this.hasUserAmount=!0}selectSymbol(e){this.selectedSymbol=e}isValidAmount(){let e=Number(this.config?.minUsd??.5),t=this.config?.maxUsd!==void 0?Number(this.config.maxUsd):1/0;return this.amountUsd>=e&&this.amountUsd<=t}async ensureWallet(){if(this.config.useOwnWallet)return this.config.actorProvider?!0:(this.pendingAction="pay",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0})),!1);if(this.walletConnected)return!0;try{Ne||(Ne=(await import("./wallet-select-X3Y5ORRN.js")).WalletSelect);let e=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab),t={...this.config?.plugNPlay||{}},i=e?W(t):t;try{if(typeof window<"u"){let{resolveDerivationOrigin:o}=await import("./origin-44ZEXSX4.js");i.derivationOrigin=this.config?.derivationOrigin||o()}}catch{}if(this.pnp=new Ne(i),!this.pnp.getEnabledWallets()?.length)throw new Error("No wallets available");return this.pendingAction="pay",this.showWalletModal=!0,!1}catch(e){return this.errorMessage=e instanceof Error?e.message:"Wallet connection failed",this.errorSeverity="error",!1}}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");this.lastWalletId=(e||"").toLowerCase(),this.pnp.connect(e).then(i=>{if(!!!(i&&(i.connected===!0||i.principal||i.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}let o=k(this.pnp,i);if(this.config={...this.config,connectedWallet:o,actorProvider:(l,p)=>this.pnp.getActor({canisterId:l,idl:p,requiresSigning:!0,anon:!1})},this.lastWalletId==="oisy")this.oisyReadyToPay=!0;else{this.showWalletModal=!1;let l=this.pendingAction;this.pendingAction=null,l==="pay"&&setTimeout(()=>this.pay(),0)}}).catch(i=>{this.errorMessage=i instanceof Error?i.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1})}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}attachTransakMessageListener(){if(!this.transakMessageHandlerBound){this.transakMessageHandlerBound=e=>this.onTransakMessage(e);try{window.addEventListener("message",this.transakMessageHandlerBound)}catch{}}}detachTransakMessageListener(){if(this.transakMessageHandlerBound){try{window.removeEventListener("message",this.transakMessageHandlerBound)}catch{}this.transakMessageHandlerBound=null}}onTransakMessage(e){let t=e?.data,i=t?.event_id||t?.eventId||t?.id;if(!(!i||typeof i!="string")&&i==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let s=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(s||void 0)}}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1,setTimeout(()=>this.createOnrampIntent(),0)}async createOnrampIntent(){try{let e=g(this.config),t=this.selectedSymbol||this.config?.defaultSymbol||"ICP",s=this.cryptoOptions.find(h=>h.symbol===t)?.canisterId||await e.client.getLedgerCanisterIdBySymbol(t),o=Number(this.amountUsd),a=await e.startOnrampUsd(o,s,{context:"amount-input:onramp"}),l=a?.metadata?.onramp?.sessionId||a?.metadata?.onramp?.session_id||null,p=a?.metadata?.paymentIntentId||a?.paymentIntentId||null,c=a?.metadata?.onramp?.errorMessage||null;this.onrampPaymentIntentId=p,l?(this.onrampSessionId=l,this.onrampErrorMessage=null,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.onrampErrorMessage=c||"Failed to obtain onramp sessionId",this.showOnrampModal=!0)}catch(e){this.onrampSessionId=null,this.onrampErrorMessage=e?.message||"Failed to obtain onramp sessionId",this.showOnrampModal=!0}}startOnrampPolling(e){if(this.onrampPollTimer){try{clearInterval(this.onrampPollTimer)}catch{}this.onrampPollTimer=null}if(this.onrampNotifyController){try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null}let t=this.onrampPaymentIntentId;if(!t)return;let i=g(this.config),s=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>s()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=i.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}async pay(){if(!(!Ae||this.processing)){if(this.errorMessage=null,this.errorSeverity=null,this.errorAction=null,!this.isValidAmount()){this.errorMessage="Please enter a valid amount",this.errorSeverity="warning";return}try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"pay",type:"sendUsd",amount:this.amountUsd,currency:this.selectedSymbol||this.config?.defaultSymbol}}))}catch{}this.processing=!0;try{if(!await this.ensureWallet())return;let t=g(this.config),i=this.selectedSymbol||this.config?.defaultSymbol||"ICP",o=this.cryptoOptions.find(c=>c.symbol===i)?.canisterId||await t.client.getLedgerCanisterIdBySymbol(i),a=Number(this.amountUsd),l={context:"amount-input"},p=await t.sendUsd(a,o,l);this.config.onSuccess&&this.config.onSuccess({id:p.transactionId,status:p.status,amountUsd:a}),this.succeeded=!0,this.dispatchEvent(new CustomEvent("icpay-amount-pay",{detail:{amount:a,tx:p},bubbles:!0}))}catch(e){U(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),B(t)&&(this.errorMessage=R(t),this.errorSeverity=z(t),this.errorAction=D(t))}});try{!this.config.useOwnWallet&&this.pnp&&(await this.pnp.disconnect?.(),this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0})}catch{}}finally{this.processing=!1}}}render(){if(!this.config)return xe`<div class="icpay-card icpay-section">Loading...</div>`;let e=this.config?.placeholder||"Enter amount in USD",i=(this.config?.buttonLabel||"Pay ${amount} with {symbol}").replace("{amount}",this.amountUsd?`${Number(this.amountUsd).toFixed(2)}`:"$0.00").replace("{symbol}",this.selectedSymbol||this.config?.defaultSymbol||"ICP"),s=this.cryptoOptions.find(P=>P.symbol===(this.selectedSymbol||""))?.label||this.cryptoOptions[0]?.label||this.config?.defaultSymbol||"ICP",o=this.config?.progressBar?.mode||"modal",a=this.config?.showLedgerDropdown,l=a==="buttons"?"buttons":a==="none"?"none":"dropdown",c=(this.cryptoOptions?.length||0)>1,h=l!=="none"&&(c||l==="dropdown"),$=l==="dropdown"?"dropdown":c?"buttons":"none",se=this.config?.progressBar?.enabled!==!1&&(o==="modal"?!0:this.processing);return xe`
1436
- <div class="icpay-card icpay-section icpay-widget-base">
1437
- ${se?xe`
1438
- <icpay-progress-bar
1439
- .debug=${!!this.config?.debug}
1440
- .theme=${this.config?.theme}
1441
- .amount=${Number(this.amountUsd||0)}
1442
- .ledgerSymbol=${this.selectedSymbol||this.config?.defaultSymbol||"ICP"}
1443
- ></icpay-progress-bar>
1444
- `:null}
1445
-
1446
- <div class="row">
1447
- <div class="top-row ${h?"with-selector":""}">
1448
- <div class="amount-field">
1449
- <span class="currency-prefix">$</span>
1450
- <input type="number" min="0" step="${Number(this.config?.stepUsd??.5)}" .value=${String(this.amountUsd||"")} placeholder="${e}" @input=${P=>this.onInputChange(P)} />
1451
- </div>
1452
- ${h?xe`
1453
- <icpay-token-selector
1454
- .options=${this.cryptoOptions}
1455
- .value=${this.selectedSymbol||""}
1456
- .defaultSymbol=${this.config?.defaultSymbol||"ICP"}
1457
- mode=${$}
1458
- .showLabel=${!1}
1459
- @icpay-token-change=${P=>this.selectSymbol(P.detail.symbol)}
1460
- ></icpay-token-selector>
1461
- `:null}
1462
- </div>
1463
- <button class="pay-button ${this.processing?"processing":""}"
1464
- ?disabled=${this.processing||this.config?.disablePaymentButton===!0||this.succeeded&&this.config?.disableAfterSuccess===!0}
1465
- @click=${()=>this.pay()}>
1466
- ${this.succeeded&&this.config?.disableAfterSuccess?"Paid":this.processing?"Processing\u2026":i}
1467
- </button>
1468
- </div>
1469
- <div class="hint">Default: ${this.config?.defaultSymbol||"ICP"}. Min: $${Number(this.config?.minUsd??.5).toFixed(2)}${this.config?.maxUsd?`, Max: $${Number(this.config.maxUsd).toFixed(2)}`:""}</div>
1470
-
1471
- ${this.errorMessage?xe`
1472
- <div class="error-message ${this.errorSeverity}" style="margin-top: 12px; padding: 8px 12px; border-radius: 6px; font-size: 14px; text-align: center;">
1473
- ${this.errorMessage}
1474
- ${this.errorAction?xe`<button style="margin-left: 8px; padding: 4px 8px; background: transparent; border: 1px solid currentColor; border-radius: 4px; font-size: 12px; cursor: pointer;">${this.errorAction}</button>`:""}
1475
- </div>
1476
- `:""}
1477
- ${(()=>{let V=(this.pnp?.getEnabledWallets?.()||[]).map(G=>({id:this.getWalletId(G),label:this.getWalletLabel(G),icon:this.getWalletIcon(G)}));return H({visible:!!(this.showWalletModal&&this.pnp),wallets:V,isConnecting:!1,onSelect:G=>this.connectWithWallet(G),onClose:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1},onCreditCard:this.config?.onramp?.enabled!==!1&&this.config?.onrampDisabled!==!0?()=>this.startOnramp():void 0,creditCardLabel:this.config?.onramp?.creditCardLabel||"Pay with credit card",showCreditCard:this.config?.onramp?.enabled!==!1&&this.config?.onrampDisabled!==!0,creditCardTooltip:(()=>{let X=Number(this.amountUsd||0);return X>0&&X<5&&this.config?.onramp?.enabled!==!1&&this.config?.onrampDisabled!==!0?`Note: Minimum card amount is $5. You will pay about $${(5-X).toFixed(2)} more.`:null})(),oisyReadyToPay:this.oisyReadyToPay,onOisyPay:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1,this.pay()}})})()}
1478
-
1479
- ${this.showOnrampModal?F({visible:this.showOnrampModal,sessionId:this.onrampSessionId,errorMessage:this.onrampErrorMessage,apiKey:this.config?.onramp?.apiKey,environment:this.config?.onramp?.environment||"STAGING",width:this.config?.onramp?.width,height:this.config?.onramp?.height,onClose:()=>{this.showOnrampModal=!1},onBack:()=>{this.showOnrampModal=!1,this.showWalletModal=!0}}):null}
1480
- </div>
1481
- `}};w.styles=[K,kt`
1482
- .row { display: grid; grid-template-columns: 1fr; gap: 12px; align-items: stretch; }
1483
- .top-row { display: grid; grid-template-columns: 1fr; gap: 10px; align-items: center; }
1484
- .top-row.with-selector { grid-template-columns: 1fr 2fr; }
1485
- icpay-token-selector { width: 100%; }
1486
- .amount-field { position: relative; width: 100%; }
1487
- .amount-field .currency-prefix { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--icpay-muted, #a3a3a3); font-weight: 600; pointer-events: none; z-index: 2; }
1488
- .amount-field input[type="number"] { padding-left: 32px; position: relative; z-index: 1; }
1489
- input[type="number"] { background: var(--icpay-surface-alt); border: 1px solid var(--icpay-border); color: var(--icpay-text); border-radius: 8px; padding: 10px; font-weight: 600; width: 100%; box-sizing: border-box; height: 54px; }
1490
- select { background: var(--icpay-surface-alt); border: 1px solid var(--icpay-border); color: var(--icpay-text); border-radius: 8px; padding: 10px; font-weight: 600; }
1491
- .pay-button { width: 100%; }
1492
- .error-message { border: 1px solid; font-weight: 500; }
1493
- .error-message.info { background: rgba(59,130,246,0.1); border-color: rgba(59,130,246,0.3); color: #3b82f6; }
1494
- .error-message.warning { background: rgba(245,158,11,0.1); border-color: rgba(245,158,11,0.3); color: #f59e0b; }
1495
- .error-message.error { background: rgba(239,68,68,0.1); border-color: rgba(239,68,68,0.3); color: #ef4444; }
1496
- .hint { font-size: 12px; color: var(--icpay-muted); margin-top: 6px; }
1497
-
1498
- @media (max-width: 520px) {
1499
- .top-row { grid-template-columns: 1fr; }
1500
- }
1501
- `],n([Ct({type:Object})],w.prototype,"config",2),n([I()],w.prototype,"amountUsd",2),n([I()],w.prototype,"hasUserAmount",2),n([I()],w.prototype,"selectedSymbol",2),n([I()],w.prototype,"processing",2),n([I()],w.prototype,"succeeded",2),n([I()],w.prototype,"availableLedgers",2),n([I()],w.prototype,"errorMessage",2),n([I()],w.prototype,"errorSeverity",2),n([I()],w.prototype,"errorAction",2),n([I()],w.prototype,"walletConnected",2),n([I()],w.prototype,"pendingAction",2),n([I()],w.prototype,"showWalletModal",2),n([I()],w.prototype,"showOnrampModal",2),n([I()],w.prototype,"onrampSessionId",2),n([I()],w.prototype,"onrampPaymentIntentId",2),n([I()],w.prototype,"onrampErrorMessage",2),n([I()],w.prototype,"oisyReadyToPay",2),n([I()],w.prototype,"lastWalletId",2),w=n([Mt("icpay-amount-input")],w);export{K as a,de as b,g as c,F as d,S as e,f,m as g,E as h,b as i,v as j,w as k};
1502
- //# sourceMappingURL=chunk-P7B3OMBC.js.map