@ic-pay/icpay-widget 1.2.17 → 1.2.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -56,7 +56,7 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var H=Xe`
|
|
|
56
56
|
0%, 100% { opacity: 1; }
|
|
57
57
|
50% { opacity: 0.7; }
|
|
58
58
|
}
|
|
59
|
-
`;function Ie(i,l){if(!i||!l)return;let e=l.primaryColor||void 0,t=l.secondaryColor||void 0,n=(C,B)=>{B&&i.style.setProperty(C,B)};n("--icpay-primary",e),n("--icpay-secondary",t);let a=C=>{if(!C)return null;let B=C.replace("#",""),me=B.length===3?B.split("").map($e=>$e+$e).join(""):B,ye=parseInt(me,16),fe=ye>>16&255,Ve=ye>>8&255,Ye=ye&255;return{r:fe,g:Ve,b:Ye}},c=(C=>{let B=a(C);if(!B)return 0;let me=ye=>{let fe=ye/255;return fe<=.03928?fe/12.92:Math.pow((fe+.055)/1.055,2.4)};return .2126*me(B.r)+.7152*me(B.g)+.0722*me(B.b)})(e||t)>.6,d=l.surfaceColor||(c?"#f3f4f6":"#1f2937"),h=l.surfaceAltColor||(c?"#e5e7eb":"#374151"),p=l.borderColor||(c?"#d1d5db":"#4b5563"),O=l.textColor||(c?"#111827":"#f9fafb"),K=l.accentColor||t||e||(c?"#6b7280":"#9ca3af"),ee=l.mutedTextColor||(c?"#6b7280":"#9ca3af");n("--icpay-accent",K),n("--icpay-text",O),n("--icpay-muted",ee),n("--icpay-surface",d),n("--icpay-surface-alt",h),n("--icpay-border",p)}import{Icpay as Be}from"@ic-pay/icpay-sdk";var Re=typeof window<"u";function ie(i,l,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${l}`,e):console.log(`[ICPay Widget] ${l}`))}function u(i){if(!Re)return{client:{},quoteUsd:async()=>({tokenAmountDecimals:"0"}),sendUsd:async()=>({transactionId:"0",status:"pending"}),startOnrampUsd:async()=>({transactionId:"0",status:"pending",metadata:{onramp:{sessionId:null}}}),notifyIntentUntilComplete:()=>({stop:()=>{}})};ie(i.debug||!1,"Creating SDK with config:",i);let l={publishableKey:i.publishableKey};i.enableEvents!==void 0?l.enableEvents=i.enableEvents:l.enableEvents=!0,i.apiUrl&&(l.apiUrl=i.apiUrl),i.icHost&&(l.icHost=i.icHost),i.actorProvider&&(l.actorProvider=i.actorProvider),i.connectedWallet&&(l.connectedWallet=i.connectedWallet),i.evmProvider&&(l.evmProvider=i.evmProvider),i.onrampDisabled!==void 0&&(l.onrampDisabled=i.onrampDisabled),i.debug!==void 0&&(l.debug=i.debug),ie(i.debug||!1,"Filtered SDK config:",l);try{let o=function(c,d,h){return t.notifyPaymentIntentOnRamp({paymentIntentId:c,intervalMs:d,orderId:h})};var e=o;ie(i.debug||!1,"typeof Icpay:",typeof Be);let t=new Be(l);if(Re){let c=t,d=h=>{c.addEventListener(h,p=>{window.dispatchEvent(new CustomEvent(h,{detail:p?.detail??p}))})};["icpay-sdk-error","icpay-sdk-transaction-created","icpay-sdk-transaction-updated","icpay-sdk-transaction-completed","icpay-sdk-transaction-failed","icpay-sdk-method-start","icpay-sdk-method-success","icpay-sdk-method-error"].forEach(d)}async function n(c,d,h){if(typeof d=="string"&&d.trim().length>0)return t.calculateTokenAmountFromUSD({usdAmount:c,tokenShortcode:d.toLowerCase()});if(typeof h=="string"&&h.trim().length>0)return t.calculateTokenAmountFromUSD({usdAmount:c,ledgerCanisterId:h});throw new Error("quoteUsd requires tokenShortcode or ledgerCanisterId")}async function a(c,d,h,p){let O={...i.metadata,...h||{}},K=`Pay ${c} with crypto`,ee=i.description||O.__description||O.description||K,C={usdAmount:c,metadata:O,description:ee};if(typeof d=="string"&&d.trim().length>0&&(C.tokenShortcode=d.toLowerCase()),typeof p=="string"&&p.trim().length>0&&(C.ledgerCanisterId=p),!C.tokenShortcode&&!C.ledgerCanisterId)throw new Error("sendUsd requires tokenShortcode or ledgerCanisterId");return ie(!!i.debug,"Calling createPaymentUsd (flow decision handled by components)",C),t.createPaymentUsd(C)}async function r(c,d,h){let p={...i.metadata,...h||{}},O=`Pay ${c} with crypto`,K=i.description||p.__description||p.description||O;return ie(!!i.debug,"Calling onramp createPaymentUsd",{usdAmount:c,ledgerCanisterId:d,description:K}),t.createPaymentUsd({usdAmount:c,ledgerCanisterId:d,metadata:p,onrampPayment:!0,description:K})}return{client:t,quoteUsd:n,sendUsd:a,startOnrampUsd:r,notifyIntentUntilComplete:o}}catch(t){throw ie(i.debug||!1,"Error creating SDK:",t),t}}import{LitElement as Qe,html as N,css as Ze}from"lit";import{customElement as Je,property as ne,state as j}from"lit/decorators.js";function m(i,l,e){i&&(e!==void 0?console.log(l,e):console.log(l))}var et=[{key:"wallet",label:"Connect wallet",tooltip:"Awaiting wallet connection",status:"pending"},{key:"await",label:"Awaiting confirmation",tooltip:"Awaiting wallet signature",status:"pending"},{key:"transfer",label:"Transferring funds",tooltip:"Awaiting transfer to merchant",status:"pending"},{key:"verify",label:"Verifying payment",tooltip:"Please wait while we verify",status:"pending"}],f=class extends Qe{constructor(){super(...arguments);this.open=!1;this.suspended=!1;this.steps=et;this.amount=0;this.currency="";this.ledgerSymbol="";this.debug=!1;this.activeIndex=0;this.completed=!1;this.failed=!1;this.errorMessage=null;this.showSuccess=!1;this.showConfetti=!1;this.currentSteps=[];this.currentAmount=0;this.currentCurrency="";this.currentLedgerSymbol="";this.confirmLoadingStartedAt=null;this.progressionTimer=null;this.currentWalletType=null;this.showWalletSelector=!1;this.isTransitioning=!1;this.onMethodStart=e=>{let t=e?.detail?.name||"",n=e?.detail?.type||"";if(m(this.debug,"ICPay Progress: Method start event received:",e.detail),t==="createPayment"||t==="createPaymentUsd"||t==="sendUsd"||t==="pay"||t==="unlock"||t==="tip"||t==="donate"||t==="order"){if(this.open=!0,this.activeIndex=0,this.completed=!1,this.failed=!1,this.errorMessage=null,this.showSuccess=!1,this.showConfetti=!1,this.showWalletSelector=!1,this.isTransitioning=!1,this.currentSteps=this.currentSteps.map(a=>({...a,status:"pending"})),n==="onramp"){let a=this.getStepIndexByKey("wallet");a>=0&&(this.currentSteps[a]={...this.currentSteps[a],label:"Transak Started",tooltip:"Awaiting Transak information"})}this.setLoadingByKey("wallet"),e?.detail?.amount!==void 0&&(this.currentAmount=e.detail.amount,this.amount=e.detail.amount,m(this.debug,"ICPay Progress: Amount updated to:",e.detail.amount)),e?.detail?.currency&&(this.currentCurrency=e.detail.currency,this.currency=e.detail.currency,m(this.debug,"ICPay Progress: Currency updated to:",e.detail.currency)),e?.detail?.ledgerSymbol&&(this.currentLedgerSymbol=e.detail.ledgerSymbol,this.ledgerSymbol=e.detail.ledgerSymbol,m(this.debug,"ICPay Progress: Current state after method start:",{activeIndex:this.activeIndex,currentAmount:this.currentAmount,currentCurrency:this.currentCurrency,currentLedgerSymbol:this.currentLedgerSymbol})),m(this.debug,"ICPay Progress: Waiting for wallet confirmation before starting progression"),this.requestUpdate()}!this.failed&&!this.completed&&(t==="createPaymentX402Usd"?(this.completeByKey("wallet"),this.setLoadingByKey("await")):t==="sendFundsToLedger"?(this.completeByKey("wallet"),this.completeByKey("await"),this.setLoadingByKey("transfer")):t==="notifyLedgerTransaction"&&(this.completeByKey("wallet"),this.completeByKey("await"),this.setLoadingByKey("transfer")))};this.onMethodSuccess=e=>{let t=e?.detail?.name||"";(t==="createPayment"||t==="createPaymentUsd"||t==="sendUsd"||t==="pay"||t==="unlock"||t==="tip"||t==="donate"||t==="order")&&this.dispatchEvent(new CustomEvent("icpay-progress-method-success",{detail:{methodName:t,step:this.activeIndex},bubbles:!0})),!this.failed&&!this.completed&&(t==="getLedgerBalance"?(this.completeByKey("wallet"),this.setLoadingByKey("await")):t==="sendFundsToLedger"?(this.completeByKey("wallet"),this.completeByKey("await"),this.completeByKey("transfer"),this.setLoadingByKey("verify")):t==="notifyLedgerTransaction"&&(this.completeByKey("wallet"),this.completeByKey("await"),this.completeByKey("transfer"),this.setLoadingByKey("verify")))};this.onTransactionCreated=e=>{let t=e?.detail?.transactionId||e?.detail?.id;m(this.debug,"ICPay Progress: Transaction created event received:",e.detail),!this.failed&&!this.completed&&(this.completeByKey("wallet"),this.completeByKey("await"),this.setLoadingByKey("transfer")),this.dispatchEvent(new CustomEvent("icpay-progress-transaction-created",{detail:{transactionId:t,step:this.activeIndex},bubbles:!0}))};this.onTransactionUpdated=e=>{let t=e?.detail?.status||"pending",n=e?.detail?.transactionId||e?.detail?.id;m(this.debug,"ICPay Progress: Transaction updated event received:",e.detail),!this.failed&&this.completed,this.dispatchEvent(new CustomEvent("icpay-progress-transaction-updated",{detail:{status:t,transactionId:n,step:this.activeIndex},bubbles:!0}))};this.onTransactionCompleted=e=>{let t=e?.detail?.transactionId||e?.detail?.id,n=e?.detail?.status||"completed";m(this.debug,"ICPay Progress: Transaction completed event received:",e.detail),m(this.debug,"ICPay Progress: Current state when transaction completed:",{activeIndex:this.activeIndex,completed:this.completed,failed:this.failed,showSuccess:this.showSuccess}),this.completeByKey("transfer"),this.completeByKey("await"),this.completeByKey("verify"),this.completed=!0,this.showSuccess=!0,this.showConfetti=!0,this.dispatchEvent(new CustomEvent("icpay-progress-completed",{detail:{transactionId:t,status:n,amount:this.currentAmount||this.amount,currency:this.currentCurrency||this.currency,ledgerSymbol:this.currentLedgerSymbol||this.ledgerSymbol},bubbles:!0})),setTimeout(()=>{this.showConfetti=!1},3e3)};this.onTransactionFailed=e=>{let t=e?.detail?.message||e?.detail?.error?.message||"Transaction failed",n=e?.detail?.error?.code||e?.detail?.code||"UNKNOWN_ERROR",a=e?.detail?.transactionId||e?.detail?.id;m(this.debug,"ICPay Progress: Transaction failed event received:",e.detail),this.failed=!0,this.errorMessage=this.transformErrorMessage(t),this.showSuccess=!1,this.updateStepStatus(this.activeIndex,"error",t),this.stopAutomaticProgression(),this.open=!0,this.dispatchEvent(new CustomEvent("icpay-progress-failed",{detail:{errorMessage:t,errorCode:n,transactionId:a,step:this.activeIndex},bubbles:!0}))};this.onTransactionMismatched=e=>{let t=e?.detail?.requestedAmount,n=e?.detail?.paidAmount,a=e?.detail?.transactionId||e?.detail?.id;this.failed=!0;let r=t!=null?String(t):"unknown",o=n!=null?String(n):"unknown";this.errorMessage=`Amount mismatch. Requested ${r}, paid ${o}.`,this.showSuccess=!1,this.updateStepStatus(this.activeIndex,"error",this.errorMessage),this.stopAutomaticProgression(),this.open=!0,this.dispatchEvent(new CustomEvent("icpay-progress-failed",{detail:{errorMessage:this.errorMessage,errorCode:"MISMATCHED_AMOUNT",transactionId:a,step:this.activeIndex,requestedAmount:t,paidAmount:n},bubbles:!0}))};this.onMethodError=e=>{let t=e?.detail?.name||"",n=e?.detail?.error?.message||e?.detail?.message||"An error occurred",a=e?.detail?.error?.code||e?.detail?.code||"METHOD_ERROR";m(this.debug,"ICPay Progress: Method error event received:",e.detail),(t?.startsWith("createPayment")||t==="sendUsd"||t==="pay"||t==="unlock"||t==="tip"||t==="donate"||t==="order")&&(this.failed=!0,this.errorMessage=this.transformErrorMessage(n),this.showSuccess=!1,this.updateStepStatus(this.activeIndex,"error",n),this.stopAutomaticProgression(),this.open=!0,this.dispatchEvent(new CustomEvent("icpay-progress-error",{detail:{methodName:t,errorMessage:n,errorCode:a,step:this.activeIndex},bubbles:!0})))};this.onSDKError=e=>{let t=e?.detail?.message||"SDK error occurred",n=e?.detail?.code||"SDK_ERROR";m(this.debug,"ICPay Progress: SDK error event received:",e.detail),this.failed=!0,this.errorMessage=this.transformErrorMessage(t),this.showSuccess=!1,this.updateStepStatus(this.activeIndex,"error",t),this.stopAutomaticProgression(),this.open=!0,this.dispatchEvent(new CustomEvent("icpay-progress-sdk-error",{detail:{errorMessage:t,errorCode:n,step:this.activeIndex},bubbles:!0}))};this.onWalletConnected=e=>{let t=e?.detail?.walletType||"unknown";m(this.debug,"ICPay Progress: Wallet connected event received:",e.detail),this.completeByKey("wallet"),this.setLoadingByKey("await"),this.startTransitionToProgress(),this.dispatchEvent(new CustomEvent("icpay-progress-wallet-connected",{detail:{walletType:t,step:this.activeIndex},bubbles:!0})),this.currentWalletType=t};this.onWalletDisconnected=e=>{let t=e?.detail?.walletType||"unknown";m(this.debug,"ICPay Progress: Wallet disconnected event received:",e.detail),this.dispatchEvent(new CustomEvent("icpay-progress-wallet-disconnected",{detail:{walletType:t,step:this.activeIndex},bubbles:!0})),this.currentWalletType=null};this.onBalanceCheck=e=>{let t=e?.detail?.hasBalance||!1,n=e?.detail?.balance||0;m(this.debug,"ICPay Progress: Balance check event received:",e.detail),t||(this.failed=!0,this.errorMessage="Insufficient balance for transaction",this.updateStepStatus(this.activeIndex,"error","Insufficient balance for transaction"),this.stopAutomaticProgression(),this.showWalletSelector=!1,this.dispatchEvent(new CustomEvent("icpay-progress-insufficient-balance",{detail:{balance:n,required:this.currentAmount||this.amount,step:this.activeIndex},bubbles:!0})))};this.onLedgerVerified=e=>{let t=e?.detail?.ledgerId||e?.detail?.canisterId,n=e?.detail?.symbol||"unknown";m(this.debug,"ICPay Progress: Ledger verified event received:",e.detail),n&&n!=="unknown"&&(this.currentLedgerSymbol=n,this.ledgerSymbol=n),this.dispatchEvent(new CustomEvent("icpay-progress-ledger-verified",{detail:{ledgerId:t,symbol:n,step:this.activeIndex},bubbles:!0}))};this.onWidgetPayment=e=>{let t=e?.detail?.amount,n=e?.detail?.currency,a=e?.detail?.ledgerSymbol;if(m(this.debug,"ICPay Progress: Widget payment event received:",e.detail),t!==void 0&&(this.currentAmount=t,this.amount=t),n&&(this.currentCurrency=n,this.currency=n),a&&(this.currentLedgerSymbol=a,this.ledgerSymbol=a),!this.failed){for(let r=this.activeIndex;r<this.currentSteps.length;r++)this.updateStepStatus(r,"completed");this.activeIndex=this.currentSteps.length-1,this.completed=!0,this.showSuccess=!0,this.showConfetti=!0}this.dispatchEvent(new CustomEvent("icpay-progress-widget-payment",{detail:{amount:t,currency:n,ledgerSymbol:a,step:this.activeIndex},bubbles:!0}))};this.onWidgetError=e=>{let t=e?.detail?.message||"Widget error occurred",n=e?.detail?.code||"WIDGET_ERROR";m(this.debug,"ICPay Progress: Widget error event received:",e.detail),this.failed=!0,this.errorMessage=this.transformErrorMessage(t),this.showSuccess=!1,this.updateStepStatus(this.activeIndex,"error",t),this.stopAutomaticProgression(),this.open=!0,this.dispatchEvent(new CustomEvent("icpay-progress-widget-error",{detail:{errorMessage:t,errorCode:n,step:this.activeIndex},bubbles:!0}))};this.onWidgetUnlock=e=>{let t=e?.detail?.amount,n=e?.detail?.currency;if(m(this.debug,"ICPay Progress: Widget unlock event received:",e.detail),!this.failed){for(let a=this.activeIndex;a<this.currentSteps.length;a++)this.updateStepStatus(a,"completed");this.activeIndex=this.currentSteps.length-1,this.completed=!0,this.showSuccess=!0,this.showConfetti=!0}this.dispatchEvent(new CustomEvent("icpay-progress-widget-unlock",{detail:{amount:t,currency:n,step:this.activeIndex},bubbles:!0}))};this.onWidgetTip=e=>{let t=e?.detail?.amount,n=e?.detail?.currency;if(m(this.debug,"ICPay Progress: Widget tip event received:",e.detail),!this.failed){for(let a=this.activeIndex;a<this.currentSteps.length;a++)this.updateStepStatus(a,"completed");this.activeIndex=this.currentSteps.length-1,this.completed=!0,this.showSuccess=!0,this.showConfetti=!0}this.dispatchEvent(new CustomEvent("icpay-progress-widget-tip",{detail:{amount:t,currency:n,step:this.activeIndex},bubbles:!0}))};this.onWidgetDonation=e=>{let t=e?.detail?.amount,n=e?.detail?.currency;if(m(this.debug,"ICPay Progress: Widget donation event received:",e.detail),!this.failed){for(let a=this.activeIndex;a<this.currentSteps.length;a++)this.updateStepStatus(a,"completed");this.activeIndex=this.currentSteps.length-1,this.completed=!0,this.showSuccess=!0,this.showConfetti=!0}this.dispatchEvent(new CustomEvent("icpay-progress-widget-donation",{detail:{amount:t,currency:n,step:this.activeIndex},bubbles:!0}))};this.onWidgetCoffee=e=>{let t=e?.detail?.amount,n=e?.detail?.currency;if(m(this.debug,"ICPay Progress: Widget coffee event received:",e.detail),!this.failed){for(let a=this.activeIndex;a<this.currentSteps.length;a++)this.updateStepStatus(a,"completed");this.activeIndex=this.currentSteps.length-1,this.completed=!0,this.showSuccess=!0,this.showConfetti=!0}this.dispatchEvent(new CustomEvent("icpay-progress-widget-coffee",{detail:{amount:t,currency:n,step:this.activeIndex},bubbles:!0}))};this.onWalletCancelled=e=>{try{this.open=!0;let t=this.getStepIndexByKey("wallet");t>=0&&(this.activeIndex=t,this.currentSteps[t]={...this.currentSteps[t],tooltip:"Wallet connection cancelled",status:"error"},this.requestUpdate())}catch{}};this.onWalletError=e=>{try{let t=e?.detail?.message||"Wallet error",n=this.transformErrorMessage(t);this.open=!0;let a=this.getStepIndexByKey("wallet");a>=0&&(this.activeIndex=a,this.currentSteps[a]={...this.currentSteps[a],tooltip:"Wallet connection failed",status:"error",errorMessage:n},this.requestUpdate())}catch{}}}connectedCallback(){super.connectedCallback();try{Ie(this,this.theme)}catch{}this.currentSteps=[...this.steps],this.currentAmount=this.amount,this.currentCurrency=this.currency,this.currentLedgerSymbol=this.ledgerSymbol,this.attachSDKEventListeners()}disconnectedCallback(){super.disconnectedCallback(),this.detachSDKEventListeners(),this.stopAutomaticProgression()}updated(e){if(e.has("theme"))try{Ie(this,this.theme)}catch{}}attachSDKEventListeners(){window.addEventListener("icpay-sdk-method-start",this.onMethodStart),window.addEventListener("icpay-sdk-method-success",this.onMethodSuccess),window.addEventListener("icpay-sdk-method-error",this.onMethodError),window.addEventListener("icpay-sdk-wallet-cancelled",this.onWalletCancelled),window.addEventListener("icpay-sdk-wallet-error",this.onWalletError),window.addEventListener("icpay-sdk-transaction-created",this.onTransactionCreated),window.addEventListener("icpay-sdk-transaction-updated",this.onTransactionUpdated),window.addEventListener("icpay-sdk-transaction-completed",this.onTransactionCompleted),window.addEventListener("icpay-sdk-transaction-failed",this.onTransactionFailed),window.addEventListener("icpay-sdk-transaction-mismatched",this.onTransactionMismatched),window.addEventListener("icpay-sdk-error",this.onSDKError),window.addEventListener("icpay-sdk-wallet-connected",this.onWalletConnected),window.addEventListener("icpay-sdk-wallet-disconnected",this.onWalletDisconnected),window.addEventListener("icpay-sdk-balance-check",this.onBalanceCheck),window.addEventListener("icpay-sdk-ledger-verified",this.onLedgerVerified),window.addEventListener("icpay-pay",this.onWidgetPayment),window.addEventListener("icpay-error",this.onWidgetError),window.addEventListener("icpay-unlock",this.onWidgetUnlock),window.addEventListener("icpay-tip",this.onWidgetTip),window.addEventListener("icpay-donation",this.onWidgetDonation),window.addEventListener("icpay-coffee",this.onWidgetCoffee)}detachSDKEventListeners(){window.removeEventListener("icpay-sdk-method-start",this.onMethodStart),window.removeEventListener("icpay-sdk-method-success",this.onMethodSuccess),window.removeEventListener("icpay-sdk-method-error",this.onMethodError),window.removeEventListener("icpay-sdk-wallet-cancelled",this.onWalletCancelled),window.removeEventListener("icpay-sdk-wallet-error",this.onWalletError),window.removeEventListener("icpay-sdk-transaction-created",this.onTransactionCreated),window.removeEventListener("icpay-sdk-transaction-updated",this.onTransactionUpdated),window.removeEventListener("icpay-sdk-transaction-completed",this.onTransactionCompleted),window.removeEventListener("icpay-sdk-transaction-failed",this.onTransactionFailed),window.removeEventListener("icpay-sdk-transaction-mismatched",this.onTransactionMismatched),window.removeEventListener("icpay-sdk-error",this.onSDKError),window.removeEventListener("icpay-sdk-wallet-connected",this.onWalletConnected),window.removeEventListener("icpay-sdk-wallet-disconnected",this.onWalletDisconnected),window.removeEventListener("icpay-sdk-balance-check",this.onBalanceCheck),window.removeEventListener("icpay-sdk-ledger-verified",this.onLedgerVerified),window.removeEventListener("icpay-pay",this.onWidgetPayment),window.removeEventListener("icpay-error",this.onWidgetError),window.removeEventListener("icpay-unlock",this.onWidgetUnlock),window.removeEventListener("icpay-tip",this.onWidgetTip),window.removeEventListener("icpay-donation",this.onWidgetDonation),window.removeEventListener("icpay-coffee",this.onWidgetCoffee)}startAutomaticProgression(){this.progressionTimer&&clearInterval(this.progressionTimer),this.activeIndex=1,this.updateStepStatus(this.activeIndex,"loading"),m(this.debug,"ICPay Progress: Starting automatic progression from step:",this.activeIndex),this.progressionTimer=setInterval(()=>{if(this.failed||this.completed){this.stopAutomaticProgression();return}m(this.debug,"ICPay Progress: Processing step:",this.activeIndex),this.updateStepStatus(this.activeIndex,"completed"),this.activeIndex<this.currentSteps.length-1?(this.activeIndex++,this.updateStepStatus(this.activeIndex,"loading"),m(this.debug,"ICPay Progress: Auto-progressed to step:",this.activeIndex)):(this.stopAutomaticProgression(),m(this.debug,"ICPay Progress: All steps completed, waiting for transaction completion")),this.requestUpdate()},3e3)}stopAutomaticProgression(){this.progressionTimer&&(clearInterval(this.progressionTimer),this.progressionTimer=null)}updateStepStatus(e,t,n){if(e>=0&&e<this.currentSteps.length){let a=this.currentSteps[e],r=a.status;a.status=t,t==="completed"&&(a.timestamp=this.getCurrentTime()),t==="error"&&n&&(a.errorMessage=this.transformErrorMessage(n)),r!==t&&m(this.debug,`ICPay Progress: Step ${e} (${a.label}) status changed from ${r} to ${t}`),this.requestUpdate()}}getCurrentTime(){return new Date().toLocaleTimeString("en-US",{hour12:!1,hour:"2-digit",minute:"2-digit",second:"2-digit"})}getStepIcon(e){return e.status==="error"?N`<div class="error-x">✕</div>`:N`<div class="spinner"></div>`}getStepIndexByKey(e){return this.currentSteps.findIndex(t=>t.key===e)}setLoadingByKey(e){let t=this.getStepIndexByKey(e);t>=0&&(this.activeIndex=t,this.updateStepStatus(t,"loading"),e==="verify"&&(this.confirmLoadingStartedAt=Date.now()))}completeByKey(e){let t=this.getStepIndexByKey(e);t>=0&&(this.updateStepStatus(t,"completed"),this.activeIndex=t)}transformErrorMessage(e){let t=String(e||"").toLowerCase();return t.includes("user rejected")||t.includes("user cancelled")||t.includes("user canceled")||t.includes("signature rejected")?"User have rejected the transfer":e}renderConfetti(){if(!this.showConfetti)return"";let e=Array.from({length:50},(n,a)=>a),t=["#0066FF","#ef4444","#10b981","#f59e0b","#8b5cf6"];return N`
|
|
59
|
+
`;function Ie(i,l){if(!i||!l)return;let e=l.primaryColor||void 0,t=l.secondaryColor||void 0,n=(C,B)=>{B&&i.style.setProperty(C,B)};n("--icpay-primary",e),n("--icpay-secondary",t);let a=C=>{if(!C)return null;let B=C.replace("#",""),me=B.length===3?B.split("").map($e=>$e+$e).join(""):B,ye=parseInt(me,16),fe=ye>>16&255,Ve=ye>>8&255,Ye=ye&255;return{r:fe,g:Ve,b:Ye}},c=(C=>{let B=a(C);if(!B)return 0;let me=ye=>{let fe=ye/255;return fe<=.03928?fe/12.92:Math.pow((fe+.055)/1.055,2.4)};return .2126*me(B.r)+.7152*me(B.g)+.0722*me(B.b)})(e||t)>.6,d=l.surfaceColor||(c?"#f3f4f6":"#1f2937"),h=l.surfaceAltColor||(c?"#e5e7eb":"#374151"),p=l.borderColor||(c?"#d1d5db":"#4b5563"),O=l.textColor||(c?"#111827":"#f9fafb"),K=l.accentColor||t||e||(c?"#6b7280":"#9ca3af"),ee=l.mutedTextColor||(c?"#6b7280":"#9ca3af");n("--icpay-accent",K),n("--icpay-text",O),n("--icpay-muted",ee),n("--icpay-surface",d),n("--icpay-surface-alt",h),n("--icpay-border",p)}import{Icpay as Be}from"@ic-pay/icpay-sdk";var Re=typeof window<"u";function ie(i,l,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${l}`,e):console.log(`[ICPay Widget] ${l}`))}function g(i){if(!Re)return{client:{},quoteUsd:async()=>({tokenAmountDecimals:"0"}),sendUsd:async()=>({transactionId:"0",status:"pending"}),startOnrampUsd:async()=>({transactionId:"0",status:"pending",metadata:{onramp:{sessionId:null}}}),notifyIntentUntilComplete:()=>({stop:()=>{}})};ie(i.debug||!1,"Creating SDK with config:",i);let l={publishableKey:i.publishableKey};i.enableEvents!==void 0?l.enableEvents=i.enableEvents:l.enableEvents=!0,i.apiUrl&&(l.apiUrl=i.apiUrl),i.icHost&&(l.icHost=i.icHost),i.actorProvider&&(l.actorProvider=i.actorProvider),i.connectedWallet&&(l.connectedWallet=i.connectedWallet),i.evmProvider&&(l.evmProvider=i.evmProvider),i.onrampDisabled!==void 0&&(l.onrampDisabled=i.onrampDisabled),i.debug!==void 0&&(l.debug=i.debug),ie(i.debug||!1,"Filtered SDK config:",l);try{let o=function(c,d,h){return t.notifyPaymentIntentOnRamp({paymentIntentId:c,intervalMs:d,orderId:h})};var e=o;ie(i.debug||!1,"typeof Icpay:",typeof Be);let t=new Be(l);if(Re){let c=t,d=h=>{c.addEventListener(h,p=>{window.dispatchEvent(new CustomEvent(h,{detail:p?.detail??p}))})};["icpay-sdk-error","icpay-sdk-transaction-created","icpay-sdk-transaction-updated","icpay-sdk-transaction-completed","icpay-sdk-transaction-failed","icpay-sdk-method-start","icpay-sdk-method-success","icpay-sdk-method-error"].forEach(d)}async function n(c,d,h){if(typeof d=="string"&&d.trim().length>0)return t.calculateTokenAmountFromUSD({usdAmount:c,tokenShortcode:d.toLowerCase()});if(typeof h=="string"&&h.trim().length>0)return t.calculateTokenAmountFromUSD({usdAmount:c,ledgerCanisterId:h});throw new Error("quoteUsd requires tokenShortcode or ledgerCanisterId")}async function a(c,d,h,p){let O={...i.metadata,...h||{}},K=`Pay ${c} with crypto`,ee=i.description||O.__description||O.description||K,C={usdAmount:c,metadata:O,description:ee};if(typeof d=="string"&&d.trim().length>0&&(C.tokenShortcode=d.toLowerCase()),typeof p=="string"&&p.trim().length>0&&(C.ledgerCanisterId=p),!C.tokenShortcode&&!C.ledgerCanisterId)throw new Error("sendUsd requires tokenShortcode or ledgerCanisterId");return ie(!!i.debug,"Calling createPaymentUsd (flow decision handled by components)",C),t.createPaymentUsd(C)}async function r(c,d,h){let p={...i.metadata,...h||{}},O=`Pay ${c} with crypto`,K=i.description||p.__description||p.description||O;return ie(!!i.debug,"Calling onramp createPaymentUsd",{usdAmount:c,ledgerCanisterId:d,description:K}),t.createPaymentUsd({usdAmount:c,ledgerCanisterId:d,metadata:p,onrampPayment:!0,description:K})}return{client:t,quoteUsd:n,sendUsd:a,startOnrampUsd:r,notifyIntentUntilComplete:o}}catch(t){throw ie(i.debug||!1,"Error creating SDK:",t),t}}import{LitElement as Qe,html as N,css as Ze}from"lit";import{customElement as Je,property as ne,state as j}from"lit/decorators.js";function m(i,l,e){i&&(e!==void 0?console.log(l,e):console.log(l))}var et=[{key:"wallet",label:"Connect wallet",tooltip:"Awaiting wallet connection",status:"pending"},{key:"await",label:"Awaiting confirmation",tooltip:"Awaiting wallet signature",status:"pending"},{key:"transfer",label:"Transferring funds",tooltip:"Awaiting transfer to merchant",status:"pending"},{key:"verify",label:"Verifying payment",tooltip:"Please wait while we verify",status:"pending"}],f=class extends Qe{constructor(){super(...arguments);this.open=!1;this.suspended=!1;this.steps=et;this.amount=0;this.currency="";this.ledgerSymbol="";this.debug=!1;this.activeIndex=0;this.completed=!1;this.failed=!1;this.errorMessage=null;this.showSuccess=!1;this.showConfetti=!1;this.currentSteps=[];this.currentAmount=0;this.currentCurrency="";this.currentLedgerSymbol="";this.confirmLoadingStartedAt=null;this.progressionTimer=null;this.currentWalletType=null;this.showWalletSelector=!1;this.isTransitioning=!1;this.onMethodStart=e=>{let t=e?.detail?.name||"",n=e?.detail?.type||"";if(m(this.debug,"ICPay Progress: Method start event received:",e.detail),t==="createPayment"||t==="createPaymentUsd"||t==="sendUsd"||t==="pay"||t==="unlock"||t==="tip"||t==="donate"||t==="order"){if(this.open=!0,this.activeIndex=0,this.completed=!1,this.failed=!1,this.errorMessage=null,this.showSuccess=!1,this.showConfetti=!1,this.showWalletSelector=!1,this.isTransitioning=!1,this.currentSteps=this.currentSteps.map(a=>({...a,status:"pending"})),n==="onramp"){let a=this.getStepIndexByKey("wallet");a>=0&&(this.currentSteps[a]={...this.currentSteps[a],label:"Transak Started",tooltip:"Awaiting Transak information"})}this.setLoadingByKey("wallet"),e?.detail?.amount!==void 0&&(this.currentAmount=e.detail.amount,this.amount=e.detail.amount,m(this.debug,"ICPay Progress: Amount updated to:",e.detail.amount)),e?.detail?.currency&&(this.currentCurrency=e.detail.currency,this.currency=e.detail.currency,m(this.debug,"ICPay Progress: Currency updated to:",e.detail.currency)),e?.detail?.ledgerSymbol&&(this.currentLedgerSymbol=e.detail.ledgerSymbol,this.ledgerSymbol=e.detail.ledgerSymbol,m(this.debug,"ICPay Progress: Current state after method start:",{activeIndex:this.activeIndex,currentAmount:this.currentAmount,currentCurrency:this.currentCurrency,currentLedgerSymbol:this.currentLedgerSymbol})),m(this.debug,"ICPay Progress: Waiting for wallet confirmation before starting progression"),this.requestUpdate()}!this.failed&&!this.completed&&(t==="createPaymentX402Usd"?(this.completeByKey("wallet"),this.setLoadingByKey("await")):t==="sendFundsToLedger"?(this.completeByKey("wallet"),this.completeByKey("await"),this.setLoadingByKey("transfer")):t==="notifyLedgerTransaction"&&(this.completeByKey("wallet"),this.completeByKey("await"),this.setLoadingByKey("transfer")))};this.onMethodSuccess=e=>{let t=e?.detail?.name||"";(t==="createPayment"||t==="createPaymentUsd"||t==="sendUsd"||t==="pay"||t==="unlock"||t==="tip"||t==="donate"||t==="order")&&this.dispatchEvent(new CustomEvent("icpay-progress-method-success",{detail:{methodName:t,step:this.activeIndex},bubbles:!0})),!this.failed&&!this.completed&&(t==="getLedgerBalance"?(this.completeByKey("wallet"),this.setLoadingByKey("await")):t==="sendFundsToLedger"?(this.completeByKey("wallet"),this.completeByKey("await"),this.completeByKey("transfer"),this.setLoadingByKey("verify")):t==="notifyLedgerTransaction"&&(this.completeByKey("wallet"),this.completeByKey("await"),this.completeByKey("transfer"),this.setLoadingByKey("verify")))};this.onTransactionCreated=e=>{let t=e?.detail?.transactionId||e?.detail?.id;m(this.debug,"ICPay Progress: Transaction created event received:",e.detail),!this.failed&&!this.completed&&(this.completeByKey("wallet"),this.completeByKey("await"),this.setLoadingByKey("transfer")),this.dispatchEvent(new CustomEvent("icpay-progress-transaction-created",{detail:{transactionId:t,step:this.activeIndex},bubbles:!0}))};this.onTransactionUpdated=e=>{let t=e?.detail?.status||"pending",n=e?.detail?.transactionId||e?.detail?.id;m(this.debug,"ICPay Progress: Transaction updated event received:",e.detail),!this.failed&&this.completed,this.dispatchEvent(new CustomEvent("icpay-progress-transaction-updated",{detail:{status:t,transactionId:n,step:this.activeIndex},bubbles:!0}))};this.onTransactionCompleted=e=>{let t=e?.detail?.transactionId||e?.detail?.id,n=e?.detail?.status||"completed";m(this.debug,"ICPay Progress: Transaction completed event received:",e.detail),m(this.debug,"ICPay Progress: Current state when transaction completed:",{activeIndex:this.activeIndex,completed:this.completed,failed:this.failed,showSuccess:this.showSuccess}),this.completeByKey("transfer"),this.completeByKey("await"),this.completeByKey("verify"),this.completed=!0,this.showSuccess=!0,this.showConfetti=!0,this.dispatchEvent(new CustomEvent("icpay-progress-completed",{detail:{transactionId:t,status:n,amount:this.currentAmount||this.amount,currency:this.currentCurrency||this.currency,ledgerSymbol:this.currentLedgerSymbol||this.ledgerSymbol},bubbles:!0})),setTimeout(()=>{this.showConfetti=!1},3e3)};this.onTransactionFailed=e=>{let t=e?.detail?.message||e?.detail?.error?.message||"Transaction failed",n=e?.detail?.error?.code||e?.detail?.code||"UNKNOWN_ERROR",a=e?.detail?.transactionId||e?.detail?.id;m(this.debug,"ICPay Progress: Transaction failed event received:",e.detail),this.failed=!0,this.errorMessage=this.transformErrorMessage(t),this.showSuccess=!1,this.updateStepStatus(this.activeIndex,"error",t),this.stopAutomaticProgression(),this.open=!0,this.dispatchEvent(new CustomEvent("icpay-progress-failed",{detail:{errorMessage:t,errorCode:n,transactionId:a,step:this.activeIndex},bubbles:!0}))};this.onTransactionMismatched=e=>{let t=e?.detail?.requestedAmount,n=e?.detail?.paidAmount,a=e?.detail?.transactionId||e?.detail?.id;this.failed=!0;let r=t!=null?String(t):"unknown",o=n!=null?String(n):"unknown";this.errorMessage=`Amount mismatch. Requested ${r}, paid ${o}.`,this.showSuccess=!1,this.updateStepStatus(this.activeIndex,"error",this.errorMessage),this.stopAutomaticProgression(),this.open=!0,this.dispatchEvent(new CustomEvent("icpay-progress-failed",{detail:{errorMessage:this.errorMessage,errorCode:"MISMATCHED_AMOUNT",transactionId:a,step:this.activeIndex,requestedAmount:t,paidAmount:n},bubbles:!0}))};this.onMethodError=e=>{let t=e?.detail?.name||"",n=e?.detail?.error?.message||e?.detail?.message||"An error occurred",a=e?.detail?.error?.code||e?.detail?.code||"METHOD_ERROR";m(this.debug,"ICPay Progress: Method error event received:",e.detail),(t?.startsWith("createPayment")||t==="sendUsd"||t==="pay"||t==="unlock"||t==="tip"||t==="donate"||t==="order")&&(this.failed=!0,this.errorMessage=this.transformErrorMessage(n),this.showSuccess=!1,this.updateStepStatus(this.activeIndex,"error",n),this.stopAutomaticProgression(),this.open=!0,this.dispatchEvent(new CustomEvent("icpay-progress-error",{detail:{methodName:t,errorMessage:n,errorCode:a,step:this.activeIndex},bubbles:!0})))};this.onSDKError=e=>{let t=e?.detail?.message||"SDK error occurred",n=e?.detail?.code||"SDK_ERROR";m(this.debug,"ICPay Progress: SDK error event received:",e.detail),this.failed=!0,this.errorMessage=this.transformErrorMessage(t),this.showSuccess=!1,this.updateStepStatus(this.activeIndex,"error",t),this.stopAutomaticProgression(),this.open=!0,this.dispatchEvent(new CustomEvent("icpay-progress-sdk-error",{detail:{errorMessage:t,errorCode:n,step:this.activeIndex},bubbles:!0}))};this.onWalletConnected=e=>{let t=e?.detail?.walletType||"unknown";m(this.debug,"ICPay Progress: Wallet connected event received:",e.detail),this.completeByKey("wallet"),this.setLoadingByKey("await"),this.startTransitionToProgress(),this.dispatchEvent(new CustomEvent("icpay-progress-wallet-connected",{detail:{walletType:t,step:this.activeIndex},bubbles:!0})),this.currentWalletType=t};this.onWalletDisconnected=e=>{let t=e?.detail?.walletType||"unknown";m(this.debug,"ICPay Progress: Wallet disconnected event received:",e.detail),this.dispatchEvent(new CustomEvent("icpay-progress-wallet-disconnected",{detail:{walletType:t,step:this.activeIndex},bubbles:!0})),this.currentWalletType=null};this.onBalanceCheck=e=>{let t=e?.detail?.hasBalance||!1,n=e?.detail?.balance||0;m(this.debug,"ICPay Progress: Balance check event received:",e.detail),t||(this.failed=!0,this.errorMessage="Insufficient balance for transaction",this.updateStepStatus(this.activeIndex,"error","Insufficient balance for transaction"),this.stopAutomaticProgression(),this.showWalletSelector=!1,this.dispatchEvent(new CustomEvent("icpay-progress-insufficient-balance",{detail:{balance:n,required:this.currentAmount||this.amount,step:this.activeIndex},bubbles:!0})))};this.onLedgerVerified=e=>{let t=e?.detail?.ledgerId||e?.detail?.canisterId,n=e?.detail?.symbol||"unknown";m(this.debug,"ICPay Progress: Ledger verified event received:",e.detail),n&&n!=="unknown"&&(this.currentLedgerSymbol=n,this.ledgerSymbol=n),this.dispatchEvent(new CustomEvent("icpay-progress-ledger-verified",{detail:{ledgerId:t,symbol:n,step:this.activeIndex},bubbles:!0}))};this.onWidgetPayment=e=>{let t=e?.detail?.amount,n=e?.detail?.currency,a=e?.detail?.ledgerSymbol;if(m(this.debug,"ICPay Progress: Widget payment event received:",e.detail),t!==void 0&&(this.currentAmount=t,this.amount=t),n&&(this.currentCurrency=n,this.currency=n),a&&(this.currentLedgerSymbol=a,this.ledgerSymbol=a),!this.failed){for(let r=this.activeIndex;r<this.currentSteps.length;r++)this.updateStepStatus(r,"completed");this.activeIndex=this.currentSteps.length-1,this.completed=!0,this.showSuccess=!0,this.showConfetti=!0}this.dispatchEvent(new CustomEvent("icpay-progress-widget-payment",{detail:{amount:t,currency:n,ledgerSymbol:a,step:this.activeIndex},bubbles:!0}))};this.onWidgetError=e=>{let t=e?.detail?.message||"Widget error occurred",n=e?.detail?.code||"WIDGET_ERROR";m(this.debug,"ICPay Progress: Widget error event received:",e.detail),this.failed=!0,this.errorMessage=this.transformErrorMessage(t),this.showSuccess=!1,this.updateStepStatus(this.activeIndex,"error",t),this.stopAutomaticProgression(),this.open=!0,this.dispatchEvent(new CustomEvent("icpay-progress-widget-error",{detail:{errorMessage:t,errorCode:n,step:this.activeIndex},bubbles:!0}))};this.onWidgetUnlock=e=>{let t=e?.detail?.amount,n=e?.detail?.currency;if(m(this.debug,"ICPay Progress: Widget unlock event received:",e.detail),!this.failed){for(let a=this.activeIndex;a<this.currentSteps.length;a++)this.updateStepStatus(a,"completed");this.activeIndex=this.currentSteps.length-1,this.completed=!0,this.showSuccess=!0,this.showConfetti=!0}this.dispatchEvent(new CustomEvent("icpay-progress-widget-unlock",{detail:{amount:t,currency:n,step:this.activeIndex},bubbles:!0}))};this.onWidgetTip=e=>{let t=e?.detail?.amount,n=e?.detail?.currency;if(m(this.debug,"ICPay Progress: Widget tip event received:",e.detail),!this.failed){for(let a=this.activeIndex;a<this.currentSteps.length;a++)this.updateStepStatus(a,"completed");this.activeIndex=this.currentSteps.length-1,this.completed=!0,this.showSuccess=!0,this.showConfetti=!0}this.dispatchEvent(new CustomEvent("icpay-progress-widget-tip",{detail:{amount:t,currency:n,step:this.activeIndex},bubbles:!0}))};this.onWidgetDonation=e=>{let t=e?.detail?.amount,n=e?.detail?.currency;if(m(this.debug,"ICPay Progress: Widget donation event received:",e.detail),!this.failed){for(let a=this.activeIndex;a<this.currentSteps.length;a++)this.updateStepStatus(a,"completed");this.activeIndex=this.currentSteps.length-1,this.completed=!0,this.showSuccess=!0,this.showConfetti=!0}this.dispatchEvent(new CustomEvent("icpay-progress-widget-donation",{detail:{amount:t,currency:n,step:this.activeIndex},bubbles:!0}))};this.onWidgetCoffee=e=>{let t=e?.detail?.amount,n=e?.detail?.currency;if(m(this.debug,"ICPay Progress: Widget coffee event received:",e.detail),!this.failed){for(let a=this.activeIndex;a<this.currentSteps.length;a++)this.updateStepStatus(a,"completed");this.activeIndex=this.currentSteps.length-1,this.completed=!0,this.showSuccess=!0,this.showConfetti=!0}this.dispatchEvent(new CustomEvent("icpay-progress-widget-coffee",{detail:{amount:t,currency:n,step:this.activeIndex},bubbles:!0}))};this.onWalletCancelled=e=>{try{this.open=!0;let t=this.getStepIndexByKey("wallet");t>=0&&(this.activeIndex=t,this.currentSteps[t]={...this.currentSteps[t],tooltip:"Wallet connection cancelled",status:"error"},this.requestUpdate())}catch{}};this.onWalletError=e=>{try{let t=e?.detail?.message||"Wallet error",n=this.transformErrorMessage(t);this.open=!0;let a=this.getStepIndexByKey("wallet");a>=0&&(this.activeIndex=a,this.currentSteps[a]={...this.currentSteps[a],tooltip:"Wallet connection failed",status:"error",errorMessage:n},this.requestUpdate())}catch{}}}connectedCallback(){super.connectedCallback();try{Ie(this,this.theme)}catch{}this.currentSteps=[...this.steps],this.currentAmount=this.amount,this.currentCurrency=this.currency,this.currentLedgerSymbol=this.ledgerSymbol,this.attachSDKEventListeners()}disconnectedCallback(){super.disconnectedCallback(),this.detachSDKEventListeners(),this.stopAutomaticProgression()}updated(e){if(e.has("theme"))try{Ie(this,this.theme)}catch{}}attachSDKEventListeners(){window.addEventListener("icpay-sdk-method-start",this.onMethodStart),window.addEventListener("icpay-sdk-method-success",this.onMethodSuccess),window.addEventListener("icpay-sdk-method-error",this.onMethodError),window.addEventListener("icpay-sdk-wallet-cancelled",this.onWalletCancelled),window.addEventListener("icpay-sdk-wallet-error",this.onWalletError),window.addEventListener("icpay-sdk-transaction-created",this.onTransactionCreated),window.addEventListener("icpay-sdk-transaction-updated",this.onTransactionUpdated),window.addEventListener("icpay-sdk-transaction-completed",this.onTransactionCompleted),window.addEventListener("icpay-sdk-transaction-failed",this.onTransactionFailed),window.addEventListener("icpay-sdk-transaction-mismatched",this.onTransactionMismatched),window.addEventListener("icpay-sdk-error",this.onSDKError),window.addEventListener("icpay-sdk-wallet-connected",this.onWalletConnected),window.addEventListener("icpay-sdk-wallet-disconnected",this.onWalletDisconnected),window.addEventListener("icpay-sdk-balance-check",this.onBalanceCheck),window.addEventListener("icpay-sdk-ledger-verified",this.onLedgerVerified),window.addEventListener("icpay-pay",this.onWidgetPayment),window.addEventListener("icpay-error",this.onWidgetError),window.addEventListener("icpay-unlock",this.onWidgetUnlock),window.addEventListener("icpay-tip",this.onWidgetTip),window.addEventListener("icpay-donation",this.onWidgetDonation),window.addEventListener("icpay-coffee",this.onWidgetCoffee)}detachSDKEventListeners(){window.removeEventListener("icpay-sdk-method-start",this.onMethodStart),window.removeEventListener("icpay-sdk-method-success",this.onMethodSuccess),window.removeEventListener("icpay-sdk-method-error",this.onMethodError),window.removeEventListener("icpay-sdk-wallet-cancelled",this.onWalletCancelled),window.removeEventListener("icpay-sdk-wallet-error",this.onWalletError),window.removeEventListener("icpay-sdk-transaction-created",this.onTransactionCreated),window.removeEventListener("icpay-sdk-transaction-updated",this.onTransactionUpdated),window.removeEventListener("icpay-sdk-transaction-completed",this.onTransactionCompleted),window.removeEventListener("icpay-sdk-transaction-failed",this.onTransactionFailed),window.removeEventListener("icpay-sdk-transaction-mismatched",this.onTransactionMismatched),window.removeEventListener("icpay-sdk-error",this.onSDKError),window.removeEventListener("icpay-sdk-wallet-connected",this.onWalletConnected),window.removeEventListener("icpay-sdk-wallet-disconnected",this.onWalletDisconnected),window.removeEventListener("icpay-sdk-balance-check",this.onBalanceCheck),window.removeEventListener("icpay-sdk-ledger-verified",this.onLedgerVerified),window.removeEventListener("icpay-pay",this.onWidgetPayment),window.removeEventListener("icpay-error",this.onWidgetError),window.removeEventListener("icpay-unlock",this.onWidgetUnlock),window.removeEventListener("icpay-tip",this.onWidgetTip),window.removeEventListener("icpay-donation",this.onWidgetDonation),window.removeEventListener("icpay-coffee",this.onWidgetCoffee)}startAutomaticProgression(){this.progressionTimer&&clearInterval(this.progressionTimer),this.activeIndex=1,this.updateStepStatus(this.activeIndex,"loading"),m(this.debug,"ICPay Progress: Starting automatic progression from step:",this.activeIndex),this.progressionTimer=setInterval(()=>{if(this.failed||this.completed){this.stopAutomaticProgression();return}m(this.debug,"ICPay Progress: Processing step:",this.activeIndex),this.updateStepStatus(this.activeIndex,"completed"),this.activeIndex<this.currentSteps.length-1?(this.activeIndex++,this.updateStepStatus(this.activeIndex,"loading"),m(this.debug,"ICPay Progress: Auto-progressed to step:",this.activeIndex)):(this.stopAutomaticProgression(),m(this.debug,"ICPay Progress: All steps completed, waiting for transaction completion")),this.requestUpdate()},3e3)}stopAutomaticProgression(){this.progressionTimer&&(clearInterval(this.progressionTimer),this.progressionTimer=null)}updateStepStatus(e,t,n){if(e>=0&&e<this.currentSteps.length){let a=this.currentSteps[e],r=a.status;a.status=t,t==="completed"&&(a.timestamp=this.getCurrentTime()),t==="error"&&n&&(a.errorMessage=this.transformErrorMessage(n)),r!==t&&m(this.debug,`ICPay Progress: Step ${e} (${a.label}) status changed from ${r} to ${t}`),this.requestUpdate()}}getCurrentTime(){return new Date().toLocaleTimeString("en-US",{hour12:!1,hour:"2-digit",minute:"2-digit",second:"2-digit"})}getStepIcon(e){return e.status==="error"?N`<div class="error-x">✕</div>`:N`<div class="spinner"></div>`}getStepIndexByKey(e){return this.currentSteps.findIndex(t=>t.key===e)}setLoadingByKey(e){let t=this.getStepIndexByKey(e);t>=0&&(this.activeIndex=t,this.updateStepStatus(t,"loading"),e==="verify"&&(this.confirmLoadingStartedAt=Date.now()))}completeByKey(e){let t=this.getStepIndexByKey(e);t>=0&&(this.updateStepStatus(t,"completed"),this.activeIndex=t)}transformErrorMessage(e){let t=String(e||"").toLowerCase();return t.includes("user rejected")||t.includes("user cancelled")||t.includes("user canceled")||t.includes("signature rejected")?"User have rejected the transfer":e}renderConfetti(){if(!this.showConfetti)return"";let e=Array.from({length:50},(n,a)=>a),t=["#0066FF","#ef4444","#10b981","#f59e0b","#8b5cf6"];return N`
|
|
60
60
|
<div class="confetti">
|
|
61
61
|
${e.map(n=>N`
|
|
62
62
|
<div
|
|
@@ -1029,7 +1029,7 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var H=Xe`
|
|
|
1029
1029
|
${Te({isLoading:i.isLoading,error:i.error,balances:i.balances,onBack:i.onClose,onSelect:i.onSelect})}
|
|
1030
1030
|
</div>
|
|
1031
1031
|
</div>
|
|
1032
|
-
`:null}function U(i){try{let l=i||{};l.adapters=l.adapters||{};let e=l.adapters.oisy||{},t=e.config||{},n={...t.transport||{},windowOpenerFeatures:"",detectNonClickEstablishment:!1};return l.adapters.oisy={...e,config:{...t,transport:n}},l}catch{return i}}function T(i,l){try{let e=l&&(l.owner||l.principal)||null,t=i&&i.account&&(i.account.owner||i.account.principal)||null,n=r=>typeof r=="string"?r:r&&typeof r.toString=="function"?r.toString():null,a=n(e)||n(t)||null;return a?{owner:a,principal:a}:l||{owner:null}}catch{return l||{owner:null}}}async function te(i){try{let l=typeof i?.getEnabledWallets=="function"?i.getEnabledWallets.bind(i):null;if(!l)return null;let t=(l()||[]).find(c=>(c?.id||"").toLowerCase()==="oisy");if(!t||!t.adapter)return null;let n=t.adapter,a=new n({config:i?.config||{}});if(!await a.isConnected())return null;let o=await a.getPrincipal();return o&&o!=="2vxsx-fae"?o:null}catch{return null}}var ze=typeof window<"u",re=null;function ve(i,l,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${l}`,e):console.log(`[ICPay Widget] ${l}`))}var E=class extends ct{constructor(){super(...arguments);this.selectedSymbol=null;this.unlocked=!1;this.succeeded=!1;this.processing=!1;this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.showOnrampModal=!1;this.onrampSessionId=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.transakMessageHandlerBound=null;this.onrampPollTimer=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.showBalanceModal=!1;this.balancesLoading=!1;this.balancesError=null;this.walletBalances=[];this.sdk=null;this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="pay",this.showWalletModal=!0,this.requestUpdate();try{let t=Number(this.config?.priceUsd||0),n=this.selectedSymbol||"ICP";window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"pay",type:"sendUsd",amount:t,currency:n}}))}catch{}}catch{}};this.onSelectBalanceSymbol=e=>{let t=(this.walletBalances||[]).find(a=>a?.tokenShortcode===e);if(t?.ledgerSymbol&&(this.selectedSymbol=t.ledgerSymbol),R(this.lastWalletId)){let a=(this.walletBalances||[]).find(o=>o?.tokenShortcode===e),r=a?.chainId;this.showBalanceModal=!1,this.showWalletModal=!1,V(r,{chainName:a?.chainName,rpcUrlPublic:a?.rpcUrlPublic,nativeSymbol:a?.ledgerSymbol,decimals:a?.decimals}).then(async()=>{try{let o=u(this.config),c=Number(this.config?.priceUsd??0);if(a?.x402Accepts)try{await o.client.createPaymentX402Usd({usdAmount:c,tokenShortcode:a?.tokenShortcode,metadata:{network:"evm",ledgerId:a?.ledgerId,chainId:a?.chainUuid||a?.chainId,context:"premium:x402"}});return}catch{}await o.client.createPaymentUsd({usdAmount:c,tokenShortcode:a?.tokenShortcode,metadata:{network:"evm",ledgerId:a?.ledgerId}})}catch{}});return}this.showBalanceModal=!1,this.showWalletModal=!1;let n=this.pendingAction;this.pendingAction=null,n==="pay"&&setTimeout(()=>this.onPay(),0)}}async tryAutoConnectPNP(){try{if(!this.config||this.config?.useOwnWallet)return;let e=localStorage.getItem("icpay:pnp");if(!e)return;let t=JSON.parse(e);if(!t?.provider||!t?.principal)return;re||(re=(await import("./wallet-select-M5KY6N6N.js")).WalletSelect);let n={...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:r}=await import("./origin-44ZEXSX4.js");n.derivationOrigin=this.config?.derivationOrigin||r()}}catch{}let a=new re(n);this.walletConnected=!1,this.config={...this.config,connectedWallet:{owner:t.principal,principal:t.principal,connected:!1}}}catch{}}connectedCallback(){if(super.connectedCallback(),!!ze){ve(this.config?.debug||!1,"Premium content connected",{config:this.config}),this.tryAutoConnectPNP();try{window.addEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}try{window.addEventListener("icpay-sdk-transaction-created",(()=>{this.showWalletModal=!1,this.showBalanceModal=!1,this.requestUpdate()}))}catch{}}}updated(e){if(e.has("config")&&this.pendingAction&&this.config?.actorProvider){let t=this.pendingAction;this.pendingAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}setTimeout(()=>{t==="pay"&&this.onPay()},0)}}async onPay(){if(ze&&!(this.processing||this.unlocked)){ve(this.config?.debug||!1,"Premium content payment started",{priceUsd:this.config.priceUsd,selectedSymbol:this.selectedSymbol,useOwnWallet:this.config.useOwnWallet}),this.errorMessage=null,this.errorSeverity=null,this.errorAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"pay",type:"sendUsd",amount:this.config.priceUsd,currency:this.selectedSymbol||"ICP"}}))}catch{}this.processing=!0;try{if(this.config.useOwnWallet){if(!this.config.actorProvider){this.pendingAction="pay",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0}));return}}else if(!this.walletConnected){ve(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{re||(re=(await import("./wallet-select-M5KY6N6N.js")).WalletSelect);let t=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab)?U({...this.config?.plugNPlay||{}}):{...this.config?.plugNPlay||{}};this.config?.chainTypes&&(t.chainTypes=this.config.chainTypes);try{if(typeof window<"u"){let{resolveDerivationOrigin:a}=await import("./origin-44ZEXSX4.js");t.derivationOrigin=this.config?.derivationOrigin||a()}}catch{}this.pnp=new re(t);try{let a=await te(this.pnp);if(a){this.walletConnected=!0;let r=T(this.pnp,{owner:a,principal:a,connected:!0}),o=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(c,d)=>this.pnp.getActor({canisterId:c,idl:d,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{}},this.sdk=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"oisy"}}))}catch{}this.onPay();return}}catch{}let n=this.pnp.getEnabledWallets();if(ve(this.config?.debug||!1,"Available wallets",n),!n?.length)throw new Error("No wallets available");this.pendingAction="pay",this.showWalletModal=!0;return}catch(e){ve(this.config?.debug||!1,"Wallet connection error:",e),this.errorMessage=e instanceof Error?e.message:"Wallet connection failed",this.errorSeverity="error";return}}this.showWalletModal=!1,await this.fetchAndShowBalances("pay");return}catch(e){P(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),D(t)&&(this.errorMessage=_(t),this.errorSeverity=F(t),this.errorAction=z(t))}});try{!this.config.useOwnWallet&&this.pnp&&(await this.pnp.disconnect?.(),this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0})}catch{}}finally{this.processing=!1}}}attachTransakMessageListener(){if(!this.transakMessageHandlerBound){this.transakMessageHandlerBound=e=>this.onTransakMessage(e);try{window.addEventListener("message",this.transakMessageHandlerBound)}catch{}}}detachTransakMessageListener(){if(this.transakMessageHandlerBound){try{window.removeEventListener("message",this.transakMessageHandlerBound)}catch{}this.transakMessageHandlerBound=null}}onTransakMessage(e){let t=e?.data,n=t?.event_id||t?.eventId||t?.id;if(!(!n||typeof n!="string")&&n==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let a=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(a||void 0)}}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1,setTimeout(()=>this.createOnrampIntent(),0)}async createOnrampIntent(){try{let e=u(this.config),t=this.selectedSymbol||"ICP",n=await e.startOnrampUsd(this.config.priceUsd,t,{context:"premium:onramp"}),a=n?.metadata?.onramp?.sessionId||n?.metadata?.onramp?.session_id||null,r=n?.metadata?.paymentIntentId||n?.paymentIntentId||null,o=n?.metadata?.onramp?.errorMessage||null;this.onrampPaymentIntentId=r,a?(this.onrampSessionId=a,this.onrampErrorMessage=null,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.onrampErrorMessage=o||"Failed to obtain onramp sessionId",this.showOnrampModal=!0)}catch(e){this.onrampSessionId=null,this.onrampErrorMessage=e?.message||"Failed to obtain onramp sessionId",this.showOnrampModal=!0}}startOnrampPolling(e){if(this.onrampPollTimer){try{clearInterval(this.onrampPollTimer)}catch{}this.onrampPollTimer=null}if(this.onrampNotifyController){try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null}let t=this.onrampPaymentIntentId;if(!t)return;let n=u(this.config),a=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>a()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=n.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}select(e){this.selectedSymbol=e}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");this.lastWalletId=(e||"").toLowerCase(),this.pnp.connect(e).then(n=>{if(!!!(n&&(n.connected===!0||n.principal||n.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}let r=T(this.pnp,n),o=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(d,h)=>this.pnp.getActor({canisterId:d,idl:h,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{}},this.sdk=null,this.lastWalletId==="oisy"?this.oisyReadyToPay=!0:(this.showWalletModal=!1,this.fetchAndShowBalances("pay"))}).catch(n=>{this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}})}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}}}async fetchAndShowBalances(e){try{this.balancesLoading=!0,this.balancesError=null,this.showBalanceModal=!0;let t=u(this.config),{balances:n}=await Y({sdk:t,lastWalletId:this.lastWalletId,connectedWallet:this.config?.connectedWallet,amountUsd:Number(this.config?.priceUsd??0)});this.walletBalances=n,this.pendingAction=e}catch(t){this.walletBalances=[],this.balancesError=t&&(t.message||String(t))||"Failed to load balances"}finally{this.balancesLoading=!1}}render(){return this.config?se`
|
|
1032
|
+
`:null}function U(i){try{let l=i||{};l.adapters=l.adapters||{};let e=l.adapters.oisy||{},t=e.config||{},n={...t.transport||{},windowOpenerFeatures:"",detectNonClickEstablishment:!1};return l.adapters.oisy={...e,config:{...t,transport:n}},l}catch{return i}}function T(i,l){try{let e=l&&(l.owner||l.principal)||null,t=i&&i.account&&(i.account.owner||i.account.principal)||null,n=r=>typeof r=="string"?r:r&&typeof r.toString=="function"?r.toString():null,a=n(e)||n(t)||null;return a?{owner:a,principal:a}:l||{owner:null}}catch{return l||{owner:null}}}async function te(i){try{let l=typeof i?.getEnabledWallets=="function"?i.getEnabledWallets.bind(i):null;if(!l)return null;let t=(l()||[]).find(c=>(c?.id||"").toLowerCase()==="oisy");if(!t||!t.adapter)return null;let n=t.adapter,a=new n({config:i?.config||{}});if(!await a.isConnected())return null;let o=await a.getPrincipal();return o&&o!=="2vxsx-fae"?o:null}catch{return null}}var ze=typeof window<"u",re=null;function ve(i,l,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${l}`,e):console.log(`[ICPay Widget] ${l}`))}var E=class extends ct{constructor(){super(...arguments);this.selectedSymbol=null;this.unlocked=!1;this.succeeded=!1;this.processing=!1;this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.showOnrampModal=!1;this.onrampSessionId=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.transakMessageHandlerBound=null;this.onrampPollTimer=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.showBalanceModal=!1;this.balancesLoading=!1;this.balancesError=null;this.walletBalances=[];this.sdk=null;this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="pay",this.showWalletModal=!0,this.requestUpdate();try{let t=Number(this.config?.priceUsd||0),n=this.selectedSymbol||"ICP";window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"pay",type:"sendUsd",amount:t,currency:n}}))}catch{}}catch{}};this.onSelectBalanceSymbol=e=>{let t=(this.walletBalances||[]).find(a=>a?.tokenShortcode===e);if(t?.ledgerSymbol&&(this.selectedSymbol=t.ledgerSymbol),R(this.lastWalletId)){let a=(this.walletBalances||[]).find(o=>o?.tokenShortcode===e),r=a?.chainId;this.showBalanceModal=!1,this.showWalletModal=!1,V(r,{chainName:a?.chainName,rpcUrlPublic:a?.rpcUrlPublic,nativeSymbol:a?.ledgerSymbol,decimals:a?.decimals}).then(async()=>{try{let o=g(this.config),c=Number(this.config?.priceUsd??0);if(a?.x402Accepts)try{await o.client.createPaymentX402Usd({usdAmount:c,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,network:"evm",ledgerId:a?.ledgerId,chainId:a?.chainUuid||a?.chainId,context:"premium:x402"}});return}catch{}await o.client.createPaymentUsd({usdAmount:c,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,network:"evm",ledgerId:a?.ledgerId}})}catch{}});return}this.showBalanceModal=!1,this.showWalletModal=!1;let n=this.pendingAction;this.pendingAction=null,n==="pay"&&setTimeout(()=>this.onPay(),0)}}async tryAutoConnectPNP(){try{if(!this.config||this.config?.useOwnWallet)return;let e=localStorage.getItem("icpay:pnp");if(!e)return;let t=JSON.parse(e);if(!t?.provider||!t?.principal)return;re||(re=(await import("./wallet-select-M5KY6N6N.js")).WalletSelect);let n={...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:r}=await import("./origin-44ZEXSX4.js");n.derivationOrigin=this.config?.derivationOrigin||r()}}catch{}let a=new re(n);this.walletConnected=!1,this.config={...this.config,connectedWallet:{owner:t.principal,principal:t.principal,connected:!1}}}catch{}}connectedCallback(){if(super.connectedCallback(),!!ze){ve(this.config?.debug||!1,"Premium content connected",{config:this.config}),this.tryAutoConnectPNP();try{window.addEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}try{window.addEventListener("icpay-sdk-transaction-created",(()=>{this.showWalletModal=!1,this.showBalanceModal=!1,this.requestUpdate()}))}catch{}}}updated(e){if(e.has("config")&&this.pendingAction&&this.config?.actorProvider){let t=this.pendingAction;this.pendingAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}setTimeout(()=>{t==="pay"&&this.onPay()},0)}}async onPay(){if(ze&&!(this.processing||this.unlocked)){ve(this.config?.debug||!1,"Premium content payment started",{priceUsd:this.config.priceUsd,selectedSymbol:this.selectedSymbol,useOwnWallet:this.config.useOwnWallet}),this.errorMessage=null,this.errorSeverity=null,this.errorAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"pay",type:"sendUsd",amount:this.config.priceUsd,currency:this.selectedSymbol||"ICP"}}))}catch{}this.processing=!0;try{if(this.config.useOwnWallet){if(!this.config.actorProvider){this.pendingAction="pay",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0}));return}}else if(!this.walletConnected){ve(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{re||(re=(await import("./wallet-select-M5KY6N6N.js")).WalletSelect);let t=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab)?U({...this.config?.plugNPlay||{}}):{...this.config?.plugNPlay||{}};this.config?.chainTypes&&(t.chainTypes=this.config.chainTypes);try{if(typeof window<"u"){let{resolveDerivationOrigin:a}=await import("./origin-44ZEXSX4.js");t.derivationOrigin=this.config?.derivationOrigin||a()}}catch{}this.pnp=new re(t);try{let a=await te(this.pnp);if(a){this.walletConnected=!0;let r=T(this.pnp,{owner:a,principal:a,connected:!0}),o=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(c,d)=>this.pnp.getActor({canisterId:c,idl:d,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{}},this.sdk=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"oisy"}}))}catch{}this.onPay();return}}catch{}let n=this.pnp.getEnabledWallets();if(ve(this.config?.debug||!1,"Available wallets",n),!n?.length)throw new Error("No wallets available");this.pendingAction="pay",this.showWalletModal=!0;return}catch(e){ve(this.config?.debug||!1,"Wallet connection error:",e),this.errorMessage=e instanceof Error?e.message:"Wallet connection failed",this.errorSeverity="error";return}}this.showWalletModal=!1,await this.fetchAndShowBalances("pay");return}catch(e){P(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),D(t)&&(this.errorMessage=_(t),this.errorSeverity=F(t),this.errorAction=z(t))}});try{!this.config.useOwnWallet&&this.pnp&&(await this.pnp.disconnect?.(),this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0})}catch{}}finally{this.processing=!1}}}attachTransakMessageListener(){if(!this.transakMessageHandlerBound){this.transakMessageHandlerBound=e=>this.onTransakMessage(e);try{window.addEventListener("message",this.transakMessageHandlerBound)}catch{}}}detachTransakMessageListener(){if(this.transakMessageHandlerBound){try{window.removeEventListener("message",this.transakMessageHandlerBound)}catch{}this.transakMessageHandlerBound=null}}onTransakMessage(e){let t=e?.data,n=t?.event_id||t?.eventId||t?.id;if(!(!n||typeof n!="string")&&n==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let a=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(a||void 0)}}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1,setTimeout(()=>this.createOnrampIntent(),0)}async createOnrampIntent(){try{let e=g(this.config),t=this.selectedSymbol||"ICP",n=await e.startOnrampUsd(this.config.priceUsd,t,{context:"premium:onramp"}),a=n?.metadata?.onramp?.sessionId||n?.metadata?.onramp?.session_id||null,r=n?.metadata?.paymentIntentId||n?.paymentIntentId||null,o=n?.metadata?.onramp?.errorMessage||null;this.onrampPaymentIntentId=r,a?(this.onrampSessionId=a,this.onrampErrorMessage=null,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.onrampErrorMessage=o||"Failed to obtain onramp sessionId",this.showOnrampModal=!0)}catch(e){this.onrampSessionId=null,this.onrampErrorMessage=e?.message||"Failed to obtain onramp sessionId",this.showOnrampModal=!0}}startOnrampPolling(e){if(this.onrampPollTimer){try{clearInterval(this.onrampPollTimer)}catch{}this.onrampPollTimer=null}if(this.onrampNotifyController){try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null}let t=this.onrampPaymentIntentId;if(!t)return;let n=g(this.config),a=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>a()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=n.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}select(e){this.selectedSymbol=e}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");this.lastWalletId=(e||"").toLowerCase(),this.pnp.connect(e).then(n=>{if(!!!(n&&(n.connected===!0||n.principal||n.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}let r=T(this.pnp,n),o=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(d,h)=>this.pnp.getActor({canisterId:d,idl:h,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{}},this.sdk=null,this.lastWalletId==="oisy"?this.oisyReadyToPay=!0:(this.showWalletModal=!1,this.fetchAndShowBalances("pay"))}).catch(n=>{this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}})}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}}}async fetchAndShowBalances(e){try{this.balancesLoading=!0,this.balancesError=null,this.showBalanceModal=!0;let t=g(this.config),{balances:n}=await Y({sdk:t,lastWalletId:this.lastWalletId,connectedWallet:this.config?.connectedWallet,amountUsd:Number(this.config?.priceUsd??0)});this.walletBalances=n,this.pendingAction=e}catch(t){this.walletBalances=[],this.balancesError=t&&(t.message||String(t))||"Failed to load balances"}finally{this.balancesLoading=!1}}render(){return this.config?se`
|
|
1033
1033
|
<div class="icpay-card icpay-section icpay-widget-base">
|
|
1034
1034
|
${this.config?.progressBar?.enabled!==!1?se`
|
|
1035
1035
|
<icpay-progress-bar
|
|
@@ -1122,7 +1122,7 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var H=Xe`
|
|
|
1122
1122
|
border-color: rgba(239, 68, 68, 0.3);
|
|
1123
1123
|
color: #ef4444;
|
|
1124
1124
|
}
|
|
1125
|
-
`],s([ht({type:Object})],E.prototype,"config",2),s([A()],E.prototype,"selectedSymbol",2),s([A()],E.prototype,"unlocked",2),s([A()],E.prototype,"succeeded",2),s([A()],E.prototype,"processing",2),s([A()],E.prototype,"errorMessage",2),s([A()],E.prototype,"errorSeverity",2),s([A()],E.prototype,"errorAction",2),s([A()],E.prototype,"walletConnected",2),s([A()],E.prototype,"pendingAction",2),s([A()],E.prototype,"showWalletModal",2),s([A()],E.prototype,"oisyReadyToPay",2),s([A()],E.prototype,"lastWalletId",2),s([A()],E.prototype,"showOnrampModal",2),s([A()],E.prototype,"onrampSessionId",2),s([A()],E.prototype,"onrampPaymentIntentId",2),s([A()],E.prototype,"onrampErrorMessage",2),s([A()],E.prototype,"showBalanceModal",2),s([A()],E.prototype,"balancesLoading",2),s([A()],E.prototype,"balancesError",2),s([A()],E.prototype,"walletBalances",2),E=s([pt("icpay-premium-content")],E);import{LitElement as ut,html as le,css as gt}from"lit";import{customElement as mt,property as yt,state as k}from"lit/decorators.js";var Fe=typeof window<"u",ce=null;function be(i,l,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${l}`,e):console.log(`[ICPay Widget] ${l}`))}var v=class extends ut{constructor(){super(...arguments);this.selectedAmount=1;this.selectedSymbol=null;this.total=0;this.processing=!1;this.succeeded=!1;this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.showOnrampModal=!1;this.onrampSessionId=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.transakMessageHandlerBound=null;this.onrampPollTimer=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.sdk=null;this.showBalanceModal=!1;this.balancesLoading=!1;this.balancesError=null;this.walletBalances=[];this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="tip",this.showWalletModal=!0,this.requestUpdate();try{let t=Number(this.selectedAmount||0),n=this.selectedSymbol||"ICP";window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"tip",type:"sendUsd",amount:t,currency:n}}))}catch{}}catch{}};this.onSelectBalanceSymbol=async e=>{let t=(this.walletBalances||[]).find(a=>a?.tokenShortcode===e);if(t?.ledgerSymbol&&(this.selectedSymbol=t.ledgerSymbol),R(this.lastWalletId)){let a=(this.walletBalances||[]).find(o=>o?.tokenShortcode===e),r=a?.chainId;V(r,{chainName:a?.chainName,rpcUrlPublic:a?.rpcUrlPublic,nativeSymbol:a?.ledgerSymbol,decimals:a?.decimals}).then(async()=>{try{let o=u(this.config),c=Number(this.selectedAmount||0);if(a?.x402Accepts)try{await o.client.createPaymentX402Usd({usdAmount:c,tokenShortcode:a?.tokenShortcode,metadata:{network:"evm",ledgerId:a?.ledgerId,chainId:a?.chainUuid,context:"tip:x402"}}),this.showBalanceModal=!1;return}catch{}await o.client.createPaymentUsd({usdAmount:c,tokenShortcode:a?.tokenShortcode,metadata:{network:"evm",ledgerId:a?.ledgerId}})}catch{}this.showBalanceModal=!1});return}this.showBalanceModal=!1;let n=this.pendingAction;if(this.pendingAction=null,n==="tip")try{let a=(this.walletBalances||[]).find(c=>c?.tokenShortcode===e),r=u(this.config),o=Number(this.selectedAmount||0);await r.client.createPaymentUsd({usdAmount:o,tokenShortcode:a?.tokenShortcode,metadata:{network:"ic",ledgerId:a?.ledgerId}})}catch{}}}async tryAutoConnectPNP(){try{if(!this.config||this.config?.useOwnWallet)return;let e=localStorage.getItem("icpay:pnp");if(!e)return;let t=JSON.parse(e);if(!t?.provider||!t?.principal)return;ce||(ce=(await import("./wallet-select-M5KY6N6N.js")).WalletSelect);let n=U({...this.config?.plugNPlay||{}});try{if(typeof window<"u"){let{resolveDerivationOrigin:r}=await import("./origin-44ZEXSX4.js");n.derivationOrigin=this.config?.derivationOrigin||r()}}catch{}let a=new ce(n);this.walletConnected=!1,this.config={...this.config,connectedWallet:{owner:t.principal,principal:t.principal,connected:!1}}}catch{}}get amounts(){return this.config?.amountsUsd||[1,5,10]}connectedCallback(){if(super.connectedCallback(),!!Fe){be(this.config?.debug||!1,"Tip jar connected",{config:this.config}),this.config&&this.config.defaultAmountUsd&&(this.selectedAmount=this.config.defaultAmountUsd),this.tryAutoConnectPNP();try{window.addEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}try{window.addEventListener("icpay-sdk-transaction-created",(()=>{this.showWalletModal=!1,this.requestUpdate()}))}catch{}}}updated(e){if(e.has("config")&&this.pendingAction&&this.config?.actorProvider){let t=this.pendingAction;this.pendingAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}setTimeout(()=>{t==="tip"&&this.tip()},0)}}selectAmount(e){this.selectedAmount=e}selectSymbol(e){this.selectedSymbol=e}get fillPercentage(){return Math.min(this.total/50*100,100)}async tip(){if(Fe&&(be(this.config?.debug||!1,"Tip button clicked!",{config:this.config,processing:this.processing}),!this.processing)){this.errorMessage=null,this.errorSeverity=null,this.errorAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"tip",type:"sendUsd",amount:this.selectedAmount,currency:this.selectedSymbol||"ICP"}}))}catch{}this.processing=!0;try{if(this.config.useOwnWallet){if(!this.config.actorProvider){this.pendingAction="tip",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0}));return}}else if(!this.walletConnected){be(this.config?.debug||!1,"Connecting to wallet via wallet");try{ce||(ce=(await import("./wallet-select-M5KY6N6N.js")).WalletSelect);let t=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab)?U({...this.config?.plugNPlay||{}}):{...this.config?.plugNPlay||{}};this.config?.chainTypes&&(t.chainTypes=this.config.chainTypes);try{if(typeof window<"u"){let{resolveDerivationOrigin:a}=await import("./origin-44ZEXSX4.js");t.derivationOrigin=this.config?.derivationOrigin||a()}}catch{}this.pnp=new ce(t);try{let a=await te(this.pnp);if(a){this.walletConnected=!0;let r=T(this.pnp,{owner:a,principal:a,connected:!0}),o=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(c,d)=>this.pnp.getActor({canisterId:c,idl:d,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{}},this.sdk=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"oisy"}}))}catch{}this.tip();return}}catch{}let n=this.pnp.getEnabledWallets();if(be(this.config?.debug||!1,"Available wallets",n),!n?.length)throw new Error("No wallets available");this.pendingAction="tip",this.showWalletModal=!0;return}catch(e){be(this.config?.debug||!1,"Wallet connection error:",e),this.errorMessage=e instanceof Error?e.message:"Wallet connection failed",this.errorSeverity="error";return}}this.showWalletModal=!0,await this.fetchAndShowBalances();return}catch(e){P(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),D(t)&&(this.errorMessage=_(t),this.errorSeverity=F(t),this.errorAction=z(t))}});try{!this.config.useOwnWallet&&this.pnp&&(await this.pnp.disconnect?.(),this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0})}catch{}}finally{this.processing=!1}}}attachTransakMessageListener(){if(!this.transakMessageHandlerBound){this.transakMessageHandlerBound=e=>this.onTransakMessage(e);try{window.addEventListener("message",this.transakMessageHandlerBound)}catch{}}}detachTransakMessageListener(){if(this.transakMessageHandlerBound){try{window.removeEventListener("message",this.transakMessageHandlerBound)}catch{}this.transakMessageHandlerBound=null}}onTransakMessage(e){let t=e?.data,n=t?.event_id||t?.eventId||t?.id;if(!(!n||typeof n!="string")&&n==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let a=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(a||void 0)}}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1,setTimeout(()=>this.createOnrampIntent(),0)}async createOnrampIntent(){try{let e=u(this.config),t=this.selectedSymbol||"ICP",n=await e.startOnrampUsd(this.selectedAmount,t,{context:"tip:onramp"}),a=n?.metadata?.onramp?.sessionId||n?.metadata?.onramp?.session_id||null,r=n?.metadata?.paymentIntentId||n?.paymentIntentId||null,o=n?.metadata?.onramp?.errorMessage||null;this.onrampPaymentIntentId=r,a?(this.onrampSessionId=a,this.onrampErrorMessage=null,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.onrampErrorMessage=o||"Failed to obtain onramp sessionId",this.showOnrampModal=!0)}catch(e){this.onrampSessionId=null,this.onrampErrorMessage=e?.message||"Failed to obtain onramp sessionId",this.showOnrampModal=!0}}startOnrampPolling(e){if(this.onrampPollTimer){try{clearInterval(this.onrampPollTimer)}catch{}this.onrampPollTimer=null}if(this.onrampNotifyController){try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null}let t=this.onrampPaymentIntentId;if(!t)return;let n=u(this.config),a=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>a()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=n.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");this.lastWalletId=(e||"").toLowerCase(),this.pnp.connect(e).then(n=>{if(!!!(n&&(n.connected===!0||n.principal||n.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}let r=T(this.pnp,n),o=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(d,h)=>this.pnp.getActor({canisterId:d,idl:h,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{}},this.sdk=null,this.lastWalletId==="oisy"?this.oisyReadyToPay=!0:(this.showWalletModal=!1,this.fetchAndShowBalances())}).catch(n=>{this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}})}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}}}async fetchAndShowBalances(){try{this.balancesLoading=!0,this.balancesError=null,this.showBalanceModal=!0;let e=u(this.config),{balances:t}=await Y({sdk:e,lastWalletId:this.lastWalletId,connectedWallet:this.config?.connectedWallet,amountUsd:Number(this.selectedAmount||0),chainShortcodes:this.config?.chainShortcodes,tokenShortcodes:this.config?.tokenShortcodes});this.walletBalances=t}catch(e){this.walletBalances=[],this.balancesError=e&&(e.message||String(e))||"Failed to load balances"}finally{this.balancesLoading=!1}}render(){return this.config?le`
|
|
1125
|
+
`],s([ht({type:Object})],E.prototype,"config",2),s([A()],E.prototype,"selectedSymbol",2),s([A()],E.prototype,"unlocked",2),s([A()],E.prototype,"succeeded",2),s([A()],E.prototype,"processing",2),s([A()],E.prototype,"errorMessage",2),s([A()],E.prototype,"errorSeverity",2),s([A()],E.prototype,"errorAction",2),s([A()],E.prototype,"walletConnected",2),s([A()],E.prototype,"pendingAction",2),s([A()],E.prototype,"showWalletModal",2),s([A()],E.prototype,"oisyReadyToPay",2),s([A()],E.prototype,"lastWalletId",2),s([A()],E.prototype,"showOnrampModal",2),s([A()],E.prototype,"onrampSessionId",2),s([A()],E.prototype,"onrampPaymentIntentId",2),s([A()],E.prototype,"onrampErrorMessage",2),s([A()],E.prototype,"showBalanceModal",2),s([A()],E.prototype,"balancesLoading",2),s([A()],E.prototype,"balancesError",2),s([A()],E.prototype,"walletBalances",2),E=s([pt("icpay-premium-content")],E);import{LitElement as gt,html as le,css as ut}from"lit";import{customElement as mt,property as yt,state as k}from"lit/decorators.js";var Fe=typeof window<"u",ce=null;function be(i,l,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${l}`,e):console.log(`[ICPay Widget] ${l}`))}var v=class extends gt{constructor(){super(...arguments);this.selectedAmount=1;this.selectedSymbol=null;this.total=0;this.processing=!1;this.succeeded=!1;this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.showOnrampModal=!1;this.onrampSessionId=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.transakMessageHandlerBound=null;this.onrampPollTimer=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.sdk=null;this.showBalanceModal=!1;this.balancesLoading=!1;this.balancesError=null;this.walletBalances=[];this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="tip",this.showWalletModal=!0,this.requestUpdate();try{let t=Number(this.selectedAmount||0),n=this.selectedSymbol||"ICP";window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"tip",type:"sendUsd",amount:t,currency:n}}))}catch{}}catch{}};this.onSelectBalanceSymbol=async e=>{let t=(this.walletBalances||[]).find(a=>a?.tokenShortcode===e);if(t?.ledgerSymbol&&(this.selectedSymbol=t.ledgerSymbol),R(this.lastWalletId)){let a=(this.walletBalances||[]).find(o=>o?.tokenShortcode===e),r=a?.chainId;V(r,{chainName:a?.chainName,rpcUrlPublic:a?.rpcUrlPublic,nativeSymbol:a?.ledgerSymbol,decimals:a?.decimals}).then(async()=>{try{let o=g(this.config),c=Number(this.selectedAmount||0);if(a?.x402Accepts)try{await o.client.createPaymentX402Usd({usdAmount:c,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,network:"evm",ledgerId:a?.ledgerId,chainId:a?.chainUuid,context:"tip:x402"}}),this.showBalanceModal=!1;return}catch{}await o.client.createPaymentUsd({usdAmount:c,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,network:"evm",ledgerId:a?.ledgerId}})}catch{}this.showBalanceModal=!1});return}this.showBalanceModal=!1;let n=this.pendingAction;if(this.pendingAction=null,n==="tip")try{let a=(this.walletBalances||[]).find(c=>c?.tokenShortcode===e),r=g(this.config),o=Number(this.selectedAmount||0);await r.client.createPaymentUsd({usdAmount:o,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,network:"ic",ledgerId:a?.ledgerId}})}catch{}}}async tryAutoConnectPNP(){try{if(!this.config||this.config?.useOwnWallet)return;let e=localStorage.getItem("icpay:pnp");if(!e)return;let t=JSON.parse(e);if(!t?.provider||!t?.principal)return;ce||(ce=(await import("./wallet-select-M5KY6N6N.js")).WalletSelect);let n=U({...this.config?.plugNPlay||{}});try{if(typeof window<"u"){let{resolveDerivationOrigin:r}=await import("./origin-44ZEXSX4.js");n.derivationOrigin=this.config?.derivationOrigin||r()}}catch{}let a=new ce(n);this.walletConnected=!1,this.config={...this.config,connectedWallet:{owner:t.principal,principal:t.principal,connected:!1}}}catch{}}get amounts(){return this.config?.amountsUsd||[1,5,10]}connectedCallback(){if(super.connectedCallback(),!!Fe){be(this.config?.debug||!1,"Tip jar connected",{config:this.config}),this.config&&this.config.defaultAmountUsd&&(this.selectedAmount=this.config.defaultAmountUsd),this.tryAutoConnectPNP();try{window.addEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}try{window.addEventListener("icpay-sdk-transaction-created",(()=>{this.showWalletModal=!1,this.requestUpdate()}))}catch{}}}updated(e){if(e.has("config")&&this.pendingAction&&this.config?.actorProvider){let t=this.pendingAction;this.pendingAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}setTimeout(()=>{t==="tip"&&this.tip()},0)}}selectAmount(e){this.selectedAmount=e}selectSymbol(e){this.selectedSymbol=e}get fillPercentage(){return Math.min(this.total/50*100,100)}async tip(){if(Fe&&(be(this.config?.debug||!1,"Tip button clicked!",{config:this.config,processing:this.processing}),!this.processing)){this.errorMessage=null,this.errorSeverity=null,this.errorAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"tip",type:"sendUsd",amount:this.selectedAmount,currency:this.selectedSymbol||"ICP"}}))}catch{}this.processing=!0;try{if(this.config.useOwnWallet){if(!this.config.actorProvider){this.pendingAction="tip",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0}));return}}else if(!this.walletConnected){be(this.config?.debug||!1,"Connecting to wallet via wallet");try{ce||(ce=(await import("./wallet-select-M5KY6N6N.js")).WalletSelect);let t=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab)?U({...this.config?.plugNPlay||{}}):{...this.config?.plugNPlay||{}};this.config?.chainTypes&&(t.chainTypes=this.config.chainTypes);try{if(typeof window<"u"){let{resolveDerivationOrigin:a}=await import("./origin-44ZEXSX4.js");t.derivationOrigin=this.config?.derivationOrigin||a()}}catch{}this.pnp=new ce(t);try{let a=await te(this.pnp);if(a){this.walletConnected=!0;let r=T(this.pnp,{owner:a,principal:a,connected:!0}),o=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(c,d)=>this.pnp.getActor({canisterId:c,idl:d,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{}},this.sdk=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"oisy"}}))}catch{}this.tip();return}}catch{}let n=this.pnp.getEnabledWallets();if(be(this.config?.debug||!1,"Available wallets",n),!n?.length)throw new Error("No wallets available");this.pendingAction="tip",this.showWalletModal=!0;return}catch(e){be(this.config?.debug||!1,"Wallet connection error:",e),this.errorMessage=e instanceof Error?e.message:"Wallet connection failed",this.errorSeverity="error";return}}this.showWalletModal=!0,await this.fetchAndShowBalances();return}catch(e){P(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),D(t)&&(this.errorMessage=_(t),this.errorSeverity=F(t),this.errorAction=z(t))}});try{!this.config.useOwnWallet&&this.pnp&&(await this.pnp.disconnect?.(),this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0})}catch{}}finally{this.processing=!1}}}attachTransakMessageListener(){if(!this.transakMessageHandlerBound){this.transakMessageHandlerBound=e=>this.onTransakMessage(e);try{window.addEventListener("message",this.transakMessageHandlerBound)}catch{}}}detachTransakMessageListener(){if(this.transakMessageHandlerBound){try{window.removeEventListener("message",this.transakMessageHandlerBound)}catch{}this.transakMessageHandlerBound=null}}onTransakMessage(e){let t=e?.data,n=t?.event_id||t?.eventId||t?.id;if(!(!n||typeof n!="string")&&n==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let a=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(a||void 0)}}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1,setTimeout(()=>this.createOnrampIntent(),0)}async createOnrampIntent(){try{let e=g(this.config),t=this.selectedSymbol||"ICP",n=await e.startOnrampUsd(this.selectedAmount,t,{context:"tip:onramp"}),a=n?.metadata?.onramp?.sessionId||n?.metadata?.onramp?.session_id||null,r=n?.metadata?.paymentIntentId||n?.paymentIntentId||null,o=n?.metadata?.onramp?.errorMessage||null;this.onrampPaymentIntentId=r,a?(this.onrampSessionId=a,this.onrampErrorMessage=null,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.onrampErrorMessage=o||"Failed to obtain onramp sessionId",this.showOnrampModal=!0)}catch(e){this.onrampSessionId=null,this.onrampErrorMessage=e?.message||"Failed to obtain onramp sessionId",this.showOnrampModal=!0}}startOnrampPolling(e){if(this.onrampPollTimer){try{clearInterval(this.onrampPollTimer)}catch{}this.onrampPollTimer=null}if(this.onrampNotifyController){try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null}let t=this.onrampPaymentIntentId;if(!t)return;let n=g(this.config),a=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>a()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=n.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");this.lastWalletId=(e||"").toLowerCase(),this.pnp.connect(e).then(n=>{if(!!!(n&&(n.connected===!0||n.principal||n.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}let r=T(this.pnp,n),o=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(d,h)=>this.pnp.getActor({canisterId:d,idl:h,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{}},this.sdk=null,this.lastWalletId==="oisy"?this.oisyReadyToPay=!0:(this.showWalletModal=!1,this.fetchAndShowBalances())}).catch(n=>{this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}})}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}}}async fetchAndShowBalances(){try{this.balancesLoading=!0,this.balancesError=null,this.showBalanceModal=!0;let e=g(this.config),{balances:t}=await Y({sdk:e,lastWalletId:this.lastWalletId,connectedWallet:this.config?.connectedWallet,amountUsd:Number(this.selectedAmount||0),chainShortcodes:this.config?.chainShortcodes,tokenShortcodes:this.config?.tokenShortcodes});this.walletBalances=t}catch(e){this.walletBalances=[],this.balancesError=e&&(e.message||String(e))||"Failed to load balances"}finally{this.balancesLoading=!1}}render(){return this.config?le`
|
|
1126
1126
|
<div class="icpay-card icpay-section icpay-widget-base" style="text-align:center;">
|
|
1127
1127
|
${this.config?.progressBar?.enabled!==!1?le`
|
|
1128
1128
|
<icpay-progress-bar
|
|
@@ -1163,7 +1163,7 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var H=Xe`
|
|
|
1163
1163
|
|
|
1164
1164
|
${this.showOnrampModal?q({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}
|
|
1165
1165
|
</div>
|
|
1166
|
-
`:le`<div class="icpay-card icpay-section">Loading...</div>`}};v.styles=[H,
|
|
1166
|
+
`:le`<div class="icpay-card icpay-section">Loading...</div>`}};v.styles=[H,ut`
|
|
1167
1167
|
.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; }
|
|
1168
1168
|
.fill { position: absolute; bottom: 0; left: 0; right: 0; background: linear-gradient(135deg, #d1d5db 0%, #9ca3af 100%); transition: height 0.8s ease; height: 0%; }
|
|
1169
1169
|
.amounts { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; margin: 12px 0; }
|
|
@@ -1195,7 +1195,7 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var H=Xe`
|
|
|
1195
1195
|
border-color: rgba(239, 68, 68, 0.3);
|
|
1196
1196
|
color: #ef4444;
|
|
1197
1197
|
}
|
|
1198
|
-
`],s([yt({type:Object})],v.prototype,"config",2),s([k()],v.prototype,"selectedAmount",2),s([k()],v.prototype,"selectedSymbol",2),s([k()],v.prototype,"total",2),s([k()],v.prototype,"processing",2),s([k()],v.prototype,"succeeded",2),s([k()],v.prototype,"errorMessage",2),s([k()],v.prototype,"errorSeverity",2),s([k()],v.prototype,"errorAction",2),s([k()],v.prototype,"walletConnected",2),s([k()],v.prototype,"pendingAction",2),s([k()],v.prototype,"showWalletModal",2),s([k()],v.prototype,"oisyReadyToPay",2),s([k()],v.prototype,"lastWalletId",2),s([k()],v.prototype,"showOnrampModal",2),s([k()],v.prototype,"onrampSessionId",2),s([k()],v.prototype,"onrampPaymentIntentId",2),s([k()],v.prototype,"onrampErrorMessage",2),s([k()],v.prototype,"showBalanceModal",2),s([k()],v.prototype,"balancesLoading",2),s([k()],v.prototype,"balancesError",2),s([k()],v.prototype,"walletBalances",2),v=s([mt("icpay-tip-jar")],v);import{LitElement as ft,html as we,css as vt}from"lit";import{customElement as bt,property as Ae,state as I}from"lit/decorators.js";var Ke=typeof window<"u",de=null;function Ee(i,l,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${l}`,e):console.log(`[ICPay Widget] ${l}`))}var g=class extends ft{constructor(){super(...arguments);this.title="Article Title";this.preview="";this.lockedContent="";this.selectedSymbol=null;this.unlocked=!1;this.succeeded=!1;this.processing=!1;this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.showOnrampModal=!1;this.onrampSessionId=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.transakMessageHandlerBound=null;this.onrampPollTimer=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.showBalanceModal=!1;this.balancesLoading=!1;this.balancesError=null;this.walletBalances=[];this.sdk=null;this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="unlock",this.showWalletModal=!0,this.requestUpdate();try{let t=Number(this.config?.priceUsd||0),n=this.selectedSymbol||"ICP";window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"unlock",type:"sendUsd",amount:t,currency:n}}))}catch{}}catch{}};this.onSelectBalanceSymbol=async e=>{let t=(this.walletBalances||[]).find(a=>a?.tokenShortcode===e);if(t?.ledgerSymbol&&(this.selectedSymbol=t.ledgerSymbol),R(this.lastWalletId)){let a=(this.walletBalances||[]).find(o=>o?.tokenShortcode===e),r=a?.chainId;this.showBalanceModal=!1,this.showWalletModal=!1,V(r,{chainName:a?.chainName,rpcUrlPublic:a?.rpcUrlPublic,nativeSymbol:a?.ledgerSymbol,decimals:a?.decimals}).then(async()=>{try{let o=u(this.config),c=Number(this.config?.priceUsd??0);if(a?.x402Accepts)try{await o.client.createPaymentX402Usd({usdAmount:c,tokenShortcode:a?.tokenShortcode,metadata:{network:"evm",ledgerId:a?.ledgerId,chainId:a?.chainUuid,context:"article:x402"}});return}catch{}await o.client.createPaymentUsd({usdAmount:c,tokenShortcode:a?.tokenShortcode,metadata:{network:"evm",ledgerId:a?.ledgerId}})}catch{}});return}this.showBalanceModal=!1,this.showWalletModal=!1;let n=this.pendingAction;if(this.pendingAction=null,n==="unlock")try{let a=(this.walletBalances||[]).find(c=>c?.tokenShortcode===e),r=u(this.config),o=Number(this.config?.priceUsd??0);await r.client.createPaymentUsd({usdAmount:o,tokenShortcode:a?.tokenShortcode,metadata:{network:"ic",ledgerId:a?.ledgerId}})}catch{}}}get obfuscatedLockedContent(){try{return(this.lockedContent||"").replace(/[^\s]/g,"x")}catch{return"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}}async tryAutoConnectPNP(){try{if(!this.config||this.config?.useOwnWallet)return;let e=localStorage.getItem("icpay:pnp");if(!e)return;let t=JSON.parse(e);if(!t?.provider||!t?.principal)return;de||(de=(await import("./wallet-select-M5KY6N6N.js")).WalletSelect);let n={...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:r}=await import("./origin-44ZEXSX4.js");n.derivationOrigin=this.config?.derivationOrigin||r()}}catch{}let a=new de(n);this.walletConnected=!1,this.config={...this.config,connectedWallet:{owner:t.principal,principal:t.principal,connected:!1}}}catch{}}attachTransakMessageListener(){if(!this.transakMessageHandlerBound){this.transakMessageHandlerBound=e=>this.onTransakMessage(e);try{window.addEventListener("message",this.transakMessageHandlerBound)}catch{}}}detachTransakMessageListener(){if(this.transakMessageHandlerBound){try{window.removeEventListener("message",this.transakMessageHandlerBound)}catch{}this.transakMessageHandlerBound=null}}onTransakMessage(e){let t=e?.data,n=t?.event_id||t?.eventId||t?.id;if(!(!n||typeof n!="string")&&n==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let a=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(a||void 0)}}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1,setTimeout(()=>this.createOnrampIntent(),0)}async createOnrampIntent(){try{let e=u(this.config),t=this.selectedSymbol||"ICP",n=await e.startOnrampUsd(this.config.priceUsd,t,{context:"article:onramp"}),a=n?.metadata?.onramp?.sessionId||n?.metadata?.onramp?.session_id||null,r=n?.metadata?.paymentIntentId||n?.paymentIntentId||null,o=n?.metadata?.onramp?.errorMessage||null;this.onrampPaymentIntentId=r,a?(this.onrampSessionId=a,this.onrampErrorMessage=null,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.onrampErrorMessage=o||"Failed to obtain onramp sessionId",this.showOnrampModal=!0)}catch(e){this.onrampSessionId=null,this.onrampErrorMessage=e?.message||"Failed to obtain onramp sessionId",this.showOnrampModal=!0}}startOnrampPolling(e){if(this.onrampPollTimer){try{clearInterval(this.onrampPollTimer)}catch{}this.onrampPollTimer=null}if(this.onrampNotifyController){try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null}let t=this.onrampPaymentIntentId;if(!t)return;let n=u(this.config),a=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>a()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=n.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}connectedCallback(){if(super.connectedCallback(),!!Ke){Ee(this.config?.debug||!1,"Article paywall connected",{config:this.config}),this.config&&(typeof this.config.title=="string"&&(this.title=this.config.title),typeof this.config.preview=="string"&&(this.preview=this.config.preview),typeof this.config.lockedContent=="string"&&(this.lockedContent=this.config.lockedContent)),this.tryAutoConnectPNP();try{window.addEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}}}updated(e){if(e.has("config")&&this.config&&(typeof this.config.title=="string"&&(this.title=this.config.title),typeof this.config.preview=="string"&&(this.preview=this.config.preview),typeof this.config.lockedContent=="string"&&(this.lockedContent=this.config.lockedContent)),e.has("config")&&this.pendingAction&&this.config?.actorProvider){let t=this.pendingAction;this.pendingAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}setTimeout(()=>{t==="unlock"&&this.unlock()},0)}}selectSymbol(e){this.selectedSymbol=e}async unlock(){if(Ke&&!(this.processing||this.unlocked)){Ee(this.config?.debug||!1,"Article paywall unlock started",{priceUsd:this.config.priceUsd,selectedSymbol:this.selectedSymbol,useOwnWallet:this.config.useOwnWallet}),this.errorMessage=null,this.errorSeverity=null,this.errorAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"unlock",type:"sendUsd",amount:this.config.priceUsd,currency:this.selectedSymbol||"ICP"}}))}catch{}this.processing=!0;try{if(this.config.useOwnWallet){if(!this.config.actorProvider){this.pendingAction="unlock",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0}));return}}else if(!this.walletConnected){Ee(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{de||(de=(await import("./wallet-select-M5KY6N6N.js")).WalletSelect);let t=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab)?U({...this.config?.plugNPlay||{}}):{...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:a}=await import("./origin-44ZEXSX4.js");t.derivationOrigin=this.config?.derivationOrigin||a()}}catch{}this.pnp=new de(t);try{let a=await te(this.pnp);if(a){this.walletConnected=!0;let r=T(this.pnp,{owner:a,principal:a,connected:!0}),o=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(c,d)=>this.pnp.getActor({canisterId:c,idl:d,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{}},this.sdk=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"oisy"}}))}catch{}this.unlock();return}}catch{}let n=this.pnp.getEnabledWallets();if(Ee(this.config?.debug||!1,"Available wallets",n),!n?.length)throw new Error("No wallets available");this.pendingAction="unlock",this.showWalletModal=!0;return}catch(e){Ee(this.config?.debug||!1,"Wallet connection error:",e),this.errorMessage=e instanceof Error?e.message:"Wallet connection failed",this.errorSeverity="error";return}}this.showWalletModal=!1,await this.fetchAndShowBalances();return}catch(e){P(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),D(t)&&(this.errorMessage=_(t),this.errorSeverity=F(t),this.errorAction=z(t))}});try{!this.config.useOwnWallet&&this.pnp&&(await this.pnp.disconnect?.(),this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0})}catch{}}finally{this.processing=!1}}}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");this.lastWalletId=(e||"").toLowerCase(),this.pnp.connect(e).then(n=>{if(!!!(n&&(n.connected===!0||n.principal||n.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}let r=T(this.pnp,n),o=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(d,h)=>this.pnp.getActor({canisterId:d,idl:h,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{}},this.sdk=null,this.lastWalletId==="oisy"?this.oisyReadyToPay=!0:(this.showWalletModal=!1,this.fetchAndShowBalances())}).catch(n=>{this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}})}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}}}async fetchAndShowBalances(){try{this.balancesLoading=!0,this.balancesError=null,this.showBalanceModal=!0;let e=u(this.config),{balances:t}=await Y({sdk:e,lastWalletId:this.lastWalletId,connectedWallet:this.config?.connectedWallet,amountUsd:Number(this.config?.priceUsd??0),chainShortcodes:this.config?.chainShortcodes,tokenShortcodes:this.config?.tokenShortcodes});this.walletBalances=t}catch(e){this.walletBalances=[],this.balancesError=e&&(e.message||String(e))||"Failed to load balances"}finally{this.balancesLoading=!1}}render(){return this.config?we`
|
|
1198
|
+
`],s([yt({type:Object})],v.prototype,"config",2),s([k()],v.prototype,"selectedAmount",2),s([k()],v.prototype,"selectedSymbol",2),s([k()],v.prototype,"total",2),s([k()],v.prototype,"processing",2),s([k()],v.prototype,"succeeded",2),s([k()],v.prototype,"errorMessage",2),s([k()],v.prototype,"errorSeverity",2),s([k()],v.prototype,"errorAction",2),s([k()],v.prototype,"walletConnected",2),s([k()],v.prototype,"pendingAction",2),s([k()],v.prototype,"showWalletModal",2),s([k()],v.prototype,"oisyReadyToPay",2),s([k()],v.prototype,"lastWalletId",2),s([k()],v.prototype,"showOnrampModal",2),s([k()],v.prototype,"onrampSessionId",2),s([k()],v.prototype,"onrampPaymentIntentId",2),s([k()],v.prototype,"onrampErrorMessage",2),s([k()],v.prototype,"showBalanceModal",2),s([k()],v.prototype,"balancesLoading",2),s([k()],v.prototype,"balancesError",2),s([k()],v.prototype,"walletBalances",2),v=s([mt("icpay-tip-jar")],v);import{LitElement as ft,html as we,css as vt}from"lit";import{customElement as bt,property as Ae,state as I}from"lit/decorators.js";var Ke=typeof window<"u",de=null;function Ee(i,l,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${l}`,e):console.log(`[ICPay Widget] ${l}`))}var u=class extends ft{constructor(){super(...arguments);this.title="Article Title";this.preview="";this.lockedContent="";this.selectedSymbol=null;this.unlocked=!1;this.succeeded=!1;this.processing=!1;this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.showOnrampModal=!1;this.onrampSessionId=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.transakMessageHandlerBound=null;this.onrampPollTimer=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.showBalanceModal=!1;this.balancesLoading=!1;this.balancesError=null;this.walletBalances=[];this.sdk=null;this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="unlock",this.showWalletModal=!0,this.requestUpdate();try{let t=Number(this.config?.priceUsd||0),n=this.selectedSymbol||"ICP";window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"unlock",type:"sendUsd",amount:t,currency:n}}))}catch{}}catch{}};this.onSelectBalanceSymbol=async e=>{let t=(this.walletBalances||[]).find(a=>a?.tokenShortcode===e);if(t?.ledgerSymbol&&(this.selectedSymbol=t.ledgerSymbol),R(this.lastWalletId)){let a=(this.walletBalances||[]).find(o=>o?.tokenShortcode===e),r=a?.chainId;this.showBalanceModal=!1,this.showWalletModal=!1,V(r,{chainName:a?.chainName,rpcUrlPublic:a?.rpcUrlPublic,nativeSymbol:a?.ledgerSymbol,decimals:a?.decimals}).then(async()=>{try{let o=g(this.config),c=Number(this.config?.priceUsd??0);if(a?.x402Accepts)try{await o.client.createPaymentX402Usd({usdAmount:c,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,network:"evm",ledgerId:a?.ledgerId,chainId:a?.chainUuid,context:"article:x402"}});return}catch{}await o.client.createPaymentUsd({usdAmount:c,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,network:"evm",ledgerId:a?.ledgerId}})}catch{}});return}this.showBalanceModal=!1,this.showWalletModal=!1;let n=this.pendingAction;if(this.pendingAction=null,n==="unlock")try{let a=(this.walletBalances||[]).find(c=>c?.tokenShortcode===e),r=g(this.config),o=Number(this.config?.priceUsd??0);await r.client.createPaymentUsd({usdAmount:o,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,network:"ic",ledgerId:a?.ledgerId}})}catch{}}}get obfuscatedLockedContent(){try{return(this.lockedContent||"").replace(/[^\s]/g,"x")}catch{return"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}}async tryAutoConnectPNP(){try{if(!this.config||this.config?.useOwnWallet)return;let e=localStorage.getItem("icpay:pnp");if(!e)return;let t=JSON.parse(e);if(!t?.provider||!t?.principal)return;de||(de=(await import("./wallet-select-M5KY6N6N.js")).WalletSelect);let n={...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:r}=await import("./origin-44ZEXSX4.js");n.derivationOrigin=this.config?.derivationOrigin||r()}}catch{}let a=new de(n);this.walletConnected=!1,this.config={...this.config,connectedWallet:{owner:t.principal,principal:t.principal,connected:!1}}}catch{}}attachTransakMessageListener(){if(!this.transakMessageHandlerBound){this.transakMessageHandlerBound=e=>this.onTransakMessage(e);try{window.addEventListener("message",this.transakMessageHandlerBound)}catch{}}}detachTransakMessageListener(){if(this.transakMessageHandlerBound){try{window.removeEventListener("message",this.transakMessageHandlerBound)}catch{}this.transakMessageHandlerBound=null}}onTransakMessage(e){let t=e?.data,n=t?.event_id||t?.eventId||t?.id;if(!(!n||typeof n!="string")&&n==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let a=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(a||void 0)}}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1,setTimeout(()=>this.createOnrampIntent(),0)}async createOnrampIntent(){try{let e=g(this.config),t=this.selectedSymbol||"ICP",n=await e.startOnrampUsd(this.config.priceUsd,t,{context:"article:onramp"}),a=n?.metadata?.onramp?.sessionId||n?.metadata?.onramp?.session_id||null,r=n?.metadata?.paymentIntentId||n?.paymentIntentId||null,o=n?.metadata?.onramp?.errorMessage||null;this.onrampPaymentIntentId=r,a?(this.onrampSessionId=a,this.onrampErrorMessage=null,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.onrampErrorMessage=o||"Failed to obtain onramp sessionId",this.showOnrampModal=!0)}catch(e){this.onrampSessionId=null,this.onrampErrorMessage=e?.message||"Failed to obtain onramp sessionId",this.showOnrampModal=!0}}startOnrampPolling(e){if(this.onrampPollTimer){try{clearInterval(this.onrampPollTimer)}catch{}this.onrampPollTimer=null}if(this.onrampNotifyController){try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null}let t=this.onrampPaymentIntentId;if(!t)return;let n=g(this.config),a=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>a()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=n.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}connectedCallback(){if(super.connectedCallback(),!!Ke){Ee(this.config?.debug||!1,"Article paywall connected",{config:this.config}),this.config&&(typeof this.config.title=="string"&&(this.title=this.config.title),typeof this.config.preview=="string"&&(this.preview=this.config.preview),typeof this.config.lockedContent=="string"&&(this.lockedContent=this.config.lockedContent)),this.tryAutoConnectPNP();try{window.addEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}}}updated(e){if(e.has("config")&&this.config&&(typeof this.config.title=="string"&&(this.title=this.config.title),typeof this.config.preview=="string"&&(this.preview=this.config.preview),typeof this.config.lockedContent=="string"&&(this.lockedContent=this.config.lockedContent)),e.has("config")&&this.pendingAction&&this.config?.actorProvider){let t=this.pendingAction;this.pendingAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}setTimeout(()=>{t==="unlock"&&this.unlock()},0)}}selectSymbol(e){this.selectedSymbol=e}async unlock(){if(Ke&&!(this.processing||this.unlocked)){Ee(this.config?.debug||!1,"Article paywall unlock started",{priceUsd:this.config.priceUsd,selectedSymbol:this.selectedSymbol,useOwnWallet:this.config.useOwnWallet}),this.errorMessage=null,this.errorSeverity=null,this.errorAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"unlock",type:"sendUsd",amount:this.config.priceUsd,currency:this.selectedSymbol||"ICP"}}))}catch{}this.processing=!0;try{if(this.config.useOwnWallet){if(!this.config.actorProvider){this.pendingAction="unlock",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0}));return}}else if(!this.walletConnected){Ee(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{de||(de=(await import("./wallet-select-M5KY6N6N.js")).WalletSelect);let t=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab)?U({...this.config?.plugNPlay||{}}):{...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:a}=await import("./origin-44ZEXSX4.js");t.derivationOrigin=this.config?.derivationOrigin||a()}}catch{}this.pnp=new de(t);try{let a=await te(this.pnp);if(a){this.walletConnected=!0;let r=T(this.pnp,{owner:a,principal:a,connected:!0}),o=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(c,d)=>this.pnp.getActor({canisterId:c,idl:d,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{}},this.sdk=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"oisy"}}))}catch{}this.unlock();return}}catch{}let n=this.pnp.getEnabledWallets();if(Ee(this.config?.debug||!1,"Available wallets",n),!n?.length)throw new Error("No wallets available");this.pendingAction="unlock",this.showWalletModal=!0;return}catch(e){Ee(this.config?.debug||!1,"Wallet connection error:",e),this.errorMessage=e instanceof Error?e.message:"Wallet connection failed",this.errorSeverity="error";return}}this.showWalletModal=!1,await this.fetchAndShowBalances();return}catch(e){P(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),D(t)&&(this.errorMessage=_(t),this.errorSeverity=F(t),this.errorAction=z(t))}});try{!this.config.useOwnWallet&&this.pnp&&(await this.pnp.disconnect?.(),this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0})}catch{}}finally{this.processing=!1}}}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");this.lastWalletId=(e||"").toLowerCase(),this.pnp.connect(e).then(n=>{if(!!!(n&&(n.connected===!0||n.principal||n.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}let r=T(this.pnp,n),o=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(d,h)=>this.pnp.getActor({canisterId:d,idl:h,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{}},this.sdk=null,this.lastWalletId==="oisy"?this.oisyReadyToPay=!0:(this.showWalletModal=!1,this.fetchAndShowBalances())}).catch(n=>{this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}})}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}}}async fetchAndShowBalances(){try{this.balancesLoading=!0,this.balancesError=null,this.showBalanceModal=!0;let e=g(this.config),{balances:t}=await Y({sdk:e,lastWalletId:this.lastWalletId,connectedWallet:this.config?.connectedWallet,amountUsd:Number(this.config?.priceUsd??0),chainShortcodes:this.config?.chainShortcodes,tokenShortcodes:this.config?.tokenShortcodes});this.walletBalances=t}catch(e){this.walletBalances=[],this.balancesError=e&&(e.message||String(e))||"Failed to load balances"}finally{this.balancesLoading=!1}}render(){return this.config?we`
|
|
1199
1199
|
<div class="icpay-card icpay-section icpay-widget-base">
|
|
1200
1200
|
${this.config?.progressBar?.enabled!==!1?we`
|
|
1201
1201
|
<icpay-progress-bar
|
|
@@ -1231,7 +1231,7 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var H=Xe`
|
|
|
1231
1231
|
|
|
1232
1232
|
${this.showOnrampModal?q({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}
|
|
1233
1233
|
</div>
|
|
1234
|
-
`:we`<div class="icpay-card icpay-section">Loading...</div>`}};
|
|
1234
|
+
`:we`<div class="icpay-card icpay-section">Loading...</div>`}};u.styles=[H,vt`
|
|
1235
1235
|
.container { background: var(--icpay-surface-alt); border: 1px solid var(--icpay-border); border-radius: 16px; padding: 16px; margin-bottom: 16px; }
|
|
1236
1236
|
.title { color: var(--icpay-text); font-weight: 700; margin-bottom: 8px; }
|
|
1237
1237
|
.preview { color: var(--icpay-muted); margin-bottom: 12px; line-height: 1.6; }
|
|
@@ -1263,7 +1263,7 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var H=Xe`
|
|
|
1263
1263
|
border-color: rgba(239, 68, 68, 0.3);
|
|
1264
1264
|
color: #ef4444;
|
|
1265
1265
|
}
|
|
1266
|
-
`],s([Ae({type:Object})],g.prototype,"config",2),s([Ae({type:String})],g.prototype,"title",2),s([Ae({type:String})],g.prototype,"preview",2),s([Ae({type:String})],g.prototype,"lockedContent",2),s([I()],g.prototype,"selectedSymbol",2),s([I()],g.prototype,"unlocked",2),s([I()],g.prototype,"succeeded",2),s([I()],g.prototype,"processing",2),s([I()],g.prototype,"errorMessage",2),s([I()],g.prototype,"errorSeverity",2),s([I()],g.prototype,"errorAction",2),s([I()],g.prototype,"walletConnected",2),s([I()],g.prototype,"pendingAction",2),s([I()],g.prototype,"showWalletModal",2),s([I()],g.prototype,"oisyReadyToPay",2),s([I()],g.prototype,"lastWalletId",2),s([I()],g.prototype,"showOnrampModal",2),s([I()],g.prototype,"onrampSessionId",2),s([I()],g.prototype,"onrampPaymentIntentId",2),s([I()],g.prototype,"onrampErrorMessage",2),s([I()],g.prototype,"showBalanceModal",2),s([I()],g.prototype,"balancesLoading",2),s([I()],g.prototype,"balancesError",2),s([I()],g.prototype,"walletBalances",2),g=s([bt("icpay-article-paywall")],g);import{LitElement as wt,html as pe,css as Et}from"lit";import{customElement as xt,property as St,state as L}from"lit/decorators.js";var He=typeof window<"u",Ne=null;function xe(i,l,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${l}`,e):console.log(`[ICPay Widget] ${l}`))}var x=class extends wt{constructor(){super(...arguments);this.selectedIndex=0;this.selectedSymbol=null;this.processing=!1;this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.showOnrampModal=!1;this.onrampSessionId=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.transakMessageHandlerBound=null;this.onrampPollTimer=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.sdk=null;this.showBalanceModal=!1;this.balancesLoading=!1;this.balancesError=null;this.walletBalances=[];this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="order",this.showWalletModal=!0,this.requestUpdate();try{let t=Number(this.selectedItem?.priceUsd||0),n=this.selectedSymbol||"ICP";window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"order",type:"sendUsd",amount:t,currency:n}}))}catch{}}catch{}};this.onSelectBalanceSymbol=async e=>{let t=(this.walletBalances||[]).find(a=>a?.tokenShortcode===e);if(t?.ledgerSymbol&&(this.selectedSymbol=t.ledgerSymbol),R(this.lastWalletId)){let a=(this.walletBalances||[]).find(o=>o?.tokenShortcode===e),r=a?.chainId;V(r,{chainName:a?.chainName,rpcUrlPublic:a?.rpcUrlPublic,nativeSymbol:a?.ledgerSymbol,decimals:a?.decimals}).then(async()=>{try{let o=u(this.config),c=Number(this.selectedItem?.priceUsd||0);if(a?.x402Accepts)try{await o.client.createPaymentX402Usd({usdAmount:c,tokenShortcode:a?.tokenShortcode,metadata:{network:"evm",ledgerId:a?.ledgerId,chainId:a?.chainUuid,context:"coffee:x402",item:this.selectedItem?.name}}),this.showBalanceModal=!1;return}catch{}await o.client.createPaymentUsd({usdAmount:c,tokenShortcode:a?.tokenShortcode,metadata:{network:"evm",ledgerId:a?.ledgerId,item:this.selectedItem?.name}})}catch{}this.showBalanceModal=!1});return}this.showBalanceModal=!1;let n=this.pendingAction;if(this.pendingAction=null,n==="order")try{let a=(this.walletBalances||[]).find(c=>c?.tokenShortcode===e),r=u(this.config),o=Number(this.selectedItem?.priceUsd||0);await r.client.createPaymentUsd({usdAmount:o,tokenShortcode:a?.tokenShortcode,metadata:{network:"ic",ledgerId:a?.ledgerId,item:this.selectedItem?.name}})}catch{}}}connectedCallback(){if(super.connectedCallback(),!!He){xe(this.config?.debug||!1,"Coffee shop connected",{config:this.config}),this.config&&typeof this.config.defaultItemIndex=="number"&&(this.selectedIndex=this.config.defaultItemIndex);try{window.addEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}try{window.addEventListener("icpay-sdk-transaction-created",(()=>{this.showWalletModal=!1,this.requestUpdate()}))}catch{}}}updated(e){if(e.has("config")&&this.pendingAction&&this.config?.actorProvider){let t=this.pendingAction;this.pendingAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}setTimeout(()=>{t==="order"&&this.order()},0)}}selectItem(e){this.selectedIndex=e}selectSymbol(e){this.selectedSymbol=e}get selectedItem(){return this.config?.items?.[this.selectedIndex]||{name:"Loading...",priceUsd:0}}async order(){if(He&&!this.processing){xe(this.config?.debug||!1,"Coffee order started",{selectedItem:this.selectedItem,selectedSymbol:this.selectedSymbol,useOwnWallet:this.config.useOwnWallet}),this.errorMessage=null,this.errorSeverity=null,this.errorAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"order",type:"sendUsd",amount:this.selectedItem.priceUsd,currency:this.selectedSymbol||"ICP"}}))}catch{}this.processing=!0;try{if(this.config.useOwnWallet){if(!this.config.actorProvider){this.pendingAction="order",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0}));return}}else if(!this.walletConnected){xe(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{Ne||(Ne=(await import("./wallet-select-M5KY6N6N.js")).WalletSelect);let t=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab)?U({...this.config?.plugNPlay||{}}):{...this.config?.plugNPlay||{}};this.config?.chainTypes&&(t.chainTypes=this.config.chainTypes);try{if(typeof window<"u"){let{resolveDerivationOrigin:a}=await import("./origin-44ZEXSX4.js");t.derivationOrigin=this.config?.derivationOrigin||a()}}catch{}this.pnp=new Ne(t);try{let a=await te(this.pnp);if(a){this.walletConnected=!0;let r=T(this.pnp,{owner:a,principal:a,connected:!0}),o=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(c,d)=>this.pnp.getActor({canisterId:c,idl:d,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{}},this.sdk=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"oisy"}}))}catch{}this.order();return}}catch{}let n=this.pnp.getEnabledWallets();if(xe(this.config?.debug||!1,"Available wallets",n),!n?.length)throw new Error("No wallets available");this.pendingAction="order",this.showWalletModal=!0;return}catch(e){xe(this.config?.debug||!1,"Wallet connection error:",e),this.errorMessage=e instanceof Error?e.message:"Wallet connection failed",this.errorSeverity="error";return}}this.pendingAction="order",this.showWalletModal=!0,await this.fetchAndShowBalances();return}catch(e){P(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),D(t)&&(this.errorMessage=_(t),this.errorSeverity=F(t),this.errorAction=z(t))}});try{!this.config.useOwnWallet&&this.pnp&&(await this.pnp.disconnect?.(),this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0})}catch{}}finally{this.processing=!1}}}attachTransakMessageListener(){if(!this.transakMessageHandlerBound){this.transakMessageHandlerBound=e=>this.onTransakMessage(e);try{window.addEventListener("message",this.transakMessageHandlerBound)}catch{}}}detachTransakMessageListener(){if(this.transakMessageHandlerBound){try{window.removeEventListener("message",this.transakMessageHandlerBound)}catch{}this.transakMessageHandlerBound=null}}onTransakMessage(e){let t=e?.data,n=t?.event_id||t?.eventId||t?.id;if(!(!n||typeof n!="string")&&n==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let a=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(a||void 0)}}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1,setTimeout(()=>this.createOnrampIntent(),0)}async createOnrampIntent(){try{let e=u(this.config),t=this.selectedSymbol||"ICP",n=await e.startOnrampUsd(this.selectedItem.priceUsd,t,{context:"coffee:onramp",item:this.selectedItem.name}),a=n?.metadata?.onramp?.sessionId||n?.metadata?.onramp?.session_id||null,r=n?.metadata?.paymentIntentId||n?.paymentIntentId||null,o=n?.metadata?.onramp?.errorMessage||null;this.onrampPaymentIntentId=r,a?(this.onrampSessionId=a,this.onrampErrorMessage=null,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.onrampErrorMessage=o||"Failed to obtain onramp sessionId",this.showOnrampModal=!0)}catch(e){this.onrampSessionId=null,this.onrampErrorMessage=e?.message||"Failed to obtain onramp sessionId",this.showOnrampModal=!0}}startOnrampPolling(e){if(this.onrampPollTimer){try{clearInterval(this.onrampPollTimer)}catch{}this.onrampPollTimer=null}if(this.onrampNotifyController){try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null}let t=this.onrampPaymentIntentId;if(!t)return;let n=u(this.config),a=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>a()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=n.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");this.lastWalletId=(e||"").toLowerCase(),this.pnp.connect(e).then(n=>{if(!!!(n&&(n.connected===!0||n.principal||n.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}let r=T(this.pnp,n),o=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(d,h)=>this.pnp.getActor({canisterId:d,idl:h,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{}},this.sdk=null,this.lastWalletId==="oisy"?this.oisyReadyToPay=!0:(this.showWalletModal=!1,this.fetchAndShowBalances())}).catch(n=>{this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}})}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}}}async fetchAndShowBalances(){try{this.balancesLoading=!0,this.balancesError=null,this.showBalanceModal=!0;let e=u(this.config),{balances:t}=await Y({sdk:e,lastWalletId:this.lastWalletId,connectedWallet:this.config?.connectedWallet,amountUsd:Number(this.selectedItem?.priceUsd??0),chainShortcodes:this.config?.chainShortcodes,tokenShortcodes:this.config?.tokenShortcodes});this.walletBalances=t}catch(e){this.walletBalances=[],this.balancesError=e&&(e.message||String(e))||"Failed to load balances"}finally{this.balancesLoading=!1}}render(){return this.config?pe`
|
|
1266
|
+
`],s([Ae({type:Object})],u.prototype,"config",2),s([Ae({type:String})],u.prototype,"title",2),s([Ae({type:String})],u.prototype,"preview",2),s([Ae({type:String})],u.prototype,"lockedContent",2),s([I()],u.prototype,"selectedSymbol",2),s([I()],u.prototype,"unlocked",2),s([I()],u.prototype,"succeeded",2),s([I()],u.prototype,"processing",2),s([I()],u.prototype,"errorMessage",2),s([I()],u.prototype,"errorSeverity",2),s([I()],u.prototype,"errorAction",2),s([I()],u.prototype,"walletConnected",2),s([I()],u.prototype,"pendingAction",2),s([I()],u.prototype,"showWalletModal",2),s([I()],u.prototype,"oisyReadyToPay",2),s([I()],u.prototype,"lastWalletId",2),s([I()],u.prototype,"showOnrampModal",2),s([I()],u.prototype,"onrampSessionId",2),s([I()],u.prototype,"onrampPaymentIntentId",2),s([I()],u.prototype,"onrampErrorMessage",2),s([I()],u.prototype,"showBalanceModal",2),s([I()],u.prototype,"balancesLoading",2),s([I()],u.prototype,"balancesError",2),s([I()],u.prototype,"walletBalances",2),u=s([bt("icpay-article-paywall")],u);import{LitElement as wt,html as pe,css as Et}from"lit";import{customElement as xt,property as St,state as L}from"lit/decorators.js";var He=typeof window<"u",Ne=null;function xe(i,l,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${l}`,e):console.log(`[ICPay Widget] ${l}`))}var x=class extends wt{constructor(){super(...arguments);this.selectedIndex=0;this.selectedSymbol=null;this.processing=!1;this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.showOnrampModal=!1;this.onrampSessionId=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.transakMessageHandlerBound=null;this.onrampPollTimer=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.sdk=null;this.showBalanceModal=!1;this.balancesLoading=!1;this.balancesError=null;this.walletBalances=[];this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="order",this.showWalletModal=!0,this.requestUpdate();try{let t=Number(this.selectedItem?.priceUsd||0),n=this.selectedSymbol||"ICP";window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"order",type:"sendUsd",amount:t,currency:n}}))}catch{}}catch{}};this.onSelectBalanceSymbol=async e=>{let t=(this.walletBalances||[]).find(a=>a?.tokenShortcode===e);if(t?.ledgerSymbol&&(this.selectedSymbol=t.ledgerSymbol),R(this.lastWalletId)){let a=(this.walletBalances||[]).find(o=>o?.tokenShortcode===e),r=a?.chainId;V(r,{chainName:a?.chainName,rpcUrlPublic:a?.rpcUrlPublic,nativeSymbol:a?.ledgerSymbol,decimals:a?.decimals}).then(async()=>{try{let o=g(this.config),c=Number(this.selectedItem?.priceUsd||0);if(a?.x402Accepts)try{await o.client.createPaymentX402Usd({usdAmount:c,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,network:"evm",ledgerId:a?.ledgerId,chainId:a?.chainUuid,context:"coffee:x402",item:this.selectedItem?.name}}),this.showBalanceModal=!1;return}catch{}await o.client.createPaymentUsd({usdAmount:c,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,network:"evm",ledgerId:a?.ledgerId,item:this.selectedItem?.name}})}catch{}this.showBalanceModal=!1});return}this.showBalanceModal=!1;let n=this.pendingAction;if(this.pendingAction=null,n==="order")try{let a=(this.walletBalances||[]).find(c=>c?.tokenShortcode===e),r=g(this.config),o=Number(this.selectedItem?.priceUsd||0);await r.client.createPaymentUsd({usdAmount:o,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,network:"ic",ledgerId:a?.ledgerId,item:this.selectedItem?.name}})}catch{}}}connectedCallback(){if(super.connectedCallback(),!!He){xe(this.config?.debug||!1,"Coffee shop connected",{config:this.config}),this.config&&typeof this.config.defaultItemIndex=="number"&&(this.selectedIndex=this.config.defaultItemIndex);try{window.addEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}try{window.addEventListener("icpay-sdk-transaction-created",(()=>{this.showWalletModal=!1,this.requestUpdate()}))}catch{}}}updated(e){if(e.has("config")&&this.pendingAction&&this.config?.actorProvider){let t=this.pendingAction;this.pendingAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}setTimeout(()=>{t==="order"&&this.order()},0)}}selectItem(e){this.selectedIndex=e}selectSymbol(e){this.selectedSymbol=e}get selectedItem(){return this.config?.items?.[this.selectedIndex]||{name:"Loading...",priceUsd:0}}async order(){if(He&&!this.processing){xe(this.config?.debug||!1,"Coffee order started",{selectedItem:this.selectedItem,selectedSymbol:this.selectedSymbol,useOwnWallet:this.config.useOwnWallet}),this.errorMessage=null,this.errorSeverity=null,this.errorAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"order",type:"sendUsd",amount:this.selectedItem.priceUsd,currency:this.selectedSymbol||"ICP"}}))}catch{}this.processing=!0;try{if(this.config.useOwnWallet){if(!this.config.actorProvider){this.pendingAction="order",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0}));return}}else if(!this.walletConnected){xe(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{Ne||(Ne=(await import("./wallet-select-M5KY6N6N.js")).WalletSelect);let t=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab)?U({...this.config?.plugNPlay||{}}):{...this.config?.plugNPlay||{}};this.config?.chainTypes&&(t.chainTypes=this.config.chainTypes);try{if(typeof window<"u"){let{resolveDerivationOrigin:a}=await import("./origin-44ZEXSX4.js");t.derivationOrigin=this.config?.derivationOrigin||a()}}catch{}this.pnp=new Ne(t);try{let a=await te(this.pnp);if(a){this.walletConnected=!0;let r=T(this.pnp,{owner:a,principal:a,connected:!0}),o=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(c,d)=>this.pnp.getActor({canisterId:c,idl:d,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{}},this.sdk=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"oisy"}}))}catch{}this.order();return}}catch{}let n=this.pnp.getEnabledWallets();if(xe(this.config?.debug||!1,"Available wallets",n),!n?.length)throw new Error("No wallets available");this.pendingAction="order",this.showWalletModal=!0;return}catch(e){xe(this.config?.debug||!1,"Wallet connection error:",e),this.errorMessage=e instanceof Error?e.message:"Wallet connection failed",this.errorSeverity="error";return}}this.pendingAction="order",this.showWalletModal=!0,await this.fetchAndShowBalances();return}catch(e){P(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),D(t)&&(this.errorMessage=_(t),this.errorSeverity=F(t),this.errorAction=z(t))}});try{!this.config.useOwnWallet&&this.pnp&&(await this.pnp.disconnect?.(),this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0})}catch{}}finally{this.processing=!1}}}attachTransakMessageListener(){if(!this.transakMessageHandlerBound){this.transakMessageHandlerBound=e=>this.onTransakMessage(e);try{window.addEventListener("message",this.transakMessageHandlerBound)}catch{}}}detachTransakMessageListener(){if(this.transakMessageHandlerBound){try{window.removeEventListener("message",this.transakMessageHandlerBound)}catch{}this.transakMessageHandlerBound=null}}onTransakMessage(e){let t=e?.data,n=t?.event_id||t?.eventId||t?.id;if(!(!n||typeof n!="string")&&n==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let a=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(a||void 0)}}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1,setTimeout(()=>this.createOnrampIntent(),0)}async createOnrampIntent(){try{let e=g(this.config),t=this.selectedSymbol||"ICP",n=await e.startOnrampUsd(this.selectedItem.priceUsd,t,{context:"coffee:onramp",item:this.selectedItem.name}),a=n?.metadata?.onramp?.sessionId||n?.metadata?.onramp?.session_id||null,r=n?.metadata?.paymentIntentId||n?.paymentIntentId||null,o=n?.metadata?.onramp?.errorMessage||null;this.onrampPaymentIntentId=r,a?(this.onrampSessionId=a,this.onrampErrorMessage=null,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.onrampErrorMessage=o||"Failed to obtain onramp sessionId",this.showOnrampModal=!0)}catch(e){this.onrampSessionId=null,this.onrampErrorMessage=e?.message||"Failed to obtain onramp sessionId",this.showOnrampModal=!0}}startOnrampPolling(e){if(this.onrampPollTimer){try{clearInterval(this.onrampPollTimer)}catch{}this.onrampPollTimer=null}if(this.onrampNotifyController){try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null}let t=this.onrampPaymentIntentId;if(!t)return;let n=g(this.config),a=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>a()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=n.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");this.lastWalletId=(e||"").toLowerCase(),this.pnp.connect(e).then(n=>{if(!!!(n&&(n.connected===!0||n.principal||n.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}let r=T(this.pnp,n),o=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(d,h)=>this.pnp.getActor({canisterId:d,idl:h,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{}},this.sdk=null,this.lastWalletId==="oisy"?this.oisyReadyToPay=!0:(this.showWalletModal=!1,this.fetchAndShowBalances())}).catch(n=>{this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}})}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}}}async fetchAndShowBalances(){try{this.balancesLoading=!0,this.balancesError=null,this.showBalanceModal=!0;let e=g(this.config),{balances:t}=await Y({sdk:e,lastWalletId:this.lastWalletId,connectedWallet:this.config?.connectedWallet,amountUsd:Number(this.selectedItem?.priceUsd??0),chainShortcodes:this.config?.chainShortcodes,tokenShortcodes:this.config?.tokenShortcodes});this.walletBalances=t}catch(e){this.walletBalances=[],this.balancesError=e&&(e.message||String(e))||"Failed to load balances"}finally{this.balancesLoading=!1}}render(){return this.config?pe`
|
|
1267
1267
|
<div class="icpay-card icpay-section icpay-widget-base">
|
|
1268
1268
|
${this.config?.progressBar?.enabled!==!1?pe`
|
|
1269
1269
|
<icpay-progress-bar
|
|
@@ -1337,7 +1337,7 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var H=Xe`
|
|
|
1337
1337
|
border-color: rgba(239, 68, 68, 0.3);
|
|
1338
1338
|
color: #ef4444;
|
|
1339
1339
|
}
|
|
1340
|
-
`],s([St({type:Object})],x.prototype,"config",2),s([L()],x.prototype,"selectedIndex",2),s([L()],x.prototype,"selectedSymbol",2),s([L()],x.prototype,"processing",2),s([L()],x.prototype,"errorMessage",2),s([L()],x.prototype,"errorSeverity",2),s([L()],x.prototype,"errorAction",2),s([L()],x.prototype,"walletConnected",2),s([L()],x.prototype,"pendingAction",2),s([L()],x.prototype,"showWalletModal",2),s([L()],x.prototype,"oisyReadyToPay",2),s([L()],x.prototype,"lastWalletId",2),s([L()],x.prototype,"showOnrampModal",2),s([L()],x.prototype,"onrampSessionId",2),s([L()],x.prototype,"onrampPaymentIntentId",2),s([L()],x.prototype,"onrampErrorMessage",2),s([L()],x.prototype,"showBalanceModal",2),s([L()],x.prototype,"balancesLoading",2),s([L()],x.prototype,"balancesError",2),s([L()],x.prototype,"walletBalances",2),x=s([xt("icpay-coffee-shop")],x);import{LitElement as kt,html as he,css as Mt}from"lit";import{customElement as Wt,property as Ct,state as M}from"lit/decorators.js";var je=typeof window<"u",ue=null;function Se(i,l,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${l}`,e):console.log(`[ICPay Widget] ${l}`))}var b=class extends kt{constructor(){super(...arguments);this.selectedAmount=10;this.selectedSymbol=null;this.raised=0;this.processing=!1;this.succeeded=!1;this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.showOnrampModal=!1;this.onrampSessionId=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.transakMessageHandlerBound=null;this.onrampPollTimer=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.sdk=null;this.showBalanceModal=!1;this.balancesLoading=!1;this.balancesError=null;this.walletBalances=[];this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="donate",this.showWalletModal=!0,this.requestUpdate();try{let t=Number(this.selectedAmount||0),n=this.selectedSymbol||"ICP";window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"donate",type:"sendUsd",amount:t,currency:n}}))}catch{}}catch{}};this.onSelectBalanceSymbol=async e=>{let t=(this.walletBalances||[]).find(a=>a?.tokenShortcode===e);if(t?.ledgerSymbol&&(this.selectedSymbol=t.ledgerSymbol),R(this.lastWalletId)){let a=(this.walletBalances||[]).find(o=>o?.tokenShortcode===e),r=a?.chainId;V(r,{chainName:a?.chainName,rpcUrlPublic:a?.rpcUrlPublic,nativeSymbol:a?.ledgerSymbol,decimals:a?.decimals}).then(async()=>{try{let o=u(this.config),c=Number(this.selectedAmount||0);if(a?.x402Accepts)try{await o.client.createPaymentX402Usd({usdAmount:c,tokenShortcode:a?.tokenShortcode,metadata:{network:"evm",ledgerId:a?.ledgerId,chainId:a?.chainUuid,context:"donation:x402"}}),this.showBalanceModal=!1;return}catch{}await o.client.createPaymentUsd({usdAmount:c,tokenShortcode:a?.tokenShortcode,metadata:{network:"evm",ledgerId:a?.ledgerId}})}catch{}this.showBalanceModal=!1});return}this.showBalanceModal=!1;let n=this.pendingAction;if(this.pendingAction=null,n==="donate")try{let a=(this.walletBalances||[]).find(c=>c?.tokenShortcode===e),r=u(this.config),o=Number(this.selectedAmount||0);await r.client.createPaymentUsd({usdAmount:o,tokenShortcode:a?.tokenShortcode,metadata:{network:"ic",ledgerId:a?.ledgerId}})}catch{}}}async tryAutoConnectPNP(){try{if(!this.config||this.config?.useOwnWallet)return;let e=localStorage.getItem("icpay:pnp");if(!e)return;let t=JSON.parse(e);if(!t?.provider||!t?.principal)return;ue||(ue=(await import("./wallet-select-M5KY6N6N.js")).WalletSelect);let n=U({...this.config?.plugNPlay||{}});try{if(typeof window<"u"){let{resolveDerivationOrigin:r}=await import("./origin-44ZEXSX4.js");n.derivationOrigin=this.config?.derivationOrigin||r()}}catch{}let a=new ue(n);this.walletConnected=!1,this.config={...this.config,connectedWallet:{owner:t.principal,principal:t.principal,connected:!1}}}catch{}}get amounts(){return this.config?.amountsUsd||[10,25,50,100,250,500]}connectedCallback(){if(super.connectedCallback(),!!je){Se(this.config?.debug||!1,"Donation thermometer connected",{config:this.config}),this.config&&typeof this.config.defaultAmountUsd=="number"&&(this.selectedAmount=this.config.defaultAmountUsd),this.tryAutoConnectPNP();try{window.addEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}try{window.addEventListener("icpay-sdk-transaction-created",(()=>{this.showWalletModal=!1,this.requestUpdate()}))}catch{}}}updated(e){if(e.has("config")&&this.pendingAction&&this.config?.actorProvider){let t=this.pendingAction;this.pendingAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}setTimeout(()=>{t==="donate"&&this.donate()},0)}}selectAmount(e){this.selectedAmount=e}selectSymbol(e){this.selectedSymbol=e}get fillPercentage(){let e=Number(this.config?.goalUsd??1e3),t=e>0?e:1e3;return Math.min(this.raised/t*100,100)}async donate(){if(je&&!this.processing){Se(this.config?.debug||!1,"Donation started",{amount:this.selectedAmount,selectedSymbol:this.selectedSymbol,useOwnWallet:this.config.useOwnWallet}),this.errorMessage=null,this.errorSeverity=null,this.errorAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"donate",type:"sendUsd",amount:this.selectedAmount,currency:this.selectedSymbol||"ICP"}}))}catch{}this.processing=!0;try{if(this.config.useOwnWallet){if(!this.config.actorProvider){this.pendingAction="donate",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0}));return}}else if(!this.walletConnected){Se(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{ue||(ue=(await import("./wallet-select-M5KY6N6N.js")).WalletSelect);let t=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab)?U({...this.config?.plugNPlay||{}}):{...this.config?.plugNPlay||{}};this.config?.chainTypes&&(t.chainTypes=this.config.chainTypes);try{if(typeof window<"u"){let{resolveDerivationOrigin:a}=await import("./origin-44ZEXSX4.js");t.derivationOrigin=this.config?.derivationOrigin||a()}}catch{}this.pnp=new ue(t);try{let a=await te(this.pnp);if(a){this.walletConnected=!0;let r=T(this.pnp,{owner:a,principal:a,connected:!0}),o=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(c,d)=>this.pnp.getActor({canisterId:c,idl:d,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{}},this.sdk=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"oisy"}}))}catch{}this.donate();return}}catch{}let n=this.pnp.getEnabledWallets();if(Se(this.config?.debug||!1,"Available wallets",n),!n?.length)throw new Error("No wallets available");this.pendingAction="donate",this.showWalletModal=!0;return}catch(e){Se(this.config?.debug||!1,"Wallet connection error:",e),this.errorMessage=e instanceof Error?e.message:"Wallet connection failed",this.errorSeverity="error";return}}this.showWalletModal=!0,await this.fetchAndShowBalances();return}catch(e){P(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),D(t)&&(this.errorMessage=_(t),this.errorSeverity=F(t),this.errorAction=z(t))}});try{!this.config.useOwnWallet&&this.pnp&&(await this.pnp.disconnect?.(),this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0})}catch{}}finally{this.processing=!1}}}attachTransakMessageListener(){if(!this.transakMessageHandlerBound){this.transakMessageHandlerBound=e=>this.onTransakMessage(e);try{window.addEventListener("message",this.transakMessageHandlerBound)}catch{}}}detachTransakMessageListener(){if(this.transakMessageHandlerBound){try{window.removeEventListener("message",this.transakMessageHandlerBound)}catch{}this.transakMessageHandlerBound=null}}onTransakMessage(e){let t=e?.data,n=t?.event_id||t?.eventId||t?.id;if(!(!n||typeof n!="string")&&n==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let a=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(a||void 0)}}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1,setTimeout(()=>this.createOnrampIntent(),0)}async createOnrampIntent(){try{let e=u(this.config),t=this.selectedSymbol||"ICP",n=await e.startOnrampUsd(this.selectedAmount,t,{context:"donation:onramp"}),a=n?.metadata?.onramp?.sessionId||n?.metadata?.onramp?.session_id||null,r=n?.metadata?.paymentIntentId||n?.paymentIntentId||null,o=n?.metadata?.onramp?.errorMessage||null;this.onrampPaymentIntentId=r,a?(this.onrampSessionId=a,this.onrampErrorMessage=null,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.onrampErrorMessage=o||"Failed to obtain onramp sessionId",this.showOnrampModal=!0)}catch(e){this.onrampSessionId=null,this.onrampErrorMessage=e?.message||"Failed to obtain onramp sessionId",this.showOnrampModal=!0}}startOnrampPolling(e){if(this.onrampPollTimer){try{clearInterval(this.onrampPollTimer)}catch{}this.onrampPollTimer=null}if(this.onrampNotifyController){try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null}let t=this.onrampPaymentIntentId;if(!t)return;let n=u(this.config),a=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>a()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=n.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");this.lastWalletId=(e||"").toLowerCase(),this.pnp.connect(e).then(n=>{if(!!!(n&&(n.connected===!0||n.principal||n.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}let r=T(this.pnp,n),o=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(d,h)=>this.pnp.getActor({canisterId:d,idl:h,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{}},this.sdk=null,this.lastWalletId==="oisy"?this.oisyReadyToPay=!0:(this.showWalletModal=!1,this.fetchAndShowBalances())}).catch(n=>{this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}})}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}}}async fetchAndShowBalances(){try{this.balancesLoading=!0,this.balancesError=null,this.showBalanceModal=!0;let e=u(this.config),{balances:t}=await Y({sdk:e,lastWalletId:this.lastWalletId,connectedWallet:this.config?.connectedWallet,amountUsd:Number(this.selectedAmount||0),chainShortcodes:this.config?.chainShortcodes,tokenShortcodes:this.config?.tokenShortcodes});this.walletBalances=t}catch(e){this.walletBalances=[],this.balancesError=e&&(e.message||String(e))||"Failed to load balances"}finally{this.balancesLoading=!1}}render(){return this.config?he`
|
|
1340
|
+
`],s([St({type:Object})],x.prototype,"config",2),s([L()],x.prototype,"selectedIndex",2),s([L()],x.prototype,"selectedSymbol",2),s([L()],x.prototype,"processing",2),s([L()],x.prototype,"errorMessage",2),s([L()],x.prototype,"errorSeverity",2),s([L()],x.prototype,"errorAction",2),s([L()],x.prototype,"walletConnected",2),s([L()],x.prototype,"pendingAction",2),s([L()],x.prototype,"showWalletModal",2),s([L()],x.prototype,"oisyReadyToPay",2),s([L()],x.prototype,"lastWalletId",2),s([L()],x.prototype,"showOnrampModal",2),s([L()],x.prototype,"onrampSessionId",2),s([L()],x.prototype,"onrampPaymentIntentId",2),s([L()],x.prototype,"onrampErrorMessage",2),s([L()],x.prototype,"showBalanceModal",2),s([L()],x.prototype,"balancesLoading",2),s([L()],x.prototype,"balancesError",2),s([L()],x.prototype,"walletBalances",2),x=s([xt("icpay-coffee-shop")],x);import{LitElement as kt,html as he,css as Mt}from"lit";import{customElement as Wt,property as Ct,state as M}from"lit/decorators.js";var je=typeof window<"u",ge=null;function Se(i,l,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${l}`,e):console.log(`[ICPay Widget] ${l}`))}var b=class extends kt{constructor(){super(...arguments);this.selectedAmount=10;this.selectedSymbol=null;this.raised=0;this.processing=!1;this.succeeded=!1;this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.showOnrampModal=!1;this.onrampSessionId=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.transakMessageHandlerBound=null;this.onrampPollTimer=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.sdk=null;this.showBalanceModal=!1;this.balancesLoading=!1;this.balancesError=null;this.walletBalances=[];this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="donate",this.showWalletModal=!0,this.requestUpdate();try{let t=Number(this.selectedAmount||0),n=this.selectedSymbol||"ICP";window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"donate",type:"sendUsd",amount:t,currency:n}}))}catch{}}catch{}};this.onSelectBalanceSymbol=async e=>{let t=(this.walletBalances||[]).find(a=>a?.tokenShortcode===e);if(t?.ledgerSymbol&&(this.selectedSymbol=t.ledgerSymbol),R(this.lastWalletId)){let a=(this.walletBalances||[]).find(o=>o?.tokenShortcode===e),r=a?.chainId;V(r,{chainName:a?.chainName,rpcUrlPublic:a?.rpcUrlPublic,nativeSymbol:a?.ledgerSymbol,decimals:a?.decimals}).then(async()=>{try{let o=g(this.config),c=Number(this.selectedAmount||0);if(a?.x402Accepts)try{await o.client.createPaymentX402Usd({usdAmount:c,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,network:"evm",ledgerId:a?.ledgerId,chainId:a?.chainUuid,context:"donation:x402"}}),this.showBalanceModal=!1;return}catch{}await o.client.createPaymentUsd({usdAmount:c,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,network:"evm",ledgerId:a?.ledgerId}})}catch{}this.showBalanceModal=!1});return}this.showBalanceModal=!1;let n=this.pendingAction;if(this.pendingAction=null,n==="donate")try{let a=(this.walletBalances||[]).find(c=>c?.tokenShortcode===e),r=g(this.config),o=Number(this.selectedAmount||0);await r.client.createPaymentUsd({usdAmount:o,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,network:"ic",ledgerId:a?.ledgerId}})}catch{}}}async tryAutoConnectPNP(){try{if(!this.config||this.config?.useOwnWallet)return;let e=localStorage.getItem("icpay:pnp");if(!e)return;let t=JSON.parse(e);if(!t?.provider||!t?.principal)return;ge||(ge=(await import("./wallet-select-M5KY6N6N.js")).WalletSelect);let n=U({...this.config?.plugNPlay||{}});try{if(typeof window<"u"){let{resolveDerivationOrigin:r}=await import("./origin-44ZEXSX4.js");n.derivationOrigin=this.config?.derivationOrigin||r()}}catch{}let a=new ge(n);this.walletConnected=!1,this.config={...this.config,connectedWallet:{owner:t.principal,principal:t.principal,connected:!1}}}catch{}}get amounts(){return this.config?.amountsUsd||[10,25,50,100,250,500]}connectedCallback(){if(super.connectedCallback(),!!je){Se(this.config?.debug||!1,"Donation thermometer connected",{config:this.config}),this.config&&typeof this.config.defaultAmountUsd=="number"&&(this.selectedAmount=this.config.defaultAmountUsd),this.tryAutoConnectPNP();try{window.addEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}try{window.addEventListener("icpay-sdk-transaction-created",(()=>{this.showWalletModal=!1,this.requestUpdate()}))}catch{}}}updated(e){if(e.has("config")&&this.pendingAction&&this.config?.actorProvider){let t=this.pendingAction;this.pendingAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}setTimeout(()=>{t==="donate"&&this.donate()},0)}}selectAmount(e){this.selectedAmount=e}selectSymbol(e){this.selectedSymbol=e}get fillPercentage(){let e=Number(this.config?.goalUsd??1e3),t=e>0?e:1e3;return Math.min(this.raised/t*100,100)}async donate(){if(je&&!this.processing){Se(this.config?.debug||!1,"Donation started",{amount:this.selectedAmount,selectedSymbol:this.selectedSymbol,useOwnWallet:this.config.useOwnWallet}),this.errorMessage=null,this.errorSeverity=null,this.errorAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"donate",type:"sendUsd",amount:this.selectedAmount,currency:this.selectedSymbol||"ICP"}}))}catch{}this.processing=!0;try{if(this.config.useOwnWallet){if(!this.config.actorProvider){this.pendingAction="donate",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0}));return}}else if(!this.walletConnected){Se(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{ge||(ge=(await import("./wallet-select-M5KY6N6N.js")).WalletSelect);let t=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab)?U({...this.config?.plugNPlay||{}}):{...this.config?.plugNPlay||{}};this.config?.chainTypes&&(t.chainTypes=this.config.chainTypes);try{if(typeof window<"u"){let{resolveDerivationOrigin:a}=await import("./origin-44ZEXSX4.js");t.derivationOrigin=this.config?.derivationOrigin||a()}}catch{}this.pnp=new ge(t);try{let a=await te(this.pnp);if(a){this.walletConnected=!0;let r=T(this.pnp,{owner:a,principal:a,connected:!0}),o=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(c,d)=>this.pnp.getActor({canisterId:c,idl:d,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{}},this.sdk=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"oisy"}}))}catch{}this.donate();return}}catch{}let n=this.pnp.getEnabledWallets();if(Se(this.config?.debug||!1,"Available wallets",n),!n?.length)throw new Error("No wallets available");this.pendingAction="donate",this.showWalletModal=!0;return}catch(e){Se(this.config?.debug||!1,"Wallet connection error:",e),this.errorMessage=e instanceof Error?e.message:"Wallet connection failed",this.errorSeverity="error";return}}this.showWalletModal=!0,await this.fetchAndShowBalances();return}catch(e){P(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),D(t)&&(this.errorMessage=_(t),this.errorSeverity=F(t),this.errorAction=z(t))}});try{!this.config.useOwnWallet&&this.pnp&&(await this.pnp.disconnect?.(),this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0})}catch{}}finally{this.processing=!1}}}attachTransakMessageListener(){if(!this.transakMessageHandlerBound){this.transakMessageHandlerBound=e=>this.onTransakMessage(e);try{window.addEventListener("message",this.transakMessageHandlerBound)}catch{}}}detachTransakMessageListener(){if(this.transakMessageHandlerBound){try{window.removeEventListener("message",this.transakMessageHandlerBound)}catch{}this.transakMessageHandlerBound=null}}onTransakMessage(e){let t=e?.data,n=t?.event_id||t?.eventId||t?.id;if(!(!n||typeof n!="string")&&n==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let a=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(a||void 0)}}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1,setTimeout(()=>this.createOnrampIntent(),0)}async createOnrampIntent(){try{let e=g(this.config),t=this.selectedSymbol||"ICP",n=await e.startOnrampUsd(this.selectedAmount,t,{context:"donation:onramp"}),a=n?.metadata?.onramp?.sessionId||n?.metadata?.onramp?.session_id||null,r=n?.metadata?.paymentIntentId||n?.paymentIntentId||null,o=n?.metadata?.onramp?.errorMessage||null;this.onrampPaymentIntentId=r,a?(this.onrampSessionId=a,this.onrampErrorMessage=null,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.onrampErrorMessage=o||"Failed to obtain onramp sessionId",this.showOnrampModal=!0)}catch(e){this.onrampSessionId=null,this.onrampErrorMessage=e?.message||"Failed to obtain onramp sessionId",this.showOnrampModal=!0}}startOnrampPolling(e){if(this.onrampPollTimer){try{clearInterval(this.onrampPollTimer)}catch{}this.onrampPollTimer=null}if(this.onrampNotifyController){try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null}let t=this.onrampPaymentIntentId;if(!t)return;let n=g(this.config),a=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>a()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=n.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");this.lastWalletId=(e||"").toLowerCase(),this.pnp.connect(e).then(n=>{if(!!!(n&&(n.connected===!0||n.principal||n.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}let r=T(this.pnp,n),o=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(d,h)=>this.pnp.getActor({canisterId:d,idl:h,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{}},this.sdk=null,this.lastWalletId==="oisy"?this.oisyReadyToPay=!0:(this.showWalletModal=!1,this.fetchAndShowBalances())}).catch(n=>{this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}})}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}}}async fetchAndShowBalances(){try{this.balancesLoading=!0,this.balancesError=null,this.showBalanceModal=!0;let e=g(this.config),{balances:t}=await Y({sdk:e,lastWalletId:this.lastWalletId,connectedWallet:this.config?.connectedWallet,amountUsd:Number(this.selectedAmount||0),chainShortcodes:this.config?.chainShortcodes,tokenShortcodes:this.config?.tokenShortcodes});this.walletBalances=t}catch(e){this.walletBalances=[],this.balancesError=e&&(e.message||String(e))||"Failed to load balances"}finally{this.balancesLoading=!1}}render(){return this.config?he`
|
|
1341
1341
|
<div class="icpay-card icpay-section icpay-widget-base" style="text-align:center;">
|
|
1342
1342
|
${this.config?.progressBar?.enabled!==!1?he`
|
|
1343
1343
|
<icpay-progress-bar
|
|
@@ -1410,7 +1410,7 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var H=Xe`
|
|
|
1410
1410
|
border-color: rgba(239, 68, 68, 0.3);
|
|
1411
1411
|
color: #ef4444;
|
|
1412
1412
|
}
|
|
1413
|
-
`],s([Ct({type:Object})],b.prototype,"config",2),s([M()],b.prototype,"selectedAmount",2),s([M()],b.prototype,"selectedSymbol",2),s([M()],b.prototype,"raised",2),s([M()],b.prototype,"processing",2),s([M()],b.prototype,"succeeded",2),s([M()],b.prototype,"errorMessage",2),s([M()],b.prototype,"errorSeverity",2),s([M()],b.prototype,"errorAction",2),s([M()],b.prototype,"walletConnected",2),s([M()],b.prototype,"pendingAction",2),s([M()],b.prototype,"showWalletModal",2),s([M()],b.prototype,"oisyReadyToPay",2),s([M()],b.prototype,"lastWalletId",2),s([M()],b.prototype,"showOnrampModal",2),s([M()],b.prototype,"onrampSessionId",2),s([M()],b.prototype,"onrampPaymentIntentId",2),s([M()],b.prototype,"onrampErrorMessage",2),s([M()],b.prototype,"showBalanceModal",2),s([M()],b.prototype,"balancesLoading",2),s([M()],b.prototype,"balancesError",2),s([M()],b.prototype,"walletBalances",2),b=s([Wt("icpay-donation-thermometer")],b);import{LitElement as Tt,html as ke,css as At}from"lit";import{customElement as It,property as Ot,state as S}from"lit/decorators.js";var qe=typeof window<"u",ge=null;function $(i,l,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${l}`,e):console.log(`[ICPay Widget] ${l}`))}var y=class extends Tt{constructor(){super(...arguments);this.selectedSymbol=null;this.processing=!1;this.succeeded=!1;this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.walletModalStep="connect";this.showOnrampModal=!1;this.onrampSessionId=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.oisyReadyToPay=!1;this.oisySignerPreopened=!1;this.skipDisconnectOnce=!1;this.lastWalletId=null;this.showBalanceModal=!1;this.balancesLoading=!1;this.balancesError=null;this.walletBalances=[];this.onrampPollTimer=null;this.transakMessageHandlerBound=null;this.pnp=null;this.oisyConnectRetriedNewTab=!1;this.sdk=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="pay",this.walletModalStep="connect",this.showWalletModal=!0,this.oisyReadyToPay=!1,this.lastWalletId=null,this.requestUpdate();try{let t=Number(this.config?.amountUsd||0),n=this.selectedSymbol||"ICP";window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"pay",type:"sendUsd",amount:t,currency:n}}))}catch{}}catch{}};this.onSelectBalanceSymbol=async e=>{let t=(this.walletBalances||[]).find(a=>a?.tokenShortcode===e);if(t?.ledgerSymbol&&(this.selectedSymbol=t.ledgerSymbol),this.showBalanceModal=!1,this.showWalletModal=!1,R(this.lastWalletId)){$(this.config?.debug||!1,"EVM selection made",{selectedSymbol:this.selectedSymbol,selPresent:!!t,selSnapshot:t?{ledgerId:t?.ledgerId,ledgerSymbol:t?.ledgerSymbol,ledgerName:t?.ledgerName,chainUuid:t?.chainUuid,chainId:t?.chainId,chainName:t?.chainName,x402Accepts:t?.x402Accepts,requiredAmount:t?.requiredAmount,hasSufficientBalance:t?.hasSufficientBalance}:null});let a=t?.chainId;V(a,{chainName:t?.chainName,rpcUrlPublic:t?.rpcUrlPublic,nativeSymbol:t?.ledgerSymbol,decimals:t?.decimals}).then(async()=>{try{let r=this.getSdk(),o=Number(this.config?.amountUsd??0),c=t?.ledgerSymbol,d=!!(t&&t.x402Accepts);if($(this.config?.debug||!1,"EVM post-ensure chain snapshot",{targetChain:a,amountUsd:o,symbolNow:c,tryX402:d,x402Accepts:t?.x402Accepts}),d)try{let h={network:"evm",ledgerId:t?.ledgerId,chainId:t?.chainUuid,context:"pay-button:x402"};$(this.config?.debug||!1,"Attempting X402 flow (EVM selection)",{amountUsd:o,tokenShortcode:t?.tokenShortcode,x402Accepts:t?.x402Accepts}),await r.client.createPaymentX402Usd({usdAmount:o,tokenShortcode:t?.tokenShortcode,metadata:h});return}catch(h){$(this.config?.debug||!1,"X402 payment failed (EVM selection), falling back",{message:h?.message,code:h?.code,data:h?.details||h?.data})}else $(this.config?.debug||!1,"Skipping X402 path",{reason:t?t.x402Accepts?"unknown":"x402Accepts false":"no selection",selPresent:!!t,x402Accepts:t?.x402Accepts});$(this.config?.debug||!1,"Falling back to normal EVM wallet flow",{amountUsd:o,tokenShortcode:t?.tokenShortcode}),await r.client.createPaymentUsd({usdAmount:o,tokenShortcode:t?.tokenShortcode,metadata:{network:"evm",ledgerId:t?.ledgerId}})}catch{}});return}let n=this.pendingAction;if(this.pendingAction=null,n==="pay")try{let a=(this.walletBalances||[]).find(c=>c?.tokenShortcode===e),r=this.getSdk(),o=Number(this.config?.amountUsd??0);$(this.config?.debug||!1,"IC selection made",{selectedSymbol:this.selectedSymbol,selPresent:!!a,selSnapshot:a?{ledgerId:a?.ledgerId,ledgerSymbol:a?.ledgerSymbol,ledgerName:a?.ledgerName,requiredAmount:a?.requiredAmount,hasSufficientBalance:a?.hasSufficientBalance,tokenShortcode:a?.tokenShortcode}:null}),await r.client.createPaymentUsd({usdAmount:o,tokenShortcode:a?.tokenShortcode,metadata:{network:"ic",ledgerId:a?.ledgerId}})}catch{}}}getSdk(){return this.sdk||(this.sdk=u(this.config)),this.sdk}connectedCallback(){if(super.connectedCallback(),!!qe){$(this.config?.debug||!1,"Pay button connected",{config:this.config});try{window.addEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}try{window.addEventListener("icpay-sdk-transaction-created",(e=>{$(this.config?.debug||!1,"SDK transaction created",{detail:e?.detail}),this.showWalletModal=!1,this.showBalanceModal=!1,this.requestUpdate()}))}catch{}}}updated(e){if(e.has("config")&&this.pendingAction&&this.config?.actorProvider){let t=this.pendingAction;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}this.walletModalStep!=="balances"&&!this.oisyReadyToPay&&(this.pendingAction=null,setTimeout(()=>{t==="pay"&&this.pay()},0))}e.has("config")&&(this.sdk=null)}selectSymbol(e){this.selectedSymbol=e}async ensureWallet(){if(this.config.useOwnWallet)return this.config.actorProvider?!0:(this.pendingAction="pay",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0})),!1);if(this.walletConnected)return!0;try{ge||(ge=(await import("./wallet-select-M5KY6N6N.js")).WalletSelect);let e=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab),t={...this.config?.plugNPlay||{}};this.config?.chainTypes&&(t.chainTypes=this.config.chainTypes);let n=e?U(t):t;try{if(typeof window<"u"){let{resolveDerivationOrigin:r}=await import("./origin-44ZEXSX4.js");n.derivationOrigin=this.config?.derivationOrigin||r()}}catch{}this.pnp=new ge(n);let a=this.pnp.getEnabledWallets();if($(this.config?.debug||!1,"Available wallets",a),!a?.length)throw new Error("No wallets available");return this.pendingAction="pay",this.showWalletModal=!0,!1}catch(e){return this.errorMessage=e instanceof Error?e.message:"Wallet connection failed",this.errorSeverity="error",!1}}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");this.lastWalletId=(e||"").toLowerCase(),this.lastWalletId==="oisy"&&(this.oisyConnectRetriedNewTab=!1),this.pnp.connect(e).then(n=>{if($(this.config?.debug||!1,"Wallet connect result",n),!!!(n&&(n.connected===!0||n.principal||n.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}let r=T(this.pnp,n),o=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(d,h)=>this.pnp.getActor({canisterId:d,idl:h,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{}},this.sdk=null,(e||"").toLowerCase()==="oisy"?(this.oisyReadyToPay=!0,this.pendingAction=null):(this.walletModalStep="balances",this.fetchAndShowBalances("pay"))}).catch(n=>{$(this.config?.debug||!1,"Wallet connection error",n);let a=(e||"").toLowerCase()==="oisy",r=n&&(n.message||String(n))||"";if(a&&!this.oisyConnectRetriedNewTab&&(r.includes("Signer window could not be opened")||r.includes("Communication channel could not be established"))){this.oisyConnectRetriedNewTab=!0,(async()=>{try{ge||(ge=(await import("./wallet-select-M5KY6N6N.js")).WalletSelect);let c={...this.config?.plugNPlay||{}};this.config?.chainTypes&&(c.chainTypes=this.config.chainTypes);let d=U(c);try{if(typeof window<"u"){let{resolveDerivationOrigin:p}=await import("./origin-44ZEXSX4.js");d.derivationOrigin=this.config?.derivationOrigin||p()}}catch{}this.pnp=new ge(d),this.pnp.connect("oisy").then(p=>{if(!!!(p&&(p.connected===!0||p.principal||p.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"oisy"}}))}catch{}let K=T(this.pnp,p),ee=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:K,actorProvider:(C,B)=>this.pnp.getActor({canisterId:C,idl:B,requiresSigning:!0,anon:!1}),...ee?{evmProvider:ee}:{}},this.sdk=null,this.oisyReadyToPay=!0,this.pendingAction=null}).catch(p=>{$(this.config?.debug||!1,"Oisy retry connect (new tab) failed",p),this.errorMessage=p instanceof Error?p.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}})}catch(c){$(this.config?.debug||!1,"Oisy new-tab init failed",c),this.errorMessage=c instanceof Error?c.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}}})();return}this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}})}catch(t){$(this.config?.debug||!1,"Wallet connection error (sync)",t),this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}}}async fetchAndShowBalances(e){try{this.balancesLoading=!0,this.balancesError=null,this.walletModalStep="balances",this.showBalanceModal=!1;let t=this.getSdk(),{balances:n}=await Y({sdk:t,lastWalletId:this.lastWalletId,connectedWallet:this.config?.connectedWallet,amountUsd:Number(this.config?.amountUsd??0),chainShortcodes:this.config?.chainShortcodes,tokenShortcodes:this.config?.tokenShortcodes});this.walletBalances=n,this.pendingAction=e}catch(t){this.walletBalances=[],this.balancesError=t&&(t.message||String(t))||"Failed to load balances"}finally{this.balancesLoading=!1}}renderWalletModal(){if(!this.showWalletModal||!this.pnp)return null;let e=this.pnp.getEnabledWallets()||[],t=G(e),n=this.config?.onramp?.enabled!==!1&&this.config?.onrampDisabled!==!0,a=5,r=Number(this.config?.amountUsd??0),o=n&&r>0&&r<a,c=Math.max(0,a-r),d=o?`Note: Minimum card amount is $${a}. You will pay about $${c.toFixed(2)} more.`:null;return Q({visible:this.showWalletModal,wallets:t,isConnecting:!1,onSwitchAccount:()=>this.onSwitchAccount(null),step:this.walletModalStep,balances:this.walletModalStep==="balances"?this.walletBalances||[]:[],balancesLoading:this.walletModalStep==="balances"?this.balancesLoading:!1,balancesError:this.walletModalStep==="balances"?this.balancesError:null,onSelectBalance:h=>this.onSelectBalanceSymbol(h),onBack:()=>{this.walletModalStep="connect"},onSelect:h=>{this.connectWithWallet(h)},onClose:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-cancelled",{detail:{reason:"user_cancelled"}}))}catch{}},onCreditCard:n?()=>this.startOnramp():void 0,creditCardLabel:this.config?.onramp?.creditCardLabel||"Pay with credit card",showCreditCard:n,creditCardTooltip:d,oisyReadyToPay:this.oisyReadyToPay,onOisyPay:()=>{this.showWalletModal=!1,this.skipDisconnectOnce=!0,this.oisyReadyToPay=!1,this.pay()}})}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1,setTimeout(()=>this.createOnrampIntent(),0)}async createOnrampIntent(){try{let e=Number(this.config?.amountUsd??0),t=this.getSdk();this.selectedSymbol||(this.selectedSymbol="ICP");let n=this.selectedSymbol||"ICP",a=await t.startOnrampUsd(e,n,{context:"pay-button:onramp"}),r=a?.metadata?.onramp?.sessionId||a?.metadata?.onramp?.session_id||null,o=a?.metadata?.onramp?.errorMessage||null;this.onrampErrorMessage=o||null;let c=a?.metadata?.paymentIntentId||a?.paymentIntentId||null;this.onrampPaymentIntentId=c,r?(this.onrampSessionId=r,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.showOnrampModal=!0)}catch(e){this.onrampSessionId=null,this.onrampErrorMessage=e?.message||null,this.showOnrampModal=!0,P(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),D(t)&&(this.errorMessage=_(t),this.errorSeverity=F(t),this.errorAction=z(t))}})}}attachTransakMessageListener(){if(!this.transakMessageHandlerBound){this.transakMessageHandlerBound=e=>this.onTransakMessage(e);try{window.addEventListener("message",this.transakMessageHandlerBound)}catch{}}}detachTransakMessageListener(){if(this.transakMessageHandlerBound){try{window.removeEventListener("message",this.transakMessageHandlerBound)}catch{}this.transakMessageHandlerBound=null}}onTransakMessage(e){let t=e?.data,n=t?.event_id||t?.eventId||t?.id;if(!(!n||typeof n!="string")&&n==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;let a=t?.data?.id||t?.id||t?.webhookData?.id||null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-success",{detail:{name:"getLedgerBalance"}}))}catch{}try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-success",{detail:{name:"sendFundsToLedger"}}))}catch{}try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-success",{detail:{name:"notifyLedgerTransaction"}}))}catch{}this.showOnrampModal=!1,this.startOnrampPolling(a||void 0)}}startOnrampPolling(e){if(this.onrampPollTimer){try{clearInterval(this.onrampPollTimer)}catch{}this.onrampPollTimer=null}if(this.onrampNotifyController){try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null}let t=this.onrampPaymentIntentId;if(!t)return;let n=this.getSdk(),a=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1},r=o=>{a()};try{window.addEventListener("icpay-sdk-transaction-completed",r,{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=n.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}async pay(){if(!(!qe||this.processing)){this.errorMessage=null,this.errorSeverity=null,this.errorAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"pay",type:"sendUsd",amount:this.config?.amountUsd,currency:this.selectedSymbol||"ICP"}}))}catch{}this.processing=!0;try{if(this.skipDisconnectOnce)this.skipDisconnectOnce=!1;else try{!this.config.useOwnWallet&&this.pnp&&(await this.pnp.disconnect?.(),this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0})}catch{}if(!await this.ensureWallet())return;let t=this.getSdk();try{let n=this.config?.connectedWallet,a=this?.pnp?.account;$(this.config?.debug||!1,"Wallet state before payment",{connectedWallet:n,pnpAccount:a,principal:n?.owner||n?.principal||a?.owner||a?.principal||null})}catch{}this.walletModalStep="balances",this.showWalletModal=!0,await this.fetchAndShowBalances("pay");return}catch(e){$(this.config?.debug||!1,"Payment error",{message:e?.message,code:e?.code,details:e?.details,stack:e?.stack}),P(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),D(t)&&(this.errorMessage=_(t),this.errorSeverity=F(t),this.errorAction=z(t))}});try{!this.config.useOwnWallet&&this.pnp&&(await this.pnp.disconnect?.(),this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0})}catch{}}finally{this.processing=!1}}}render(){if(!this.config)return ke`<div class="icpay-card icpay-section">Loading...</div>`;let e=this.selectedSymbol||"ICP",t=typeof this.config?.amountUsd=="number"?`${Number(this.config.amountUsd).toFixed(2)}`:"",a=(this.config?.buttonLabel||(typeof this.config?.amountUsd=="number"?"Pay ${amount} with crypto":"Pay with {symbol}")).replace("{amount}",t||"$0.00").replace("{symbol}",e),o=this.config?.progressBar?.enabled!==!1,c=this.showWalletModal||this.showBalanceModal;return ke`
|
|
1413
|
+
`],s([Ct({type:Object})],b.prototype,"config",2),s([M()],b.prototype,"selectedAmount",2),s([M()],b.prototype,"selectedSymbol",2),s([M()],b.prototype,"raised",2),s([M()],b.prototype,"processing",2),s([M()],b.prototype,"succeeded",2),s([M()],b.prototype,"errorMessage",2),s([M()],b.prototype,"errorSeverity",2),s([M()],b.prototype,"errorAction",2),s([M()],b.prototype,"walletConnected",2),s([M()],b.prototype,"pendingAction",2),s([M()],b.prototype,"showWalletModal",2),s([M()],b.prototype,"oisyReadyToPay",2),s([M()],b.prototype,"lastWalletId",2),s([M()],b.prototype,"showOnrampModal",2),s([M()],b.prototype,"onrampSessionId",2),s([M()],b.prototype,"onrampPaymentIntentId",2),s([M()],b.prototype,"onrampErrorMessage",2),s([M()],b.prototype,"showBalanceModal",2),s([M()],b.prototype,"balancesLoading",2),s([M()],b.prototype,"balancesError",2),s([M()],b.prototype,"walletBalances",2),b=s([Wt("icpay-donation-thermometer")],b);import{LitElement as Tt,html as ke,css as At}from"lit";import{customElement as It,property as Ot,state as S}from"lit/decorators.js";var qe=typeof window<"u",ue=null;function $(i,l,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${l}`,e):console.log(`[ICPay Widget] ${l}`))}var y=class extends Tt{constructor(){super(...arguments);this.selectedSymbol=null;this.processing=!1;this.succeeded=!1;this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.walletModalStep="connect";this.showOnrampModal=!1;this.onrampSessionId=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.oisyReadyToPay=!1;this.oisySignerPreopened=!1;this.skipDisconnectOnce=!1;this.lastWalletId=null;this.showBalanceModal=!1;this.balancesLoading=!1;this.balancesError=null;this.walletBalances=[];this.onrampPollTimer=null;this.transakMessageHandlerBound=null;this.pnp=null;this.oisyConnectRetriedNewTab=!1;this.sdk=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="pay",this.walletModalStep="connect",this.showWalletModal=!0,this.oisyReadyToPay=!1,this.lastWalletId=null,this.requestUpdate();try{let t=Number(this.config?.amountUsd||0),n=this.selectedSymbol||"ICP";window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"pay",type:"sendUsd",amount:t,currency:n}}))}catch{}}catch{}};this.onSelectBalanceSymbol=async e=>{let t=(this.walletBalances||[]).find(a=>a?.tokenShortcode===e);if(t?.ledgerSymbol&&(this.selectedSymbol=t.ledgerSymbol),this.showBalanceModal=!1,this.showWalletModal=!1,R(this.lastWalletId)){$(this.config?.debug||!1,"EVM selection made",{selectedSymbol:this.selectedSymbol,selPresent:!!t,selSnapshot:t?{ledgerId:t?.ledgerId,ledgerSymbol:t?.ledgerSymbol,ledgerName:t?.ledgerName,chainUuid:t?.chainUuid,chainId:t?.chainId,chainName:t?.chainName,x402Accepts:t?.x402Accepts,requiredAmount:t?.requiredAmount,hasSufficientBalance:t?.hasSufficientBalance}:null});let a=t?.chainId;V(a,{chainName:t?.chainName,rpcUrlPublic:t?.rpcUrlPublic,nativeSymbol:t?.ledgerSymbol,decimals:t?.decimals}).then(async()=>{try{let r=this.getSdk(),o=Number(this.config?.amountUsd??0),c=t?.ledgerSymbol,d=!!(t&&t.x402Accepts);if($(this.config?.debug||!1,"EVM post-ensure chain snapshot",{targetChain:a,amountUsd:o,symbolNow:c,tryX402:d,x402Accepts:t?.x402Accepts}),d)try{let h={...this.config?.metadata,network:"evm",ledgerId:t?.ledgerId,chainId:t?.chainUuid,context:"pay-button:x402"};$(this.config?.debug||!1,"Attempting X402 flow (EVM selection)",{amountUsd:o,tokenShortcode:t?.tokenShortcode,x402Accepts:t?.x402Accepts}),await r.client.createPaymentX402Usd({usdAmount:o,tokenShortcode:t?.tokenShortcode,metadata:h});return}catch(h){$(this.config?.debug||!1,"X402 payment failed (EVM selection), falling back",{message:h?.message,code:h?.code,data:h?.details||h?.data})}else $(this.config?.debug||!1,"Skipping X402 path",{reason:t?t.x402Accepts?"unknown":"x402Accepts false":"no selection",selPresent:!!t,x402Accepts:t?.x402Accepts});$(this.config?.debug||!1,"Falling back to normal EVM wallet flow",{amountUsd:o,tokenShortcode:t?.tokenShortcode}),await r.client.createPaymentUsd({usdAmount:o,tokenShortcode:t?.tokenShortcode,metadata:{...this.config?.metadata,network:"evm",ledgerId:t?.ledgerId}})}catch{}});return}let n=this.pendingAction;if(this.pendingAction=null,n==="pay")try{let a=(this.walletBalances||[]).find(c=>c?.tokenShortcode===e),r=this.getSdk(),o=Number(this.config?.amountUsd??0);$(this.config?.debug||!1,"IC selection made",{selectedSymbol:this.selectedSymbol,selPresent:!!a,selSnapshot:a?{ledgerId:a?.ledgerId,ledgerSymbol:a?.ledgerSymbol,ledgerName:a?.ledgerName,requiredAmount:a?.requiredAmount,hasSufficientBalance:a?.hasSufficientBalance,tokenShortcode:a?.tokenShortcode}:null}),await r.client.createPaymentUsd({usdAmount:o,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,network:"ic",ledgerId:a?.ledgerId}})}catch{}}}getSdk(){return this.sdk||(this.sdk=g(this.config)),this.sdk}connectedCallback(){if(super.connectedCallback(),!!qe){$(this.config?.debug||!1,"Pay button connected",{config:this.config});try{window.addEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}try{window.addEventListener("icpay-sdk-transaction-created",(e=>{$(this.config?.debug||!1,"SDK transaction created",{detail:e?.detail}),this.showWalletModal=!1,this.showBalanceModal=!1,this.requestUpdate()}))}catch{}}}updated(e){if(e.has("config")&&this.pendingAction&&this.config?.actorProvider){let t=this.pendingAction;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}this.walletModalStep!=="balances"&&!this.oisyReadyToPay&&(this.pendingAction=null,setTimeout(()=>{t==="pay"&&this.pay()},0))}e.has("config")&&(this.sdk=null)}selectSymbol(e){this.selectedSymbol=e}async ensureWallet(){if(this.config.useOwnWallet)return this.config.actorProvider?!0:(this.pendingAction="pay",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0})),!1);if(this.walletConnected)return!0;try{ue||(ue=(await import("./wallet-select-M5KY6N6N.js")).WalletSelect);let e=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab),t={...this.config?.plugNPlay||{}};this.config?.chainTypes&&(t.chainTypes=this.config.chainTypes);let n=e?U(t):t;try{if(typeof window<"u"){let{resolveDerivationOrigin:r}=await import("./origin-44ZEXSX4.js");n.derivationOrigin=this.config?.derivationOrigin||r()}}catch{}this.pnp=new ue(n);let a=this.pnp.getEnabledWallets();if($(this.config?.debug||!1,"Available wallets",a),!a?.length)throw new Error("No wallets available");return this.pendingAction="pay",this.showWalletModal=!0,!1}catch(e){return this.errorMessage=e instanceof Error?e.message:"Wallet connection failed",this.errorSeverity="error",!1}}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");this.lastWalletId=(e||"").toLowerCase(),this.lastWalletId==="oisy"&&(this.oisyConnectRetriedNewTab=!1),this.pnp.connect(e).then(n=>{if($(this.config?.debug||!1,"Wallet connect result",n),!!!(n&&(n.connected===!0||n.principal||n.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}let r=T(this.pnp,n),o=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(d,h)=>this.pnp.getActor({canisterId:d,idl:h,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{}},this.sdk=null,(e||"").toLowerCase()==="oisy"?(this.oisyReadyToPay=!0,this.pendingAction=null):(this.walletModalStep="balances",this.fetchAndShowBalances("pay"))}).catch(n=>{$(this.config?.debug||!1,"Wallet connection error",n);let a=(e||"").toLowerCase()==="oisy",r=n&&(n.message||String(n))||"";if(a&&!this.oisyConnectRetriedNewTab&&(r.includes("Signer window could not be opened")||r.includes("Communication channel could not be established"))){this.oisyConnectRetriedNewTab=!0,(async()=>{try{ue||(ue=(await import("./wallet-select-M5KY6N6N.js")).WalletSelect);let c={...this.config?.plugNPlay||{}};this.config?.chainTypes&&(c.chainTypes=this.config.chainTypes);let d=U(c);try{if(typeof window<"u"){let{resolveDerivationOrigin:p}=await import("./origin-44ZEXSX4.js");d.derivationOrigin=this.config?.derivationOrigin||p()}}catch{}this.pnp=new ue(d),this.pnp.connect("oisy").then(p=>{if(!!!(p&&(p.connected===!0||p.principal||p.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"oisy"}}))}catch{}let K=T(this.pnp,p),ee=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:K,actorProvider:(C,B)=>this.pnp.getActor({canisterId:C,idl:B,requiresSigning:!0,anon:!1}),...ee?{evmProvider:ee}:{}},this.sdk=null,this.oisyReadyToPay=!0,this.pendingAction=null}).catch(p=>{$(this.config?.debug||!1,"Oisy retry connect (new tab) failed",p),this.errorMessage=p instanceof Error?p.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}})}catch(c){$(this.config?.debug||!1,"Oisy new-tab init failed",c),this.errorMessage=c instanceof Error?c.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}}})();return}this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}})}catch(t){$(this.config?.debug||!1,"Wallet connection error (sync)",t),this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}}}async fetchAndShowBalances(e){try{this.balancesLoading=!0,this.balancesError=null,this.walletModalStep="balances",this.showBalanceModal=!1;let t=this.getSdk(),{balances:n}=await Y({sdk:t,lastWalletId:this.lastWalletId,connectedWallet:this.config?.connectedWallet,amountUsd:Number(this.config?.amountUsd??0),chainShortcodes:this.config?.chainShortcodes,tokenShortcodes:this.config?.tokenShortcodes});this.walletBalances=n,this.pendingAction=e}catch(t){this.walletBalances=[],this.balancesError=t&&(t.message||String(t))||"Failed to load balances"}finally{this.balancesLoading=!1}}renderWalletModal(){if(!this.showWalletModal||!this.pnp)return null;let e=this.pnp.getEnabledWallets()||[],t=G(e),n=this.config?.onramp?.enabled!==!1&&this.config?.onrampDisabled!==!0,a=5,r=Number(this.config?.amountUsd??0),o=n&&r>0&&r<a,c=Math.max(0,a-r),d=o?`Note: Minimum card amount is $${a}. You will pay about $${c.toFixed(2)} more.`:null;return Q({visible:this.showWalletModal,wallets:t,isConnecting:!1,onSwitchAccount:()=>this.onSwitchAccount(null),step:this.walletModalStep,balances:this.walletModalStep==="balances"?this.walletBalances||[]:[],balancesLoading:this.walletModalStep==="balances"?this.balancesLoading:!1,balancesError:this.walletModalStep==="balances"?this.balancesError:null,onSelectBalance:h=>this.onSelectBalanceSymbol(h),onBack:()=>{this.walletModalStep="connect"},onSelect:h=>{this.connectWithWallet(h)},onClose:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-cancelled",{detail:{reason:"user_cancelled"}}))}catch{}},onCreditCard:n?()=>this.startOnramp():void 0,creditCardLabel:this.config?.onramp?.creditCardLabel||"Pay with credit card",showCreditCard:n,creditCardTooltip:d,oisyReadyToPay:this.oisyReadyToPay,onOisyPay:()=>{this.showWalletModal=!1,this.skipDisconnectOnce=!0,this.oisyReadyToPay=!1,this.pay()}})}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1,setTimeout(()=>this.createOnrampIntent(),0)}async createOnrampIntent(){try{let e=Number(this.config?.amountUsd??0),t=this.getSdk();this.selectedSymbol||(this.selectedSymbol="ICP");let n=this.selectedSymbol||"ICP",a=await t.startOnrampUsd(e,n,{context:"pay-button:onramp"}),r=a?.metadata?.onramp?.sessionId||a?.metadata?.onramp?.session_id||null,o=a?.metadata?.onramp?.errorMessage||null;this.onrampErrorMessage=o||null;let c=a?.metadata?.paymentIntentId||a?.paymentIntentId||null;this.onrampPaymentIntentId=c,r?(this.onrampSessionId=r,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.showOnrampModal=!0)}catch(e){this.onrampSessionId=null,this.onrampErrorMessage=e?.message||null,this.showOnrampModal=!0,P(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),D(t)&&(this.errorMessage=_(t),this.errorSeverity=F(t),this.errorAction=z(t))}})}}attachTransakMessageListener(){if(!this.transakMessageHandlerBound){this.transakMessageHandlerBound=e=>this.onTransakMessage(e);try{window.addEventListener("message",this.transakMessageHandlerBound)}catch{}}}detachTransakMessageListener(){if(this.transakMessageHandlerBound){try{window.removeEventListener("message",this.transakMessageHandlerBound)}catch{}this.transakMessageHandlerBound=null}}onTransakMessage(e){let t=e?.data,n=t?.event_id||t?.eventId||t?.id;if(!(!n||typeof n!="string")&&n==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;let a=t?.data?.id||t?.id||t?.webhookData?.id||null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-success",{detail:{name:"getLedgerBalance"}}))}catch{}try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-success",{detail:{name:"sendFundsToLedger"}}))}catch{}try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-success",{detail:{name:"notifyLedgerTransaction"}}))}catch{}this.showOnrampModal=!1,this.startOnrampPolling(a||void 0)}}startOnrampPolling(e){if(this.onrampPollTimer){try{clearInterval(this.onrampPollTimer)}catch{}this.onrampPollTimer=null}if(this.onrampNotifyController){try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null}let t=this.onrampPaymentIntentId;if(!t)return;let n=this.getSdk(),a=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1},r=o=>{a()};try{window.addEventListener("icpay-sdk-transaction-completed",r,{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=n.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}async pay(){if(!(!qe||this.processing)){this.errorMessage=null,this.errorSeverity=null,this.errorAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"pay",type:"sendUsd",amount:this.config?.amountUsd,currency:this.selectedSymbol||"ICP"}}))}catch{}this.processing=!0;try{if(this.skipDisconnectOnce)this.skipDisconnectOnce=!1;else try{!this.config.useOwnWallet&&this.pnp&&(await this.pnp.disconnect?.(),this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0})}catch{}if(!await this.ensureWallet())return;let t=this.getSdk();try{let n=this.config?.connectedWallet,a=this?.pnp?.account;$(this.config?.debug||!1,"Wallet state before payment",{connectedWallet:n,pnpAccount:a,principal:n?.owner||n?.principal||a?.owner||a?.principal||null})}catch{}this.walletModalStep="balances",this.showWalletModal=!0,await this.fetchAndShowBalances("pay");return}catch(e){$(this.config?.debug||!1,"Payment error",{message:e?.message,code:e?.code,details:e?.details,stack:e?.stack}),P(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),D(t)&&(this.errorMessage=_(t),this.errorSeverity=F(t),this.errorAction=z(t))}});try{!this.config.useOwnWallet&&this.pnp&&(await this.pnp.disconnect?.(),this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0})}catch{}}finally{this.processing=!1}}}render(){if(!this.config)return ke`<div class="icpay-card icpay-section">Loading...</div>`;let e=this.selectedSymbol||"ICP",t=typeof this.config?.amountUsd=="number"?`${Number(this.config.amountUsd).toFixed(2)}`:"",a=(this.config?.buttonLabel||(typeof this.config?.amountUsd=="number"?"Pay ${amount} with crypto":"Pay with {symbol}")).replace("{amount}",t||"$0.00").replace("{symbol}",e),o=this.config?.progressBar?.enabled!==!1,c=this.showWalletModal||this.showBalanceModal;return ke`
|
|
1414
1414
|
<div class="icpay-card icpay-section icpay-widget-base">
|
|
1415
1415
|
${o?ke`
|
|
1416
1416
|
<icpay-progress-bar
|
|
@@ -1448,7 +1448,7 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var H=Xe`
|
|
|
1448
1448
|
.error-message.info { background: rgba(59,130,246,0.1); border-color: rgba(59,130,246,0.3); color: #3b82f6; }
|
|
1449
1449
|
.error-message.warning { background: rgba(245,158,11,0.1); border-color: rgba(245,158,11,0.3); color: #f59e0b; }
|
|
1450
1450
|
.error-message.error { background: rgba(239,68,68,0.1); border-color: rgba(239,68,68,0.3); color: #ef4444; }
|
|
1451
|
-
`],s([Ot({type:Object})],y.prototype,"config",2),s([S()],y.prototype,"selectedSymbol",2),s([S()],y.prototype,"processing",2),s([S()],y.prototype,"succeeded",2),s([S()],y.prototype,"errorMessage",2),s([S()],y.prototype,"errorSeverity",2),s([S()],y.prototype,"errorAction",2),s([S()],y.prototype,"walletConnected",2),s([S()],y.prototype,"pendingAction",2),s([S()],y.prototype,"showWalletModal",2),s([S()],y.prototype,"walletModalStep",2),s([S()],y.prototype,"showOnrampModal",2),s([S()],y.prototype,"onrampSessionId",2),s([S()],y.prototype,"onrampPaymentIntentId",2),s([S()],y.prototype,"onrampErrorMessage",2),s([S()],y.prototype,"oisyReadyToPay",2),s([S()],y.prototype,"oisySignerPreopened",2),s([S()],y.prototype,"skipDisconnectOnce",2),s([S()],y.prototype,"lastWalletId",2),s([S()],y.prototype,"showBalanceModal",2),s([S()],y.prototype,"balancesLoading",2),s([S()],y.prototype,"balancesError",2),s([S()],y.prototype,"walletBalances",2),y=s([It("icpay-pay-button")],y);import{LitElement as Lt,html as Me,css as Nt}from"lit";import{customElement as Ut,property as $t,state as W}from"lit/decorators.js";var Ge=typeof window<"u",Ue=null;function Bt(i,l,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${l}`,e):console.log(`[ICPay Widget] ${l}`))}var w=class extends Lt{constructor(){super(...arguments);this.amountUsd=0;this.hasUserAmount=!1;this.selectedSymbol=null;this.processing=!1;this.succeeded=!1;this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.showOnrampModal=!1;this.onrampSessionId=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.transakMessageHandlerBound=null;this.onrampPollTimer=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.showBalanceModal=!1;this.balancesLoading=!1;this.balancesError=null;this.walletBalances=[];this.sdk=null;this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="pay",this.showWalletModal=!0,this.requestUpdate();try{let t=Number(this.amountUsd||0),n=this.selectedSymbol||"ICP";window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"pay",type:"sendUsd",amount:t,currency:n}}))}catch{}}catch{}};this.onSelectBalanceSymbol=async e=>{let t=(this.walletBalances||[]).find(a=>a?.tokenShortcode===e);if(t?.ledgerSymbol&&(this.selectedSymbol=t.ledgerSymbol),R(this.lastWalletId)){let a=(this.walletBalances||[]).find(o=>o?.tokenShortcode===e),r=a?.chainId;V(r,{chainName:a?.chainName,rpcUrlPublic:a?.rpcUrlPublic,nativeSymbol:a?.ledgerSymbol,decimals:a?.decimals}).then(async()=>{try{let o=u(this.config),c=Number(this.amountUsd||0);if(a?.x402Accepts)try{await o.client.createPaymentX402Usd({usdAmount:c,tokenShortcode:a?.tokenShortcode,metadata:{network:"evm",ledgerId:a?.ledgerId,chainId:a?.chainUuid,context:"amount-input:x402"}}),this.showBalanceModal=!1;return}catch{}await o.client.createPaymentUsd({usdAmount:c,tokenShortcode:a?.tokenShortcode,metadata:{network:"evm",ledgerId:a?.ledgerId}})}catch{}this.showBalanceModal=!1});return}this.showBalanceModal=!1;let n=this.pendingAction;if(this.pendingAction=null,n==="pay")try{let a=(this.walletBalances||[]).find(c=>c?.tokenShortcode===e),r=u(this.config),o=Number(this.amountUsd||0);await r.client.createPaymentUsd({usdAmount:o,tokenShortcode:a?.tokenShortcode,metadata:{network:"ic",ledgerId:a?.ledgerId}})}catch{}}}connectedCallback(){if(super.connectedCallback(),!!Ge){Bt(this.config?.debug||!1,"Amount input connected",{config:this.config}),this.amountUsd=Number(this.config?.defaultAmountUsd??0),this.hasUserAmount=!1;try{window.addEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}try{window.addEventListener("icpay-sdk-transaction-created",(()=>{this.showWalletModal=!1,this.requestUpdate()}))}catch{}}}updated(e){if(e.has("config")&&(!this.hasUserAmount&&typeof this.config?.defaultAmountUsd=="number"&&(this.amountUsd===0||this.amountUsd==null||Number.isNaN(this.amountUsd))&&(this.amountUsd=Number(this.config.defaultAmountUsd)),this.pendingAction&&this.config?.actorProvider)){let t=this.pendingAction;this.pendingAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}setTimeout(()=>{t==="pay"&&this.pay()},0)}}onInputChange(e){let t=Number(this.config?.stepUsd??.5),n=Math.max(0,Number(e.target.value||0)),a=Math.round(n/t)*t;this.amountUsd=Number(a.toFixed(2)),this.hasUserAmount=!0}selectSymbol(e){this.selectedSymbol=e}isValidAmount(){let e=Number(this.config?.minUsd??.5),t=this.config?.maxUsd!==void 0?Number(this.config.maxUsd):1/0;return this.amountUsd>=e&&this.amountUsd<=t}async ensureWallet(){if(this.config.useOwnWallet)return this.config.actorProvider?!0:(this.pendingAction="pay",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0})),!1);if(this.walletConnected)return!0;try{Ue||(Ue=(await import("./wallet-select-M5KY6N6N.js")).WalletSelect);let e=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab),t={...this.config?.plugNPlay||{}};this.config?.chainTypes&&(t.chainTypes=this.config.chainTypes);let n=e?U(t):t;try{if(typeof window<"u"){let{resolveDerivationOrigin:r}=await import("./origin-44ZEXSX4.js");n.derivationOrigin=this.config?.derivationOrigin||r()}}catch{}if(this.pnp=new Ue(n),!this.pnp.getEnabledWallets()?.length)throw new Error("No wallets available");return this.pendingAction="pay",this.showWalletModal=!0,!1}catch(e){return this.errorMessage=e instanceof Error?e.message:"Wallet connection failed",this.errorSeverity="error",!1}}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");this.lastWalletId=(e||"").toLowerCase(),this.pnp.connect(e).then(n=>{if(!!!(n&&(n.connected===!0||n.principal||n.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}let r=T(this.pnp,n),o=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(d,h)=>this.pnp.getActor({canisterId:d,idl:h,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{}},this.sdk=null,this.lastWalletId==="oisy"?this.oisyReadyToPay=!0:(this.showWalletModal=!1,this.fetchAndShowBalances())}).catch(n=>{this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}})}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}}}async fetchAndShowBalances(){try{this.balancesLoading=!0,this.balancesError=null,this.showBalanceModal=!0;let e=u(this.config),{balances:t}=await Y({sdk:e,lastWalletId:this.lastWalletId,connectedWallet:this.config?.connectedWallet,amountUsd:Number(this.amountUsd??0),chainShortcodes:this.config?.chainShortcodes,tokenShortcodes:this.config?.tokenShortcodes});this.walletBalances=t}catch(e){this.walletBalances=[],this.balancesError=e&&(e.message||String(e))||"Failed to load balances"}finally{this.balancesLoading=!1}}attachTransakMessageListener(){if(!this.transakMessageHandlerBound){this.transakMessageHandlerBound=e=>this.onTransakMessage(e);try{window.addEventListener("message",this.transakMessageHandlerBound)}catch{}}}detachTransakMessageListener(){if(this.transakMessageHandlerBound){try{window.removeEventListener("message",this.transakMessageHandlerBound)}catch{}this.transakMessageHandlerBound=null}}onTransakMessage(e){let t=e?.data,n=t?.event_id||t?.eventId||t?.id;if(!(!n||typeof n!="string")&&n==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let a=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(a||void 0)}}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1,setTimeout(()=>this.createOnrampIntent(),0)}async createOnrampIntent(){try{let e=u(this.config),t=this.selectedSymbol||"ICP",n=Number(this.amountUsd),a=await e.startOnrampUsd(n,t,{context:"amount-input:onramp"}),r=a?.metadata?.onramp?.sessionId||a?.metadata?.onramp?.session_id||null,o=a?.metadata?.paymentIntentId||a?.paymentIntentId||null,c=a?.metadata?.onramp?.errorMessage||null;this.onrampPaymentIntentId=o,r?(this.onrampSessionId=r,this.onrampErrorMessage=null,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.onrampErrorMessage=c||"Failed to obtain onramp sessionId",this.showOnrampModal=!0)}catch(e){this.onrampSessionId=null,this.onrampErrorMessage=e?.message||"Failed to obtain onramp sessionId",this.showOnrampModal=!0}}startOnrampPolling(e){if(this.onrampPollTimer){try{clearInterval(this.onrampPollTimer)}catch{}this.onrampPollTimer=null}if(this.onrampNotifyController){try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null}let t=this.onrampPaymentIntentId;if(!t)return;let n=u(this.config),a=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>a()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=n.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}async pay(){if(!(!Ge||this.processing)){if(this.errorMessage=null,this.errorSeverity=null,this.errorAction=null,!this.isValidAmount()){this.errorMessage="Please enter a valid amount",this.errorSeverity="warning";return}try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"pay",type:"sendUsd",amount:this.amountUsd,currency:this.selectedSymbol||"ICP"}}))}catch{}this.processing=!0;try{if(!await this.ensureWallet())return;this.showWalletModal=!0,await this.fetchAndShowBalances();return}catch(e){P(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),D(t)&&(this.errorMessage=_(t),this.errorSeverity=F(t),this.errorAction=z(t))}});try{!this.config.useOwnWallet&&this.pnp&&(await this.pnp.disconnect?.(),this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0})}catch{}}finally{this.processing=!1}}}render(){if(!this.config)return Me`<div class="icpay-card icpay-section">Loading...</div>`;let e=this.config?.placeholder||"Enter amount in USD",n=(this.config?.buttonLabel||"Pay ${amount} with crypto").replace("{amount}",this.amountUsd?`${Number(this.amountUsd).toFixed(2)}`:"$0.00").replace("{symbol}",this.selectedSymbol||"ICP"),a=this.selectedSymbol||"ICP",o=this.config?.progressBar?.enabled!==!1;return Me`
|
|
1451
|
+
`],s([Ot({type:Object})],y.prototype,"config",2),s([S()],y.prototype,"selectedSymbol",2),s([S()],y.prototype,"processing",2),s([S()],y.prototype,"succeeded",2),s([S()],y.prototype,"errorMessage",2),s([S()],y.prototype,"errorSeverity",2),s([S()],y.prototype,"errorAction",2),s([S()],y.prototype,"walletConnected",2),s([S()],y.prototype,"pendingAction",2),s([S()],y.prototype,"showWalletModal",2),s([S()],y.prototype,"walletModalStep",2),s([S()],y.prototype,"showOnrampModal",2),s([S()],y.prototype,"onrampSessionId",2),s([S()],y.prototype,"onrampPaymentIntentId",2),s([S()],y.prototype,"onrampErrorMessage",2),s([S()],y.prototype,"oisyReadyToPay",2),s([S()],y.prototype,"oisySignerPreopened",2),s([S()],y.prototype,"skipDisconnectOnce",2),s([S()],y.prototype,"lastWalletId",2),s([S()],y.prototype,"showBalanceModal",2),s([S()],y.prototype,"balancesLoading",2),s([S()],y.prototype,"balancesError",2),s([S()],y.prototype,"walletBalances",2),y=s([It("icpay-pay-button")],y);import{LitElement as Lt,html as Me,css as Nt}from"lit";import{customElement as Ut,property as $t,state as W}from"lit/decorators.js";var Ge=typeof window<"u",Ue=null;function Bt(i,l,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${l}`,e):console.log(`[ICPay Widget] ${l}`))}var w=class extends Lt{constructor(){super(...arguments);this.amountUsd=0;this.hasUserAmount=!1;this.selectedSymbol=null;this.processing=!1;this.succeeded=!1;this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.showOnrampModal=!1;this.onrampSessionId=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.transakMessageHandlerBound=null;this.onrampPollTimer=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.showBalanceModal=!1;this.balancesLoading=!1;this.balancesError=null;this.walletBalances=[];this.sdk=null;this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="pay",this.showWalletModal=!0,this.requestUpdate();try{let t=Number(this.amountUsd||0),n=this.selectedSymbol||"ICP";window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"pay",type:"sendUsd",amount:t,currency:n}}))}catch{}}catch{}};this.onSelectBalanceSymbol=async e=>{let t=(this.walletBalances||[]).find(a=>a?.tokenShortcode===e);if(t?.ledgerSymbol&&(this.selectedSymbol=t.ledgerSymbol),R(this.lastWalletId)){let a=(this.walletBalances||[]).find(o=>o?.tokenShortcode===e),r=a?.chainId;V(r,{chainName:a?.chainName,rpcUrlPublic:a?.rpcUrlPublic,nativeSymbol:a?.ledgerSymbol,decimals:a?.decimals}).then(async()=>{try{let o=g(this.config),c=Number(this.amountUsd||0);if(a?.x402Accepts)try{await o.client.createPaymentX402Usd({usdAmount:c,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,network:"evm",ledgerId:a?.ledgerId,chainId:a?.chainUuid,context:"amount-input:x402"}}),this.showBalanceModal=!1;return}catch{}await o.client.createPaymentUsd({usdAmount:c,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,network:"evm",ledgerId:a?.ledgerId}})}catch{}this.showBalanceModal=!1});return}this.showBalanceModal=!1;let n=this.pendingAction;if(this.pendingAction=null,n==="pay")try{let a=(this.walletBalances||[]).find(c=>c?.tokenShortcode===e),r=g(this.config),o=Number(this.amountUsd||0);await r.client.createPaymentUsd({usdAmount:o,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,network:"ic",ledgerId:a?.ledgerId}})}catch{}}}connectedCallback(){if(super.connectedCallback(),!!Ge){Bt(this.config?.debug||!1,"Amount input connected",{config:this.config}),this.amountUsd=Number(this.config?.defaultAmountUsd??0),this.hasUserAmount=!1;try{window.addEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}try{window.addEventListener("icpay-sdk-transaction-created",(()=>{this.showWalletModal=!1,this.requestUpdate()}))}catch{}}}updated(e){if(e.has("config")&&(!this.hasUserAmount&&typeof this.config?.defaultAmountUsd=="number"&&(this.amountUsd===0||this.amountUsd==null||Number.isNaN(this.amountUsd))&&(this.amountUsd=Number(this.config.defaultAmountUsd)),this.pendingAction&&this.config?.actorProvider)){let t=this.pendingAction;this.pendingAction=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}setTimeout(()=>{t==="pay"&&this.pay()},0)}}onInputChange(e){let t=Number(this.config?.stepUsd??.5),n=Math.max(0,Number(e.target.value||0)),a=Math.round(n/t)*t;this.amountUsd=Number(a.toFixed(2)),this.hasUserAmount=!0}selectSymbol(e){this.selectedSymbol=e}isValidAmount(){let e=Number(this.config?.minUsd??.5),t=this.config?.maxUsd!==void 0?Number(this.config.maxUsd):1/0;return this.amountUsd>=e&&this.amountUsd<=t}async ensureWallet(){if(this.config.useOwnWallet)return this.config.actorProvider?!0:(this.pendingAction="pay",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0})),!1);if(this.walletConnected)return!0;try{Ue||(Ue=(await import("./wallet-select-M5KY6N6N.js")).WalletSelect);let e=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab),t={...this.config?.plugNPlay||{}};this.config?.chainTypes&&(t.chainTypes=this.config.chainTypes);let n=e?U(t):t;try{if(typeof window<"u"){let{resolveDerivationOrigin:r}=await import("./origin-44ZEXSX4.js");n.derivationOrigin=this.config?.derivationOrigin||r()}}catch{}if(this.pnp=new Ue(n),!this.pnp.getEnabledWallets()?.length)throw new Error("No wallets available");return this.pendingAction="pay",this.showWalletModal=!0,!1}catch(e){return this.errorMessage=e instanceof Error?e.message:"Wallet connection failed",this.errorSeverity="error",!1}}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");this.lastWalletId=(e||"").toLowerCase(),this.pnp.connect(e).then(n=>{if(!!!(n&&(n.connected===!0||n.principal||n.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}let r=T(this.pnp,n),o=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(d,h)=>this.pnp.getActor({canisterId:d,idl:h,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{}},this.sdk=null,this.lastWalletId==="oisy"?this.oisyReadyToPay=!0:(this.showWalletModal=!1,this.fetchAndShowBalances())}).catch(n=>{this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}})}catch(t){this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}}}async fetchAndShowBalances(){try{this.balancesLoading=!0,this.balancesError=null,this.showBalanceModal=!0;let e=g(this.config),{balances:t}=await Y({sdk:e,lastWalletId:this.lastWalletId,connectedWallet:this.config?.connectedWallet,amountUsd:Number(this.amountUsd??0),chainShortcodes:this.config?.chainShortcodes,tokenShortcodes:this.config?.tokenShortcodes});this.walletBalances=t}catch(e){this.walletBalances=[],this.balancesError=e&&(e.message||String(e))||"Failed to load balances"}finally{this.balancesLoading=!1}}attachTransakMessageListener(){if(!this.transakMessageHandlerBound){this.transakMessageHandlerBound=e=>this.onTransakMessage(e);try{window.addEventListener("message",this.transakMessageHandlerBound)}catch{}}}detachTransakMessageListener(){if(this.transakMessageHandlerBound){try{window.removeEventListener("message",this.transakMessageHandlerBound)}catch{}this.transakMessageHandlerBound=null}}onTransakMessage(e){let t=e?.data,n=t?.event_id||t?.eventId||t?.id;if(!(!n||typeof n!="string")&&n==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let a=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(a||void 0)}}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1,setTimeout(()=>this.createOnrampIntent(),0)}async createOnrampIntent(){try{let e=g(this.config),t=this.selectedSymbol||"ICP",n=Number(this.amountUsd),a=await e.startOnrampUsd(n,t,{context:"amount-input:onramp"}),r=a?.metadata?.onramp?.sessionId||a?.metadata?.onramp?.session_id||null,o=a?.metadata?.paymentIntentId||a?.paymentIntentId||null,c=a?.metadata?.onramp?.errorMessage||null;this.onrampPaymentIntentId=o,r?(this.onrampSessionId=r,this.onrampErrorMessage=null,this.showOnrampModal=!0,this.attachTransakMessageListener()):(this.onrampSessionId=null,this.onrampErrorMessage=c||"Failed to obtain onramp sessionId",this.showOnrampModal=!0)}catch(e){this.onrampSessionId=null,this.onrampErrorMessage=e?.message||"Failed to obtain onramp sessionId",this.showOnrampModal=!0}}startOnrampPolling(e){if(this.onrampPollTimer){try{clearInterval(this.onrampPollTimer)}catch{}this.onrampPollTimer=null}if(this.onrampNotifyController){try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null}let t=this.onrampPaymentIntentId;if(!t)return;let n=g(this.config),a=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>a()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=n.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}async pay(){if(!(!Ge||this.processing)){if(this.errorMessage=null,this.errorSeverity=null,this.errorAction=null,!this.isValidAmount()){this.errorMessage="Please enter a valid amount",this.errorSeverity="warning";return}try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"pay",type:"sendUsd",amount:this.amountUsd,currency:this.selectedSymbol||"ICP"}}))}catch{}this.processing=!0;try{if(!await this.ensureWallet())return;this.showWalletModal=!0,await this.fetchAndShowBalances();return}catch(e){P(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),D(t)&&(this.errorMessage=_(t),this.errorSeverity=F(t),this.errorAction=z(t))}});try{!this.config.useOwnWallet&&this.pnp&&(await this.pnp.disconnect?.(),this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0})}catch{}}finally{this.processing=!1}}}render(){if(!this.config)return Me`<div class="icpay-card icpay-section">Loading...</div>`;let e=this.config?.placeholder||"Enter amount in USD",n=(this.config?.buttonLabel||"Pay ${amount} with crypto").replace("{amount}",this.amountUsd?`${Number(this.amountUsd).toFixed(2)}`:"$0.00").replace("{symbol}",this.selectedSymbol||"ICP"),a=this.selectedSymbol||"ICP",o=this.config?.progressBar?.enabled!==!1;return Me`
|
|
1452
1452
|
<div class="icpay-card icpay-section icpay-widget-base">
|
|
1453
1453
|
${o?Me`
|
|
1454
1454
|
<icpay-progress-bar
|
|
@@ -1507,5 +1507,5 @@ import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var H=Xe`
|
|
|
1507
1507
|
@media (max-width: 520px) {
|
|
1508
1508
|
.top-row { grid-template-columns: 1fr; }
|
|
1509
1509
|
}
|
|
1510
|
-
`],s([$t({type:Object})],w.prototype,"config",2),s([W()],w.prototype,"amountUsd",2),s([W()],w.prototype,"hasUserAmount",2),s([W()],w.prototype,"selectedSymbol",2),s([W()],w.prototype,"processing",2),s([W()],w.prototype,"succeeded",2),s([W()],w.prototype,"errorMessage",2),s([W()],w.prototype,"errorSeverity",2),s([W()],w.prototype,"errorAction",2),s([W()],w.prototype,"walletConnected",2),s([W()],w.prototype,"pendingAction",2),s([W()],w.prototype,"showWalletModal",2),s([W()],w.prototype,"showOnrampModal",2),s([W()],w.prototype,"onrampSessionId",2),s([W()],w.prototype,"onrampPaymentIntentId",2),s([W()],w.prototype,"onrampErrorMessage",2),s([W()],w.prototype,"oisyReadyToPay",2),s([W()],w.prototype,"lastWalletId",2),s([W()],w.prototype,"showBalanceModal",2),s([W()],w.prototype,"balancesLoading",2),s([W()],w.prototype,"balancesError",2),s([W()],w.prototype,"walletBalances",2),w=s([Ut("icpay-amount-input")],w);export{H as a,Ie as b,
|
|
1511
|
-
//# sourceMappingURL=chunk-
|
|
1510
|
+
`],s([$t({type:Object})],w.prototype,"config",2),s([W()],w.prototype,"amountUsd",2),s([W()],w.prototype,"hasUserAmount",2),s([W()],w.prototype,"selectedSymbol",2),s([W()],w.prototype,"processing",2),s([W()],w.prototype,"succeeded",2),s([W()],w.prototype,"errorMessage",2),s([W()],w.prototype,"errorSeverity",2),s([W()],w.prototype,"errorAction",2),s([W()],w.prototype,"walletConnected",2),s([W()],w.prototype,"pendingAction",2),s([W()],w.prototype,"showWalletModal",2),s([W()],w.prototype,"showOnrampModal",2),s([W()],w.prototype,"onrampSessionId",2),s([W()],w.prototype,"onrampPaymentIntentId",2),s([W()],w.prototype,"onrampErrorMessage",2),s([W()],w.prototype,"oisyReadyToPay",2),s([W()],w.prototype,"lastWalletId",2),s([W()],w.prototype,"showBalanceModal",2),s([W()],w.prototype,"balancesLoading",2),s([W()],w.prototype,"balancesError",2),s([W()],w.prototype,"walletBalances",2),w=s([Ut("icpay-amount-input")],w);export{H as a,Ie as b,g as c,q as d,E as e,v as f,u as g,x as h,b as i,y as j,w as k};
|
|
1511
|
+
//# sourceMappingURL=chunk-OCJP7SJM.js.map
|