@ic-pay/icpay-widget 1.2.83 → 1.2.87
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{amount-input-CxXtbYPB.d.ts → amount-input-3JvxFvnp.d.ts} +3 -2
- package/dist/{chunk-RA6KGDIL.js → chunk-5UZLVWIN.js} +147 -103
- package/dist/chunk-5UZLVWIN.js.map +1 -0
- package/dist/index.d.ts +6 -4
- package/dist/index.js +1 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/react/index.js +1 -1
- package/package.json +6 -3
- package/dist/chunk-RA6KGDIL.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as r}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var
|
|
1
|
+
import{a as r}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var K=Xe`
|
|
2
2
|
:host {
|
|
3
3
|
/* Light mode defaults (from COLOR_PALETTE.md) */
|
|
4
4
|
--icpay-background: #ffffff;
|
|
@@ -113,7 +113,7 @@ import{a as r}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var j=Xe`
|
|
|
113
113
|
width: 100%;
|
|
114
114
|
background: var(--icpay-foreground);
|
|
115
115
|
color: var(--icpay-background);
|
|
116
|
-
border:
|
|
116
|
+
border: none;
|
|
117
117
|
border-radius: 16px;
|
|
118
118
|
padding: 16px;
|
|
119
119
|
font-size: 16px;
|
|
@@ -123,6 +123,10 @@ import{a as r}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var j=Xe`
|
|
|
123
123
|
box-shadow: none;
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
+
:host([data-theme="dark"]) .pay-button {
|
|
127
|
+
border: 1px solid var(--icpay-border);
|
|
128
|
+
}
|
|
129
|
+
|
|
126
130
|
.pay-button:hover {
|
|
127
131
|
background: color-mix(in srgb, var(--icpay-foreground) 90%, transparent);
|
|
128
132
|
}
|
|
@@ -139,7 +143,7 @@ import{a as r}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var j=Xe`
|
|
|
139
143
|
0%, 100% { opacity: 1; }
|
|
140
144
|
50% { opacity: 0.7; }
|
|
141
145
|
}
|
|
142
|
-
`;function Te(i,s){if(!i)return;let e="light";if(s?.mode)e=s.mode;else if(typeof document<"u"){let a=document.documentElement.getAttribute("data-icpay-theme")||document.documentElement.getAttribute("data-theme");(a==="light"||a==="dark")&&(e=a)}if(!s){i instanceof HTMLElement&&i.setAttribute("data-theme",e),typeof document<"u"&&document.documentElement&&(document.documentElement.setAttribute("data-icpay-theme",e),document.documentElement.style.setProperty("--icpay-theme-mode",e));return}i instanceof HTMLElement&&i.setAttribute("data-theme",e),typeof document<"u"&&document.documentElement&&(document.documentElement.setAttribute("data-icpay-theme",e),document.documentElement.style.setProperty("--icpay-theme-mode",e));let t=(a,n)=>{n&&i.style.setProperty(a,n)};s.primaryColor&&t("--icpay-primary",s.primaryColor),s.secondaryColor&&t("--icpay-secondary",s.secondaryColor),s.accentColor&&t("--icpay-accent",s.accentColor),s.textColor&&t("--icpay-foreground",s.textColor),s.mutedTextColor&&t("--icpay-muted-foreground",s.mutedTextColor),s.surfaceColor&&t("--icpay-background",s.surfaceColor),s.surfaceAltColor&&t("--icpay-secondary",s.surfaceAltColor),s.borderColor&&t("--icpay-border",s.borderColor),s.fontFamily&&t("--icpay-font",s.fontFamily),s.textColor&&t("--icpay-text",s.textColor),s.mutedTextColor&&t("--icpay-muted",s.mutedTextColor),s.surfaceAltColor&&t("--icpay-surface-alt",s.surfaceAltColor)}import{Icpay as $e}from"@ic-pay/icpay-sdk";var Ie=typeof window<"u";function ne(i,s,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${s}`,e):console.log(`[ICPay Widget] ${s}`))}function u(i){if(!Ie)return{client:{},quoteUsd:async()=>({tokenAmountDecimals:"0"}),sendUsd:async()=>({transactionId:"0",status:"pending"}),startOnrampUsd:async()=>({transactionId:"0",status:"pending",metadata:{icpay_onramp:{sessionId:null}}}),notifyIntentUntilComplete:()=>({stop:()=>{}})};ne(i.debug||!1,"Creating SDK with config:",i);let s={publishableKey:i.publishableKey};i.enableEvents!==void 0?s.enableEvents=i.enableEvents:s.enableEvents=!0,i.apiUrl&&(s.apiUrl=i.apiUrl),i.icHost&&(s.icHost=i.icHost),i.actorProvider&&(s.actorProvider=i.actorProvider),i.connectedWallet&&(s.connectedWallet=i.connectedWallet),i.evmProvider&&(s.evmProvider=i.evmProvider),i.solanaProvider&&(s.solanaProvider=i.solanaProvider),i.onrampDisabled!==void 0&&(s.onrampDisabled=i.onrampDisabled),i.debug!==void 0&&(s.debug=i.debug),ne(i.debug||!1,"Filtered SDK config:",s);try{let l=function(d,p,h){return t.notifyPaymentIntentOnRamp({paymentIntentId:d,intervalMs:p,orderId:h})};var e=l;ne(i.debug||!1,"typeof Icpay:",typeof $e);let t=new $e(s);if(Ie){let d=t,p=h=>{d.addEventListener(h,c=>{window.dispatchEvent(new CustomEvent(h,{detail:c?.detail??c}))})};["icpay-sdk-error","icpay-sdk-transaction-created","icpay-sdk-transaction-updated","icpay-sdk-transaction-completed","icpay-sdk-transaction-failed","icpay-sdk-method-start","icpay-sdk-method-success","icpay-sdk-method-error"].forEach(p)}async function a(d,p,h){if(typeof p=="string"&&p.trim().length>0)return t.calculateTokenAmountFromUSD({usdAmount:d,tokenShortcode:p.toLowerCase()});if(typeof h=="string"&&h.trim().length>0)return t.calculateTokenAmountFromUSD({usdAmount:d,ledgerCanisterId:h});throw new Error("quoteUsd requires tokenShortcode or ledgerCanisterId")}async function n(d,p,h,c){let y={...i.metadata,...h||{}};i.externalCostAmount!=null&&y.externalCostAmount==null&&(y.externalCostAmount=i.externalCostAmount);let g=`Pay ${d} with crypto`,I=i.description||y.__description||y.description||g,Z={usdAmount:d,metadata:y,description:I,recipientAddresses:i.recipientAddresses,recipientAddress:i.recipientAddress};if(typeof p=="string"&&p.trim().length>0&&(Z.tokenShortcode=p.toLowerCase()),typeof c=="string"&&c.trim().length>0&&(Z.ledgerCanisterId=c),!Z.tokenShortcode&&!Z.ledgerCanisterId)throw new Error("sendUsd requires tokenShortcode or ledgerCanisterId");return ne(!!i.debug,"Calling createPaymentUsd (flow decision handled by components)",Z),t.createPaymentUsd(Z)}async function o(d,p,h){let c={...i.metadata,...h||{}},y=`Pay ${d} with crypto`,g=i.description||c.__description||c.description||y;return ne(!!i.debug,"Calling onramp createPaymentUsd",{usdAmount:d,ledgerCanisterId:p,description:g}),t.createPaymentUsd({usdAmount:d,ledgerCanisterId:p,metadata:c,onrampPayment:!0,description:g,recipientAddresses:i.recipientAddresses,recipientAddress:""})}return{client:t,quoteUsd:a,sendUsd:n,startOnrampUsd:o,notifyIntentUntilComplete:l}}catch(t){throw ne(i.debug||!1,"Error creating SDK:",t),t}}import{LitElement as Ye,html as P,css as Ge}from"lit";import{customElement as Qe,property as ae,state as R}from"lit/decorators.js";function v(i,s,e){i&&(e!==void 0?console.log(s,e):console.log(s))}var Ze=[{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"}],b=class extends Ye{constructor(){super(...arguments);this.open=!1;this.suspended=!1;this.steps=Ze;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.isOnrampFlow=!1;this.onMethodStart=e=>{let t=e?.detail?.name||"",a=e?.detail?.type||"";if(v(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(n=>({...n,status:"pending"})),a==="onramp"){this.isOnrampFlow=!0;let n={wallet:{label:"Payment initiated",tooltip:"Please pay in the new tab"},await:{label:"Onramp process started",tooltip:"Verifying funds with provider"},transfer:{label:"Funds received",tooltip:"Payment in progress"},verify:{label:"Payment completed",tooltip:"Finalizing your payment"}};this.currentSteps=this.currentSteps.map(o=>n[o.key]?{...o,label:n[o.key].label,tooltip:n[o.key].tooltip}:o)}this.setLoadingByKey("wallet"),e?.detail?.amount!==void 0&&(this.currentAmount=e.detail.amount,this.amount=e.detail.amount,v(this.debug,"ICPay Progress: Amount updated to:",e.detail.amount)),e?.detail?.currency&&(this.currentCurrency=e.detail.currency,this.currency=e.detail.currency,v(this.debug,"ICPay Progress: Currency updated to:",e.detail.currency)),e?.detail?.ledgerSymbol&&(this.currentLedgerSymbol=e.detail.ledgerSymbol,this.ledgerSymbol=e.detail.ledgerSymbol,v(this.debug,"ICPay Progress: Current state after method start:",{activeIndex:this.activeIndex,currentAmount:this.currentAmount,currentCurrency:this.currentCurrency,currentLedgerSymbol:this.currentLedgerSymbol})),v(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||"";if((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){if(this.isOnrampFlow)return;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;if(v(this.debug,"ICPay Progress: Transaction created event received:",e.detail),!this.failed&&!this.completed){if(this.isOnrampFlow)return;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",a=e?.detail?.transactionId||e?.detail?.id,n=e?.detail?.metadata||e?.detail?.intent?.metadata||{};if(v(this.debug,"ICPay Progress: Transaction updated event received:",e.detail),!this.failed&&!this.completed&&this.isOnrampFlow){let o=n?.onramp_order_completed===!0||n?.icpay_onramp?.status==="completed"||n?.onrampCompleted===!0;t==="requires_payment"&&!o?(this.completeByKey("wallet"),this.setLoadingByKey("await")):(t==="pending"||t==="processing"||o)&&(this.completeByKey("wallet"),this.completeByKey("await"),this.setLoadingByKey("transfer"))}this.dispatchEvent(new CustomEvent("icpay-progress-transaction-updated",{detail:{status:t,transactionId:a,step:this.activeIndex},bubbles:!0}))};this.onTransactionCompleted=e=>{let t=e?.detail?.transactionId||e?.detail?.id,a=e?.detail?.status||"completed";v(this.debug,"ICPay Progress: Transaction completed event received:",e.detail),v(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.isOnrampFlow=!1,this.dispatchEvent(new CustomEvent("icpay-progress-completed",{detail:{transactionId:t,status:a,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",a=e?.detail?.error?.code||e?.detail?.code||"UNKNOWN_ERROR",n=e?.detail?.transactionId||e?.detail?.id;v(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.isOnrampFlow=!1,this.dispatchEvent(new CustomEvent("icpay-progress-failed",{detail:{errorMessage:t,errorCode:a,transactionId:n,step:this.activeIndex},bubbles:!0}))};this.onTransactionMismatched=e=>{let t=e?.detail?.requestedAmount,a=e?.detail?.paidAmount,n=e?.detail?.transactionId||e?.detail?.id;this.failed=!0;let o=t!=null?String(t):"unknown",l=a!=null?String(a):"unknown";this.errorMessage=`Amount mismatch. Requested ${o}, paid ${l}.`,this.showSuccess=!1,this.updateStepStatus(this.activeIndex,"error",this.errorMessage),this.stopAutomaticProgression(),this.open=!0,this.isOnrampFlow=!1,this.dispatchEvent(new CustomEvent("icpay-progress-failed",{detail:{errorMessage:this.errorMessage,errorCode:"MISMATCHED_AMOUNT",transactionId:n,step:this.activeIndex,requestedAmount:t,paidAmount:a},bubbles:!0}))};this.onMethodError=e=>{let t=e?.detail?.name||"",a=e?.detail?.error?.message||e?.detail?.message||"An error occurred",n=e?.detail?.error?.code||e?.detail?.code||"METHOD_ERROR";v(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(a),this.showSuccess=!1,this.updateStepStatus(this.activeIndex,"error",a),this.stopAutomaticProgression(),this.open=!0,this.isOnrampFlow=!1,this.dispatchEvent(new CustomEvent("icpay-progress-error",{detail:{methodName:t,errorMessage:a,errorCode:n,step:this.activeIndex},bubbles:!0})))};this.onSDKError=e=>{let t=e?.detail?.message||"SDK error occurred",a=e?.detail?.code||"SDK_ERROR";v(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.isOnrampFlow=!1,this.dispatchEvent(new CustomEvent("icpay-progress-sdk-error",{detail:{errorMessage:t,errorCode:a,step:this.activeIndex},bubbles:!0}))};this.onWalletConnected=e=>{let t=e?.detail?.walletType||"unknown";v(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.onOnrampOpened=e=>{!this.isOnrampFlow||this.failed||this.completed||(this.completeByKey("wallet"),this.setLoadingByKey("await"))};this.onWalletDisconnected=e=>{let t=e?.detail?.walletType||"unknown";v(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,a=e?.detail?.balance||0;v(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:a,required:this.currentAmount||this.amount,step:this.activeIndex},bubbles:!0})))};this.onLedgerVerified=e=>{let t=e?.detail?.ledgerId||e?.detail?.canisterId,a=e?.detail?.symbol||"unknown";v(this.debug,"ICPay Progress: Ledger verified event received:",e.detail),a&&a!=="unknown"&&(this.currentLedgerSymbol=a,this.ledgerSymbol=a),this.dispatchEvent(new CustomEvent("icpay-progress-ledger-verified",{detail:{ledgerId:t,symbol:a,step:this.activeIndex},bubbles:!0}))};this.onWidgetPayment=e=>{let t=e?.detail?.amount,a=e?.detail?.currency,n=e?.detail?.ledgerSymbol;if(v(this.debug,"ICPay Progress: Widget payment event received:",e.detail),t!==void 0&&(this.currentAmount=t,this.amount=t),a&&(this.currentCurrency=a,this.currency=a),n&&(this.currentLedgerSymbol=n,this.ledgerSymbol=n),!this.failed){for(let o=this.activeIndex;o<this.currentSteps.length;o++)this.updateStepStatus(o,"completed");this.activeIndex=this.currentSteps.length-1,this.completed=!0,this.showSuccess=!0,this.showConfetti=!0}this.dispatchEvent(new CustomEvent("icpay-progress-widget-payment",{detail:{amount:t,currency:a,ledgerSymbol:n,step:this.activeIndex},bubbles:!0}))};this.onWidgetError=e=>{let t=e?.detail?.message||"Widget error occurred",a=e?.detail?.code||"WIDGET_ERROR";v(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:a,step:this.activeIndex},bubbles:!0}))};this.onWidgetUnlock=e=>{let t=e?.detail?.amount,a=e?.detail?.currency;if(v(this.debug,"ICPay Progress: Widget unlock event received:",e.detail),!this.failed){for(let n=this.activeIndex;n<this.currentSteps.length;n++)this.updateStepStatus(n,"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:a,step:this.activeIndex},bubbles:!0}))};this.onWidgetTip=e=>{let t=e?.detail?.amount,a=e?.detail?.currency;if(v(this.debug,"ICPay Progress: Widget tip event received:",e.detail),!this.failed){for(let n=this.activeIndex;n<this.currentSteps.length;n++)this.updateStepStatus(n,"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:a,step:this.activeIndex},bubbles:!0}))};this.onWidgetDonation=e=>{let t=e?.detail?.amount,a=e?.detail?.currency;if(v(this.debug,"ICPay Progress: Widget donation event received:",e.detail),!this.failed){for(let n=this.activeIndex;n<this.currentSteps.length;n++)this.updateStepStatus(n,"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:a,step:this.activeIndex},bubbles:!0}))};this.onWidgetCoffee=e=>{let t=e?.detail?.amount,a=e?.detail?.currency;if(v(this.debug,"ICPay Progress: Widget coffee event received:",e.detail),!this.failed){for(let n=this.activeIndex;n<this.currentSteps.length;n++)this.updateStepStatus(n,"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:a,step:this.activeIndex},bubbles:!0}))};this.onWalletCancelled=e=>{try{let t=this.getStepIndexByKey("wallet"),a=this.getStepIndexByKey("await"),n=this.getStepIndexByKey("transfer"),o=this.getStepIndexByKey("verify"),l=this.currentSteps&&this.currentSteps.length>0&&this.currentSteps.some((h,c)=>t>=0&&c>t?h.status==="loading"||h.status==="completed":!1),p=(t>=0?this.currentSteps[t]:null)?.status==="completed";if(!l&&!p){this.open=!1,this.activeIndex=0,this.currentSteps=this.currentSteps.map(h=>({...h,status:"pending"})),this.requestUpdate();return}this.open=!0,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",a=this.transformErrorMessage(t);this.open=!0;let n=this.getStepIndexByKey("wallet");n>=0&&(this.activeIndex=n,this.currentSteps[n]={...this.currentSteps[n],tooltip:"Wallet connection failed",status:"error",errorMessage:a},this.requestUpdate())}catch{}}}connectedCallback(){super.connectedCallback();try{if(Te(this,this.theme),!this.theme&&typeof document<"u"){let e=document.documentElement.getAttribute("data-icpay-theme")||document.documentElement.getAttribute("data-theme");e==="light"||e==="dark"?this.setAttribute("data-theme",e):this.setAttribute("data-theme","light")}}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{if(Te(this,this.theme),!this.theme&&typeof document<"u"){let t=document.documentElement.getAttribute("data-icpay-theme")||document.documentElement.getAttribute("data-theme");t==="light"||t==="dark"?this.setAttribute("data-theme",t):this.setAttribute("data-theme","light")}}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-onramp-opened",this.onOnrampOpened),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-onramp-opened",this.onOnrampOpened),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"),v(this.debug,"ICPay Progress: Starting automatic progression from step:",this.activeIndex),this.progressionTimer=setInterval(()=>{if(this.failed||this.completed){this.stopAutomaticProgression();return}v(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"),v(this.debug,"ICPay Progress: Auto-progressed to step:",this.activeIndex)):(this.stopAutomaticProgression(),v(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,a){if(e>=0&&e<this.currentSteps.length){let n=this.currentSteps[e],o=n.status;n.status=t,t==="completed"&&(n.timestamp=this.getCurrentTime()),t==="error"&&a&&(n.errorMessage=this.transformErrorMessage(a)),o!==t&&v(this.debug,`ICPay Progress: Step ${e} (${n.label}) status changed from ${o} to ${t}`),this.requestUpdate()}}getCurrentTime(){return new Date().toLocaleTimeString("en-US",{hour12:!1,hour:"2-digit",minute:"2-digit",second:"2-digit"})}getStepIcon(e){return e.status==="error"?P`<div class="error-x">✕</div>`:P`<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},(a,n)=>n),t=["#0066FF","#ef4444","#10b981","#f59e0b","#8b5cf6"];return P`
|
|
146
|
+
`;function zt(i){return typeof i=="string"?i:i&&typeof i=="object"&&i.mode?i.mode:"light"}function oe(i,l){if(!i)return;let e=null,t="light";if(typeof l=="string")t=l,e={mode:t};else if(l&&typeof l=="object")e=l,t=l.mode||"light";else if(typeof document<"u"){let n=document.documentElement.getAttribute("data-icpay-theme")||document.documentElement.getAttribute("data-theme");(n==="light"||n==="dark")&&(t=n)}if(i instanceof HTMLElement&&i.setAttribute("data-theme",t),typeof document<"u"&&document.documentElement&&(document.documentElement.setAttribute("data-icpay-theme",t),document.documentElement.style.setProperty("--icpay-theme-mode",t)),!e)return;let a=(n,s)=>{s&&i.style.setProperty(n,s)};e.primaryColor&&a("--icpay-primary",e.primaryColor),e.secondaryColor&&a("--icpay-secondary",e.secondaryColor),e.accentColor&&a("--icpay-accent",e.accentColor),e.textColor&&a("--icpay-foreground",e.textColor),e.mutedTextColor&&a("--icpay-muted-foreground",e.mutedTextColor),e.surfaceColor&&a("--icpay-background",e.surfaceColor),e.surfaceAltColor&&a("--icpay-secondary",e.surfaceAltColor),e.borderColor&&a("--icpay-border",e.borderColor),e.fontFamily&&a("--icpay-font",e.fontFamily),e.textColor&&a("--icpay-text",e.textColor),e.mutedTextColor&&a("--icpay-muted",e.mutedTextColor),e.surfaceAltColor&&a("--icpay-surface-alt",e.surfaceAltColor)}import{Icpay as $e}from"@ic-pay/icpay-sdk";var Ie=typeof window<"u";function le(i,l,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${l}`,e):console.log(`[ICPay Widget] ${l}`))}function g(i){if(!Ie)return{client:{},quoteUsd:async()=>({tokenAmountDecimals:"0"}),sendUsd:async()=>({transactionId:"0",status:"pending"}),startOnrampUsd:async()=>({transactionId:"0",status:"pending",metadata:{icpay_onramp:{sessionId:null}}}),notifyIntentUntilComplete:()=>({stop:()=>{}})};le(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.solanaProvider&&(l.solanaProvider=i.solanaProvider),i.onrampDisabled!==void 0&&(l.onrampDisabled=i.onrampDisabled),i.debug!==void 0&&(l.debug=i.debug),le(i.debug||!1,"Filtered SDK config:",l);try{let o=function(c,p,h){return t.notifyPaymentIntentOnRamp({paymentIntentId:c,intervalMs:p,orderId:h})};var e=o;le(i.debug||!1,"typeof Icpay:",typeof $e);let t=new $e(l);if(Ie){let c=t,p=h=>{c.addEventListener(h,d=>{window.dispatchEvent(new CustomEvent(h,{detail:d?.detail??d}))})};["icpay-sdk-error","icpay-sdk-transaction-created","icpay-sdk-transaction-updated","icpay-sdk-transaction-completed","icpay-sdk-transaction-failed","icpay-sdk-method-start","icpay-sdk-method-success","icpay-sdk-method-error"].forEach(p)}async function a(c,p,h){if(typeof p=="string"&&p.trim().length>0)return t.calculateTokenAmountFromUSD({usdAmount:c,tokenShortcode:p.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 n(c,p,h,d){let y={...i.metadata,...h||{}};i.externalCostAmount!=null&&y.externalCostAmount==null&&(y.externalCostAmount=i.externalCostAmount);let m=`Pay ${c} with crypto`,I=i.description||y.__description||y.description||m,Z={usdAmount:c,metadata:y,description:I,recipientAddresses:i.recipientAddresses,recipientAddress:i.recipientAddress};if(typeof p=="string"&&p.trim().length>0&&(Z.tokenShortcode=p.toLowerCase()),typeof d=="string"&&d.trim().length>0&&(Z.ledgerCanisterId=d),!Z.tokenShortcode&&!Z.ledgerCanisterId)throw new Error("sendUsd requires tokenShortcode or ledgerCanisterId");return le(!!i.debug,"Calling createPaymentUsd (flow decision handled by components)",Z),t.createPaymentUsd(Z)}async function s(c,p,h){let d={...i.metadata,...h||{}},y=`Pay ${c} with crypto`,m=i.description||d.__description||d.description||y;return le(!!i.debug,"Calling onramp createPaymentUsd",{usdAmount:c,ledgerCanisterId:p,description:m}),t.createPaymentUsd({usdAmount:c,ledgerCanisterId:p,metadata:d,onrampPayment:!0,description:m,recipientAddresses:i.recipientAddresses,recipientAddress:""})}return{client:t,quoteUsd:a,sendUsd:n,startOnrampUsd:s,notifyIntentUntilComplete:o}}catch(t){throw le(i.debug||!1,"Error creating SDK:",t),t}}import{LitElement as Ye,html as P,css as Ge}from"lit";import{customElement as Qe,property as ae,state as R}from"lit/decorators.js";function v(i,l,e){i&&(e!==void 0?console.log(l,e):console.log(l))}var Ze=[{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"}],b=class extends Ye{constructor(){super(...arguments);this.open=!1;this.suspended=!1;this.steps=Ze;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.isOnrampFlow=!1;this.onMethodStart=e=>{let t=e?.detail?.name||"",a=e?.detail?.type||"";if(v(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(n=>({...n,status:"pending"})),a==="onramp"){this.isOnrampFlow=!0;let n={wallet:{label:"Payment initiated",tooltip:"Please pay in the new tab"},await:{label:"Onramp process started",tooltip:"Verifying funds with provider"},transfer:{label:"Funds received",tooltip:"Payment in progress"},verify:{label:"Payment completed",tooltip:"Finalizing your payment"}};this.currentSteps=this.currentSteps.map(s=>n[s.key]?{...s,label:n[s.key].label,tooltip:n[s.key].tooltip}:s)}this.setLoadingByKey("wallet"),e?.detail?.amount!==void 0&&(this.currentAmount=e.detail.amount,this.amount=e.detail.amount,v(this.debug,"ICPay Progress: Amount updated to:",e.detail.amount)),e?.detail?.currency&&(this.currentCurrency=e.detail.currency,this.currency=e.detail.currency,v(this.debug,"ICPay Progress: Currency updated to:",e.detail.currency)),e?.detail?.ledgerSymbol&&(this.currentLedgerSymbol=e.detail.ledgerSymbol,this.ledgerSymbol=e.detail.ledgerSymbol,v(this.debug,"ICPay Progress: Current state after method start:",{activeIndex:this.activeIndex,currentAmount:this.currentAmount,currentCurrency:this.currentCurrency,currentLedgerSymbol:this.currentLedgerSymbol})),v(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||"";if((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){if(this.isOnrampFlow)return;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;if(v(this.debug,"ICPay Progress: Transaction created event received:",e.detail),!this.failed&&!this.completed){if(this.isOnrampFlow)return;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",a=e?.detail?.transactionId||e?.detail?.id,n=e?.detail?.metadata||e?.detail?.intent?.metadata||{};if(v(this.debug,"ICPay Progress: Transaction updated event received:",e.detail),!this.failed&&!this.completed&&this.isOnrampFlow){let s=n?.onramp_order_completed===!0||n?.icpay_onramp?.status==="completed"||n?.onrampCompleted===!0;t==="requires_payment"&&!s?(this.completeByKey("wallet"),this.setLoadingByKey("await")):(t==="pending"||t==="processing"||s)&&(this.completeByKey("wallet"),this.completeByKey("await"),this.setLoadingByKey("transfer"))}this.dispatchEvent(new CustomEvent("icpay-progress-transaction-updated",{detail:{status:t,transactionId:a,step:this.activeIndex},bubbles:!0}))};this.onTransactionCompleted=e=>{let t=e?.detail?.transactionId||e?.detail?.id,a=e?.detail?.status||"completed";v(this.debug,"ICPay Progress: Transaction completed event received:",e.detail),v(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.isOnrampFlow=!1,this.dispatchEvent(new CustomEvent("icpay-progress-completed",{detail:{transactionId:t,status:a,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",a=e?.detail?.error?.code||e?.detail?.code||"UNKNOWN_ERROR",n=e?.detail?.transactionId||e?.detail?.id;v(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.isOnrampFlow=!1,this.dispatchEvent(new CustomEvent("icpay-progress-failed",{detail:{errorMessage:t,errorCode:a,transactionId:n,step:this.activeIndex},bubbles:!0}))};this.onTransactionMismatched=e=>{let t=e?.detail?.requestedAmount,a=e?.detail?.paidAmount,n=e?.detail?.transactionId||e?.detail?.id;this.failed=!0;let s=t!=null?String(t):"unknown",o=a!=null?String(a):"unknown";this.errorMessage=`Amount mismatch. Requested ${s}, paid ${o}.`,this.showSuccess=!1,this.updateStepStatus(this.activeIndex,"error",this.errorMessage),this.stopAutomaticProgression(),this.open=!0,this.isOnrampFlow=!1,this.dispatchEvent(new CustomEvent("icpay-progress-failed",{detail:{errorMessage:this.errorMessage,errorCode:"MISMATCHED_AMOUNT",transactionId:n,step:this.activeIndex,requestedAmount:t,paidAmount:a},bubbles:!0}))};this.onMethodError=e=>{let t=e?.detail?.name||"",a=e?.detail?.error?.message||e?.detail?.message||"An error occurred",n=e?.detail?.error?.code||e?.detail?.code||"METHOD_ERROR";v(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(a),this.showSuccess=!1,this.updateStepStatus(this.activeIndex,"error",a),this.stopAutomaticProgression(),this.open=!0,this.isOnrampFlow=!1,this.dispatchEvent(new CustomEvent("icpay-progress-error",{detail:{methodName:t,errorMessage:a,errorCode:n,step:this.activeIndex},bubbles:!0})))};this.onSDKError=e=>{let t=e?.detail?.message||"SDK error occurred",a=e?.detail?.code||"SDK_ERROR";v(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.isOnrampFlow=!1,this.dispatchEvent(new CustomEvent("icpay-progress-sdk-error",{detail:{errorMessage:t,errorCode:a,step:this.activeIndex},bubbles:!0}))};this.onWalletConnected=e=>{let t=e?.detail?.walletType||"unknown";v(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.onOnrampOpened=e=>{!this.isOnrampFlow||this.failed||this.completed||(this.completeByKey("wallet"),this.setLoadingByKey("await"))};this.onWalletDisconnected=e=>{let t=e?.detail?.walletType||"unknown";v(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,a=e?.detail?.balance||0;v(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:a,required:this.currentAmount||this.amount,step:this.activeIndex},bubbles:!0})))};this.onLedgerVerified=e=>{let t=e?.detail?.ledgerId||e?.detail?.canisterId,a=e?.detail?.symbol||"unknown";v(this.debug,"ICPay Progress: Ledger verified event received:",e.detail),a&&a!=="unknown"&&(this.currentLedgerSymbol=a,this.ledgerSymbol=a),this.dispatchEvent(new CustomEvent("icpay-progress-ledger-verified",{detail:{ledgerId:t,symbol:a,step:this.activeIndex},bubbles:!0}))};this.onWidgetPayment=e=>{let t=e?.detail?.amount,a=e?.detail?.currency,n=e?.detail?.ledgerSymbol;if(v(this.debug,"ICPay Progress: Widget payment event received:",e.detail),t!==void 0&&(this.currentAmount=t,this.amount=t),a&&(this.currentCurrency=a,this.currency=a),n&&(this.currentLedgerSymbol=n,this.ledgerSymbol=n),!this.failed){for(let s=this.activeIndex;s<this.currentSteps.length;s++)this.updateStepStatus(s,"completed");this.activeIndex=this.currentSteps.length-1,this.completed=!0,this.showSuccess=!0,this.showConfetti=!0}this.dispatchEvent(new CustomEvent("icpay-progress-widget-payment",{detail:{amount:t,currency:a,ledgerSymbol:n,step:this.activeIndex},bubbles:!0}))};this.onWidgetError=e=>{let t=e?.detail?.message||"Widget error occurred",a=e?.detail?.code||"WIDGET_ERROR";v(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:a,step:this.activeIndex},bubbles:!0}))};this.onWidgetUnlock=e=>{let t=e?.detail?.amount,a=e?.detail?.currency;if(v(this.debug,"ICPay Progress: Widget unlock event received:",e.detail),!this.failed){for(let n=this.activeIndex;n<this.currentSteps.length;n++)this.updateStepStatus(n,"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:a,step:this.activeIndex},bubbles:!0}))};this.onWidgetTip=e=>{let t=e?.detail?.amount,a=e?.detail?.currency;if(v(this.debug,"ICPay Progress: Widget tip event received:",e.detail),!this.failed){for(let n=this.activeIndex;n<this.currentSteps.length;n++)this.updateStepStatus(n,"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:a,step:this.activeIndex},bubbles:!0}))};this.onWidgetDonation=e=>{let t=e?.detail?.amount,a=e?.detail?.currency;if(v(this.debug,"ICPay Progress: Widget donation event received:",e.detail),!this.failed){for(let n=this.activeIndex;n<this.currentSteps.length;n++)this.updateStepStatus(n,"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:a,step:this.activeIndex},bubbles:!0}))};this.onWidgetCoffee=e=>{let t=e?.detail?.amount,a=e?.detail?.currency;if(v(this.debug,"ICPay Progress: Widget coffee event received:",e.detail),!this.failed){for(let n=this.activeIndex;n<this.currentSteps.length;n++)this.updateStepStatus(n,"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:a,step:this.activeIndex},bubbles:!0}))};this.onWalletCancelled=e=>{try{let t=this.getStepIndexByKey("wallet"),a=this.getStepIndexByKey("await"),n=this.getStepIndexByKey("transfer"),s=this.getStepIndexByKey("verify"),o=this.currentSteps&&this.currentSteps.length>0&&this.currentSteps.some((h,d)=>t>=0&&d>t?h.status==="loading"||h.status==="completed":!1),p=(t>=0?this.currentSteps[t]:null)?.status==="completed";if(!o&&!p){this.open=!1,this.activeIndex=0,this.currentSteps=this.currentSteps.map(h=>({...h,status:"pending"})),this.requestUpdate();return}this.open=!0,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",a=this.transformErrorMessage(t);this.open=!0;let n=this.getStepIndexByKey("wallet");n>=0&&(this.activeIndex=n,this.currentSteps[n]={...this.currentSteps[n],tooltip:"Wallet connection failed",status:"error",errorMessage:a},this.requestUpdate())}catch{}}}connectedCallback(){super.connectedCallback();try{oe(this,this.theme);let e="light";if(typeof this.theme=="string")e=this.theme;else if(this.theme&&typeof this.theme=="object"&&this.theme.mode)e=this.theme.mode;else if(typeof document<"u"){let t=document.documentElement.getAttribute("data-icpay-theme")||document.documentElement.getAttribute("data-theme");(t==="light"||t==="dark")&&(e=t)}this.setAttribute("data-theme",e)}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{oe(this,this.theme);let t="light";if(typeof this.theme=="string")t=this.theme;else if(this.theme&&typeof this.theme=="object"&&this.theme.mode)t=this.theme.mode;else if(typeof document<"u"){let a=document.documentElement.getAttribute("data-icpay-theme")||document.documentElement.getAttribute("data-theme");(a==="light"||a==="dark")&&(t=a)}this.setAttribute("data-theme",t)}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-onramp-opened",this.onOnrampOpened),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-onramp-opened",this.onOnrampOpened),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"),v(this.debug,"ICPay Progress: Starting automatic progression from step:",this.activeIndex),this.progressionTimer=setInterval(()=>{if(this.failed||this.completed){this.stopAutomaticProgression();return}v(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"),v(this.debug,"ICPay Progress: Auto-progressed to step:",this.activeIndex)):(this.stopAutomaticProgression(),v(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,a){if(e>=0&&e<this.currentSteps.length){let n=this.currentSteps[e],s=n.status;n.status=t,t==="completed"&&(n.timestamp=this.getCurrentTime()),t==="error"&&a&&(n.errorMessage=this.transformErrorMessage(a)),s!==t&&v(this.debug,`ICPay Progress: Step ${e} (${n.label}) status changed from ${s} 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"?P`<div class="error-x">✕</div>`:P`<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},(a,n)=>n),t=["#0066FF","#ef4444","#10b981","#f59e0b","#8b5cf6"];return P`
|
|
143
147
|
<div class="confetti">
|
|
144
148
|
${e.map(a=>P`
|
|
145
149
|
<div
|
|
@@ -1043,7 +1047,7 @@ import{a as r}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var j=Xe`
|
|
|
1043
1047
|
opacity: 0;
|
|
1044
1048
|
}
|
|
1045
1049
|
}
|
|
1046
|
-
`,r([ae({type:Boolean})],b.prototype,"open",2),r([ae({type:Boolean})],b.prototype,"suspended",2),r([ae({type:Array})],b.prototype,"steps",2),r([ae({type:Number})],b.prototype,"amount",2),r([ae({type:String})],b.prototype,"currency",2),r([ae({type:String})],b.prototype,"ledgerSymbol",2),r([ae({type:Boolean})],b.prototype,"debug",2),r([R()],b.prototype,"activeIndex",2),r([R()],b.prototype,"completed",2),r([R()],b.prototype,"failed",2),r([R()],b.prototype,"errorMessage",2),r([R()],b.prototype,"showSuccess",2),r([R()],b.prototype,"showConfetti",2),r([R()],b.prototype,"currentSteps",2),r([R()],b.prototype,"currentAmount",2),r([R()],b.prototype,"currentCurrency",2),r([R()],b.prototype,"currentLedgerSymbol",2),r([R()],b.prototype,"confirmLoadingStartedAt",2),r([R()],b.prototype,"currentWalletType",2),r([R()],b.prototype,"showWalletSelector",2),r([R()],b.prototype,"isTransitioning",2),r([R()],b.prototype,"isOnrampFlow",2),r([ae({type:Object})],b.prototype,"theme",2),b=r([Qe("icpay-progress-bar")],b);import{html as
|
|
1050
|
+
`,r([ae({type:Boolean})],b.prototype,"open",2),r([ae({type:Boolean})],b.prototype,"suspended",2),r([ae({type:Array})],b.prototype,"steps",2),r([ae({type:Number})],b.prototype,"amount",2),r([ae({type:String})],b.prototype,"currency",2),r([ae({type:String})],b.prototype,"ledgerSymbol",2),r([ae({type:Boolean})],b.prototype,"debug",2),r([R()],b.prototype,"activeIndex",2),r([R()],b.prototype,"completed",2),r([R()],b.prototype,"failed",2),r([R()],b.prototype,"errorMessage",2),r([R()],b.prototype,"showSuccess",2),r([R()],b.prototype,"showConfetti",2),r([R()],b.prototype,"currentSteps",2),r([R()],b.prototype,"currentAmount",2),r([R()],b.prototype,"currentCurrency",2),r([R()],b.prototype,"currentLedgerSymbol",2),r([R()],b.prototype,"confirmLoadingStartedAt",2),r([R()],b.prototype,"currentWalletType",2),r([R()],b.prototype,"showWalletSelector",2),r([R()],b.prototype,"isTransitioning",2),r([R()],b.prototype,"isOnrampFlow",2),r([ae({type:Object})],b.prototype,"theme",2),b=r([Qe("icpay-progress-bar")],b);import{html as Me}from"lit";function Je(i){if(i==="light"||i==="dark")return i;if(typeof document>"u")return"light";let l=document.documentElement.getAttribute("data-icpay-theme");if(l==="light"||l==="dark")return l;let e=document.documentElement.getAttribute("data-theme");return e==="light"||e==="dark"?e:"light"}function q(i){if(!i.visible)return null;let l=i.width??420,e=i.height??680,t=typeof i.url=="string"&&(i.url||"").startsWith("http"),a=Je(i.theme);return Me`
|
|
1047
1051
|
<style>
|
|
1048
1052
|
/* Theme-aware color variables - Light mode defaults */
|
|
1049
1053
|
.icpay-onramp-modal-overlay {
|
|
@@ -1120,27 +1124,27 @@ import{a as r}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var j=Xe`
|
|
|
1120
1124
|
<div class="icpay-onramp-modal-overlay" data-theme="${a}">
|
|
1121
1125
|
<div class="icpay-onramp-modal-container">
|
|
1122
1126
|
<button @click=${i.onClose} style="position:absolute;right:12px;top:12px;background:transparent;border:none;color:var(--icpay-foreground);cursor:pointer;font-size:20px;opacity:0.8;z-index:10">×</button>
|
|
1123
|
-
${i.onBack?
|
|
1127
|
+
${i.onBack?Me`<button @click=${i.onBack} style="position:absolute;left:12px;top:12px;background:transparent;border:1px solid var(--icpay-border);color:var(--icpay-foreground);cursor:pointer;font-size:12px;border-radius:8px;padding:6px 10px;opacity:0.9;z-index:10">Back</button>`:null}
|
|
1124
1128
|
<div style="color:var(--icpay-foreground);font-weight:600;font-size:15px;margin-bottom:12px">${i.title||"Complete purchase"}</div>
|
|
1125
|
-
${t?
|
|
1129
|
+
${t?Me`
|
|
1126
1130
|
<iframe
|
|
1127
1131
|
title="Onramp"
|
|
1128
1132
|
src="${i.url}"
|
|
1129
|
-
style="border:0;width:${typeof
|
|
1133
|
+
style="border:0;width:${typeof l=="number"?`${l}px`:l};height:${typeof e=="number"?`${e}px`:e};border-radius:12px;background:#000"
|
|
1130
1134
|
sandbox="allow-forms allow-same-origin allow-scripts allow-popups allow-top-navigation-by-user-activation"
|
|
1131
1135
|
allow="payment *"
|
|
1132
1136
|
></iframe>
|
|
1133
1137
|
<div style="margin-top:10px;text-align:right">
|
|
1134
1138
|
<a href="${i.url}" target="_blank" rel="noopener noreferrer" style="color:var(--icpay-primary);font-size:12px;text-decoration:underline">Open in a new tab</a>
|
|
1135
1139
|
</div>
|
|
1136
|
-
`:
|
|
1137
|
-
<div style="width:${typeof
|
|
1140
|
+
`:Me`
|
|
1141
|
+
<div style="width:${typeof l=="number"?`${l}px`:l};height:${typeof e=="number"?`${e}px`:e};display:flex;align-items:center;justify-content:center;background:var(--icpay-secondary);border:1px dashed var(--icpay-border);border-radius:12px;color:var(--icpay-foreground)">
|
|
1138
1142
|
${i.errorMessage||"Onramp URL not available"}
|
|
1139
1143
|
</div>
|
|
1140
1144
|
`}
|
|
1141
1145
|
</div>
|
|
1142
1146
|
</div>
|
|
1143
|
-
`}import{LitElement as pt,html as
|
|
1147
|
+
`}import{LitElement as pt,html as ne,css as ht}from"lit";import{customElement as yt,property as gt,state as L}from"lit/decorators.js";import{IcpayError as Be}from"@ic-pay/icpay-sdk";var J={WALLET_NOT_CONNECTED:"WALLET_NOT_CONNECTED",WALLET_USER_CANCELLED:"WALLET_USER_CANCELLED",WALLET_SIGNATURE_REJECTED:"WALLET_SIGNATURE_REJECTED",INSUFFICIENT_BALANCE:"INSUFFICIENT_BALANCE",NETWORK_ERROR:"NETWORK_ERROR",API_ERROR:"API_ERROR",LEDGER_NOT_FOUND:"LEDGER_NOT_FOUND",TRANSACTION_FAILED:"TRANSACTION_FAILED",TRANSACTION_TIMEOUT:"TRANSACTION_TIMEOUT",UNKNOWN_ERROR:"UNKNOWN_ERROR"},et={onError:i=>{console.error("[ICPay Widget] Error:",i)},onUserCancelled:()=>{console.log("[ICPay Widget] User cancelled the action")},onInsufficientBalance:i=>{console.warn("[ICPay Widget] Insufficient balance:",i.message)},onWalletError:i=>{console.warn("[ICPay Widget] Wallet error:",i.message)},onNetworkError:i=>{console.error("[ICPay Widget] Network error:",i.message)}};function _(i,l=et){i instanceof Be?(l.onError(i),i.isUserCancelled()?l.onUserCancelled?.():i.isBalanceError()?l.onInsufficientBalance?.(i):i.isWalletError()?l.onWalletError?.(i):i.isNetworkError()&&l.onNetworkError?.(i)):(console.error("[ICPay Widget] Unknown error:",i),l.onError(new Be({code:J.UNKNOWN_ERROR,message:i instanceof Error?i.message:"An unknown error occurred",details:i})))}var tt={[J.WALLET_NOT_CONNECTED]:"Please connect your wallet to continue",[J.WALLET_USER_CANCELLED]:"User have rejected the transfer",[J.WALLET_SIGNATURE_REJECTED]:"User have rejected the transfer",[J.INSUFFICIENT_BALANCE]:"Insufficient balance for this transaction",[J.NETWORK_ERROR]:"Network error. Please try again",[J.API_ERROR]:"Service temporarily unavailable",[J.LEDGER_NOT_FOUND]:"Selected token is not supported",[J.TRANSACTION_FAILED]:"Transaction failed. Please try again",[J.TRANSACTION_TIMEOUT]:"Transaction timed out. Please try again",[J.UNKNOWN_ERROR]:"Something went wrong. Please try again"};function D(i){return tt[i.code]||i.message||"An error occurred"}function z(i){return!i.isUserCancelled()}function F(i){return null}function j(i){return i.isUserCancelled()?"info":i.isBalanceError()||i.isWalletError()?"warning":"error"}import{html as ee}from"lit";var Re=new Set(["metamask","walletconnect","coinbase","brave","rainbow","rabby","okx"]),at=new Set(["phantom","backpack"]);function B(i){return i?Re.has(String(i).toLowerCase()):!1}function nt(i){return i&&(i.id||i.provider||i.key)||""}function it(i){return i&&(i.label||i.name||i.title||i.id)||"Wallet"}function rt(i){return i&&(i.icon||i.logo||i.image)||null}function H(i){return(i||[]).map(l=>({id:nt(l),label:it(l),icon:rt(l)}))}async function V(i,l){try{let e=l?.provider||(typeof window<"u"?window.ethereum:null);if(!e||i===void 0||i===null)return!0;let t=typeof i=="number"?i:String(i).startsWith("0x")?parseInt(String(i),16):parseInt(String(i),10);if(!Number.isFinite(t))return!0;let a=await e.request({method:"eth_chainId"});if(parseInt(a,16)===t)return!0;let s="0x"+t.toString(16);return await e.request({method:"wallet_switchEthereumChain",params:[{chainId:s}]}),!0}catch{try{let t=l?.provider||(typeof window<"u"?window.ethereum:null);if(!t||i===void 0||i===null)return!1;let a=typeof i=="number"?i:String(i).startsWith("0x")?parseInt(String(i),16):parseInt(String(i),10),n="0x"+a.toString(16),s=l?.chainName||`Network ${a}`,o=(l?.rpcUrlPublic?[l.rpcUrlPublic]:[]).filter(Boolean),c={name:l?.nativeSymbol||"ETH",symbol:l?.nativeSymbol||"ETH",decimals:typeof l?.decimals=="number"&&isFinite(l.decimals)?l.decimals:18};return await t.request({method:"wallet_addEthereumChain",params:[{chainId:n,chainName:s,rpcUrls:o,nativeCurrency:c}]}),!0}catch{return!1}}}async function X(i){let{sdk:l,lastWalletId:e,connectedWallet:t,amountUsd:a,chainShortcodes:n,tokenShortcodes:s}=i,o,c=(e||"").toLowerCase(),p=(t?.owner||t?.principal||"").toString();try{c&&Re.has(c)?o=await l?.client?.getExternalWalletBalances?.({network:"evm",address:p,amountUsd:a,chainShortcodes:n,tokenShortcodes:s}):c&&at.has(c)?o=await l?.client?.getExternalWalletBalances?.({network:"sol",address:p,amountUsd:a,chainShortcodes:n,tokenShortcodes:s}):o=await l?.client?.getExternalWalletBalances?.({network:"ic",principal:p,amountUsd:a,chainShortcodes:n,tokenShortcodes:s})}catch{o={balances:[],totalBalancesUSD:0,lastUpdated:new Date}}return{balances:(o?.balances||[]).map(d=>({ledgerId:d.ledgerId,ledgerName:d.ledgerName,ledgerSymbol:d.ledgerSymbol,tokenShortcode:d.tokenShortcode??d.shortcode??null,canisterId:d.canisterId,eip3009Version:d?.eip3009Version??null,x402Accepts:d?.x402Accepts!=null?!!d.x402Accepts:void 0,balance:d.balance,formattedBalance:d.formattedBalance,decimals:d.decimals,currentPrice:d.currentPrice,lastPriceUpdate:d.lastPriceUpdate?new Date(d.lastPriceUpdate):void 0,lastUpdated:d.lastUpdated?new Date(d.lastUpdated):new Date,chainId:typeof d.chainId=="string"?d.chainId:typeof d.chainId=="number"?String(d.chainId):void 0,chainName:d.chainName||d.chain&&(d.chain.name||d.chain.chainName)||d.networkName||void 0,rpcUrlPublic:d.rpcUrlPublic,chainUuid:d.chainUuid,requiredAmount:d.requiredAmount,requiredAmountFormatted:d.requiredAmountFormatted,hasSufficientBalance:d.hasSufficientBalance,logoUrl:d.logoUrl??null})),totalBalancesUSD:o?.totalBalancesUSD,lastUpdated:o?.lastUpdated?new Date(o.lastUpdated):new Date}}function We(i){let l=Number(i);if(!isFinite(l)||l===0)return"0";if(Math.abs(l)<1e-5)return"< 0.00001";let t=1e5;return(Math.trunc(l*t)/t).toFixed(5).replace(/\.0+$/,"").replace(/(\.[0-9]*?)0+$/,"$1")}import{html as Y}from"lit";function Ue(i){let l=parseFloat(String(i.formattedBalance||"0")),e=Number(i.currentPrice??0),t=(isFinite(l)?l:0)*(isFinite(e)?e:0);return isFinite(t)?t:0}var _e=(i,l)=>Ue(l)-Ue(i);function Ae(){return Y`<style>
|
|
1144
1148
|
/* Theme-aware color variables - Light mode defaults */
|
|
1145
1149
|
.modal {
|
|
1146
1150
|
--icpay-background: #ffffff;
|
|
@@ -1201,7 +1205,7 @@ import{a as r}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var j=Xe`
|
|
|
1201
1205
|
.get-started { font-size:14px; color:var(--icpay-primary); background:none; border:none; cursor:pointer; font-weight:500; }
|
|
1202
1206
|
.get-started:hover { text-decoration:underline; }
|
|
1203
1207
|
.muted { color:var(--icpay-muted-foreground); }
|
|
1204
|
-
</style>`}function
|
|
1208
|
+
</style>`}function Ce(i){let l=e=>We(e);return Y`
|
|
1205
1209
|
<div class="header">
|
|
1206
1210
|
<button class="back-button" @click=${i.onBack}>‹</button>
|
|
1207
1211
|
<h1 class="title">Pay with</h1>
|
|
@@ -1223,7 +1227,7 @@ import{a as r}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var j=Xe`
|
|
|
1223
1227
|
<div class="currency-network">${t.chainName||""}</div>
|
|
1224
1228
|
</div>
|
|
1225
1229
|
<div class="currency-balance">
|
|
1226
|
-
<div class="balance-amount">${
|
|
1230
|
+
<div class="balance-amount">${l(t.formattedBalance)} ${a}</div>
|
|
1227
1231
|
<div class="balance-available">$${Ue(t).toFixed(2)}</div>
|
|
1228
1232
|
</div>
|
|
1229
1233
|
</div>
|
|
@@ -1242,7 +1246,7 @@ import{a as r}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var j=Xe`
|
|
|
1242
1246
|
</div>
|
|
1243
1247
|
<div class="currency-balance">
|
|
1244
1248
|
<div class="balance-amount">need ${t.requiredAmountFormatted||"--"}</div>
|
|
1245
|
-
<div class="balance-available">${
|
|
1249
|
+
<div class="balance-available">${l(t.formattedBalance)} ${a} available</div>
|
|
1246
1250
|
</div>
|
|
1247
1251
|
</div>
|
|
1248
1252
|
`})}
|
|
@@ -1253,8 +1257,8 @@ import{a as r}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var j=Xe`
|
|
|
1253
1257
|
<span class="need-wallet">Need a wallet?</span>
|
|
1254
1258
|
<button class="get-started" @click=${()=>{try{window.open("https://internetcomputer.org/wallets","_blank","noopener,noreferrer")}catch{}}}>Get started</button>
|
|
1255
1259
|
</div>
|
|
1256
|
-
`}function st(){if(typeof document>"u")return"light";let
|
|
1257
|
-
<div class="icpay-modal-overlay" data-theme="${p}" @click=${
|
|
1260
|
+
`}function st(i){if(i==="light"||i==="dark")return i;if(typeof document>"u")return"light";let l=document.documentElement.getAttribute("data-icpay-theme");if(l==="light"||l==="dark")return l;let e=document.documentElement.getAttribute("data-theme");return e==="light"||e==="dark"?e:"light"}function ot(i){return!i||!i.startsWith("data:")?i:i.replace(/\s+/g,"")}function lt(i,l){let e=(i||"").toLowerCase();return e==="ii"?"Internet Identity":e==="nfid"?"NFID":e==="plug"?"Plug":e==="oisy"?"Oisy":l&&l.trim()?l:i?i.charAt(0).toUpperCase()+i.slice(1):"Wallet"}function G(i){if(!i.visible)return null;let{wallets:l,onSelect:e,onClose:t,isConnecting:a}=i,n=d=>We(d),s=d=>{let y=parseFloat(String(d.formattedBalance||"0")),m=Number(d.currentPrice??0),I=(isFinite(y)?y:0)*(isFinite(m)?m:0);return isFinite(I)?I:0},o=(d,y)=>s(y)-s(d),c=l.map(d=>{let y=(d.id||"").toLowerCase();return{...d,icon:d.icon??null}}),p=st(i.theme);return ee`
|
|
1261
|
+
<div class="icpay-modal-overlay" data-theme="${p}" @click=${d=>{d.target===d.currentTarget&&(d.preventDefault(),d.stopPropagation(),i.onDismiss?i.onDismiss():i.onClose())}} style="position:fixed !important;inset:0 !important;display:flex;align-items:center;justify-content:center;background:rgba(0,0,0,0.5);z-index:99999 !important;transform:none !important;">
|
|
1258
1262
|
<style>
|
|
1259
1263
|
.icpay-w-8 { width: 2rem; }
|
|
1260
1264
|
.icpay-h-8 { height: 2rem; }
|
|
@@ -1298,7 +1302,7 @@ import{a as r}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var j=Xe`
|
|
|
1298
1302
|
--icpay-secondary: hsl(217.2 32.6% 17.5%);
|
|
1299
1303
|
--icpay-secondary-foreground: hsl(210 40% 98%);
|
|
1300
1304
|
--icpay-accent: hsl(217.2 32.6% 17.5%);
|
|
1301
|
-
--icpay-border:
|
|
1305
|
+
--icpay-border: hsla(217.2 32.6% 30% / 0.15);
|
|
1302
1306
|
--icpay-success-bg: rgba(16, 185, 129, 0.1);
|
|
1303
1307
|
--icpay-success-text: #34d399;
|
|
1304
1308
|
--icpay-success-border: rgba(16, 185, 129, 0.3);
|
|
@@ -1334,15 +1338,41 @@ import{a as r}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var j=Xe`
|
|
|
1334
1338
|
}
|
|
1335
1339
|
.modal { background-color:var(--icpay-background); border-radius:24px; width:100%; max-width:420px; padding:24px; color:var(--icpay-foreground); display:flex; flex-direction:column; border:1px solid var(--icpay-border); height:460px; margin:auto; transition:transform 0.3s ease; }
|
|
1336
1340
|
@media (max-width: 768px) {
|
|
1337
|
-
.modal {
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
+
.icpay-modal-overlay {
|
|
1342
|
+
align-items: flex-end;
|
|
1343
|
+
justify-content: stretch;
|
|
1344
|
+
padding: 0;
|
|
1345
|
+
}
|
|
1346
|
+
.modal {
|
|
1347
|
+
max-width:100%;
|
|
1348
|
+
width:100%;
|
|
1349
|
+
height:auto;
|
|
1350
|
+
max-height:50vh;
|
|
1351
|
+
border-radius:24px 24px 0 0;
|
|
1352
|
+
margin:0;
|
|
1353
|
+
padding:16px;
|
|
1354
|
+
transform:translateY(100%);
|
|
1355
|
+
overflow:hidden;
|
|
1356
|
+
display:flex;
|
|
1357
|
+
flex-direction:column;
|
|
1358
|
+
transition:transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
|
|
1359
|
+
align-self: flex-end;
|
|
1360
|
+
}
|
|
1361
|
+
.icpay-modal-overlay:not([style*="display: none"]) .modal {
|
|
1362
|
+
transform:translateY(0);
|
|
1363
|
+
}
|
|
1364
|
+
.wallet-list {
|
|
1365
|
+
overflow-y:auto;
|
|
1366
|
+
flex:1;
|
|
1367
|
+
min-height:0;
|
|
1368
|
+
max-height:calc(50vh - 120px); /* Account for header, footer, and padding */
|
|
1369
|
+
}
|
|
1341
1370
|
}
|
|
1342
|
-
.header { display:flex; align-items:center; margin-bottom:
|
|
1343
|
-
.
|
|
1344
|
-
.
|
|
1345
|
-
.
|
|
1371
|
+
.header { display:flex; align-items:center; justify-content:center; margin-bottom:12px; padding-bottom:12px; border-bottom:1px solid var(--icpay-border); flex-shrink:0; position:relative; }
|
|
1372
|
+
.close-button { background:none; border:none; color:var(--icpay-foreground); font-size:20px; cursor:pointer; padding:4px; margin:0; line-height:1; opacity:0.7; transition:opacity 0.2s; position:absolute; right:0; }
|
|
1373
|
+
.close-button:hover { opacity:1; }
|
|
1374
|
+
.title { font-size:20px; font-weight:600; text-align:center; margin:0; }
|
|
1375
|
+
.wallet-list { display:flex; flex-direction:column; gap:0; overflow-y:auto; flex:1; padding-right:8px; padding-top:4px; scrollbar-gutter: stable; }
|
|
1346
1376
|
.wallet-item { display:flex; align-items:center; padding:16px 12px; cursor:pointer; transition:background-color 0.2s; border-radius:12px; }
|
|
1347
1377
|
.wallet-item:hover { background-color:var(--icpay-accent); }
|
|
1348
1378
|
.wallet-icon { width:48px; height:48px; border-radius:12px; margin-right:16px; display:flex; align-items:center; justify-content:center; font-size:24px; overflow:hidden; }
|
|
@@ -1357,14 +1387,14 @@ import{a as r}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var j=Xe`
|
|
|
1357
1387
|
.get-started { font-size:14px; color:var(--icpay-primary); background:none; border:none; cursor:pointer; font-weight:500; }
|
|
1358
1388
|
.get-started:hover { text-decoration:underline; }
|
|
1359
1389
|
</style>
|
|
1360
|
-
${
|
|
1361
|
-
<div class="modal" @click=${
|
|
1390
|
+
${Ae()}
|
|
1391
|
+
<div class="modal" @click=${d=>d.stopPropagation()}>
|
|
1362
1392
|
${i.step==="balances"?ee`
|
|
1363
|
-
${
|
|
1393
|
+
${Ce({isLoading:!!i.balancesLoading,error:i.balancesError,balances:i.balances,onBack:()=>i.onBack&&i.onBack(),onSelect:d=>i.onSelectBalance&&i.onSelectBalance(d)})}
|
|
1364
1394
|
`:ee`
|
|
1365
1395
|
<div class="header">
|
|
1366
|
-
<button class="back-button" @click=${()=>{try{t()}catch{}}}>‹</button>
|
|
1367
1396
|
<h1 class="title">Connect</h1>
|
|
1397
|
+
<button class="close-button" @click=${()=>{try{t()}catch{}}} aria-label="Close">×</button>
|
|
1368
1398
|
</div>
|
|
1369
1399
|
<div class="wallet-list">
|
|
1370
1400
|
${i.showCreditCard&&i.onCreditCard?ee`
|
|
@@ -1379,17 +1409,17 @@ import{a as r}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var j=Xe`
|
|
|
1379
1409
|
</div>
|
|
1380
1410
|
<div class="divider"></div>
|
|
1381
1411
|
`:null}
|
|
1382
|
-
${(()=>{let
|
|
1383
|
-
<div class="wallet-item" style="opacity:${a?.6:1}" @click=${()=>e(
|
|
1412
|
+
${(()=>{let d=[],y=null;return c.forEach(m=>{let I=(m.id||"").toLowerCase(),Z=lt(m.id,m.label),Ee=B(I),Se=I==="phantom"||I==="backpack"?"sol":Ee?"evm":"ic";y!==null&&Se!==y&&d.push(ee`<div class="divider"></div>`);let Pe=I==="oisy"||I==="plug"||I==="nfid"||I==="ii"?"Internet Computer":I==="phantom"||I==="backpack"?"Solana":Ee?"Ethereum-compatible":"";d.push(ee`
|
|
1413
|
+
<div class="wallet-item" style="opacity:${a?.6:1}" @click=${()=>e(m.id)}>
|
|
1384
1414
|
<div class="wallet-icon">
|
|
1385
|
-
${
|
|
1415
|
+
${m.icon?ee`<img src="${ot(m.icon)}" alt="${Z} logo" class="icpay-w-8 icpay-h-8" style="object-fit:contain" />`:ee`<span>${Z.charAt(0)}</span>`}
|
|
1386
1416
|
</div>
|
|
1387
1417
|
<div class="wallet-info">
|
|
1388
1418
|
<div class="wallet-name">${Z}</div>
|
|
1389
1419
|
${Pe?ee`<div class="wallet-status">${Pe}</div>`:null}
|
|
1390
1420
|
</div>
|
|
1391
1421
|
</div>
|
|
1392
|
-
`),y=
|
|
1422
|
+
`),y=Se}),d})()}
|
|
1393
1423
|
</div>
|
|
1394
1424
|
<div class="footer">
|
|
1395
1425
|
<span class="need-wallet">Need a wallet?</span>
|
|
@@ -1398,8 +1428,8 @@ import{a as r}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var j=Xe`
|
|
|
1398
1428
|
`}
|
|
1399
1429
|
</div>
|
|
1400
1430
|
</div>
|
|
1401
|
-
`}import{html as ct}from"lit";function dt(){if(typeof document>"u")return"
|
|
1402
|
-
<div class="icpay-modal-overlay" data-theme="${
|
|
1431
|
+
`}import{html as ct}from"lit";function dt(i){if(i==="light"||i==="dark")return i;if(typeof document>"u")return"light";let l=document.documentElement.getAttribute("data-icpay-theme");if(l==="light"||l==="dark")return l;let e=document.documentElement.getAttribute("data-theme");return e==="light"||e==="dark"?e:"light"}function Q(i){if(!i.visible)return null;let l=dt(i.theme);return ct`
|
|
1432
|
+
<div class="icpay-modal-overlay" data-theme="${l}" style="position:fixed !important;inset:0 !important;display:flex;align-items:center;justify-content:center;background:rgba(0, 0, 0, 0.5);z-index:99999 !important;transform:none !important;">
|
|
1403
1433
|
<style>
|
|
1404
1434
|
/* Theme-aware color variables - Light mode defaults */
|
|
1405
1435
|
.icpay-modal-overlay {
|
|
@@ -1453,14 +1483,14 @@ import{a as r}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var j=Xe`
|
|
|
1453
1483
|
}
|
|
1454
1484
|
}
|
|
1455
1485
|
</style>
|
|
1456
|
-
${
|
|
1486
|
+
${Ae()}
|
|
1457
1487
|
<div class="modal">
|
|
1458
|
-
${
|
|
1488
|
+
${Ce({isLoading:i.isLoading,error:i.error,balances:i.balances,onBack:i.onClose,onSelect:i.onSelect})}
|
|
1459
1489
|
</div>
|
|
1460
1490
|
</div>
|
|
1461
|
-
`}function $(i){try{let s=i||{};s.adapters=s.adapters||{};let e=s.adapters.oisy||{},t=e.config||{},a={...t.transport||{},windowOpenerFeatures:"",detectNonClickEstablishment:!1};return s.adapters.oisy={...e,config:{...t,transport:a}},s}catch{return i}}function U(i,s){try{let e=s&&(s.owner||s.principal)||null,t=i&&i.account&&(i.account.owner||i.account.principal)||null,a=o=>typeof o=="string"?o:o&&typeof o.toString=="function"?o.toString():null,n=a(e)||a(t)||null;return n?{owner:n,principal:n}:s||{owner:null}}catch{return s||{owner:null}}}async function te(i){try{let s=typeof i?.getEnabledWallets=="function"?i.getEnabledWallets.bind(i):null;if(!s)return null;let t=(s()||[]).find(d=>(d?.id||"").toLowerCase()==="oisy");if(!t||!t.adapter)return null;let a=t.adapter,n=new a({config:i?.config||{}});if(!await n.isConnected())return null;let l=await n.getPrincipal();return l&&l!=="2vxsx-fae"?l:null}catch{return null}}var De=typeof window<"u",re=null;function ue(i,s,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${s}`,e):console.log(`[ICPay Widget] ${s}`))}var k=class extends pt{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.walletModalStep="connect";this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.showOnrampModal=!1;this.onrampUrl=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.onTransactionCompleted=null;this.onUnlock=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),a=this.selectedSymbol||"ICP";window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"pay",type:"sendUsd",amount:t,currency:a}}))}catch{}}catch{}};this.onSelectBalanceSymbol=async e=>{let t=(this.walletBalances||[]).find(n=>n?.tokenShortcode===e);if(t?.ledgerSymbol&&(this.selectedSymbol=t.ledgerSymbol),B(this.lastWalletId)){let n=(this.walletBalances||[]).find(l=>l?.tokenShortcode===e),o=n?.chainId;this.showBalanceModal=!1,this.showWalletModal=!1,V(o,{provider:this.pnp?.getEvmProvider?.()||this.config?.evmProvider,chainName:n?.chainName,rpcUrlPublic:n?.rpcUrlPublic,nativeSymbol:n?.ledgerSymbol,decimals:n?.decimals}).then(async()=>{try{let l=u(this.config),d=Number(this.config?.priceUsd??0);if(n?.x402Accepts)try{await l.client.createPaymentX402Usd({usdAmount:d,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"evm",icpay_ledger_id:n?.ledgerId,icpay_context:"premium:x402"}},recipientAddress:(this.config?.recipientAddresses||{})?.evm||"0x0000000000000000000000000000000000000000"});return}catch{}await l.client.createPaymentUsd({usdAmount:d,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"evm",icpay_ledger_id:n?.ledgerId}},recipientAddress:(this.config?.recipientAddresses||{})?.evm||"0x0000000000000000000000000000000000000000"})}catch{}});return}this.showBalanceModal=!1,this.showWalletModal=!1;let a=this.pendingAction;if(this.pendingAction=null,a==="pay")try{let n=(this.walletBalances||[]).find(g=>g?.tokenShortcode===e),o=u(this.config),l=Number(this.config?.priceUsd??0),d=String(n?.chainName||n?.ledgerName||"").toLowerCase(),p=d.includes("sol"),h=this.config?.recipientAddresses||{},c=p&&h.sol||h.ic,y=d.includes("ic");if(n?.x402Accepts)try{await o.client.createPaymentX402Usd({usdAmount:l,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:p?"sol":y?"ic":this.config?.icpay_network,icpay_ledger_id:n?.ledgerId,icpay_context:"premium:x402"}},recipientAddress:c||""});return}catch{return}await o.client.createPaymentUsd({usdAmount:l,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"ic",icpay_ledger_id:n?.ledgerId}},recipientAddress:c||"0x0000000000000000000000000000000000000000"})}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;re||(re=(await import("./wallet-select-BEKXSS66.js")).WalletSelect);let a={...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:o}=await import("./origin-44ZEXSX4.js");a.derivationOrigin=this.config?.derivationOrigin||o()}}catch{}let n=new re(a);this.walletConnected=!1,this.config={...this.config,connectedWallet:{owner:t.principal,principal:t.principal,connected:!1}}}catch{}}connectedCallback(){if(super.connectedCallback(),!!De){ue(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{}this.onTransactionCompleted=(()=>{this.unlocked=!0,this.succeeded=!0,this.processing=!1;try{window.dispatchEvent(new CustomEvent("icpay-unlock",{detail:{amount:this.config?.priceUsd,currency:this.selectedSymbol||"ICP"}}))}catch{}this.requestUpdate()});try{window.addEventListener("icpay-sdk-transaction-completed",this.onTransactionCompleted)}catch{}this.onUnlock=(()=>{this.unlocked=!0,this.succeeded=!0,this.processing=!1,this.requestUpdate()});try{window.addEventListener("icpay-unlock",this.onUnlock)}catch{}}}disconnectedCallback(){super.disconnectedCallback();try{window.removeEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}if(this.onTransactionCompleted)try{window.removeEventListener("icpay-sdk-transaction-completed",this.onTransactionCompleted)}catch{}if(this.onUnlock)try{window.removeEventListener("icpay-unlock",this.onUnlock)}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.onPay()},0))}}async onPay(){if(De&&!(this.processing||this.unlocked)){ue(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){ue(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{re||(re=(await import("./wallet-select-BEKXSS66.js")).WalletSelect);let t=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab)?$({...this.config?.plugNPlay||{}}):{...this.config?.plugNPlay||{}};this.config?.chainTypes&&(t.chainTypes=this.config.chainTypes);try{if(typeof window<"u"){let{resolveDerivationOrigin:n}=await import("./origin-44ZEXSX4.js");t.derivationOrigin=this.config?.derivationOrigin||n()}}catch{}this.pnp=new re(t);try{let n=await te(this.pnp);if(n){this.walletConnected=!0;let o=U(this.pnp,{owner:n,principal:n,connected:!0}),l=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:o,actorProvider:(d,p)=>this.pnp.getActor({canisterId:d,idl:p,requiresSigning:!0,anon:!1}),...l?{evmProvider:l}:{}},this.sdk=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"oisy"}}))}catch{}this.onPay();return}}catch{}let a=this.pnp.getEnabledWallets();if(ue(this.config?.debug||!1,"Available wallets",a),!a?.length)throw new Error("No wallets available");this.pendingAction="pay",this.showWalletModal=!0;return}catch(e){ue(this.config?.debug||!1,"Wallet connection error:",e),this.errorMessage=e instanceof Error?e.message:"Wallet connection failed",this.errorSeverity="error";return}}this.walletModalStep="balances",this.showBalanceModal=!1,this.showWalletModal=!0,await this.fetchAndShowBalances("pay");return}catch(e){_(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),z(t)&&(this.errorMessage=D(t),this.errorSeverity=K(t),this.errorAction=F(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,a=t?.event_id||t?.eventId||t?.id;if(!(!a||typeof a!="string")&&a==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let n=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(n||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 t=await u(this.config).startOnrampUsd(this.config.priceUsd,void 0,{context:"premium:onramp",onrampPayment:!0,onrampProvider:"coinbase"}),a=t?.metadata?.onramp?.url||t?.onramp?.url||t?.metadata?.icpay_onramp?.url||t?.paymentIntent?.metadata?.icpay?.onrampUrl||t?.metadata?.icpay?.onrampUrl||null,n=t?.metadata?.icpay_payment_intent_id||t?.metadata?.paymentIntentId||t?.paymentIntentId||null,o=t?.metadata?.icpay_onramp?.errorMessage||t?.metadata?.onramp?.errorMessage||t?.paymentIntent?.metadata?.icpay?.onrampError||t?.paymentIntent?.metadata?.icpay?.errorMessage||t?.metadata?.icpay?.onrampError||t?.metadata?.icpay?.errorMessage||null;if(this.onrampPaymentIntentId=n,a){this.onrampUrl=a,this.onrampErrorMessage=null;try{window.open(a,"icpay_onramp","noopener,noreferrer");try{window.dispatchEvent(new CustomEvent("icpay-onramp-opened",{detail:{url:a}}))}catch{}}catch{}this.startOnrampPolling()}else this.onrampUrl=null,this.onrampErrorMessage=o||"Failed to obtain onramp URL",this.showOnrampModal=!0}catch(e){this.onrampUrl=null,this.onrampErrorMessage=e?.message||"Failed to obtain onramp URL",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 a=u(this.config),n=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>n()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=a.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(a=>{if(!!!(a&&(a.connected===!0||a.principal||a.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}let o=U(this.pnp,a),l=this.pnp?.getEvmProvider?.(),d=this.pnp?.getSolanaProvider?.();this.config={...this.config,connectedWallet:o,actorProvider:(p,h)=>this.pnp.getActor({canisterId:p,idl:h,requiresSigning:!0,anon:!1}),...l?{evmProvider:l}:{},...d?{solanaProvider:d}:{}},this.sdk=null,this.walletModalStep="balances",this.showBalanceModal=!1,this.showWalletModal=!0,this.fetchAndShowBalances("pay")}).catch(a=>{this.errorMessage=a instanceof Error?a.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.walletModalStep="balances",this.showBalanceModal=!1;let t=u(this.config),{balances:a}=await X({sdk:t,lastWalletId:this.lastWalletId,connectedWallet:this.config?.connectedWallet,amountUsd:Number(this.config?.priceUsd??0)});this.walletBalances=a,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?ie`
|
|
1491
|
+
`}function $(i){try{let l=i||{};l.adapters=l.adapters||{};let e=l.adapters.oisy||{},t=e.config||{},a={...t.transport||{},windowOpenerFeatures:"",detectNonClickEstablishment:!1};return l.adapters.oisy={...e,config:{...t,transport:a}},l}catch{return i}}function U(i,l){try{let e=l&&(l.owner||l.principal)||null,t=i&&i.account&&(i.account.owner||i.account.principal)||null,a=s=>typeof s=="string"?s:s&&typeof s.toString=="function"?s.toString():null,n=a(e)||a(t)||null;return n?{owner:n,principal:n}: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 a=t.adapter,n=new a({config:i?.config||{}});if(!await n.isConnected())return null;let o=await n.getPrincipal();return o&&o!=="2vxsx-fae"?o:null}catch{return null}}var De=typeof window<"u",ce=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 pt{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.walletModalStep="connect";this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.showOnrampModal=!1;this.onrampUrl=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.onTransactionCompleted=null;this.onUnlock=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),a=this.selectedSymbol||"ICP";window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"pay",type:"sendUsd",amount:t,currency:a}}))}catch{}}catch{}};this.onSelectBalanceSymbol=async e=>{let t=(this.walletBalances||[]).find(n=>n?.tokenShortcode===e);if(t?.ledgerSymbol&&(this.selectedSymbol=t.ledgerSymbol),B(this.lastWalletId)){let n=(this.walletBalances||[]).find(o=>o?.tokenShortcode===e),s=n?.chainId;this.showBalanceModal=!1,this.showWalletModal=!1,V(s,{provider:this.pnp?.getEvmProvider?.()||this.config?.evmProvider,chainName:n?.chainName,rpcUrlPublic:n?.rpcUrlPublic,nativeSymbol:n?.ledgerSymbol,decimals:n?.decimals}).then(async()=>{try{let o=g(this.config),c=Number(this.config?.priceUsd??0);if(n?.x402Accepts)try{await o.client.createPaymentX402Usd({usdAmount:c,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"evm",icpay_ledger_id:n?.ledgerId,icpay_context:"premium:x402"}},recipientAddress:(this.config?.recipientAddresses||{})?.evm||"0x0000000000000000000000000000000000000000"});return}catch{}await o.client.createPaymentUsd({usdAmount:c,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"evm",icpay_ledger_id:n?.ledgerId}},recipientAddress:(this.config?.recipientAddresses||{})?.evm||"0x0000000000000000000000000000000000000000"})}catch{}});return}this.showBalanceModal=!1,this.showWalletModal=!1;let a=this.pendingAction;if(this.pendingAction=null,a==="pay")try{let n=(this.walletBalances||[]).find(m=>m?.tokenShortcode===e),s=g(this.config),o=Number(this.config?.priceUsd??0),c=String(n?.chainName||n?.ledgerName||"").toLowerCase(),p=c.includes("sol"),h=this.config?.recipientAddresses||{},d=p&&h.sol||h.ic,y=c.includes("ic");if(n?.x402Accepts)try{await s.client.createPaymentX402Usd({usdAmount:o,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:p?"sol":y?"ic":this.config?.icpay_network,icpay_ledger_id:n?.ledgerId,icpay_context:"premium:x402"}},recipientAddress:d||""});return}catch{return}await s.client.createPaymentUsd({usdAmount:o,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"ic",icpay_ledger_id:n?.ledgerId}},recipientAddress:d||"0x0000000000000000000000000000000000000000"})}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-BEKXSS66.js")).WalletSelect);let a={...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:s}=await import("./origin-44ZEXSX4.js");a.derivationOrigin=this.config?.derivationOrigin||s()}}catch{}let n=new ce(a);this.walletConnected=!1,this.config={...this.config,connectedWallet:{owner:t.principal,principal:t.principal,connected:!1}}}catch{}}connectedCallback(){if(super.connectedCallback(),!!De){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{}this.onTransactionCompleted=(()=>{this.unlocked=!0,this.succeeded=!0,this.processing=!1;try{window.dispatchEvent(new CustomEvent("icpay-unlock",{detail:{amount:this.config?.priceUsd,currency:this.selectedSymbol||"ICP"}}))}catch{}this.requestUpdate()});try{window.addEventListener("icpay-sdk-transaction-completed",this.onTransactionCompleted)}catch{}this.onUnlock=(()=>{this.unlocked=!0,this.succeeded=!0,this.processing=!1,this.requestUpdate()});try{window.addEventListener("icpay-unlock",this.onUnlock)}catch{}}}disconnectedCallback(){super.disconnectedCallback();try{window.removeEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}if(this.onTransactionCompleted)try{window.removeEventListener("icpay-sdk-transaction-completed",this.onTransactionCompleted)}catch{}if(this.onUnlock)try{window.removeEventListener("icpay-unlock",this.onUnlock)}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.onPay()},0))}}async onPay(){if(De&&!(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{ce||(ce=(await import("./wallet-select-BEKXSS66.js")).WalletSelect);let t=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab)?$({...this.config?.plugNPlay||{}}):{...this.config?.plugNPlay||{}};this.config?.chainTypes&&(t.chainTypes=this.config.chainTypes);try{if(typeof window<"u"){let{resolveDerivationOrigin:n}=await import("./origin-44ZEXSX4.js");t.derivationOrigin=this.config?.derivationOrigin||n()}}catch{}this.pnp=new ce(t);try{let n=await te(this.pnp);if(n){this.walletConnected=!0;let s=U(this.pnp,{owner:n,principal:n,connected:!0}),o=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:s,actorProvider:(c,p)=>this.pnp.getActor({canisterId:c,idl:p,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 a=this.pnp.getEnabledWallets();if(ve(this.config?.debug||!1,"Available wallets",a),!a?.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.walletModalStep="balances",this.showBalanceModal=!1,this.showWalletModal=!0,await this.fetchAndShowBalances("pay");return}catch(e){_(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),z(t)&&(this.errorMessage=D(t),this.errorSeverity=j(t),this.errorAction=F(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,a=t?.event_id||t?.eventId||t?.id;if(!(!a||typeof a!="string")&&a==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let n=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(n||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 t=await g(this.config).startOnrampUsd(this.config.priceUsd,void 0,{context:"premium:onramp",onrampPayment:!0,onrampProvider:"coinbase"}),a=t?.metadata?.onramp?.url||t?.onramp?.url||t?.metadata?.icpay_onramp?.url||t?.paymentIntent?.metadata?.icpay?.onrampUrl||t?.metadata?.icpay?.onrampUrl||null,n=t?.metadata?.icpay_payment_intent_id||t?.metadata?.paymentIntentId||t?.paymentIntentId||null,s=t?.metadata?.icpay_onramp?.errorMessage||t?.metadata?.onramp?.errorMessage||t?.paymentIntent?.metadata?.icpay?.onrampError||t?.paymentIntent?.metadata?.icpay?.errorMessage||t?.metadata?.icpay?.onrampError||t?.metadata?.icpay?.errorMessage||null;if(this.onrampPaymentIntentId=n,a){this.onrampUrl=a,this.onrampErrorMessage=null;try{window.open(a,"icpay_onramp","noopener,noreferrer");try{window.dispatchEvent(new CustomEvent("icpay-onramp-opened",{detail:{url:a}}))}catch{}}catch{}this.startOnrampPolling()}else this.onrampUrl=null,this.onrampErrorMessage=s||"Failed to obtain onramp URL",this.showOnrampModal=!0}catch(e){this.onrampUrl=null,this.onrampErrorMessage=e?.message||"Failed to obtain onramp URL",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 a=g(this.config),n=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>n()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=a.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(a=>{if(!!!(a&&(a.connected===!0||a.principal||a.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 s=U(this.pnp,a),o=this.pnp?.getEvmProvider?.(),c=this.pnp?.getSolanaProvider?.();this.config={...this.config,connectedWallet:s,actorProvider:(p,h)=>this.pnp.getActor({canisterId:p,idl:h,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{},...c?{solanaProvider:c}:{}},this.sdk=null,this.walletModalStep="balances",this.showBalanceModal=!1,this.showWalletModal=!0,this.fetchAndShowBalances("pay")}).catch(a=>{this.errorMessage=a instanceof Error?a.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.walletModalStep="balances",this.showBalanceModal=!1;let t=g(this.config),{balances:a}=await X({sdk:t,lastWalletId:this.lastWalletId,connectedWallet:this.config?.connectedWallet,amountUsd:Number(this.config?.priceUsd??0)});this.walletBalances=a,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?ne`
|
|
1462
1492
|
<div class="icpay-card icpay-section icpay-widget-base">
|
|
1463
|
-
${this.config?.progressBar?.enabled!==!1?
|
|
1493
|
+
${this.config?.progressBar?.enabled!==!1?ne`
|
|
1464
1494
|
<icpay-progress-bar
|
|
1465
1495
|
.debug=${!!this.config?.debug}
|
|
1466
1496
|
.theme=${this.config?.theme}
|
|
@@ -1470,7 +1500,7 @@ import{a as r}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var j=Xe`
|
|
|
1470
1500
|
`:null}
|
|
1471
1501
|
<div class="image-container">
|
|
1472
1502
|
<div class="locked-image ${this.unlocked?"unlocked":""}" style="background-image:url('${this.config.imageUrl||""}')"></div>
|
|
1473
|
-
${this.unlocked?null:
|
|
1503
|
+
${this.unlocked?null:ne`<div class="lock-overlay">🔒</div>`}
|
|
1474
1504
|
</div>
|
|
1475
1505
|
|
|
1476
1506
|
<div class="pricing">
|
|
@@ -1484,26 +1514,28 @@ import{a as r}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var j=Xe`
|
|
|
1484
1514
|
${this.unlocked?"Unlocked":this.processing?"Processing\u2026":(this.config?.buttonLabel||"Pay ${amount} with crypto").replace("{amount}",`${Number(this.config?.priceUsd??0).toFixed(2)}`).replace("{symbol}",this.selectedSymbol||"ICP")}
|
|
1485
1515
|
</button>
|
|
1486
1516
|
|
|
1487
|
-
${this.errorMessage?
|
|
1517
|
+
${this.errorMessage?ne`
|
|
1488
1518
|
<div class="error-message ${this.errorSeverity}" style="margin-top: 12px; padding: 8px 12px; border-radius: 6px; font-size: 14px; text-align: center;">
|
|
1489
1519
|
${this.errorMessage}
|
|
1490
|
-
${this.errorAction?
|
|
1520
|
+
${this.errorAction?ne`
|
|
1491
1521
|
<button style="margin-left: 8px; padding: 4px 8px; background: transparent; border: 1px solid currentColor; border-radius: 4px; font-size: 12px; cursor: pointer;">
|
|
1492
1522
|
${this.errorAction}
|
|
1493
1523
|
</button>
|
|
1494
1524
|
`:""}
|
|
1495
1525
|
</div>
|
|
1496
1526
|
`:""}
|
|
1497
|
-
${(()=>{let e=this.pnp?.getEnabledWallets?.()||[],t=H(e);return G({visible:!!(this.showWalletModal&&this.pnp),wallets:t,isConnecting:!1,step:this.walletModalStep,balances:this.walletModalStep==="balances"?this.walletBalances:[],balancesLoading:this.walletModalStep==="balances"?this.balancesLoading:!1,balancesError:this.walletModalStep==="balances"?this.balancesError:null,onSelectBalance:
|
|
1527
|
+
${(()=>{let e=this.pnp?.getEnabledWallets?.()||[],t=H(e),a=this.config?.theme?typeof this.config.theme=="string"?this.config.theme:this.config.theme.mode||"light":void 0;return G({visible:!!(this.showWalletModal&&this.pnp),wallets:t,isConnecting:!1,step:this.walletModalStep,balances:this.walletModalStep==="balances"?this.walletBalances:[],balancesLoading:this.walletModalStep==="balances"?this.balancesLoading:!1,balancesError:this.walletModalStep==="balances"?this.balancesError:null,onSelectBalance:n=>this.onSelectBalanceSymbol(n),onBack:()=>{this.walletModalStep="connect"},onSwitchAccount:()=>this.onSwitchAccount(null),onSelect:n=>this.connectWithWallet(n),onClose:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-cancelled",{detail:{reason:"user_cancelled"}}))}catch{}},onDismiss:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1},onCreditCard:this.config?.onramp?.enabled===!0&&this.config?.onrampDisabled!==!0?()=>this.startOnramp():void 0,creditCardLabel:this.config?.onramp?.creditCardLabel||"Pay with credit card",showCreditCard:this.config?.onramp?.enabled===!0&&this.config?.onrampDisabled!==!0,creditCardTooltip:(()=>{let s=Number(this.config?.priceUsd||0);return s>0&&s<5&&this.config?.onramp?.enabled===!0&&this.config?.onrampDisabled!==!0?`Note: Minimum card amount is $5. You will pay about $${(5-s).toFixed(2)} more.`:null})(),oisyReadyToPay:this.oisyReadyToPay,onOisyPay:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1,this.onPay()},theme:a})})()}
|
|
1498
1528
|
|
|
1499
|
-
${
|
|
1529
|
+
${(()=>{let e=this.config?.theme?typeof this.config.theme=="string"?this.config.theme:this.config.theme.mode||"light":void 0;return ne`
|
|
1530
|
+
${Q({visible:this.showBalanceModal,isLoading:this.balancesLoading,error:this.balancesError,balances:this.walletBalances,onSelect:t=>this.onSelectBalanceSymbol(t),onClose:()=>{this.showBalanceModal=!1},theme:e})}
|
|
1500
1531
|
|
|
1501
|
-
|
|
1532
|
+
${q({visible:this.showOnrampModal,url:this.onrampUrl||void 0,errorMessage:this.onrampErrorMessage||void 0,width:this.config?.onramp?.width,height:this.config?.onramp?.height,onClose:()=>{this.showOnrampModal=!1},onBack:()=>{this.showOnrampModal=!1,this.showWalletModal=!0},title:"Pay with credit card",theme:e})}
|
|
1533
|
+
`})()}
|
|
1502
1534
|
<div class="icpay-powered-by">
|
|
1503
1535
|
<a href="https://icpay.org" target="_blank" rel="noopener noreferrer">Powered by icpay</a>
|
|
1504
1536
|
</div>
|
|
1505
1537
|
</div>
|
|
1506
|
-
`:
|
|
1538
|
+
`:ne`<div class="icpay-card icpay-section">Loading...</div>`}};E.styles=[K,ht`
|
|
1507
1539
|
.image-container {
|
|
1508
1540
|
position: relative;
|
|
1509
1541
|
border-radius: 16px;
|
|
@@ -1554,9 +1586,9 @@ import{a as r}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var j=Xe`
|
|
|
1554
1586
|
border-color: var(--icpay-error-border);
|
|
1555
1587
|
color: var(--icpay-error-text);
|
|
1556
1588
|
}
|
|
1557
|
-
`],r([ut({type:Object})],k.prototype,"config",2),r([L()],k.prototype,"selectedSymbol",2),r([L()],k.prototype,"unlocked",2),r([L()],k.prototype,"succeeded",2),r([L()],k.prototype,"processing",2),r([L()],k.prototype,"errorMessage",2),r([L()],k.prototype,"errorSeverity",2),r([L()],k.prototype,"errorAction",2),r([L()],k.prototype,"walletConnected",2),r([L()],k.prototype,"pendingAction",2),r([L()],k.prototype,"showWalletModal",2),r([L()],k.prototype,"walletModalStep",2),r([L()],k.prototype,"oisyReadyToPay",2),r([L()],k.prototype,"lastWalletId",2),r([L()],k.prototype,"showOnrampModal",2),r([L()],k.prototype,"onrampUrl",2),r([L()],k.prototype,"onrampPaymentIntentId",2),r([L()],k.prototype,"onrampErrorMessage",2),r([L()],k.prototype,"showBalanceModal",2),r([L()],k.prototype,"balancesLoading",2),r([L()],k.prototype,"balancesError",2),r([L()],k.prototype,"walletBalances",2),k=r([yt("icpay-premium-content")],k);import{LitElement as gt,html as oe,css as mt}from"lit";import{customElement as ft,property as vt,state as W}from"lit/decorators.js";var ze=typeof window<"u",le=null;function ge(i,s,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${s}`,e):console.log(`[ICPay Widget] ${s}`))}var w=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.walletModalStep="connect";this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.showOnrampModal=!1;this.onrampUrl=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),a=this.selectedSymbol||"ICP";window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"tip",type:"sendUsd",amount:t,currency:a}}))}catch{}}catch{}};this.onSelectBalanceSymbol=async e=>{let t=(this.walletBalances||[]).find(n=>n?.tokenShortcode===e);if(t?.ledgerSymbol&&(this.selectedSymbol=t.ledgerSymbol),this.showBalanceModal=!1,this.showWalletModal=!1,B(this.lastWalletId)){let n=(this.walletBalances||[]).find(l=>l?.tokenShortcode===e),o=n?.chainId;V(o,{provider:this.pnp?.getEvmProvider?.()||this.config?.evmProvider,chainName:n?.chainName,rpcUrlPublic:n?.rpcUrlPublic,nativeSymbol:n?.ledgerSymbol,decimals:n?.decimals}).then(async()=>{try{let l=u(this.config),d=Number(this.selectedAmount||0);if(n?.x402Accepts)try{await l.client.createPaymentX402Usd({usdAmount:d,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"evm",icpay_ledger_id:n?.ledgerId,icpay_context:"tip:x402"}},recipientAddress:(this.config?.recipientAddresses||{})?.evm||"0x0000000000000000000000000000000000000000"}),this.showBalanceModal=!1;return}catch{}await l.client.createPaymentUsd({usdAmount:d,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"evm",icpay_ledger_id:n?.ledgerId}},recipientAddress:(this.config?.recipientAddresses||{})?.evm||"0x0000000000000000000000000000000000000000"})}catch{}this.showBalanceModal=!1});return}let a=this.pendingAction;if(this.pendingAction=null,a==="tip")try{let n=(this.walletBalances||[]).find(g=>g?.tokenShortcode===e),o=u(this.config),l=Number(this.selectedAmount||0),d=String(n?.ledgerName||n?.chainName||"").toLowerCase(),p=d.includes("sol"),h=d.includes("ic"),c=this.config?.recipientAddresses||{},y=p&&c.sol||c.ic;if(n?.x402Accepts)try{await o.client.createPaymentX402Usd({usdAmount:l,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:p?"sol":h?"ic":this.config?.icpay_network,icpay_ledger_id:n?.ledgerId,icpay_context:"tip:x402"}},recipientAddress:y||""});return}catch{return}await o.client.createPaymentUsd({usdAmount:l,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"ic",icpay_ledger_id:n?.ledgerId}},recipientAddress:y||"0x0000000000000000000000000000000000000000"})}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;le||(le=(await import("./wallet-select-BEKXSS66.js")).WalletSelect);let a=$({...this.config?.plugNPlay||{}});try{if(typeof window<"u"){let{resolveDerivationOrigin:o}=await import("./origin-44ZEXSX4.js");a.derivationOrigin=this.config?.derivationOrigin||o()}}catch{}let n=new le(a);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(),!!ze){ge(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;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}this.walletModalStep!=="balances"&&!this.oisyReadyToPay&&(this.pendingAction=null,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(ze&&(ge(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){ge(this.config?.debug||!1,"Connecting to wallet via wallet");try{le||(le=(await import("./wallet-select-BEKXSS66.js")).WalletSelect);let t=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab)?$({...this.config?.plugNPlay||{}}):{...this.config?.plugNPlay||{}};this.config?.chainTypes&&(t.chainTypes=this.config.chainTypes);try{if(typeof window<"u"){let{resolveDerivationOrigin:n}=await import("./origin-44ZEXSX4.js");t.derivationOrigin=this.config?.derivationOrigin||n()}}catch{}this.pnp=new le(t);try{let n=await te(this.pnp);if(n){this.walletConnected=!0;let o=U(this.pnp,{owner:n,principal:n,connected:!0}),l=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:o,actorProvider:(d,p)=>this.pnp.getActor({canisterId:d,idl:p,requiresSigning:!0,anon:!1}),...l?{evmProvider:l}:{}},this.sdk=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"oisy"}}))}catch{}this.tip();return}}catch{}let a=this.pnp.getEnabledWallets();if(ge(this.config?.debug||!1,"Available wallets",a),!a?.length)throw new Error("No wallets available");this.pendingAction="tip",this.showWalletModal=!0;return}catch(e){ge(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){_(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),z(t)&&(this.errorMessage=D(t),this.errorSeverity=K(t),this.errorAction=F(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,a=t?.event_id||t?.eventId||t?.id;if(!(!a||typeof a!="string")&&a==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let n=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(n||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 t=await u(this.config).startOnrampUsd(this.selectedAmount,void 0,{context:"tip:onramp",onrampPayment:!0,onrampProvider:this?.selectedOnrampProvider||"coinbase"}),a=t?.metadata?.onramp?.url||t?.onramp?.url||t?.metadata?.icpay_onramp?.url||t?.paymentIntent?.metadata?.icpay?.onrampUrl||t?.metadata?.icpay?.onrampUrl||null,n=t?.metadata?.icpay_payment_intent_id||t?.metadata?.paymentIntentId||t?.paymentIntentId||null,o=t?.metadata?.icpay_onramp?.errorMessage||t?.metadata?.onramp?.errorMessage||t?.paymentIntent?.metadata?.icpay?.onrampError||t?.paymentIntent?.metadata?.icpay?.errorMessage||t?.metadata?.icpay?.onrampError||t?.metadata?.icpay?.errorMessage||null;if(this.onrampPaymentIntentId=n,a){this.onrampUrl=a,this.onrampErrorMessage=null;try{window.open(a,"icpay_onramp","noopener,noreferrer");try{window.dispatchEvent(new CustomEvent("icpay-onramp-opened",{detail:{url:a}}))}catch{}}catch{}this.startOnrampPolling()}else this.onrampUrl=null,this.onrampErrorMessage=o||"Failed to obtain onramp sessionId",this.showOnrampModal=!0}catch(e){this.onrampUrl=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 a=u(this.config),n=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>n()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=a.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(a=>{if(!!!(a&&(a.connected===!0||a.principal||a.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}let o=U(this.pnp,a),l=this.pnp?.getEvmProvider?.(),d=this.pnp?.getSolanaProvider?.();this.config={...this.config,connectedWallet:o,actorProvider:(p,h)=>this.pnp.getActor({canisterId:p,idl:h,requiresSigning:!0,anon:!1}),...l?{evmProvider:l}:{},...d?{solanaProvider:d}:{}},this.sdk=null,this.walletModalStep="balances",this.showBalanceModal=!1,this.showWalletModal=!0,this.fetchAndShowBalances()}).catch(a=>{this.errorMessage=a instanceof Error?a.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.walletModalStep="balances",this.showBalanceModal=!1;let e=u(this.config),{balances:t}=await X({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?oe`
|
|
1589
|
+
`],r([gt({type:Object})],E.prototype,"config",2),r([L()],E.prototype,"selectedSymbol",2),r([L()],E.prototype,"unlocked",2),r([L()],E.prototype,"succeeded",2),r([L()],E.prototype,"processing",2),r([L()],E.prototype,"errorMessage",2),r([L()],E.prototype,"errorSeverity",2),r([L()],E.prototype,"errorAction",2),r([L()],E.prototype,"walletConnected",2),r([L()],E.prototype,"pendingAction",2),r([L()],E.prototype,"showWalletModal",2),r([L()],E.prototype,"walletModalStep",2),r([L()],E.prototype,"oisyReadyToPay",2),r([L()],E.prototype,"lastWalletId",2),r([L()],E.prototype,"showOnrampModal",2),r([L()],E.prototype,"onrampUrl",2),r([L()],E.prototype,"onrampPaymentIntentId",2),r([L()],E.prototype,"onrampErrorMessage",2),r([L()],E.prototype,"showBalanceModal",2),r([L()],E.prototype,"balancesLoading",2),r([L()],E.prototype,"balancesError",2),r([L()],E.prototype,"walletBalances",2),E=r([yt("icpay-premium-content")],E);import{LitElement as mt,html as ie,css as ut}from"lit";import{customElement as ft,property as vt,state as W}from"lit/decorators.js";var ze=typeof window<"u",pe=null;function be(i,l,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${l}`,e):console.log(`[ICPay Widget] ${l}`))}var w=class extends mt{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.walletModalStep="connect";this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.showOnrampModal=!1;this.onrampUrl=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),a=this.selectedSymbol||"ICP";window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"tip",type:"sendUsd",amount:t,currency:a}}))}catch{}}catch{}};this.onSelectBalanceSymbol=async e=>{let t=(this.walletBalances||[]).find(n=>n?.tokenShortcode===e);if(t?.ledgerSymbol&&(this.selectedSymbol=t.ledgerSymbol),this.showBalanceModal=!1,this.showWalletModal=!1,B(this.lastWalletId)){let n=(this.walletBalances||[]).find(o=>o?.tokenShortcode===e),s=n?.chainId;V(s,{provider:this.pnp?.getEvmProvider?.()||this.config?.evmProvider,chainName:n?.chainName,rpcUrlPublic:n?.rpcUrlPublic,nativeSymbol:n?.ledgerSymbol,decimals:n?.decimals}).then(async()=>{try{let o=g(this.config),c=Number(this.selectedAmount||0);if(n?.x402Accepts)try{await o.client.createPaymentX402Usd({usdAmount:c,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"evm",icpay_ledger_id:n?.ledgerId,icpay_context:"tip:x402"}},recipientAddress:(this.config?.recipientAddresses||{})?.evm||"0x0000000000000000000000000000000000000000"}),this.showBalanceModal=!1;return}catch{}await o.client.createPaymentUsd({usdAmount:c,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"evm",icpay_ledger_id:n?.ledgerId}},recipientAddress:(this.config?.recipientAddresses||{})?.evm||"0x0000000000000000000000000000000000000000"})}catch{}this.showBalanceModal=!1});return}let a=this.pendingAction;if(this.pendingAction=null,a==="tip")try{let n=(this.walletBalances||[]).find(m=>m?.tokenShortcode===e),s=g(this.config),o=Number(this.selectedAmount||0),c=String(n?.ledgerName||n?.chainName||"").toLowerCase(),p=c.includes("sol"),h=c.includes("ic"),d=this.config?.recipientAddresses||{},y=p&&d.sol||d.ic;if(n?.x402Accepts)try{await s.client.createPaymentX402Usd({usdAmount:o,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:p?"sol":h?"ic":this.config?.icpay_network,icpay_ledger_id:n?.ledgerId,icpay_context:"tip:x402"}},recipientAddress:y||""});return}catch{return}await s.client.createPaymentUsd({usdAmount:o,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"ic",icpay_ledger_id:n?.ledgerId}},recipientAddress:y||"0x0000000000000000000000000000000000000000"})}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;pe||(pe=(await import("./wallet-select-BEKXSS66.js")).WalletSelect);let a=$({...this.config?.plugNPlay||{}});try{if(typeof window<"u"){let{resolveDerivationOrigin:s}=await import("./origin-44ZEXSX4.js");a.derivationOrigin=this.config?.derivationOrigin||s()}}catch{}let n=new pe(a);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(),!!ze){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;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}this.walletModalStep!=="balances"&&!this.oisyReadyToPay&&(this.pendingAction=null,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(ze&&(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{pe||(pe=(await import("./wallet-select-BEKXSS66.js")).WalletSelect);let t=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab)?$({...this.config?.plugNPlay||{}}):{...this.config?.plugNPlay||{}};this.config?.chainTypes&&(t.chainTypes=this.config.chainTypes);try{if(typeof window<"u"){let{resolveDerivationOrigin:n}=await import("./origin-44ZEXSX4.js");t.derivationOrigin=this.config?.derivationOrigin||n()}}catch{}this.pnp=new pe(t);try{let n=await te(this.pnp);if(n){this.walletConnected=!0;let s=U(this.pnp,{owner:n,principal:n,connected:!0}),o=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:s,actorProvider:(c,p)=>this.pnp.getActor({canisterId:c,idl:p,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 a=this.pnp.getEnabledWallets();if(be(this.config?.debug||!1,"Available wallets",a),!a?.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){_(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),z(t)&&(this.errorMessage=D(t),this.errorSeverity=j(t),this.errorAction=F(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,a=t?.event_id||t?.eventId||t?.id;if(!(!a||typeof a!="string")&&a==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let n=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(n||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 t=await g(this.config).startOnrampUsd(this.selectedAmount,void 0,{context:"tip:onramp",onrampPayment:!0,onrampProvider:this?.selectedOnrampProvider||"coinbase"}),a=t?.metadata?.onramp?.url||t?.onramp?.url||t?.metadata?.icpay_onramp?.url||t?.paymentIntent?.metadata?.icpay?.onrampUrl||t?.metadata?.icpay?.onrampUrl||null,n=t?.metadata?.icpay_payment_intent_id||t?.metadata?.paymentIntentId||t?.paymentIntentId||null,s=t?.metadata?.icpay_onramp?.errorMessage||t?.metadata?.onramp?.errorMessage||t?.paymentIntent?.metadata?.icpay?.onrampError||t?.paymentIntent?.metadata?.icpay?.errorMessage||t?.metadata?.icpay?.onrampError||t?.metadata?.icpay?.errorMessage||null;if(this.onrampPaymentIntentId=n,a){this.onrampUrl=a,this.onrampErrorMessage=null;try{window.open(a,"icpay_onramp","noopener,noreferrer");try{window.dispatchEvent(new CustomEvent("icpay-onramp-opened",{detail:{url:a}}))}catch{}}catch{}this.startOnrampPolling()}else this.onrampUrl=null,this.onrampErrorMessage=s||"Failed to obtain onramp sessionId",this.showOnrampModal=!0}catch(e){this.onrampUrl=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 a=g(this.config),n=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>n()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=a.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(a=>{if(!!!(a&&(a.connected===!0||a.principal||a.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 s=U(this.pnp,a),o=this.pnp?.getEvmProvider?.(),c=this.pnp?.getSolanaProvider?.();this.config={...this.config,connectedWallet:s,actorProvider:(p,h)=>this.pnp.getActor({canisterId:p,idl:h,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{},...c?{solanaProvider:c}:{}},this.sdk=null,this.walletModalStep="balances",this.showBalanceModal=!1,this.showWalletModal=!0,this.fetchAndShowBalances()}).catch(a=>{this.errorMessage=a instanceof Error?a.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.walletModalStep="balances",this.showBalanceModal=!1;let e=g(this.config),{balances:t}=await X({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?ie`
|
|
1558
1590
|
<div class="icpay-card icpay-section icpay-widget-base" style="text-align:center;">
|
|
1559
|
-
${this.config?.progressBar?.enabled!==!1?
|
|
1591
|
+
${this.config?.progressBar?.enabled!==!1?ie`
|
|
1560
1592
|
<icpay-progress-bar
|
|
1561
1593
|
.debug=${!!this.config?.debug}
|
|
1562
1594
|
.theme=${this.config?.theme}
|
|
@@ -1568,7 +1600,7 @@ import{a as r}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var j=Xe`
|
|
|
1568
1600
|
<div class="label">Total Tips: $${this.total}</div>
|
|
1569
1601
|
|
|
1570
1602
|
<div class="amounts">
|
|
1571
|
-
${this.amounts.map(e=>
|
|
1603
|
+
${this.amounts.map(e=>ie`<div class="chip ${this.selectedAmount===e?"selected":""}" @click=${()=>this.selectAmount(e)}>$${e}</div>`)}
|
|
1572
1604
|
</div>
|
|
1573
1605
|
|
|
1574
1606
|
|
|
@@ -1579,26 +1611,28 @@ import{a as r}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var j=Xe`
|
|
|
1579
1611
|
${this.succeeded&&this.config?.disableAfterSuccess?"Paid":this.processing?"Processing\u2026":this.config?.buttonLabel?this.config.buttonLabel.replace("{amount}",String(this.selectedAmount)).replace("{symbol}",this.selectedSymbol||"ICP"):`Tip $${this.selectedAmount} with crypto`}
|
|
1580
1612
|
</button>
|
|
1581
1613
|
|
|
1582
|
-
${this.errorMessage?
|
|
1614
|
+
${this.errorMessage?ie`
|
|
1583
1615
|
<div class="error-message ${this.errorSeverity}" style="margin-top: 12px; padding: 8px 12px; border-radius: 6px; font-size: 14px; text-align: center;">
|
|
1584
1616
|
${this.errorMessage}
|
|
1585
|
-
${this.errorAction?
|
|
1617
|
+
${this.errorAction?ie`
|
|
1586
1618
|
<button style="margin-left: 8px; padding: 4px 8px; background: transparent; border: 1px solid currentColor; border-radius: 4px; font-size: 12px; cursor: pointer;">
|
|
1587
1619
|
${this.errorAction}
|
|
1588
1620
|
</button>
|
|
1589
1621
|
`:""}
|
|
1590
1622
|
</div>
|
|
1591
1623
|
`:""}
|
|
1592
|
-
${(()=>{let e=this.pnp?.getEnabledWallets?.()||[],t=H(e);return G({visible:!!(this.showWalletModal&&this.pnp),wallets:t,isConnecting:!1,step:this.walletModalStep,balances:this.walletModalStep==="balances"?this.walletBalances:[],balancesLoading:this.walletModalStep==="balances"?this.balancesLoading:!1,balancesError:this.walletModalStep==="balances"?this.balancesError:null,onSelectBalance:
|
|
1624
|
+
${(()=>{let e=this.pnp?.getEnabledWallets?.()||[],t=H(e),a=this.config?.theme?typeof this.config.theme=="string"?this.config.theme:this.config.theme.mode||"light":void 0;return G({visible:!!(this.showWalletModal&&this.pnp),wallets:t,isConnecting:!1,step:this.walletModalStep,balances:this.walletModalStep==="balances"?this.walletBalances:[],balancesLoading:this.walletModalStep==="balances"?this.balancesLoading:!1,balancesError:this.walletModalStep==="balances"?this.balancesError:null,onSelectBalance:n=>this.onSelectBalanceSymbol(n),onBack:()=>{this.walletModalStep="connect"},onSwitchAccount:()=>this.onSwitchAccount(null),onSelect:n=>this.connectWithWallet(n),onClose:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-cancelled",{detail:{reason:"user_cancelled"}}))}catch{}},onDismiss:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1},onCreditCard:this.config?.onramp?.enabled===!0&&this.config?.onrampDisabled!==!0?()=>this.startOnramp():void 0,creditCardLabel:this.config?.onramp?.creditCardLabel||"Pay with credit card",showCreditCard:this.config?.onramp?.enabled===!0&&this.config?.onrampDisabled!==!0,creditCardTooltip:(()=>{let s=Number(this.selectedAmount||this.config?.defaultAmountUsd||0);return s>0&&s<5&&this.config?.onramp?.enabled===!0&&this.config?.onrampDisabled!==!0?`Note: Minimum card amount is $5. You will pay about $${(5-s).toFixed(2)} more.`:null})(),oisyReadyToPay:this.oisyReadyToPay,onOisyPay:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1,this.tip()},theme:a})})()}
|
|
1593
1625
|
|
|
1594
|
-
${
|
|
1626
|
+
${(()=>{let e=this.config?.theme?typeof this.config.theme=="string"?this.config.theme:this.config.theme.mode||"light":void 0;return ie`
|
|
1627
|
+
${Q({visible:this.showBalanceModal,isLoading:this.balancesLoading,error:this.balancesError,balances:this.walletBalances,onSelect:t=>this.onSelectBalanceSymbol(t),onClose:()=>{this.showBalanceModal=!1},theme:e})}
|
|
1595
1628
|
|
|
1596
|
-
|
|
1629
|
+
${q({visible:this.showOnrampModal,url:this.onrampUrl||void 0,errorMessage:this.onrampErrorMessage||void 0,width:this.config?.onramp?.width,height:this.config?.onramp?.height,onClose:()=>{this.showOnrampModal=!1},onBack:()=>{this.showOnrampModal=!1,this.showWalletModal=!0},title:"Pay with credit card",theme:e})}
|
|
1630
|
+
`})()}
|
|
1597
1631
|
<div class="icpay-powered-by">
|
|
1598
1632
|
<a href="https://icpay.org" target="_blank" rel="noopener noreferrer">Powered by icpay</a>
|
|
1599
1633
|
</div>
|
|
1600
1634
|
</div>
|
|
1601
|
-
`:
|
|
1635
|
+
`:ie`<div class="icpay-card icpay-section">Loading...</div>`}};w.styles=[K,ut`
|
|
1602
1636
|
.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; }
|
|
1603
1637
|
.fill { position: absolute; bottom: 0; left: 0; right: 0; background: linear-gradient(135deg, #d1d5db 0%, #9ca3af 100%); transition: height 0.8s ease; height: 0%; }
|
|
1604
1638
|
.amounts { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; margin: 12px 0; }
|
|
@@ -1630,9 +1664,9 @@ import{a as r}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var j=Xe`
|
|
|
1630
1664
|
border-color: var(--icpay-error-border);
|
|
1631
1665
|
color: var(--icpay-error-text);
|
|
1632
1666
|
}
|
|
1633
|
-
`],r([vt({type:Object})],w.prototype,"config",2),r([W()],w.prototype,"selectedAmount",2),r([W()],w.prototype,"selectedSymbol",2),r([W()],w.prototype,"total",2),r([W()],w.prototype,"processing",2),r([W()],w.prototype,"succeeded",2),r([W()],w.prototype,"errorMessage",2),r([W()],w.prototype,"errorSeverity",2),r([W()],w.prototype,"errorAction",2),r([W()],w.prototype,"walletConnected",2),r([W()],w.prototype,"pendingAction",2),r([W()],w.prototype,"showWalletModal",2),r([W()],w.prototype,"walletModalStep",2),r([W()],w.prototype,"oisyReadyToPay",2),r([W()],w.prototype,"lastWalletId",2),r([W()],w.prototype,"showOnrampModal",2),r([W()],w.prototype,"onrampUrl",2),r([W()],w.prototype,"onrampPaymentIntentId",2),r([W()],w.prototype,"onrampErrorMessage",2),r([W()],w.prototype,"showBalanceModal",2),r([W()],w.prototype,"balancesLoading",2),r([W()],w.prototype,"balancesError",2),r([W()],w.prototype,"walletBalances",2),w=r([ft("icpay-tip-jar")],w);import{LitElement as bt,html as me,css as wt}from"lit";import{customElement as xt,property as Ce,state as T}from"lit/decorators.js";var Fe=typeof window<"u",ce=null;function fe(i,s,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${s}`,e):console.log(`[ICPay Widget] ${s}`))}var m=class extends bt{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.walletModalStep="connect";this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.showOnrampModal=!1;this.onrampUrl=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),a=this.selectedSymbol||"ICP";window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"unlock",type:"sendUsd",amount:t,currency:a}}))}catch{}}catch{}};this.onSelectBalanceSymbol=async e=>{let t=(this.walletBalances||[]).find(n=>n?.tokenShortcode===e);if(t?.ledgerSymbol&&(this.selectedSymbol=t.ledgerSymbol),B(this.lastWalletId)){let n=(this.walletBalances||[]).find(l=>l?.tokenShortcode===e),o=n?.chainId;this.showBalanceModal=!1,this.showWalletModal=!1,V(o,{provider:this.pnp?.getEvmProvider?.()||this.config?.evmProvider,chainName:n?.chainName,rpcUrlPublic:n?.rpcUrlPublic,nativeSymbol:n?.ledgerSymbol,decimals:n?.decimals}).then(async()=>{try{let l=u(this.config),d=Number(this.config?.priceUsd??0);if(n?.x402Accepts)try{await l.client.createPaymentX402Usd({usdAmount:d,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"evm",icpay_ledger_id:n?.ledgerId,icpay_context:"article:x402"}},recipientAddress:(this.config?.recipientAddresses||{})?.evm||"0x0000000000000000000000000000000000000000"});return}catch{}await l.client.createPaymentUsd({usdAmount:d,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"evm",icpay_ledger_id:n?.ledgerId}},recipientAddress:(this.config?.recipientAddresses||{})?.evm||"0x0000000000000000000000000000000000000000"})}catch{}});return}this.showBalanceModal=!1,this.showWalletModal=!1;let a=this.pendingAction;if(this.pendingAction=null,a==="unlock")try{let n=(this.walletBalances||[]).find(y=>y?.tokenShortcode===e),o=u(this.config),l=Number(this.config?.priceUsd??0),p=String(n?.ledgerName||n?.chainName||"").toLowerCase().includes("sol"),h=this.config?.recipientAddresses||{},c=p&&h.sol||h.ic;if(p&&n?.x402Accepts)try{await o.client.createPaymentX402Usd({usdAmount:l,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"sol",icpay_ledger_id:n?.ledgerId,icpay_context:"article:x402"}},recipientAddress:c||""});return}catch{return}await o.client.createPaymentUsd({usdAmount:l,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"ic",icpay_ledger_id:n?.ledgerId}},recipientAddress:c||"0x0000000000000000000000000000000000000000"})}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;ce||(ce=(await import("./wallet-select-BEKXSS66.js")).WalletSelect);let a={...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:o}=await import("./origin-44ZEXSX4.js");a.derivationOrigin=this.config?.derivationOrigin||o()}}catch{}let n=new ce(a);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,a=t?.event_id||t?.eventId||t?.id;if(!(!a||typeof a!="string")&&a==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let n=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(n||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 t=await u(this.config).startOnrampUsd(this.config.priceUsd,void 0,{context:"article:onramp",onrampPayment:!0,onrampProvider:"coinbase"}),a=t?.metadata?.onramp?.url||t?.onramp?.url||t?.metadata?.icpay_onramp?.url||t?.paymentIntent?.metadata?.icpay?.onrampUrl||t?.metadata?.icpay?.onrampUrl||null,n=t?.metadata?.icpay_payment_intent_id||t?.metadata?.paymentIntentId||t?.paymentIntentId||null,o=t?.metadata?.icpay_onramp?.errorMessage||t?.metadata?.onramp?.errorMessage||t?.paymentIntent?.metadata?.icpay?.onrampError||t?.paymentIntent?.metadata?.icpay?.errorMessage||t?.metadata?.icpay?.onrampError||t?.metadata?.icpay?.errorMessage||null;if(this.onrampPaymentIntentId=n,a){this.onrampUrl=a,this.onrampErrorMessage=null;try{window.open(a,"icpay_onramp","noopener,noreferrer");try{window.dispatchEvent(new CustomEvent("icpay-onramp-opened",{detail:{url:a}}))}catch{}}catch{}this.startOnrampPolling()}else this.onrampUrl=null,this.onrampErrorMessage=o||"Failed to obtain onramp URL",this.showOnrampModal=!0}catch(e){this.onrampUrl=null,this.onrampErrorMessage=e?.message||"Failed to obtain onramp URL",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 a=u(this.config),n=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>n()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=a.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}connectedCallback(){if(super.connectedCallback(),!!Fe){fe(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;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}this.walletModalStep!=="balances"&&!this.oisyReadyToPay&&(this.pendingAction=null,setTimeout(()=>{t==="unlock"&&this.unlock()},0))}}selectSymbol(e){this.selectedSymbol=e}async unlock(){if(Fe&&!(this.processing||this.unlocked)){fe(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){fe(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{ce||(ce=(await import("./wallet-select-BEKXSS66.js")).WalletSelect);let t=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab)?$({...this.config?.plugNPlay||{}}):{...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:n}=await import("./origin-44ZEXSX4.js");t.derivationOrigin=this.config?.derivationOrigin||n()}}catch{}this.pnp=new ce(t);try{let n=await te(this.pnp);if(n){this.walletConnected=!0;let o=U(this.pnp,{owner:n,principal:n,connected:!0}),l=this.pnp?.getEvmProvider?.(),d=this.pnp?.getSolanaProvider?.();this.config={...this.config,connectedWallet:o,actorProvider:(p,h)=>this.pnp.getActor({canisterId:p,idl:h,requiresSigning:!0,anon:!1}),...l?{evmProvider:l}:{},...d?{solanaProvider:d}:{}},this.sdk=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"oisy"}}))}catch{}this.unlock();return}}catch{}let a=this.pnp.getEnabledWallets();if(fe(this.config?.debug||!1,"Available wallets",a),!a?.length)throw new Error("No wallets available");this.pendingAction="unlock",this.showWalletModal=!0;return}catch(e){fe(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){_(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),z(t)&&(this.errorMessage=D(t),this.errorSeverity=K(t),this.errorAction=F(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(a=>{if(!!!(a&&(a.connected===!0||a.principal||a.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}let o=U(this.pnp,a),l=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:o,actorProvider:(d,p)=>this.pnp.getActor({canisterId:d,idl:p,requiresSigning:!0,anon:!1}),...l?{evmProvider:l}:{}},this.sdk=null,this.walletModalStep="balances",this.showBalanceModal=!1,this.showWalletModal=!0,this.fetchAndShowBalances()}).catch(a=>{this.errorMessage=a instanceof Error?a.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.walletModalStep="balances",this.showBalanceModal=!1;let e=u(this.config),{balances:t}=await X({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?me`
|
|
1667
|
+
`],r([vt({type:Object})],w.prototype,"config",2),r([W()],w.prototype,"selectedAmount",2),r([W()],w.prototype,"selectedSymbol",2),r([W()],w.prototype,"total",2),r([W()],w.prototype,"processing",2),r([W()],w.prototype,"succeeded",2),r([W()],w.prototype,"errorMessage",2),r([W()],w.prototype,"errorSeverity",2),r([W()],w.prototype,"errorAction",2),r([W()],w.prototype,"walletConnected",2),r([W()],w.prototype,"pendingAction",2),r([W()],w.prototype,"showWalletModal",2),r([W()],w.prototype,"walletModalStep",2),r([W()],w.prototype,"oisyReadyToPay",2),r([W()],w.prototype,"lastWalletId",2),r([W()],w.prototype,"showOnrampModal",2),r([W()],w.prototype,"onrampUrl",2),r([W()],w.prototype,"onrampPaymentIntentId",2),r([W()],w.prototype,"onrampErrorMessage",2),r([W()],w.prototype,"showBalanceModal",2),r([W()],w.prototype,"balancesLoading",2),r([W()],w.prototype,"balancesError",2),r([W()],w.prototype,"walletBalances",2),w=r([ft("icpay-tip-jar")],w);import{LitElement as bt,html as he,css as wt}from"lit";import{customElement as xt,property as Le,state as T}from"lit/decorators.js";var Fe=typeof window<"u",ye=null;function we(i,l,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${l}`,e):console.log(`[ICPay Widget] ${l}`))}var u=class extends bt{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.walletModalStep="connect";this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.showOnrampModal=!1;this.onrampUrl=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),a=this.selectedSymbol||"ICP";window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"unlock",type:"sendUsd",amount:t,currency:a}}))}catch{}}catch{}};this.onSelectBalanceSymbol=async e=>{let t=(this.walletBalances||[]).find(n=>n?.tokenShortcode===e);if(t?.ledgerSymbol&&(this.selectedSymbol=t.ledgerSymbol),B(this.lastWalletId)){let n=(this.walletBalances||[]).find(o=>o?.tokenShortcode===e),s=n?.chainId;this.showBalanceModal=!1,this.showWalletModal=!1,V(s,{provider:this.pnp?.getEvmProvider?.()||this.config?.evmProvider,chainName:n?.chainName,rpcUrlPublic:n?.rpcUrlPublic,nativeSymbol:n?.ledgerSymbol,decimals:n?.decimals}).then(async()=>{try{let o=g(this.config),c=Number(this.config?.priceUsd??0);if(n?.x402Accepts)try{await o.client.createPaymentX402Usd({usdAmount:c,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"evm",icpay_ledger_id:n?.ledgerId,icpay_context:"article:x402"}},recipientAddress:(this.config?.recipientAddresses||{})?.evm||"0x0000000000000000000000000000000000000000"});return}catch{}await o.client.createPaymentUsd({usdAmount:c,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"evm",icpay_ledger_id:n?.ledgerId}},recipientAddress:(this.config?.recipientAddresses||{})?.evm||"0x0000000000000000000000000000000000000000"})}catch{}});return}this.showBalanceModal=!1,this.showWalletModal=!1;let a=this.pendingAction;if(this.pendingAction=null,a==="unlock")try{let n=(this.walletBalances||[]).find(y=>y?.tokenShortcode===e),s=g(this.config),o=Number(this.config?.priceUsd??0),p=String(n?.ledgerName||n?.chainName||"").toLowerCase().includes("sol"),h=this.config?.recipientAddresses||{},d=p&&h.sol||h.ic;if(p&&n?.x402Accepts)try{await s.client.createPaymentX402Usd({usdAmount:o,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"sol",icpay_ledger_id:n?.ledgerId,icpay_context:"article:x402"}},recipientAddress:d||""});return}catch{return}await s.client.createPaymentUsd({usdAmount:o,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"ic",icpay_ledger_id:n?.ledgerId}},recipientAddress:d||"0x0000000000000000000000000000000000000000"})}catch{}}}get obfuscatedLockedContent(){try{return(this.lockedContent||"").replace(/[^\s]/g,"x")}catch{return"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}}async tryAutoConnectPNP(){try{if(!this.config||this.config?.useOwnWallet)return;let e=localStorage.getItem("icpay:pnp");if(!e)return;let t=JSON.parse(e);if(!t?.provider||!t?.principal)return;ye||(ye=(await import("./wallet-select-BEKXSS66.js")).WalletSelect);let a={...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:s}=await import("./origin-44ZEXSX4.js");a.derivationOrigin=this.config?.derivationOrigin||s()}}catch{}let n=new ye(a);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,a=t?.event_id||t?.eventId||t?.id;if(!(!a||typeof a!="string")&&a==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let n=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(n||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 t=await g(this.config).startOnrampUsd(this.config.priceUsd,void 0,{context:"article:onramp",onrampPayment:!0,onrampProvider:"coinbase"}),a=t?.metadata?.onramp?.url||t?.onramp?.url||t?.metadata?.icpay_onramp?.url||t?.paymentIntent?.metadata?.icpay?.onrampUrl||t?.metadata?.icpay?.onrampUrl||null,n=t?.metadata?.icpay_payment_intent_id||t?.metadata?.paymentIntentId||t?.paymentIntentId||null,s=t?.metadata?.icpay_onramp?.errorMessage||t?.metadata?.onramp?.errorMessage||t?.paymentIntent?.metadata?.icpay?.onrampError||t?.paymentIntent?.metadata?.icpay?.errorMessage||t?.metadata?.icpay?.onrampError||t?.metadata?.icpay?.errorMessage||null;if(this.onrampPaymentIntentId=n,a){this.onrampUrl=a,this.onrampErrorMessage=null;try{window.open(a,"icpay_onramp","noopener,noreferrer");try{window.dispatchEvent(new CustomEvent("icpay-onramp-opened",{detail:{url:a}}))}catch{}}catch{}this.startOnrampPolling()}else this.onrampUrl=null,this.onrampErrorMessage=s||"Failed to obtain onramp URL",this.showOnrampModal=!0}catch(e){this.onrampUrl=null,this.onrampErrorMessage=e?.message||"Failed to obtain onramp URL",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 a=g(this.config),n=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>n()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=a.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}connectedCallback(){if(super.connectedCallback(),!!Fe){we(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;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}this.walletModalStep!=="balances"&&!this.oisyReadyToPay&&(this.pendingAction=null,setTimeout(()=>{t==="unlock"&&this.unlock()},0))}}selectSymbol(e){this.selectedSymbol=e}async unlock(){if(Fe&&!(this.processing||this.unlocked)){we(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){we(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{ye||(ye=(await import("./wallet-select-BEKXSS66.js")).WalletSelect);let t=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab)?$({...this.config?.plugNPlay||{}}):{...this.config?.plugNPlay||{}};try{if(typeof window<"u"){let{resolveDerivationOrigin:n}=await import("./origin-44ZEXSX4.js");t.derivationOrigin=this.config?.derivationOrigin||n()}}catch{}this.pnp=new ye(t);try{let n=await te(this.pnp);if(n){this.walletConnected=!0;let s=U(this.pnp,{owner:n,principal:n,connected:!0}),o=this.pnp?.getEvmProvider?.(),c=this.pnp?.getSolanaProvider?.();this.config={...this.config,connectedWallet:s,actorProvider:(p,h)=>this.pnp.getActor({canisterId:p,idl:h,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{},...c?{solanaProvider:c}:{}},this.sdk=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"oisy"}}))}catch{}this.unlock();return}}catch{}let a=this.pnp.getEnabledWallets();if(we(this.config?.debug||!1,"Available wallets",a),!a?.length)throw new Error("No wallets available");this.pendingAction="unlock",this.showWalletModal=!0;return}catch(e){we(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){_(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),z(t)&&(this.errorMessage=D(t),this.errorSeverity=j(t),this.errorAction=F(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(a=>{if(!!!(a&&(a.connected===!0||a.principal||a.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 s=U(this.pnp,a),o=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:s,actorProvider:(c,p)=>this.pnp.getActor({canisterId:c,idl:p,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{}},this.sdk=null,this.walletModalStep="balances",this.showBalanceModal=!1,this.showWalletModal=!0,this.fetchAndShowBalances()}).catch(a=>{this.errorMessage=a instanceof Error?a.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.walletModalStep="balances",this.showBalanceModal=!1;let e=g(this.config),{balances:t}=await X({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?he`
|
|
1634
1668
|
<div class="icpay-card icpay-section icpay-widget-base">
|
|
1635
|
-
${this.config?.progressBar?.enabled!==!1?
|
|
1669
|
+
${this.config?.progressBar?.enabled!==!1?he`
|
|
1636
1670
|
<icpay-progress-bar
|
|
1637
1671
|
.debug=${!!this.config?.debug}
|
|
1638
1672
|
.theme=${this.config?.theme}
|
|
@@ -1650,26 +1684,28 @@ import{a as r}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var j=Xe`
|
|
|
1650
1684
|
${this.unlocked?"Unlocked":this.processing?"Processing\u2026":(this.config?.buttonLabel||"Pay ${amount} with crypto").replace("{amount}",`${Number(this.config?.priceUsd??0).toFixed(2)}`).replace("{symbol}",this.selectedSymbol||"ICP")}
|
|
1651
1685
|
</button>
|
|
1652
1686
|
|
|
1653
|
-
${this.errorMessage?
|
|
1687
|
+
${this.errorMessage?he`
|
|
1654
1688
|
<div class="error-message ${this.errorSeverity}" style="margin-top: 12px; padding: 8px 12px; border-radius: 6px; font-size: 14px; text-align: center;">
|
|
1655
1689
|
${this.errorMessage}
|
|
1656
|
-
${this.errorAction?
|
|
1690
|
+
${this.errorAction?he`
|
|
1657
1691
|
<button style="margin-left: 8px; padding: 4px 8px; background: transparent; border: 1px solid currentColor; border-radius: 4px; font-size: 12px; cursor: pointer;">
|
|
1658
1692
|
${this.errorAction}
|
|
1659
1693
|
</button>
|
|
1660
1694
|
`:""}
|
|
1661
1695
|
</div>
|
|
1662
1696
|
`:""}
|
|
1663
|
-
${(()=>{let e=this.pnp?.getEnabledWallets?.()||[],t=H(e);return G({visible:!!(this.showWalletModal&&this.pnp),wallets:t,isConnecting:!1,step:this.walletModalStep,balances:this.walletModalStep==="balances"?this.walletBalances:[],balancesLoading:this.walletModalStep==="balances"?this.balancesLoading:!1,balancesError:this.walletModalStep==="balances"?this.balancesError:null,onSelectBalance:
|
|
1697
|
+
${(()=>{let e=this.pnp?.getEnabledWallets?.()||[],t=H(e),a=this.config?.theme?typeof this.config.theme=="string"?this.config.theme:this.config.theme.mode||"light":void 0;return G({visible:!!(this.showWalletModal&&this.pnp),wallets:t,isConnecting:!1,step:this.walletModalStep,balances:this.walletModalStep==="balances"?this.walletBalances:[],balancesLoading:this.walletModalStep==="balances"?this.balancesLoading:!1,balancesError:this.walletModalStep==="balances"?this.balancesError:null,onSelectBalance:n=>this.onSelectBalanceSymbol(n),onBack:()=>{this.walletModalStep="connect"},onSelect:n=>this.connectWithWallet(n),onClose:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-cancelled",{detail:{reason:"user_cancelled"}}))}catch{}},onDismiss:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1},onCreditCard:this.config?.onramp?.enabled===!0&&this.config?.onrampDisabled!==!0?()=>this.startOnramp():void 0,creditCardLabel:this.config?.onramp?.creditCardLabel||"Pay with credit card",showCreditCard:this.config?.onramp?.enabled===!0&&this.config?.onrampDisabled!==!0,creditCardTooltip:(()=>{let s=Number(this.config?.priceUsd||0);return s>0&&s<5&&this.config?.onramp?.enabled===!0&&this.config?.onrampDisabled!==!0?`Note: Minimum card amount is $5. You will pay about $${(5-s).toFixed(2)} more.`:null})(),oisyReadyToPay:this.oisyReadyToPay,onOisyPay:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1,this.unlock()},theme:a})})()}
|
|
1664
1698
|
|
|
1665
|
-
${
|
|
1699
|
+
${(()=>{let e=this.config?.theme?typeof this.config.theme=="string"?this.config.theme:this.config.theme.mode||"light":void 0;return he`
|
|
1700
|
+
${Q({visible:this.showBalanceModal,isLoading:this.balancesLoading,error:this.balancesError,balances:this.walletBalances,onSelect:t=>this.onSelectBalanceSymbol(t),onClose:()=>{this.showBalanceModal=!1},theme:e})}
|
|
1666
1701
|
|
|
1667
|
-
|
|
1702
|
+
${q({visible:this.showOnrampModal,url:this.onrampUrl||void 0,errorMessage:this.onrampErrorMessage||void 0,width:this.config?.onramp?.width,height:this.config?.onramp?.height,onClose:()=>{this.showOnrampModal=!1},onBack:()=>{this.showOnrampModal=!1,this.showWalletModal=!0},title:"Pay with credit card",theme:e})}
|
|
1703
|
+
`})()}
|
|
1668
1704
|
<div class="icpay-powered-by">
|
|
1669
1705
|
<a href="https://icpay.org" target="_blank" rel="noopener noreferrer">Powered by icpay</a>
|
|
1670
1706
|
</div>
|
|
1671
1707
|
</div>
|
|
1672
|
-
`:
|
|
1708
|
+
`:he`<div class="icpay-card icpay-section">Loading...</div>`}};u.styles=[K,wt`
|
|
1673
1709
|
.container { background: var(--icpay-surface-alt); border: 1px solid var(--icpay-border); border-radius: 16px; padding: 16px; margin-bottom: 16px; }
|
|
1674
1710
|
.title { color: var(--icpay-text); font-weight: 700; margin-bottom: 8px; }
|
|
1675
1711
|
.preview { color: var(--icpay-muted-foreground); margin-bottom: 12px; line-height: 1.6; }
|
|
@@ -1701,9 +1737,9 @@ import{a as r}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var j=Xe`
|
|
|
1701
1737
|
border-color: var(--icpay-error-border);
|
|
1702
1738
|
color: var(--icpay-error-text);
|
|
1703
1739
|
}
|
|
1704
|
-
`],r([Ce({type:Object})],m.prototype,"config",2),r([Ce({type:String})],m.prototype,"title",2),r([Ce({type:String})],m.prototype,"preview",2),r([Ce({type:String})],m.prototype,"lockedContent",2),r([T()],m.prototype,"selectedSymbol",2),r([T()],m.prototype,"unlocked",2),r([T()],m.prototype,"succeeded",2),r([T()],m.prototype,"processing",2),r([T()],m.prototype,"errorMessage",2),r([T()],m.prototype,"errorSeverity",2),r([T()],m.prototype,"errorAction",2),r([T()],m.prototype,"walletConnected",2),r([T()],m.prototype,"pendingAction",2),r([T()],m.prototype,"showWalletModal",2),r([T()],m.prototype,"walletModalStep",2),r([T()],m.prototype,"oisyReadyToPay",2),r([T()],m.prototype,"lastWalletId",2),r([T()],m.prototype,"showOnrampModal",2),r([T()],m.prototype,"onrampUrl",2),r([T()],m.prototype,"onrampPaymentIntentId",2),r([T()],m.prototype,"onrampErrorMessage",2),r([T()],m.prototype,"showBalanceModal",2),r([T()],m.prototype,"balancesLoading",2),r([T()],m.prototype,"balancesError",2),r([T()],m.prototype,"walletBalances",2),m=r([xt("icpay-article-paywall")],m);import{LitElement as Et,html as de,css as kt}from"lit";import{customElement as St,property as Mt,state as O}from"lit/decorators.js";var Ke=typeof window<"u",Oe=null;function ve(i,s,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${s}`,e):console.log(`[ICPay Widget] ${s}`))}var S=class extends Et{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.walletModalStep="connect";this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.showOnrampModal=!1;this.onrampUrl=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),a=this.selectedSymbol||"ICP";window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"order",type:"sendUsd",amount:t,currency:a}}))}catch{}}catch{}};this.onSelectBalanceSymbol=async e=>{let t=(this.walletBalances||[]).find(n=>n?.tokenShortcode===e);if(t?.ledgerSymbol&&(this.selectedSymbol=t.ledgerSymbol),this.showBalanceModal=!1,this.showWalletModal=!1,B(this.lastWalletId)){let n=(this.walletBalances||[]).find(l=>l?.tokenShortcode===e),o=n?.chainId;V(o,{provider:this.pnp?.getEvmProvider?.()||this.config?.evmProvider,chainName:n?.chainName,rpcUrlPublic:n?.rpcUrlPublic,nativeSymbol:n?.ledgerSymbol,decimals:n?.decimals}).then(async()=>{try{let l=u(this.config),d=Number(this.selectedItem?.priceUsd||0);if(n?.x402Accepts)try{await l.client.createPaymentX402Usd({usdAmount:d,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"evm",icpay_ledger_id:n?.ledgerId,icpay_context:"coffee:x402",item:this.selectedItem?.name}},recipientAddress:(this.config?.recipientAddresses||{})?.evm||"0x0000000000000000000000000000000000000000"}),this.showBalanceModal=!1;return}catch{}await l.client.createPaymentUsd({usdAmount:d,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"evm",icpay_ledger_id:n?.ledgerId,item:this.selectedItem?.name}},recipientAddress:(this.config?.recipientAddresses||{})?.evm||"0x0000000000000000000000000000000000000000"})}catch{}this.showBalanceModal=!1});return}let a=this.pendingAction;if(this.pendingAction=null,a==="order")try{let n=(this.walletBalances||[]).find(g=>g?.tokenShortcode===e),o=u(this.config),l=Number(this.selectedItem?.priceUsd||0),d=String(n?.ledgerName||n?.chainName||"").toLowerCase(),p=d.includes("sol"),h=d.includes("ic"),c=this.config?.recipientAddresses||{},y=p&&c.sol||c.ic;if(n?.x402Accepts)try{await o.client.createPaymentX402Usd({usdAmount:l,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:p?"sol":h?"ic":this.config?.icpay_network,icpay_ledger_id:n?.ledgerId,icpay_context:"coffee:x402",item:this.selectedItem?.name}},recipientAddress:y||""});return}catch{return}await o.client.createPaymentUsd({usdAmount:l,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"ic",icpay_ledger_id:n?.ledgerId,item:this.selectedItem?.name}},recipientAddress:y||"0x0000000000000000000000000000000000000000"})}catch{}}}connectedCallback(){if(super.connectedCallback(),!!Ke){ve(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;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}this.walletModalStep!=="balances"&&!this.oisyReadyToPay&&(this.pendingAction=null,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(Ke&&!this.processing){ve(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){ve(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{Oe||(Oe=(await import("./wallet-select-BEKXSS66.js")).WalletSelect);let t=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab)?$({...this.config?.plugNPlay||{}}):{...this.config?.plugNPlay||{}},a=this.config?.recipientAddresses;if(a&&(a.ic||a.evm||a.sol)){let o=[];a.ic&&o.push("ic"),a.evm&&o.push("evm"),a.sol&&o.push("sol"),o.length&&(t.chainTypes=o)}else this.config?.chainTypes&&(t.chainTypes=this.config.chainTypes);try{if(typeof window<"u"){let{resolveDerivationOrigin:o}=await import("./origin-44ZEXSX4.js");t.derivationOrigin=this.config?.derivationOrigin||o()}}catch{}this.pnp=new Oe(t);try{let o=await te(this.pnp);if(o){this.walletConnected=!0;let l=U(this.pnp,{owner:o,principal:o,connected:!0}),d=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:l,actorProvider:(p,h)=>this.pnp.getActor({canisterId:p,idl:h,requiresSigning:!0,anon:!1}),...d?{evmProvider:d}:{}},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(ve(this.config?.debug||!1,"Available wallets",n),!n?.length)throw new Error("No wallets available");this.pendingAction="order",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.pendingAction="order",this.showWalletModal=!0,await this.fetchAndShowBalances();return}catch(e){_(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),z(t)&&(this.errorMessage=D(t),this.errorSeverity=K(t),this.errorAction=F(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,a=t?.event_id||t?.eventId||t?.id;if(!(!a||typeof a!="string")&&a==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let n=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(n||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 t=await u(this.config).startOnrampUsd(this.selectedItem.priceUsd,void 0,{context:"coffee:onramp",onrampPayment:!0,item:this.selectedItem.name,onrampProvider:"coinbase"}),a=t?.metadata?.onramp?.url||t?.onramp?.url||t?.metadata?.icpay_onramp?.url||t?.paymentIntent?.metadata?.icpay?.onrampUrl||t?.metadata?.icpay?.onrampUrl||null,n=t?.metadata?.icpay_payment_intent_id||t?.metadata?.paymentIntentId||t?.paymentIntentId||null,o=t?.metadata?.icpay_onramp?.errorMessage||t?.metadata?.onramp?.errorMessage||t?.paymentIntent?.metadata?.icpay?.onrampError||t?.paymentIntent?.metadata?.icpay?.errorMessage||t?.metadata?.icpay?.onrampError||t?.metadata?.icpay?.errorMessage||null;if(this.onrampPaymentIntentId=n,a){this.onrampUrl=a,this.onrampErrorMessage=null;try{window.open(a,"icpay_onramp","noopener,noreferrer");try{window.dispatchEvent(new CustomEvent("icpay-onramp-opened",{detail:{url:a}}))}catch{}}catch{}this.startOnrampPolling()}else this.onrampUrl=null,this.onrampErrorMessage=o||"Failed to obtain onramp URL",this.showOnrampModal=!0}catch(e){this.onrampUrl=null,this.onrampErrorMessage=e?.message||"Failed to obtain onramp URL",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 a=u(this.config),n=()=>{if(this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>n()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=a.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(a=>{if(!!!(a&&(a.connected===!0||a.principal||a.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}let o=U(this.pnp,a),l=this.pnp?.getEvmProvider?.(),d=this.pnp?.getSolanaProvider?.();this.config={...this.config,connectedWallet:o,actorProvider:(p,h)=>this.pnp.getActor({canisterId:p,idl:h,requiresSigning:!0,anon:!1}),...l?{evmProvider:l}:{},...d?{solanaProvider:d}:{}},this.sdk=null,this.walletModalStep="balances",this.showBalanceModal=!1,this.showWalletModal=!0,this.fetchAndShowBalances()}).catch(a=>{this.errorMessage=a instanceof Error?a.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.walletModalStep="balances",this.showBalanceModal=!1;let e=u(this.config),{balances:t}=await X({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?de`
|
|
1740
|
+
`],r([Le({type:Object})],u.prototype,"config",2),r([Le({type:String})],u.prototype,"title",2),r([Le({type:String})],u.prototype,"preview",2),r([Le({type:String})],u.prototype,"lockedContent",2),r([T()],u.prototype,"selectedSymbol",2),r([T()],u.prototype,"unlocked",2),r([T()],u.prototype,"succeeded",2),r([T()],u.prototype,"processing",2),r([T()],u.prototype,"errorMessage",2),r([T()],u.prototype,"errorSeverity",2),r([T()],u.prototype,"errorAction",2),r([T()],u.prototype,"walletConnected",2),r([T()],u.prototype,"pendingAction",2),r([T()],u.prototype,"showWalletModal",2),r([T()],u.prototype,"walletModalStep",2),r([T()],u.prototype,"oisyReadyToPay",2),r([T()],u.prototype,"lastWalletId",2),r([T()],u.prototype,"showOnrampModal",2),r([T()],u.prototype,"onrampUrl",2),r([T()],u.prototype,"onrampPaymentIntentId",2),r([T()],u.prototype,"onrampErrorMessage",2),r([T()],u.prototype,"showBalanceModal",2),r([T()],u.prototype,"balancesLoading",2),r([T()],u.prototype,"balancesError",2),r([T()],u.prototype,"walletBalances",2),u=r([xt("icpay-article-paywall")],u);import{LitElement as kt,html as re,css as Et}from"lit";import{customElement as St,property as Mt,state as O}from"lit/decorators.js";var je=typeof window<"u",Oe=null;function xe(i,l,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${l}`,e):console.log(`[ICPay Widget] ${l}`))}var S=class extends kt{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.walletModalStep="connect";this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.showOnrampModal=!1;this.onrampUrl=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),a=this.selectedSymbol||"ICP";window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"order",type:"sendUsd",amount:t,currency:a}}))}catch{}}catch{}};this.onSelectBalanceSymbol=async e=>{let t=(this.walletBalances||[]).find(n=>n?.tokenShortcode===e);if(t?.ledgerSymbol&&(this.selectedSymbol=t.ledgerSymbol),this.showBalanceModal=!1,this.showWalletModal=!1,B(this.lastWalletId)){let n=(this.walletBalances||[]).find(o=>o?.tokenShortcode===e),s=n?.chainId;V(s,{provider:this.pnp?.getEvmProvider?.()||this.config?.evmProvider,chainName:n?.chainName,rpcUrlPublic:n?.rpcUrlPublic,nativeSymbol:n?.ledgerSymbol,decimals:n?.decimals}).then(async()=>{try{let o=g(this.config),c=Number(this.selectedItem?.priceUsd||0);if(n?.x402Accepts)try{await o.client.createPaymentX402Usd({usdAmount:c,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"evm",icpay_ledger_id:n?.ledgerId,icpay_context:"coffee:x402",item:this.selectedItem?.name}},recipientAddress:(this.config?.recipientAddresses||{})?.evm||"0x0000000000000000000000000000000000000000"}),this.showBalanceModal=!1;return}catch{}await o.client.createPaymentUsd({usdAmount:c,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"evm",icpay_ledger_id:n?.ledgerId,item:this.selectedItem?.name}},recipientAddress:(this.config?.recipientAddresses||{})?.evm||"0x0000000000000000000000000000000000000000"})}catch{}this.showBalanceModal=!1});return}let a=this.pendingAction;if(this.pendingAction=null,a==="order")try{let n=(this.walletBalances||[]).find(m=>m?.tokenShortcode===e),s=g(this.config),o=Number(this.selectedItem?.priceUsd||0),c=String(n?.ledgerName||n?.chainName||"").toLowerCase(),p=c.includes("sol"),h=c.includes("ic"),d=this.config?.recipientAddresses||{},y=p&&d.sol||d.ic;if(n?.x402Accepts)try{await s.client.createPaymentX402Usd({usdAmount:o,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:p?"sol":h?"ic":this.config?.icpay_network,icpay_ledger_id:n?.ledgerId,icpay_context:"coffee:x402",item:this.selectedItem?.name}},recipientAddress:y||""});return}catch{return}await s.client.createPaymentUsd({usdAmount:o,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"ic",icpay_ledger_id:n?.ledgerId,item:this.selectedItem?.name}},recipientAddress:y||"0x0000000000000000000000000000000000000000"})}catch{}}}connectedCallback(){if(super.connectedCallback(),!!je){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;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}this.walletModalStep!=="balances"&&!this.oisyReadyToPay&&(this.pendingAction=null,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(je&&!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{Oe||(Oe=(await import("./wallet-select-BEKXSS66.js")).WalletSelect);let t=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab)?$({...this.config?.plugNPlay||{}}):{...this.config?.plugNPlay||{}},a=this.config?.recipientAddresses;if(a&&(a.ic||a.evm||a.sol)){let s=[];a.ic&&s.push("ic"),a.evm&&s.push("evm"),a.sol&&s.push("sol"),s.length&&(t.chainTypes=s)}else this.config?.chainTypes&&(t.chainTypes=this.config.chainTypes);try{if(typeof window<"u"){let{resolveDerivationOrigin:s}=await import("./origin-44ZEXSX4.js");t.derivationOrigin=this.config?.derivationOrigin||s()}}catch{}this.pnp=new Oe(t);try{let s=await te(this.pnp);if(s){this.walletConnected=!0;let o=U(this.pnp,{owner:s,principal:s,connected:!0}),c=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:o,actorProvider:(p,h)=>this.pnp.getActor({canisterId:p,idl:h,requiresSigning:!0,anon:!1}),...c?{evmProvider:c}:{}},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){_(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),z(t)&&(this.errorMessage=D(t),this.errorSeverity=j(t),this.errorAction=F(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,a=t?.event_id||t?.eventId||t?.id;if(!(!a||typeof a!="string")&&a==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let n=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(n||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 t=await g(this.config).startOnrampUsd(this.selectedItem.priceUsd,void 0,{context:"coffee:onramp",onrampPayment:!0,item:this.selectedItem.name,onrampProvider:"coinbase"}),a=t?.metadata?.onramp?.url||t?.onramp?.url||t?.metadata?.icpay_onramp?.url||t?.paymentIntent?.metadata?.icpay?.onrampUrl||t?.metadata?.icpay?.onrampUrl||null,n=t?.metadata?.icpay_payment_intent_id||t?.metadata?.paymentIntentId||t?.paymentIntentId||null,s=t?.metadata?.icpay_onramp?.errorMessage||t?.metadata?.onramp?.errorMessage||t?.paymentIntent?.metadata?.icpay?.onrampError||t?.paymentIntent?.metadata?.icpay?.errorMessage||t?.metadata?.icpay?.onrampError||t?.metadata?.icpay?.errorMessage||null;if(this.onrampPaymentIntentId=n,a){this.onrampUrl=a,this.onrampErrorMessage=null;try{window.open(a,"icpay_onramp","noopener,noreferrer");try{window.dispatchEvent(new CustomEvent("icpay-onramp-opened",{detail:{url:a}}))}catch{}}catch{}this.startOnrampPolling()}else this.onrampUrl=null,this.onrampErrorMessage=s||"Failed to obtain onramp URL",this.showOnrampModal=!0}catch(e){this.onrampUrl=null,this.onrampErrorMessage=e?.message||"Failed to obtain onramp URL",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 a=g(this.config),n=()=>{if(this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>n()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=a.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(a=>{if(!!!(a&&(a.connected===!0||a.principal||a.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 s=U(this.pnp,a),o=this.pnp?.getEvmProvider?.(),c=this.pnp?.getSolanaProvider?.();this.config={...this.config,connectedWallet:s,actorProvider:(p,h)=>this.pnp.getActor({canisterId:p,idl:h,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{},...c?{solanaProvider:c}:{}},this.sdk=null,this.walletModalStep="balances",this.showBalanceModal=!1,this.showWalletModal=!0,this.fetchAndShowBalances()}).catch(a=>{this.errorMessage=a instanceof Error?a.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.walletModalStep="balances",this.showBalanceModal=!1;let e=g(this.config),{balances:t}=await X({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?re`
|
|
1705
1741
|
<div class="icpay-card icpay-section icpay-widget-base">
|
|
1706
|
-
${this.config?.progressBar?.enabled!==!1?
|
|
1742
|
+
${this.config?.progressBar?.enabled!==!1?re`
|
|
1707
1743
|
<icpay-progress-bar
|
|
1708
1744
|
.debug=${!!this.config?.debug}
|
|
1709
1745
|
.theme=${this.config?.theme}
|
|
@@ -1712,7 +1748,7 @@ import{a as r}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var j=Xe`
|
|
|
1712
1748
|
></icpay-progress-bar>
|
|
1713
1749
|
`:null}
|
|
1714
1750
|
<div class="menu">
|
|
1715
|
-
${this.config.items.map((e,t)=>
|
|
1751
|
+
${this.config.items.map((e,t)=>re`
|
|
1716
1752
|
<div class="item ${this.selectedIndex===t?"selected":""}" @click=${()=>this.selectItem(t)}>
|
|
1717
1753
|
<span>${e.name}</span>
|
|
1718
1754
|
<span>$${Number(e?.priceUsd??0).toFixed(2)}</span>
|
|
@@ -1728,26 +1764,28 @@ import{a as r}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var j=Xe`
|
|
|
1728
1764
|
${this.processing?"Processing\u2026":`Order ${this.selectedItem.name}`}
|
|
1729
1765
|
</button>
|
|
1730
1766
|
|
|
1731
|
-
${this.errorMessage?
|
|
1767
|
+
${this.errorMessage?re`
|
|
1732
1768
|
<div class="error-message ${this.errorSeverity}" style="margin-top: 12px; padding: 8px 12px; border-radius: 6px; font-size: 14px; text-align: center;">
|
|
1733
1769
|
${this.errorMessage}
|
|
1734
|
-
${this.errorAction?
|
|
1770
|
+
${this.errorAction?re`
|
|
1735
1771
|
<button style="margin-left: 8px; padding: 4px 8px; background: transparent; border: 1px solid currentColor; border-radius: 4px; font-size: 12px; cursor: pointer;">
|
|
1736
1772
|
${this.errorAction}
|
|
1737
1773
|
</button>
|
|
1738
1774
|
`:""}
|
|
1739
1775
|
</div>
|
|
1740
1776
|
`:""}
|
|
1741
|
-
${(()=>{let e=this.pnp?.getEnabledWallets?.()||[],t=H(e);return G({visible:!!(this.showWalletModal&&this.pnp),wallets:t,isConnecting:!1,step:this.walletModalStep,balances:this.walletModalStep==="balances"?this.walletBalances:[],balancesLoading:this.walletModalStep==="balances"?this.balancesLoading:!1,balancesError:this.walletModalStep==="balances"?this.balancesError:null,onSelectBalance:
|
|
1777
|
+
${(()=>{let e=this.pnp?.getEnabledWallets?.()||[],t=H(e),a=this.config?.theme?typeof this.config.theme=="string"?this.config.theme:this.config.theme.mode||"light":void 0;return G({visible:!!(this.showWalletModal&&this.pnp),wallets:t,isConnecting:!1,step:this.walletModalStep,balances:this.walletModalStep==="balances"?this.walletBalances:[],balancesLoading:this.walletModalStep==="balances"?this.balancesLoading:!1,balancesError:this.walletModalStep==="balances"?this.balancesError:null,onSelectBalance:n=>this.onSelectBalanceSymbol(n),onBack:()=>{this.walletModalStep="connect"},onSwitchAccount:()=>this.onSwitchAccount(null),onSelect:n=>this.connectWithWallet(n),onClose:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-cancelled",{detail:{reason:"user_cancelled"}}))}catch{}},onDismiss:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1},onCreditCard:this.config?.onramp?.enabled===!0&&this.config?.onrampDisabled!==!0?()=>this.startOnramp():void 0,creditCardLabel:this.config?.onramp?.creditCardLabel||"Pay with credit card",showCreditCard:this.config?.onramp?.enabled===!0&&this.config?.onrampDisabled!==!0,creditCardTooltip:(()=>{let s=this.config?.defaultItemIndex??0,o=Number(this.config?.items?.[s]?.priceUsd||0);return o>0&&o<5&&this.config?.onramp?.enabled===!0&&this.config?.onrampDisabled!==!0?`Note: Minimum card amount is $5. You will pay about $${(5-o).toFixed(2)} more.`:null})(),oisyReadyToPay:this.oisyReadyToPay,onOisyPay:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1,this.order()},theme:a})})()}
|
|
1742
1778
|
|
|
1743
|
-
${
|
|
1779
|
+
${(()=>{let e=this.config?.theme?typeof this.config.theme=="string"?this.config.theme:this.config.theme.mode||"light":void 0;return re`
|
|
1780
|
+
${Q({visible:this.showBalanceModal,isLoading:this.balancesLoading,error:this.balancesError,balances:this.walletBalances,onSelect:t=>this.onSelectBalanceSymbol(t),onClose:()=>{this.showBalanceModal=!1},theme:e})}
|
|
1744
1781
|
|
|
1745
|
-
|
|
1782
|
+
${q({visible:this.showOnrampModal,url:this.onrampUrl||void 0,errorMessage:this.onrampErrorMessage||void 0,width:this.config?.onramp?.width,height:this.config?.onramp?.height,onClose:()=>{this.showOnrampModal=!1},onBack:()=>{this.showOnrampModal=!1,this.showWalletModal=!0},title:"Pay with credit card",theme:e})}
|
|
1783
|
+
`})()}
|
|
1746
1784
|
<div class="icpay-powered-by">
|
|
1747
1785
|
<a href="https://icpay.org" target="_blank" rel="noopener noreferrer">Powered by icpay</a>
|
|
1748
1786
|
</div>
|
|
1749
1787
|
</div>
|
|
1750
|
-
`:
|
|
1788
|
+
`:re`<div class="icpay-card icpay-section">Loading...</div>`}};S.styles=[K,Et`
|
|
1751
1789
|
.menu { display: grid; gap: 8px; margin-bottom: 12px; }
|
|
1752
1790
|
.item { background: var(--icpay-surface-alt); border: 2px solid var(--icpay-border); border-radius: 12px; padding: 16px; display:flex; justify-content: space-between; align-items:center; cursor: pointer; color: var(--icpay-text); font-weight: 600; }
|
|
1753
1791
|
.item.selected { background: var(--icpay-primary); color: #111827; border-color: var(--icpay-primary); }
|
|
@@ -1778,9 +1816,9 @@ import{a as r}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var j=Xe`
|
|
|
1778
1816
|
border-color: var(--icpay-error-border);
|
|
1779
1817
|
color: var(--icpay-error-text);
|
|
1780
1818
|
}
|
|
1781
|
-
`],r([Mt({type:Object})],S.prototype,"config",2),r([O()],S.prototype,"selectedIndex",2),r([O()],S.prototype,"selectedSymbol",2),r([O()],S.prototype,"processing",2),r([O()],S.prototype,"errorMessage",2),r([O()],S.prototype,"errorSeverity",2),r([O()],S.prototype,"errorAction",2),r([O()],S.prototype,"walletConnected",2),r([O()],S.prototype,"pendingAction",2),r([O()],S.prototype,"showWalletModal",2),r([O()],S.prototype,"walletModalStep",2),r([O()],S.prototype,"oisyReadyToPay",2),r([O()],S.prototype,"lastWalletId",2),r([O()],S.prototype,"showOnrampModal",2),r([O()],S.prototype,"onrampUrl",2),r([O()],S.prototype,"onrampPaymentIntentId",2),r([O()],S.prototype,"onrampErrorMessage",2),r([O()],S.prototype,"showBalanceModal",2),r([O()],S.prototype,"balancesLoading",2),r([O()],S.prototype,"balancesError",2),r([O()],S.prototype,"walletBalances",2),S=r([St("icpay-coffee-shop")],S);import{LitElement as Wt,html as pe,css as At}from"lit";import{customElement as Ct,property as Lt,state as A}from"lit/decorators.js";var je=typeof window<"u",he=null;function be(i,s,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${s}`,e):console.log(`[ICPay Widget] ${s}`))}var x=class extends Wt{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.walletModalStep="connect";this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.showOnrampModal=!1;this.onrampUrl=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),a=this.selectedSymbol||"ICP";window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"donate",type:"sendUsd",amount:t,currency:a}}))}catch{}}catch{}};this.onSelectBalanceSymbol=async e=>{let t=(this.walletBalances||[]).find(n=>n?.tokenShortcode===e);if(t?.ledgerSymbol&&(this.selectedSymbol=t.ledgerSymbol),this.showBalanceModal=!1,this.showWalletModal=!1,B(this.lastWalletId)){let n=(this.walletBalances||[]).find(l=>l?.tokenShortcode===e),o=n?.chainId;V(o,{provider:this.pnp?.getEvmProvider?.()||this.config?.evmProvider,chainName:n?.chainName,rpcUrlPublic:n?.rpcUrlPublic,nativeSymbol:n?.ledgerSymbol,decimals:n?.decimals}).then(async()=>{try{let l=u(this.config),d=Number(this.selectedAmount||0);if(n?.x402Accepts)try{await l.client.createPaymentX402Usd({usdAmount:d,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay_network:"evm",icpay_ledger_id:n?.ledgerId,icpay_context:"donation:x402"},recipientAddress:(this.config?.recipientAddresses||{})?.evm||"0x0000000000000000000000000000000000000000"}),this.showBalanceModal=!1;return}catch{}await l.client.createPaymentUsd({usdAmount:d,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay_network:"evm",icpay_ledger_id:n?.ledgerId},recipientAddress:(this.config?.recipientAddresses||{})?.evm||"0x0000000000000000000000000000000000000000"})}catch{}this.showBalanceModal=!1});return}let a=this.pendingAction;if(this.pendingAction=null,a==="donate")try{let n=(this.walletBalances||[]).find(y=>y?.tokenShortcode===e),o=u(this.config),l=Number(this.selectedAmount||0),p=String(n?.ledgerName||n?.chainName||"").toLowerCase().includes("sol"),h=this.config?.recipientAddresses||{},c=p&&h.sol||h.ic;if(p&&n?.x402Accepts)try{await o.client.createPaymentX402Usd({usdAmount:l,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"sol",icpay_ledger_id:n?.ledgerId,icpay_context:"donation:x402"}},recipientAddress:c||""});return}catch{return}await o.client.createPaymentUsd({usdAmount:l,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"ic",icpay_ledger_id:n?.ledgerId}},recipientAddress:c||"0x0000000000000000000000000000000000000000"})}catch{}}}async tryAutoConnectPNP(){try{if(!this.config||this.config?.useOwnWallet)return;let e=localStorage.getItem("icpay:pnp");if(!e)return;let t=JSON.parse(e);if(!t?.provider||!t?.principal)return;he||(he=(await import("./wallet-select-BEKXSS66.js")).WalletSelect);let a=$({...this.config?.plugNPlay||{}});try{if(typeof window<"u"){let{resolveDerivationOrigin:o}=await import("./origin-44ZEXSX4.js");a.derivationOrigin=this.config?.derivationOrigin||o()}}catch{}let n=new he(a);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){be(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;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}this.walletModalStep!=="balances"&&!this.oisyReadyToPay&&(this.pendingAction=null,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){be(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){be(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{he||(he=(await import("./wallet-select-BEKXSS66.js")).WalletSelect);let t=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab)?$({...this.config?.plugNPlay||{}}):{...this.config?.plugNPlay||{}};this.config?.chainTypes&&(t.chainTypes=this.config.chainTypes);try{if(typeof window<"u"){let{resolveDerivationOrigin:n}=await import("./origin-44ZEXSX4.js");t.derivationOrigin=this.config?.derivationOrigin||n()}}catch{}this.pnp=new he(t);try{let n=await te(this.pnp);if(n){this.walletConnected=!0;let o=U(this.pnp,{owner:n,principal:n,connected:!0}),l=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:o,actorProvider:(d,p)=>this.pnp.getActor({canisterId:d,idl:p,requiresSigning:!0,anon:!1}),...l?{evmProvider:l}:{}},this.sdk=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"oisy"}}))}catch{}this.donate();return}}catch{}let a=this.pnp.getEnabledWallets();if(be(this.config?.debug||!1,"Available wallets",a),!a?.length)throw new Error("No wallets available");this.pendingAction="donate",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){_(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),z(t)&&(this.errorMessage=D(t),this.errorSeverity=K(t),this.errorAction=F(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,a=t?.event_id||t?.eventId||t?.id;if(!(!a||typeof a!="string")&&a==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let n=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(n||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 t=await u(this.config).startOnrampUsd(this.selectedAmount,void 0,{context:"donation:onramp",onrampPayment:!0,onrampProvider:"coinbase"}),a=t?.metadata?.onramp?.url||t?.onramp?.url||t?.metadata?.icpay_onramp?.url||t?.paymentIntent?.metadata?.icpay?.onrampUrl||t?.metadata?.icpay?.onrampUrl||null,n=t?.metadata?.icpay_payment_intent_id||t?.metadata?.paymentIntentId||t?.paymentIntentId||null,o=t?.metadata?.icpay_onramp?.errorMessage||t?.metadata?.onramp?.errorMessage||t?.paymentIntent?.metadata?.icpay?.onrampError||t?.paymentIntent?.metadata?.icpay?.errorMessage||t?.metadata?.icpay?.onrampError||t?.metadata?.icpay?.errorMessage||null;if(this.onrampPaymentIntentId=n,a){this.onrampUrl=a,this.onrampErrorMessage=null;try{window.open(a,"icpay_onramp","noopener,noreferrer");try{window.dispatchEvent(new CustomEvent("icpay-onramp-opened",{detail:{url:a}}))}catch{}}catch{}this.startOnrampPolling()}else this.onrampUrl=null,this.onrampErrorMessage=o||"Failed to obtain onramp URL",this.showOnrampModal=!0}catch(e){this.onrampUrl=null,this.onrampErrorMessage=e?.message||"Failed to obtain onramp URL",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 a=u(this.config),n=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>n()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=a.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(a=>{if(!!!(a&&(a.connected===!0||a.principal||a.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}let o=U(this.pnp,a),l=this.pnp?.getEvmProvider?.(),d=this.pnp?.getSolanaProvider?.();this.config={...this.config,connectedWallet:o,actorProvider:(p,h)=>this.pnp.getActor({canisterId:p,idl:h,requiresSigning:!0,anon:!1}),...l?{evmProvider:l}:{},...d?{solanaProvider:d}:{}},this.sdk=null,this.walletModalStep="balances",this.showBalanceModal=!1,this.showWalletModal=!0,this.fetchAndShowBalances()}).catch(a=>{this.errorMessage=a instanceof Error?a.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.walletModalStep="balances",this.showBalanceModal=!1;let e=u(this.config),{balances:t}=await X({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?pe`
|
|
1819
|
+
`],r([Mt({type:Object})],S.prototype,"config",2),r([O()],S.prototype,"selectedIndex",2),r([O()],S.prototype,"selectedSymbol",2),r([O()],S.prototype,"processing",2),r([O()],S.prototype,"errorMessage",2),r([O()],S.prototype,"errorSeverity",2),r([O()],S.prototype,"errorAction",2),r([O()],S.prototype,"walletConnected",2),r([O()],S.prototype,"pendingAction",2),r([O()],S.prototype,"showWalletModal",2),r([O()],S.prototype,"walletModalStep",2),r([O()],S.prototype,"oisyReadyToPay",2),r([O()],S.prototype,"lastWalletId",2),r([O()],S.prototype,"showOnrampModal",2),r([O()],S.prototype,"onrampUrl",2),r([O()],S.prototype,"onrampPaymentIntentId",2),r([O()],S.prototype,"onrampErrorMessage",2),r([O()],S.prototype,"showBalanceModal",2),r([O()],S.prototype,"balancesLoading",2),r([O()],S.prototype,"balancesError",2),r([O()],S.prototype,"walletBalances",2),S=r([St("icpay-coffee-shop")],S);import{LitElement as Wt,html as se,css as At}from"lit";import{customElement as Ct,property as Lt,state as A}from"lit/decorators.js";var Ke=typeof window<"u",ge=null;function ke(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.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.walletModalStep="connect";this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.showOnrampModal=!1;this.onrampUrl=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),a=this.selectedSymbol||"ICP";window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"donate",type:"sendUsd",amount:t,currency:a}}))}catch{}}catch{}};this.onSelectBalanceSymbol=async e=>{let t=(this.walletBalances||[]).find(n=>n?.tokenShortcode===e);if(t?.ledgerSymbol&&(this.selectedSymbol=t.ledgerSymbol),this.showBalanceModal=!1,this.showWalletModal=!1,B(this.lastWalletId)){let n=(this.walletBalances||[]).find(o=>o?.tokenShortcode===e),s=n?.chainId;V(s,{provider:this.pnp?.getEvmProvider?.()||this.config?.evmProvider,chainName:n?.chainName,rpcUrlPublic:n?.rpcUrlPublic,nativeSymbol:n?.ledgerSymbol,decimals:n?.decimals}).then(async()=>{try{let o=g(this.config),c=Number(this.selectedAmount||0);if(n?.x402Accepts)try{await o.client.createPaymentX402Usd({usdAmount:c,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay_network:"evm",icpay_ledger_id:n?.ledgerId,icpay_context:"donation:x402"},recipientAddress:(this.config?.recipientAddresses||{})?.evm||"0x0000000000000000000000000000000000000000"}),this.showBalanceModal=!1;return}catch{}await o.client.createPaymentUsd({usdAmount:c,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay_network:"evm",icpay_ledger_id:n?.ledgerId},recipientAddress:(this.config?.recipientAddresses||{})?.evm||"0x0000000000000000000000000000000000000000"})}catch{}this.showBalanceModal=!1});return}let a=this.pendingAction;if(this.pendingAction=null,a==="donate")try{let n=(this.walletBalances||[]).find(y=>y?.tokenShortcode===e),s=g(this.config),o=Number(this.selectedAmount||0),p=String(n?.ledgerName||n?.chainName||"").toLowerCase().includes("sol"),h=this.config?.recipientAddresses||{},d=p&&h.sol||h.ic;if(p&&n?.x402Accepts)try{await s.client.createPaymentX402Usd({usdAmount:o,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"sol",icpay_ledger_id:n?.ledgerId,icpay_context:"donation:x402"}},recipientAddress:d||""});return}catch{return}await s.client.createPaymentUsd({usdAmount:o,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"ic",icpay_ledger_id:n?.ledgerId}},recipientAddress:d||"0x0000000000000000000000000000000000000000"})}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-BEKXSS66.js")).WalletSelect);let a=$({...this.config?.plugNPlay||{}});try{if(typeof window<"u"){let{resolveDerivationOrigin:s}=await import("./origin-44ZEXSX4.js");a.derivationOrigin=this.config?.derivationOrigin||s()}}catch{}let n=new ge(a);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(),!!Ke){ke(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;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}this.walletModalStep!=="balances"&&!this.oisyReadyToPay&&(this.pendingAction=null,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(Ke&&!this.processing){ke(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){ke(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{ge||(ge=(await import("./wallet-select-BEKXSS66.js")).WalletSelect);let t=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab)?$({...this.config?.plugNPlay||{}}):{...this.config?.plugNPlay||{}};this.config?.chainTypes&&(t.chainTypes=this.config.chainTypes);try{if(typeof window<"u"){let{resolveDerivationOrigin:n}=await import("./origin-44ZEXSX4.js");t.derivationOrigin=this.config?.derivationOrigin||n()}}catch{}this.pnp=new ge(t);try{let n=await te(this.pnp);if(n){this.walletConnected=!0;let s=U(this.pnp,{owner:n,principal:n,connected:!0}),o=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:s,actorProvider:(c,p)=>this.pnp.getActor({canisterId:c,idl:p,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 a=this.pnp.getEnabledWallets();if(ke(this.config?.debug||!1,"Available wallets",a),!a?.length)throw new Error("No wallets available");this.pendingAction="donate",this.showWalletModal=!0;return}catch(e){ke(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){_(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),z(t)&&(this.errorMessage=D(t),this.errorSeverity=j(t),this.errorAction=F(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,a=t?.event_id||t?.eventId||t?.id;if(!(!a||typeof a!="string")&&a==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let n=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(n||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 t=await g(this.config).startOnrampUsd(this.selectedAmount,void 0,{context:"donation:onramp",onrampPayment:!0,onrampProvider:"coinbase"}),a=t?.metadata?.onramp?.url||t?.onramp?.url||t?.metadata?.icpay_onramp?.url||t?.paymentIntent?.metadata?.icpay?.onrampUrl||t?.metadata?.icpay?.onrampUrl||null,n=t?.metadata?.icpay_payment_intent_id||t?.metadata?.paymentIntentId||t?.paymentIntentId||null,s=t?.metadata?.icpay_onramp?.errorMessage||t?.metadata?.onramp?.errorMessage||t?.paymentIntent?.metadata?.icpay?.onrampError||t?.paymentIntent?.metadata?.icpay?.errorMessage||t?.metadata?.icpay?.onrampError||t?.metadata?.icpay?.errorMessage||null;if(this.onrampPaymentIntentId=n,a){this.onrampUrl=a,this.onrampErrorMessage=null;try{window.open(a,"icpay_onramp","noopener,noreferrer");try{window.dispatchEvent(new CustomEvent("icpay-onramp-opened",{detail:{url:a}}))}catch{}}catch{}this.startOnrampPolling()}else this.onrampUrl=null,this.onrampErrorMessage=s||"Failed to obtain onramp URL",this.showOnrampModal=!0}catch(e){this.onrampUrl=null,this.onrampErrorMessage=e?.message||"Failed to obtain onramp URL",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 a=g(this.config),n=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>n()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=a.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(a=>{if(!!!(a&&(a.connected===!0||a.principal||a.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 s=U(this.pnp,a),o=this.pnp?.getEvmProvider?.(),c=this.pnp?.getSolanaProvider?.();this.config={...this.config,connectedWallet:s,actorProvider:(p,h)=>this.pnp.getActor({canisterId:p,idl:h,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{},...c?{solanaProvider:c}:{}},this.sdk=null,this.walletModalStep="balances",this.showBalanceModal=!1,this.showWalletModal=!0,this.fetchAndShowBalances()}).catch(a=>{this.errorMessage=a instanceof Error?a.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.walletModalStep="balances",this.showBalanceModal=!1;let e=g(this.config),{balances:t}=await X({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?se`
|
|
1782
1820
|
<div class="icpay-card icpay-section icpay-widget-base" style="text-align:center;">
|
|
1783
|
-
${this.config?.progressBar?.enabled!==!1?
|
|
1821
|
+
${this.config?.progressBar?.enabled!==!1?se`
|
|
1784
1822
|
<icpay-progress-bar
|
|
1785
1823
|
.debug=${!!this.config?.debug}
|
|
1786
1824
|
.theme=${this.config?.theme}
|
|
@@ -1792,7 +1830,7 @@ import{a as r}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var j=Xe`
|
|
|
1792
1830
|
<div class="total">$${Number(this.raised).toFixed(0)} / $${Number(this.config?.goalUsd??0).toFixed(2)}</div>
|
|
1793
1831
|
|
|
1794
1832
|
<div class="amounts">
|
|
1795
|
-
${this.amounts.map(e=>
|
|
1833
|
+
${this.amounts.map(e=>se`<div class="chip ${this.selectedAmount===e?"selected":""}" @click=${()=>this.selectAmount(e)}>$${e}</div>`)}
|
|
1796
1834
|
</div>
|
|
1797
1835
|
|
|
1798
1836
|
|
|
@@ -1803,26 +1841,28 @@ import{a as r}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var j=Xe`
|
|
|
1803
1841
|
${this.succeeded&&this.config?.disableAfterSuccess?"Donated":this.processing?"Processing\u2026":(this.config?.buttonLabel||"Donate {amount} with crypto").replace("{amount}",`${this.selectedAmount}`).replace("{symbol}",this.selectedSymbol||"ICP")}
|
|
1804
1842
|
</button>
|
|
1805
1843
|
|
|
1806
|
-
${this.errorMessage?
|
|
1844
|
+
${this.errorMessage?se`
|
|
1807
1845
|
<div class="error-message ${this.errorSeverity}" style="margin-top: 12px; padding: 8px 12px; border-radius: 6px; font-size: 14px; text-align: center;">
|
|
1808
1846
|
${this.errorMessage}
|
|
1809
|
-
${this.errorAction?
|
|
1847
|
+
${this.errorAction?se`
|
|
1810
1848
|
<button style="margin-left: 8px; padding: 4px 8px; background: transparent; border: 1px solid currentColor; border-radius: 4px; font-size: 12px; cursor: pointer;">
|
|
1811
1849
|
${this.errorAction}
|
|
1812
1850
|
</button>
|
|
1813
1851
|
`:""}
|
|
1814
1852
|
</div>
|
|
1815
1853
|
`:""}
|
|
1816
|
-
${(()=>{let e=this.pnp?.getEnabledWallets?.()||[],t=H(e);return G({visible:!!(this.showWalletModal&&this.pnp),wallets:t,isConnecting:!1,step:this.walletModalStep,balances:this.walletModalStep==="balances"?this.walletBalances:[],balancesLoading:this.walletModalStep==="balances"?this.balancesLoading:!1,balancesError:this.walletModalStep==="balances"?this.balancesError:null,onSelectBalance:
|
|
1854
|
+
${(()=>{let e=this.pnp?.getEnabledWallets?.()||[],t=H(e),a=this.config?.theme?typeof this.config.theme=="string"?this.config.theme:this.config.theme.mode||"light":void 0;return G({visible:!!(this.showWalletModal&&this.pnp),wallets:t,isConnecting:!1,step:this.walletModalStep,balances:this.walletModalStep==="balances"?this.walletBalances:[],balancesLoading:this.walletModalStep==="balances"?this.balancesLoading:!1,balancesError:this.walletModalStep==="balances"?this.balancesError:null,onSelectBalance:n=>this.onSelectBalanceSymbol(n),onBack:()=>{this.walletModalStep="connect"},onSwitchAccount:()=>this.onSwitchAccount(null),onSelect:n=>this.connectWithWallet(n),onClose:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-cancelled",{detail:{reason:"user_cancelled"}}))}catch{}},onDismiss:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1},onCreditCard:this.config?.onramp?.enabled===!0&&this.config?.onrampDisabled!==!0?()=>this.startOnramp():void 0,creditCardLabel:this.config?.onramp?.creditCardLabel||"Pay with credit card",showCreditCard:this.config?.onramp?.enabled===!0&&this.config?.onrampDisabled!==!0,creditCardTooltip:(()=>{let s=Number(this.selectedAmount||this.config?.defaultAmountUsd||0);return s>0&&s<5&&this.config?.onramp?.enabled===!0&&this.config?.onrampDisabled!==!0?`Note: Minimum card amount is $5. You will pay about $${(5-s).toFixed(2)} more.`:null})(),oisyReadyToPay:this.oisyReadyToPay,onOisyPay:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1,this.donate()},theme:a})})()}
|
|
1817
1855
|
|
|
1818
|
-
${
|
|
1856
|
+
${(()=>{let e=this.config?.theme?typeof this.config.theme=="string"?this.config.theme:this.config.theme.mode||"light":void 0;return se`
|
|
1857
|
+
${Q({visible:this.showBalanceModal,isLoading:this.balancesLoading,error:this.balancesError,balances:this.walletBalances,onSelect:t=>this.onSelectBalanceSymbol(t),onClose:()=>{this.showBalanceModal=!1},theme:e})}
|
|
1819
1858
|
|
|
1820
|
-
|
|
1859
|
+
${q({visible:this.showOnrampModal,url:this.onrampUrl||void 0,errorMessage:this.onrampErrorMessage||void 0,width:this.config?.onramp?.width,height:this.config?.onramp?.height,onClose:()=>{this.showOnrampModal=!1},onBack:()=>{this.showOnrampModal=!1,this.showWalletModal=!0},title:"Pay with credit card",theme:e})}
|
|
1860
|
+
`})()}
|
|
1821
1861
|
<div class="icpay-powered-by">
|
|
1822
1862
|
<a href="https://icpay.org" target="_blank" rel="noopener noreferrer">Powered by icpay</a>
|
|
1823
1863
|
</div>
|
|
1824
1864
|
</div>
|
|
1825
|
-
`:
|
|
1865
|
+
`:se`<div class="icpay-card icpay-section">Loading...</div>`}};x.styles=[K,At`
|
|
1826
1866
|
.thermo { width: 60px; height: 200px; background: var(--icpay-surface-alt); border: 3px solid #6b7280; border-radius: 30px; margin: 0 auto 12px; position: relative; overflow: hidden; }
|
|
1827
1867
|
.fill { position: absolute; bottom: 0; left: 0; right: 0; background: linear-gradient(135deg, #d1d5db 0%, #9ca3af 100%); transition: height 0.8s ease; height: 0%; border-radius: 0 0 27px 27px; }
|
|
1828
1868
|
.amounts { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; margin: 12px 0; }
|
|
@@ -1854,7 +1894,7 @@ import{a as r}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var j=Xe`
|
|
|
1854
1894
|
border-color: var(--icpay-error-border);
|
|
1855
1895
|
color: var(--icpay-error-text);
|
|
1856
1896
|
}
|
|
1857
|
-
`],r([Lt({type:Object})],x.prototype,"config",2),r([A()],x.prototype,"selectedAmount",2),r([A()],x.prototype,"selectedSymbol",2),r([A()],x.prototype,"raised",2),r([A()],x.prototype,"processing",2),r([A()],x.prototype,"succeeded",2),r([A()],x.prototype,"errorMessage",2),r([A()],x.prototype,"errorSeverity",2),r([A()],x.prototype,"errorAction",2),r([A()],x.prototype,"walletConnected",2),r([A()],x.prototype,"pendingAction",2),r([A()],x.prototype,"showWalletModal",2),r([A()],x.prototype,"walletModalStep",2),r([A()],x.prototype,"oisyReadyToPay",2),r([A()],x.prototype,"lastWalletId",2),r([A()],x.prototype,"showOnrampModal",2),r([A()],x.prototype,"onrampUrl",2),r([A()],x.prototype,"onrampPaymentIntentId",2),r([A()],x.prototype,"onrampErrorMessage",2),r([A()],x.prototype,"showBalanceModal",2),r([A()],x.prototype,"balancesLoading",2),r([A()],x.prototype,"balancesError",2),r([A()],x.prototype,"walletBalances",2),x=r([Ct("icpay-donation-thermometer")],x);import{LitElement as Ut,html as
|
|
1897
|
+
`],r([Lt({type:Object})],x.prototype,"config",2),r([A()],x.prototype,"selectedAmount",2),r([A()],x.prototype,"selectedSymbol",2),r([A()],x.prototype,"raised",2),r([A()],x.prototype,"processing",2),r([A()],x.prototype,"succeeded",2),r([A()],x.prototype,"errorMessage",2),r([A()],x.prototype,"errorSeverity",2),r([A()],x.prototype,"errorAction",2),r([A()],x.prototype,"walletConnected",2),r([A()],x.prototype,"pendingAction",2),r([A()],x.prototype,"showWalletModal",2),r([A()],x.prototype,"walletModalStep",2),r([A()],x.prototype,"oisyReadyToPay",2),r([A()],x.prototype,"lastWalletId",2),r([A()],x.prototype,"showOnrampModal",2),r([A()],x.prototype,"onrampUrl",2),r([A()],x.prototype,"onrampPaymentIntentId",2),r([A()],x.prototype,"onrampErrorMessage",2),r([A()],x.prototype,"showBalanceModal",2),r([A()],x.prototype,"balancesLoading",2),r([A()],x.prototype,"balancesError",2),r([A()],x.prototype,"walletBalances",2),x=r([Ct("icpay-donation-thermometer")],x);import{LitElement as Ut,html as me,css as Ot}from"lit";import{customElement as Nt,property as Pt,state as M}from"lit/decorators.js";import{html as Te}from"lit";function Tt(i){if(i==="light"||i==="dark")return i;if(typeof document>"u")return"light";let l=document.documentElement.getAttribute("data-icpay-theme");if(l==="light"||l==="dark")return l;let e=document.documentElement.getAttribute("data-theme");return e==="light"||e==="dark"?e:"light"}function qe(i){if(!i.visible)return null;let l=i.providers||[],e=Tt(i.theme);return Te`
|
|
1858
1898
|
<style>
|
|
1859
1899
|
/* Theme-aware color variables - Light mode defaults */
|
|
1860
1900
|
.icpay-onramp-overlay {
|
|
@@ -1948,27 +1988,27 @@ import{a as r}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var j=Xe`
|
|
|
1948
1988
|
<button @click=${i.onClose} style="position:absolute;right:12px;top:12px;background:transparent;border:none;color:var(--icpay-foreground);cursor:pointer;font-size:20px;opacity:0.8">×</button>
|
|
1949
1989
|
<div style="color:var(--icpay-foreground);font-weight:600;font-size:16px;margin-bottom:12px">${i.title||"Choose a provider"}</div>
|
|
1950
1990
|
<div style="display:flex;flex-direction:column;gap:10px">
|
|
1951
|
-
${
|
|
1991
|
+
${l.map(t=>Te`
|
|
1952
1992
|
<button
|
|
1953
1993
|
class="icpay-onramp-provider-btn"
|
|
1954
1994
|
@click=${()=>i.onSelect(t.slug)}
|
|
1955
1995
|
>
|
|
1956
|
-
${t.logoUrl?
|
|
1996
|
+
${t.logoUrl?Te`<img src="${t.logoUrl}" style="width:24px;height:24px;border-radius:4px" />`:Te`<div style="width:24px;height:24px;border-radius:4px;background:var(--icpay-secondary)"></div>`}
|
|
1957
1997
|
<span style="font-size:14px">${t.name}</span>
|
|
1958
1998
|
</button>
|
|
1959
1999
|
`)}
|
|
1960
2000
|
</div>
|
|
1961
2001
|
</div>
|
|
1962
2002
|
</div>
|
|
1963
|
-
`}var He=typeof window<"u",ye=null;function N(i,s,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${s}`,e):console.log(`[ICPay Widget] ${s}`))}var f=class extends Ut{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.onrampUrl=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.showProviderPicker=!1;this.selectedOnrampProvider=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.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),a=this.selectedSymbol||"ICP";window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"pay",type:"sendUsd",amount:t,currency:a}}))}catch{}}catch{}};this.onSelectBalanceSymbol=async e=>{let t=(this.walletBalances||[]).find(n=>n?.tokenShortcode===e);if(t?.ledgerSymbol&&(this.selectedSymbol=t.ledgerSymbol),this.showBalanceModal=!1,this.showWalletModal=!1,B(this.lastWalletId)){N(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 n=t?.chainId;V(n,{provider:this.pnp?.getEvmProvider?.()||this.config?.evmProvider,chainName:t?.chainName,rpcUrlPublic:t?.rpcUrlPublic,nativeSymbol:t?.ledgerSymbol,decimals:t?.decimals}).then(async()=>{try{let o=this.getSdk(),l=Number(this.config?.amountUsd??0),d=t?.ledgerSymbol,p=!!(t&&t.x402Accepts);if(N(this.config?.debug||!1,"EVM post-ensure chain snapshot",{targetChain:n,amountUsd:l,symbolNow:d,tryX402:p,x402Accepts:t?.x402Accepts}),p)try{let c=this.config?.recipientAddresses?.evm||"0x0000000000000000000000000000000000000000";N(this.config?.debug||!1,"Using recipientAddress (x402)",{recipientAddress:c});let y={...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"evm",icpay_ledger_id:t?.ledgerId,icpay_context:"pay-button:x402"}};N(this.config?.debug||!1,"Attempting X402 flow (EVM selection)",{amountUsd:l,tokenShortcode:t?.tokenShortcode,x402Accepts:t?.x402Accepts}),await o.client.createPaymentX402Usd({usdAmount:l,tokenShortcode:t?.tokenShortcode,metadata:y,recipientAddress:c});return}catch(c){N(this.config?.debug||!1,"X402 payment failed (EVM selection), falling back",{message:c?.message,code:c?.code,data:c?.details||c?.data})}else N(this.config?.debug||!1,"Skipping X402 path",{reason:t?t.x402Accepts?"unknown":"x402Accepts false":"no selection",selPresent:!!t,x402Accepts:t?.x402Accepts});N(this.config?.debug||!1,"Falling back to normal EVM wallet flow",{amountUsd:l,tokenShortcode:t?.tokenShortcode});let h=this.config?.recipientAddresses?.evm||"0x0000000000000000000000000000000000000000";N(this.config?.debug||!1,"Using recipientAddress (normal)",{recipientAddress:h}),await o.client.createPaymentUsd({usdAmount:l,tokenShortcode:t?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"evm",icpay_ledger_id:t?.ledgerId}},recipientAddress:h})}catch{}});return}let a=this.pendingAction;if(this.pendingAction=null,a==="pay")try{let n=(this.walletBalances||[]).find(g=>g?.tokenShortcode===e),o=this.getSdk(),l=Number(this.config?.amountUsd??0);N(this.config?.debug||!1,"IC selection made",{selectedSymbol:this.selectedSymbol,selPresent:!!n,selSnapshot:n?{ledgerId:n?.ledgerId,ledgerSymbol:n?.ledgerSymbol,ledgerName:n?.ledgerName,requiredAmount:n?.requiredAmount,hasSufficientBalance:n?.hasSufficientBalance,tokenShortcode:n?.tokenShortcode}:null});let d=String(n?.chainName||"").toLowerCase(),p=d.includes("sol"),h=this.config?.recipientAddresses||{},c=p?h.sol||h.ic||this.config?.recipientAddress:h.ic||this.config?.recipientAddress,y=d.includes("ic");if(n?.x402Accepts)try{let g={...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:p?"sol":y?"ic":this.config?.icpay_network,icpay_ledger_id:n?.ledgerId,icpay_context:"pay-button:x402"}};await o.client.createPaymentX402Usd({usdAmount:l,tokenShortcode:n?.tokenShortcode,metadata:g,recipientAddress:c||""});return}catch(g){N(this.config?.debug||!1,"X402 payment failed (SOL selection), falling back",{message:g?.message,code:g?.code,data:g?.details||g?.data});return}await o.client.createPaymentUsd({usdAmount:l,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"ic",icpay_ledger_id:n?.ledgerId}},recipientAddress:c||"0x0000000000000000000000000000000000000000"})}catch{}}}getSdk(){return this.sdk||(this.sdk=u(this.config)),this.sdk}connectedCallback(){if(super.connectedCallback(),!!He){N(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=>{N(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{ye||(ye=(await import("./wallet-select-BEKXSS66.js")).WalletSelect);let e=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab),t={...this.config?.plugNPlay||{}},a=this.config?.recipientAddresses;if(a&&(a.ic||a.evm||a.sol)){let l=[];a.ic&&l.push("ic"),a.evm&&l.push("evm"),a.sol&&l.push("sol"),l.length&&(t.chainTypes=l)}else this.config?.chainTypes&&(t.chainTypes=this.config.chainTypes);let n=e?$(t):t;try{if(typeof window<"u"){let{resolveDerivationOrigin:l}=await import("./origin-44ZEXSX4.js");n.derivationOrigin=this.config?.derivationOrigin||l()}}catch{}this.pnp=new ye(n);let o=this.pnp.getEnabledWallets();if(N(this.config?.debug||!1,"Available wallets",o),!o?.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(a=>{if(N(this.config?.debug||!1,"Wallet connect result",a),!!!(a&&(a.connected===!0||a.principal||a.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}let o=U(this.pnp,a),l=this.pnp?.getEvmProvider?.(),d=this.pnp?.getSolanaProvider?.();this.config={...this.config,connectedWallet:o,actorProvider:(p,h)=>this.pnp.getActor({canisterId:p,idl:h,requiresSigning:!0,anon:!1}),...l?{evmProvider:l}:{},...d?{solanaProvider:d}:{}},this.sdk=null,this.walletModalStep="balances",this.fetchAndShowBalances("pay")}).catch(a=>{N(this.config?.debug||!1,"Wallet connection error",a);let n=(e||"").toLowerCase()==="oisy",o=a&&(a.message||String(a))||"";if(n&&!this.oisyConnectRetriedNewTab&&(o.includes("Signer window could not be opened")||o.includes("Communication channel could not be established"))){this.oisyConnectRetriedNewTab=!0,(async()=>{try{ye||(ye=(await import("./wallet-select-BEKXSS66.js")).WalletSelect);let d={...this.config?.plugNPlay||{}},p=this.config?.recipientAddresses;if(p&&(p.ic||p.evm||p.sol)){let y=[];p.ic&&y.push("ic"),p.evm&&y.push("evm"),p.sol&&y.push("sol"),y.length&&(d.chainTypes=y)}else this.config?.chainTypes&&(d.chainTypes=this.config.chainTypes);let h=$(d);try{if(typeof window<"u"){let{resolveDerivationOrigin:y}=await import("./origin-44ZEXSX4.js");h.derivationOrigin=this.config?.derivationOrigin||y()}}catch{}this.pnp=new ye(h),this.pnp.connect("oisy").then(y=>{if(!!!(y&&(y.connected===!0||y.principal||y.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 I=U(this.pnp,y),Z=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:I,actorProvider:(Ee,ke)=>this.pnp.getActor({canisterId:Ee,idl:ke,requiresSigning:!0,anon:!1}),...Z?{evmProvider:Z}:{}},this.sdk=null,this.walletModalStep="balances",this.fetchAndShowBalances("pay")}).catch(y=>{N(this.config?.debug||!1,"Oisy retry connect (new tab) failed",y),this.errorMessage=y instanceof Error?y.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(d){N(this.config?.debug||!1,"Oisy new-tab init failed",d),this.errorMessage=d instanceof Error?d.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=a instanceof Error?a.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){N(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:a}=await X({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=a,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=H(e),a=this.config?.onramp?.enabled===!0&&this.config?.onrampDisabled!==!0,n=2,o=Number(this.config?.amountUsd??0),l=a&&o>0&&o<n,d=Math.max(0,n-o),p=l?`Note: Minimum card amount is $${n}. You will pay about $${d.toFixed(2)} more.`:null;return G({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{}},onDismiss:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1},onCreditCard:a?()=>this.startOnramp():void 0,creditCardLabel:this.config?.onramp?.creditCardLabel||"Pay with credit card",showCreditCard:a,creditCardTooltip:p,oisyReadyToPay:this.oisyReadyToPay,onOisyPay:()=>{this.showWalletModal=!1,this.skipDisconnectOnce=!0,this.oisyReadyToPay=!1,this.pay()}})}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1;let e=Array.isArray(this.config?.onramp?.providers)?this.config.onramp.providers.filter(a=>a&&a.enabled!==!1):[],t=e.length?e:[{slug:"coinbase",name:"Coinbase",enabled:!0}];t.length>1?this.showProviderPicker=!0:(this.selectedOnrampProvider=t[0]?.slug||"coinbase",setTimeout(()=>this.createOnrampIntent(),0))}async createOnrampIntent(){try{let e=Number(this.config?.amountUsd??0),t=this.getSdk();this.selectedSymbol||(this.selectedSymbol="ICP");let a=await t.startOnrampUsd(e,void 0,{context:"pay-button:onramp",onrampPayment:!0,onrampProvider:this.selectedOnrampProvider||"coinbase"}),n=a?.metadata?.onramp?.url||a?.onramp?.url||a?.metadata?.icpay_onramp?.url||a?.paymentIntent?.metadata?.icpay?.onrampUrl||a?.metadata?.icpay?.onrampUrl||null,o=a?.metadata?.icpay_onramp?.errorMessage||a?.metadata?.onramp?.errorMessage||a?.paymentIntent?.metadata?.icpay?.onrampError||a?.paymentIntent?.metadata?.icpay?.errorMessage||a?.metadata?.icpay?.onrampError||a?.metadata?.icpay?.errorMessage||null;this.onrampErrorMessage=o||null;let l=a?.metadata?.icpay_payment_intent_id||a?.metadata?.paymentIntentId||a?.paymentIntentId||null;if(this.onrampPaymentIntentId=l,n){this.onrampUrl=n;try{window.open(n,"icpay_onramp","noopener,noreferrer");try{window.dispatchEvent(new CustomEvent("icpay-onramp-opened",{detail:{url:n}}))}catch{}}catch{}this.startOnrampPolling(void 0)}else this.onrampUrl=null,this.showOnrampModal=!0}catch(e){this.onrampUrl=null,this.onrampErrorMessage=e?.message||null,this.showOnrampModal=!0,_(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),z(t)&&(this.errorMessage=D(t),this.errorSeverity=K(t),this.errorAction=F(t))}})}}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 a=this.getSdk(),n=()=>{if(this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1},o=l=>{n()};try{window.addEventListener("icpay-sdk-transaction-completed",o,{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=a.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}async pay(){if(!(!He||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 a=this.config?.connectedWallet,n=this?.pnp?.account;N(this.config?.debug||!1,"Wallet state before payment",{connectedWallet:a,pnpAccount:n,principal:a?.owner||a?.principal||n?.owner||n?.principal||null})}catch{}this.walletModalStep="balances",this.showWalletModal=!0,await this.fetchAndShowBalances("pay");return}catch(e){N(this.config?.debug||!1,"Payment error",{message:e?.message,code:e?.code,details:e?.details,stack:e?.stack}),_(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),z(t)&&(this.errorMessage=D(t),this.errorSeverity=K(t),this.errorAction=F(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 we`<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)}`:"",n=(this.config?.buttonLabel||(typeof this.config?.amountUsd=="number"?"Pay ${amount} with crypto":"Pay with {symbol}")).replace("{amount}",t||"$0.00").replace("{symbol}",e),l=this.config?.progressBar?.enabled!==!1,d=this.showWalletModal||this.showBalanceModal;return we`
|
|
2003
|
+
`}var He=typeof window<"u",ue=null;function N(i,l,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${l}`,e):console.log(`[ICPay Widget] ${l}`))}var f=class extends Ut{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.onrampUrl=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.showProviderPicker=!1;this.selectedOnrampProvider=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.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),a=this.selectedSymbol||"ICP";window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"pay",type:"sendUsd",amount:t,currency:a}}))}catch{}}catch{}};this.onSelectBalanceSymbol=async e=>{let t=(this.walletBalances||[]).find(n=>n?.tokenShortcode===e);if(t?.ledgerSymbol&&(this.selectedSymbol=t.ledgerSymbol),this.showBalanceModal=!1,this.showWalletModal=!1,B(this.lastWalletId)){N(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 n=t?.chainId;V(n,{provider:this.pnp?.getEvmProvider?.()||this.config?.evmProvider,chainName:t?.chainName,rpcUrlPublic:t?.rpcUrlPublic,nativeSymbol:t?.ledgerSymbol,decimals:t?.decimals}).then(async()=>{try{let s=this.getSdk(),o=Number(this.config?.amountUsd??0),c=t?.ledgerSymbol,p=!!(t&&t.x402Accepts);if(N(this.config?.debug||!1,"EVM post-ensure chain snapshot",{targetChain:n,amountUsd:o,symbolNow:c,tryX402:p,x402Accepts:t?.x402Accepts}),p)try{let d=this.config?.recipientAddresses?.evm||"0x0000000000000000000000000000000000000000";N(this.config?.debug||!1,"Using recipientAddress (x402)",{recipientAddress:d});let y={...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"evm",icpay_ledger_id:t?.ledgerId,icpay_context:"pay-button:x402"}};N(this.config?.debug||!1,"Attempting X402 flow (EVM selection)",{amountUsd:o,tokenShortcode:t?.tokenShortcode,x402Accepts:t?.x402Accepts}),await s.client.createPaymentX402Usd({usdAmount:o,tokenShortcode:t?.tokenShortcode,metadata:y,recipientAddress:d});return}catch(d){N(this.config?.debug||!1,"X402 payment failed (EVM selection), falling back",{message:d?.message,code:d?.code,data:d?.details||d?.data})}else N(this.config?.debug||!1,"Skipping X402 path",{reason:t?t.x402Accepts?"unknown":"x402Accepts false":"no selection",selPresent:!!t,x402Accepts:t?.x402Accepts});N(this.config?.debug||!1,"Falling back to normal EVM wallet flow",{amountUsd:o,tokenShortcode:t?.tokenShortcode});let h=this.config?.recipientAddresses?.evm||"0x0000000000000000000000000000000000000000";N(this.config?.debug||!1,"Using recipientAddress (normal)",{recipientAddress:h}),await s.client.createPaymentUsd({usdAmount:o,tokenShortcode:t?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"evm",icpay_ledger_id:t?.ledgerId}},recipientAddress:h})}catch{}});return}let a=this.pendingAction;if(this.pendingAction=null,a==="pay")try{let n=(this.walletBalances||[]).find(m=>m?.tokenShortcode===e),s=this.getSdk(),o=Number(this.config?.amountUsd??0);N(this.config?.debug||!1,"IC selection made",{selectedSymbol:this.selectedSymbol,selPresent:!!n,selSnapshot:n?{ledgerId:n?.ledgerId,ledgerSymbol:n?.ledgerSymbol,ledgerName:n?.ledgerName,requiredAmount:n?.requiredAmount,hasSufficientBalance:n?.hasSufficientBalance,tokenShortcode:n?.tokenShortcode}:null});let c=String(n?.chainName||"").toLowerCase(),p=c.includes("sol"),h=this.config?.recipientAddresses||{},d=p?h.sol||h.ic||this.config?.recipientAddress:h.ic||this.config?.recipientAddress,y=c.includes("ic");if(n?.x402Accepts)try{let m={...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:p?"sol":y?"ic":this.config?.icpay_network,icpay_ledger_id:n?.ledgerId,icpay_context:"pay-button:x402"}};await s.client.createPaymentX402Usd({usdAmount:o,tokenShortcode:n?.tokenShortcode,metadata:m,recipientAddress:d||""});return}catch(m){N(this.config?.debug||!1,"X402 payment failed (SOL selection), falling back",{message:m?.message,code:m?.code,data:m?.details||m?.data});return}await s.client.createPaymentUsd({usdAmount:o,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"ic",icpay_ledger_id:n?.ledgerId}},recipientAddress:d||"0x0000000000000000000000000000000000000000"})}catch{}}}getSdk(){return this.sdk||(this.sdk=g(this.config)),this.sdk}connectedCallback(){if(super.connectedCallback(),!!He){N(this.config?.debug||!1,"Pay button connected",{config:this.config}),this.config?.theme&&oe(this,this.config.theme);try{window.addEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}try{window.addEventListener("icpay-sdk-transaction-created",(e=>{N(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.config?.theme&&oe(this,this.config.theme),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-BEKXSS66.js")).WalletSelect);let e=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab),t={...this.config?.plugNPlay||{}},a=this.config?.recipientAddresses;if(a&&(a.ic||a.evm||a.sol)){let o=[];a.ic&&o.push("ic"),a.evm&&o.push("evm"),a.sol&&o.push("sol"),o.length&&(t.chainTypes=o)}else this.config?.chainTypes&&(t.chainTypes=this.config.chainTypes);let n=e?$(t):t;try{if(typeof window<"u"){let{resolveDerivationOrigin:o}=await import("./origin-44ZEXSX4.js");n.derivationOrigin=this.config?.derivationOrigin||o()}}catch{}this.pnp=new ue(n);let s=this.pnp.getEnabledWallets();if(N(this.config?.debug||!1,"Available wallets",s),!s?.length)throw new Error("No wallets available");return this.pendingAction="pay",this.showWalletModal=!0,!1}catch(e){return this.errorMessage=e instanceof Error?e.message:"Wallet connection failed",this.errorSeverity="error",!1}}getWalletId(e){return e&&(e.id||e.provider||e.key)||""}getWalletLabel(e){return e&&(e.label||e.name||e.title||e.id)||"Wallet"}getWalletIcon(e){return e&&(e.icon||e.logo||e.image)||null}connectWithWallet(e){if(this.pnp)try{if(!e)throw new Error("No wallet ID provided");this.lastWalletId=(e||"").toLowerCase(),this.lastWalletId==="oisy"&&(this.oisyConnectRetriedNewTab=!1),this.pnp.connect(e).then(a=>{if(N(this.config?.debug||!1,"Wallet connect result",a),!!!(a&&(a.connected===!0||a.principal||a.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 s=U(this.pnp,a),o=this.pnp?.getEvmProvider?.(),c=this.pnp?.getSolanaProvider?.();this.config={...this.config,connectedWallet:s,actorProvider:(p,h)=>this.pnp.getActor({canisterId:p,idl:h,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{},...c?{solanaProvider:c}:{}},this.sdk=null,this.walletModalStep="balances",this.fetchAndShowBalances("pay")}).catch(a=>{N(this.config?.debug||!1,"Wallet connection error",a);let n=(e||"").toLowerCase()==="oisy",s=a&&(a.message||String(a))||"";if(n&&!this.oisyConnectRetriedNewTab&&(s.includes("Signer window could not be opened")||s.includes("Communication channel could not be established"))){this.oisyConnectRetriedNewTab=!0,(async()=>{try{ue||(ue=(await import("./wallet-select-BEKXSS66.js")).WalletSelect);let c={...this.config?.plugNPlay||{}},p=this.config?.recipientAddresses;if(p&&(p.ic||p.evm||p.sol)){let y=[];p.ic&&y.push("ic"),p.evm&&y.push("evm"),p.sol&&y.push("sol"),y.length&&(c.chainTypes=y)}else this.config?.chainTypes&&(c.chainTypes=this.config.chainTypes);let h=$(c);try{if(typeof window<"u"){let{resolveDerivationOrigin:y}=await import("./origin-44ZEXSX4.js");h.derivationOrigin=this.config?.derivationOrigin||y()}}catch{}this.pnp=new ue(h),this.pnp.connect("oisy").then(y=>{if(!!!(y&&(y.connected===!0||y.principal||y.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 I=U(this.pnp,y),Z=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:I,actorProvider:(Ee,Se)=>this.pnp.getActor({canisterId:Ee,idl:Se,requiresSigning:!0,anon:!1}),...Z?{evmProvider:Z}:{}},this.sdk=null,this.walletModalStep="balances",this.fetchAndShowBalances("pay")}).catch(y=>{N(this.config?.debug||!1,"Oisy retry connect (new tab) failed",y),this.errorMessage=y instanceof Error?y.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){N(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=a instanceof Error?a.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){N(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:a}=await X({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=a,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=H(e),a=this.config?.onramp?.enabled===!0&&this.config?.onrampDisabled!==!0,n=2,s=Number(this.config?.amountUsd??0),o=a&&s>0&&s<n,c=Math.max(0,n-s),p=o?`Note: Minimum card amount is $${n}. You will pay about $${c.toFixed(2)} more.`:null,h=this.config?.theme?typeof this.config.theme=="string"?this.config.theme:this.config.theme.mode||"light":void 0;return G({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:d=>this.onSelectBalanceSymbol(d),onBack:()=>{this.walletModalStep="connect"},onSelect:d=>{this.connectWithWallet(d)},onClose:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-cancelled",{detail:{reason:"user_cancelled"}}))}catch{}},onDismiss:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1},onCreditCard:a?()=>this.startOnramp():void 0,creditCardLabel:this.config?.onramp?.creditCardLabel||"Pay with credit card",showCreditCard:a,creditCardTooltip:p,oisyReadyToPay:this.oisyReadyToPay,onOisyPay:()=>{this.showWalletModal=!1,this.skipDisconnectOnce=!0,this.oisyReadyToPay=!1,this.pay()},theme:h})}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1;let e=Array.isArray(this.config?.onramp?.providers)?this.config.onramp.providers.filter(a=>a&&a.enabled!==!1):[],t=e.length?e:[{slug:"coinbase",name:"Coinbase",enabled:!0}];t.length>1?this.showProviderPicker=!0:(this.selectedOnrampProvider=t[0]?.slug||"coinbase",setTimeout(()=>this.createOnrampIntent(),0))}async createOnrampIntent(){try{let e=Number(this.config?.amountUsd??0),t=this.getSdk();this.selectedSymbol||(this.selectedSymbol="ICP");let a=await t.startOnrampUsd(e,void 0,{context:"pay-button:onramp",onrampPayment:!0,onrampProvider:this.selectedOnrampProvider||"coinbase"}),n=a?.metadata?.onramp?.url||a?.onramp?.url||a?.metadata?.icpay_onramp?.url||a?.paymentIntent?.metadata?.icpay?.onrampUrl||a?.metadata?.icpay?.onrampUrl||null,s=a?.metadata?.icpay_onramp?.errorMessage||a?.metadata?.onramp?.errorMessage||a?.paymentIntent?.metadata?.icpay?.onrampError||a?.paymentIntent?.metadata?.icpay?.errorMessage||a?.metadata?.icpay?.onrampError||a?.metadata?.icpay?.errorMessage||null;this.onrampErrorMessage=s||null;let o=a?.metadata?.icpay_payment_intent_id||a?.metadata?.paymentIntentId||a?.paymentIntentId||null;if(this.onrampPaymentIntentId=o,n){this.onrampUrl=n;try{window.open(n,"icpay_onramp","noopener,noreferrer");try{window.dispatchEvent(new CustomEvent("icpay-onramp-opened",{detail:{url:n}}))}catch{}}catch{}this.startOnrampPolling(void 0)}else this.onrampUrl=null,this.showOnrampModal=!0}catch(e){this.onrampUrl=null,this.onrampErrorMessage=e?.message||null,this.showOnrampModal=!0,_(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),z(t)&&(this.errorMessage=D(t),this.errorSeverity=j(t),this.errorAction=F(t))}})}}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 a=this.getSdk(),n=()=>{if(this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1},s=o=>{n()};try{window.addEventListener("icpay-sdk-transaction-completed",s,{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=a.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}async pay(){if(!(!He||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 a=this.config?.connectedWallet,n=this?.pnp?.account;N(this.config?.debug||!1,"Wallet state before payment",{connectedWallet:a,pnpAccount:n,principal:a?.owner||a?.principal||n?.owner||n?.principal||null})}catch{}this.walletModalStep="balances",this.showWalletModal=!0,await this.fetchAndShowBalances("pay");return}catch(e){N(this.config?.debug||!1,"Payment error",{message:e?.message,code:e?.code,details:e?.details,stack:e?.stack}),_(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),z(t)&&(this.errorMessage=D(t),this.errorSeverity=j(t),this.errorAction=F(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.selectedSymbol||"ICP",t=typeof this.config?.amountUsd=="number"?`${Number(this.config.amountUsd).toFixed(2)}`:"",n=(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 me`
|
|
1964
2004
|
<div class="icpay-card icpay-section icpay-widget-base">
|
|
1965
|
-
${
|
|
2005
|
+
${o?me`
|
|
1966
2006
|
<icpay-progress-bar
|
|
1967
2007
|
.debug=${!!this.config?.debug}
|
|
1968
2008
|
.theme=${this.config?.theme}
|
|
1969
2009
|
.amount=${Number(this.config?.amountUsd||0)}
|
|
1970
2010
|
.ledgerSymbol=${e}
|
|
1971
|
-
.suspended=${
|
|
2011
|
+
.suspended=${c}
|
|
1972
2012
|
></icpay-progress-bar>
|
|
1973
2013
|
`:null}
|
|
1974
2014
|
|
|
@@ -1980,21 +2020,23 @@ import{a as r}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var j=Xe`
|
|
|
1980
2020
|
</button>
|
|
1981
2021
|
</div>
|
|
1982
2022
|
|
|
1983
|
-
${this.errorMessage?
|
|
2023
|
+
${this.errorMessage?me`
|
|
1984
2024
|
<div class="error-message ${this.errorSeverity}" style="margin-top: 12px; padding: 8px 12px; border-radius: 6px; font-size: 14px; text-align: center;">
|
|
1985
2025
|
${this.errorMessage}
|
|
1986
|
-
${this.errorAction?
|
|
2026
|
+
${this.errorAction?me`<button style="margin-left: 8px; padding: 4px 8px; background: transparent; border: 1px solid currentColor; border-radius: 4px; font-size: 12px; cursor: pointer;">${this.errorAction}</button>`:""}
|
|
1987
2027
|
</div>
|
|
1988
2028
|
`:""}
|
|
1989
2029
|
${this.renderWalletModal()}
|
|
1990
|
-
${
|
|
1991
|
-
|
|
1992
|
-
|
|
2030
|
+
${(()=>{let p=this.config?.theme?typeof this.config.theme=="string"?this.config.theme:this.config.theme.mode||"light":void 0;return me`
|
|
2031
|
+
${Q({visible:this.showBalanceModal,isLoading:this.balancesLoading,error:this.balancesError,balances:this.walletBalances,onSelect:h=>this.onSelectBalanceSymbol(h),onClose:()=>{this.showBalanceModal=!1},theme:p})}
|
|
2032
|
+
${q({visible:this.showOnrampModal,url:this.onrampUrl||void 0,errorMessage:this.onrampErrorMessage||void 0,width:this.config?.onramp?.width,height:this.config?.onramp?.height,onClose:()=>{this.showOnrampModal=!1},onBack:()=>{this.showOnrampModal=!1,this.showWalletModal=!0},title:"Pay with credit card",theme:p})}
|
|
2033
|
+
${qe({visible:this.showProviderPicker,providers:(()=>{let h=Array.isArray(this.config?.onramp?.providers)?this.config.onramp.providers.filter(y=>y&&y.enabled!==!1):[];return(h.length?h:[{slug:"coinbase",name:"Coinbase",enabled:!0}]).map(y=>({slug:y.slug,name:y.name||(y.slug==="coinbase"?"Coinbase":y.slug),logoUrl:y.logoUrl||null}))})(),onSelect:h=>{this.selectedOnrampProvider=h,this.showProviderPicker=!1,setTimeout(()=>this.createOnrampIntent(),0)},onClose:()=>{this.showProviderPicker=!1},title:"Choose onramp provider",theme:p})}
|
|
2034
|
+
`})()}
|
|
1993
2035
|
<div class="icpay-powered-by">
|
|
1994
2036
|
<a href="https://icpay.org" target="_blank" rel="noopener noreferrer">Powered by icpay</a>
|
|
1995
2037
|
</div>
|
|
1996
2038
|
</div>
|
|
1997
|
-
`}};f.styles=[
|
|
2039
|
+
`}};f.styles=[K,Ot`
|
|
1998
2040
|
.row { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; }
|
|
1999
2041
|
.row.single { grid-template-columns: 1fr; }
|
|
2000
2042
|
select { background: var(--icpay-surface-alt); border: 1px solid var(--icpay-border); color: var(--icpay-text); border-radius: 8px; padding: 10px; font-weight: 600; }
|
|
@@ -2002,9 +2044,9 @@ import{a as r}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var j=Xe`
|
|
|
2002
2044
|
.error-message.info { background: var(--icpay-processing-bg); border-color: var(--icpay-processing-border); color: var(--icpay-processing-text); }
|
|
2003
2045
|
.error-message.warning { background: var(--icpay-warning-bg); border-color: var(--icpay-warning-border); color: var(--icpay-warning-text); }
|
|
2004
2046
|
.error-message.error { background: var(--icpay-error-bg); border-color: var(--icpay-error-border); color: var(--icpay-error-text); }
|
|
2005
|
-
`],r([Pt({type:Object})],f.prototype,"config",2),r([M()],f.prototype,"selectedSymbol",2),r([M()],f.prototype,"processing",2),r([M()],f.prototype,"succeeded",2),r([M()],f.prototype,"errorMessage",2),r([M()],f.prototype,"errorSeverity",2),r([M()],f.prototype,"errorAction",2),r([M()],f.prototype,"walletConnected",2),r([M()],f.prototype,"pendingAction",2),r([M()],f.prototype,"showWalletModal",2),r([M()],f.prototype,"walletModalStep",2),r([M()],f.prototype,"showOnrampModal",2),r([M()],f.prototype,"onrampUrl",2),r([M()],f.prototype,"onrampPaymentIntentId",2),r([M()],f.prototype,"onrampErrorMessage",2),r([M()],f.prototype,"showProviderPicker",2),r([M()],f.prototype,"selectedOnrampProvider",2),r([M()],f.prototype,"oisyReadyToPay",2),r([M()],f.prototype,"oisySignerPreopened",2),r([M()],f.prototype,"skipDisconnectOnce",2),r([M()],f.prototype,"lastWalletId",2),r([M()],f.prototype,"showBalanceModal",2),r([M()],f.prototype,"balancesLoading",2),r([M()],f.prototype,"balancesError",2),r([M()],f.prototype,"walletBalances",2),f=r([Nt("icpay-pay-button")],f);import{LitElement as $t,html as xe,css as It}from"lit";import{customElement as Bt,property as Rt,state as C}from"lit/decorators.js";var Ve=typeof window<"u",Ne=null;function _t(i,s,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${s}`,e):console.log(`[ICPay Widget] ${s}`))}var E=class extends $t{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.walletModalStep="connect";this.showOnrampModal=!1;this.onrampUrl=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),a=this.selectedSymbol||"ICP";window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"pay",type:"sendUsd",amount:t,currency:a}}))}catch{}}catch{}};this.onSelectBalanceSymbol=async e=>{let t=(this.walletBalances||[]).find(n=>n?.tokenShortcode===e);if(t?.ledgerSymbol&&(this.selectedSymbol=t.ledgerSymbol),this.showBalanceModal=!1,this.showWalletModal=!1,B(this.lastWalletId)){let n=(this.walletBalances||[]).find(l=>l?.tokenShortcode===e),o=n?.chainId;V(o,{provider:this.pnp?.getEvmProvider?.()||this.config?.evmProvider,chainName:n?.chainName,rpcUrlPublic:n?.rpcUrlPublic,nativeSymbol:n?.ledgerSymbol,decimals:n?.decimals}).then(async()=>{try{let l=u(this.config),d=Number(this.amountUsd||0);if(n?.x402Accepts)try{await l.client.createPaymentX402Usd({usdAmount:d,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay_network:"evm",icpay_ledger_id:n?.ledgerId,icpay_context:"amount-input:x402"},recipientAddress:(this.config?.recipientAddresses||{})?.evm||"0x0000000000000000000000000000000000000000"}),this.showBalanceModal=!1;return}catch{}await l.client.createPaymentUsd({usdAmount:d,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay_network:"evm",icpay_ledger_id:n?.ledgerId},recipientAddress:(this.config?.recipientAddresses||{})?.evm||"0x0000000000000000000000000000000000000000"})}catch{}this.showBalanceModal=!1});return}let a=this.pendingAction;if(this.pendingAction=null,a==="pay")try{let n=(this.walletBalances||[]).find(g=>g?.tokenShortcode===e),o=u(this.config),l=Number(this.amountUsd||0),d=String(n?.ledgerName||n?.chainName||"").toLowerCase(),p=d.includes("sol"),h=d.includes("ic"),c=this.config?.recipientAddresses||{},y=p&&c.sol||c.ic;if(n?.x402Accepts)try{let g={...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:p?"sol":h?"ic":this.config?.icpay_network,icpay_ledger_id:n?.ledgerId,icpay_context:"amount-input:x402"}};await o.client.createPaymentX402Usd({usdAmount:l,tokenShortcode:n?.tokenShortcode,metadata:g,recipientAddress:y||""});return}catch{return}await o.client.createPaymentUsd({usdAmount:l,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"ic",icpay_ledger_id:n?.ledgerId}},recipientAddress:y||"0x0000000000000000000000000000000000000000"})}catch{}}}connectedCallback(){if(super.connectedCallback(),!!Ve){_t(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;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}this.walletModalStep!=="balances"&&(this.pendingAction=null,setTimeout(()=>{t==="pay"&&this.pay()},0))}}onInputChange(e){let t=Number(this.config?.stepUsd??.5),a=Math.max(0,Number(e.target.value||0)),n=Math.round(a/t)*t;this.amountUsd=Number(n.toFixed(2)),this.hasUserAmount=!0}selectSymbol(e){this.selectedSymbol=e}isValidAmount(){let e=Number(this.config?.minUsd??.5),t=this.config?.maxUsd!==void 0?Number(this.config.maxUsd):1/0;return this.amountUsd>=e&&this.amountUsd<=t}async ensureWallet(){if(this.config.useOwnWallet)return this.config.actorProvider?!0:(this.pendingAction="pay",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0})),!1);if(this.walletConnected)return!0;try{Ne||(Ne=(await import("./wallet-select-BEKXSS66.js")).WalletSelect);let e=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab),t={...this.config?.plugNPlay||{}},a=this.config?.recipientAddresses;if(a&&(a.ic||a.evm||a.sol)){let l=[];a.ic&&l.push("ic"),a.evm&&l.push("evm"),a.sol&&l.push("sol"),l.length&&(t.chainTypes=l)}else this.config?.chainTypes&&(t.chainTypes=this.config.chainTypes);let n=e?$(t):t;try{if(typeof window<"u"){let{resolveDerivationOrigin:l}=await import("./origin-44ZEXSX4.js");n.derivationOrigin=this.config?.derivationOrigin||l()}}catch{}if(this.pnp=new Ne(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(a=>{if(!!!(a&&(a.connected===!0||a.principal||a.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:e}}))}catch{}let o=U(this.pnp,a),l=this.pnp?.getEvmProvider?.(),d=this.pnp?.getSolanaProvider?.();this.config={...this.config,connectedWallet:o,actorProvider:(p,h)=>this.pnp.getActor({canisterId:p,idl:h,requiresSigning:!0,anon:!1}),...l?{evmProvider:l}:{},...d?{solanaProvider:d}:{}},this.sdk=null,this.walletModalStep="balances",this.showBalanceModal=!1,this.showWalletModal=!0,this.fetchAndShowBalances()}).catch(a=>{this.errorMessage=a instanceof Error?a.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.walletModalStep="balances",this.showBalanceModal=!1;let e=u(this.config),{balances:t}=await X({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,a=t?.event_id||t?.eventId||t?.id;if(!(!a||typeof a!="string")&&a==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let n=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(n||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=Number(this.amountUsd),a=await e.startOnrampUsd(t,void 0,{context:"amount-input:onramp",onrampPayment:!0,onrampProvider:this?.selectedOnrampProvider||"coinbase"}),n=a?.metadata?.onramp?.url||a?.onramp?.url||a?.metadata?.icpay_onramp?.url||a?.paymentIntent?.metadata?.icpay?.onrampUrl||a?.metadata?.icpay?.onrampUrl||null,o=a?.metadata?.icpay_payment_intent_id||a?.metadata?.paymentIntentId||a?.paymentIntentId||null,l=a?.metadata?.icpay_onramp?.errorMessage||a?.metadata?.onramp?.errorMessage||null;if(this.onrampPaymentIntentId=o,n){this.onrampUrl=n,this.onrampErrorMessage=null;try{window.open(n,"icpay_onramp","noopener,noreferrer");try{window.dispatchEvent(new CustomEvent("icpay-onramp-opened",{detail:{url:n}}))}catch{}}catch{}this.startOnrampPolling()}else this.onrampUrl=null,this.onrampErrorMessage=l||"Failed to obtain onramp sessionId",this.showOnrampModal=!0}catch(e){this.onrampUrl=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 a=u(this.config),n=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>n()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=a.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}async pay(){if(!(!Ve||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){_(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),z(t)&&(this.errorMessage=D(t),this.errorSeverity=K(t),this.errorAction=F(t))}});try{!this.config.useOwnWallet&&this.pnp&&(await this.pnp.disconnect?.(),this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0})}catch{}}finally{this.processing=!1}}}render(){if(!this.config)return xe`<div class="icpay-card icpay-section">Loading...</div>`;let e=this.config?.placeholder||"Enter amount in USD",a=(this.config?.buttonLabel||"Pay ${amount} with crypto").replace("{amount}",this.amountUsd?`${Number(this.amountUsd).toFixed(2)}`:"$0.00").replace("{symbol}",this.selectedSymbol||"ICP"),n=this.selectedSymbol||"ICP",l=this.config?.progressBar?.enabled!==!1;return xe`
|
|
2047
|
+
`],r([Pt({type:Object})],f.prototype,"config",2),r([M()],f.prototype,"selectedSymbol",2),r([M()],f.prototype,"processing",2),r([M()],f.prototype,"succeeded",2),r([M()],f.prototype,"errorMessage",2),r([M()],f.prototype,"errorSeverity",2),r([M()],f.prototype,"errorAction",2),r([M()],f.prototype,"walletConnected",2),r([M()],f.prototype,"pendingAction",2),r([M()],f.prototype,"showWalletModal",2),r([M()],f.prototype,"walletModalStep",2),r([M()],f.prototype,"showOnrampModal",2),r([M()],f.prototype,"onrampUrl",2),r([M()],f.prototype,"onrampPaymentIntentId",2),r([M()],f.prototype,"onrampErrorMessage",2),r([M()],f.prototype,"showProviderPicker",2),r([M()],f.prototype,"selectedOnrampProvider",2),r([M()],f.prototype,"oisyReadyToPay",2),r([M()],f.prototype,"oisySignerPreopened",2),r([M()],f.prototype,"skipDisconnectOnce",2),r([M()],f.prototype,"lastWalletId",2),r([M()],f.prototype,"showBalanceModal",2),r([M()],f.prototype,"balancesLoading",2),r([M()],f.prototype,"balancesError",2),r([M()],f.prototype,"walletBalances",2),f=r([Nt("icpay-pay-button")],f);import{LitElement as $t,html as fe,css as It}from"lit";import{customElement as Bt,property as Rt,state as C}from"lit/decorators.js";var Ve=typeof window<"u",Ne=null;function _t(i,l,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${l}`,e):console.log(`[ICPay Widget] ${l}`))}var k=class extends $t{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.walletModalStep="connect";this.showOnrampModal=!1;this.onrampUrl=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),a=this.selectedSymbol||"ICP";window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"pay",type:"sendUsd",amount:t,currency:a}}))}catch{}}catch{}};this.onSelectBalanceSymbol=async e=>{let t=(this.walletBalances||[]).find(n=>n?.tokenShortcode===e);if(t?.ledgerSymbol&&(this.selectedSymbol=t.ledgerSymbol),this.showBalanceModal=!1,this.showWalletModal=!1,B(this.lastWalletId)){let n=(this.walletBalances||[]).find(o=>o?.tokenShortcode===e),s=n?.chainId;V(s,{provider:this.pnp?.getEvmProvider?.()||this.config?.evmProvider,chainName:n?.chainName,rpcUrlPublic:n?.rpcUrlPublic,nativeSymbol:n?.ledgerSymbol,decimals:n?.decimals}).then(async()=>{try{let o=g(this.config),c=Number(this.amountUsd||0);if(n?.x402Accepts)try{await o.client.createPaymentX402Usd({usdAmount:c,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay_network:"evm",icpay_ledger_id:n?.ledgerId,icpay_context:"amount-input:x402"},recipientAddress:(this.config?.recipientAddresses||{})?.evm||"0x0000000000000000000000000000000000000000"}),this.showBalanceModal=!1;return}catch{}await o.client.createPaymentUsd({usdAmount:c,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay_network:"evm",icpay_ledger_id:n?.ledgerId},recipientAddress:(this.config?.recipientAddresses||{})?.evm||"0x0000000000000000000000000000000000000000"})}catch{}this.showBalanceModal=!1});return}let a=this.pendingAction;if(this.pendingAction=null,a==="pay")try{let n=(this.walletBalances||[]).find(m=>m?.tokenShortcode===e),s=g(this.config),o=Number(this.amountUsd||0),c=String(n?.ledgerName||n?.chainName||"").toLowerCase(),p=c.includes("sol"),h=c.includes("ic"),d=this.config?.recipientAddresses||{},y=p&&d.sol||d.ic;if(n?.x402Accepts)try{let m={...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:p?"sol":h?"ic":this.config?.icpay_network,icpay_ledger_id:n?.ledgerId,icpay_context:"amount-input:x402"}};await s.client.createPaymentX402Usd({usdAmount:o,tokenShortcode:n?.tokenShortcode,metadata:m,recipientAddress:y||""});return}catch{return}await s.client.createPaymentUsd({usdAmount:o,tokenShortcode:n?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"ic",icpay_ledger_id:n?.ledgerId}},recipientAddress:y||"0x0000000000000000000000000000000000000000"})}catch{}}}connectedCallback(){if(super.connectedCallback(),!!Ve){_t(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;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}this.walletModalStep!=="balances"&&(this.pendingAction=null,setTimeout(()=>{t==="pay"&&this.pay()},0))}}onInputChange(e){let t=Number(this.config?.stepUsd??.5),a=Math.max(0,Number(e.target.value||0)),n=Math.round(a/t)*t;this.amountUsd=Number(n.toFixed(2)),this.hasUserAmount=!0}selectSymbol(e){this.selectedSymbol=e}isValidAmount(){let e=Number(this.config?.minUsd??.5),t=this.config?.maxUsd!==void 0?Number(this.config.maxUsd):1/0;return this.amountUsd>=e&&this.amountUsd<=t}async ensureWallet(){if(this.config.useOwnWallet)return this.config.actorProvider?!0:(this.pendingAction="pay",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0})),!1);if(this.walletConnected)return!0;try{Ne||(Ne=(await import("./wallet-select-BEKXSS66.js")).WalletSelect);let e=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab),t={...this.config?.plugNPlay||{}},a=this.config?.recipientAddresses;if(a&&(a.ic||a.evm||a.sol)){let o=[];a.ic&&o.push("ic"),a.evm&&o.push("evm"),a.sol&&o.push("sol"),o.length&&(t.chainTypes=o)}else this.config?.chainTypes&&(t.chainTypes=this.config.chainTypes);let n=e?$(t):t;try{if(typeof window<"u"){let{resolveDerivationOrigin:o}=await import("./origin-44ZEXSX4.js");n.derivationOrigin=this.config?.derivationOrigin||o()}}catch{}if(this.pnp=new Ne(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(a=>{if(!!!(a&&(a.connected===!0||a.principal||a.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 s=U(this.pnp,a),o=this.pnp?.getEvmProvider?.(),c=this.pnp?.getSolanaProvider?.();this.config={...this.config,connectedWallet:s,actorProvider:(p,h)=>this.pnp.getActor({canisterId:p,idl:h,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{},...c?{solanaProvider:c}:{}},this.sdk=null,this.walletModalStep="balances",this.showBalanceModal=!1,this.showWalletModal=!0,this.fetchAndShowBalances()}).catch(a=>{this.errorMessage=a instanceof Error?a.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.walletModalStep="balances",this.showBalanceModal=!1;let e=g(this.config),{balances:t}=await X({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,a=t?.event_id||t?.eventId||t?.id;if(!(!a||typeof a!="string")&&a==="TRANSAK_ORDER_SUCCESSFUL"){if(this.detachTransakMessageListener(),this.onrampPollingActive)return;this.showOnrampModal=!1;let n=t?.data?.id||t?.id||t?.webhookData?.id||null;this.startOnrampPolling(n||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=Number(this.amountUsd),a=await e.startOnrampUsd(t,void 0,{context:"amount-input:onramp",onrampPayment:!0,onrampProvider:this?.selectedOnrampProvider||"coinbase"}),n=a?.metadata?.onramp?.url||a?.onramp?.url||a?.metadata?.icpay_onramp?.url||a?.paymentIntent?.metadata?.icpay?.onrampUrl||a?.metadata?.icpay?.onrampUrl||null,s=a?.metadata?.icpay_payment_intent_id||a?.metadata?.paymentIntentId||a?.paymentIntentId||null,o=a?.metadata?.icpay_onramp?.errorMessage||a?.metadata?.onramp?.errorMessage||null;if(this.onrampPaymentIntentId=s,n){this.onrampUrl=n,this.onrampErrorMessage=null;try{window.open(n,"icpay_onramp","noopener,noreferrer");try{window.dispatchEvent(new CustomEvent("icpay-onramp-opened",{detail:{url:n}}))}catch{}}catch{}this.startOnrampPolling()}else this.onrampUrl=null,this.onrampErrorMessage=o||"Failed to obtain onramp sessionId",this.showOnrampModal=!0}catch(e){this.onrampUrl=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 a=g(this.config),n=()=>{if(this.detachTransakMessageListener(),this.onrampNotifyController)try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null,this.onrampPollingActive=!1};try{window.addEventListener("icpay-sdk-transaction-completed",(()=>n()),{once:!0})}catch{}this.onrampPollingActive=!0,this.onrampNotifyController=a.notifyIntentUntilComplete(t,5e3,e),this.onrampPollTimer=1}async pay(){if(!(!Ve||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){_(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),z(t)&&(this.errorMessage=D(t),this.errorSeverity=j(t),this.errorAction=F(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 fe`<div class="icpay-card icpay-section">Loading...</div>`;let e=this.config?.placeholder||"Enter amount in USD",a=(this.config?.buttonLabel||"Pay ${amount} with crypto").replace("{amount}",this.amountUsd?`${Number(this.amountUsd).toFixed(2)}`:"$0.00").replace("{symbol}",this.selectedSymbol||"ICP"),n=this.selectedSymbol||"ICP",o=this.config?.progressBar?.enabled!==!1;return fe`
|
|
2006
2048
|
<div class="icpay-card icpay-section icpay-widget-base">
|
|
2007
|
-
${
|
|
2049
|
+
${o?fe`
|
|
2008
2050
|
<icpay-progress-bar
|
|
2009
2051
|
.debug=${!!this.config?.debug}
|
|
2010
2052
|
.theme=${this.config?.theme}
|
|
@@ -2017,7 +2059,7 @@ import{a as r}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var j=Xe`
|
|
|
2017
2059
|
<div class="top-row">
|
|
2018
2060
|
<div class="amount-field">
|
|
2019
2061
|
<span class="currency-prefix">$</span>
|
|
2020
|
-
<input type="number" min="0" step="${Number(this.config?.stepUsd??.5)}" .value=${String(this.amountUsd||"")} placeholder="${e}" @input=${
|
|
2062
|
+
<input type="number" min="0" step="${Number(this.config?.stepUsd??.5)}" .value=${String(this.amountUsd||"")} placeholder="${e}" @input=${c=>this.onInputChange(c)} />
|
|
2021
2063
|
</div>
|
|
2022
2064
|
${null}
|
|
2023
2065
|
</div>
|
|
@@ -2029,22 +2071,24 @@ import{a as r}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var j=Xe`
|
|
|
2029
2071
|
</div>
|
|
2030
2072
|
<div class="hint">Min: $${Number(this.config?.minUsd??.5).toFixed(2)}${this.config?.maxUsd?`, Max: $${Number(this.config.maxUsd).toFixed(2)}`:""}</div>
|
|
2031
2073
|
|
|
2032
|
-
${this.errorMessage?
|
|
2074
|
+
${this.errorMessage?fe`
|
|
2033
2075
|
<div class="error-message ${this.errorSeverity}" style="margin-top: 12px; padding: 8px 12px; border-radius: 6px; font-size: 14px; text-align: center;">
|
|
2034
2076
|
${this.errorMessage}
|
|
2035
|
-
${this.errorAction?
|
|
2077
|
+
${this.errorAction?fe`<button style="margin-left: 8px; padding: 4px 8px; background: transparent; border: 1px solid currentColor; border-radius: 4px; font-size: 12px; cursor: pointer;">${this.errorAction}</button>`:""}
|
|
2036
2078
|
</div>
|
|
2037
2079
|
`:""}
|
|
2038
|
-
${(()=>{let
|
|
2080
|
+
${(()=>{let c=this.pnp?.getEnabledWallets?.()||[],p=H(c),h=this.config?.theme?typeof this.config.theme=="string"?this.config.theme:this.config.theme.mode||"light":void 0;return G({visible:!!(this.showWalletModal&&this.pnp),wallets:p,isConnecting:!1,step:this.walletModalStep,balances:this.walletModalStep==="balances"?this.walletBalances:[],balancesLoading:this.walletModalStep==="balances"?this.balancesLoading:!1,balancesError:this.walletModalStep==="balances"?this.balancesError:null,onSelectBalance:d=>this.onSelectBalanceSymbol(d),onBack:()=>{this.walletModalStep="connect"},onSwitchAccount:()=>this.onSwitchAccount(null),onSelect:d=>this.connectWithWallet(d),onClose:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-cancelled",{detail:{reason:"user_cancelled"}}))}catch{}},onDismiss:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1},onCreditCard:this.config?.onramp?.enabled===!0&&this.config?.onrampDisabled!==!0?()=>this.startOnramp():void 0,creditCardLabel:this.config?.onramp?.creditCardLabel||"Pay with credit card",showCreditCard:this.config?.onramp?.enabled===!0&&this.config?.onrampDisabled!==!0,creditCardTooltip:(()=>{let y=Number(this.amountUsd||0);return y>0&&y<5&&this.config?.onramp?.enabled===!0&&this.config?.onrampDisabled!==!0?`Note: Minimum card amount is $5. You will pay about $${(5-y).toFixed(2)} more.`:null})(),oisyReadyToPay:this.oisyReadyToPay,onOisyPay:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1,this.pay()},theme:h})})()}
|
|
2039
2081
|
|
|
2040
|
-
${
|
|
2082
|
+
${(()=>{let c=this.config?.theme?typeof this.config.theme=="string"?this.config.theme:this.config.theme.mode||"light":void 0;return fe`
|
|
2083
|
+
${Q({visible:this.showBalanceModal,isLoading:this.balancesLoading,error:this.balancesError,balances:this.walletBalances,onSelect:p=>this.onSelectBalanceSymbol(p),onClose:()=>{this.showBalanceModal=!1},theme:c})}
|
|
2041
2084
|
|
|
2042
|
-
|
|
2085
|
+
${q({visible:this.showOnrampModal,url:this.onrampUrl||void 0,errorMessage:this.onrampErrorMessage||void 0,width:this.config?.onramp?.width,height:this.config?.onramp?.height,onClose:()=>{this.showOnrampModal=!1},onBack:()=>{this.showOnrampModal=!1,this.showWalletModal=!0},title:"Pay with credit card",theme:c})}
|
|
2086
|
+
`})()}
|
|
2043
2087
|
<div class="icpay-powered-by">
|
|
2044
2088
|
<a href="https://icpay.org" target="_blank" rel="noopener noreferrer">Powered by icpay</a>
|
|
2045
2089
|
</div>
|
|
2046
2090
|
</div>
|
|
2047
|
-
`}};
|
|
2091
|
+
`}};k.styles=[K,It`
|
|
2048
2092
|
.row { display: grid; grid-template-columns: 1fr; gap: 12px; align-items: stretch; }
|
|
2049
2093
|
.top-row { display: grid; grid-template-columns: 1fr; gap: 10px; align-items: center; }
|
|
2050
2094
|
.top-row.with-selector { grid-template-columns: 1fr 2fr; }
|
|
@@ -2064,5 +2108,5 @@ import{a as r}from"./chunk-LTEQ7OUJ.js";import{css as Xe}from"lit";var j=Xe`
|
|
|
2064
2108
|
@media (max-width: 520px) {
|
|
2065
2109
|
.top-row { grid-template-columns: 1fr; }
|
|
2066
2110
|
}
|
|
2067
|
-
`],r([Rt({type:Object})],
|
|
2068
|
-
//# sourceMappingURL=chunk-
|
|
2111
|
+
`],r([Rt({type:Object})],k.prototype,"config",2),r([C()],k.prototype,"amountUsd",2),r([C()],k.prototype,"hasUserAmount",2),r([C()],k.prototype,"selectedSymbol",2),r([C()],k.prototype,"processing",2),r([C()],k.prototype,"succeeded",2),r([C()],k.prototype,"errorMessage",2),r([C()],k.prototype,"errorSeverity",2),r([C()],k.prototype,"errorAction",2),r([C()],k.prototype,"walletConnected",2),r([C()],k.prototype,"pendingAction",2),r([C()],k.prototype,"showWalletModal",2),r([C()],k.prototype,"walletModalStep",2),r([C()],k.prototype,"showOnrampModal",2),r([C()],k.prototype,"onrampUrl",2),r([C()],k.prototype,"onrampPaymentIntentId",2),r([C()],k.prototype,"onrampErrorMessage",2),r([C()],k.prototype,"oisyReadyToPay",2),r([C()],k.prototype,"lastWalletId",2),r([C()],k.prototype,"showBalanceModal",2),r([C()],k.prototype,"balancesLoading",2),r([C()],k.prototype,"balancesError",2),r([C()],k.prototype,"walletBalances",2),k=r([Bt("icpay-amount-input")],k);export{K as a,zt as b,oe as c,g as d,q as e,E as f,w as g,u as h,S as i,x as j,f as k,k as l};
|
|
2112
|
+
//# sourceMappingURL=chunk-5UZLVWIN.js.map
|