@ic-pay/icpay-widget 1.2.94 → 1.2.111
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/README.md +45 -17
- package/dist/{amount-input-DBc6rB3K.d.ts → amount-input-DlnLWkeX.d.ts} +170 -0
- package/dist/chunk-QEOLHVOE.js +2 -0
- package/dist/chunk-QEOLHVOE.js.map +1 -0
- package/dist/chunk-RCWWBMN4.js +2112 -0
- package/dist/chunk-RCWWBMN4.js.map +1 -0
- package/dist/index.d.ts +14 -2
- package/dist/index.js +1 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/react/index.js +1 -1
- package/dist/wallet-select-VE5FSSFG.js +2 -0
- package/package.json +14 -3
- package/dist/chunk-WVNSOAVU.js +0 -2
- package/dist/chunk-WVNSOAVU.js.map +0 -1
- package/dist/chunk-Z7MZQN3H.js +0 -2112
- package/dist/chunk-Z7MZQN3H.js.map +0 -1
- package/dist/wallet-select-BEKXSS66.js +0 -2
- /package/dist/{wallet-select-BEKXSS66.js.map → wallet-select-VE5FSSFG.js.map} +0 -0
package/dist/chunk-Z7MZQN3H.js
DELETED
|
@@ -1,2112 +0,0 @@
|
|
|
1
|
-
import{a as s}from"./chunk-LTEQ7OUJ.js";import{css as Ye}from"lit";var K=Ye`
|
|
2
|
-
:host {
|
|
3
|
-
/* Light mode defaults (from COLOR_PALETTE.md) */
|
|
4
|
-
--icpay-background: #ffffff;
|
|
5
|
-
--icpay-foreground: #171717;
|
|
6
|
-
--icpay-muted-foreground: #6b7280;
|
|
7
|
-
--icpay-accent-foreground: #ffffff;
|
|
8
|
-
--icpay-primary: #3b82f6;
|
|
9
|
-
--icpay-destructive: #ef4444;
|
|
10
|
-
--icpay-primary-foreground: #ffffff;
|
|
11
|
-
--icpay-secondary: #f3f4f6;
|
|
12
|
-
--icpay-secondary-foreground: #171717;
|
|
13
|
-
--icpay-accent: #f9fafb;
|
|
14
|
-
--icpay-muted: #f9fafb;
|
|
15
|
-
--icpay-border: #e5e7eb;
|
|
16
|
-
--icpay-input: #e5e7eb;
|
|
17
|
-
--icpay-ring: #3b82f6;
|
|
18
|
-
--icpay-destructive-foreground: #ffffff;
|
|
19
|
-
|
|
20
|
-
/* Status colors */
|
|
21
|
-
--icpay-success-bg: rgba(16, 185, 129, 0.1);
|
|
22
|
-
--icpay-success-text: #059669;
|
|
23
|
-
--icpay-success-border: rgba(16, 185, 129, 0.3);
|
|
24
|
-
--icpay-warning-bg: rgba(245, 158, 11, 0.1);
|
|
25
|
-
--icpay-warning-text: #d97706;
|
|
26
|
-
--icpay-warning-border: rgba(245, 158, 11, 0.3);
|
|
27
|
-
--icpay-error-bg: rgba(239, 68, 68, 0.1);
|
|
28
|
-
--icpay-error-text: #dc2626;
|
|
29
|
-
--icpay-error-border: rgba(239, 68, 68, 0.3);
|
|
30
|
-
--icpay-processing-bg: rgba(59, 130, 246, 0.1);
|
|
31
|
-
--icpay-processing-text: #2563eb;
|
|
32
|
-
--icpay-processing-border: rgba(59, 130, 246, 0.3);
|
|
33
|
-
|
|
34
|
-
/* Legacy compatibility variables */
|
|
35
|
-
--icpay-text: var(--icpay-foreground);
|
|
36
|
-
--icpay-surface: transparent;
|
|
37
|
-
--icpay-surface-alt: var(--icpay-secondary);
|
|
38
|
-
--icpay-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
39
|
-
|
|
40
|
-
display: block;
|
|
41
|
-
font-family: var(--icpay-font);
|
|
42
|
-
color: var(--icpay-foreground);
|
|
43
|
-
background: transparent;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
:host([data-theme="dark"]) {
|
|
47
|
-
/* Dark mode (from COLOR_PALETTE.md) */
|
|
48
|
-
--icpay-background: hsl(222.2 84% 4.9%);
|
|
49
|
-
--icpay-foreground: hsl(210 40% 98%);
|
|
50
|
-
--icpay-muted-foreground: hsl(215 20.2% 65.1%);
|
|
51
|
-
--icpay-accent-foreground: hsl(210 40% 98%);
|
|
52
|
-
--icpay-primary: hsl(210 40% 98%);
|
|
53
|
-
--icpay-destructive: hsl(0 62.8% 30.6%);
|
|
54
|
-
--icpay-primary-foreground: hsl(222.2 47.4% 11.2%);
|
|
55
|
-
--icpay-secondary: hsl(217.2 32.6% 17.5%);
|
|
56
|
-
--icpay-secondary-foreground: hsl(210 40% 98%);
|
|
57
|
-
--icpay-accent: hsl(217.2 32.6% 17.5%);
|
|
58
|
-
--icpay-muted: hsl(217.2 32.6% 17.5%);
|
|
59
|
-
--icpay-border: hsl(217.2 32.6% 30%);
|
|
60
|
-
--icpay-input: hsl(217.2 32.6% 17.5%);
|
|
61
|
-
--icpay-ring: hsl(210 40% 98%);
|
|
62
|
-
--icpay-destructive-foreground: hsl(210 40% 98%);
|
|
63
|
-
|
|
64
|
-
/* Status colors for dark mode */
|
|
65
|
-
--icpay-success-bg: rgba(16, 185, 129, 0.1);
|
|
66
|
-
--icpay-success-text: #34d399;
|
|
67
|
-
--icpay-success-border: rgba(16, 185, 129, 0.3);
|
|
68
|
-
--icpay-warning-bg: rgba(245, 158, 11, 0.1);
|
|
69
|
-
--icpay-warning-text: #fbbf24;
|
|
70
|
-
--icpay-warning-border: rgba(245, 158, 11, 0.3);
|
|
71
|
-
--icpay-error-bg: rgba(239, 68, 68, 0.1);
|
|
72
|
-
--icpay-error-text: #f87171;
|
|
73
|
-
--icpay-error-border: rgba(239, 68, 68, 0.3);
|
|
74
|
-
--icpay-processing-bg: rgba(59, 130, 246, 0.1);
|
|
75
|
-
--icpay-processing-text: #60a5fa;
|
|
76
|
-
--icpay-processing-border: rgba(59, 130, 246, 0.3);
|
|
77
|
-
|
|
78
|
-
--icpay-text: var(--icpay-foreground);
|
|
79
|
-
--icpay-surface-alt: var(--icpay-secondary);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
.icpay-card {
|
|
83
|
-
background: none;
|
|
84
|
-
border: none;
|
|
85
|
-
border-radius: 16px;
|
|
86
|
-
box-shadow: none;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
.icpay-section {
|
|
90
|
-
padding: 20px;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
.icpay-powered-by {
|
|
94
|
-
margin-top: 12px;
|
|
95
|
-
text-align: center;
|
|
96
|
-
font-size: 10px;
|
|
97
|
-
color: var(--icpay-muted-foreground);
|
|
98
|
-
opacity: 0.6;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
.icpay-powered-by a {
|
|
102
|
-
color: var(--icpay-muted-foreground);
|
|
103
|
-
text-decoration: none;
|
|
104
|
-
transition: opacity 0.2s ease;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
.icpay-powered-by a:hover {
|
|
108
|
-
opacity: 1;
|
|
109
|
-
text-decoration: underline;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
.pay-button {
|
|
113
|
-
width: 100%;
|
|
114
|
-
background: var(--icpay-foreground);
|
|
115
|
-
color: var(--icpay-background);
|
|
116
|
-
border: none;
|
|
117
|
-
border-radius: 16px;
|
|
118
|
-
padding: 16px;
|
|
119
|
-
font-size: 16px;
|
|
120
|
-
font-weight: 600;
|
|
121
|
-
cursor: pointer;
|
|
122
|
-
transition: all 0.3s ease;
|
|
123
|
-
box-shadow: none;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
:host([data-theme="dark"]) .pay-button {
|
|
127
|
-
border: 1px solid var(--icpay-border);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
.pay-button:hover {
|
|
131
|
-
background: color-mix(in srgb, var(--icpay-foreground) 90%, transparent);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
.pay-button.processing {
|
|
135
|
-
background: var(--icpay-muted-foreground);
|
|
136
|
-
color: var(--icpay-background);
|
|
137
|
-
border-color: var(--icpay-muted-foreground);
|
|
138
|
-
cursor: not-allowed;
|
|
139
|
-
animation: pulse 2s infinite;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
@keyframes pulse {
|
|
143
|
-
0%, 100% { opacity: 1; }
|
|
144
|
-
50% { opacity: 0.7; }
|
|
145
|
-
}
|
|
146
|
-
`;function qt(i){return typeof i=="string"?i:i&&typeof i=="object"&&i.mode?i.mode:"light"}function ce(i,c){if(!i)return;let e=null,t="light";if(typeof c=="string")t=c,e={mode:t};else if(c&&typeof c=="object")e=c,t=c.mode||"light";else if(typeof document<"u"){let a=document.documentElement.getAttribute("data-icpay-theme")||document.documentElement.getAttribute("data-theme");(a==="light"||a==="dark")&&(t=a)}if(i instanceof HTMLElement&&i.setAttribute("data-theme",t),typeof document<"u"&&document.documentElement&&(document.documentElement.setAttribute("data-icpay-theme",t),document.documentElement.style.setProperty("--icpay-theme-mode",t)),!e)return;let n=(a,r)=>{r&&i.style.setProperty(a,r)};e.primaryColor&&n("--icpay-primary",e.primaryColor),e.secondaryColor&&n("--icpay-secondary",e.secondaryColor),e.accentColor&&n("--icpay-accent",e.accentColor),e.textColor&&n("--icpay-foreground",e.textColor),e.mutedTextColor&&n("--icpay-muted-foreground",e.mutedTextColor),e.surfaceColor&&n("--icpay-background",e.surfaceColor),e.surfaceAltColor&&n("--icpay-secondary",e.surfaceAltColor),e.borderColor&&n("--icpay-border",e.borderColor),e.fontFamily&&n("--icpay-font",e.fontFamily),e.textColor&&n("--icpay-text",e.textColor),e.mutedTextColor&&n("--icpay-muted",e.mutedTextColor),e.surfaceAltColor&&n("--icpay-surface-alt",e.surfaceAltColor)}import{Icpay as Be}from"@ic-pay/icpay-sdk";var Ie=typeof window<"u";function le(i,c,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${c}`,e):console.log(`[ICPay Widget] ${c}`))}function x(i){if(!Ie)return{client:{},quoteUsd:async()=>({tokenAmountDecimals:"0"}),sendUsd:async()=>({transactionId:"0",status:"pending"}),startOnrampUsd:async()=>({transactionId:"0",status:"pending",metadata:{icpay_onramp:{sessionId:null}}}),notifyIntentUntilComplete:()=>({stop:()=>{}})};le(i.debug||!1,"Creating SDK with config:",i);let c={publishableKey:i.publishableKey};i.enableEvents!==void 0?c.enableEvents=i.enableEvents:c.enableEvents=!0,i.apiUrl&&(c.apiUrl=i.apiUrl),i.icHost&&(c.icHost=i.icHost),i.actorProvider&&(c.actorProvider=i.actorProvider),i.connectedWallet&&(c.connectedWallet=i.connectedWallet),i.evmProvider&&(c.evmProvider=i.evmProvider),i.solanaProvider&&(c.solanaProvider=i.solanaProvider),i.onrampDisabled!==void 0&&(c.onrampDisabled=i.onrampDisabled),i.debug!==void 0&&(c.debug=i.debug),le(i.debug||!1,"Filtered SDK config:",c);try{let o=function(l,p,h){return t.notifyPaymentIntentOnRamp({paymentIntentId:l,intervalMs:p,orderId:h})};var e=o;le(i.debug||!1,"typeof Icpay:",typeof Be);let t=new Be(c);if(Ie){let l=t,p=h=>{l.addEventListener(h,d=>{window.dispatchEvent(new CustomEvent(h,{detail:d?.detail??d}))})};["icpay-sdk-error","icpay-sdk-transaction-created","icpay-sdk-transaction-updated","icpay-sdk-transaction-completed","icpay-sdk-transaction-failed","icpay-sdk-method-start","icpay-sdk-method-success","icpay-sdk-method-error"].forEach(p)}async function n(l,p,h){if(typeof p=="string"&&p.trim().length>0)return t.calculateTokenAmountFromUSD({usdAmount:l,tokenShortcode:p.toLowerCase()});if(typeof h=="string"&&h.trim().length>0)return t.calculateTokenAmountFromUSD({usdAmount:l,ledgerCanisterId:h});throw new Error("quoteUsd requires tokenShortcode or ledgerCanisterId")}async function a(l,p,h,d){let y={...i.metadata,...h||{}};i.externalCostAmount!=null&&y.externalCostAmount==null&&(y.externalCostAmount=i.externalCostAmount);let m=`Pay ${l} with crypto`,w=i.description||y.__description||y.description||m,J={usdAmount:l,metadata:y,description:w,recipientAddresses:i.recipientAddresses,recipientAddress:i.recipientAddress};if(typeof p=="string"&&p.trim().length>0&&(J.tokenShortcode=p.toLowerCase()),typeof d=="string"&&d.trim().length>0&&(J.ledgerCanisterId=d),!J.tokenShortcode&&!J.ledgerCanisterId)throw new Error("sendUsd requires tokenShortcode or ledgerCanisterId");return le(!!i.debug,"Calling createPaymentUsd (flow decision handled by components)",J),t.createPaymentUsd(J)}async function r(l,p,h){let d={...i.metadata,...h||{}},y=`Pay ${l} with crypto`,m=i.description||d.__description||d.description||y;return le(!!i.debug,"Calling onramp createPaymentUsd",{usdAmount:l,ledgerCanisterId:p,description:m}),t.createPaymentUsd({usdAmount:l,ledgerCanisterId:p,metadata:d,onrampPayment:!0,description:m,recipientAddresses:i.recipientAddresses,recipientAddress:""})}return{client:t,quoteUsd:n,sendUsd:a,startOnrampUsd:r,notifyIntentUntilComplete:o}}catch(t){throw le(i.debug||!1,"Error creating SDK:",t),t}}import{LitElement as Ze,html as F,css as Je}from"lit";import{customElement as et,property as ne,state as j}from"lit/decorators.js";import{IcpayError as Re}from"@ic-pay/icpay-sdk";var ee={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"},Ge={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 g(i,c=Ge){i instanceof Re?(c.onError(i),i.isUserCancelled()?c.onUserCancelled?.():i.isBalanceError()?c.onInsufficientBalance?.(i):i.isWalletError()?c.onWalletError?.(i):i.isNetworkError()&&c.onNetworkError?.(i)):(console.error("[ICPay Widget] Unknown error:",i),c.onError(new Re({code:ee.UNKNOWN_ERROR,message:i instanceof Error?i.message:"An unknown error occurred",details:i})))}var Qe={[ee.WALLET_NOT_CONNECTED]:"Please connect your wallet to continue",[ee.WALLET_USER_CANCELLED]:"User have rejected the transfer",[ee.WALLET_SIGNATURE_REJECTED]:"User have rejected the transfer",[ee.INSUFFICIENT_BALANCE]:"Insufficient balance for this transaction",[ee.NETWORK_ERROR]:"Network error. Please try again",[ee.API_ERROR]:"Service temporarily unavailable",[ee.LEDGER_NOT_FOUND]:"Selected token is not supported",[ee.TRANSACTION_FAILED]:"Transaction failed. Please try again",[ee.TRANSACTION_TIMEOUT]:"Transaction timed out. Please try again",[ee.UNKNOWN_ERROR]:"Something went wrong. Please try again"};function u(i){let c=i?.details||{},e=typeof c?.data?.message=="string"?c.data.message:void 0,t=typeof c?.message=="string"?c.message:void 0,n=e||t;if(n&&n.length>0){if(n.startsWith("missing_required_fields:")){let o=(n.split(":")[1]||"").split(",").map(l=>l.trim()).filter(Boolean);return o.length?`Missing required: ${o.join(", ")}`:"Missing required fields"}let a=n.match(/^Missing required fields:\s*(.+)$/i);if(a&&a[1]){let r=a[1].split(",").map(o=>o.trim()).filter(Boolean);return r.length?`Missing required: ${r.join(", ")}`:"Missing required fields"}return n}return Qe[i.code]||i.message||"An error occurred"}function f(i){return!i.isUserCancelled()}function v(i){return null}function b(i){return i.isUserCancelled()?"info":i.isBalanceError()||i.isWalletError()?"warning":"error"}function S(i,c,e){i&&(e!==void 0?console.log(c,e):console.log(c))}var tt=[{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"}],M=class extends Ze{constructor(){super(...arguments);this.open=!1;this.suspended=!1;this.steps=tt;this.amount=0;this.currency="";this.ledgerSymbol="";this.debug=!1;this.activeIndex=0;this.completed=!1;this.failed=!1;this.errorMessage=null;this.showSuccess=!1;this.showConfetti=!1;this.currentSteps=[];this.currentAmount=0;this.currentCurrency="";this.currentLedgerSymbol="";this.confirmLoadingStartedAt=null;this.progressionTimer=null;this.currentWalletType=null;this.showWalletSelector=!1;this.isTransitioning=!1;this.isOnrampFlow=!1;this.onPaymentReset=()=>{this.stopAutomaticProgression(),this.open=!1,this.showWalletSelector=!1,this.isTransitioning=!1,this.activeIndex=0,this.completed=!1,this.failed=!1,this.errorMessage=null,this.showSuccess=!1,this.showConfetti=!1,this.isOnrampFlow=!1,this.currentSteps=[...this.steps].map(e=>({...e,status:"pending"})),this.requestUpdate()};this.onMethodStart=e=>{let t=e?.detail?.name||"",n=e?.detail?.type||"";if(S(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"){this.isOnrampFlow=!0;let a={wallet:{label:"Payment initiated",tooltip:"Please pay in the new tab"},await:{label:"Onramp process started",tooltip:"Verifying funds with provider"},transfer:{label:"Funds received",tooltip:"Payment in progress"},verify:{label:"Payment completed",tooltip:"Finalizing your payment"}};this.currentSteps=this.currentSteps.map(r=>a[r.key]?{...r,label:a[r.key].label,tooltip:a[r.key].tooltip}:r)}this.setLoadingByKey("wallet"),e?.detail?.amount!==void 0&&(this.currentAmount=e.detail.amount,this.amount=e.detail.amount,S(this.debug,"ICPay Progress: Amount updated to:",e.detail.amount)),e?.detail?.currency&&(this.currentCurrency=e.detail.currency,this.currency=e.detail.currency,S(this.debug,"ICPay Progress: Currency updated to:",e.detail.currency)),e?.detail?.ledgerSymbol&&(this.currentLedgerSymbol=e.detail.ledgerSymbol,this.ledgerSymbol=e.detail.ledgerSymbol,S(this.debug,"ICPay Progress: Current state after method start:",{activeIndex:this.activeIndex,currentAmount:this.currentAmount,currentCurrency:this.currentCurrency,currentLedgerSymbol:this.currentLedgerSymbol})),S(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")):t==="settleX402"&&(this.completeByKey("wallet"),this.completeByKey("await"),this.setLoadingByKey("transfer")))};this.onMethodSuccess=e=>{let t=e?.detail?.name||"";if((t==="createPayment"||t==="createPaymentUsd"||t==="sendUsd"||t==="pay"||t==="unlock"||t==="tip"||t==="donate"||t==="order")&&this.dispatchEvent(new CustomEvent("icpay-progress-method-success",{detail:{methodName:t,step:this.activeIndex},bubbles:!0})),!this.failed&&!this.completed){if(this.isOnrampFlow)return;t==="getLedgerBalance"?(this.completeByKey("wallet"),this.setLoadingByKey("await")):t==="sendFundsToLedger"?(this.completeByKey("wallet"),this.completeByKey("await"),this.completeByKey("transfer"),this.setLoadingByKey("verify")):t==="notifyLedgerTransaction"?(this.completeByKey("wallet"),this.completeByKey("await"),this.completeByKey("transfer"),this.setLoadingByKey("verify")):t==="createPaymentX402Usd"&&(this.completeByKey("wallet"),this.completeByKey("await"),this.completeByKey("transfer"),this.setLoadingByKey("verify"))}};this.onTransactionCreated=e=>{let t=e?.detail?.transactionId||e?.detail?.id;if(S(this.debug,"ICPay Progress: Transaction created event received:",e.detail),!this.failed&&!this.completed){if(this.isOnrampFlow)return;this.completeByKey("wallet"),this.completeByKey("await"),this.setLoadingByKey("transfer")}this.dispatchEvent(new CustomEvent("icpay-progress-transaction-created",{detail:{transactionId:t,step:this.activeIndex},bubbles:!0}))};this.onTransactionUpdated=e=>{let t=e?.detail?.status||"pending",n=e?.detail?.transactionId||e?.detail?.id,a=e?.detail?.metadata||e?.detail?.intent?.metadata||{};if(S(this.debug,"ICPay Progress: Transaction updated event received:",e.detail),!this.failed&&!this.completed&&this.isOnrampFlow){let r=a?.onramp_order_completed===!0||a?.icpay_onramp?.status==="completed"||a?.onrampCompleted===!0;t==="requires_payment"&&!r?(this.completeByKey("wallet"),this.setLoadingByKey("await")):(t==="pending"||t==="processing"||r)&&(this.completeByKey("wallet"),this.completeByKey("await"),this.setLoadingByKey("transfer"))}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";S(this.debug,"ICPay Progress: Transaction completed event received:",e.detail),S(this.debug,"ICPay Progress: Current state when transaction completed:",{activeIndex:this.activeIndex,completed:this.completed,failed:this.failed,showSuccess:this.showSuccess}),this.completeByKey("transfer"),this.completeByKey("await"),this.completeByKey("verify"),this.completed=!0,this.showSuccess=!0,this.showConfetti=!0,this.isOnrampFlow=!1,this.dispatchEvent(new CustomEvent("icpay-progress-completed",{detail:{transactionId:t,status: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?.error,n=e?.detail?.message||e?.detail?.error?.message||"Transaction failed",a=t?u(t):this.transformErrorMessage(n),r=e?.detail?.error?.code||e?.detail?.code||"UNKNOWN_ERROR",o=e?.detail?.transactionId||e?.detail?.id;S(this.debug,"ICPay Progress: Transaction failed event received:",e.detail),this.failed=!0,this.errorMessage=this.preferSpecificError(this.errorMessage,a),this.showSuccess=!1,this.updateStepStatus(this.activeIndex,"error",this.errorMessage),this.stopAutomaticProgression(),this.open=!0,this.isOnrampFlow=!1,this.dispatchEvent(new CustomEvent("icpay-progress-failed",{detail:{errorMessage:this.errorMessage,errorCode:r,transactionId:o,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.isOnrampFlow=!1,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,a=e?.detail?.message||n&&n.message||"An error occurred",r=n?u(n):this.transformErrorMessage(a),o=e?.detail?.error?.code||e?.detail?.code||"METHOD_ERROR";S(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.preferSpecificError(this.errorMessage,r),this.showSuccess=!1,this.updateStepStatus(this.activeIndex,"error",this.errorMessage),this.stopAutomaticProgression(),this.open=!0,this.isOnrampFlow=!1,this.dispatchEvent(new CustomEvent("icpay-progress-error",{detail:{methodName:t,errorMessage:this.errorMessage,errorCode:o,step:this.activeIndex},bubbles:!0})))};this.onSDKError=e=>{let t=e?.detail?.error,n=e?.detail?.message||t&&t.message||"SDK error occurred",a=t?u(t):this.transformErrorMessage(n),r=e?.detail?.code||"SDK_ERROR";S(this.debug,"ICPay Progress: SDK error event received:",e.detail),this.failed=!0,this.errorMessage=this.preferSpecificError(this.errorMessage,a),this.showSuccess=!1,this.updateStepStatus(this.activeIndex,"error",this.errorMessage),this.stopAutomaticProgression(),this.open=!0,this.isOnrampFlow=!1,this.dispatchEvent(new CustomEvent("icpay-progress-sdk-error",{detail:{errorMessage:this.errorMessage,errorCode:r,step:this.activeIndex},bubbles:!0}))};this.onWalletConnected=e=>{let t=e?.detail?.walletType||"unknown";S(this.debug,"ICPay Progress: Wallet connected event received:",e.detail),this.completeByKey("wallet"),this.setLoadingByKey("await"),this.startTransitionToProgress(),this.dispatchEvent(new CustomEvent("icpay-progress-wallet-connected",{detail:{walletType:t,step:this.activeIndex},bubbles:!0})),this.currentWalletType=t};this.onOnrampOpened=e=>{!this.isOnrampFlow||this.failed||this.completed||(this.completeByKey("wallet"),this.setLoadingByKey("await"))};this.onWalletDisconnected=e=>{let t=e?.detail?.walletType||"unknown";S(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;S(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";S(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(S(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?.error||e?.detail,n=t&&t.message||e?.detail?.message||"Widget error occurred",a=t?u(t):this.transformErrorMessage(n),r=t&&t.code||e?.detail?.code||"WIDGET_ERROR";S(this.debug,"ICPay Progress: Widget error event received:",e.detail),this.failed=!0,this.errorMessage=this.preferSpecificError(this.errorMessage,a),this.showSuccess=!1,this.updateStepStatus(this.activeIndex,"error",this.errorMessage),this.stopAutomaticProgression(),this.open=!0,this.dispatchEvent(new CustomEvent("icpay-progress-widget-error",{detail:{errorMessage:this.errorMessage,errorCode:r,step:this.activeIndex},bubbles:!0}))};this.onWidgetUnlock=e=>{let t=e?.detail?.amount,n=e?.detail?.currency;if(S(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(S(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(S(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(S(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{let t=this.getStepIndexByKey("wallet"),n=this.getStepIndexByKey("await"),a=this.getStepIndexByKey("transfer"),r=this.getStepIndexByKey("verify"),o=this.currentSteps&&this.currentSteps.length>0&&this.currentSteps.some((h,d)=>t>=0&&d>t?h.status==="loading"||h.status==="completed":!1),p=(t>=0?this.currentSteps[t]:null)?.status==="completed";if(!o&&!p){this.open=!1,this.activeIndex=0,this.currentSteps=this.currentSteps.map(h=>({...h,status:"pending"})),this.requestUpdate();return}this.open=!0,t>=0&&(this.activeIndex=t,this.currentSteps[t]={...this.currentSteps[t],tooltip:"Wallet connection cancelled",status:"error"},this.requestUpdate())}catch{}};this.onWalletError=e=>{try{let t=e?.detail?.message||"Wallet error",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{ce(this,this.theme);let e="light";if(typeof this.theme=="string")e=this.theme;else if(this.theme&&typeof this.theme=="object"&&this.theme.mode)e=this.theme.mode;else if(typeof document<"u"){let t=document.documentElement.getAttribute("data-icpay-theme")||document.documentElement.getAttribute("data-theme");(t==="light"||t==="dark")&&(e=t)}this.setAttribute("data-theme",e)}catch{}this.currentSteps=[...this.steps],this.currentAmount=this.amount,this.currentCurrency=this.currency,this.currentLedgerSymbol=this.ledgerSymbol,this.attachSDKEventListeners()}disconnectedCallback(){super.disconnectedCallback(),this.detachSDKEventListeners(),this.stopAutomaticProgression()}updated(e){if(e.has("theme"))try{ce(this,this.theme);let t="light";if(typeof this.theme=="string")t=this.theme;else if(this.theme&&typeof this.theme=="object"&&this.theme.mode)t=this.theme.mode;else if(typeof document<"u"){let n=document.documentElement.getAttribute("data-icpay-theme")||document.documentElement.getAttribute("data-theme");(n==="light"||n==="dark")&&(t=n)}this.setAttribute("data-theme",t)}catch{}}attachSDKEventListeners(){window.addEventListener("icpay-sdk-method-start",this.onMethodStart),window.addEventListener("icpay-sdk-method-success",this.onMethodSuccess),window.addEventListener("icpay-sdk-method-error",this.onMethodError),window.addEventListener("icpay-sdk-wallet-cancelled",this.onWalletCancelled),window.addEventListener("icpay-sdk-wallet-error",this.onWalletError),window.addEventListener("icpay-sdk-transaction-created",this.onTransactionCreated),window.addEventListener("icpay-sdk-transaction-updated",this.onTransactionUpdated),window.addEventListener("icpay-sdk-transaction-completed",this.onTransactionCompleted),window.addEventListener("icpay-sdk-transaction-failed",this.onTransactionFailed),window.addEventListener("icpay-sdk-transaction-mismatched",this.onTransactionMismatched),window.addEventListener("icpay-onramp-opened",this.onOnrampOpened),window.addEventListener("icpay-sdk-error",this.onSDKError),window.addEventListener("icpay-sdk-wallet-connected",this.onWalletConnected),window.addEventListener("icpay-sdk-wallet-disconnected",this.onWalletDisconnected),window.addEventListener("icpay-sdk-balance-check",this.onBalanceCheck),window.addEventListener("icpay-sdk-ledger-verified",this.onLedgerVerified),window.addEventListener("icpay-pay",this.onWidgetPayment),window.addEventListener("icpay-error",this.onWidgetError),window.addEventListener("icpay-unlock",this.onWidgetUnlock),window.addEventListener("icpay-tip",this.onWidgetTip),window.addEventListener("icpay-donation",this.onWidgetDonation),window.addEventListener("icpay-coffee",this.onWidgetCoffee),window.addEventListener("icpay-payment-reset",this.onPaymentReset)}detachSDKEventListeners(){window.removeEventListener("icpay-sdk-method-start",this.onMethodStart),window.removeEventListener("icpay-sdk-method-success",this.onMethodSuccess),window.removeEventListener("icpay-sdk-method-error",this.onMethodError),window.removeEventListener("icpay-sdk-wallet-cancelled",this.onWalletCancelled),window.removeEventListener("icpay-sdk-wallet-error",this.onWalletError),window.removeEventListener("icpay-sdk-transaction-created",this.onTransactionCreated),window.removeEventListener("icpay-sdk-transaction-updated",this.onTransactionUpdated),window.removeEventListener("icpay-sdk-transaction-completed",this.onTransactionCompleted),window.removeEventListener("icpay-sdk-transaction-failed",this.onTransactionFailed),window.removeEventListener("icpay-sdk-transaction-mismatched",this.onTransactionMismatched),window.removeEventListener("icpay-onramp-opened",this.onOnrampOpened),window.removeEventListener("icpay-sdk-error",this.onSDKError),window.removeEventListener("icpay-sdk-wallet-connected",this.onWalletConnected),window.removeEventListener("icpay-sdk-wallet-disconnected",this.onWalletDisconnected),window.removeEventListener("icpay-sdk-balance-check",this.onBalanceCheck),window.removeEventListener("icpay-sdk-ledger-verified",this.onLedgerVerified),window.removeEventListener("icpay-pay",this.onWidgetPayment),window.removeEventListener("icpay-error",this.onWidgetError),window.removeEventListener("icpay-unlock",this.onWidgetUnlock),window.removeEventListener("icpay-tip",this.onWidgetTip),window.removeEventListener("icpay-donation",this.onWidgetDonation),window.removeEventListener("icpay-coffee",this.onWidgetCoffee),window.removeEventListener("icpay-payment-reset",this.onPaymentReset)}startAutomaticProgression(){this.progressionTimer&&clearInterval(this.progressionTimer),this.activeIndex=1,this.updateStepStatus(this.activeIndex,"loading"),S(this.debug,"ICPay Progress: Starting automatic progression from step:",this.activeIndex),this.progressionTimer=setInterval(()=>{if(this.failed||this.completed){this.stopAutomaticProgression();return}S(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"),S(this.debug,"ICPay Progress: Auto-progressed to step:",this.activeIndex)):(this.stopAutomaticProgression(),S(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&&S(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"?F`<div class="error-x">✕</div>`:F`<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}isGenericErrorText(e){if(!e)return!0;let t=e.toLowerCase();return t==="an error occurred"||t==="sdk error occurred"||t==="transaction failed"||t.includes("failed to create payment")||t.includes("wallet error")||t.includes("network error")}preferSpecificError(e,t){let n=this.transformErrorMessage(t||"");return e&&!this.isGenericErrorText(e)&&this.isGenericErrorText(n)?e:n}renderConfetti(){if(!this.showConfetti)return"";let e=Array.from({length:50},(n,a)=>a),t=["#0066FF","#ef4444","#10b981","#f59e0b","#8b5cf6"];return F`
|
|
147
|
-
<div class="confetti">
|
|
148
|
-
${e.map(n=>F`
|
|
149
|
-
<div
|
|
150
|
-
class="confetti-piece"
|
|
151
|
-
style="
|
|
152
|
-
left: ${Math.random()*100}%;
|
|
153
|
-
top: ${Math.random()*100}%;
|
|
154
|
-
background-color: ${t[Math.floor(Math.random()*t.length)]};
|
|
155
|
-
animation-delay: ${Math.random()*2}s;
|
|
156
|
-
animation-duration: ${2+Math.random()*2}s;
|
|
157
|
-
"
|
|
158
|
-
></div>
|
|
159
|
-
`)}
|
|
160
|
-
</div>
|
|
161
|
-
`}renderSuccessState(){let e=this.currentAmount||this.amount;return S(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}),F`
|
|
162
|
-
<div class="success-center">
|
|
163
|
-
<div class="success-container">
|
|
164
|
-
<div class="success-icon">
|
|
165
|
-
<svg fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
|
166
|
-
<path stroke-linecap="round" stroke-linejoin="round" d="M5 13l4 4L19 7" />
|
|
167
|
-
</svg>
|
|
168
|
-
</div>
|
|
169
|
-
<h2 class="success-title">Payment Complete!</h2>
|
|
170
|
-
<p class="success-message">Your payment of ${e} USD has been successfully processed.</p>
|
|
171
|
-
<div class="success-actions">
|
|
172
|
-
<button class="btn btn-primary" @click=${()=>{this.open=!1}}>Close</button>
|
|
173
|
-
</div>
|
|
174
|
-
</div>
|
|
175
|
-
</div>
|
|
176
|
-
`}renderErrorState(){return this.errorMessage?.includes("Insufficient balance")||!1?this.renderInsufficientFundsError():this.renderGenericError()}renderInsufficientFundsError(){let e=this.currentAmount||this.amount;return F`
|
|
177
|
-
<div class="insufficient-funds-container">
|
|
178
|
-
<div class="payment-summary">
|
|
179
|
-
<div class="payment-amount">Pay $${e} with crypto</div>
|
|
180
|
-
</div>
|
|
181
|
-
|
|
182
|
-
<div class="error-notification">
|
|
183
|
-
<div class="error-content">
|
|
184
|
-
<div class="error-icon-small">
|
|
185
|
-
<svg fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
|
186
|
-
<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" />
|
|
187
|
-
</svg>
|
|
188
|
-
</div>
|
|
189
|
-
<div class="error-text">Insufficient balance for this transaction</div>
|
|
190
|
-
</div>
|
|
191
|
-
</div>
|
|
192
|
-
|
|
193
|
-
<div class="error-actions">
|
|
194
|
-
<button class="btn btn-secondary" @click=${()=>this.requestSwitchAccount()} title="Switch to a different account">
|
|
195
|
-
<svg fill="none" viewBox="0 0 24 24" stroke="currentColor" style="width: 16px; height: 16px;">
|
|
196
|
-
<path stroke-linecap="round" stroke-linejoin="round" d="M8 7h12m0 0l-4-4m4 4l-4 4m0 6H4m0 0l4 4m-4-4l4-4" />
|
|
197
|
-
</svg>
|
|
198
|
-
Switch Account
|
|
199
|
-
</button>
|
|
200
|
-
<button class="btn btn-primary" @click=${()=>{this.open=!1}}>
|
|
201
|
-
<svg fill="none" viewBox="0 0 24 24" stroke="currentColor" style="width: 16px; height: 16px;">
|
|
202
|
-
<path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />
|
|
203
|
-
</svg>
|
|
204
|
-
Close
|
|
205
|
-
</button>
|
|
206
|
-
</div>
|
|
207
|
-
</div>
|
|
208
|
-
`}renderGenericError(){return F`
|
|
209
|
-
<div class="error-container">
|
|
210
|
-
<div class="error-icon-large">
|
|
211
|
-
<svg fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
|
212
|
-
<path stroke-linecap="round" stroke-linejoin="round" d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
|
|
213
|
-
</svg>
|
|
214
|
-
</div>
|
|
215
|
-
<h2 class="error-title">Transaction Failed</h2>
|
|
216
|
-
<p class="error-message-text">${this.errorMessage}</p>
|
|
217
|
-
<div class="error-actions">
|
|
218
|
-
<button class="btn btn-secondary" @click=${()=>this.requestSwitchAccount()} title="Switch to a different account">
|
|
219
|
-
<svg fill="none" viewBox="0 0 24 24" stroke="currentColor" style="width: 16px; height: 16px;">
|
|
220
|
-
<path stroke-linecap="round" stroke-linejoin="round" d="M8 7h12m0 0l-4-4m4 4l-4 4m0 6H4m0 0l4 4m-4-4l4-4" />
|
|
221
|
-
</svg>
|
|
222
|
-
Switch Account
|
|
223
|
-
</button>
|
|
224
|
-
<button class="btn btn-primary" @click=${()=>{this.open=!1}}>
|
|
225
|
-
<svg fill="none" viewBox="0 0 24 24" stroke="currentColor" style="width: 16px; height: 16px;">
|
|
226
|
-
<path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />
|
|
227
|
-
</svg>
|
|
228
|
-
Close
|
|
229
|
-
</button>
|
|
230
|
-
</div>
|
|
231
|
-
</div>
|
|
232
|
-
`}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():F`
|
|
233
|
-
<div class="progress-container">
|
|
234
|
-
<div class="progress-header">
|
|
235
|
-
<span class="progress-spacer"></span>
|
|
236
|
-
<h3 class="progress-title">Processing</h3>
|
|
237
|
-
</div>
|
|
238
|
-
${this.renderConfirmTip()}
|
|
239
|
-
<div class="progress-steps">
|
|
240
|
-
${this.currentSteps.map((e,t)=>F`
|
|
241
|
-
<div class="step ${t===this.activeIndex?"active":""} ${e.status==="completed"?"completed":""} ${e.status==="error"?"error":""}">
|
|
242
|
-
<div class="step-icon">
|
|
243
|
-
${this.getStepIcon(e)}
|
|
244
|
-
</div>
|
|
245
|
-
<div class="step-content">
|
|
246
|
-
<div class="step-title">${e.label}</div>
|
|
247
|
-
<div class="step-description">${e.tooltip}</div>
|
|
248
|
-
${e.status==="error"&&e.errorMessage?F`
|
|
249
|
-
<div class="step-error-message">${e.errorMessage}</div>
|
|
250
|
-
`:""}
|
|
251
|
-
</div>
|
|
252
|
-
</div>
|
|
253
|
-
`)}
|
|
254
|
-
</div>
|
|
255
|
-
</div>
|
|
256
|
-
`}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:F`<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 F`
|
|
257
|
-
<div class="step-item ${e.status}">
|
|
258
|
-
<div class="step-icon">
|
|
259
|
-
${this.getStepIcon(e)}
|
|
260
|
-
</div>
|
|
261
|
-
<div class="step-content">
|
|
262
|
-
<div class="step-title">
|
|
263
|
-
${e.status==="completed"?"COMPLETED":e.label}
|
|
264
|
-
</div>
|
|
265
|
-
${e.status==="completed"?F`
|
|
266
|
-
<div class="step-subtitle">
|
|
267
|
-
${e.timestamp} - ${e.tooltip}
|
|
268
|
-
</div>
|
|
269
|
-
`:e.status==="error"&&e.errorMessage?F`
|
|
270
|
-
<div class="step-error">${e.errorMessage}</div>
|
|
271
|
-
`:F`
|
|
272
|
-
<div class="step-subtitle">${e.tooltip}</div>
|
|
273
|
-
`}
|
|
274
|
-
</div>
|
|
275
|
-
</div>
|
|
276
|
-
`}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:F`
|
|
277
|
-
${this.open?F`
|
|
278
|
-
${this.renderConfetti()}
|
|
279
|
-
<div class="modal-overlay active">
|
|
280
|
-
<div class="modal-container">
|
|
281
|
-
${this.showSuccess?null:F`<button class="close-button" @click=${()=>this.closeProgress()} aria-label="Close" title="Close">✕</button>`}
|
|
282
|
-
<div class="modal-content ${this.isTransitioning?"transitioning":""}">
|
|
283
|
-
${this.renderProgressContent()}
|
|
284
|
-
</div>
|
|
285
|
-
</div>
|
|
286
|
-
</div>
|
|
287
|
-
`:null}
|
|
288
|
-
`}};M.styles=Je`
|
|
289
|
-
:host {
|
|
290
|
-
display: block;
|
|
291
|
-
font-family: var(--icpay-font, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif);
|
|
292
|
-
color: var(--icpay-foreground);
|
|
293
|
-
background: var(--icpay-background);
|
|
294
|
-
|
|
295
|
-
/* Theme-aware color variables - Light mode defaults */
|
|
296
|
-
--icpay-background: #ffffff;
|
|
297
|
-
--icpay-foreground: #171717;
|
|
298
|
-
--icpay-muted-foreground: #6b7280;
|
|
299
|
-
--icpay-accent-foreground: #ffffff;
|
|
300
|
-
--icpay-primary: #3b82f6;
|
|
301
|
-
--icpay-destructive: #ef4444;
|
|
302
|
-
--icpay-primary-foreground: #ffffff;
|
|
303
|
-
--icpay-secondary: #f3f4f6;
|
|
304
|
-
--icpay-secondary-foreground: #171717;
|
|
305
|
-
--icpay-accent: #f9fafb;
|
|
306
|
-
--icpay-muted: #f9fafb;
|
|
307
|
-
--icpay-border: #e5e7eb;
|
|
308
|
-
--icpay-input: #e5e7eb;
|
|
309
|
-
--icpay-ring: #3b82f6;
|
|
310
|
-
--icpay-destructive-foreground: #ffffff;
|
|
311
|
-
|
|
312
|
-
/* Status colors */
|
|
313
|
-
--icpay-success-bg: rgba(16, 185, 129, 0.1);
|
|
314
|
-
--icpay-success-text: #059669;
|
|
315
|
-
--icpay-success-border: rgba(16, 185, 129, 0.3);
|
|
316
|
-
--icpay-warning-bg: rgba(245, 158, 11, 0.1);
|
|
317
|
-
--icpay-warning-text: #d97706;
|
|
318
|
-
--icpay-warning-border: rgba(245, 158, 11, 0.3);
|
|
319
|
-
--icpay-error-bg: rgba(239, 68, 68, 0.1);
|
|
320
|
-
--icpay-error-text: #dc2626;
|
|
321
|
-
--icpay-error-border: rgba(239, 68, 68, 0.3);
|
|
322
|
-
--icpay-processing-bg: rgba(59, 130, 246, 0.1);
|
|
323
|
-
--icpay-processing-text: #2563eb;
|
|
324
|
-
--icpay-processing-border: rgba(59, 130, 246, 0.3);
|
|
325
|
-
|
|
326
|
-
/* Use new color palette variables */
|
|
327
|
-
--icpay-text-primary: var(--icpay-foreground);
|
|
328
|
-
--icpay-text-secondary: var(--icpay-muted-foreground);
|
|
329
|
-
--icpay-text-muted: var(--icpay-muted-foreground);
|
|
330
|
-
--icpay-bg-primary: var(--icpay-background);
|
|
331
|
-
--icpay-bg-secondary: var(--icpay-secondary);
|
|
332
|
-
--icpay-bg-secondary-hover: var(--icpay-accent);
|
|
333
|
-
--icpay-bg-success: var(--icpay-success-bg);
|
|
334
|
-
--icpay-bg-error: var(--icpay-error-bg);
|
|
335
|
-
--icpay-border-primary: var(--icpay-border);
|
|
336
|
-
--icpay-border-secondary: var(--icpay-border);
|
|
337
|
-
--icpay-border-success: var(--icpay-success-border);
|
|
338
|
-
--icpay-border-error: var(--icpay-error-border);
|
|
339
|
-
--icpay-accent-primary: var(--icpay-primary);
|
|
340
|
-
--icpay-accent-success: var(--icpay-success-text);
|
|
341
|
-
--icpay-accent-error: var(--icpay-error-text);
|
|
342
|
-
|
|
343
|
-
--icpay-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
|
|
344
|
-
--icpay-shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
|
|
345
|
-
--icpay-shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
|
|
346
|
-
--icpay-shadow-xl: 0 20px 25px rgba(0, 0, 0, 0.1);
|
|
347
|
-
|
|
348
|
-
--icpay-radius-sm: 6px;
|
|
349
|
-
--icpay-radius-md: 8px;
|
|
350
|
-
--icpay-radius-lg: 12px;
|
|
351
|
-
--icpay-radius-xl: 16px;
|
|
352
|
-
|
|
353
|
-
--icpay-spacing-xs: 4px;
|
|
354
|
-
--icpay-spacing-sm: 8px;
|
|
355
|
-
--icpay-spacing-md: 12px;
|
|
356
|
-
--icpay-spacing-lg: 16px;
|
|
357
|
-
--icpay-spacing-xl: 24px;
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
:host([data-theme="dark"]) {
|
|
361
|
-
/* Dark mode (from COLOR_PALETTE.md) */
|
|
362
|
-
--icpay-background: hsl(222.2 84% 4.9%);
|
|
363
|
-
--icpay-foreground: hsl(210 40% 98%);
|
|
364
|
-
--icpay-muted-foreground: hsl(215 20.2% 65.1%);
|
|
365
|
-
--icpay-accent-foreground: hsl(210 40% 98%);
|
|
366
|
-
--icpay-primary: hsl(210 40% 98%);
|
|
367
|
-
--icpay-destructive: hsl(0 62.8% 30.6%);
|
|
368
|
-
--icpay-primary-foreground: hsl(222.2 47.4% 11.2%);
|
|
369
|
-
--icpay-secondary: hsl(217.2 32.6% 17.5%);
|
|
370
|
-
--icpay-secondary-foreground: hsl(210 40% 98%);
|
|
371
|
-
--icpay-accent: hsl(217.2 32.6% 17.5%);
|
|
372
|
-
--icpay-muted: hsl(217.2 32.6% 17.5%);
|
|
373
|
-
--icpay-border: hsl(217.2 32.6% 30%);
|
|
374
|
-
--icpay-input: hsl(217.2 32.6% 17.5%);
|
|
375
|
-
--icpay-ring: hsl(210 40% 98%);
|
|
376
|
-
--icpay-destructive-foreground: hsl(210 40% 98%);
|
|
377
|
-
|
|
378
|
-
/* Status colors for dark mode */
|
|
379
|
-
--icpay-success-bg: rgba(16, 185, 129, 0.1);
|
|
380
|
-
--icpay-success-text: #34d399;
|
|
381
|
-
--icpay-success-border: rgba(16, 185, 129, 0.3);
|
|
382
|
-
--icpay-warning-bg: rgba(245, 158, 11, 0.1);
|
|
383
|
-
--icpay-warning-text: #fbbf24;
|
|
384
|
-
--icpay-warning-border: rgba(245, 158, 11, 0.3);
|
|
385
|
-
--icpay-error-bg: rgba(239, 68, 68, 0.1);
|
|
386
|
-
--icpay-error-text: #f87171;
|
|
387
|
-
--icpay-error-border: rgba(239, 68, 68, 0.3);
|
|
388
|
-
--icpay-processing-bg: rgba(59, 130, 246, 0.1);
|
|
389
|
-
--icpay-processing-text: #60a5fa;
|
|
390
|
-
--icpay-processing-border: rgba(59, 130, 246, 0.3);
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
.modal-overlay {
|
|
394
|
-
position: fixed !important;
|
|
395
|
-
top: 0 !important;
|
|
396
|
-
left: 0 !important;
|
|
397
|
-
right: 0 !important;
|
|
398
|
-
bottom: 0 !important;
|
|
399
|
-
background: rgba(0, 0, 0, 0.5);
|
|
400
|
-
backdrop-filter: blur(8px);
|
|
401
|
-
display: flex;
|
|
402
|
-
align-items: center;
|
|
403
|
-
justify-content: center;
|
|
404
|
-
z-index: 99999 !important;
|
|
405
|
-
opacity: 0;
|
|
406
|
-
visibility: hidden;
|
|
407
|
-
transition: opacity 0.3s ease, visibility 0.3s ease;
|
|
408
|
-
/* Ensure modal breaks out of any parent constraints */
|
|
409
|
-
transform: none !important;
|
|
410
|
-
will-change: opacity, visibility;
|
|
411
|
-
isolation: isolate;
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
@media (max-width: 768px) {
|
|
415
|
-
.modal-overlay {
|
|
416
|
-
align-items: flex-end;
|
|
417
|
-
justify-content: stretch;
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
.modal-content {
|
|
422
|
-
transition: opacity 0.4s ease, transform 0.4s ease;
|
|
423
|
-
opacity: 1;
|
|
424
|
-
transform: translateY(0);
|
|
425
|
-
flex: 1;
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
.modal-content.transitioning {
|
|
429
|
-
opacity: 0;
|
|
430
|
-
transform: translateY(20px);
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
.wallet-selector-container {
|
|
434
|
-
width: 100%;
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
.wallet-selector-title {
|
|
438
|
-
color: var(--icpay-text-primary);
|
|
439
|
-
margin: 0 48px var(--icpay-spacing-lg) 0;
|
|
440
|
-
font-size: 18px;
|
|
441
|
-
font-weight: 600;
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
.wallet-options {
|
|
445
|
-
display: flex;
|
|
446
|
-
flex-direction: column;
|
|
447
|
-
gap: var(--icpay-spacing-sm);
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
.wallet-option {
|
|
451
|
-
width: 100%;
|
|
452
|
-
padding: 12px 16px;
|
|
453
|
-
background: var(--icpay-secondary);
|
|
454
|
-
border: 1px solid var(--icpay-border);
|
|
455
|
-
border-radius: 8px;
|
|
456
|
-
display: flex;
|
|
457
|
-
align-items: center;
|
|
458
|
-
gap: 12px;
|
|
459
|
-
cursor: pointer;
|
|
460
|
-
transition: all 0.3s ease;
|
|
461
|
-
box-sizing: border-box;
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
.wallet-option:hover {
|
|
465
|
-
background: var(--icpay-accent);
|
|
466
|
-
border-color: var(--icpay-border);
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
.wallet-icon {
|
|
470
|
-
width: 48px;
|
|
471
|
-
height: 48px;
|
|
472
|
-
border-radius: 12px;
|
|
473
|
-
background: var(--icpay-primary);
|
|
474
|
-
display: flex;
|
|
475
|
-
align-items: center;
|
|
476
|
-
justify-content: center;
|
|
477
|
-
flex-shrink: 0;
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
.wallet-icon img {
|
|
481
|
-
width: 40px;
|
|
482
|
-
height: 40px;
|
|
483
|
-
object-fit: cover;
|
|
484
|
-
border-radius: 12px;
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
.wallet-icon-placeholder {
|
|
488
|
-
color: var(--icpay-primary-foreground);
|
|
489
|
-
font-size: 12px;
|
|
490
|
-
font-weight: bold;
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
.wallet-label {
|
|
494
|
-
font-weight: 500;
|
|
495
|
-
font-size: 14px;
|
|
496
|
-
color: var(--icpay-foreground);
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
.modal-overlay.active {
|
|
500
|
-
opacity: 1;
|
|
501
|
-
visibility: visible;
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
.modal-container {
|
|
505
|
-
background: var(--icpay-background);
|
|
506
|
-
border: 1px solid var(--icpay-border);
|
|
507
|
-
border-radius: 24px;
|
|
508
|
-
padding: 24px;
|
|
509
|
-
max-width: 420px;
|
|
510
|
-
width: 100%;
|
|
511
|
-
height: 460px;
|
|
512
|
-
box-shadow: var(--icpay-shadow-xl);
|
|
513
|
-
transform: translateY(20px);
|
|
514
|
-
transition: transform 0.3s ease;
|
|
515
|
-
position: relative;
|
|
516
|
-
display: flex;
|
|
517
|
-
flex-direction: column;
|
|
518
|
-
margin: auto;
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
@media (max-width: 768px) {
|
|
522
|
-
.modal-container {
|
|
523
|
-
max-width: 100%;
|
|
524
|
-
width: 100%;
|
|
525
|
-
height: 70vh;
|
|
526
|
-
max-height: 70vh;
|
|
527
|
-
border-radius: 24px 24px 0 0;
|
|
528
|
-
margin: 0;
|
|
529
|
-
transform: translateY(100%);
|
|
530
|
-
overflow: hidden;
|
|
531
|
-
display: flex;
|
|
532
|
-
flex-direction: column;
|
|
533
|
-
}
|
|
534
|
-
.modal-overlay.active .modal-container {
|
|
535
|
-
transform: translateY(0);
|
|
536
|
-
}
|
|
537
|
-
.progress-steps {
|
|
538
|
-
overflow-y: auto;
|
|
539
|
-
flex: 1;
|
|
540
|
-
min-height: 0;
|
|
541
|
-
}
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
.modal-overlay.active .modal-container {
|
|
545
|
-
transform: translateY(0);
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
.close-button {
|
|
549
|
-
position: absolute;
|
|
550
|
-
top: var(--icpay-spacing-lg);
|
|
551
|
-
right: var(--icpay-spacing-lg);
|
|
552
|
-
width: 32px;
|
|
553
|
-
height: 32px;
|
|
554
|
-
display: flex;
|
|
555
|
-
align-items: center;
|
|
556
|
-
justify-content: center;
|
|
557
|
-
color: var(--icpay-text-secondary);
|
|
558
|
-
cursor: pointer;
|
|
559
|
-
border: none;
|
|
560
|
-
background: transparent;
|
|
561
|
-
font-size: 20px;
|
|
562
|
-
transition: all 0.2s;
|
|
563
|
-
z-index: 10;
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
.close-button:hover {
|
|
567
|
-
color: var(--icpay-text-primary);
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
.progress-header {
|
|
571
|
-
display:flex;
|
|
572
|
-
align-items:center;
|
|
573
|
-
margin-bottom: 20px;
|
|
574
|
-
padding-bottom: 20px;
|
|
575
|
-
border-bottom: 1px solid var(--icpay-border);
|
|
576
|
-
flex-shrink: 0;
|
|
577
|
-
}
|
|
578
|
-
.progress-title {
|
|
579
|
-
font-size: 20px;
|
|
580
|
-
font-weight: 600;
|
|
581
|
-
margin: 0;
|
|
582
|
-
color: var(--icpay-foreground);
|
|
583
|
-
flex: 1;
|
|
584
|
-
text-align: center;
|
|
585
|
-
margin-right: 40px;
|
|
586
|
-
}
|
|
587
|
-
.progress-spacer { width:24px; display:inline-block; margin-right:16px; }
|
|
588
|
-
.progress-subtitle { color: var(--icpay-text-secondary); font-size: 14px; }
|
|
589
|
-
.progress-steps {
|
|
590
|
-
margin-bottom: var(--icpay-spacing-xl);
|
|
591
|
-
display: flex;
|
|
592
|
-
flex-direction: column;
|
|
593
|
-
gap: 24px;
|
|
594
|
-
overflow-y: auto;
|
|
595
|
-
flex: 1;
|
|
596
|
-
}
|
|
597
|
-
.step {
|
|
598
|
-
width: 100%;
|
|
599
|
-
padding: 16px;
|
|
600
|
-
background: var(--icpay-secondary);
|
|
601
|
-
border: none;
|
|
602
|
-
border-radius: 12px;
|
|
603
|
-
display: flex;
|
|
604
|
-
align-items: flex-start;
|
|
605
|
-
gap: 16px;
|
|
606
|
-
transition: all 0.3s ease;
|
|
607
|
-
cursor: default;
|
|
608
|
-
box-sizing: border-box;
|
|
609
|
-
}
|
|
610
|
-
.step.active {
|
|
611
|
-
background: var(--icpay-accent);
|
|
612
|
-
}
|
|
613
|
-
.step.completed {
|
|
614
|
-
opacity: 1;
|
|
615
|
-
background: var(--icpay-secondary);
|
|
616
|
-
}
|
|
617
|
-
|
|
618
|
-
.step.error {
|
|
619
|
-
opacity: 1;
|
|
620
|
-
background: var(--icpay-error-bg);
|
|
621
|
-
border: 1px solid var(--icpay-error-border);
|
|
622
|
-
}
|
|
623
|
-
.step-icon {
|
|
624
|
-
width: 40px;
|
|
625
|
-
height: 40px;
|
|
626
|
-
border-radius: 0;
|
|
627
|
-
background: transparent;
|
|
628
|
-
display: flex;
|
|
629
|
-
align-items: center;
|
|
630
|
-
justify-content: center;
|
|
631
|
-
transition: all 0.3s ease;
|
|
632
|
-
position: relative;
|
|
633
|
-
flex-shrink: 0;
|
|
634
|
-
}
|
|
635
|
-
.step.active .step-icon { }
|
|
636
|
-
.step.completed .step-icon { }
|
|
637
|
-
|
|
638
|
-
.step.error .step-icon { background: transparent; }
|
|
639
|
-
.step-icon svg {
|
|
640
|
-
width: 20px;
|
|
641
|
-
height: 20px;
|
|
642
|
-
stroke: var(--icpay-text-primary);
|
|
643
|
-
transition: stroke 0.3s ease;
|
|
644
|
-
}
|
|
645
|
-
.step-content {
|
|
646
|
-
flex: 1;
|
|
647
|
-
display: flex;
|
|
648
|
-
flex-direction: column;
|
|
649
|
-
gap: 0;
|
|
650
|
-
}
|
|
651
|
-
.step-title {
|
|
652
|
-
font-weight: 500;
|
|
653
|
-
font-size: 16px;
|
|
654
|
-
color: var(--icpay-foreground);
|
|
655
|
-
transition: color 0.3s ease;
|
|
656
|
-
margin: 0;
|
|
657
|
-
}
|
|
658
|
-
.step-description {
|
|
659
|
-
font-size: 14px;
|
|
660
|
-
color: var(--icpay-muted-foreground);
|
|
661
|
-
margin: 0;
|
|
662
|
-
}
|
|
663
|
-
|
|
664
|
-
.step-error-message {
|
|
665
|
-
font-size: 11px;
|
|
666
|
-
color: var(--icpay-error-text);
|
|
667
|
-
margin-top: 4px;
|
|
668
|
-
padding: 4px 8px;
|
|
669
|
-
background: var(--icpay-error-bg);
|
|
670
|
-
border-radius: 4px;
|
|
671
|
-
border-left: 3px solid var(--icpay-error-text);
|
|
672
|
-
}
|
|
673
|
-
/* Spinner exactly like in design: wrapper + ::before ring */
|
|
674
|
-
.spinner {
|
|
675
|
-
width: 40px;
|
|
676
|
-
height: 40px;
|
|
677
|
-
margin-right: 0;
|
|
678
|
-
position: relative;
|
|
679
|
-
flex-shrink: 0;
|
|
680
|
-
}
|
|
681
|
-
.spinner::before {
|
|
682
|
-
content: '';
|
|
683
|
-
position: absolute;
|
|
684
|
-
width: 100%;
|
|
685
|
-
height: 100%;
|
|
686
|
-
border: 3px solid var(--icpay-border);
|
|
687
|
-
border-top: 3px solid var(--icpay-primary);
|
|
688
|
-
border-radius: 50%;
|
|
689
|
-
animation: spin 1s linear infinite;
|
|
690
|
-
box-sizing: border-box;
|
|
691
|
-
}
|
|
692
|
-
/* Completed: replace ring with filled green circle + tick */
|
|
693
|
-
.step.completed .spinner::before { display: none; }
|
|
694
|
-
.step.completed .spinner::after {
|
|
695
|
-
content: '✓';
|
|
696
|
-
position: absolute;
|
|
697
|
-
top: 0;
|
|
698
|
-
left: 0;
|
|
699
|
-
width: 100%;
|
|
700
|
-
height: 100%;
|
|
701
|
-
background-color: var(--icpay-success-text);
|
|
702
|
-
border-radius: 50%;
|
|
703
|
-
display: flex;
|
|
704
|
-
align-items: center;
|
|
705
|
-
justify-content: center;
|
|
706
|
-
color: var(--icpay-background);
|
|
707
|
-
font-size: 24px;
|
|
708
|
-
font-weight: bold;
|
|
709
|
-
box-sizing: border-box;
|
|
710
|
-
}
|
|
711
|
-
|
|
712
|
-
/* Error icon (pastel red) like success's green circle */
|
|
713
|
-
.error-x {
|
|
714
|
-
width: 40px;
|
|
715
|
-
height: 40px;
|
|
716
|
-
border-radius: 50%;
|
|
717
|
-
background-color: var(--icpay-error-text);
|
|
718
|
-
display: flex;
|
|
719
|
-
align-items: center;
|
|
720
|
-
justify-content: center;
|
|
721
|
-
color: var(--icpay-background);
|
|
722
|
-
font-size: 20px;
|
|
723
|
-
font-weight: bold;
|
|
724
|
-
box-sizing: border-box;
|
|
725
|
-
}
|
|
726
|
-
|
|
727
|
-
/* Completed icon to match design proportions */
|
|
728
|
-
.complete-icon {
|
|
729
|
-
width: 40px;
|
|
730
|
-
height: 40px;
|
|
731
|
-
position: relative;
|
|
732
|
-
flex-shrink: 0;
|
|
733
|
-
display: flex;
|
|
734
|
-
align-items: center;
|
|
735
|
-
justify-content: center;
|
|
736
|
-
}
|
|
737
|
-
.complete-icon::before {
|
|
738
|
-
content: '';
|
|
739
|
-
position: absolute;
|
|
740
|
-
inset: 0;
|
|
741
|
-
border: 3px solid var(--icpay-border);
|
|
742
|
-
border-radius: 50%;
|
|
743
|
-
background: var(--icpay-secondary);
|
|
744
|
-
box-sizing: border-box;
|
|
745
|
-
}
|
|
746
|
-
.complete-icon svg {
|
|
747
|
-
position: relative;
|
|
748
|
-
width: 20px;
|
|
749
|
-
height: 20px;
|
|
750
|
-
stroke: var(--icpay-foreground);
|
|
751
|
-
display: block;
|
|
752
|
-
}
|
|
753
|
-
|
|
754
|
-
.error-container {
|
|
755
|
-
height: 100%;
|
|
756
|
-
display: flex;
|
|
757
|
-
align-items: center;
|
|
758
|
-
justify-content: center;
|
|
759
|
-
flex-direction: column;
|
|
760
|
-
text-align: center;
|
|
761
|
-
}
|
|
762
|
-
|
|
763
|
-
.error-icon-large {
|
|
764
|
-
width: 64px;
|
|
765
|
-
height: 64px;
|
|
766
|
-
margin: 0 auto var(--icpay-spacing-lg);
|
|
767
|
-
background: var(--icpay-error-text);
|
|
768
|
-
border-radius: var(--icpay-radius-xl);
|
|
769
|
-
display: flex;
|
|
770
|
-
align-items: center;
|
|
771
|
-
justify-content: center;
|
|
772
|
-
}
|
|
773
|
-
|
|
774
|
-
.error-icon-large svg {
|
|
775
|
-
width: 32px;
|
|
776
|
-
height: 32px;
|
|
777
|
-
stroke: var(--icpay-background);
|
|
778
|
-
stroke-width: 2;
|
|
779
|
-
}
|
|
780
|
-
|
|
781
|
-
.error-title {
|
|
782
|
-
font-size: 20px;
|
|
783
|
-
font-weight: 600;
|
|
784
|
-
margin-bottom: var(--icpay-spacing-sm);
|
|
785
|
-
color: var(--icpay-text-primary);
|
|
786
|
-
}
|
|
787
|
-
|
|
788
|
-
.error-message-text {
|
|
789
|
-
color: var(--icpay-text-secondary);
|
|
790
|
-
margin-bottom: var(--icpay-spacing-xl);
|
|
791
|
-
font-size: 14px;
|
|
792
|
-
}
|
|
793
|
-
|
|
794
|
-
.error-details {
|
|
795
|
-
background: var(--icpay-error-bg);
|
|
796
|
-
border: 1px solid var(--icpay-error-border);
|
|
797
|
-
border-radius: var(--icpay-radius-md);
|
|
798
|
-
padding: var(--icpay-spacing-lg);
|
|
799
|
-
margin-bottom: var(--icpay-spacing-xl);
|
|
800
|
-
text-align: left;
|
|
801
|
-
}
|
|
802
|
-
|
|
803
|
-
.error-detail-item {
|
|
804
|
-
display: flex;
|
|
805
|
-
justify-content: space-between;
|
|
806
|
-
align-items: center;
|
|
807
|
-
margin-bottom: var(--icpay-spacing-sm);
|
|
808
|
-
}
|
|
809
|
-
|
|
810
|
-
.error-detail-item:last-child {
|
|
811
|
-
margin-bottom: 0;
|
|
812
|
-
}
|
|
813
|
-
|
|
814
|
-
.error-detail-label {
|
|
815
|
-
font-size: 14px;
|
|
816
|
-
color: var(--icpay-text-secondary);
|
|
817
|
-
font-weight: 500;
|
|
818
|
-
}
|
|
819
|
-
|
|
820
|
-
.error-detail-value {
|
|
821
|
-
font-size: 14px;
|
|
822
|
-
color: var(--icpay-text-primary);
|
|
823
|
-
font-weight: 600;
|
|
824
|
-
}
|
|
825
|
-
|
|
826
|
-
.error-actions {
|
|
827
|
-
display: flex;
|
|
828
|
-
gap: var(--icpay-spacing-sm);
|
|
829
|
-
justify-content: center;
|
|
830
|
-
}
|
|
831
|
-
|
|
832
|
-
.insufficient-funds-container {
|
|
833
|
-
width: 100%;
|
|
834
|
-
}
|
|
835
|
-
|
|
836
|
-
.payment-summary {
|
|
837
|
-
background: var(--icpay-secondary);
|
|
838
|
-
border-radius: var(--icpay-radius-md);
|
|
839
|
-
padding: var(--icpay-spacing-lg);
|
|
840
|
-
margin-bottom: var(--icpay-spacing-lg);
|
|
841
|
-
text-align: center;
|
|
842
|
-
}
|
|
843
|
-
|
|
844
|
-
.payment-amount {
|
|
845
|
-
font-size: 16px;
|
|
846
|
-
font-weight: 600;
|
|
847
|
-
color: var(--icpay-text-primary);
|
|
848
|
-
}
|
|
849
|
-
|
|
850
|
-
.error-notification {
|
|
851
|
-
background: var(--icpay-warning-bg);
|
|
852
|
-
border: 1px solid var(--icpay-warning-border);
|
|
853
|
-
border-radius: var(--icpay-radius-md);
|
|
854
|
-
padding: var(--icpay-spacing-lg);
|
|
855
|
-
margin-bottom: var(--icpay-spacing-xl);
|
|
856
|
-
display: flex;
|
|
857
|
-
align-items: center;
|
|
858
|
-
justify-content: space-between;
|
|
859
|
-
gap: var(--icpay-spacing-lg);
|
|
860
|
-
}
|
|
861
|
-
|
|
862
|
-
.error-content {
|
|
863
|
-
display: flex;
|
|
864
|
-
align-items: center;
|
|
865
|
-
gap: var(--icpay-spacing-md);
|
|
866
|
-
flex: 1;
|
|
867
|
-
}
|
|
868
|
-
|
|
869
|
-
.error-icon-small {
|
|
870
|
-
width: 20px;
|
|
871
|
-
height: 20px;
|
|
872
|
-
color: var(--icpay-warning-text);
|
|
873
|
-
flex-shrink: 0;
|
|
874
|
-
}
|
|
875
|
-
|
|
876
|
-
.error-icon-small svg {
|
|
877
|
-
width: 100%;
|
|
878
|
-
height: 100%;
|
|
879
|
-
}
|
|
880
|
-
|
|
881
|
-
.error-text {
|
|
882
|
-
font-size: 14px;
|
|
883
|
-
font-weight: 500;
|
|
884
|
-
color: var(--icpay-warning-text);
|
|
885
|
-
}
|
|
886
|
-
|
|
887
|
-
.add-funds-btn {
|
|
888
|
-
background: var(--icpay-secondary);
|
|
889
|
-
border: 1px solid var(--icpay-border);
|
|
890
|
-
border-radius: var(--icpay-radius-sm);
|
|
891
|
-
padding: 8px 16px;
|
|
892
|
-
color: var(--icpay-foreground);
|
|
893
|
-
font-size: 14px;
|
|
894
|
-
font-weight: 500;
|
|
895
|
-
cursor: pointer;
|
|
896
|
-
transition: all 0.3s ease;
|
|
897
|
-
flex-shrink: 0;
|
|
898
|
-
}
|
|
899
|
-
|
|
900
|
-
.add-funds-btn:hover {
|
|
901
|
-
background: var(--icpay-accent);
|
|
902
|
-
border-color: var(--icpay-border);
|
|
903
|
-
}
|
|
904
|
-
|
|
905
|
-
.error-message {
|
|
906
|
-
display: flex;
|
|
907
|
-
align-items: flex-start;
|
|
908
|
-
gap: var(--icpay-spacing-md);
|
|
909
|
-
padding: var(--icpay-spacing-lg);
|
|
910
|
-
background: var(--icpay-bg-error);
|
|
911
|
-
border: 1px solid var(--icpay-border-error);
|
|
912
|
-
border-radius: var(--icpay-radius-md);
|
|
913
|
-
margin-top: var(--icpay-spacing-sm);
|
|
914
|
-
}
|
|
915
|
-
|
|
916
|
-
.error-icon {
|
|
917
|
-
flex-shrink: 0;
|
|
918
|
-
width: 20px;
|
|
919
|
-
height: 20px;
|
|
920
|
-
background: var(--icpay-accent-error);
|
|
921
|
-
border-radius: 50%;
|
|
922
|
-
display: flex;
|
|
923
|
-
align-items: center;
|
|
924
|
-
justify-content: center;
|
|
925
|
-
color: var(--icpay-text-primary);
|
|
926
|
-
font-size: 12px;
|
|
927
|
-
font-weight: bold;
|
|
928
|
-
}
|
|
929
|
-
|
|
930
|
-
.error-content h4 {
|
|
931
|
-
margin: 0 0 4px 0;
|
|
932
|
-
font-size: 14px;
|
|
933
|
-
font-weight: 600;
|
|
934
|
-
color: var(--icpay-text-primary);
|
|
935
|
-
}
|
|
936
|
-
|
|
937
|
-
.error-content p {
|
|
938
|
-
margin: 0;
|
|
939
|
-
font-size: 12px;
|
|
940
|
-
color: var(--icpay-error-text);
|
|
941
|
-
line-height: 1.4;
|
|
942
|
-
}
|
|
943
|
-
|
|
944
|
-
.success-container { text-align: center; }
|
|
945
|
-
.success-center {
|
|
946
|
-
height: 100%;
|
|
947
|
-
display: flex;
|
|
948
|
-
align-items: center;
|
|
949
|
-
justify-content: center;
|
|
950
|
-
}
|
|
951
|
-
.success-icon {
|
|
952
|
-
width: 64px;
|
|
953
|
-
height: 64px;
|
|
954
|
-
margin: 0 auto var(--icpay-spacing-lg);
|
|
955
|
-
background: var(--icpay-success-text);
|
|
956
|
-
border-radius: var(--icpay-radius-xl);
|
|
957
|
-
display: flex;
|
|
958
|
-
align-items: center;
|
|
959
|
-
justify-content: center;
|
|
960
|
-
}
|
|
961
|
-
.success-icon svg {
|
|
962
|
-
width: 32px;
|
|
963
|
-
height: 32px;
|
|
964
|
-
stroke: var(--icpay-background);
|
|
965
|
-
stroke-width: 2;
|
|
966
|
-
}
|
|
967
|
-
.success-title {
|
|
968
|
-
font-size: 20px;
|
|
969
|
-
font-weight: 600;
|
|
970
|
-
margin-bottom: var(--icpay-spacing-sm);
|
|
971
|
-
color: var(--icpay-foreground);
|
|
972
|
-
}
|
|
973
|
-
.success-message {
|
|
974
|
-
color: var(--icpay-muted-foreground);
|
|
975
|
-
margin-bottom: 20px;
|
|
976
|
-
font-size: 14px;
|
|
977
|
-
}
|
|
978
|
-
.success-actions {
|
|
979
|
-
display: flex;
|
|
980
|
-
gap: var(--icpay-spacing-sm);
|
|
981
|
-
justify-content: center;
|
|
982
|
-
}
|
|
983
|
-
.btn {
|
|
984
|
-
padding: 10px 20px;
|
|
985
|
-
border-radius: var(--icpay-radius-md);
|
|
986
|
-
font-size: 14px;
|
|
987
|
-
font-weight: 500;
|
|
988
|
-
cursor: pointer;
|
|
989
|
-
transition: all 0.3s ease;
|
|
990
|
-
text-decoration: none;
|
|
991
|
-
display: inline-flex;
|
|
992
|
-
align-items: center;
|
|
993
|
-
gap: var(--icpay-spacing-sm);
|
|
994
|
-
}
|
|
995
|
-
.btn-primary {
|
|
996
|
-
background: var(--icpay-primary);
|
|
997
|
-
color: var(--icpay-primary-foreground);
|
|
998
|
-
border: none;
|
|
999
|
-
}
|
|
1000
|
-
.btn-primary:hover {
|
|
1001
|
-
transform: translateY(-1px);
|
|
1002
|
-
opacity: 0.9;
|
|
1003
|
-
}
|
|
1004
|
-
.btn-secondary {
|
|
1005
|
-
background: transparent;
|
|
1006
|
-
color: var(--icpay-muted-foreground);
|
|
1007
|
-
border: 1px solid var(--icpay-border);
|
|
1008
|
-
}
|
|
1009
|
-
.btn-secondary:hover {
|
|
1010
|
-
background: var(--icpay-secondary);
|
|
1011
|
-
border-color: var(--icpay-border);
|
|
1012
|
-
color: var(--icpay-foreground);
|
|
1013
|
-
}
|
|
1014
|
-
|
|
1015
|
-
.confetti {
|
|
1016
|
-
position: fixed;
|
|
1017
|
-
top: 0;
|
|
1018
|
-
left: 0;
|
|
1019
|
-
width: 100%;
|
|
1020
|
-
height: 100%;
|
|
1021
|
-
pointer-events: none;
|
|
1022
|
-
z-index: 1001;
|
|
1023
|
-
}
|
|
1024
|
-
|
|
1025
|
-
.confetti-piece {
|
|
1026
|
-
position: absolute;
|
|
1027
|
-
width: 8px;
|
|
1028
|
-
height: 8px;
|
|
1029
|
-
background: var(--icpay-primary);
|
|
1030
|
-
animation: confetti-fall 3s linear forwards;
|
|
1031
|
-
}
|
|
1032
|
-
|
|
1033
|
-
@keyframes spin {
|
|
1034
|
-
from { transform: rotate(0deg); }
|
|
1035
|
-
to { transform: rotate(360deg); }
|
|
1036
|
-
}
|
|
1037
|
-
|
|
1038
|
-
/* legacy spinner removed; unified spinner defined above to match design */
|
|
1039
|
-
|
|
1040
|
-
@keyframes confetti-fall {
|
|
1041
|
-
0% {
|
|
1042
|
-
transform: translateY(-100vh) rotate(0deg);
|
|
1043
|
-
opacity: 1;
|
|
1044
|
-
}
|
|
1045
|
-
100% {
|
|
1046
|
-
transform: translateY(100vh) rotate(720deg);
|
|
1047
|
-
opacity: 0;
|
|
1048
|
-
}
|
|
1049
|
-
}
|
|
1050
|
-
`,s([ne({type:Boolean})],M.prototype,"open",2),s([ne({type:Boolean})],M.prototype,"suspended",2),s([ne({type:Array})],M.prototype,"steps",2),s([ne({type:Number})],M.prototype,"amount",2),s([ne({type:String})],M.prototype,"currency",2),s([ne({type:String})],M.prototype,"ledgerSymbol",2),s([ne({type:Boolean})],M.prototype,"debug",2),s([j()],M.prototype,"activeIndex",2),s([j()],M.prototype,"completed",2),s([j()],M.prototype,"failed",2),s([j()],M.prototype,"errorMessage",2),s([j()],M.prototype,"showSuccess",2),s([j()],M.prototype,"showConfetti",2),s([j()],M.prototype,"currentSteps",2),s([j()],M.prototype,"currentAmount",2),s([j()],M.prototype,"currentCurrency",2),s([j()],M.prototype,"currentLedgerSymbol",2),s([j()],M.prototype,"confirmLoadingStartedAt",2),s([j()],M.prototype,"currentWalletType",2),s([j()],M.prototype,"showWalletSelector",2),s([j()],M.prototype,"isTransitioning",2),s([j()],M.prototype,"isOnrampFlow",2),s([ne({type:Object})],M.prototype,"theme",2),M=s([et("icpay-progress-bar")],M);import{html as We}from"lit";function at(i){if(i==="light"||i==="dark")return i;if(typeof document>"u")return"light";let c=document.documentElement.getAttribute("data-icpay-theme");if(c==="light"||c==="dark")return c;let e=document.documentElement.getAttribute("data-theme");return e==="light"||e==="dark"?e:"light"}function q(i){if(!i.visible)return null;let c=i.width??420,e=i.height??680,t=typeof i.url=="string"&&(i.url||"").startsWith("http"),n=at(i.theme);return We`
|
|
1051
|
-
<style>
|
|
1052
|
-
/* Theme-aware color variables - Light mode defaults */
|
|
1053
|
-
.icpay-onramp-modal-overlay {
|
|
1054
|
-
--icpay-background: #ffffff;
|
|
1055
|
-
--icpay-foreground: #171717;
|
|
1056
|
-
--icpay-muted-foreground: #6b7280;
|
|
1057
|
-
--icpay-primary: #3b82f6;
|
|
1058
|
-
--icpay-primary-foreground: #ffffff;
|
|
1059
|
-
--icpay-secondary: #f3f4f6;
|
|
1060
|
-
--icpay-secondary-foreground: #171717;
|
|
1061
|
-
--icpay-accent: #f9fafb;
|
|
1062
|
-
--icpay-border: #e5e7eb;
|
|
1063
|
-
}
|
|
1064
|
-
/* Dark mode */
|
|
1065
|
-
[data-theme="dark"] .icpay-onramp-modal-overlay,
|
|
1066
|
-
[data-icpay-theme="dark"] .icpay-onramp-modal-overlay,
|
|
1067
|
-
:root[data-theme="dark"] .icpay-onramp-modal-overlay,
|
|
1068
|
-
:root[data-icpay-theme="dark"] .icpay-onramp-modal-overlay,
|
|
1069
|
-
html[data-theme="dark"] .icpay-onramp-modal-overlay,
|
|
1070
|
-
html[data-icpay-theme="dark"] .icpay-onramp-modal-overlay,
|
|
1071
|
-
.icpay-onramp-modal-overlay[data-theme="dark"] {
|
|
1072
|
-
--icpay-background: hsl(222.2 84% 4.9%);
|
|
1073
|
-
--icpay-foreground: hsl(210 40% 98%);
|
|
1074
|
-
--icpay-muted-foreground: hsl(215 20.2% 65.1%);
|
|
1075
|
-
--icpay-primary: hsl(210 40% 98%);
|
|
1076
|
-
--icpay-primary-foreground: hsl(222.2 47.4% 11.2%);
|
|
1077
|
-
--icpay-secondary: hsl(217.2 32.6% 17.5%);
|
|
1078
|
-
--icpay-secondary-foreground: hsl(210 40% 98%);
|
|
1079
|
-
--icpay-accent: hsl(217.2 32.6% 17.5%);
|
|
1080
|
-
--icpay-border: hsl(217.2 32.6% 30%);
|
|
1081
|
-
}
|
|
1082
|
-
.icpay-onramp-modal-overlay {
|
|
1083
|
-
position: fixed !important;
|
|
1084
|
-
inset: 0 !important;
|
|
1085
|
-
display: flex;
|
|
1086
|
-
align-items: center;
|
|
1087
|
-
justify-content: center;
|
|
1088
|
-
background: rgba(0,0,0,0.85);
|
|
1089
|
-
backdrop-filter: blur(10px);
|
|
1090
|
-
z-index: 99999 !important;
|
|
1091
|
-
/* Ensure modal breaks out of any parent constraints */
|
|
1092
|
-
transform: none !important;
|
|
1093
|
-
will-change: auto;
|
|
1094
|
-
isolation: isolate;
|
|
1095
|
-
}
|
|
1096
|
-
.icpay-onramp-modal-container {
|
|
1097
|
-
position: relative;
|
|
1098
|
-
background: var(--icpay-background);
|
|
1099
|
-
border: 1px solid var(--icpay-border);
|
|
1100
|
-
border-radius: 16px;
|
|
1101
|
-
padding: 16px;
|
|
1102
|
-
box-shadow: 0 20px 60px rgba(0,0,0,0.5);
|
|
1103
|
-
margin: auto;
|
|
1104
|
-
max-width: 90vw;
|
|
1105
|
-
}
|
|
1106
|
-
@media (max-width: 768px) {
|
|
1107
|
-
.icpay-onramp-modal-overlay {
|
|
1108
|
-
align-items: flex-end;
|
|
1109
|
-
justify-content: stretch;
|
|
1110
|
-
}
|
|
1111
|
-
.icpay-onramp-modal-container {
|
|
1112
|
-
max-width: 100%;
|
|
1113
|
-
width: 100%;
|
|
1114
|
-
height: 70vh;
|
|
1115
|
-
max-height: 70vh;
|
|
1116
|
-
border-radius: 16px 16px 0 0;
|
|
1117
|
-
margin: 0;
|
|
1118
|
-
overflow-y: auto;
|
|
1119
|
-
display: flex;
|
|
1120
|
-
flex-direction: column;
|
|
1121
|
-
}
|
|
1122
|
-
}
|
|
1123
|
-
</style>
|
|
1124
|
-
<div class="icpay-onramp-modal-overlay" data-theme="${n}">
|
|
1125
|
-
<div class="icpay-onramp-modal-container">
|
|
1126
|
-
<button @click=${i.onClose} style="position:absolute;right:12px;top:12px;background:transparent;border:none;color:var(--icpay-foreground);cursor:pointer;font-size:20px;opacity:0.8;z-index:10">×</button>
|
|
1127
|
-
${i.onBack?We`<button @click=${i.onBack} style="position:absolute;left:12px;top:12px;background:transparent;border:1px solid var(--icpay-border);color:var(--icpay-foreground);cursor:pointer;font-size:12px;border-radius:8px;padding:6px 10px;opacity:0.9;z-index:10">Back</button>`:null}
|
|
1128
|
-
<div style="color:var(--icpay-foreground);font-weight:600;font-size:15px;margin-bottom:12px">${i.title||"Complete purchase"}</div>
|
|
1129
|
-
${t?We`
|
|
1130
|
-
<iframe
|
|
1131
|
-
title="Onramp"
|
|
1132
|
-
src="${i.url}"
|
|
1133
|
-
style="border:0;width:${typeof c=="number"?`${c}px`:c};height:${typeof e=="number"?`${e}px`:e};border-radius:12px;background:#000"
|
|
1134
|
-
sandbox="allow-forms allow-same-origin allow-scripts allow-popups allow-top-navigation-by-user-activation"
|
|
1135
|
-
allow="payment *"
|
|
1136
|
-
></iframe>
|
|
1137
|
-
<div style="margin-top:10px;text-align:right">
|
|
1138
|
-
<a href="${i.url}" target="_blank" rel="noopener noreferrer" style="color:var(--icpay-primary);font-size:12px;text-decoration:underline">Open in a new tab</a>
|
|
1139
|
-
</div>
|
|
1140
|
-
`:We`
|
|
1141
|
-
<div style="width:${typeof c=="number"?`${c}px`:c};height:${typeof e=="number"?`${e}px`:e};display:flex;align-items:center;justify-content:center;background:var(--icpay-secondary);border:1px dashed var(--icpay-border);border-radius:12px;color:var(--icpay-foreground)">
|
|
1142
|
-
${i.errorMessage||"Onramp URL not available"}
|
|
1143
|
-
</div>
|
|
1144
|
-
`}
|
|
1145
|
-
</div>
|
|
1146
|
-
</div>
|
|
1147
|
-
`}import{LitElement as ut,html as ie,css as gt}from"lit";import{customElement as ft,property as vt,state as $}from"lit/decorators.js";import{html as te}from"lit";var _e=new Set(["metamask","walletconnect","coinbase","brave","rainbow","rabby","okx"]),nt=new Set(["phantom","backpack"]);function z(i){return i?_e.has(String(i).toLowerCase()):!1}function it(i){return i&&(i.id||i.provider||i.key)||""}function rt(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 H(i){return(i||[]).map(c=>({id:it(c),label:rt(c),icon:st(c)}))}async function V(i,c){try{let e=c?.provider||(typeof window<"u"?window.ethereum:null);if(!e||i===void 0||i===null)return!0;let t=typeof i=="number"?i:String(i).startsWith("0x")?parseInt(String(i),16):parseInt(String(i),10);if(!Number.isFinite(t))return!0;let n=await e.request({method:"eth_chainId"});if(parseInt(n,16)===t)return!0;let r="0x"+t.toString(16);return await e.request({method:"wallet_switchEthereumChain",params:[{chainId:r}]}),!0}catch{try{let t=c?.provider||(typeof window<"u"?window.ethereum:null);if(!t||i===void 0||i===null)return!1;let n=typeof i=="number"?i:String(i).startsWith("0x")?parseInt(String(i),16):parseInt(String(i),10),a="0x"+n.toString(16),r=c?.chainName||`Network ${n}`,o=(c?.rpcUrlPublic?[c.rpcUrlPublic]:[]).filter(Boolean),l={name:c?.nativeSymbol||"ETH",symbol:c?.nativeSymbol||"ETH",decimals:typeof c?.decimals=="number"&&isFinite(c.decimals)?c.decimals:18};return await t.request({method:"wallet_addEthereumChain",params:[{chainId:a,chainName:r,rpcUrls:o,nativeCurrency:l}]}),!0}catch{return!1}}}async function X(i){let{sdk:c,lastWalletId:e,connectedWallet:t,amountUsd:n,chainShortcodes:a,tokenShortcodes:r}=i,o,l=(e||"").toLowerCase(),p=(t?.owner||t?.principal||"").toString();try{l&&_e.has(l)?o=await c?.client?.getExternalWalletBalances?.({network:"evm",address:p,amountUsd:n,chainShortcodes:a,tokenShortcodes:r}):l&&nt.has(l)?o=await c?.client?.getExternalWalletBalances?.({network:"sol",address:p,amountUsd:n,chainShortcodes:a,tokenShortcodes:r}):o=await c?.client?.getExternalWalletBalances?.({network:"ic",principal:p,amountUsd:n,chainShortcodes:a,tokenShortcodes:r})}catch{o={balances:[],totalBalancesUSD:0,lastUpdated:new Date}}return{balances:(o?.balances||[]).map(d=>({ledgerId:d.ledgerId,ledgerName:d.ledgerName,ledgerSymbol:d.ledgerSymbol,tokenShortcode:d.tokenShortcode??d.shortcode??null,canisterId:d.canisterId,eip3009Version:d?.eip3009Version??null,x402Accepts:d?.x402Accepts!=null?!!d.x402Accepts:void 0,balance:d.balance,formattedBalance:d.formattedBalance,decimals:d.decimals,currentPrice:d.currentPrice,lastPriceUpdate:d.lastPriceUpdate?new Date(d.lastPriceUpdate):void 0,lastUpdated:d.lastUpdated?new Date(d.lastUpdated):new Date,chainId:typeof d.chainId=="string"?d.chainId:typeof d.chainId=="number"?String(d.chainId):void 0,chainName:d.chainName||d.chain&&(d.chain.name||d.chain.chainName)||d.networkName||void 0,rpcUrlPublic:d.rpcUrlPublic,chainUuid:d.chainUuid,requiredAmount:d.requiredAmount,requiredAmountFormatted:d.requiredAmountFormatted,hasSufficientBalance:d.hasSufficientBalance,logoUrl:d.logoUrl??null})),totalBalancesUSD:o?.totalBalancesUSD,lastUpdated:o?.lastUpdated?new Date(o.lastUpdated):new Date}}function Ae(i){let c=Number(i);if(!isFinite(c)||c===0)return"0";if(Math.abs(c)<1e-5)return"< 0.00001";let t=1e5;return(Math.trunc(c*t)/t).toFixed(5).replace(/\.0+$/,"").replace(/(\.[0-9]*?)0+$/,"$1")}import{html as Y}from"lit";function Pe(i){let c=parseFloat(String(i.formattedBalance||"0")),e=Number(i.currentPrice??0),t=(isFinite(c)?c:0)*(isFinite(e)?e:0);return isFinite(t)?t:0}var Fe=(i,c)=>Pe(c)-Pe(i);function Ce(){return Y`<style>
|
|
1148
|
-
/* Theme-aware color variables - Light mode defaults */
|
|
1149
|
-
.modal {
|
|
1150
|
-
--icpay-background: #ffffff;
|
|
1151
|
-
--icpay-foreground: #171717;
|
|
1152
|
-
--icpay-muted-foreground: #6b7280;
|
|
1153
|
-
--icpay-primary: #3b82f6;
|
|
1154
|
-
--icpay-primary-foreground: #ffffff;
|
|
1155
|
-
--icpay-secondary: #f3f4f6;
|
|
1156
|
-
--icpay-secondary-foreground: #171717;
|
|
1157
|
-
--icpay-accent: #f9fafb;
|
|
1158
|
-
--icpay-border: #e5e7eb;
|
|
1159
|
-
--icpay-error-text: #dc2626;
|
|
1160
|
-
}
|
|
1161
|
-
/* Dark mode */
|
|
1162
|
-
[data-theme="dark"] .modal,
|
|
1163
|
-
[data-icpay-theme="dark"] .modal,
|
|
1164
|
-
:root[data-theme="dark"] .modal,
|
|
1165
|
-
:root[data-icpay-theme="dark"] .modal,
|
|
1166
|
-
html[data-theme="dark"] .modal,
|
|
1167
|
-
html[data-icpay-theme="dark"] .modal,
|
|
1168
|
-
.modal[data-theme="dark"] {
|
|
1169
|
-
--icpay-background: hsl(222.2 84% 4.9%);
|
|
1170
|
-
--icpay-foreground: hsl(210 40% 98%);
|
|
1171
|
-
--icpay-muted-foreground: hsl(215 20.2% 65.1%);
|
|
1172
|
-
--icpay-primary: hsl(210 40% 98%);
|
|
1173
|
-
--icpay-primary-foreground: hsl(222.2 47.4% 11.2%);
|
|
1174
|
-
--icpay-secondary: hsl(217.2 32.6% 17.5%);
|
|
1175
|
-
--icpay-secondary-foreground: hsl(210 40% 98%);
|
|
1176
|
-
--icpay-accent: hsl(217.2 32.6% 17.5%);
|
|
1177
|
-
--icpay-border: hsl(217.2 32.6% 30%);
|
|
1178
|
-
--icpay-error-text: #f87171;
|
|
1179
|
-
}
|
|
1180
|
-
.modal { background-color:var(--icpay-background); border-radius:24px; width:100%; max-width:420px; padding:24px; color:var(--icpay-foreground); display:flex; flex-direction:column; border:1px solid var(--icpay-border); height:460px; margin:auto; transition:transform 0.3s ease; position:relative; z-index:1; }
|
|
1181
|
-
@media (max-width: 768px) {
|
|
1182
|
-
.modal { max-width:100%; width:100%; height:70vh; max-height:70vh; border-radius:24px 24px 0 0; margin:0; transform:translateY(100%); overflow:hidden; display:flex; flex-direction:column; }
|
|
1183
|
-
.currency-list { overflow-y:auto; flex:1; min-height:0; }
|
|
1184
|
-
.wallet-list { overflow-y:auto; flex:1; min-height:0; }
|
|
1185
|
-
}
|
|
1186
|
-
.header { display:flex; align-items:center; margin-bottom:20px; padding-bottom:20px; border-bottom:1px solid var(--icpay-border); flex-shrink:0; }
|
|
1187
|
-
.back-button { background:none; border:none; color:var(--icpay-foreground); font-size:24px; cursor:pointer; padding:0; margin-right:16px; }
|
|
1188
|
-
.title { font-size:20px; font-weight:600; flex:1; text-align:center; margin-right:40px; }
|
|
1189
|
-
.currency-list { display:flex; flex-direction:column; gap:0; overflow-y:auto; flex:1; margin-bottom:0; }
|
|
1190
|
-
.currency-item { display:flex; align-items:center; padding:16px 12px; cursor:pointer; transition:background-color 0.2s; border-radius:12px; }
|
|
1191
|
-
.currency-item:hover { background-color:var(--icpay-accent); }
|
|
1192
|
-
.currency-item[disabled] { opacity:0.6; cursor:not-allowed; }
|
|
1193
|
-
.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; }
|
|
1194
|
-
.eth-icon { background:linear-gradient(135deg,#627eea 0%, #8a9bff 100%); }
|
|
1195
|
-
.usdc-icon { background:linear-gradient(135deg,#2775ca 0%, #4da4ff 100%); }
|
|
1196
|
-
.usdt-icon { background:linear-gradient(135deg,#26a17b 0%, #50af95 100%); }
|
|
1197
|
-
.currency-info { flex:1; }
|
|
1198
|
-
.currency-name { font-size:16px; font-weight:500; margin-bottom:4px; }
|
|
1199
|
-
.currency-network { font-size:14px; color:var(--icpay-muted-foreground); }
|
|
1200
|
-
.currency-balance { text-align:right; }
|
|
1201
|
-
.balance-amount { font-size:16px; font-weight:500; margin-bottom:4px; }
|
|
1202
|
-
.balance-available { font-size:14px; color:var(--icpay-muted-foreground); }
|
|
1203
|
-
.footer { display:flex; justify-content:space-between; align-items:center; margin-top:16px; padding-top:16px; border-top:1px solid var(--icpay-border); flex-shrink:0; }
|
|
1204
|
-
.need-wallet { font-size:14px; color:var(--icpay-muted-foreground); }
|
|
1205
|
-
.get-started { font-size:14px; color:var(--icpay-primary); background:none; border:none; cursor:pointer; font-weight:500; }
|
|
1206
|
-
.get-started:hover { text-decoration:underline; }
|
|
1207
|
-
.muted { color:var(--icpay-muted-foreground); }
|
|
1208
|
-
</style>`}function Le(i){let c=e=>Ae(e);return Y`
|
|
1209
|
-
<div class="header">
|
|
1210
|
-
<button class="back-button" @click=${i.onBack}>‹</button>
|
|
1211
|
-
<h1 class="title">Pay with</h1>
|
|
1212
|
-
</div>
|
|
1213
|
-
${i.isLoading?Y`
|
|
1214
|
-
<div class="muted">Loading your balances…</div>
|
|
1215
|
-
`:i.error?Y`
|
|
1216
|
-
<div style="color:var(--icpay-error-text)">${i.error}</div>
|
|
1217
|
-
`:Y`
|
|
1218
|
-
<div class="currency-list">
|
|
1219
|
-
${(()=>{let e=(i.balances||[]).filter(t=>t.hasSufficientBalance===!0||t.hasSufficientBalance===void 0).sort(Fe);return e.length>0?Y`
|
|
1220
|
-
${e.map(t=>{let n=(t.ledgerSymbol||"").toUpperCase(),a=t.logoUrl?"":n==="ETH"?"eth-icon":n==="USDC"?"usdc-icon":n==="USDT"?"usdt-icon":"";return Y`
|
|
1221
|
-
<div class="currency-item" @click=${()=>i.onSelect(t.tokenShortcode||t.ledgerSymbol)}>
|
|
1222
|
-
<div class="currency-icon ${a}">
|
|
1223
|
-
${t.logoUrl?Y`<img src="${t.logoUrl}" alt="${n} logo" style="width:100%;height:100%;object-fit:fill" />`:Y`<span>${n.slice(0,1)}</span>`}
|
|
1224
|
-
</div>
|
|
1225
|
-
<div class="currency-info">
|
|
1226
|
-
<div class="currency-name">${t.ledgerName}</div>
|
|
1227
|
-
<div class="currency-network">${t.chainName||""}</div>
|
|
1228
|
-
</div>
|
|
1229
|
-
<div class="currency-balance">
|
|
1230
|
-
<div class="balance-amount">${c(t.formattedBalance)} ${n}</div>
|
|
1231
|
-
<div class="balance-available">$${Pe(t).toFixed(2)}</div>
|
|
1232
|
-
</div>
|
|
1233
|
-
</div>
|
|
1234
|
-
`})}
|
|
1235
|
-
`:Y`<div class="muted" style="margin-bottom:8px">You have no balances on verified tokens.</div>`})()}
|
|
1236
|
-
|
|
1237
|
-
${(()=>{let e=(i.balances||[]).filter(t=>t.hasSufficientBalance===!1).sort(Fe);return e.length>0?Y`
|
|
1238
|
-
${e.map(t=>{let n=(t.ledgerSymbol||"").toUpperCase(),a=t.logoUrl?"":n==="ETH"?"eth-icon":n==="USDC"?"usdc-icon":n==="USDT"?"usdt-icon":"";return Y`
|
|
1239
|
-
<div class="currency-item" disabled title="Insufficient balance">
|
|
1240
|
-
<div class="currency-icon ${a}">
|
|
1241
|
-
${t.logoUrl?Y`<img src="${t.logoUrl}" alt="${n} logo" style="width:100%;height:100%;object-fit:fill" />`:Y`<span>${n.slice(0,1)}</span>`}
|
|
1242
|
-
</div>
|
|
1243
|
-
<div class="currency-info">
|
|
1244
|
-
<div class="currency-name">${t.ledgerName}</div>
|
|
1245
|
-
<div class="currency-network">${t.chainName||""}</div>
|
|
1246
|
-
</div>
|
|
1247
|
-
<div class="currency-balance">
|
|
1248
|
-
<div class="balance-amount">need ${t.requiredAmountFormatted||"--"}</div>
|
|
1249
|
-
<div class="balance-available">${c(t.formattedBalance)} ${n} available</div>
|
|
1250
|
-
</div>
|
|
1251
|
-
</div>
|
|
1252
|
-
`})}
|
|
1253
|
-
`:null})()}
|
|
1254
|
-
</div>
|
|
1255
|
-
`}
|
|
1256
|
-
<div class="footer">
|
|
1257
|
-
<span class="need-wallet">Need a wallet?</span>
|
|
1258
|
-
<button class="get-started" @click=${()=>{try{window.open("https://internetcomputer.org/wallets","_blank","noopener,noreferrer")}catch{}}}>Get started</button>
|
|
1259
|
-
</div>
|
|
1260
|
-
`}function ot(i){if(i==="light"||i==="dark")return i;if(typeof document>"u")return"light";let c=document.documentElement.getAttribute("data-icpay-theme");if(c==="light"||c==="dark")return c;let e=document.documentElement.getAttribute("data-theme");return e==="light"||e==="dark"?e:"light"}function ct(i){return!i||!i.startsWith("data:")?i:i.replace(/\s+/g,"")}function lt(i,c){let e=(i||"").toLowerCase();return e==="ii"?"Internet Identity":e==="nfid"?"NFID":e==="plug"?"Plug":e==="oisy"?"Oisy":c&&c.trim()?c:i?i.charAt(0).toUpperCase()+i.slice(1):"Wallet"}function G(i){if(!i.visible)return null;let{wallets:c,onSelect:e,onClose:t,isConnecting:n}=i,a=d=>Ae(d),r=d=>{let y=parseFloat(String(d.formattedBalance||"0")),m=Number(d.currentPrice??0),w=(isFinite(y)?y:0)*(isFinite(m)?m:0);return isFinite(w)?w:0},o=(d,y)=>r(y)-r(d),l=c.map(d=>{let y=(d.id||"").toLowerCase();return{...d,icon:d.icon??null}}),p=ot(i.theme);return te`
|
|
1261
|
-
<div class="icpay-modal-overlay" data-theme="${p}" @click=${d=>{d.target===d.currentTarget&&(d.preventDefault(),d.stopPropagation(),i.onDismiss?i.onDismiss():i.onClose())}} style="position:fixed !important;inset:0 !important;display:flex;align-items:center;justify-content:center;background:rgba(0,0,0,0.5);z-index:99999 !important;transform:none !important;">
|
|
1262
|
-
<style>
|
|
1263
|
-
.icpay-w-8 { width: 2rem; }
|
|
1264
|
-
.icpay-h-8 { height: 2rem; }
|
|
1265
|
-
/* Theme-aware color variables - Light mode defaults */
|
|
1266
|
-
.icpay-modal-overlay {
|
|
1267
|
-
--icpay-background: #ffffff;
|
|
1268
|
-
--icpay-foreground: #171717;
|
|
1269
|
-
--icpay-muted-foreground: #6b7280;
|
|
1270
|
-
--icpay-primary: #3b82f6;
|
|
1271
|
-
--icpay-primary-foreground: #ffffff;
|
|
1272
|
-
--icpay-secondary: #f3f4f6;
|
|
1273
|
-
--icpay-secondary-foreground: #171717;
|
|
1274
|
-
--icpay-accent: #f9fafb;
|
|
1275
|
-
--icpay-border: #e5e7eb;
|
|
1276
|
-
--icpay-success-bg: rgba(16, 185, 129, 0.1);
|
|
1277
|
-
--icpay-success-text: #059669;
|
|
1278
|
-
--icpay-success-border: rgba(16, 185, 129, 0.3);
|
|
1279
|
-
--icpay-warning-bg: rgba(245, 158, 11, 0.1);
|
|
1280
|
-
--icpay-warning-text: #d97706;
|
|
1281
|
-
--icpay-warning-border: rgba(245, 158, 11, 0.3);
|
|
1282
|
-
--icpay-error-bg: rgba(239, 68, 68, 0.1);
|
|
1283
|
-
--icpay-error-text: #dc2626;
|
|
1284
|
-
--icpay-error-border: rgba(239, 68, 68, 0.3);
|
|
1285
|
-
--icpay-processing-bg: rgba(59, 130, 246, 0.1);
|
|
1286
|
-
--icpay-processing-text: #2563eb;
|
|
1287
|
-
--icpay-processing-border: rgba(59, 130, 246, 0.3);
|
|
1288
|
-
}
|
|
1289
|
-
/* Dark mode - check for data-theme on any ancestor or document */
|
|
1290
|
-
[data-theme="dark"] .icpay-modal-overlay,
|
|
1291
|
-
[data-icpay-theme="dark"] .icpay-modal-overlay,
|
|
1292
|
-
:root[data-theme="dark"] .icpay-modal-overlay,
|
|
1293
|
-
:root[data-icpay-theme="dark"] .icpay-modal-overlay,
|
|
1294
|
-
html[data-theme="dark"] .icpay-modal-overlay,
|
|
1295
|
-
html[data-icpay-theme="dark"] .icpay-modal-overlay,
|
|
1296
|
-
.icpay-modal-overlay[data-theme="dark"] {
|
|
1297
|
-
--icpay-background: hsl(222.2 84% 4.9%);
|
|
1298
|
-
--icpay-foreground: hsl(210 40% 98%);
|
|
1299
|
-
--icpay-muted-foreground: hsl(215 20.2% 65.1%);
|
|
1300
|
-
--icpay-primary: hsl(210 40% 98%);
|
|
1301
|
-
--icpay-primary-foreground: hsl(222.2 47.4% 11.2%);
|
|
1302
|
-
--icpay-secondary: hsl(217.2 32.6% 17.5%);
|
|
1303
|
-
--icpay-secondary-foreground: hsl(210 40% 98%);
|
|
1304
|
-
--icpay-accent: hsl(217.2 32.6% 17.5%);
|
|
1305
|
-
--icpay-border: hsla(217.2 32.6% 30% / 0.15);
|
|
1306
|
-
--icpay-success-bg: rgba(16, 185, 129, 0.1);
|
|
1307
|
-
--icpay-success-text: #34d399;
|
|
1308
|
-
--icpay-success-border: rgba(16, 185, 129, 0.3);
|
|
1309
|
-
--icpay-warning-bg: rgba(245, 158, 11, 0.1);
|
|
1310
|
-
--icpay-warning-text: #fbbf24;
|
|
1311
|
-
--icpay-warning-border: rgba(245, 158, 11, 0.3);
|
|
1312
|
-
--icpay-error-bg: rgba(239, 68, 68, 0.1);
|
|
1313
|
-
--icpay-error-text: #f87171;
|
|
1314
|
-
--icpay-error-border: rgba(239, 68, 68, 0.3);
|
|
1315
|
-
--icpay-processing-bg: rgba(59, 130, 246, 0.1);
|
|
1316
|
-
--icpay-processing-text: #60a5fa;
|
|
1317
|
-
--icpay-processing-border: rgba(59, 130, 246, 0.3);
|
|
1318
|
-
}
|
|
1319
|
-
/* New design styles (scoped) */
|
|
1320
|
-
.icpay-modal-overlay {
|
|
1321
|
-
position: fixed !important;
|
|
1322
|
-
inset: 0 !important;
|
|
1323
|
-
display: flex;
|
|
1324
|
-
align-items: center;
|
|
1325
|
-
justify-content: center;
|
|
1326
|
-
background: rgba(0,0,0,0.5);
|
|
1327
|
-
z-index: 99999 !important;
|
|
1328
|
-
/* Ensure modal breaks out of any parent constraints */
|
|
1329
|
-
transform: none !important;
|
|
1330
|
-
will-change: auto;
|
|
1331
|
-
isolation: isolate;
|
|
1332
|
-
}
|
|
1333
|
-
@media (max-width: 768px) {
|
|
1334
|
-
.icpay-modal-overlay {
|
|
1335
|
-
align-items: flex-end;
|
|
1336
|
-
justify-content: stretch;
|
|
1337
|
-
}
|
|
1338
|
-
}
|
|
1339
|
-
.modal { background-color:var(--icpay-background); border-radius:24px; width:100%; max-width:420px; padding:24px; color:var(--icpay-foreground); display:flex; flex-direction:column; border:1px solid var(--icpay-border); height:460px; margin:auto; transition:transform 0.3s ease; }
|
|
1340
|
-
@media (max-width: 768px) {
|
|
1341
|
-
.icpay-modal-overlay {
|
|
1342
|
-
align-items: flex-end;
|
|
1343
|
-
justify-content: stretch;
|
|
1344
|
-
padding: 0;
|
|
1345
|
-
}
|
|
1346
|
-
.modal {
|
|
1347
|
-
max-width:100%;
|
|
1348
|
-
width:100%;
|
|
1349
|
-
height:auto;
|
|
1350
|
-
max-height:50vh;
|
|
1351
|
-
border-radius:24px 24px 0 0;
|
|
1352
|
-
margin:0;
|
|
1353
|
-
padding:16px;
|
|
1354
|
-
transform:translateY(100%);
|
|
1355
|
-
overflow:hidden;
|
|
1356
|
-
display:flex;
|
|
1357
|
-
flex-direction:column;
|
|
1358
|
-
transition:transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
|
|
1359
|
-
align-self: flex-end;
|
|
1360
|
-
}
|
|
1361
|
-
.icpay-modal-overlay:not([style*="display: none"]) .modal {
|
|
1362
|
-
transform:translateY(0);
|
|
1363
|
-
}
|
|
1364
|
-
.wallet-list {
|
|
1365
|
-
overflow-y:auto;
|
|
1366
|
-
flex:1;
|
|
1367
|
-
min-height:0;
|
|
1368
|
-
max-height:calc(50vh - 120px); /* Account for header, footer, and padding */
|
|
1369
|
-
}
|
|
1370
|
-
}
|
|
1371
|
-
.header { display:flex; align-items:center; justify-content:center; margin-bottom:12px; padding-bottom:12px; border-bottom:1px solid var(--icpay-border); flex-shrink:0; position:relative; }
|
|
1372
|
-
.close-button { background:none; border:none; color:var(--icpay-foreground); font-size:20px; cursor:pointer; padding:4px; margin:0; line-height:1; opacity:0.7; transition:opacity 0.2s; position:absolute; right:0; }
|
|
1373
|
-
.close-button:hover { opacity:1; }
|
|
1374
|
-
.title { font-size:20px; font-weight:600; text-align:center; margin:0; }
|
|
1375
|
-
.wallet-list { display:flex; flex-direction:column; gap:0; overflow-y:auto; flex:1; padding-right:8px; padding-top:4px; scrollbar-gutter: stable; }
|
|
1376
|
-
.wallet-item { display:flex; align-items:center; padding:16px 12px; cursor:pointer; transition:background-color 0.2s; border-radius:12px; }
|
|
1377
|
-
.wallet-item:hover { background-color:var(--icpay-accent); }
|
|
1378
|
-
.wallet-icon { width:48px; height:48px; border-radius:12px; margin-right:16px; display:flex; align-items:center; justify-content:center; font-size:24px; overflow:hidden; }
|
|
1379
|
-
.oisy-icon { background-color:var(--icpay-primary); }
|
|
1380
|
-
.plug-icon { background:linear-gradient(135deg,#667eea 0%, #764ba2 100%); }
|
|
1381
|
-
.wallet-info { flex:1; }
|
|
1382
|
-
.wallet-name { font-size:16px; font-weight:500; margin-bottom:4px; }
|
|
1383
|
-
.wallet-status { font-size:14px; color:var(--icpay-muted-foreground); }
|
|
1384
|
-
.divider { height:0; border-top:1px solid var(--icpay-border); margin:8px 0; border-radius:1px; width:100%; }
|
|
1385
|
-
.footer { display:flex; justify-content:space-between; align-items:center; margin-top:16px; padding-top:16px; flex-shrink:0; }
|
|
1386
|
-
.need-wallet { font-size:14px; color:var(--icpay-muted-foreground); }
|
|
1387
|
-
.get-started { font-size:14px; color:var(--icpay-primary); background:none; border:none; cursor:pointer; font-weight:500; }
|
|
1388
|
-
.get-started:hover { text-decoration:underline; }
|
|
1389
|
-
</style>
|
|
1390
|
-
${Ce()}
|
|
1391
|
-
<div class="modal" @click=${d=>d.stopPropagation()}>
|
|
1392
|
-
${i.step==="balances"?te`
|
|
1393
|
-
${Le({isLoading:!!i.balancesLoading,error:i.balancesError,balances:i.balances,onBack:()=>i.onBack&&i.onBack(),onSelect:d=>i.onSelectBalance&&i.onSelectBalance(d)})}
|
|
1394
|
-
`:te`
|
|
1395
|
-
<div class="header">
|
|
1396
|
-
<h1 class="title">Connect</h1>
|
|
1397
|
-
<button class="close-button" @click=${()=>{try{t()}catch{}}} aria-label="Close">×</button>
|
|
1398
|
-
</div>
|
|
1399
|
-
<div class="wallet-list">
|
|
1400
|
-
${i.showCreditCard&&i.onCreditCard?te`
|
|
1401
|
-
<div class="wallet-item" style="border:1px solid var(--icpay-primary);background:var(--icpay-processing-bg)" @click=${()=>i.onCreditCard&&i.onCreditCard()}>
|
|
1402
|
-
<div class="wallet-icon">
|
|
1403
|
-
💳
|
|
1404
|
-
</div>
|
|
1405
|
-
<div class="wallet-info">
|
|
1406
|
-
<div class="wallet-name">${i.creditCardLabel||"Pay with credit card"}</div>
|
|
1407
|
-
${i.creditCardTooltip?te`<div class="wallet-status">${i.creditCardTooltip}</div>`:null}
|
|
1408
|
-
</div>
|
|
1409
|
-
</div>
|
|
1410
|
-
<div class="divider"></div>
|
|
1411
|
-
`:null}
|
|
1412
|
-
${(()=>{let d=[],y=null;return l.forEach(m=>{let w=(m.id||"").toLowerCase(),J=lt(m.id,m.label),Se=z(w),Me=w==="phantom"||w==="backpack"?"sol":Se?"evm":"ic";y!==null&&Me!==y&&d.push(te`<div class="divider"></div>`);let $e=w==="oisy"||w==="plug"||w==="nfid"||w==="ii"?"Internet Computer":w==="phantom"||w==="backpack"?"Solana":Se?"Ethereum-compatible":"";d.push(te`
|
|
1413
|
-
<div class="wallet-item" style="opacity:${n?.6:1}" @click=${()=>e(m.id)}>
|
|
1414
|
-
<div class="wallet-icon">
|
|
1415
|
-
${m.icon?te`<img src="${ct(m.icon)}" alt="${J} logo" class="icpay-w-8 icpay-h-8" style="object-fit:contain" />`:te`<span>${J.charAt(0)}</span>`}
|
|
1416
|
-
</div>
|
|
1417
|
-
<div class="wallet-info">
|
|
1418
|
-
<div class="wallet-name">${J}</div>
|
|
1419
|
-
${$e?te`<div class="wallet-status">${$e}</div>`:null}
|
|
1420
|
-
</div>
|
|
1421
|
-
</div>
|
|
1422
|
-
`),y=Me}),d})()}
|
|
1423
|
-
</div>
|
|
1424
|
-
<div class="footer">
|
|
1425
|
-
<span class="need-wallet">Need a wallet?</span>
|
|
1426
|
-
<button class="get-started" @click=${()=>{try{window.open("https://metamask.io/en-GB/download","_blank","noopener,noreferrer")}catch{}}}>Get started</button>
|
|
1427
|
-
</div>
|
|
1428
|
-
`}
|
|
1429
|
-
</div>
|
|
1430
|
-
</div>
|
|
1431
|
-
`}import{html as dt}from"lit";function pt(i){if(i==="light"||i==="dark")return i;if(typeof document>"u")return"light";let c=document.documentElement.getAttribute("data-icpay-theme");if(c==="light"||c==="dark")return c;let e=document.documentElement.getAttribute("data-theme");return e==="light"||e==="dark"?e:"light"}function Q(i){if(!i.visible)return null;let c=pt(i.theme);return dt`
|
|
1432
|
-
<div class="icpay-modal-overlay" data-theme="${c}" style="position:fixed !important;inset:0 !important;display:flex;align-items:center;justify-content:center;background:rgba(0, 0, 0, 0.5);z-index:99999 !important;transform:none !important;">
|
|
1433
|
-
<style>
|
|
1434
|
-
/* Theme-aware color variables - Light mode defaults */
|
|
1435
|
-
.icpay-modal-overlay {
|
|
1436
|
-
--icpay-background: #ffffff;
|
|
1437
|
-
--icpay-foreground: #171717;
|
|
1438
|
-
--icpay-muted-foreground: #6b7280;
|
|
1439
|
-
--icpay-primary: #3b82f6;
|
|
1440
|
-
--icpay-primary-foreground: #ffffff;
|
|
1441
|
-
--icpay-secondary: #f3f4f6;
|
|
1442
|
-
--icpay-secondary-foreground: #171717;
|
|
1443
|
-
--icpay-accent: #f9fafb;
|
|
1444
|
-
--icpay-border: #e5e7eb;
|
|
1445
|
-
--icpay-error-text: #dc2626;
|
|
1446
|
-
}
|
|
1447
|
-
/* Dark mode */
|
|
1448
|
-
[data-theme="dark"] .icpay-modal-overlay,
|
|
1449
|
-
[data-icpay-theme="dark"] .icpay-modal-overlay,
|
|
1450
|
-
:root[data-theme="dark"] .icpay-modal-overlay,
|
|
1451
|
-
:root[data-icpay-theme="dark"] .icpay-modal-overlay,
|
|
1452
|
-
html[data-theme="dark"] .icpay-modal-overlay,
|
|
1453
|
-
html[data-icpay-theme="dark"] .icpay-modal-overlay,
|
|
1454
|
-
.icpay-modal-overlay[data-theme="dark"] {
|
|
1455
|
-
--icpay-background: hsl(222.2 84% 4.9%);
|
|
1456
|
-
--icpay-foreground: hsl(210 40% 98%);
|
|
1457
|
-
--icpay-muted-foreground: hsl(215 20.2% 65.1%);
|
|
1458
|
-
--icpay-primary: hsl(210 40% 98%);
|
|
1459
|
-
--icpay-primary-foreground: hsl(222.2 47.4% 11.2%);
|
|
1460
|
-
--icpay-secondary: hsl(217.2 32.6% 17.5%);
|
|
1461
|
-
--icpay-secondary-foreground: hsl(210 40% 98%);
|
|
1462
|
-
--icpay-accent: hsl(217.2 32.6% 17.5%);
|
|
1463
|
-
--icpay-border: hsl(217.2 32.6% 30%);
|
|
1464
|
-
--icpay-error-text: #f87171;
|
|
1465
|
-
}
|
|
1466
|
-
.icpay-modal-overlay {
|
|
1467
|
-
position: fixed !important;
|
|
1468
|
-
inset: 0 !important;
|
|
1469
|
-
display: flex;
|
|
1470
|
-
align-items: center;
|
|
1471
|
-
justify-content: center;
|
|
1472
|
-
background: rgba(0, 0, 0, 0.5);
|
|
1473
|
-
z-index: 99999 !important;
|
|
1474
|
-
/* Ensure modal breaks out of any parent constraints */
|
|
1475
|
-
transform: none !important;
|
|
1476
|
-
will-change: auto;
|
|
1477
|
-
isolation: isolate;
|
|
1478
|
-
}
|
|
1479
|
-
@media (max-width: 768px) {
|
|
1480
|
-
.icpay-modal-overlay {
|
|
1481
|
-
align-items: flex-end;
|
|
1482
|
-
justify-content: stretch;
|
|
1483
|
-
}
|
|
1484
|
-
}
|
|
1485
|
-
</style>
|
|
1486
|
-
${Ce()}
|
|
1487
|
-
<div class="modal">
|
|
1488
|
-
${Le({isLoading:i.isLoading,error:i.error,balances:i.balances,onBack:i.onClose,onSelect:i.onSelect})}
|
|
1489
|
-
</div>
|
|
1490
|
-
</div>
|
|
1491
|
-
`}function D(i){try{let c=i||{};c.adapters=c.adapters||{};let e=c.adapters.oisy||{},t=e.config||{},n={...t.transport||{},windowOpenerFeatures:"",detectNonClickEstablishment:!1};return c.adapters.oisy={...e,config:{...t,transport:n}},c}catch{return i}}function I(i,c){try{let e=c&&(c.owner||c.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}:c||{owner:null}}catch{return c||{owner:null}}}async function ae(i){try{let c=typeof i?.getEnabledWallets=="function"?i.getEnabledWallets.bind(i):null;if(!c)return null;let t=(c()||[]).find(l=>(l?.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}}function ht(){try{typeof window<"u"&&window.dispatchEvent(new CustomEvent("icpay-payment-reset"))}catch{}}function yt(i){let c=i;if(!c||typeof c!="object")return;let e=c.onrampNotifyController;if(e){try{e.stop()}catch{}c.onrampNotifyController=null}let t=c.onrampPollTimer;if(t!=null){try{clearTimeout(t)}catch{}c.onrampPollTimer=null}"onrampPollingActive"in c&&(c.onrampPollingActive=!1)}function mt(i){let c=i;if(!c||typeof c!="object")return;let e=c.config,t=c.pnp;if(!(e?.useOwnWallet||!t||!e)){try{t.disconnect?.()}catch{}c.config={...e,actorProvider:void 0,connectedWallet:void 0}}}function Z(i,c){let e=i??{};if(typeof e!="object")return;ht(),e.errorMessage=null,e.errorSeverity=null,e.errorAction=null,e.processing=!1,e.showWalletModal=!0,e.walletModalStep="connect",e.showBalanceModal=!1,e.selectedSymbol=null,e.lastWalletId=null,e.walletConnected=!1,e.pendingAction=c.pendingAction,e.oisyReadyToPay=!1,e.showOnrampModal=!1,e.onrampUrl=null,e.onrampPaymentIntentId=null,e.onrampErrorMessage=null,"succeeded"in e&&(e.succeeded=!1),"skipDisconnectOnce"in e&&(e.skipDisconnectOnce=!1),"oisySignerPreopened"in e&&(e.oisySignerPreopened=!1),"showProviderPicker"in e&&(e.showProviderPicker=!1),"selectedOnrampProvider"in e&&(e.selectedOnrampProvider=null),yt(i),mt(i);let t=i.requestUpdate;typeof t=="function"&&t.call(i)}var De=typeof window<"u",de=null;function be(i,c,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${c}`,e):console.log(`[ICPay Widget] ${c}`))}var L=class extends ut{constructor(){super(...arguments);this.selectedSymbol=null;this.unlocked=!1;this.succeeded=!1;this.processing=!1;this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.walletModalStep="connect";this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.showOnrampModal=!1;this.onrampUrl=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.transakMessageHandlerBound=null;this.onrampPollTimer=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.showBalanceModal=!1;this.balancesLoading=!1;this.balancesError=null;this.walletBalances=[];this.sdk=null;this.onTransactionCompleted=null;this.onUnlock=null;this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="pay",this.showWalletModal=!0,this.requestUpdate();try{let t=Number(this.config?.priceUsd||0),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),z(this.lastWalletId)){let a=(this.walletBalances||[]).find(o=>o?.tokenShortcode===e),r=a?.chainId;this.showBalanceModal=!1,this.showWalletModal=!1,V(r,{provider:this.pnp?.getEvmProvider?.()||this.config?.evmProvider,chainName:a?.chainName,rpcUrlPublic:a?.rpcUrlPublic,nativeSymbol:a?.ledgerSymbol,decimals:a?.decimals}).then(async()=>{try{let o=x(this.config),l=Number(this.config?.priceUsd??0);if(a?.x402Accepts)try{await o.client.createPaymentX402Usd({usdAmount:l,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"evm",icpay_ledger_id:a?.ledgerId,icpay_context:"premium:x402"}},recipientAddress:(this.config?.recipientAddresses||{})?.evm||"0x0000000000000000000000000000000000000000"});return}catch(p){g(p,{onError:h=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:h,bubbles:!0})),f(h)&&(this.errorMessage=u(h),this.errorSeverity=b(h),this.errorAction=v(h))}})}await o.client.createPaymentUsd({usdAmount:l,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"evm",icpay_ledger_id:a?.ledgerId}},recipientAddress:(this.config?.recipientAddresses||{})?.evm||"0x0000000000000000000000000000000000000000"}).catch(p=>{throw p})}catch(o){g(o,{onError:l=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:l,bubbles:!0})),f(l)&&(this.errorMessage=u(l),this.errorSeverity=b(l),this.errorAction=v(l))}})}});return}this.showBalanceModal=!1,this.showWalletModal=!1;let n=this.pendingAction;if(this.pendingAction=null,n==="pay")try{let a=(this.walletBalances||[]).find(m=>m?.tokenShortcode===e),r=x(this.config),o=Number(this.config?.priceUsd??0),l=String(a?.chainName||a?.ledgerName||"").toLowerCase(),p=l.includes("sol"),h=this.config?.recipientAddresses||{},d=p&&h.sol||h.ic,y=l.includes("ic");if(a?.x402Accepts)try{await r.client.createPaymentX402Usd({usdAmount:o,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:p?"sol":y?"ic":this.config?.icpay_network,icpay_ledger_id:a?.ledgerId,icpay_context:"premium:x402"}},recipientAddress:d||""});return}catch(m){g(m,{onError:w=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:w,bubbles:!0})),f(w)&&(this.errorMessage=u(w),this.errorSeverity=b(w),this.errorAction=v(w))}});return}await r.client.createPaymentUsd({usdAmount:o,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"ic",icpay_ledger_id:a?.ledgerId}},recipientAddress:d||"0x0000000000000000000000000000000000000000"}).catch(m=>{throw m})}catch(a){g(a,{onError:r=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:r,bubbles:!0})),f(r)&&(this.errorMessage=u(r),this.errorSeverity=b(r),this.errorAction=v(r))}})}}}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-BEKXSS66.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{}}connectedCallback(){if(super.connectedCallback(),!!De){be(this.config?.debug||!1,"Premium content connected",{config:this.config}),this.tryAutoConnectPNP();try{window.addEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}try{window.addEventListener("icpay-sdk-transaction-created",(()=>{this.showWalletModal=!1,this.showBalanceModal=!1,this.requestUpdate()}))}catch{}this.onTransactionCompleted=(()=>{this.unlocked=!0,this.succeeded=!0,this.processing=!1;try{window.dispatchEvent(new CustomEvent("icpay-unlock",{detail:{amount:this.config?.priceUsd,currency:this.selectedSymbol||"ICP"}}))}catch{}this.requestUpdate()});try{window.addEventListener("icpay-sdk-transaction-completed",this.onTransactionCompleted)}catch{}this.onUnlock=(()=>{this.unlocked=!0,this.succeeded=!0,this.processing=!1,this.requestUpdate()});try{window.addEventListener("icpay-unlock",this.onUnlock)}catch{}}}disconnectedCallback(){super.disconnectedCallback();try{window.removeEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}if(this.onTransactionCompleted)try{window.removeEventListener("icpay-sdk-transaction-completed",this.onTransactionCompleted)}catch{}if(this.onUnlock)try{window.removeEventListener("icpay-unlock",this.onUnlock)}catch{}}updated(e){if(e.has("config")&&this.pendingAction&&this.config?.actorProvider){let t=this.pendingAction;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}this.walletModalStep!=="balances"&&!this.oisyReadyToPay&&(this.pendingAction=null,setTimeout(()=>{t==="pay"&&this.onPay()},0))}}resetPaymentFlow(){Z(this,{pendingAction:"pay"})}async onPay(){if(De&&!this.unlocked){this.resetPaymentFlow(),be(this.config?.debug||!1,"Premium content payment started",{priceUsd:this.config.priceUsd,selectedSymbol:this.selectedSymbol,useOwnWallet:this.config.useOwnWallet});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){be(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{de||(de=(await import("./wallet-select-BEKXSS66.js")).WalletSelect);let t=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab)?D({...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 de(t);try{let a=await ae(this.pnp);if(a){this.walletConnected=!0;let r=I(this.pnp,{owner:a,principal:a,connected:!0}),o=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(l,p)=>this.pnp.getActor({canisterId:l,idl:p,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{}},this.sdk=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"oisy"}}))}catch{}this.onPay();return}}catch{}let n=this.pnp.getEnabledWallets();if(be(this.config?.debug||!1,"Available wallets",n),!n?.length)throw new Error("No wallets available");this.pendingAction="pay",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.walletModalStep="balances",this.showBalanceModal=!1,this.showWalletModal=!0,await this.fetchAndShowBalances("pay");return}catch(e){g(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),f(t)&&(this.errorMessage=u(t),this.errorSeverity=b(t),this.errorAction=v(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 t=await x(this.config).startOnrampUsd(this.config.priceUsd,void 0,{context:"premium:onramp",onrampPayment:!0,onrampProvider:"coinbase"}),n=t?.metadata?.onramp?.url||t?.onramp?.url||t?.metadata?.icpay_onramp?.url||t?.paymentIntent?.metadata?.icpay?.onrampUrl||t?.metadata?.icpay?.onrampUrl||null,a=t?.metadata?.icpay_payment_intent_id||t?.metadata?.paymentIntentId||t?.paymentIntentId||null,r=t?.metadata?.icpay_onramp?.errorMessage||t?.metadata?.onramp?.errorMessage||t?.paymentIntent?.metadata?.icpay?.onrampError||t?.paymentIntent?.metadata?.icpay?.errorMessage||t?.metadata?.icpay?.onrampError||t?.metadata?.icpay?.errorMessage||null;if(this.onrampPaymentIntentId=a,n){this.onrampUrl=n,this.onrampErrorMessage=null;try{window.open(n,"icpay_onramp","noopener,noreferrer");try{window.dispatchEvent(new CustomEvent("icpay-onramp-opened",{detail:{url:n}}))}catch{}}catch{}this.startOnrampPolling()}else this.onrampUrl=null,this.onrampErrorMessage=r||"Failed to obtain onramp URL",this.showOnrampModal=!0}catch(e){this.onrampUrl=null,this.onrampErrorMessage=e?.message||"Failed to obtain onramp URL",this.showOnrampModal=!0}}startOnrampPolling(e){if(this.onrampPollTimer){try{clearInterval(this.onrampPollTimer)}catch{}this.onrampPollTimer=null}if(this.onrampNotifyController){try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null}let t=this.onrampPaymentIntentId;if(!t)return;let n=x(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=I(this.pnp,n),o=this.pnp?.getEvmProvider?.(),l=this.pnp?.getSolanaProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(p,h)=>this.pnp.getActor({canisterId:p,idl:h,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{},...l?{solanaProvider:l}:{}},this.sdk=null,this.walletModalStep="balances",this.showBalanceModal=!1,this.showWalletModal=!0,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.walletModalStep="balances",this.showBalanceModal=!1;let t=x(this.config),{balances:n}=await X({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?ie`
|
|
1492
|
-
<div class="icpay-card icpay-section icpay-widget-base">
|
|
1493
|
-
${this.config?.progressBar?.enabled!==!1?ie`
|
|
1494
|
-
<icpay-progress-bar
|
|
1495
|
-
.debug=${!!this.config?.debug}
|
|
1496
|
-
.theme=${this.config?.theme}
|
|
1497
|
-
.amount=${Number(this.config?.priceUsd||0)}
|
|
1498
|
-
.ledgerSymbol=${this.selectedSymbol||"ICP"}
|
|
1499
|
-
></icpay-progress-bar>
|
|
1500
|
-
`:null}
|
|
1501
|
-
<div class="image-container">
|
|
1502
|
-
<div class="locked-image ${this.unlocked?"unlocked":""}" style="background-image:url('${this.config.imageUrl||""}')"></div>
|
|
1503
|
-
${this.unlocked?null:ie`<div class="lock-overlay">🔒</div>`}
|
|
1504
|
-
</div>
|
|
1505
|
-
|
|
1506
|
-
<div class="pricing">
|
|
1507
|
-
<div class="price">$${Number(this.config?.priceUsd??0).toFixed(2)}</div>
|
|
1508
|
-
<div class="label">One-time unlock</div>
|
|
1509
|
-
</div>
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
<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()}>
|
|
1514
|
-
${this.unlocked?"Unlocked":this.processing?"Processing\u2026":(this.config?.buttonLabel||"Pay ${amount} with crypto").replace("{amount}",`${Number(this.config?.priceUsd??0).toFixed(2)}`).replace("{symbol}",this.selectedSymbol||"ICP")}
|
|
1515
|
-
</button>
|
|
1516
|
-
|
|
1517
|
-
${this.errorMessage?ie`
|
|
1518
|
-
<div class="error-message ${this.errorSeverity}" style="margin-top: 12px; padding: 8px 12px; border-radius: 6px; font-size: 14px; text-align: center;">
|
|
1519
|
-
${this.errorMessage}
|
|
1520
|
-
${this.errorAction?ie`
|
|
1521
|
-
<button style="margin-left: 8px; padding: 4px 8px; background: transparent; border: 1px solid currentColor; border-radius: 4px; font-size: 12px; cursor: pointer;">
|
|
1522
|
-
${this.errorAction}
|
|
1523
|
-
</button>
|
|
1524
|
-
`:""}
|
|
1525
|
-
</div>
|
|
1526
|
-
`:""}
|
|
1527
|
-
${(()=>{let e=this.pnp?.getEnabledWallets?.()||[],t=H(e),n=this.config?.theme?typeof this.config.theme=="string"?this.config.theme:this.config.theme.mode||"light":void 0;return G({visible:!!(this.showWalletModal&&this.pnp),wallets:t,isConnecting:!1,step:this.walletModalStep,balances:this.walletModalStep==="balances"?this.walletBalances:[],balancesLoading:this.walletModalStep==="balances"?this.balancesLoading:!1,balancesError:this.walletModalStep==="balances"?this.balancesError:null,onSelectBalance:a=>this.onSelectBalanceSymbol(a),onBack:()=>{this.walletModalStep="connect"},onSwitchAccount:()=>this.onSwitchAccount(null),onSelect:a=>this.connectWithWallet(a),onClose:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-cancelled",{detail:{reason:"user_cancelled"}}))}catch{}},onDismiss:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1},onCreditCard:this.config?.onramp?.enabled===!0&&this.config?.onrampDisabled!==!0?()=>this.startOnramp():void 0,creditCardLabel:this.config?.onramp?.creditCardLabel||"Pay with credit card",showCreditCard:this.config?.onramp?.enabled===!0&&this.config?.onrampDisabled!==!0,creditCardTooltip:(()=>{let r=Number(this.config?.priceUsd||0);return r>0&&r<5&&this.config?.onramp?.enabled===!0&&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.onPay()},theme:n})})()}
|
|
1528
|
-
|
|
1529
|
-
${(()=>{let e=this.config?.theme?typeof this.config.theme=="string"?this.config.theme:this.config.theme.mode||"light":void 0;return ie`
|
|
1530
|
-
${Q({visible:this.showBalanceModal,isLoading:this.balancesLoading,error:this.balancesError,balances:this.walletBalances,onSelect:t=>this.onSelectBalanceSymbol(t),onClose:()=>{this.showBalanceModal=!1},theme:e})}
|
|
1531
|
-
|
|
1532
|
-
${q({visible:this.showOnrampModal,url:this.onrampUrl||void 0,errorMessage:this.onrampErrorMessage||void 0,width:this.config?.onramp?.width,height:this.config?.onramp?.height,onClose:()=>{this.showOnrampModal=!1},onBack:()=>{this.showOnrampModal=!1,this.showWalletModal=!0},title:"Pay with credit card",theme:e})}
|
|
1533
|
-
`})()}
|
|
1534
|
-
<div class="icpay-powered-by">
|
|
1535
|
-
<a href="https://icpay.org" target="_blank" rel="noopener noreferrer">Powered by icpay</a>
|
|
1536
|
-
</div>
|
|
1537
|
-
</div>
|
|
1538
|
-
`:ie`<div class="icpay-card icpay-section">Loading...</div>`}};L.styles=[K,gt`
|
|
1539
|
-
.image-container {
|
|
1540
|
-
position: relative;
|
|
1541
|
-
border-radius: 16px;
|
|
1542
|
-
overflow: hidden;
|
|
1543
|
-
margin-bottom: 16px;
|
|
1544
|
-
background: #111827;
|
|
1545
|
-
border: 1px solid var(--icpay-border);
|
|
1546
|
-
aspect-ratio: 16/10;
|
|
1547
|
-
}
|
|
1548
|
-
.locked-image {
|
|
1549
|
-
width: 100%;
|
|
1550
|
-
height: 100%;
|
|
1551
|
-
background-size: cover;
|
|
1552
|
-
background-position: center;
|
|
1553
|
-
background-repeat: no-repeat;
|
|
1554
|
-
filter: blur(8px) grayscale(1);
|
|
1555
|
-
transition: all 0.6s ease;
|
|
1556
|
-
min-height: 200px;
|
|
1557
|
-
}
|
|
1558
|
-
.locked-image.unlocked { filter: blur(0px) grayscale(1); }
|
|
1559
|
-
.lock-overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
|
|
1560
|
-
.pricing { text-align: center; margin: 16px 0; }
|
|
1561
|
-
.price { font-size: 28px; font-weight: 800; color: var(--icpay-text); }
|
|
1562
|
-
.label { color: var(--icpay-muted); font-size: 14px; }
|
|
1563
|
-
.crypto-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0 16px; }
|
|
1564
|
-
.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; }
|
|
1565
|
-
.crypto-option.selected { background: var(--icpay-primary); color: #111827; border-color: var(--icpay-primary); }
|
|
1566
|
-
|
|
1567
|
-
.error-message {
|
|
1568
|
-
border: 1px solid;
|
|
1569
|
-
font-weight: 500;
|
|
1570
|
-
}
|
|
1571
|
-
|
|
1572
|
-
.error-message.info {
|
|
1573
|
-
background: var(--icpay-processing-bg);
|
|
1574
|
-
border-color: var(--icpay-processing-border);
|
|
1575
|
-
color: var(--icpay-processing-text);
|
|
1576
|
-
}
|
|
1577
|
-
|
|
1578
|
-
.error-message.warning {
|
|
1579
|
-
background: var(--icpay-warning-bg);
|
|
1580
|
-
border-color: var(--icpay-warning-border);
|
|
1581
|
-
color: var(--icpay-warning-text);
|
|
1582
|
-
}
|
|
1583
|
-
|
|
1584
|
-
.error-message.error {
|
|
1585
|
-
background: var(--icpay-error-bg);
|
|
1586
|
-
border-color: var(--icpay-error-border);
|
|
1587
|
-
color: var(--icpay-error-text);
|
|
1588
|
-
}
|
|
1589
|
-
`],s([vt({type:Object})],L.prototype,"config",2),s([$()],L.prototype,"selectedSymbol",2),s([$()],L.prototype,"unlocked",2),s([$()],L.prototype,"succeeded",2),s([$()],L.prototype,"processing",2),s([$()],L.prototype,"errorMessage",2),s([$()],L.prototype,"errorSeverity",2),s([$()],L.prototype,"errorAction",2),s([$()],L.prototype,"walletConnected",2),s([$()],L.prototype,"pendingAction",2),s([$()],L.prototype,"showWalletModal",2),s([$()],L.prototype,"walletModalStep",2),s([$()],L.prototype,"oisyReadyToPay",2),s([$()],L.prototype,"lastWalletId",2),s([$()],L.prototype,"showOnrampModal",2),s([$()],L.prototype,"onrampUrl",2),s([$()],L.prototype,"onrampPaymentIntentId",2),s([$()],L.prototype,"onrampErrorMessage",2),s([$()],L.prototype,"showBalanceModal",2),s([$()],L.prototype,"balancesLoading",2),s([$()],L.prototype,"balancesError",2),s([$()],L.prototype,"walletBalances",2),L=s([ft("icpay-premium-content")],L);import{LitElement as bt,html as re,css as wt}from"lit";import{customElement as xt,property as Et,state as P}from"lit/decorators.js";var ze=typeof window<"u",he=null;function we(i,c,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${c}`,e):console.log(`[ICPay Widget] ${c}`))}var W=class extends bt{constructor(){super(...arguments);this.selectedAmount=1;this.selectedSymbol=null;this.total=0;this.processing=!1;this.succeeded=!1;this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.walletModalStep="connect";this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.showOnrampModal=!1;this.onrampUrl=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.transakMessageHandlerBound=null;this.onrampPollTimer=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.sdk=null;this.showBalanceModal=!1;this.balancesLoading=!1;this.balancesError=null;this.walletBalances=[];this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="tip",this.showWalletModal=!0,this.requestUpdate();try{let t=Number(this.selectedAmount||0),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),this.showBalanceModal=!1,this.showWalletModal=!1,z(this.lastWalletId)){let a=(this.walletBalances||[]).find(o=>o?.tokenShortcode===e),r=a?.chainId;V(r,{provider:this.pnp?.getEvmProvider?.()||this.config?.evmProvider,chainName:a?.chainName,rpcUrlPublic:a?.rpcUrlPublic,nativeSymbol:a?.ledgerSymbol,decimals:a?.decimals}).then(async()=>{try{let o=x(this.config),l=Number(this.selectedAmount||0);if(a?.x402Accepts)try{await o.client.createPaymentX402Usd({usdAmount:l,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"evm",icpay_ledger_id:a?.ledgerId,icpay_context:"tip:x402"}},recipientAddress:(this.config?.recipientAddresses||{})?.evm||"0x0000000000000000000000000000000000000000"}),this.showBalanceModal=!1;return}catch(p){g(p,{onError:h=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:h,bubbles:!0})),f(h)&&(this.errorMessage=u(h),this.errorSeverity=b(h),this.errorAction=v(h))}})}await o.client.createPaymentUsd({usdAmount:l,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"evm",icpay_ledger_id:a?.ledgerId}},recipientAddress:(this.config?.recipientAddresses||{})?.evm||"0x0000000000000000000000000000000000000000"}).catch(p=>{throw p})}catch(o){g(o,{onError:l=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:l,bubbles:!0})),f(l)&&(this.errorMessage=u(l),this.errorSeverity=b(l),this.errorAction=v(l))}})}this.showBalanceModal=!1});return}let n=this.pendingAction;if(this.pendingAction=null,n==="tip")try{let a=(this.walletBalances||[]).find(m=>m?.tokenShortcode===e),r=x(this.config),o=Number(this.selectedAmount||0),l=String(a?.ledgerName||a?.chainName||"").toLowerCase(),p=l.includes("sol"),h=l.includes("ic"),d=this.config?.recipientAddresses||{},y=p&&d.sol||d.ic;if(a?.x402Accepts)try{await r.client.createPaymentX402Usd({usdAmount:o,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:p?"sol":h?"ic":this.config?.icpay_network,icpay_ledger_id:a?.ledgerId,icpay_context:"tip:x402"}},recipientAddress:y||""});return}catch(m){g(m,{onError:w=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:w,bubbles:!0})),f(w)&&(this.errorMessage=u(w),this.errorSeverity=b(w),this.errorAction=v(w))}});return}await r.client.createPaymentUsd({usdAmount:o,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"ic",icpay_ledger_id:a?.ledgerId}},recipientAddress:y||"0x0000000000000000000000000000000000000000"}).catch(m=>{throw m})}catch(a){g(a,{onError:r=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:r,bubbles:!0})),f(r)&&(this.errorMessage=u(r),this.errorSeverity=b(r),this.errorAction=v(r))}})}}}async tryAutoConnectPNP(){try{if(!this.config||this.config?.useOwnWallet)return;let e=localStorage.getItem("icpay:pnp");if(!e)return;let t=JSON.parse(e);if(!t?.provider||!t?.principal)return;he||(he=(await import("./wallet-select-BEKXSS66.js")).WalletSelect);let n=D({...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 he(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(),!!ze){we(this.config?.debug||!1,"Tip jar connected",{config:this.config}),this.config&&this.config.defaultAmountUsd&&(this.selectedAmount=this.config.defaultAmountUsd),this.tryAutoConnectPNP();try{window.addEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}try{window.addEventListener("icpay-sdk-transaction-created",(()=>{this.showWalletModal=!1,this.requestUpdate()}))}catch{}}}updated(e){if(e.has("config")&&this.pendingAction&&this.config?.actorProvider){let t=this.pendingAction;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}this.walletModalStep!=="balances"&&!this.oisyReadyToPay&&(this.pendingAction=null,setTimeout(()=>{t==="tip"&&this.tip()},0))}}selectAmount(e){this.selectedAmount=e}selectSymbol(e){this.selectedSymbol=e}get fillPercentage(){return Math.min(this.total/50*100,100)}resetPaymentFlow(){Z(this,{pendingAction:"tip"})}async tip(){if(ze){this.resetPaymentFlow(),we(this.config?.debug||!1,"Tip button clicked!",{config:this.config,processing:this.processing});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){we(this.config?.debug||!1,"Connecting to wallet via wallet");try{he||(he=(await import("./wallet-select-BEKXSS66.js")).WalletSelect);let t=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab)?D({...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 he(t);try{let a=await ae(this.pnp);if(a){this.walletConnected=!0;let r=I(this.pnp,{owner:a,principal:a,connected:!0}),o=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(l,p)=>this.pnp.getActor({canisterId:l,idl:p,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{}},this.sdk=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"oisy"}}))}catch{}this.tip();return}}catch{}let n=this.pnp.getEnabledWallets();if(we(this.config?.debug||!1,"Available wallets",n),!n?.length)throw new Error("No wallets available");this.pendingAction="tip",this.showWalletModal=!0;return}catch(e){we(this.config?.debug||!1,"Wallet connection error:",e),this.errorMessage=e instanceof Error?e.message:"Wallet connection failed",this.errorSeverity="error";return}}this.showWalletModal=!0,await this.fetchAndShowBalances();return}catch(e){g(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),f(t)&&(this.errorMessage=u(t),this.errorSeverity=b(t),this.errorAction=v(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 t=await x(this.config).startOnrampUsd(this.selectedAmount,void 0,{context:"tip:onramp",onrampPayment:!0,onrampProvider:this?.selectedOnrampProvider||"coinbase"}),n=t?.metadata?.onramp?.url||t?.onramp?.url||t?.metadata?.icpay_onramp?.url||t?.paymentIntent?.metadata?.icpay?.onrampUrl||t?.metadata?.icpay?.onrampUrl||null,a=t?.metadata?.icpay_payment_intent_id||t?.metadata?.paymentIntentId||t?.paymentIntentId||null,r=t?.metadata?.icpay_onramp?.errorMessage||t?.metadata?.onramp?.errorMessage||t?.paymentIntent?.metadata?.icpay?.onrampError||t?.paymentIntent?.metadata?.icpay?.errorMessage||t?.metadata?.icpay?.onrampError||t?.metadata?.icpay?.errorMessage||null;if(this.onrampPaymentIntentId=a,n){this.onrampUrl=n,this.onrampErrorMessage=null;try{window.open(n,"icpay_onramp","noopener,noreferrer");try{window.dispatchEvent(new CustomEvent("icpay-onramp-opened",{detail:{url:n}}))}catch{}}catch{}this.startOnrampPolling()}else this.onrampUrl=null,this.onrampErrorMessage=r||"Failed to obtain onramp sessionId",this.showOnrampModal=!0}catch(e){this.onrampUrl=null,this.onrampErrorMessage=e?.message||"Failed to obtain onramp sessionId",this.showOnrampModal=!0}}startOnrampPolling(e){if(this.onrampPollTimer){try{clearInterval(this.onrampPollTimer)}catch{}this.onrampPollTimer=null}if(this.onrampNotifyController){try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null}let t=this.onrampPaymentIntentId;if(!t)return;let n=x(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=I(this.pnp,n),o=this.pnp?.getEvmProvider?.(),l=this.pnp?.getSolanaProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(p,h)=>this.pnp.getActor({canisterId:p,idl:h,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{},...l?{solanaProvider:l}:{}},this.sdk=null,this.walletModalStep="balances",this.showBalanceModal=!1,this.showWalletModal=!0,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.walletModalStep="balances",this.showBalanceModal=!1;let e=x(this.config),{balances:t}=await X({sdk:e,lastWalletId:this.lastWalletId,connectedWallet:this.config?.connectedWallet,amountUsd:Number(this.selectedAmount||0),chainShortcodes:this.config?.chainShortcodes,tokenShortcodes:this.config?.tokenShortcodes});this.walletBalances=t}catch(e){this.walletBalances=[],this.balancesError=e&&(e.message||String(e))||"Failed to load balances"}finally{this.balancesLoading=!1}}render(){return this.config?re`
|
|
1590
|
-
<div class="icpay-card icpay-section icpay-widget-base" style="text-align:center;">
|
|
1591
|
-
${this.config?.progressBar?.enabled!==!1?re`
|
|
1592
|
-
<icpay-progress-bar
|
|
1593
|
-
.debug=${!!this.config?.debug}
|
|
1594
|
-
.theme=${this.config?.theme}
|
|
1595
|
-
.amount=${Number(this.selectedAmount||0)}
|
|
1596
|
-
.ledgerSymbol=${this.selectedSymbol||"ICP"}
|
|
1597
|
-
></icpay-progress-bar>
|
|
1598
|
-
`:null}
|
|
1599
|
-
<div class="jar"><div class="fill" style="height:${this.fillPercentage}%"></div></div>
|
|
1600
|
-
<div class="label">Total Tips: $${this.total}</div>
|
|
1601
|
-
|
|
1602
|
-
<div class="amounts">
|
|
1603
|
-
${this.amounts.map(e=>re`<div class="chip ${this.selectedAmount===e?"selected":""}" @click=${()=>this.selectAmount(e)}>$${e}</div>`)}
|
|
1604
|
-
</div>
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
<button class="pay-button ${this.processing?"processing":""}"
|
|
1609
|
-
?disabled=${this.processing||this.config?.disablePaymentButton===!0||this.succeeded&&this.config?.disableAfterSuccess===!0}
|
|
1610
|
-
@click=${()=>this.tip()}>
|
|
1611
|
-
${this.succeeded&&this.config?.disableAfterSuccess?"Paid":this.processing?"Processing\u2026":this.config?.buttonLabel?this.config.buttonLabel.replace("{amount}",String(this.selectedAmount)).replace("{symbol}",this.selectedSymbol||"ICP"):`Tip $${this.selectedAmount} with crypto`}
|
|
1612
|
-
</button>
|
|
1613
|
-
|
|
1614
|
-
${this.errorMessage?re`
|
|
1615
|
-
<div class="error-message ${this.errorSeverity}" style="margin-top: 12px; padding: 8px 12px; border-radius: 6px; font-size: 14px; text-align: center;">
|
|
1616
|
-
${this.errorMessage}
|
|
1617
|
-
${this.errorAction?re`
|
|
1618
|
-
<button style="margin-left: 8px; padding: 4px 8px; background: transparent; border: 1px solid currentColor; border-radius: 4px; font-size: 12px; cursor: pointer;">
|
|
1619
|
-
${this.errorAction}
|
|
1620
|
-
</button>
|
|
1621
|
-
`:""}
|
|
1622
|
-
</div>
|
|
1623
|
-
`:""}
|
|
1624
|
-
${(()=>{let e=this.pnp?.getEnabledWallets?.()||[],t=H(e),n=this.config?.theme?typeof this.config.theme=="string"?this.config.theme:this.config.theme.mode||"light":void 0;return G({visible:!!(this.showWalletModal&&this.pnp),wallets:t,isConnecting:!1,step:this.walletModalStep,balances:this.walletModalStep==="balances"?this.walletBalances:[],balancesLoading:this.walletModalStep==="balances"?this.balancesLoading:!1,balancesError:this.walletModalStep==="balances"?this.balancesError:null,onSelectBalance:a=>this.onSelectBalanceSymbol(a),onBack:()=>{this.walletModalStep="connect"},onSwitchAccount:()=>this.onSwitchAccount(null),onSelect:a=>this.connectWithWallet(a),onClose:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-cancelled",{detail:{reason:"user_cancelled"}}))}catch{}},onDismiss:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1},onCreditCard:this.config?.onramp?.enabled===!0&&this.config?.onrampDisabled!==!0?()=>this.startOnramp():void 0,creditCardLabel:this.config?.onramp?.creditCardLabel||"Pay with credit card",showCreditCard:this.config?.onramp?.enabled===!0&&this.config?.onrampDisabled!==!0,creditCardTooltip:(()=>{let r=Number(this.selectedAmount||this.config?.defaultAmountUsd||0);return r>0&&r<5&&this.config?.onramp?.enabled===!0&&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.tip()},theme:n})})()}
|
|
1625
|
-
|
|
1626
|
-
${(()=>{let e=this.config?.theme?typeof this.config.theme=="string"?this.config.theme:this.config.theme.mode||"light":void 0;return re`
|
|
1627
|
-
${Q({visible:this.showBalanceModal,isLoading:this.balancesLoading,error:this.balancesError,balances:this.walletBalances,onSelect:t=>this.onSelectBalanceSymbol(t),onClose:()=>{this.showBalanceModal=!1},theme:e})}
|
|
1628
|
-
|
|
1629
|
-
${q({visible:this.showOnrampModal,url:this.onrampUrl||void 0,errorMessage:this.onrampErrorMessage||void 0,width:this.config?.onramp?.width,height:this.config?.onramp?.height,onClose:()=>{this.showOnrampModal=!1},onBack:()=>{this.showOnrampModal=!1,this.showWalletModal=!0},title:"Pay with credit card",theme:e})}
|
|
1630
|
-
`})()}
|
|
1631
|
-
<div class="icpay-powered-by">
|
|
1632
|
-
<a href="https://icpay.org" target="_blank" rel="noopener noreferrer">Powered by icpay</a>
|
|
1633
|
-
</div>
|
|
1634
|
-
</div>
|
|
1635
|
-
`:re`<div class="icpay-card icpay-section">Loading...</div>`}};W.styles=[K,wt`
|
|
1636
|
-
.jar { width: 120px; height: 160px; margin: 0 auto 12px; position: relative; background: linear-gradient(135deg, #374151 0%, #4b5563 100%); border-radius: 0 0 60px 60px; border: 3px solid #6b7280; border-top: 8px solid #6b7280; overflow: hidden; }
|
|
1637
|
-
.fill { position: absolute; bottom: 0; left: 0; right: 0; background: linear-gradient(135deg, #d1d5db 0%, #9ca3af 100%); transition: height 0.8s ease; height: 0%; }
|
|
1638
|
-
.amounts { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; margin: 12px 0; }
|
|
1639
|
-
.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; }
|
|
1640
|
-
.chip.selected { background: var(--icpay-primary); color: #111827; border-color: var(--icpay-primary); }
|
|
1641
|
-
.crypto-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0 16px; }
|
|
1642
|
-
.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; }
|
|
1643
|
-
.crypto-option.selected { background: var(--icpay-primary); color: #111827; border-color: var(--icpay-primary); }
|
|
1644
|
-
|
|
1645
|
-
.error-message {
|
|
1646
|
-
border: 1px solid;
|
|
1647
|
-
font-weight: 500;
|
|
1648
|
-
}
|
|
1649
|
-
|
|
1650
|
-
.error-message.info {
|
|
1651
|
-
background: var(--icpay-processing-bg);
|
|
1652
|
-
border-color: var(--icpay-processing-border);
|
|
1653
|
-
color: var(--icpay-processing-text);
|
|
1654
|
-
}
|
|
1655
|
-
|
|
1656
|
-
.error-message.warning {
|
|
1657
|
-
background: var(--icpay-warning-bg);
|
|
1658
|
-
border-color: var(--icpay-warning-border);
|
|
1659
|
-
color: var(--icpay-warning-text);
|
|
1660
|
-
}
|
|
1661
|
-
|
|
1662
|
-
.error-message.error {
|
|
1663
|
-
background: var(--icpay-error-bg);
|
|
1664
|
-
border-color: var(--icpay-error-border);
|
|
1665
|
-
color: var(--icpay-error-text);
|
|
1666
|
-
}
|
|
1667
|
-
`],s([Et({type:Object})],W.prototype,"config",2),s([P()],W.prototype,"selectedAmount",2),s([P()],W.prototype,"selectedSymbol",2),s([P()],W.prototype,"total",2),s([P()],W.prototype,"processing",2),s([P()],W.prototype,"succeeded",2),s([P()],W.prototype,"errorMessage",2),s([P()],W.prototype,"errorSeverity",2),s([P()],W.prototype,"errorAction",2),s([P()],W.prototype,"walletConnected",2),s([P()],W.prototype,"pendingAction",2),s([P()],W.prototype,"showWalletModal",2),s([P()],W.prototype,"walletModalStep",2),s([P()],W.prototype,"oisyReadyToPay",2),s([P()],W.prototype,"lastWalletId",2),s([P()],W.prototype,"showOnrampModal",2),s([P()],W.prototype,"onrampUrl",2),s([P()],W.prototype,"onrampPaymentIntentId",2),s([P()],W.prototype,"onrampErrorMessage",2),s([P()],W.prototype,"showBalanceModal",2),s([P()],W.prototype,"balancesLoading",2),s([P()],W.prototype,"balancesError",2),s([P()],W.prototype,"walletBalances",2),W=s([xt("icpay-tip-jar")],W);import{LitElement as kt,html as ye,css as St}from"lit";import{customElement as Mt,property as Te,state as B}from"lit/decorators.js";var je=typeof window<"u",me=null;function xe(i,c,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${c}`,e):console.log(`[ICPay Widget] ${c}`))}var E=class extends kt{constructor(){super(...arguments);this.title="Article Title";this.preview="";this.lockedContent="";this.selectedSymbol=null;this.unlocked=!1;this.succeeded=!1;this.processing=!1;this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.walletModalStep="connect";this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.showOnrampModal=!1;this.onrampUrl=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.transakMessageHandlerBound=null;this.onrampPollTimer=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.showBalanceModal=!1;this.balancesLoading=!1;this.balancesError=null;this.walletBalances=[];this.sdk=null;this.onTransactionCompleted=null;this.onUnlock=null;this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="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),z(this.lastWalletId)){let a=(this.walletBalances||[]).find(o=>o?.tokenShortcode===e),r=a?.chainId;this.showBalanceModal=!1,this.showWalletModal=!1,V(r,{provider:this.pnp?.getEvmProvider?.()||this.config?.evmProvider,chainName:a?.chainName,rpcUrlPublic:a?.rpcUrlPublic,nativeSymbol:a?.ledgerSymbol,decimals:a?.decimals}).then(async()=>{try{let o=x(this.config),l=Number(this.config?.priceUsd??0);if(a?.x402Accepts)try{await o.client.createPaymentX402Usd({usdAmount:l,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"evm",icpay_ledger_id:a?.ledgerId,icpay_context:"article:x402"}},recipientAddress:(this.config?.recipientAddresses||{})?.evm||"0x0000000000000000000000000000000000000000"});return}catch(p){g(p,{onError:h=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:h,bubbles:!0})),f(h)&&(this.errorMessage=u(h),this.errorSeverity=b(h),this.errorAction=v(h))}})}await o.client.createPaymentUsd({usdAmount:l,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"evm",icpay_ledger_id:a?.ledgerId}},recipientAddress:(this.config?.recipientAddresses||{})?.evm||"0x0000000000000000000000000000000000000000"}).catch(p=>{throw p})}catch(o){g(o,{onError:l=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:l,bubbles:!0})),f(l)&&(this.errorMessage=u(l),this.errorSeverity=b(l),this.errorAction=v(l))}})}});return}this.showBalanceModal=!1,this.showWalletModal=!1;let n=this.pendingAction;if(this.pendingAction=null,n==="unlock")try{let a=(this.walletBalances||[]).find(y=>y?.tokenShortcode===e),r=x(this.config),o=Number(this.config?.priceUsd??0),p=String(a?.ledgerName||a?.chainName||"").toLowerCase().includes("sol"),h=this.config?.recipientAddresses||{},d=p&&h.sol||h.ic;if(p&&a?.x402Accepts)try{await r.client.createPaymentX402Usd({usdAmount:o,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"sol",icpay_ledger_id:a?.ledgerId,icpay_context:"article:x402"}},recipientAddress:d||""});return}catch(y){g(y,{onError:m=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:m,bubbles:!0})),f(m)&&(this.errorMessage=u(m),this.errorSeverity=b(m),this.errorAction=v(m))}});return}await r.client.createPaymentUsd({usdAmount:o,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"ic",icpay_ledger_id:a?.ledgerId}},recipientAddress:d||"0x0000000000000000000000000000000000000000"}).catch(y=>{throw y})}catch(a){g(a,{onError:r=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:r,bubbles:!0})),f(r)&&(this.errorMessage=u(r),this.errorSeverity=b(r),this.errorAction=v(r))}})}}}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;me||(me=(await import("./wallet-select-BEKXSS66.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 me(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 t=await x(this.config).startOnrampUsd(this.config.priceUsd,void 0,{context:"article:onramp",onrampPayment:!0,onrampProvider:"coinbase"}),n=t?.metadata?.onramp?.url||t?.onramp?.url||t?.metadata?.icpay_onramp?.url||t?.paymentIntent?.metadata?.icpay?.onrampUrl||t?.metadata?.icpay?.onrampUrl||null,a=t?.metadata?.icpay_payment_intent_id||t?.metadata?.paymentIntentId||t?.paymentIntentId||null,r=t?.metadata?.icpay_onramp?.errorMessage||t?.metadata?.onramp?.errorMessage||t?.paymentIntent?.metadata?.icpay?.onrampError||t?.paymentIntent?.metadata?.icpay?.errorMessage||t?.metadata?.icpay?.onrampError||t?.metadata?.icpay?.errorMessage||null;if(this.onrampPaymentIntentId=a,n){this.onrampUrl=n,this.onrampErrorMessage=null;try{window.open(n,"icpay_onramp","noopener,noreferrer");try{window.dispatchEvent(new CustomEvent("icpay-onramp-opened",{detail:{url:n}}))}catch{}}catch{}this.startOnrampPolling()}else this.onrampUrl=null,this.onrampErrorMessage=r||"Failed to obtain onramp URL",this.showOnrampModal=!0}catch(e){this.onrampUrl=null,this.onrampErrorMessage=e?.message||"Failed to obtain onramp URL",this.showOnrampModal=!0}}startOnrampPolling(e){if(this.onrampPollTimer){try{clearInterval(this.onrampPollTimer)}catch{}this.onrampPollTimer=null}if(this.onrampNotifyController){try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null}let t=this.onrampPaymentIntentId;if(!t)return;let n=x(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(),!!je){xe(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{}try{window.addEventListener("icpay-sdk-transaction-created",(()=>{this.showWalletModal=!1,this.showBalanceModal=!1,this.requestUpdate()}))}catch{}this.onTransactionCompleted=(()=>{this.unlocked=!0,this.succeeded=!0,this.processing=!1;try{window.dispatchEvent(new CustomEvent("icpay-unlock",{detail:{amount:this.config?.priceUsd,currency:this.selectedSymbol||"ICP"}}))}catch{}this.requestUpdate()});try{window.addEventListener("icpay-sdk-transaction-completed",this.onTransactionCompleted)}catch{}this.onUnlock=(()=>{this.unlocked=!0,this.succeeded=!0,this.processing=!1,this.requestUpdate()});try{window.addEventListener("icpay-unlock",this.onUnlock)}catch{}}}disconnectedCallback(){super.disconnectedCallback();try{window.removeEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}if(this.onTransactionCompleted)try{window.removeEventListener("icpay-sdk-transaction-completed",this.onTransactionCompleted)}catch{}if(this.onUnlock)try{window.removeEventListener("icpay-unlock",this.onUnlock)}catch{}}updated(e){if(e.has("config")&&this.config&&(typeof this.config.title=="string"&&(this.title=this.config.title),typeof this.config.preview=="string"&&(this.preview=this.config.preview),typeof this.config.lockedContent=="string"&&(this.lockedContent=this.config.lockedContent)),e.has("config")&&this.pendingAction&&this.config?.actorProvider){let t=this.pendingAction;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}this.walletModalStep!=="balances"&&!this.oisyReadyToPay&&(this.pendingAction=null,setTimeout(()=>{t==="unlock"&&this.unlock()},0))}}selectSymbol(e){this.selectedSymbol=e}resetPaymentFlow(){Z(this,{pendingAction:"unlock"})}async unlock(){if(je&&!this.unlocked){this.resetPaymentFlow(),xe(this.config?.debug||!1,"Article paywall unlock started",{priceUsd:this.config.priceUsd,selectedSymbol:this.selectedSymbol,useOwnWallet:this.config.useOwnWallet});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){xe(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{me||(me=(await import("./wallet-select-BEKXSS66.js")).WalletSelect);let t=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab)?D({...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 me(t);try{let a=await ae(this.pnp);if(a){this.walletConnected=!0;let r=I(this.pnp,{owner:a,principal:a,connected:!0}),o=this.pnp?.getEvmProvider?.(),l=this.pnp?.getSolanaProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(p,h)=>this.pnp.getActor({canisterId:p,idl:h,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{},...l?{solanaProvider:l}:{}},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(xe(this.config?.debug||!1,"Available wallets",n),!n?.length)throw new Error("No wallets available");this.pendingAction="unlock",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.showWalletModal=!1,await this.fetchAndShowBalances();return}catch(e){g(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),f(t)&&(this.errorMessage=u(t),this.errorSeverity=b(t),this.errorAction=v(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=I(this.pnp,n),o=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(l,p)=>this.pnp.getActor({canisterId:l,idl:p,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{}},this.sdk=null,this.walletModalStep="balances",this.showBalanceModal=!1,this.showWalletModal=!0,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.walletModalStep="balances",this.showBalanceModal=!1;let e=x(this.config),{balances:t}=await X({sdk:e,lastWalletId:this.lastWalletId,connectedWallet:this.config?.connectedWallet,amountUsd:Number(this.config?.priceUsd??0),chainShortcodes:this.config?.chainShortcodes,tokenShortcodes:this.config?.tokenShortcodes});this.walletBalances=t}catch(e){this.walletBalances=[],this.balancesError=e&&(e.message||String(e))||"Failed to load balances"}finally{this.balancesLoading=!1}}render(){return this.config?ye`
|
|
1668
|
-
<div class="icpay-card icpay-section icpay-widget-base">
|
|
1669
|
-
${this.config?.progressBar?.enabled!==!1?ye`
|
|
1670
|
-
<icpay-progress-bar
|
|
1671
|
-
.debug=${!!this.config?.debug}
|
|
1672
|
-
.theme=${this.config?.theme}
|
|
1673
|
-
.amount=${Number(this.config?.priceUsd||0)}
|
|
1674
|
-
.ledgerSymbol=${this.selectedSymbol||"ICP"}
|
|
1675
|
-
></icpay-progress-bar>
|
|
1676
|
-
`:null}
|
|
1677
|
-
<div class="container">
|
|
1678
|
-
<div class="title">${this.title}</div>
|
|
1679
|
-
<div class="preview">${this.preview}</div>
|
|
1680
|
-
<div class="${this.unlocked?"unlocked":"locked"}">${this.unlocked?this.lockedContent:this.obfuscatedLockedContent}</div>
|
|
1681
|
-
</div>
|
|
1682
|
-
|
|
1683
|
-
<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()}>
|
|
1684
|
-
${this.unlocked?"Unlocked":this.processing?"Processing\u2026":(this.config?.buttonLabel||"Pay ${amount} with crypto").replace("{amount}",`${Number(this.config?.priceUsd??0).toFixed(2)}`).replace("{symbol}",this.selectedSymbol||"ICP")}
|
|
1685
|
-
</button>
|
|
1686
|
-
|
|
1687
|
-
${this.errorMessage?ye`
|
|
1688
|
-
<div class="error-message ${this.errorSeverity}" style="margin-top: 12px; padding: 8px 12px; border-radius: 6px; font-size: 14px; text-align: center;">
|
|
1689
|
-
${this.errorMessage}
|
|
1690
|
-
${this.errorAction?ye`
|
|
1691
|
-
<button style="margin-left: 8px; padding: 4px 8px; background: transparent; border: 1px solid currentColor; border-radius: 4px; font-size: 12px; cursor: pointer;">
|
|
1692
|
-
${this.errorAction}
|
|
1693
|
-
</button>
|
|
1694
|
-
`:""}
|
|
1695
|
-
</div>
|
|
1696
|
-
`:""}
|
|
1697
|
-
${(()=>{let e=this.pnp?.getEnabledWallets?.()||[],t=H(e),n=this.config?.theme?typeof this.config.theme=="string"?this.config.theme:this.config.theme.mode||"light":void 0;return G({visible:!!(this.showWalletModal&&this.pnp),wallets:t,isConnecting:!1,step:this.walletModalStep,balances:this.walletModalStep==="balances"?this.walletBalances:[],balancesLoading:this.walletModalStep==="balances"?this.balancesLoading:!1,balancesError:this.walletModalStep==="balances"?this.balancesError:null,onSelectBalance:a=>this.onSelectBalanceSymbol(a),onBack:()=>{this.walletModalStep="connect"},onSelect:a=>this.connectWithWallet(a),onClose:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-cancelled",{detail:{reason:"user_cancelled"}}))}catch{}},onDismiss:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1},onCreditCard:this.config?.onramp?.enabled===!0&&this.config?.onrampDisabled!==!0?()=>this.startOnramp():void 0,creditCardLabel:this.config?.onramp?.creditCardLabel||"Pay with credit card",showCreditCard:this.config?.onramp?.enabled===!0&&this.config?.onrampDisabled!==!0,creditCardTooltip:(()=>{let r=Number(this.config?.priceUsd||0);return r>0&&r<5&&this.config?.onramp?.enabled===!0&&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.unlock()},theme:n})})()}
|
|
1698
|
-
|
|
1699
|
-
${(()=>{let e=this.config?.theme?typeof this.config.theme=="string"?this.config.theme:this.config.theme.mode||"light":void 0;return ye`
|
|
1700
|
-
${Q({visible:this.showBalanceModal,isLoading:this.balancesLoading,error:this.balancesError,balances:this.walletBalances,onSelect:t=>this.onSelectBalanceSymbol(t),onClose:()=>{this.showBalanceModal=!1},theme:e})}
|
|
1701
|
-
|
|
1702
|
-
${q({visible:this.showOnrampModal,url:this.onrampUrl||void 0,errorMessage:this.onrampErrorMessage||void 0,width:this.config?.onramp?.width,height:this.config?.onramp?.height,onClose:()=>{this.showOnrampModal=!1},onBack:()=>{this.showOnrampModal=!1,this.showWalletModal=!0},title:"Pay with credit card",theme:e})}
|
|
1703
|
-
`})()}
|
|
1704
|
-
<div class="icpay-powered-by">
|
|
1705
|
-
<a href="https://icpay.org" target="_blank" rel="noopener noreferrer">Powered by icpay</a>
|
|
1706
|
-
</div>
|
|
1707
|
-
</div>
|
|
1708
|
-
`:ye`<div class="icpay-card icpay-section">Loading...</div>`}};E.styles=[K,St`
|
|
1709
|
-
.container { background: var(--icpay-surface-alt); border: 1px solid var(--icpay-border); border-radius: 16px; padding: 16px; margin-bottom: 16px; }
|
|
1710
|
-
.title { color: var(--icpay-text); font-weight: 700; margin-bottom: 8px; }
|
|
1711
|
-
.preview { color: var(--icpay-muted-foreground); margin-bottom: 12px; line-height: 1.6; }
|
|
1712
|
-
.locked { filter: blur(3px); color: #6b7280; margin-bottom: 12px; }
|
|
1713
|
-
.unlocked { filter: blur(0); color: var(--icpay-text); }
|
|
1714
|
-
.crypto-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0 16px; }
|
|
1715
|
-
.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; }
|
|
1716
|
-
.crypto-option.selected { background: var(--icpay-primary); color: #111827; border-color: var(--icpay-primary); }
|
|
1717
|
-
|
|
1718
|
-
.error-message {
|
|
1719
|
-
border: 1px solid;
|
|
1720
|
-
font-weight: 500;
|
|
1721
|
-
}
|
|
1722
|
-
|
|
1723
|
-
.error-message.info {
|
|
1724
|
-
background: var(--icpay-processing-bg);
|
|
1725
|
-
border-color: var(--icpay-processing-border);
|
|
1726
|
-
color: var(--icpay-processing-text);
|
|
1727
|
-
}
|
|
1728
|
-
|
|
1729
|
-
.error-message.warning {
|
|
1730
|
-
background: var(--icpay-warning-bg);
|
|
1731
|
-
border-color: var(--icpay-warning-border);
|
|
1732
|
-
color: var(--icpay-warning-text);
|
|
1733
|
-
}
|
|
1734
|
-
|
|
1735
|
-
.error-message.error {
|
|
1736
|
-
background: var(--icpay-error-bg);
|
|
1737
|
-
border-color: var(--icpay-error-border);
|
|
1738
|
-
color: var(--icpay-error-text);
|
|
1739
|
-
}
|
|
1740
|
-
`],s([Te({type:Object})],E.prototype,"config",2),s([Te({type:String})],E.prototype,"title",2),s([Te({type:String})],E.prototype,"preview",2),s([Te({type:String})],E.prototype,"lockedContent",2),s([B()],E.prototype,"selectedSymbol",2),s([B()],E.prototype,"unlocked",2),s([B()],E.prototype,"succeeded",2),s([B()],E.prototype,"processing",2),s([B()],E.prototype,"errorMessage",2),s([B()],E.prototype,"errorSeverity",2),s([B()],E.prototype,"errorAction",2),s([B()],E.prototype,"walletConnected",2),s([B()],E.prototype,"pendingAction",2),s([B()],E.prototype,"showWalletModal",2),s([B()],E.prototype,"walletModalStep",2),s([B()],E.prototype,"oisyReadyToPay",2),s([B()],E.prototype,"lastWalletId",2),s([B()],E.prototype,"showOnrampModal",2),s([B()],E.prototype,"onrampUrl",2),s([B()],E.prototype,"onrampPaymentIntentId",2),s([B()],E.prototype,"onrampErrorMessage",2),s([B()],E.prototype,"showBalanceModal",2),s([B()],E.prototype,"balancesLoading",2),s([B()],E.prototype,"balancesError",2),s([B()],E.prototype,"walletBalances",2),E=s([Mt("icpay-article-paywall")],E);import{LitElement as Wt,html as se,css as At}from"lit";import{customElement as Ct,property as Lt,state as R}from"lit/decorators.js";var Ke=typeof window<"u",Oe=null;function Ee(i,c,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${c}`,e):console.log(`[ICPay Widget] ${c}`))}var T=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.walletModalStep="connect";this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.showOnrampModal=!1;this.onrampUrl=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.transakMessageHandlerBound=null;this.onrampPollTimer=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.sdk=null;this.showBalanceModal=!1;this.balancesLoading=!1;this.balancesError=null;this.walletBalances=[];this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="order",this.showWalletModal=!0,this.requestUpdate();try{let t=Number(this.selectedItem?.priceUsd||0),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),this.showBalanceModal=!1,this.showWalletModal=!1,z(this.lastWalletId)){let a=(this.walletBalances||[]).find(o=>o?.tokenShortcode===e),r=a?.chainId;V(r,{provider:this.pnp?.getEvmProvider?.()||this.config?.evmProvider,chainName:a?.chainName,rpcUrlPublic:a?.rpcUrlPublic,nativeSymbol:a?.ledgerSymbol,decimals:a?.decimals}).then(async()=>{try{let o=x(this.config),l=Number(this.selectedItem?.priceUsd||0);if(a?.x402Accepts)try{await o.client.createPaymentX402Usd({usdAmount:l,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"evm",icpay_ledger_id:a?.ledgerId,icpay_context:"coffee:x402",item:this.selectedItem?.name}},recipientAddress:(this.config?.recipientAddresses||{})?.evm||"0x0000000000000000000000000000000000000000"}),this.showBalanceModal=!1;return}catch(p){g(p,{onError:h=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:h,bubbles:!0})),f(h)&&(this.errorMessage=u(h),this.errorSeverity=b(h),this.errorAction=v(h))}})}await o.client.createPaymentUsd({usdAmount:l,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"evm",icpay_ledger_id:a?.ledgerId,item:this.selectedItem?.name}},recipientAddress:(this.config?.recipientAddresses||{})?.evm||"0x0000000000000000000000000000000000000000"}).catch(p=>{throw p})}catch(o){g(o,{onError:l=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:l,bubbles:!0})),f(l)&&(this.errorMessage=u(l),this.errorSeverity=b(l),this.errorAction=v(l))}})}this.showBalanceModal=!1});return}let n=this.pendingAction;if(this.pendingAction=null,n==="order")try{let a=(this.walletBalances||[]).find(m=>m?.tokenShortcode===e),r=x(this.config),o=Number(this.selectedItem?.priceUsd||0),l=String(a?.ledgerName||a?.chainName||"").toLowerCase(),p=l.includes("sol"),h=l.includes("ic"),d=this.config?.recipientAddresses||{},y=p&&d.sol||d.ic;if(a?.x402Accepts)try{await r.client.createPaymentX402Usd({usdAmount:o,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:p?"sol":h?"ic":this.config?.icpay_network,icpay_ledger_id:a?.ledgerId,icpay_context:"coffee:x402",item:this.selectedItem?.name}},recipientAddress:y||""});return}catch(m){g(m,{onError:w=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:w,bubbles:!0})),f(w)&&(this.errorMessage=u(w),this.errorSeverity=b(w),this.errorAction=v(w))}});return}await r.client.createPaymentUsd({usdAmount:o,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"ic",icpay_ledger_id:a?.ledgerId,item:this.selectedItem?.name}},recipientAddress:y||"0x0000000000000000000000000000000000000000"}).catch(m=>{throw m})}catch(a){g(a,{onError:r=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:r,bubbles:!0})),f(r)&&(this.errorMessage=u(r),this.errorSeverity=b(r),this.errorAction=v(r))}})}}}connectedCallback(){if(super.connectedCallback(),!!Ke){Ee(this.config?.debug||!1,"Coffee shop connected",{config:this.config}),this.config&&typeof this.config.defaultItemIndex=="number"&&(this.selectedIndex=this.config.defaultItemIndex);try{window.addEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}try{window.addEventListener("icpay-sdk-transaction-created",(()=>{this.showWalletModal=!1,this.requestUpdate()}))}catch{}}}updated(e){if(e.has("config")&&this.pendingAction&&this.config?.actorProvider){let t=this.pendingAction;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}this.walletModalStep!=="balances"&&!this.oisyReadyToPay&&(this.pendingAction=null,setTimeout(()=>{t==="order"&&this.order()},0))}}selectItem(e){this.selectedIndex=e}selectSymbol(e){this.selectedSymbol=e}get selectedItem(){return this.config?.items?.[this.selectedIndex]||{name:"Loading...",priceUsd:0}}resetPaymentFlow(){Z(this,{pendingAction:"order"})}async order(){if(Ke){this.resetPaymentFlow(),Ee(this.config?.debug||!1,"Coffee order started",{selectedItem:this.selectedItem,selectedSymbol:this.selectedSymbol,useOwnWallet:this.config.useOwnWallet});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){Ee(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{Oe||(Oe=(await import("./wallet-select-BEKXSS66.js")).WalletSelect);let t=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab)?D({...this.config?.plugNPlay||{}}):{...this.config?.plugNPlay||{}},n=this.config?.recipientAddresses;if(n&&(n.ic||n.evm||n.sol)){let r=[];n.ic&&r.push("ic"),n.evm&&r.push("evm"),n.sol&&r.push("sol"),r.length&&(t.chainTypes=r)}else this.config?.chainTypes&&(t.chainTypes=this.config.chainTypes);try{if(typeof window<"u"){let{resolveDerivationOrigin:r}=await import("./origin-44ZEXSX4.js");t.derivationOrigin=this.config?.derivationOrigin||r()}}catch{}this.pnp=new Oe(t);try{let r=await ae(this.pnp);if(r){this.walletConnected=!0;let o=I(this.pnp,{owner:r,principal:r,connected:!0}),l=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:o,actorProvider:(p,h)=>this.pnp.getActor({canisterId:p,idl:h,requiresSigning:!0,anon:!1}),...l?{evmProvider:l}:{}},this.sdk=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"oisy"}}))}catch{}this.order();return}}catch{}let a=this.pnp.getEnabledWallets();if(Ee(this.config?.debug||!1,"Available wallets",a),!a?.length)throw new Error("No wallets available");this.pendingAction="order",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.pendingAction="order",this.showWalletModal=!0,await this.fetchAndShowBalances();return}catch(e){g(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),f(t)&&(this.errorMessage=u(t),this.errorSeverity=b(t),this.errorAction=v(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 t=await x(this.config).startOnrampUsd(this.selectedItem.priceUsd,void 0,{context:"coffee:onramp",onrampPayment:!0,item:this.selectedItem.name,onrampProvider:"coinbase"}),n=t?.metadata?.onramp?.url||t?.onramp?.url||t?.metadata?.icpay_onramp?.url||t?.paymentIntent?.metadata?.icpay?.onrampUrl||t?.metadata?.icpay?.onrampUrl||null,a=t?.metadata?.icpay_payment_intent_id||t?.metadata?.paymentIntentId||t?.paymentIntentId||null,r=t?.metadata?.icpay_onramp?.errorMessage||t?.metadata?.onramp?.errorMessage||t?.paymentIntent?.metadata?.icpay?.onrampError||t?.paymentIntent?.metadata?.icpay?.errorMessage||t?.metadata?.icpay?.onrampError||t?.metadata?.icpay?.errorMessage||null;if(this.onrampPaymentIntentId=a,n){this.onrampUrl=n,this.onrampErrorMessage=null;try{window.open(n,"icpay_onramp","noopener,noreferrer");try{window.dispatchEvent(new CustomEvent("icpay-onramp-opened",{detail:{url:n}}))}catch{}}catch{}this.startOnrampPolling()}else this.onrampUrl=null,this.onrampErrorMessage=r||"Failed to obtain onramp URL",this.showOnrampModal=!0}catch(e){this.onrampUrl=null,this.onrampErrorMessage=e?.message||"Failed to obtain onramp URL",this.showOnrampModal=!0}}startOnrampPolling(e){if(this.onrampPollTimer){try{clearInterval(this.onrampPollTimer)}catch{}this.onrampPollTimer=null}if(this.onrampNotifyController){try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null}let t=this.onrampPaymentIntentId;if(!t)return;let n=x(this.config),a=()=>{if(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=I(this.pnp,n),o=this.pnp?.getEvmProvider?.(),l=this.pnp?.getSolanaProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(p,h)=>this.pnp.getActor({canisterId:p,idl:h,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{},...l?{solanaProvider:l}:{}},this.sdk=null,this.walletModalStep="balances",this.showBalanceModal=!1,this.showWalletModal=!0,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.walletModalStep="balances",this.showBalanceModal=!1;let e=x(this.config),{balances:t}=await X({sdk:e,lastWalletId:this.lastWalletId,connectedWallet:this.config?.connectedWallet,amountUsd:Number(this.selectedItem?.priceUsd??0),chainShortcodes:this.config?.chainShortcodes,tokenShortcodes:this.config?.tokenShortcodes});this.walletBalances=t}catch(e){this.walletBalances=[],this.balancesError=e&&(e.message||String(e))||"Failed to load balances"}finally{this.balancesLoading=!1}}render(){return this.config?se`
|
|
1741
|
-
<div class="icpay-card icpay-section icpay-widget-base">
|
|
1742
|
-
${this.config?.progressBar?.enabled!==!1?se`
|
|
1743
|
-
<icpay-progress-bar
|
|
1744
|
-
.debug=${!!this.config?.debug}
|
|
1745
|
-
.theme=${this.config?.theme}
|
|
1746
|
-
.amount=${Number(this.selectedItem?.priceUsd||0)}
|
|
1747
|
-
.ledgerSymbol=${this.selectedSymbol||"ICP"}
|
|
1748
|
-
></icpay-progress-bar>
|
|
1749
|
-
`:null}
|
|
1750
|
-
<div class="menu">
|
|
1751
|
-
${this.config.items.map((e,t)=>se`
|
|
1752
|
-
<div class="item ${this.selectedIndex===t?"selected":""}" @click=${()=>this.selectItem(t)}>
|
|
1753
|
-
<span>${e.name}</span>
|
|
1754
|
-
<span>$${Number(e?.priceUsd??0).toFixed(2)}</span>
|
|
1755
|
-
</div>
|
|
1756
|
-
`)}
|
|
1757
|
-
</div>
|
|
1758
|
-
|
|
1759
|
-
<div class="total">Order Total: $${Number(this.selectedItem?.priceUsd??0).toFixed(2)}</div>
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
<button class="pay-button ${this.processing?"processing":""}" ?disabled=${this.processing} @click=${()=>this.order()}>
|
|
1764
|
-
${this.processing?"Processing\u2026":`Order ${this.selectedItem.name}`}
|
|
1765
|
-
</button>
|
|
1766
|
-
|
|
1767
|
-
${this.errorMessage?se`
|
|
1768
|
-
<div class="error-message ${this.errorSeverity}" style="margin-top: 12px; padding: 8px 12px; border-radius: 6px; font-size: 14px; text-align: center;">
|
|
1769
|
-
${this.errorMessage}
|
|
1770
|
-
${this.errorAction?se`
|
|
1771
|
-
<button style="margin-left: 8px; padding: 4px 8px; background: transparent; border: 1px solid currentColor; border-radius: 4px; font-size: 12px; cursor: pointer;">
|
|
1772
|
-
${this.errorAction}
|
|
1773
|
-
</button>
|
|
1774
|
-
`:""}
|
|
1775
|
-
</div>
|
|
1776
|
-
`:""}
|
|
1777
|
-
${(()=>{let e=this.pnp?.getEnabledWallets?.()||[],t=H(e),n=this.config?.theme?typeof this.config.theme=="string"?this.config.theme:this.config.theme.mode||"light":void 0;return G({visible:!!(this.showWalletModal&&this.pnp),wallets:t,isConnecting:!1,step:this.walletModalStep,balances:this.walletModalStep==="balances"?this.walletBalances:[],balancesLoading:this.walletModalStep==="balances"?this.balancesLoading:!1,balancesError:this.walletModalStep==="balances"?this.balancesError:null,onSelectBalance:a=>this.onSelectBalanceSymbol(a),onBack:()=>{this.walletModalStep="connect"},onSwitchAccount:()=>this.onSwitchAccount(null),onSelect:a=>this.connectWithWallet(a),onClose:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-cancelled",{detail:{reason:"user_cancelled"}}))}catch{}},onDismiss:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1},onCreditCard:this.config?.onramp?.enabled===!0&&this.config?.onrampDisabled!==!0?()=>this.startOnramp():void 0,creditCardLabel:this.config?.onramp?.creditCardLabel||"Pay with credit card",showCreditCard:this.config?.onramp?.enabled===!0&&this.config?.onrampDisabled!==!0,creditCardTooltip:(()=>{let r=this.config?.defaultItemIndex??0,o=Number(this.config?.items?.[r]?.priceUsd||0);return o>0&&o<5&&this.config?.onramp?.enabled===!0&&this.config?.onrampDisabled!==!0?`Note: Minimum card amount is $5. You will pay about $${(5-o).toFixed(2)} more.`:null})(),oisyReadyToPay:this.oisyReadyToPay,onOisyPay:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1,this.order()},theme:n})})()}
|
|
1778
|
-
|
|
1779
|
-
${(()=>{let e=this.config?.theme?typeof this.config.theme=="string"?this.config.theme:this.config.theme.mode||"light":void 0;return se`
|
|
1780
|
-
${Q({visible:this.showBalanceModal,isLoading:this.balancesLoading,error:this.balancesError,balances:this.walletBalances,onSelect:t=>this.onSelectBalanceSymbol(t),onClose:()=>{this.showBalanceModal=!1},theme:e})}
|
|
1781
|
-
|
|
1782
|
-
${q({visible:this.showOnrampModal,url:this.onrampUrl||void 0,errorMessage:this.onrampErrorMessage||void 0,width:this.config?.onramp?.width,height:this.config?.onramp?.height,onClose:()=>{this.showOnrampModal=!1},onBack:()=>{this.showOnrampModal=!1,this.showWalletModal=!0},title:"Pay with credit card",theme:e})}
|
|
1783
|
-
`})()}
|
|
1784
|
-
<div class="icpay-powered-by">
|
|
1785
|
-
<a href="https://icpay.org" target="_blank" rel="noopener noreferrer">Powered by icpay</a>
|
|
1786
|
-
</div>
|
|
1787
|
-
</div>
|
|
1788
|
-
`:se`<div class="icpay-card icpay-section">Loading...</div>`}};T.styles=[K,At`
|
|
1789
|
-
.menu { display: grid; gap: 8px; margin-bottom: 12px; }
|
|
1790
|
-
.item { background: var(--icpay-surface-alt); border: 2px solid var(--icpay-border); border-radius: 12px; padding: 16px; display:flex; justify-content: space-between; align-items:center; cursor: pointer; color: var(--icpay-text); font-weight: 600; }
|
|
1791
|
-
.item.selected { background: var(--icpay-primary); color: #111827; border-color: var(--icpay-primary); }
|
|
1792
|
-
.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); }
|
|
1793
|
-
.crypto-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0 16px; }
|
|
1794
|
-
.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; }
|
|
1795
|
-
.crypto-option.selected { background: var(--icpay-primary); color: #111827; border-color: var(--icpay-primary); }
|
|
1796
|
-
|
|
1797
|
-
.error-message {
|
|
1798
|
-
border: 1px solid;
|
|
1799
|
-
font-weight: 500;
|
|
1800
|
-
}
|
|
1801
|
-
|
|
1802
|
-
.error-message.info {
|
|
1803
|
-
background: var(--icpay-processing-bg);
|
|
1804
|
-
border-color: var(--icpay-processing-border);
|
|
1805
|
-
color: var(--icpay-processing-text);
|
|
1806
|
-
}
|
|
1807
|
-
|
|
1808
|
-
.error-message.warning {
|
|
1809
|
-
background: var(--icpay-warning-bg);
|
|
1810
|
-
border-color: var(--icpay-warning-border);
|
|
1811
|
-
color: var(--icpay-warning-text);
|
|
1812
|
-
}
|
|
1813
|
-
|
|
1814
|
-
.error-message.error {
|
|
1815
|
-
background: var(--icpay-error-bg);
|
|
1816
|
-
border-color: var(--icpay-error-border);
|
|
1817
|
-
color: var(--icpay-error-text);
|
|
1818
|
-
}
|
|
1819
|
-
`],s([Lt({type:Object})],T.prototype,"config",2),s([R()],T.prototype,"selectedIndex",2),s([R()],T.prototype,"selectedSymbol",2),s([R()],T.prototype,"processing",2),s([R()],T.prototype,"errorMessage",2),s([R()],T.prototype,"errorSeverity",2),s([R()],T.prototype,"errorAction",2),s([R()],T.prototype,"walletConnected",2),s([R()],T.prototype,"pendingAction",2),s([R()],T.prototype,"showWalletModal",2),s([R()],T.prototype,"walletModalStep",2),s([R()],T.prototype,"oisyReadyToPay",2),s([R()],T.prototype,"lastWalletId",2),s([R()],T.prototype,"showOnrampModal",2),s([R()],T.prototype,"onrampUrl",2),s([R()],T.prototype,"onrampPaymentIntentId",2),s([R()],T.prototype,"onrampErrorMessage",2),s([R()],T.prototype,"showBalanceModal",2),s([R()],T.prototype,"balancesLoading",2),s([R()],T.prototype,"balancesError",2),s([R()],T.prototype,"walletBalances",2),T=s([Ct("icpay-coffee-shop")],T);import{LitElement as Tt,html as oe,css as Ut}from"lit";import{customElement as Pt,property as Ot,state as O}from"lit/decorators.js";var qe=typeof window<"u",ue=null;function ke(i,c,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${c}`,e):console.log(`[ICPay Widget] ${c}`))}var A=class extends Tt{constructor(){super(...arguments);this.selectedAmount=10;this.selectedSymbol=null;this.raised=0;this.processing=!1;this.succeeded=!1;this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.walletModalStep="connect";this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.showOnrampModal=!1;this.onrampUrl=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.transakMessageHandlerBound=null;this.onrampPollTimer=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.sdk=null;this.showBalanceModal=!1;this.balancesLoading=!1;this.balancesError=null;this.walletBalances=[];this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="donate",this.showWalletModal=!0,this.requestUpdate();try{let t=Number(this.selectedAmount||0),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),this.showBalanceModal=!1,this.showWalletModal=!1,z(this.lastWalletId)){let a=(this.walletBalances||[]).find(o=>o?.tokenShortcode===e),r=a?.chainId;V(r,{provider:this.pnp?.getEvmProvider?.()||this.config?.evmProvider,chainName:a?.chainName,rpcUrlPublic:a?.rpcUrlPublic,nativeSymbol:a?.ledgerSymbol,decimals:a?.decimals}).then(async()=>{try{let o=x(this.config),l=Number(this.selectedAmount||0);if(a?.x402Accepts)try{await o.client.createPaymentX402Usd({usdAmount:l,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,icpay_network:"evm",icpay_ledger_id:a?.ledgerId,icpay_context:"donation:x402"},recipientAddress:(this.config?.recipientAddresses||{})?.evm||"0x0000000000000000000000000000000000000000"}),this.showBalanceModal=!1;return}catch(p){g(p,{onError:h=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:h,bubbles:!0})),f(h)&&(this.errorMessage=u(h),this.errorSeverity=b(h),this.errorAction=v(h))}})}await o.client.createPaymentUsd({usdAmount:l,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,icpay_network:"evm",icpay_ledger_id:a?.ledgerId},recipientAddress:(this.config?.recipientAddresses||{})?.evm||"0x0000000000000000000000000000000000000000"}).catch(p=>{throw p})}catch(o){g(o,{onError:l=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:l,bubbles:!0})),f(l)&&(this.errorMessage=u(l),this.errorSeverity=b(l),this.errorAction=v(l))}})}this.showBalanceModal=!1});return}let n=this.pendingAction;if(this.pendingAction=null,n==="donate")try{let a=(this.walletBalances||[]).find(y=>y?.tokenShortcode===e),r=x(this.config),o=Number(this.selectedAmount||0),p=String(a?.ledgerName||a?.chainName||"").toLowerCase().includes("sol"),h=this.config?.recipientAddresses||{},d=p&&h.sol||h.ic;if(p&&a?.x402Accepts)try{await r.client.createPaymentX402Usd({usdAmount:o,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"sol",icpay_ledger_id:a?.ledgerId,icpay_context:"donation:x402"}},recipientAddress:d||""});return}catch(y){g(y,{onError:m=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:m,bubbles:!0})),f(m)&&(this.errorMessage=u(m),this.errorSeverity=b(m),this.errorAction=v(m))}});return}await r.client.createPaymentUsd({usdAmount:o,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"ic",icpay_ledger_id:a?.ledgerId}},recipientAddress:d||"0x0000000000000000000000000000000000000000"}).catch(y=>{throw y})}catch(a){g(a,{onError:r=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:r,bubbles:!0})),f(r)&&(this.errorMessage=u(r),this.errorSeverity=b(r),this.errorAction=v(r))}})}}}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-BEKXSS66.js")).WalletSelect);let n=D({...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(),!!qe){ke(this.config?.debug||!1,"Donation thermometer connected",{config:this.config}),this.config&&typeof this.config.defaultAmountUsd=="number"&&(this.selectedAmount=this.config.defaultAmountUsd),this.tryAutoConnectPNP();try{window.addEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}try{window.addEventListener("icpay-sdk-transaction-created",(()=>{this.showWalletModal=!1,this.requestUpdate()}))}catch{}}}updated(e){if(e.has("config")&&this.pendingAction&&this.config?.actorProvider){let t=this.pendingAction;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}this.walletModalStep!=="balances"&&!this.oisyReadyToPay&&(this.pendingAction=null,setTimeout(()=>{t==="donate"&&this.donate()},0))}}selectAmount(e){this.selectedAmount=e}selectSymbol(e){this.selectedSymbol=e}get fillPercentage(){let e=Number(this.config?.goalUsd??1e3),t=e>0?e:1e3;return Math.min(this.raised/t*100,100)}resetPaymentFlow(){Z(this,{pendingAction:"donate"})}async donate(){if(qe){this.resetPaymentFlow(),ke(this.config?.debug||!1,"Donation started",{amount:this.selectedAmount,selectedSymbol:this.selectedSymbol,useOwnWallet:this.config.useOwnWallet});try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"donate",type:"sendUsd",amount:this.selectedAmount,currency:this.selectedSymbol||"ICP"}}))}catch{}this.processing=!0;try{if(this.config.useOwnWallet){if(!this.config.actorProvider){this.pendingAction="donate",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0}));return}}else if(!this.walletConnected){ke(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{ue||(ue=(await import("./wallet-select-BEKXSS66.js")).WalletSelect);let t=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab)?D({...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 ae(this.pnp);if(a){this.walletConnected=!0;let r=I(this.pnp,{owner:a,principal:a,connected:!0}),o=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(l,p)=>this.pnp.getActor({canisterId:l,idl:p,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{}},this.sdk=null;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"oisy"}}))}catch{}this.donate();return}}catch{}let n=this.pnp.getEnabledWallets();if(ke(this.config?.debug||!1,"Available wallets",n),!n?.length)throw new Error("No wallets available");this.pendingAction="donate",this.showWalletModal=!0;return}catch(e){ke(this.config?.debug||!1,"Wallet connection error:",e),this.errorMessage=e instanceof Error?e.message:"Wallet connection failed",this.errorSeverity="error";return}}this.showWalletModal=!0,await this.fetchAndShowBalances();return}catch(e){g(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),f(t)&&(this.errorMessage=u(t),this.errorSeverity=b(t),this.errorAction=v(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 t=await x(this.config).startOnrampUsd(this.selectedAmount,void 0,{context:"donation:onramp",onrampPayment:!0,onrampProvider:"coinbase"}),n=t?.metadata?.onramp?.url||t?.onramp?.url||t?.metadata?.icpay_onramp?.url||t?.paymentIntent?.metadata?.icpay?.onrampUrl||t?.metadata?.icpay?.onrampUrl||null,a=t?.metadata?.icpay_payment_intent_id||t?.metadata?.paymentIntentId||t?.paymentIntentId||null,r=t?.metadata?.icpay_onramp?.errorMessage||t?.metadata?.onramp?.errorMessage||t?.paymentIntent?.metadata?.icpay?.onrampError||t?.paymentIntent?.metadata?.icpay?.errorMessage||t?.metadata?.icpay?.onrampError||t?.metadata?.icpay?.errorMessage||null;if(this.onrampPaymentIntentId=a,n){this.onrampUrl=n,this.onrampErrorMessage=null;try{window.open(n,"icpay_onramp","noopener,noreferrer");try{window.dispatchEvent(new CustomEvent("icpay-onramp-opened",{detail:{url:n}}))}catch{}}catch{}this.startOnrampPolling()}else this.onrampUrl=null,this.onrampErrorMessage=r||"Failed to obtain onramp URL",this.showOnrampModal=!0}catch(e){this.onrampUrl=null,this.onrampErrorMessage=e?.message||"Failed to obtain onramp URL",this.showOnrampModal=!0}}startOnrampPolling(e){if(this.onrampPollTimer){try{clearInterval(this.onrampPollTimer)}catch{}this.onrampPollTimer=null}if(this.onrampNotifyController){try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null}let t=this.onrampPaymentIntentId;if(!t)return;let n=x(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=I(this.pnp,n),o=this.pnp?.getEvmProvider?.(),l=this.pnp?.getSolanaProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(p,h)=>this.pnp.getActor({canisterId:p,idl:h,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{},...l?{solanaProvider:l}:{}},this.sdk=null,this.walletModalStep="balances",this.showBalanceModal=!1,this.showWalletModal=!0,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.walletModalStep="balances",this.showBalanceModal=!1;let e=x(this.config),{balances:t}=await X({sdk:e,lastWalletId:this.lastWalletId,connectedWallet:this.config?.connectedWallet,amountUsd:Number(this.selectedAmount||0),chainShortcodes:this.config?.chainShortcodes,tokenShortcodes:this.config?.tokenShortcodes});this.walletBalances=t}catch(e){this.walletBalances=[],this.balancesError=e&&(e.message||String(e))||"Failed to load balances"}finally{this.balancesLoading=!1}}render(){return this.config?oe`
|
|
1820
|
-
<div class="icpay-card icpay-section icpay-widget-base" style="text-align:center;">
|
|
1821
|
-
${this.config?.progressBar?.enabled!==!1?oe`
|
|
1822
|
-
<icpay-progress-bar
|
|
1823
|
-
.debug=${!!this.config?.debug}
|
|
1824
|
-
.theme=${this.config?.theme}
|
|
1825
|
-
.amount=${Number(this.selectedAmount||0)}
|
|
1826
|
-
.ledgerSymbol=${this.selectedSymbol||"ICP"}
|
|
1827
|
-
></icpay-progress-bar>
|
|
1828
|
-
`:null}
|
|
1829
|
-
<div class="thermo"><div class="fill" style="height:${this.fillPercentage}%"></div></div>
|
|
1830
|
-
<div class="total">$${Number(this.raised).toFixed(0)} / $${Number(this.config?.goalUsd??0).toFixed(2)}</div>
|
|
1831
|
-
|
|
1832
|
-
<div class="amounts">
|
|
1833
|
-
${this.amounts.map(e=>oe`<div class="chip ${this.selectedAmount===e?"selected":""}" @click=${()=>this.selectAmount(e)}>$${e}</div>`)}
|
|
1834
|
-
</div>
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
<button class="pay-button ${this.processing?"processing":""}"
|
|
1839
|
-
?disabled=${this.processing||this.config?.disablePaymentButton===!0||this.succeeded&&this.config?.disableAfterSuccess===!0}
|
|
1840
|
-
@click=${()=>this.donate()}>
|
|
1841
|
-
${this.succeeded&&this.config?.disableAfterSuccess?"Donated":this.processing?"Processing\u2026":(this.config?.buttonLabel||"Donate {amount} with crypto").replace("{amount}",`${this.selectedAmount}`).replace("{symbol}",this.selectedSymbol||"ICP")}
|
|
1842
|
-
</button>
|
|
1843
|
-
|
|
1844
|
-
${this.errorMessage?oe`
|
|
1845
|
-
<div class="error-message ${this.errorSeverity}" style="margin-top: 12px; padding: 8px 12px; border-radius: 6px; font-size: 14px; text-align: center;">
|
|
1846
|
-
${this.errorMessage}
|
|
1847
|
-
${this.errorAction?oe`
|
|
1848
|
-
<button style="margin-left: 8px; padding: 4px 8px; background: transparent; border: 1px solid currentColor; border-radius: 4px; font-size: 12px; cursor: pointer;">
|
|
1849
|
-
${this.errorAction}
|
|
1850
|
-
</button>
|
|
1851
|
-
`:""}
|
|
1852
|
-
</div>
|
|
1853
|
-
`:""}
|
|
1854
|
-
${(()=>{let e=this.pnp?.getEnabledWallets?.()||[],t=H(e),n=this.config?.theme?typeof this.config.theme=="string"?this.config.theme:this.config.theme.mode||"light":void 0;return G({visible:!!(this.showWalletModal&&this.pnp),wallets:t,isConnecting:!1,step:this.walletModalStep,balances:this.walletModalStep==="balances"?this.walletBalances:[],balancesLoading:this.walletModalStep==="balances"?this.balancesLoading:!1,balancesError:this.walletModalStep==="balances"?this.balancesError:null,onSelectBalance:a=>this.onSelectBalanceSymbol(a),onBack:()=>{this.walletModalStep="connect"},onSwitchAccount:()=>this.onSwitchAccount(null),onSelect:a=>this.connectWithWallet(a),onClose:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-cancelled",{detail:{reason:"user_cancelled"}}))}catch{}},onDismiss:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1},onCreditCard:this.config?.onramp?.enabled===!0&&this.config?.onrampDisabled!==!0?()=>this.startOnramp():void 0,creditCardLabel:this.config?.onramp?.creditCardLabel||"Pay with credit card",showCreditCard:this.config?.onramp?.enabled===!0&&this.config?.onrampDisabled!==!0,creditCardTooltip:(()=>{let r=Number(this.selectedAmount||this.config?.defaultAmountUsd||0);return r>0&&r<5&&this.config?.onramp?.enabled===!0&&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.donate()},theme:n})})()}
|
|
1855
|
-
|
|
1856
|
-
${(()=>{let e=this.config?.theme?typeof this.config.theme=="string"?this.config.theme:this.config.theme.mode||"light":void 0;return oe`
|
|
1857
|
-
${Q({visible:this.showBalanceModal,isLoading:this.balancesLoading,error:this.balancesError,balances:this.walletBalances,onSelect:t=>this.onSelectBalanceSymbol(t),onClose:()=>{this.showBalanceModal=!1},theme:e})}
|
|
1858
|
-
|
|
1859
|
-
${q({visible:this.showOnrampModal,url:this.onrampUrl||void 0,errorMessage:this.onrampErrorMessage||void 0,width:this.config?.onramp?.width,height:this.config?.onramp?.height,onClose:()=>{this.showOnrampModal=!1},onBack:()=>{this.showOnrampModal=!1,this.showWalletModal=!0},title:"Pay with credit card",theme:e})}
|
|
1860
|
-
`})()}
|
|
1861
|
-
<div class="icpay-powered-by">
|
|
1862
|
-
<a href="https://icpay.org" target="_blank" rel="noopener noreferrer">Powered by icpay</a>
|
|
1863
|
-
</div>
|
|
1864
|
-
</div>
|
|
1865
|
-
`:oe`<div class="icpay-card icpay-section">Loading...</div>`}};A.styles=[K,Ut`
|
|
1866
|
-
.thermo { width: 60px; height: 200px; background: var(--icpay-surface-alt); border: 3px solid #6b7280; border-radius: 30px; margin: 0 auto 12px; position: relative; overflow: hidden; }
|
|
1867
|
-
.fill { position: absolute; bottom: 0; left: 0; right: 0; background: linear-gradient(135deg, #d1d5db 0%, #9ca3af 100%); transition: height 0.8s ease; height: 0%; border-radius: 0 0 27px 27px; }
|
|
1868
|
-
.amounts { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; margin: 12px 0; }
|
|
1869
|
-
.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; }
|
|
1870
|
-
.chip.selected { background: var(--icpay-primary); color: #111827; border-color: var(--icpay-primary); }
|
|
1871
|
-
.crypto-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0 16px; }
|
|
1872
|
-
.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; }
|
|
1873
|
-
.crypto-option.selected { background: var(--icpay-primary); color: #111827; border-color: var(--icpay-primary); }
|
|
1874
|
-
|
|
1875
|
-
.error-message {
|
|
1876
|
-
border: 1px solid;
|
|
1877
|
-
font-weight: 500;
|
|
1878
|
-
}
|
|
1879
|
-
|
|
1880
|
-
.error-message.info {
|
|
1881
|
-
background: var(--icpay-processing-bg);
|
|
1882
|
-
border-color: var(--icpay-processing-border);
|
|
1883
|
-
color: var(--icpay-processing-text);
|
|
1884
|
-
}
|
|
1885
|
-
|
|
1886
|
-
.error-message.warning {
|
|
1887
|
-
background: var(--icpay-warning-bg);
|
|
1888
|
-
border-color: var(--icpay-warning-border);
|
|
1889
|
-
color: var(--icpay-warning-text);
|
|
1890
|
-
}
|
|
1891
|
-
|
|
1892
|
-
.error-message.error {
|
|
1893
|
-
background: var(--icpay-error-bg);
|
|
1894
|
-
border-color: var(--icpay-error-border);
|
|
1895
|
-
color: var(--icpay-error-text);
|
|
1896
|
-
}
|
|
1897
|
-
`],s([Ot({type:Object})],A.prototype,"config",2),s([O()],A.prototype,"selectedAmount",2),s([O()],A.prototype,"selectedSymbol",2),s([O()],A.prototype,"raised",2),s([O()],A.prototype,"processing",2),s([O()],A.prototype,"succeeded",2),s([O()],A.prototype,"errorMessage",2),s([O()],A.prototype,"errorSeverity",2),s([O()],A.prototype,"errorAction",2),s([O()],A.prototype,"walletConnected",2),s([O()],A.prototype,"pendingAction",2),s([O()],A.prototype,"showWalletModal",2),s([O()],A.prototype,"walletModalStep",2),s([O()],A.prototype,"oisyReadyToPay",2),s([O()],A.prototype,"lastWalletId",2),s([O()],A.prototype,"showOnrampModal",2),s([O()],A.prototype,"onrampUrl",2),s([O()],A.prototype,"onrampPaymentIntentId",2),s([O()],A.prototype,"onrampErrorMessage",2),s([O()],A.prototype,"showBalanceModal",2),s([O()],A.prototype,"balancesLoading",2),s([O()],A.prototype,"balancesError",2),s([O()],A.prototype,"walletBalances",2),A=s([Pt("icpay-donation-thermometer")],A);import{LitElement as $t,html as ge,css as Bt}from"lit";import{customElement as It,property as Rt,state as U}from"lit/decorators.js";import{html as Ue}from"lit";function Nt(i){if(i==="light"||i==="dark")return i;if(typeof document>"u")return"light";let c=document.documentElement.getAttribute("data-icpay-theme");if(c==="light"||c==="dark")return c;let e=document.documentElement.getAttribute("data-theme");return e==="light"||e==="dark"?e:"light"}function He(i){if(!i.visible)return null;let c=i.providers||[],e=Nt(i.theme);return Ue`
|
|
1898
|
-
<style>
|
|
1899
|
-
/* Theme-aware color variables - Light mode defaults */
|
|
1900
|
-
.icpay-onramp-overlay {
|
|
1901
|
-
--icpay-background: #ffffff;
|
|
1902
|
-
--icpay-foreground: #171717;
|
|
1903
|
-
--icpay-muted-foreground: #6b7280;
|
|
1904
|
-
--icpay-primary: #3b82f6;
|
|
1905
|
-
--icpay-primary-foreground: #ffffff;
|
|
1906
|
-
--icpay-secondary: #f3f4f6;
|
|
1907
|
-
--icpay-secondary-foreground: #171717;
|
|
1908
|
-
--icpay-accent: #f9fafb;
|
|
1909
|
-
--icpay-border: #e5e7eb;
|
|
1910
|
-
}
|
|
1911
|
-
/* Dark mode */
|
|
1912
|
-
[data-theme="dark"] .icpay-onramp-overlay,
|
|
1913
|
-
[data-icpay-theme="dark"] .icpay-onramp-overlay,
|
|
1914
|
-
:root[data-theme="dark"] .icpay-onramp-overlay,
|
|
1915
|
-
:root[data-icpay-theme="dark"] .icpay-onramp-overlay,
|
|
1916
|
-
html[data-theme="dark"] .icpay-onramp-overlay,
|
|
1917
|
-
html[data-icpay-theme="dark"] .icpay-onramp-overlay,
|
|
1918
|
-
.icpay-onramp-overlay[data-theme="dark"] {
|
|
1919
|
-
--icpay-background: hsl(222.2 84% 4.9%);
|
|
1920
|
-
--icpay-foreground: hsl(210 40% 98%);
|
|
1921
|
-
--icpay-muted-foreground: hsl(215 20.2% 65.1%);
|
|
1922
|
-
--icpay-primary: hsl(210 40% 98%);
|
|
1923
|
-
--icpay-primary-foreground: hsl(222.2 47.4% 11.2%);
|
|
1924
|
-
--icpay-secondary: hsl(217.2 32.6% 17.5%);
|
|
1925
|
-
--icpay-secondary-foreground: hsl(210 40% 98%);
|
|
1926
|
-
--icpay-accent: hsl(217.2 32.6% 17.5%);
|
|
1927
|
-
--icpay-border: hsl(217.2 32.6% 30%);
|
|
1928
|
-
}
|
|
1929
|
-
.icpay-onramp-provider-btn {
|
|
1930
|
-
display: flex;
|
|
1931
|
-
align-items: center;
|
|
1932
|
-
gap: 10px;
|
|
1933
|
-
background: var(--icpay-secondary);
|
|
1934
|
-
border: 1px solid var(--icpay-border);
|
|
1935
|
-
border-radius: 10px;
|
|
1936
|
-
padding: 10px 12px;
|
|
1937
|
-
color: var(--icpay-foreground);
|
|
1938
|
-
cursor: pointer;
|
|
1939
|
-
text-align: left;
|
|
1940
|
-
transition: background-color 0.2s;
|
|
1941
|
-
}
|
|
1942
|
-
.icpay-onramp-provider-btn:hover {
|
|
1943
|
-
background: var(--icpay-accent);
|
|
1944
|
-
}
|
|
1945
|
-
.icpay-onramp-overlay {
|
|
1946
|
-
position: fixed !important;
|
|
1947
|
-
inset: 0 !important;
|
|
1948
|
-
display: flex;
|
|
1949
|
-
align-items: center;
|
|
1950
|
-
justify-content: center;
|
|
1951
|
-
background: rgba(0,0,0,0.85);
|
|
1952
|
-
backdrop-filter: blur(10px);
|
|
1953
|
-
z-index: 99999 !important;
|
|
1954
|
-
/* Ensure modal breaks out of any parent constraints */
|
|
1955
|
-
transform: none !important;
|
|
1956
|
-
will-change: auto;
|
|
1957
|
-
isolation: isolate;
|
|
1958
|
-
}
|
|
1959
|
-
.icpay-onramp-container {
|
|
1960
|
-
position: relative;
|
|
1961
|
-
background: var(--icpay-background);
|
|
1962
|
-
border: 1px solid var(--icpay-border);
|
|
1963
|
-
border-radius: 16px;
|
|
1964
|
-
padding: 16px;
|
|
1965
|
-
box-shadow: 0 20px 60px rgba(0,0,0,0.5);
|
|
1966
|
-
min-width: 320px;
|
|
1967
|
-
max-width: 420px;
|
|
1968
|
-
margin: auto;
|
|
1969
|
-
}
|
|
1970
|
-
@media (max-width: 768px) {
|
|
1971
|
-
.icpay-onramp-overlay {
|
|
1972
|
-
align-items: flex-end;
|
|
1973
|
-
justify-content: stretch;
|
|
1974
|
-
}
|
|
1975
|
-
.icpay-onramp-container {
|
|
1976
|
-
max-width: 100%;
|
|
1977
|
-
width: 100%;
|
|
1978
|
-
height: 70vh;
|
|
1979
|
-
max-height: 70vh;
|
|
1980
|
-
border-radius: 16px 16px 0 0;
|
|
1981
|
-
margin: 0;
|
|
1982
|
-
overflow-y: auto;
|
|
1983
|
-
}
|
|
1984
|
-
}
|
|
1985
|
-
</style>
|
|
1986
|
-
<div class="icpay-onramp-overlay" data-theme="${e}">
|
|
1987
|
-
<div class="icpay-onramp-container">
|
|
1988
|
-
<button @click=${i.onClose} style="position:absolute;right:12px;top:12px;background:transparent;border:none;color:var(--icpay-foreground);cursor:pointer;font-size:20px;opacity:0.8">×</button>
|
|
1989
|
-
<div style="color:var(--icpay-foreground);font-weight:600;font-size:16px;margin-bottom:12px">${i.title||"Choose a provider"}</div>
|
|
1990
|
-
<div style="display:flex;flex-direction:column;gap:10px">
|
|
1991
|
-
${c.map(t=>Ue`
|
|
1992
|
-
<button
|
|
1993
|
-
class="icpay-onramp-provider-btn"
|
|
1994
|
-
@click=${()=>i.onSelect(t.slug)}
|
|
1995
|
-
>
|
|
1996
|
-
${t.logoUrl?Ue`<img src="${t.logoUrl}" style="width:24px;height:24px;border-radius:4px" />`:Ue`<div style="width:24px;height:24px;border-radius:4px;background:var(--icpay-secondary)"></div>`}
|
|
1997
|
-
<span style="font-size:14px">${t.name}</span>
|
|
1998
|
-
</button>
|
|
1999
|
-
`)}
|
|
2000
|
-
</div>
|
|
2001
|
-
</div>
|
|
2002
|
-
</div>
|
|
2003
|
-
`}var Ve=typeof window<"u",fe=null;function _(i,c,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${c}`,e):console.log(`[ICPay Widget] ${c}`))}var k=class extends $t{constructor(){super(...arguments);this.selectedSymbol=null;this.processing=!1;this.succeeded=!1;this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.walletModalStep="connect";this.showOnrampModal=!1;this.onrampUrl=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.showProviderPicker=!1;this.selectedOnrampProvider=null;this.oisyReadyToPay=!1;this.oisySignerPreopened=!1;this.skipDisconnectOnce=!1;this.lastWalletId=null;this.showBalanceModal=!1;this.balancesLoading=!1;this.balancesError=null;this.walletBalances=[];this.onrampPollTimer=null;this.pnp=null;this.oisyConnectRetriedNewTab=!1;this.sdk=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="pay",this.walletModalStep="connect",this.showWalletModal=!0,this.oisyReadyToPay=!1,this.lastWalletId=null,this.requestUpdate();try{let t=Number(this.config?.amountUsd||0),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,z(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,{provider:this.pnp?.getEvmProvider?.()||this.config?.evmProvider,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),l=t?.ledgerSymbol,p=!!(t&&t.x402Accepts);if(_(this.config?.debug||!1,"EVM post-ensure chain snapshot",{targetChain:a,amountUsd:o,symbolNow:l,tryX402:p,x402Accepts:t?.x402Accepts}),p)try{let d=this.config?.recipientAddresses?.evm||"0x0000000000000000000000000000000000000000";_(this.config?.debug||!1,"Using recipientAddress (x402)",{recipientAddress:d});let y={...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"evm",icpay_ledger_id:t?.ledgerId,icpay_context:"pay-button:x402"}};_(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:y,recipientAddress:d});return}catch(d){_(this.config?.debug||!1,"X402 payment failed (EVM selection), falling back",{message:d?.message,code:d?.code,data:d?.details||d?.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});let h=this.config?.recipientAddresses?.evm||"0x0000000000000000000000000000000000000000";_(this.config?.debug||!1,"Using recipientAddress (normal)",{recipientAddress:h}),await r.client.createPaymentUsd({usdAmount:o,tokenShortcode:t?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"evm",icpay_ledger_id:t?.ledgerId}},recipientAddress:h}).catch(d=>{throw d})}catch(r){g(r,{onError:o=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:o,bubbles:!0})),f(o)&&(this.errorMessage=u(o),this.errorSeverity=b(o),this.errorAction=v(o))}})}});return}let n=this.pendingAction;if(this.pendingAction=null,n==="pay")try{let a=(this.walletBalances||[]).find(m=>m?.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});let l=String(a?.chainName||"").toLowerCase(),p=l.includes("sol"),h=this.config?.recipientAddresses||{},d=p?h.sol||h.ic||this.config?.recipientAddress:h.ic||this.config?.recipientAddress,y=l.includes("ic");if(a?.x402Accepts)try{let m={...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:p?"sol":y?"ic":this.config?.icpay_network,icpay_ledger_id:a?.ledgerId,icpay_context:"pay-button:x402"}};await r.client.createPaymentX402Usd({usdAmount:o,tokenShortcode:a?.tokenShortcode,metadata:m,recipientAddress:d||""});return}catch(m){_(this.config?.debug||!1,"X402 payment failed (SOL selection), falling back",{message:m?.message,code:m?.code,data:m?.details||m?.data});return}await r.client.createPaymentUsd({usdAmount:o,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"ic",icpay_ledger_id:a?.ledgerId}},recipientAddress:d||"0x0000000000000000000000000000000000000000"}).catch(m=>{throw m})}catch(a){g(a,{onError:r=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:r,bubbles:!0})),f(r)&&(this.errorMessage=u(r),this.errorSeverity=b(r),this.errorAction=v(r))}})}}}getSdk(){return this.sdk||(this.sdk=x(this.config)),this.sdk}connectedCallback(){if(super.connectedCallback(),!!Ve){_(this.config?.debug||!1,"Pay button connected",{config:this.config}),this.config?.theme&&ce(this,this.config.theme);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.config?.theme&&ce(this,this.config.theme),e.has("config")&&this.pendingAction&&this.config?.actorProvider){let t=this.pendingAction;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}this.walletModalStep!=="balances"&&!this.oisyReadyToPay&&(this.pendingAction=null,setTimeout(()=>{t==="pay"&&this.pay()},0))}e.has("config")&&(this.sdk=null)}selectSymbol(e){this.selectedSymbol=e}async ensureWallet(){if(this.config.useOwnWallet)return this.config.actorProvider?!0:(this.pendingAction="pay",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0})),!1);if(this.walletConnected)return!0;try{fe||(fe=(await import("./wallet-select-BEKXSS66.js")).WalletSelect);let e=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab),t={...this.config?.plugNPlay||{}},n=this.config?.recipientAddresses;if(n&&(n.ic||n.evm||n.sol)){let o=[];n.ic&&o.push("ic"),n.evm&&o.push("evm"),n.sol&&o.push("sol"),o.length&&(t.chainTypes=o)}else this.config?.chainTypes&&(t.chainTypes=this.config.chainTypes);let a=e?D(t):t;try{if(typeof window<"u"){let{resolveDerivationOrigin:o}=await import("./origin-44ZEXSX4.js");a.derivationOrigin=this.config?.derivationOrigin||o()}}catch{}this.pnp=new fe(a);let r=this.pnp.getEnabledWallets();if(_(this.config?.debug||!1,"Available wallets",r),!r?.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=I(this.pnp,n),o=this.pnp?.getEvmProvider?.(),l=this.pnp?.getSolanaProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(p,h)=>this.pnp.getActor({canisterId:p,idl:h,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{},...l?{solanaProvider:l}:{}},this.sdk=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{fe||(fe=(await import("./wallet-select-BEKXSS66.js")).WalletSelect);let l={...this.config?.plugNPlay||{}},p=this.config?.recipientAddresses;if(p&&(p.ic||p.evm||p.sol)){let y=[];p.ic&&y.push("ic"),p.evm&&y.push("evm"),p.sol&&y.push("sol"),y.length&&(l.chainTypes=y)}else this.config?.chainTypes&&(l.chainTypes=this.config.chainTypes);let h=D(l);try{if(typeof window<"u"){let{resolveDerivationOrigin:y}=await import("./origin-44ZEXSX4.js");h.derivationOrigin=this.config?.derivationOrigin||y()}}catch{}this.pnp=new fe(h),this.pnp.connect("oisy").then(y=>{if(!!!(y&&(y.connected===!0||y.principal||y.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"oisy"}}))}catch{}let w=I(this.pnp,y),J=this.pnp?.getEvmProvider?.();this.config={...this.config,connectedWallet:w,actorProvider:(Se,Me)=>this.pnp.getActor({canisterId:Se,idl:Me,requiresSigning:!0,anon:!1}),...J?{evmProvider:J}:{}},this.sdk=null,this.walletModalStep="balances",this.fetchAndShowBalances("pay")}).catch(y=>{_(this.config?.debug||!1,"Oisy retry connect (new tab) failed",y),this.errorMessage=y instanceof Error?y.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-error",{detail:{message:this.errorMessage,code:"WALLET_CONNECT_ERROR"}}))}catch{}})}catch(l){_(this.config?.debug||!1,"Oisy new-tab init failed",l),this.errorMessage=l instanceof Error?l.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1;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 X({sdk:t,lastWalletId:this.lastWalletId,connectedWallet:this.config?.connectedWallet,amountUsd:Number(this.config?.amountUsd??0),chainShortcodes:this.config?.chainShortcodes,tokenShortcodes:this.config?.tokenShortcodes});this.walletBalances=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=H(e),n=this.config?.onramp?.enabled===!0&&this.config?.onrampDisabled!==!0,a=2,r=Number(this.config?.amountUsd??0),o=n&&r>0&&r<a,l=Math.max(0,a-r),p=o?`Note: Minimum card amount is $${a}. You will pay about $${l.toFixed(2)} more.`:null,h=this.config?.theme?typeof this.config.theme=="string"?this.config.theme:this.config.theme.mode||"light":void 0;return G({visible:this.showWalletModal,wallets:t,isConnecting:!1,onSwitchAccount:()=>this.onSwitchAccount(null),step:this.walletModalStep,balances:this.walletModalStep==="balances"?this.walletBalances||[]:[],balancesLoading:this.walletModalStep==="balances"?this.balancesLoading:!1,balancesError:this.walletModalStep==="balances"?this.balancesError:null,onSelectBalance:d=>this.onSelectBalanceSymbol(d),onBack:()=>{this.walletModalStep="connect"},onSelect:d=>{this.connectWithWallet(d)},onClose:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-cancelled",{detail:{reason:"user_cancelled"}}))}catch{}},onDismiss:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1},onCreditCard:n?()=>this.startOnramp():void 0,creditCardLabel:this.config?.onramp?.creditCardLabel||"Pay with credit card",showCreditCard:n,creditCardTooltip:p,oisyReadyToPay:this.oisyReadyToPay,onOisyPay:()=>{this.showWalletModal=!1,this.skipDisconnectOnce=!0,this.oisyReadyToPay=!1,this.pay()},theme:h})}startOnramp(){try{window.dispatchEvent(new CustomEvent("icpay-sdk-method-start",{detail:{name:"createPaymentUsd",type:"onramp"}}))}catch{}this.showWalletModal=!1;let e=Array.isArray(this.config?.onramp?.providers)?this.config.onramp.providers.filter(n=>n&&n.enabled!==!1):[],t=e.length?e:[{slug:"coinbase",name:"Coinbase",enabled:!0}];t.length>1?this.showProviderPicker=!0:(this.selectedOnrampProvider=t[0]?.slug||"coinbase",setTimeout(()=>this.createOnrampIntent(),0))}async createOnrampIntent(){try{let e=Number(this.config?.amountUsd??0),t=this.getSdk();this.selectedSymbol||(this.selectedSymbol="ICP");let n=await t.startOnrampUsd(e,void 0,{context:"pay-button:onramp",onrampPayment:!0,onrampProvider:this.selectedOnrampProvider||"coinbase"}),a=n?.metadata?.onramp?.url||n?.onramp?.url||n?.metadata?.icpay_onramp?.url||n?.paymentIntent?.metadata?.icpay?.onrampUrl||n?.metadata?.icpay?.onrampUrl||null,r=n?.metadata?.icpay_onramp?.errorMessage||n?.metadata?.onramp?.errorMessage||n?.paymentIntent?.metadata?.icpay?.onrampError||n?.paymentIntent?.metadata?.icpay?.errorMessage||n?.metadata?.icpay?.onrampError||n?.metadata?.icpay?.errorMessage||null;this.onrampErrorMessage=r||null;let o=n?.metadata?.icpay_payment_intent_id||n?.metadata?.paymentIntentId||n?.paymentIntentId||null;if(this.onrampPaymentIntentId=o,a){this.onrampUrl=a;try{window.open(a,"icpay_onramp","noopener,noreferrer");try{window.dispatchEvent(new CustomEvent("icpay-onramp-opened",{detail:{url:a}}))}catch{}}catch{}this.startOnrampPolling(void 0)}else this.onrampUrl=null,this.showOnrampModal=!0}catch(e){this.onrampUrl=null,this.onrampErrorMessage=e?.message||null,this.showOnrampModal=!0,g(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),f(t)&&(this.errorMessage=u(t),this.errorSeverity=b(t),this.errorAction=v(t))}})}}startOnrampPolling(e){if(this.onrampPollTimer){try{clearInterval(this.onrampPollTimer)}catch{}this.onrampPollTimer=null}if(this.onrampNotifyController){try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null}let t=this.onrampPaymentIntentId;if(!t)return;let n=this.getSdk(),a=()=>{if(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}resetPaymentFlow(){Z(this,{pendingAction:"pay"})}async pay(){if(Ve){this.resetPaymentFlow();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(!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}),g(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),f(t)&&(this.errorMessage=u(t),this.errorSeverity=b(t),this.errorAction=v(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 ge`<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,l=this.showWalletModal||this.showBalanceModal;return ge`
|
|
2004
|
-
<div class="icpay-card icpay-section icpay-widget-base">
|
|
2005
|
-
${o?ge`
|
|
2006
|
-
<icpay-progress-bar
|
|
2007
|
-
.debug=${!!this.config?.debug}
|
|
2008
|
-
.theme=${this.config?.theme}
|
|
2009
|
-
.amount=${Number(this.config?.amountUsd||0)}
|
|
2010
|
-
.ledgerSymbol=${e}
|
|
2011
|
-
.suspended=${l}
|
|
2012
|
-
></icpay-progress-bar>
|
|
2013
|
-
`:null}
|
|
2014
|
-
|
|
2015
|
-
<div class="row single">
|
|
2016
|
-
<button class="pay-button ${this.processing?"processing":""}"
|
|
2017
|
-
?disabled=${this.processing||this.config?.disablePaymentButton===!0||this.succeeded&&this.config?.disableAfterSuccess===!0}
|
|
2018
|
-
@click=${()=>this.pay()}>
|
|
2019
|
-
${this.succeeded&&this.config?.disableAfterSuccess?"Paid":this.processing?"Processing\u2026":a}
|
|
2020
|
-
</button>
|
|
2021
|
-
</div>
|
|
2022
|
-
|
|
2023
|
-
${this.errorMessage?ge`
|
|
2024
|
-
<div class="error-message ${this.errorSeverity}" style="margin-top: 12px; padding: 8px 12px; border-radius: 6px; font-size: 14px; text-align: center;">
|
|
2025
|
-
${this.errorMessage}
|
|
2026
|
-
${this.errorAction?ge`<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>`:""}
|
|
2027
|
-
</div>
|
|
2028
|
-
`:""}
|
|
2029
|
-
${this.renderWalletModal()}
|
|
2030
|
-
${(()=>{let p=this.config?.theme?typeof this.config.theme=="string"?this.config.theme:this.config.theme.mode||"light":void 0;return ge`
|
|
2031
|
-
${Q({visible:this.showBalanceModal,isLoading:this.balancesLoading,error:this.balancesError,balances:this.walletBalances,onSelect:h=>this.onSelectBalanceSymbol(h),onClose:()=>{this.showBalanceModal=!1},theme:p})}
|
|
2032
|
-
${q({visible:this.showOnrampModal,url:this.onrampUrl||void 0,errorMessage:this.onrampErrorMessage||void 0,width:this.config?.onramp?.width,height:this.config?.onramp?.height,onClose:()=>{this.showOnrampModal=!1},onBack:()=>{this.showOnrampModal=!1,this.showWalletModal=!0},title:"Pay with credit card",theme:p})}
|
|
2033
|
-
${He({visible:this.showProviderPicker,providers:(()=>{let h=Array.isArray(this.config?.onramp?.providers)?this.config.onramp.providers.filter(y=>y&&y.enabled!==!1):[];return(h.length?h:[{slug:"coinbase",name:"Coinbase",enabled:!0}]).map(y=>({slug:y.slug,name:y.name||(y.slug==="coinbase"?"Coinbase":y.slug),logoUrl:y.logoUrl||null}))})(),onSelect:h=>{this.selectedOnrampProvider=h,this.showProviderPicker=!1,setTimeout(()=>this.createOnrampIntent(),0)},onClose:()=>{this.showProviderPicker=!1},title:"Choose onramp provider",theme:p})}
|
|
2034
|
-
`})()}
|
|
2035
|
-
<div class="icpay-powered-by">
|
|
2036
|
-
<a href="https://icpay.org" target="_blank" rel="noopener noreferrer">Powered by icpay</a>
|
|
2037
|
-
</div>
|
|
2038
|
-
</div>
|
|
2039
|
-
`}};k.styles=[K,Bt`
|
|
2040
|
-
.row { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; }
|
|
2041
|
-
.row.single { grid-template-columns: 1fr; }
|
|
2042
|
-
select { background: var(--icpay-surface-alt); border: 1px solid var(--icpay-border); color: var(--icpay-text); border-radius: 8px; padding: 10px; font-weight: 600; }
|
|
2043
|
-
.error-message { border: 1px solid; font-weight: 500; }
|
|
2044
|
-
.error-message.info { background: var(--icpay-processing-bg); border-color: var(--icpay-processing-border); color: var(--icpay-processing-text); }
|
|
2045
|
-
.error-message.warning { background: var(--icpay-warning-bg); border-color: var(--icpay-warning-border); color: var(--icpay-warning-text); }
|
|
2046
|
-
.error-message.error { background: var(--icpay-error-bg); border-color: var(--icpay-error-border); color: var(--icpay-error-text); }
|
|
2047
|
-
`],s([Rt({type:Object})],k.prototype,"config",2),s([U()],k.prototype,"selectedSymbol",2),s([U()],k.prototype,"processing",2),s([U()],k.prototype,"succeeded",2),s([U()],k.prototype,"errorMessage",2),s([U()],k.prototype,"errorSeverity",2),s([U()],k.prototype,"errorAction",2),s([U()],k.prototype,"walletConnected",2),s([U()],k.prototype,"pendingAction",2),s([U()],k.prototype,"showWalletModal",2),s([U()],k.prototype,"walletModalStep",2),s([U()],k.prototype,"showOnrampModal",2),s([U()],k.prototype,"onrampUrl",2),s([U()],k.prototype,"onrampPaymentIntentId",2),s([U()],k.prototype,"onrampErrorMessage",2),s([U()],k.prototype,"showProviderPicker",2),s([U()],k.prototype,"selectedOnrampProvider",2),s([U()],k.prototype,"oisyReadyToPay",2),s([U()],k.prototype,"oisySignerPreopened",2),s([U()],k.prototype,"skipDisconnectOnce",2),s([U()],k.prototype,"lastWalletId",2),s([U()],k.prototype,"showBalanceModal",2),s([U()],k.prototype,"balancesLoading",2),s([U()],k.prototype,"balancesError",2),s([U()],k.prototype,"walletBalances",2),k=s([It("icpay-pay-button")],k);import{LitElement as _t,html as ve,css as Ft}from"lit";import{customElement as Dt,property as zt,state as N}from"lit/decorators.js";var Xe=typeof window<"u",Ne=null;function jt(i,c,e){i&&(e!==void 0?console.log(`[ICPay Widget] ${c}`,e):console.log(`[ICPay Widget] ${c}`))}var C=class extends _t{constructor(){super(...arguments);this.amountUsd=0;this.hasUserAmount=!1;this.selectedSymbol=null;this.processing=!1;this.succeeded=!1;this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.walletModalStep="connect";this.showOnrampModal=!1;this.onrampUrl=null;this.onrampPaymentIntentId=null;this.onrampErrorMessage=null;this.oisyReadyToPay=!1;this.lastWalletId=null;this.pnp=null;this.transakMessageHandlerBound=null;this.onrampPollTimer=null;this.onrampPollingActive=!1;this.onrampNotifyController=null;this.showBalanceModal=!1;this.balancesLoading=!1;this.balancesError=null;this.walletBalances=[];this.sdk=null;this.onSwitchAccount=async e=>{try{if(this.pnp)try{await this.pnp.disconnect()}catch{}this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0},this.pendingAction="pay",this.showWalletModal=!0,this.requestUpdate();try{let t=Number(this.amountUsd||0),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,z(this.lastWalletId)){let a=(this.walletBalances||[]).find(o=>o?.tokenShortcode===e),r=a?.chainId;V(r,{provider:this.pnp?.getEvmProvider?.()||this.config?.evmProvider,chainName:a?.chainName,rpcUrlPublic:a?.rpcUrlPublic,nativeSymbol:a?.ledgerSymbol,decimals:a?.decimals}).then(async()=>{try{let o=x(this.config),l=Number(this.amountUsd||0);if(a?.x402Accepts)try{await o.client.createPaymentX402Usd({usdAmount:l,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,icpay_network:"evm",icpay_ledger_id:a?.ledgerId,icpay_context:"amount-input:x402"},recipientAddress:(this.config?.recipientAddresses||{})?.evm||"0x0000000000000000000000000000000000000000"}),this.showBalanceModal=!1;return}catch(p){g(p,{onError:h=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:h,bubbles:!0})),f(h)&&(this.errorMessage=u(h),this.errorSeverity=b(h),this.errorAction=v(h))}})}await o.client.createPaymentUsd({usdAmount:l,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,icpay_network:"evm",icpay_ledger_id:a?.ledgerId},recipientAddress:(this.config?.recipientAddresses||{})?.evm||"0x0000000000000000000000000000000000000000"}).catch(p=>{throw p})}catch(o){g(o,{onError:l=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:l,bubbles:!0})),f(l)&&(this.errorMessage=u(l),this.errorSeverity=b(l),this.errorAction=v(l))}})}this.showBalanceModal=!1});return}let n=this.pendingAction;if(this.pendingAction=null,n==="pay")try{let a=(this.walletBalances||[]).find(m=>m?.tokenShortcode===e),r=x(this.config),o=Number(this.amountUsd||0),l=String(a?.ledgerName||a?.chainName||"").toLowerCase(),p=l.includes("sol"),h=l.includes("ic"),d=this.config?.recipientAddresses||{},y=p&&d.sol||d.ic;if(a?.x402Accepts)try{let m={...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:p?"sol":h?"ic":this.config?.icpay_network,icpay_ledger_id:a?.ledgerId,icpay_context:"amount-input:x402"}};await r.client.createPaymentX402Usd({usdAmount:o,tokenShortcode:a?.tokenShortcode,metadata:m,recipientAddress:y||""});return}catch(m){g(m,{onError:w=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:w,bubbles:!0})),f(w)&&(this.errorMessage=u(w),this.errorSeverity=b(w),this.errorAction=v(w))}});return}await r.client.createPaymentUsd({usdAmount:o,tokenShortcode:a?.tokenShortcode,metadata:{...this.config?.metadata,icpay:{...(this.config?.metadata||{})?.icpay||{},icpay_network:"ic",icpay_ledger_id:a?.ledgerId}},recipientAddress:y||"0x0000000000000000000000000000000000000000"}).catch(m=>{throw m})}catch(a){g(a,{onError:r=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:r,bubbles:!0})),f(r)&&(this.errorMessage=u(r),this.errorSeverity=b(r),this.errorAction=v(r))}})}}}connectedCallback(){if(super.connectedCallback(),!!Xe){jt(this.config?.debug||!1,"Amount input connected",{config:this.config}),this.amountUsd=Number(this.config?.defaultAmountUsd??0),this.hasUserAmount=!1;try{window.addEventListener("icpay-switch-account",this.onSwitchAccount)}catch{}try{window.addEventListener("icpay-sdk-transaction-created",(()=>{this.showWalletModal=!1,this.requestUpdate()}))}catch{}}}updated(e){if(e.has("config")&&(!this.hasUserAmount&&typeof this.config?.defaultAmountUsd=="number"&&(this.amountUsd===0||this.amountUsd==null||Number.isNaN(this.amountUsd))&&(this.amountUsd=Number(this.config.defaultAmountUsd)),this.pendingAction&&this.config?.actorProvider)){let t=this.pendingAction;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-connected",{detail:{walletType:"external"}}))}catch{}this.walletModalStep!=="balances"&&(this.pendingAction=null,setTimeout(()=>{t==="pay"&&this.pay()},0))}}onInputChange(e){let t=Number(this.config?.stepUsd??.5),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{Ne||(Ne=(await import("./wallet-select-BEKXSS66.js")).WalletSelect);let e=!!(this.config?.openOisyInNewTab||this.config?.plugNPlay?.openOisyInNewTab),t={...this.config?.plugNPlay||{}},n=this.config?.recipientAddresses;if(n&&(n.ic||n.evm||n.sol)){let o=[];n.ic&&o.push("ic"),n.evm&&o.push("evm"),n.sol&&o.push("sol"),o.length&&(t.chainTypes=o)}else this.config?.chainTypes&&(t.chainTypes=this.config.chainTypes);let a=e?D(t):t;try{if(typeof window<"u"){let{resolveDerivationOrigin:o}=await import("./origin-44ZEXSX4.js");a.derivationOrigin=this.config?.derivationOrigin||o()}}catch{}if(this.pnp=new Ne(a),!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=I(this.pnp,n),o=this.pnp?.getEvmProvider?.(),l=this.pnp?.getSolanaProvider?.();this.config={...this.config,connectedWallet:r,actorProvider:(p,h)=>this.pnp.getActor({canisterId:p,idl:h,requiresSigning:!0,anon:!1}),...o?{evmProvider:o}:{},...l?{solanaProvider:l}:{}},this.sdk=null,this.walletModalStep="balances",this.showBalanceModal=!1,this.showWalletModal=!0,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.walletModalStep="balances",this.showBalanceModal=!1;let e=x(this.config),{balances:t}=await X({sdk:e,lastWalletId:this.lastWalletId,connectedWallet:this.config?.connectedWallet,amountUsd:Number(this.amountUsd??0),chainShortcodes:this.config?.chainShortcodes,tokenShortcodes:this.config?.tokenShortcodes});this.walletBalances=t}catch(e){this.walletBalances=[],this.balancesError=e&&(e.message||String(e))||"Failed to load balances"}finally{this.balancesLoading=!1}}attachTransakMessageListener(){if(!this.transakMessageHandlerBound){this.transakMessageHandlerBound=e=>this.onTransakMessage(e);try{window.addEventListener("message",this.transakMessageHandlerBound)}catch{}}}detachTransakMessageListener(){if(this.transakMessageHandlerBound){try{window.removeEventListener("message",this.transakMessageHandlerBound)}catch{}this.transakMessageHandlerBound=null}}onTransakMessage(e){let t=e?.data,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=x(this.config),t=Number(this.amountUsd),n=await e.startOnrampUsd(t,void 0,{context:"amount-input:onramp",onrampPayment:!0,onrampProvider:this?.selectedOnrampProvider||"coinbase"}),a=n?.metadata?.onramp?.url||n?.onramp?.url||n?.metadata?.icpay_onramp?.url||n?.paymentIntent?.metadata?.icpay?.onrampUrl||n?.metadata?.icpay?.onrampUrl||null,r=n?.metadata?.icpay_payment_intent_id||n?.metadata?.paymentIntentId||n?.paymentIntentId||null,o=n?.metadata?.icpay_onramp?.errorMessage||n?.metadata?.onramp?.errorMessage||null;if(this.onrampPaymentIntentId=r,a){this.onrampUrl=a,this.onrampErrorMessage=null;try{window.open(a,"icpay_onramp","noopener,noreferrer");try{window.dispatchEvent(new CustomEvent("icpay-onramp-opened",{detail:{url:a}}))}catch{}}catch{}this.startOnrampPolling()}else this.onrampUrl=null,this.onrampErrorMessage=o||"Failed to obtain onramp sessionId",this.showOnrampModal=!0}catch(e){this.onrampUrl=null,this.onrampErrorMessage=e?.message||"Failed to obtain onramp sessionId",this.showOnrampModal=!0}}startOnrampPolling(e){if(this.onrampPollTimer){try{clearInterval(this.onrampPollTimer)}catch{}this.onrampPollTimer=null}if(this.onrampNotifyController){try{this.onrampNotifyController.stop()}catch{}this.onrampNotifyController=null}let t=this.onrampPaymentIntentId;if(!t)return;let n=x(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}resetPaymentFlow(){Z(this,{pendingAction:"pay"})}async pay(){if(Xe){if(this.resetPaymentFlow(),!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){g(e,{onError:t=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:t,bubbles:!0})),f(t)&&(this.errorMessage=u(t),this.errorSeverity=b(t),this.errorAction=v(t))}});try{!this.config.useOwnWallet&&this.pnp&&(await this.pnp.disconnect?.(),this.walletConnected=!1,this.config={...this.config,actorProvider:void 0,connectedWallet:void 0})}catch{}}finally{this.processing=!1}}}render(){if(!this.config)return ve`<div class="icpay-card icpay-section">Loading...</div>`;let 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 ve`
|
|
2048
|
-
<div class="icpay-card icpay-section icpay-widget-base">
|
|
2049
|
-
${o?ve`
|
|
2050
|
-
<icpay-progress-bar
|
|
2051
|
-
.debug=${!!this.config?.debug}
|
|
2052
|
-
.theme=${this.config?.theme}
|
|
2053
|
-
.amount=${Number(this.amountUsd||0)}
|
|
2054
|
-
.ledgerSymbol=${this.selectedSymbol||"ICP"}
|
|
2055
|
-
></icpay-progress-bar>
|
|
2056
|
-
`:null}
|
|
2057
|
-
|
|
2058
|
-
<div class="row">
|
|
2059
|
-
<div class="top-row">
|
|
2060
|
-
<div class="amount-field">
|
|
2061
|
-
<span class="currency-prefix">$</span>
|
|
2062
|
-
<input type="number" min="0" step="${Number(this.config?.stepUsd??.5)}" .value=${String(this.amountUsd||"")} placeholder="${e}" @input=${l=>this.onInputChange(l)} />
|
|
2063
|
-
</div>
|
|
2064
|
-
${null}
|
|
2065
|
-
</div>
|
|
2066
|
-
<button class="pay-button ${this.processing?"processing":""}"
|
|
2067
|
-
?disabled=${this.processing||this.config?.disablePaymentButton===!0||this.succeeded&&this.config?.disableAfterSuccess===!0}
|
|
2068
|
-
@click=${()=>this.pay()}>
|
|
2069
|
-
${this.succeeded&&this.config?.disableAfterSuccess?"Paid":this.processing?"Processing\u2026":n}
|
|
2070
|
-
</button>
|
|
2071
|
-
</div>
|
|
2072
|
-
<div class="hint">Min: $${Number(this.config?.minUsd??.5).toFixed(2)}${this.config?.maxUsd?`, Max: $${Number(this.config.maxUsd).toFixed(2)}`:""}</div>
|
|
2073
|
-
|
|
2074
|
-
${this.errorMessage?ve`
|
|
2075
|
-
<div class="error-message ${this.errorSeverity}" style="margin-top: 12px; padding: 8px 12px; border-radius: 6px; font-size: 14px; text-align: center;">
|
|
2076
|
-
${this.errorMessage}
|
|
2077
|
-
${this.errorAction?ve`<button style="margin-left: 8px; padding: 4px 8px; background: transparent; border: 1px solid currentColor; border-radius: 4px; font-size: 12px; cursor: pointer;">${this.errorAction}</button>`:""}
|
|
2078
|
-
</div>
|
|
2079
|
-
`:""}
|
|
2080
|
-
${(()=>{let l=this.pnp?.getEnabledWallets?.()||[],p=H(l),h=this.config?.theme?typeof this.config.theme=="string"?this.config.theme:this.config.theme.mode||"light":void 0;return G({visible:!!(this.showWalletModal&&this.pnp),wallets:p,isConnecting:!1,step:this.walletModalStep,balances:this.walletModalStep==="balances"?this.walletBalances:[],balancesLoading:this.walletModalStep==="balances"?this.balancesLoading:!1,balancesError:this.walletModalStep==="balances"?this.balancesError:null,onSelectBalance:d=>this.onSelectBalanceSymbol(d),onBack:()=>{this.walletModalStep="connect"},onSwitchAccount:()=>this.onSwitchAccount(null),onSelect:d=>this.connectWithWallet(d),onClose:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1;try{window.dispatchEvent(new CustomEvent("icpay-sdk-wallet-cancelled",{detail:{reason:"user_cancelled"}}))}catch{}},onDismiss:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1},onCreditCard:this.config?.onramp?.enabled===!0&&this.config?.onrampDisabled!==!0?()=>this.startOnramp():void 0,creditCardLabel:this.config?.onramp?.creditCardLabel||"Pay with credit card",showCreditCard:this.config?.onramp?.enabled===!0&&this.config?.onrampDisabled!==!0,creditCardTooltip:(()=>{let y=Number(this.amountUsd||0);return y>0&&y<5&&this.config?.onramp?.enabled===!0&&this.config?.onrampDisabled!==!0?`Note: Minimum card amount is $5. You will pay about $${(5-y).toFixed(2)} more.`:null})(),oisyReadyToPay:this.oisyReadyToPay,onOisyPay:()=>{this.showWalletModal=!1,this.oisyReadyToPay=!1,this.pay()},theme:h})})()}
|
|
2081
|
-
|
|
2082
|
-
${(()=>{let l=this.config?.theme?typeof this.config.theme=="string"?this.config.theme:this.config.theme.mode||"light":void 0;return ve`
|
|
2083
|
-
${Q({visible:this.showBalanceModal,isLoading:this.balancesLoading,error:this.balancesError,balances:this.walletBalances,onSelect:p=>this.onSelectBalanceSymbol(p),onClose:()=>{this.showBalanceModal=!1},theme:l})}
|
|
2084
|
-
|
|
2085
|
-
${q({visible:this.showOnrampModal,url:this.onrampUrl||void 0,errorMessage:this.onrampErrorMessage||void 0,width:this.config?.onramp?.width,height:this.config?.onramp?.height,onClose:()=>{this.showOnrampModal=!1},onBack:()=>{this.showOnrampModal=!1,this.showWalletModal=!0},title:"Pay with credit card",theme:l})}
|
|
2086
|
-
`})()}
|
|
2087
|
-
<div class="icpay-powered-by">
|
|
2088
|
-
<a href="https://icpay.org" target="_blank" rel="noopener noreferrer">Powered by icpay</a>
|
|
2089
|
-
</div>
|
|
2090
|
-
</div>
|
|
2091
|
-
`}};C.styles=[K,Ft`
|
|
2092
|
-
.row { display: grid; grid-template-columns: 1fr; gap: 12px; align-items: stretch; }
|
|
2093
|
-
.top-row { display: grid; grid-template-columns: 1fr; gap: 10px; align-items: center; }
|
|
2094
|
-
.top-row.with-selector { grid-template-columns: 1fr 2fr; }
|
|
2095
|
-
icpay-token-selector { width: 100%; }
|
|
2096
|
-
.amount-field { position: relative; width: 100%; }
|
|
2097
|
-
.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; }
|
|
2098
|
-
.amount-field input[type="number"] { padding-left: 32px; position: relative; z-index: 1; }
|
|
2099
|
-
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; }
|
|
2100
|
-
select { background: var(--icpay-surface-alt); border: 1px solid var(--icpay-border); color: var(--icpay-text); border-radius: 8px; padding: 10px; font-weight: 600; }
|
|
2101
|
-
.pay-button { width: 100%; }
|
|
2102
|
-
.error-message { border: 1px solid; font-weight: 500; }
|
|
2103
|
-
.error-message.info { background: var(--icpay-processing-bg); border-color: var(--icpay-processing-border); color: var(--icpay-processing-text); }
|
|
2104
|
-
.error-message.warning { background: var(--icpay-warning-bg); border-color: var(--icpay-warning-border); color: var(--icpay-warning-text); }
|
|
2105
|
-
.error-message.error { background: var(--icpay-error-bg); border-color: var(--icpay-error-border); color: var(--icpay-error-text); }
|
|
2106
|
-
.hint { font-size: 12px; color: var(--icpay-muted); margin-top: 6px; }
|
|
2107
|
-
|
|
2108
|
-
@media (max-width: 520px) {
|
|
2109
|
-
.top-row { grid-template-columns: 1fr; }
|
|
2110
|
-
}
|
|
2111
|
-
`],s([zt({type:Object})],C.prototype,"config",2),s([N()],C.prototype,"amountUsd",2),s([N()],C.prototype,"hasUserAmount",2),s([N()],C.prototype,"selectedSymbol",2),s([N()],C.prototype,"processing",2),s([N()],C.prototype,"succeeded",2),s([N()],C.prototype,"errorMessage",2),s([N()],C.prototype,"errorSeverity",2),s([N()],C.prototype,"errorAction",2),s([N()],C.prototype,"walletConnected",2),s([N()],C.prototype,"pendingAction",2),s([N()],C.prototype,"showWalletModal",2),s([N()],C.prototype,"walletModalStep",2),s([N()],C.prototype,"showOnrampModal",2),s([N()],C.prototype,"onrampUrl",2),s([N()],C.prototype,"onrampPaymentIntentId",2),s([N()],C.prototype,"onrampErrorMessage",2),s([N()],C.prototype,"oisyReadyToPay",2),s([N()],C.prototype,"lastWalletId",2),s([N()],C.prototype,"showBalanceModal",2),s([N()],C.prototype,"balancesLoading",2),s([N()],C.prototype,"balancesError",2),s([N()],C.prototype,"walletBalances",2),C=s([Dt("icpay-amount-input")],C);export{K as a,qt as b,ce as c,x as d,q as e,L as f,W as g,E as h,T as i,A as j,k,C as l};
|
|
2112
|
-
//# sourceMappingURL=chunk-Z7MZQN3H.js.map
|