@cedros/pay-react 1.1.16 → 1.1.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/AISettingsSection--jn-BNmd.mjs +539 -0
- package/dist/AISettingsSection-BrXUD4l_.js +51 -0
- package/dist/AutosaveIndicator-B3T328jH.mjs +35 -0
- package/dist/AutosaveIndicator-BQkm3cn8.js +1 -0
- package/dist/{CedrosContext-D7nh5-Zh.mjs → CedrosContext-BnJ2Cf7R.mjs} +1179 -642
- package/dist/CedrosContext-C26DlvLF.js +6 -0
- package/dist/CryptoButton-B4-oJ8lF.js +1 -0
- package/dist/CryptoButton-Dhxnk9d7.mjs +542 -0
- package/dist/FAQSection-BB1wJRsR.mjs +366 -0
- package/dist/FAQSection-aoAz35MV.js +1 -0
- package/dist/MessagingSection-BG9O62ko.mjs +347 -0
- package/dist/MessagingSection-DId-WJdU.js +1 -0
- package/dist/PaymentSettingsSection-D92IO4xJ.js +1 -0
- package/dist/PaymentSettingsSection-c13RAUxn.mjs +94 -0
- package/dist/SettingsSection-DUxjXl2G.js +1 -0
- package/dist/SettingsSection-htem-WL3.mjs +57 -0
- package/dist/SingleCategorySettings-BIEs6s6Z.mjs +1421 -0
- package/dist/SingleCategorySettings-CQ-osdzb.js +3 -0
- package/dist/StorefrontSection-CKTQt255.mjs +765 -0
- package/dist/StorefrontSection-DcSoDx-k.js +1 -0
- package/dist/SubscriptionsSection-C0hYf7Hr.js +1 -0
- package/dist/SubscriptionsSection-CONwHhT4.mjs +616 -0
- package/dist/Toggle-CsPSF8Dr.js +1 -0
- package/dist/Toggle-DAxIdpY4.mjs +48 -0
- package/dist/WalletManager-D6BYTwXn.js +1 -0
- package/dist/{WalletManager-oEjZhaFk.mjs → WalletManager-HXXyARQ7.mjs} +36 -32
- package/dist/components/CedrosPay.d.ts.map +1 -1
- package/dist/components/CryptoSubscribeButton.d.ts.map +1 -1
- package/dist/components/PaymentModal.d.ts.map +1 -1
- package/dist/components/SubscriptionManagementPanel.d.ts.map +1 -1
- package/dist/components/admin/AISettingsSection.d.ts.map +1 -1
- package/dist/components/admin/AdminAuthManager.d.ts +2 -1
- package/dist/components/admin/AdminAuthManager.d.ts.map +1 -1
- package/dist/components/admin/AutosaveIndicator.d.ts +7 -0
- package/dist/components/admin/AutosaveIndicator.d.ts.map +1 -0
- package/dist/components/admin/CedrosPayAdminDashboard.d.ts.map +1 -1
- package/dist/components/admin/ConfigEditor.d.ts +0 -2
- package/dist/components/admin/ConfigEditor.d.ts.map +1 -1
- package/dist/components/admin/MessagingSection.d.ts.map +1 -1
- package/dist/components/admin/ProductsSection.d.ts.map +1 -1
- package/dist/components/admin/RefundsSection.d.ts.map +1 -1
- package/dist/components/admin/SecretArrayEditor.d.ts +16 -0
- package/dist/components/admin/SecretArrayEditor.d.ts.map +1 -0
- package/dist/components/admin/SingleCategorySettings.d.ts.map +1 -1
- package/dist/components/admin/StorefrontSection.d.ts.map +1 -1
- package/dist/components/admin/Toggle.d.ts +14 -0
- package/dist/components/admin/Toggle.d.ts.map +1 -0
- package/dist/components/admin/TokenMintSelector.d.ts +27 -0
- package/dist/components/admin/TokenMintSelector.d.ts.map +1 -0
- package/dist/components/admin/configApi.d.ts +5 -3
- package/dist/components/admin/configApi.d.ts.map +1 -1
- package/dist/components/admin/index.d.ts +8 -9
- package/dist/components/admin/index.d.ts.map +1 -1
- package/dist/components/admin/sections-more.d.ts +2 -9
- package/dist/components/admin/sections-more.d.ts.map +1 -1
- package/dist/context/CedrosContext.d.ts +1 -1
- package/dist/context/CedrosContext.d.ts.map +1 -1
- package/dist/crypto-only.js +1 -1
- package/dist/crypto-only.mjs +391 -380
- package/dist/ecommerce/__tests__/inventoryHooks.test.d.ts +2 -0
- package/dist/ecommerce/__tests__/inventoryHooks.test.d.ts.map +1 -0
- package/dist/ecommerce/__tests__/storage.test.d.ts +2 -0
- package/dist/ecommerce/__tests__/storage.test.d.ts.map +1 -0
- package/dist/ecommerce/adapters/CommerceAdapter.d.ts +5 -0
- package/dist/ecommerce/adapters/CommerceAdapter.d.ts.map +1 -1
- package/dist/ecommerce/adapters/mock/mockAdapter.d.ts.map +1 -1
- package/dist/ecommerce/adapters/paywall/paywallAdapter.d.ts.map +1 -1
- package/dist/ecommerce/adapters/paywall/paywallAdapter.test.d.ts +2 -0
- package/dist/ecommerce/adapters/paywall/paywallAdapter.test.d.ts.map +1 -0
- package/dist/ecommerce/components/catalog/ProductCard.d.ts.map +1 -1
- package/dist/ecommerce/components/catalog/QuickViewDialog.d.ts.map +1 -1
- package/dist/ecommerce/components/chat/ShopChatPanel.d.ts +4 -0
- package/dist/ecommerce/components/chat/ShopChatPanel.d.ts.map +1 -1
- package/dist/ecommerce/components/checkout/PaymentStep.d.ts.map +1 -1
- package/dist/ecommerce/components/faq/FAQItem.d.ts.map +1 -1
- package/dist/ecommerce/config/context.d.ts.map +1 -1
- package/dist/ecommerce/hooks/useAIRelatedProducts.d.ts.map +1 -1
- package/dist/ecommerce/hooks/useCartInventory.d.ts.map +1 -1
- package/dist/ecommerce/hooks/useHoldExpiry.d.ts.map +1 -1
- package/dist/ecommerce/hooks/useInventoryVerification.d.ts.map +1 -1
- package/dist/ecommerce/hooks/useProducts.d.ts.map +1 -1
- package/dist/ecommerce/index.d.ts +2 -0
- package/dist/ecommerce/index.d.ts.map +1 -1
- package/dist/ecommerce/integrations/cedros-pay/useCedrosPayCheckoutAdapter.d.ts.map +1 -1
- package/dist/ecommerce/state/cart/CartProvider.d.ts.map +1 -1
- package/dist/ecommerce/state/checkout/checkoutSchema.d.ts +1 -1
- package/dist/ecommerce/state/checkout/useCheckout.d.ts.map +1 -1
- package/dist/ecommerce/templates/ProductTemplate.d.ts.map +1 -1
- package/dist/ecommerce/utils/storage.d.ts +1 -1
- package/dist/ecommerce/utils/storage.d.ts.map +1 -1
- package/dist/hooks/useCreditsPayment.d.ts.map +1 -1
- package/dist/hooks/useCreditsSubscription.d.ts.map +1 -1
- package/dist/hooks/useCryptoSubscription.d.ts.map +1 -1
- package/dist/hooks/useRefundVerification.d.ts.map +1 -1
- package/dist/hooks/useStripeCheckout.d.ts +1 -1
- package/dist/hooks/useStripeCheckout.d.ts.map +1 -1
- package/dist/hooks/useSubscription.d.ts.map +1 -1
- package/dist/hooks/useSubscriptionManagement.d.ts.map +1 -1
- package/dist/hooks/useX402Payment.d.ts.map +1 -1
- package/dist/index-2N_CMVAv.js +84 -0
- package/dist/index-C1hbnxn0.mjs +22915 -0
- package/dist/index.js +1 -1
- package/dist/index.mjs +67 -72
- package/dist/managers/CreditsManager.d.ts +6 -0
- package/dist/managers/CreditsManager.d.ts.map +1 -1
- package/dist/managers/ManagerCache.d.ts.map +1 -1
- package/dist/managers/RouteDiscoveryManager.d.ts +3 -0
- package/dist/managers/RouteDiscoveryManager.d.ts.map +1 -1
- package/dist/managers/StripeManager.d.ts +15 -0
- package/dist/managers/StripeManager.d.ts.map +1 -1
- package/dist/managers/SubscriptionChangeManager.d.ts.map +1 -1
- package/dist/managers/SubscriptionManager.d.ts +7 -14
- package/dist/managers/SubscriptionManager.d.ts.map +1 -1
- package/dist/managers/WalletManager.d.ts +2 -1
- package/dist/managers/WalletManager.d.ts.map +1 -1
- package/dist/managers/X402Manager.d.ts.map +1 -1
- package/dist/{sections-CL3lbNui.js → sections-D2GMJuKq.js} +1 -1
- package/dist/{sections-DnmB0qdx.mjs → sections-DICaHGhz.mjs} +1 -1
- package/dist/stripe-only.js +1 -1
- package/dist/stripe-only.mjs +67 -72
- package/dist/telemetry.js +1 -1
- package/dist/telemetry.mjs +23 -25
- package/dist/testing/index.js +1 -1
- package/dist/testing/index.mjs +1 -1
- package/dist/types/index.d.ts +13 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/useAutosave-B2p6iwh8.js +1 -0
- package/dist/useAutosave-YwMqRzqy.mjs +44 -0
- package/dist/utils/circuitBreaker.d.ts +3 -1
- package/dist/utils/circuitBreaker.d.ts.map +1 -1
- package/dist/utils/cspHelper.d.ts +6 -0
- package/dist/utils/cspHelper.d.ts.map +1 -1
- package/dist/utils/csvHelpers.d.ts +0 -41
- package/dist/utils/csvHelpers.d.ts.map +1 -1
- package/dist/utils/errorHandling.d.ts.map +1 -1
- package/dist/utils/exponentialBackoff.d.ts.map +1 -1
- package/dist/utils/requestDeduplication.d.ts.map +1 -1
- package/dist/utils/telemetry.d.ts.map +1 -1
- package/dist/utils/validateConfig.d.ts +1 -1
- package/dist/utils/validateConfig.d.ts.map +1 -1
- package/dist/walletDetection-JZR3UCOa.mjs +27 -0
- package/dist/walletDetection-bNmV5ItZ.js +1 -0
- package/dist/{walletPool-BR6etEiq.mjs → walletPool-BV_z1lEA.mjs} +1 -1
- package/dist/{walletPool-BZyAG4YS.js → walletPool-DjA7J3a9.js} +1 -1
- package/package.json +8 -7
- package/dist/CedrosContext-C2v_s8cc.js +0 -6
- package/dist/WalletManager-B5KLZK2D.js +0 -1
- package/dist/index-BU0vgA-7.js +0 -136
- package/dist/index-DWXEBUbu.mjs +0 -27912
|
@@ -0,0 +1,542 @@
|
|
|
1
|
+
import { jsxs as G, jsx as h } from "react/jsx-runtime";
|
|
2
|
+
import { useState as L, useRef as R, useCallback as P, useMemo as Y, useEffect as H } from "react";
|
|
3
|
+
import { useWallet as be } from "@solana/wallet-adapter-react";
|
|
4
|
+
import { WalletReadyState as pe } from "@solana/wallet-adapter-base";
|
|
5
|
+
import { WalletIcon as Te } from "@solana/wallet-adapter-react-ui";
|
|
6
|
+
import { u as he, m as Z, i as n, a as Ie } from "./CedrosContext-BnJ2Cf7R.mjs";
|
|
7
|
+
import { a3 as Ee, k as We, T as Re, a4 as J, E as _e, F as fe, A as qe, D as ge, y as ze, z as we, B as ee, a5 as Me, a6 as De } from "./index-C1hbnxn0.mjs";
|
|
8
|
+
function Fe() {
|
|
9
|
+
const { x402Manager: g, walletManager: s } = he(), { publicKey: _, signTransaction: q } = be(), [X, d] = L({
|
|
10
|
+
status: "idle",
|
|
11
|
+
error: null,
|
|
12
|
+
transactionId: null
|
|
13
|
+
}), [I, k] = L(null), [O, x] = L(null), C = R(_);
|
|
14
|
+
C.current = _;
|
|
15
|
+
const w = R(q);
|
|
16
|
+
w.current = q;
|
|
17
|
+
const u = R(0), K = 6e4, E = () => {
|
|
18
|
+
const o = u.current;
|
|
19
|
+
return o > 0 && Date.now() - o < K;
|
|
20
|
+
}, v = P(() => {
|
|
21
|
+
if (!_) {
|
|
22
|
+
const o = "Wallet not connected";
|
|
23
|
+
return d({ status: "error", error: o, transactionId: null }), { valid: !1, error: o };
|
|
24
|
+
}
|
|
25
|
+
if (!q) {
|
|
26
|
+
const o = "Wallet does not support signing";
|
|
27
|
+
return d({ status: "error", error: o, transactionId: null }), { valid: !1, error: o };
|
|
28
|
+
}
|
|
29
|
+
return { valid: !0 };
|
|
30
|
+
}, [_, q]), z = P(
|
|
31
|
+
async (o) => {
|
|
32
|
+
try {
|
|
33
|
+
d((i) => ({ ...i, status: "loading" }));
|
|
34
|
+
const l = await g.requestQuote({ resource: o });
|
|
35
|
+
if (!g.validateRequirement(l))
|
|
36
|
+
throw new Error("Invalid requirement received from server");
|
|
37
|
+
return k(l), d((i) => ({ ...i, status: "idle" })), l;
|
|
38
|
+
} catch (l) {
|
|
39
|
+
const i = Z(l, "Failed to fetch requirement");
|
|
40
|
+
throw d({
|
|
41
|
+
status: "error",
|
|
42
|
+
error: i,
|
|
43
|
+
transactionId: null
|
|
44
|
+
}), l;
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
[g]
|
|
48
|
+
), B = P(
|
|
49
|
+
async (o, l, i, b, r = "regular") => {
|
|
50
|
+
const a = C.current, y = w.current;
|
|
51
|
+
if (!a || !y)
|
|
52
|
+
throw new Error("Wallet disconnected during payment flow");
|
|
53
|
+
if (!!o.extra?.feePayer) {
|
|
54
|
+
n().debug("[useX402Payment] Gasless flow enabled"), n().debug("[useX402Payment] Building gasless transaction");
|
|
55
|
+
const { transaction: f, blockhash: D } = await g.buildGaslessTransaction({
|
|
56
|
+
resourceId: l,
|
|
57
|
+
userWallet: a.toString(),
|
|
58
|
+
feePayer: o.extra.feePayer,
|
|
59
|
+
couponCode: i
|
|
60
|
+
});
|
|
61
|
+
n().debug("[useX402Payment] Deserializing backend transaction");
|
|
62
|
+
const A = s.deserializeTransaction(f);
|
|
63
|
+
if (C.current?.toString() !== a.toString())
|
|
64
|
+
throw new Error("Wallet changed during payment flow");
|
|
65
|
+
n().debug("[useX402Payment] Requesting partial signature");
|
|
66
|
+
const T = await s.partiallySignTransaction({
|
|
67
|
+
transaction: A,
|
|
68
|
+
signTransaction: y,
|
|
69
|
+
blockhash: D
|
|
70
|
+
});
|
|
71
|
+
n().debug("[useX402Payment] Submitting partial transaction");
|
|
72
|
+
const F = await g.submitGaslessTransaction({
|
|
73
|
+
resource: l,
|
|
74
|
+
partialTx: T,
|
|
75
|
+
couponCode: i,
|
|
76
|
+
metadata: b,
|
|
77
|
+
resourceType: r,
|
|
78
|
+
requirement: o
|
|
79
|
+
});
|
|
80
|
+
return F.success && F.settlement && x(F.settlement), F;
|
|
81
|
+
} else {
|
|
82
|
+
const f = await s.buildTransaction({
|
|
83
|
+
requirement: o,
|
|
84
|
+
payerPublicKey: a
|
|
85
|
+
});
|
|
86
|
+
if (C.current?.toString() !== a.toString())
|
|
87
|
+
throw new Error("Wallet changed during payment flow");
|
|
88
|
+
const D = await s.signTransaction({
|
|
89
|
+
transaction: f,
|
|
90
|
+
signTransaction: y
|
|
91
|
+
}), A = s.buildPaymentPayload({
|
|
92
|
+
requirement: o,
|
|
93
|
+
signedTx: D,
|
|
94
|
+
payerPublicKey: a
|
|
95
|
+
}), T = await g.submitPayment({
|
|
96
|
+
resource: l,
|
|
97
|
+
payload: A,
|
|
98
|
+
couponCode: i,
|
|
99
|
+
metadata: b,
|
|
100
|
+
resourceType: r
|
|
101
|
+
});
|
|
102
|
+
return T.success && T.settlement && x(T.settlement), T;
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
[g, s]
|
|
106
|
+
), p = P(
|
|
107
|
+
async (o, l, i) => {
|
|
108
|
+
if (E())
|
|
109
|
+
return { success: !1, error: "Payment already in progress" };
|
|
110
|
+
const b = v();
|
|
111
|
+
if (!b.valid)
|
|
112
|
+
return { success: !1, error: b.error };
|
|
113
|
+
u.current = Date.now(), d({
|
|
114
|
+
status: "loading",
|
|
115
|
+
error: null,
|
|
116
|
+
transactionId: null
|
|
117
|
+
});
|
|
118
|
+
try {
|
|
119
|
+
n().debug("[useX402Payment] Fetching fresh quote");
|
|
120
|
+
const r = await g.requestQuote({ resource: o, couponCode: l });
|
|
121
|
+
n().debug("[useX402Payment] Received quote", {
|
|
122
|
+
amount: r.maxAmountRequired
|
|
123
|
+
}), k(r), n().debug("[useX402Payment] Executing payment flow");
|
|
124
|
+
const a = await B(r, o, l, i, "regular");
|
|
125
|
+
return a.success ? d({
|
|
126
|
+
status: "success",
|
|
127
|
+
error: null,
|
|
128
|
+
transactionId: a.transactionId || "payment-success"
|
|
129
|
+
}) : d({
|
|
130
|
+
status: "error",
|
|
131
|
+
error: a.error || "Payment failed",
|
|
132
|
+
transactionId: null
|
|
133
|
+
}), a;
|
|
134
|
+
} catch (r) {
|
|
135
|
+
const a = Z(r, "Payment failed");
|
|
136
|
+
return d({
|
|
137
|
+
status: "error",
|
|
138
|
+
error: a,
|
|
139
|
+
transactionId: null
|
|
140
|
+
}), { success: !1, error: a };
|
|
141
|
+
} finally {
|
|
142
|
+
u.current = 0;
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
[v, g, B]
|
|
146
|
+
), M = P(
|
|
147
|
+
async (o, l, i) => {
|
|
148
|
+
if (E())
|
|
149
|
+
return { success: !1, error: "Payment already in progress" };
|
|
150
|
+
const b = v();
|
|
151
|
+
if (!b.valid)
|
|
152
|
+
return { success: !1, error: b.error };
|
|
153
|
+
u.current = Date.now(), d({
|
|
154
|
+
status: "loading",
|
|
155
|
+
error: null,
|
|
156
|
+
transactionId: null
|
|
157
|
+
});
|
|
158
|
+
try {
|
|
159
|
+
const r = Ee(o), a = await g.requestCartQuote({
|
|
160
|
+
items: r,
|
|
161
|
+
metadata: l,
|
|
162
|
+
couponCode: i
|
|
163
|
+
}), y = a.cartId, c = a.quote;
|
|
164
|
+
if (!g.validateRequirement(c))
|
|
165
|
+
throw new Error("Invalid cart quote received from server");
|
|
166
|
+
k(c);
|
|
167
|
+
const f = await B(c, y, i, l, "cart");
|
|
168
|
+
return f.success ? d({
|
|
169
|
+
status: "success",
|
|
170
|
+
error: null,
|
|
171
|
+
transactionId: f.transactionId || "cart-payment-success"
|
|
172
|
+
}) : d({
|
|
173
|
+
status: "error",
|
|
174
|
+
error: f.error || "Cart payment failed",
|
|
175
|
+
transactionId: null
|
|
176
|
+
}), f;
|
|
177
|
+
} catch (r) {
|
|
178
|
+
const a = Z(r, "Cart payment failed");
|
|
179
|
+
return d({
|
|
180
|
+
status: "error",
|
|
181
|
+
error: a,
|
|
182
|
+
transactionId: null
|
|
183
|
+
}), { success: !1, error: a };
|
|
184
|
+
} finally {
|
|
185
|
+
u.current = 0;
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
[v, g, B]
|
|
189
|
+
), W = P(() => {
|
|
190
|
+
d({
|
|
191
|
+
status: "idle",
|
|
192
|
+
error: null,
|
|
193
|
+
transactionId: null
|
|
194
|
+
}), k(null), x(null), u.current = 0;
|
|
195
|
+
}, []);
|
|
196
|
+
return {
|
|
197
|
+
...X,
|
|
198
|
+
requirement: I,
|
|
199
|
+
settlement: O,
|
|
200
|
+
fetchQuote: z,
|
|
201
|
+
processPayment: p,
|
|
202
|
+
processCartPayment: M,
|
|
203
|
+
reset: W
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
function $e({
|
|
207
|
+
resource: g,
|
|
208
|
+
items: s,
|
|
209
|
+
label: _,
|
|
210
|
+
disabled: q = !1,
|
|
211
|
+
onAttempt: X,
|
|
212
|
+
onSuccess: d,
|
|
213
|
+
onError: I,
|
|
214
|
+
className: k = "",
|
|
215
|
+
testPageUrl: O,
|
|
216
|
+
hideMessages: x = !1,
|
|
217
|
+
metadata: C,
|
|
218
|
+
couponCode: w
|
|
219
|
+
}) {
|
|
220
|
+
const { connected: u, connecting: K, connect: E, disconnect: v, select: z, wallets: B, wallet: p, publicKey: M } = be(), { status: W, error: o, transactionId: l, processPayment: i, processCartPayment: b } = Fe(), r = Ie(), { solanaError: a } = he(), { isCartMode: y, effectiveResource: c } = We(g, s), { t: f, translations: D } = Re(), A = _ || f("ui.pay_with_crypto"), T = o && typeof o != "string" ? o?.code ?? null : null, F = a && typeof a != "string" ? a?.code ?? null : null, te = (e) => {
|
|
221
|
+
if (!e || !D) return "";
|
|
222
|
+
const t = D.errors[e];
|
|
223
|
+
return t ? t.action ? `${t.message} ${t.action}` : t.message : "";
|
|
224
|
+
}, re = o ? typeof o == "string" ? o : te(T) : null, ne = a ? typeof a == "string" ? a : te(F) : null, oe = R(d), ae = R(I), se = R(i), le = R(b);
|
|
225
|
+
oe.current = d, ae.current = I, se.current = i, le.current = b;
|
|
226
|
+
const Ce = Y(
|
|
227
|
+
() => B.map((e) => `${e.adapter.name}-${e.readyState}`).join(","),
|
|
228
|
+
[B]
|
|
229
|
+
), Q = Y(
|
|
230
|
+
() => B.filter(
|
|
231
|
+
({ readyState: e }) => e === pe.Installed || e === pe.Loadable
|
|
232
|
+
),
|
|
233
|
+
// walletStateKey is derived from availableWallets, so we only need availableWallets as dependency
|
|
234
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
235
|
+
[Ce]
|
|
236
|
+
);
|
|
237
|
+
H(() => {
|
|
238
|
+
if (W === "success" && l) {
|
|
239
|
+
const e = y && s ? J(s) : void 0;
|
|
240
|
+
_e("crypto", l, c, e), oe.current?.(l);
|
|
241
|
+
}
|
|
242
|
+
}, [W, l, y, s, c]), H(() => {
|
|
243
|
+
if (W === "error" && o) {
|
|
244
|
+
const e = y && s ? J(s) : void 0;
|
|
245
|
+
fe("crypto", o, c, e), ae.current?.(o);
|
|
246
|
+
}
|
|
247
|
+
}, [W, o, y, s, c]);
|
|
248
|
+
const ce = typeof window < "u" && window.top !== window.self, [ie, $] = L(!1), [ue, V] = L(!1), [N, S] = L(null), j = a;
|
|
249
|
+
H(() => {
|
|
250
|
+
let e = !1;
|
|
251
|
+
return e || (async () => {
|
|
252
|
+
if (ue && p && !u && !K) {
|
|
253
|
+
n().debug("[CryptoButton] Wallet detected, attempting auto-connect:", p.adapter.name), V(!1), we(p.adapter.name);
|
|
254
|
+
try {
|
|
255
|
+
await E(), e || n().debug("[CryptoButton] Auto-connect successful");
|
|
256
|
+
} catch (m) {
|
|
257
|
+
if (!e) {
|
|
258
|
+
n().error("[CryptoButton] Auto-connect failed:", m);
|
|
259
|
+
const U = m instanceof Error ? m.message : "Failed to connect wallet";
|
|
260
|
+
ee(U, p.adapter.name), S(null);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
})(), () => {
|
|
265
|
+
e = !0;
|
|
266
|
+
};
|
|
267
|
+
}, [p, ue, u, K, E]), H(() => {
|
|
268
|
+
let e = !0;
|
|
269
|
+
if (n().debug("[CryptoButton] Payment useEffect triggered", {
|
|
270
|
+
connected: u,
|
|
271
|
+
hasPendingPayment: !!N,
|
|
272
|
+
hasPublicKey: !!M,
|
|
273
|
+
pendingPaymentType: N?.type
|
|
274
|
+
}), u && N && M && p && e) {
|
|
275
|
+
qe(p.adapter.name, M.toString()), n().debug("[CryptoButton] All conditions met! Processing pending payment:", N);
|
|
276
|
+
const t = N;
|
|
277
|
+
S(null), $(!1);
|
|
278
|
+
const m = t.type === "cart" && t.items ? J(t.items) : void 0;
|
|
279
|
+
ge("crypto", t.resource, m), t.type === "cart" && t.items ? (n().debug("[CryptoButton] Auto-processing cart payment"), le.current(t.items, t.metadata, t.couponCode)) : t.type === "single" && t.resource && (n().debug("[CryptoButton] Auto-processing single payment"), se.current(t.resource, t.couponCode, t.metadata));
|
|
280
|
+
}
|
|
281
|
+
return () => {
|
|
282
|
+
e = !1;
|
|
283
|
+
};
|
|
284
|
+
}, [u, N, M, p]);
|
|
285
|
+
const de = P(async () => {
|
|
286
|
+
n().debug("[CryptoButton] executePaymentFlow called", {
|
|
287
|
+
connected: u,
|
|
288
|
+
wallet: p?.adapter.name,
|
|
289
|
+
couponCode: w,
|
|
290
|
+
isCartMode: y,
|
|
291
|
+
hasItems: !!s,
|
|
292
|
+
effectiveResource: c
|
|
293
|
+
});
|
|
294
|
+
const e = y && s ? J(s) : void 0;
|
|
295
|
+
if (ze("crypto", c, e), X && X("crypto"), j) {
|
|
296
|
+
n().error("[CryptoButton] Solana dependencies missing:", j), fe("crypto", j, c, e), I && I(j);
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
if (ce) {
|
|
300
|
+
const t = O || window.location.href;
|
|
301
|
+
try {
|
|
302
|
+
if (new URL(t, window.location.origin).origin !== window.location.origin)
|
|
303
|
+
throw n().error("[CryptoButton] Blocked attempt to open external URL:", t), new Error("Cannot open external URLs from embedded context");
|
|
304
|
+
window.open(t, "_blank", "noopener,noreferrer");
|
|
305
|
+
} catch (m) {
|
|
306
|
+
throw n().error("[CryptoButton] URL validation failed:", m), m;
|
|
307
|
+
}
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
if (u)
|
|
311
|
+
ge("crypto", c, e), y && s ? (n().debug("[CryptoButton] Processing cart payment with coupon:", w), await b(s, C, w)) : c && (n().debug("[CryptoButton] Processing single payment with coupon:", w), await i(c, w, C));
|
|
312
|
+
else {
|
|
313
|
+
let t = !1;
|
|
314
|
+
if (y && s ? (n().debug("[CryptoButton] Setting pending cart payment with coupon:", w), S({ type: "cart", items: s, metadata: C, couponCode: w }), t = !0) : c && (n().debug("[CryptoButton] Setting pending single payment with coupon:", w), S({ type: "single", resource: c, metadata: C, couponCode: w }), t = !0), !t) {
|
|
315
|
+
n().error("[CryptoButton] No valid payment to process");
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
try {
|
|
319
|
+
if (p)
|
|
320
|
+
n().debug("[CryptoButton] Wallet already selected, connecting:", p.adapter.name), we(p.adapter.name), await E();
|
|
321
|
+
else {
|
|
322
|
+
if (n().debug(
|
|
323
|
+
"[CryptoButton] No wallet selected, showing selector. Available wallets:",
|
|
324
|
+
Q.map((m) => m.adapter.name)
|
|
325
|
+
), Q.length === 0) {
|
|
326
|
+
S(null);
|
|
327
|
+
const m = "No wallets available";
|
|
328
|
+
throw ee(m), new Error(m);
|
|
329
|
+
}
|
|
330
|
+
$(!0);
|
|
331
|
+
}
|
|
332
|
+
} catch (m) {
|
|
333
|
+
S(null);
|
|
334
|
+
const U = m instanceof Error ? m.message : "Failed to connect wallet";
|
|
335
|
+
n().error("[CryptoButton] Connection error:", U), ee(U, p?.adapter.name);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}, [u, p, w, y, s, c, ce, O, Q, E, C, b, i, j, X, I]), ye = Y(() => y && s ? `crypto-cart-${s.map((e) => e.resource).join("-")}` : `crypto-${c || "unknown"}`, [y, s, c]), Pe = Y(
|
|
339
|
+
() => Me(ye, de, {
|
|
340
|
+
cooldownMs: 200,
|
|
341
|
+
deduplicationWindowMs: 0
|
|
342
|
+
// MUST be 0 for crypto - each payment needs fresh transaction
|
|
343
|
+
}),
|
|
344
|
+
[ye, de]
|
|
345
|
+
), me = W === "loading", xe = q || me || K || !!j, ve = me ? f("ui.processing") : A, Se = P(async () => {
|
|
346
|
+
try {
|
|
347
|
+
V(!1), u && await v(), z(null), $(!0);
|
|
348
|
+
} catch (e) {
|
|
349
|
+
n().error("Failed to change wallet:", e);
|
|
350
|
+
}
|
|
351
|
+
}, [u, v, z]), ke = P((e) => {
|
|
352
|
+
n().debug("[CryptoButton] Wallet clicked:", e), $(!1), z(e), V(!0), n().debug("[CryptoButton] Wallet selected, useEffect will auto-connect");
|
|
353
|
+
}, [z]), Be = P(async () => {
|
|
354
|
+
try {
|
|
355
|
+
if (await v(), S(null), typeof window < "u" && window.localStorage)
|
|
356
|
+
try {
|
|
357
|
+
window.localStorage.removeItem("walletName");
|
|
358
|
+
} catch (e) {
|
|
359
|
+
e instanceof Error && e.name === "QuotaExceededError" ? n().warn("localStorage quota exceeded when removing wallet preference") : n().error("Failed to clear wallet preference from localStorage:", e);
|
|
360
|
+
}
|
|
361
|
+
} catch (e) {
|
|
362
|
+
n().error("Failed to disconnect wallet:", e);
|
|
363
|
+
}
|
|
364
|
+
}, [v]);
|
|
365
|
+
return /* @__PURE__ */ G("div", { className: r.unstyled ? k : `${r.className} cedros-theme__crypto-button ${k || ""}`, style: r.unstyled ? {} : r.style, children: [
|
|
366
|
+
/* @__PURE__ */ h(
|
|
367
|
+
"button",
|
|
368
|
+
{
|
|
369
|
+
onClick: Pe,
|
|
370
|
+
disabled: xe,
|
|
371
|
+
className: r.unstyled ? k : "cedros-theme__button cedros-theme__crypto",
|
|
372
|
+
type: "button",
|
|
373
|
+
children: ve
|
|
374
|
+
}
|
|
375
|
+
),
|
|
376
|
+
ie && !x && /* @__PURE__ */ h(
|
|
377
|
+
"div",
|
|
378
|
+
{
|
|
379
|
+
className: "cedros-modal-overlay",
|
|
380
|
+
style: {
|
|
381
|
+
position: "fixed",
|
|
382
|
+
top: 0,
|
|
383
|
+
left: 0,
|
|
384
|
+
right: 0,
|
|
385
|
+
bottom: 0,
|
|
386
|
+
backgroundColor: r.tokens.modalOverlay,
|
|
387
|
+
display: "flex",
|
|
388
|
+
alignItems: "center",
|
|
389
|
+
justifyContent: "center",
|
|
390
|
+
zIndex: 9999,
|
|
391
|
+
padding: "1rem"
|
|
392
|
+
},
|
|
393
|
+
onClick: () => {
|
|
394
|
+
$(!1), S(null);
|
|
395
|
+
},
|
|
396
|
+
children: /* @__PURE__ */ G(
|
|
397
|
+
"div",
|
|
398
|
+
{
|
|
399
|
+
className: "cedros-modal-content",
|
|
400
|
+
style: {
|
|
401
|
+
backgroundColor: r.tokens.modalBackground,
|
|
402
|
+
borderRadius: "12px",
|
|
403
|
+
padding: "2rem",
|
|
404
|
+
maxWidth: "400px",
|
|
405
|
+
width: "100%",
|
|
406
|
+
boxShadow: "0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04)",
|
|
407
|
+
border: `1px solid ${r.tokens.modalBorder}`
|
|
408
|
+
},
|
|
409
|
+
onClick: (e) => e.stopPropagation(),
|
|
410
|
+
children: [
|
|
411
|
+
/* @__PURE__ */ G(
|
|
412
|
+
"div",
|
|
413
|
+
{
|
|
414
|
+
style: {
|
|
415
|
+
display: "flex",
|
|
416
|
+
justifyContent: "space-between",
|
|
417
|
+
alignItems: "center",
|
|
418
|
+
marginBottom: "1.5rem"
|
|
419
|
+
},
|
|
420
|
+
children: [
|
|
421
|
+
/* @__PURE__ */ h(
|
|
422
|
+
"h3",
|
|
423
|
+
{
|
|
424
|
+
style: {
|
|
425
|
+
margin: 0,
|
|
426
|
+
fontSize: "1.25rem",
|
|
427
|
+
fontWeight: 600,
|
|
428
|
+
color: r.tokens.surfaceText
|
|
429
|
+
},
|
|
430
|
+
children: f("wallet.select_wallet")
|
|
431
|
+
}
|
|
432
|
+
),
|
|
433
|
+
/* @__PURE__ */ h(
|
|
434
|
+
"button",
|
|
435
|
+
{
|
|
436
|
+
onClick: () => {
|
|
437
|
+
$(!1), S(null);
|
|
438
|
+
},
|
|
439
|
+
style: De(r.tokens.surfaceText),
|
|
440
|
+
"aria-label": "Close modal",
|
|
441
|
+
type: "button",
|
|
442
|
+
children: "×"
|
|
443
|
+
}
|
|
444
|
+
)
|
|
445
|
+
]
|
|
446
|
+
}
|
|
447
|
+
),
|
|
448
|
+
/* @__PURE__ */ h("div", { style: { display: "flex", flexDirection: "column", gap: "0.75rem" }, children: Q.map((e) => /* @__PURE__ */ G(
|
|
449
|
+
"button",
|
|
450
|
+
{
|
|
451
|
+
onClick: () => ke(e.adapter.name),
|
|
452
|
+
style: {
|
|
453
|
+
width: "100%",
|
|
454
|
+
padding: "1rem",
|
|
455
|
+
backgroundColor: r.tokens.surfaceBackground,
|
|
456
|
+
border: `1px solid ${r.tokens.surfaceBorder}`,
|
|
457
|
+
borderRadius: "0.5rem",
|
|
458
|
+
cursor: "pointer",
|
|
459
|
+
fontSize: "1rem",
|
|
460
|
+
textAlign: "left",
|
|
461
|
+
color: r.tokens.surfaceText,
|
|
462
|
+
display: "flex",
|
|
463
|
+
alignItems: "center",
|
|
464
|
+
gap: "1rem",
|
|
465
|
+
transition: "all 0.2s ease"
|
|
466
|
+
},
|
|
467
|
+
onMouseEnter: (t) => {
|
|
468
|
+
t.currentTarget.style.backgroundColor = r.tokens.modalBackground, t.currentTarget.style.borderColor = r.tokens.surfaceText, t.currentTarget.style.transform = "translateY(-2px)";
|
|
469
|
+
},
|
|
470
|
+
onMouseLeave: (t) => {
|
|
471
|
+
t.currentTarget.style.backgroundColor = r.tokens.surfaceBackground, t.currentTarget.style.borderColor = r.tokens.surfaceBorder, t.currentTarget.style.transform = "translateY(0)";
|
|
472
|
+
},
|
|
473
|
+
type: "button",
|
|
474
|
+
children: [
|
|
475
|
+
/* @__PURE__ */ h(Te, { wallet: e, style: { width: "24px", height: "24px" } }),
|
|
476
|
+
/* @__PURE__ */ h("span", { style: { fontWeight: 500 }, children: e.adapter.name })
|
|
477
|
+
]
|
|
478
|
+
},
|
|
479
|
+
e.adapter.name
|
|
480
|
+
)) })
|
|
481
|
+
]
|
|
482
|
+
}
|
|
483
|
+
)
|
|
484
|
+
}
|
|
485
|
+
),
|
|
486
|
+
u && !x && !ie && /* @__PURE__ */ G("div", { style: {
|
|
487
|
+
display: "flex",
|
|
488
|
+
justifyContent: "space-between",
|
|
489
|
+
marginTop: "0.5rem",
|
|
490
|
+
fontSize: "0.75rem",
|
|
491
|
+
color: r.tokens.surfaceText,
|
|
492
|
+
opacity: 0.7
|
|
493
|
+
}, children: [
|
|
494
|
+
/* @__PURE__ */ h(
|
|
495
|
+
"button",
|
|
496
|
+
{
|
|
497
|
+
onClick: Se,
|
|
498
|
+
style: {
|
|
499
|
+
background: "none",
|
|
500
|
+
border: "none",
|
|
501
|
+
padding: 0,
|
|
502
|
+
color: "inherit",
|
|
503
|
+
textDecoration: "none",
|
|
504
|
+
cursor: "pointer",
|
|
505
|
+
fontSize: "inherit"
|
|
506
|
+
},
|
|
507
|
+
type: "button",
|
|
508
|
+
children: f("wallet.change")
|
|
509
|
+
}
|
|
510
|
+
),
|
|
511
|
+
/* @__PURE__ */ h(
|
|
512
|
+
"button",
|
|
513
|
+
{
|
|
514
|
+
onClick: Be,
|
|
515
|
+
style: {
|
|
516
|
+
background: "none",
|
|
517
|
+
border: "none",
|
|
518
|
+
padding: 0,
|
|
519
|
+
color: "inherit",
|
|
520
|
+
textDecoration: "none",
|
|
521
|
+
cursor: "pointer",
|
|
522
|
+
fontSize: "inherit"
|
|
523
|
+
},
|
|
524
|
+
type: "button",
|
|
525
|
+
children: f("ui.disconnect")
|
|
526
|
+
}
|
|
527
|
+
)
|
|
528
|
+
] }),
|
|
529
|
+
!x && ne && /* @__PURE__ */ h("div", { className: r.unstyled ? "" : "cedros-theme__error", children: ne }),
|
|
530
|
+
!x && re && /* @__PURE__ */ h("div", { className: r.unstyled ? "" : "cedros-theme__error", children: re }),
|
|
531
|
+
!x && l && /* @__PURE__ */ h("div", { className: r.unstyled ? "" : "cedros-theme__success", children: f("ui.payment_successful") })
|
|
532
|
+
] });
|
|
533
|
+
}
|
|
534
|
+
const Oe = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
535
|
+
__proto__: null,
|
|
536
|
+
CryptoButton: $e
|
|
537
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
538
|
+
export {
|
|
539
|
+
$e as C,
|
|
540
|
+
Oe as a,
|
|
541
|
+
Fe as u
|
|
542
|
+
};
|