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