@superlogic/spree-pay 0.1.16 → 0.1.18

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/build/index.cjs CHANGED
@@ -30,6 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
+ PaymentType: () => PaymentType,
33
34
  SpreePay: () => SpreePay,
34
35
  SpreePayProvider: () => SpreePayProvider,
35
36
  useCapture3DS: () => useCapture3DS,
@@ -38,8 +39,8 @@ __export(index_exports, {
38
39
  module.exports = __toCommonJS(index_exports);
39
40
 
40
41
  // src/SpreePay.tsx
41
- var import_react10 = require("react");
42
- var import_nice_modal_react6 = __toESM(require("@ebay/nice-modal-react"), 1);
42
+ var import_react16 = require("react");
43
+ var import_nice_modal_react7 = __toESM(require("@ebay/nice-modal-react"), 1);
43
44
  var import_swr4 = require("swr");
44
45
 
45
46
  // src/context/SpreePayActionsContext.tsx
@@ -57,6 +58,15 @@ var PaymentError = class extends Error {
57
58
  }
58
59
  };
59
60
 
61
+ // src/types/payments.ts
62
+ var PaymentType = /* @__PURE__ */ ((PaymentType2) => {
63
+ PaymentType2["CREDIT_CARD"] = "CREDIT_CARD";
64
+ PaymentType2["CRYPTO"] = "CRYPTO";
65
+ PaymentType2["SPLIT"] = "SPLIT";
66
+ PaymentType2["POINTS"] = "POINTS";
67
+ return PaymentType2;
68
+ })(PaymentType || {});
69
+
60
70
  // src/context/SpreePayActionsContext.tsx
61
71
  var import_jsx_runtime = require("react/jsx-runtime");
62
72
  var SpreePayActionsContext = (0, import_react.createContext)(void 0);
@@ -123,6 +133,86 @@ var useSpreePayRegister = () => {
123
133
  return { register: ctx.register };
124
134
  };
125
135
 
136
+ // src/context/StaticConfigContext.tsx
137
+ var import_react2 = require("react");
138
+ var import_jsx_runtime2 = require("react/jsx-runtime");
139
+ var CONFIG = {
140
+ dev: {
141
+ bookit: {
142
+ slapiUrl: "https://slapi.dev.superlogic.com",
143
+ keycloakUrl: "https://auth.dev.join.bookit.com",
144
+ keycloakClientId: "oneof-next",
145
+ pointsConversionRatio: 100,
146
+ pointsTitle: "AIR SP"
147
+ },
148
+ moca: {
149
+ slapiUrl: "https://slapi.dev.air.shop",
150
+ keycloakUrl: "https://login.dev.air.shop",
151
+ keycloakClientId: "oneof-next",
152
+ pointsConversionRatio: 100,
153
+ pointsTitle: "AIR SP"
154
+ }
155
+ },
156
+ stg: {
157
+ bookit: {
158
+ slapiUrl: "https://slapi.stg.superlogic.com",
159
+ keycloakUrl: "https://auth.stg.join.bookit.com",
160
+ keycloakClientId: "oneof-next",
161
+ pointsConversionRatio: 100,
162
+ pointsTitle: "AIR SP"
163
+ },
164
+ moca: {
165
+ slapiUrl: "https://slapi.stg.air.shop",
166
+ keycloakUrl: "https://login.stg.air.shop",
167
+ keycloakClientId: "oneof-next",
168
+ pointsConversionRatio: 100,
169
+ pointsTitle: "AIR SP"
170
+ }
171
+ },
172
+ prod: {
173
+ bookit: {
174
+ slapiUrl: "https://slapi.superlogic.com",
175
+ keycloakUrl: "https://auth.join.bookit.com",
176
+ keycloakClientId: "oneof-next",
177
+ pointsConversionRatio: 100,
178
+ pointsTitle: "AIR SP"
179
+ },
180
+ moca: {
181
+ slapiUrl: "https://slapi.air.shop",
182
+ keycloakUrl: "https://login.air.shop",
183
+ keycloakClientId: "oneof-next",
184
+ pointsConversionRatio: 100,
185
+ pointsTitle: "AIR SP"
186
+ }
187
+ }
188
+ };
189
+ var StaticConfigContext = (0, import_react2.createContext)(null);
190
+ var StaticConfigProvider = ({ children, props }) => {
191
+ const { env } = useSpreePayEnv();
192
+ const [appProps, setAppProps] = (0, import_react2.useState)(props);
193
+ (0, import_react2.useEffect)(() => {
194
+ setAppProps(props);
195
+ }, [props]);
196
+ const staticConfig = (0, import_react2.useMemo)(() => {
197
+ const envConfig = CONFIG[env.environment];
198
+ const appKey = env.tenantId in envConfig ? env.tenantId : "moca";
199
+ return envConfig[appKey];
200
+ }, [env.environment, env.tenantId]);
201
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(StaticConfigContext.Provider, { value: { staticConfig, appProps }, children });
202
+ };
203
+ var useStaticConfig = () => {
204
+ const ctx = (0, import_react2.useContext)(StaticConfigContext);
205
+ if (!ctx) throw new Error("useStaticConfig must be used within StaticConfigProvider");
206
+ return ctx;
207
+ };
208
+
209
+ // src/hooks/useSpreePayConfig.ts
210
+ var import_swr = __toESM(require("swr"), 1);
211
+ var useSpreePayConfig = () => {
212
+ const { data, isLoading } = (0, import_swr.default)("/v1/tenants/configs/spree-pay");
213
+ return { spreePayConfig: data, configIsLoading: isLoading };
214
+ };
215
+
126
216
  // src/lib/utils.ts
127
217
  var import_clsx = require("clsx");
128
218
  var import_tailwind_merge = require("tailwind-merge");
@@ -131,7 +221,7 @@ function cn(...inputs) {
131
221
  }
132
222
 
133
223
  // src/ui/spinner.tsx
134
- var import_jsx_runtime2 = require("react/jsx-runtime");
224
+ var import_jsx_runtime3 = require("react/jsx-runtime");
135
225
  var Spinner = (props) => {
136
226
  const { size = "md", className } = props;
137
227
  const sizeClasses = {
@@ -141,7 +231,7 @@ var Spinner = (props) => {
141
231
  lg: "size-12",
142
232
  xl: "size-16"
143
233
  };
144
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
234
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
145
235
  "svg",
146
236
  {
147
237
  className: cn(`${sizeClasses[size]} animate-spin text-gray-300`, className),
@@ -151,7 +241,7 @@ var Spinner = (props) => {
151
241
  width: "24",
152
242
  height: "24",
153
243
  children: [
154
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
244
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
155
245
  "path",
156
246
  {
157
247
  d: "M32 3C35.8083 3 39.5794 3.75011 43.0978 5.20749C46.6163 6.66488 49.8132 8.80101 52.5061 11.4939C55.199 14.1868 57.3351 17.3837 58.7925 20.9022C60.2499 24.4206 61 28.1917 61 32C61 35.8083 60.2499 39.5794 58.7925 43.0978C57.3351 46.6163 55.199 49.8132 52.5061 52.5061C49.8132 55.199 46.6163 57.3351 43.0978 58.7925C39.5794 60.2499 35.8083 61 32 61C28.1917 61 24.4206 60.2499 20.9022 58.7925C17.3837 57.3351 14.1868 55.199 11.4939 52.5061C8.801 49.8132 6.66487 46.6163 5.20749 43.0978C3.7501 39.5794 3 35.8083 3 32C3 28.1917 3.75011 24.4206 5.2075 20.9022C6.66489 17.3837 8.80101 14.1868 11.4939 11.4939C14.1868 8.80099 17.3838 6.66487 20.9022 5.20749C24.4206 3.7501 28.1917 3 32 3L32 3Z",
@@ -161,7 +251,7 @@ var Spinner = (props) => {
161
251
  strokeLinejoin: "round"
162
252
  }
163
253
  ),
164
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
254
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
165
255
  "path",
166
256
  {
167
257
  d: "M32 3C36.5778 3 41.0906 4.08374 45.1692 6.16256C49.2477 8.24138 52.7762 11.2562 55.466 14.9605C58.1558 18.6647 59.9304 22.9531 60.6448 27.4748C61.3591 31.9965 60.9928 36.6232 59.5759 40.9762",
@@ -189,8 +279,9 @@ var formatUSD = (amount, currency = "USD") => {
189
279
  };
190
280
  var formatPoints = (amount, pointsTitle = "Pts") => {
191
281
  const formattedAmount = new Intl.NumberFormat("en-US", {
282
+ notation: "compact",
192
283
  style: "decimal",
193
- maximumFractionDigits: 5,
284
+ maximumFractionDigits: 1,
194
285
  minimumFractionDigits: 0
195
286
  }).format(amount);
196
287
  return `${formattedAmount} ${pointsTitle}`;
@@ -204,45 +295,85 @@ var formatCoin = (amount, currency = "USDC") => {
204
295
  return `${formattedAmount} ${currency}`;
205
296
  };
206
297
 
298
+ // src/utils/split.ts
299
+ var getSplitAmount = (amount, splitTokens, pointsConversionRatio) => {
300
+ if (!Number.isFinite(amount) || !Number.isFinite(splitTokens) || !Number.isFinite(pointsConversionRatio)) {
301
+ return amount;
302
+ }
303
+ if (pointsConversionRatio <= 0) return amount;
304
+ const usdCoveredByPoints = splitTokens / pointsConversionRatio;
305
+ const remaining = amount - usdCoveredByPoints;
306
+ return Math.max(0, parseFloat(remaining.toFixed(2)));
307
+ };
308
+
309
+ // src/utils/transactionFee.ts
310
+ var getTransactionFee = (amount = 0, transactionFeePercentage) => {
311
+ if (!Number.isFinite(amount) || amount <= 0) return 0;
312
+ if (!Number.isFinite(transactionFeePercentage) || !transactionFeePercentage || transactionFeePercentage <= 0) {
313
+ return 0;
314
+ }
315
+ const fee = amount * transactionFeePercentage;
316
+ return Math.round((fee + Number.EPSILON) * 100) / 100;
317
+ };
318
+
207
319
  // src/components/CheckoutButton.tsx
208
- var import_jsx_runtime3 = require("react/jsx-runtime");
209
- var CheckoutButton = ({ isLoggedIn, isProcessing, amount, onCheckout }) => {
320
+ var import_jsx_runtime4 = require("react/jsx-runtime");
321
+ var CheckoutButton = ({ isLoggedIn }) => {
322
+ const { staticConfig, appProps } = useStaticConfig();
323
+ const { amount, onProcess, isProcessing, transactionFeePercentage } = appProps;
324
+ const { spreePayConfig } = useSpreePayConfig();
325
+ const { pointsTitle, pointsConversionRatio } = staticConfig;
210
326
  const { selectedPaymentMethod, isInternalProcessing } = useSpreePaymentMethod();
211
- const isDisabled = !amount || !selectedPaymentMethod.method || !!isProcessing || isInternalProcessing || !isLoggedIn;
212
- const isUSD = selectedPaymentMethod.type === "CREDIT_CARD" /* CREDIT_CARD */;
213
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "flex w-full flex-col overflow-hidden rounded-3xl border border-black/25 bg-white text-xs font-medium", children: [
214
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "px-5 py-5 md:px-7 md:py-6", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("p", { className: "text-black/50", children: [
327
+ const { splitAmount, type, method } = selectedPaymentMethod;
328
+ const isDisabled = !amount || !method || !!isProcessing || isInternalProcessing || !isLoggedIn;
329
+ const isCC = type === "CREDIT_CARD" /* CREDIT_CARD */;
330
+ const isCrypto = type === "CRYPTO" /* CRYPTO */;
331
+ const getCheckoutContent = () => {
332
+ if (!!isProcessing || isInternalProcessing) {
333
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Spinner, { className: "inline", size: "sm" });
334
+ }
335
+ if (isCC && amount) {
336
+ const usdAmount = getSplitAmount(amount, splitAmount ?? 0, pointsConversionRatio);
337
+ if (splitAmount && usdAmount) {
338
+ return `Pay ${formatUSD(usdAmount + getTransactionFee(usdAmount, transactionFeePercentage))} + ${formatPoints(splitAmount, pointsTitle)}`;
339
+ }
340
+ if (usdAmount) {
341
+ return `Pay ${formatUSD(usdAmount + getTransactionFee(usdAmount, transactionFeePercentage))}`;
342
+ }
343
+ if (splitAmount) {
344
+ return `Pay ${formatPoints(splitAmount, pointsTitle)}`;
345
+ }
346
+ return "Checkout";
347
+ }
348
+ if (isCrypto && amount) {
349
+ return `Pay ${formatCoin(amount)}`;
350
+ }
351
+ return "Checkout";
352
+ };
353
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "flex w-full flex-col overflow-hidden rounded-3xl border border-black/25 bg-white text-xs font-medium", children: [
354
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "px-5 py-5 md:px-7 md:py-6", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("p", { className: "text-black/50", children: [
215
355
  "By clicking on the button below I acknowledge that I have read and accepted the",
216
356
  " ",
217
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
218
- "a",
219
- {
220
- className: "underline",
221
- href: "https://uat.travel.air.shop/terms?locale=en-US&currency=USD",
222
- target: "_blank",
223
- rel: "noreferrer",
224
- children: "Terms and Conditions"
225
- }
226
- ),
357
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("a", { className: "underline", href: spreePayConfig?.termsConditionsUrl, target: "_blank", rel: "noreferrer", children: "Terms and Conditions" }),
227
358
  "."
228
359
  ] }) }),
229
- onCheckout && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
360
+ onProcess && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
230
361
  "button",
231
362
  {
232
363
  disabled: isDisabled,
233
- onClick: onCheckout,
364
+ onClick: onProcess,
234
365
  className: "bg-primary h-[60px] w-full cursor-pointer text-xl font-semibold text-white disabled:cursor-not-allowed disabled:opacity-50",
235
- children: !!isProcessing || isInternalProcessing ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Spinner, { className: "inline", size: "sm" }) : amount ? `Pay ${isUSD ? formatUSD(amount) : formatCoin(amount)}` : "Checkout"
366
+ children: getCheckoutContent()
236
367
  }
237
368
  )
238
369
  ] });
239
370
  };
240
371
 
241
372
  // src/components/SpreeLegal.tsx
242
- var import_jsx_runtime4 = require("react/jsx-runtime");
373
+ var import_jsx_runtime5 = require("react/jsx-runtime");
243
374
  var SpreeLegal = () => {
244
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "mt-4 flex items-center gap-4", children: [
245
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("svg", { className: "flex-shrink-0", xmlns: "http://www.w3.org/2000/svg", width: "66", height: "30", fill: "none", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
375
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "mt-4 flex items-center gap-4", children: [
376
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("svg", { className: "flex-shrink-0", xmlns: "http://www.w3.org/2000/svg", width: "66", height: "30", fill: "none", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
246
377
  "path",
247
378
  {
248
379
  fill: "#000",
@@ -250,10 +381,10 @@ var SpreeLegal = () => {
250
381
  d: "M57.79 25.48a4.82 4.82 0 0 1-1.55-.25l.55-1.86c.34.1.65.15.92.15s.51-.1.72-.26c.21-.16.39-.43.53-.81l.2-.55-3.65-10.3h2.52l2.32 7.62h.1l2.34-7.62h2.53l-4.04 11.31c-.19.54-.44 1-.75 1.38-.31.38-.7.68-1.14.88-.45.2-.98.3-1.6.3ZM48.95 21.9a4.2 4.2 0 0 1-1.73-.35c-.5-.23-.9-.57-1.2-1.02a3 3 0 0 1-.44-1.67 2.44 2.44 0 0 1 1.18-2.3c.35-.23.76-.4 1.22-.5.46-.13.93-.21 1.42-.27l1.44-.16c.37-.05.64-.13.8-.24.18-.1.26-.27.26-.5v-.04c0-.5-.15-.88-.44-1.15-.3-.27-.72-.4-1.27-.4-.58 0-1.04.12-1.38.37-.34.26-.57.56-.69.9l-2.22-.31a3.54 3.54 0 0 1 2.35-2.47 6.29 6.29 0 0 1 3.38-.14c.48.1.92.3 1.32.56.4.26.72.6.96 1.06.25.44.37 1 .37 1.67v6.75h-2.29v-1.38h-.08a2.9 2.9 0 0 1-1.59 1.37c-.39.14-.84.22-1.37.22Zm.62-1.75c.48 0 .89-.1 1.24-.28.35-.2.62-.45.8-.77.2-.31.3-.65.3-1.03V16.9c-.08.06-.2.11-.38.17a18.34 18.34 0 0 1-1.8.32c-.36.05-.68.12-.96.23-.28.11-.5.27-.66.46-.16.2-.24.45-.24.75 0 .44.16.77.48 1 .32.22.72.33 1.22.33ZM34.43 21.7V8.23h5.05c1.03 0 1.9.2 2.6.58.7.38 1.23.91 1.6 1.59.36.67.54 1.43.54 2.28 0 .87-.18 1.63-.55 2.3a3.9 3.9 0 0 1-1.6 1.59c-.72.38-1.59.57-2.63.57H36.1v-2h3.01c.6 0 1.1-.11 1.49-.32.38-.21.67-.5.85-.87.2-.37.29-.79.29-1.27 0-.47-.1-.9-.29-1.26a1.92 1.92 0 0 0-.86-.84c-.38-.2-.88-.31-1.49-.31h-2.23v11.41h-2.44ZM14.54.46a14.54 14.54 0 1 1 0 29.08 14.54 14.54 0 0 1 0-29.08ZM5.59 18.12l-.84 3.35h.83l.84-3.35h-.83Zm1.66 0-.83 3.35h1.66l.84-3.35H7.25Zm3.35-9.58c-1.03 0-2.08.84-2.34 1.87l-1.1 4.4c-.26 1.03.37 1.87 1.4 1.87h9.64l-.34 1.44h-8.1l-.85 3.35h9.6c1.04 0 2.1-.85 2.35-1.89l1.05-4.4c.25-1.03-.38-1.85-1.4-1.85h-9.63l.36-1.44h8.13l.84-3.35H10.6Zm10.44 0-.84 3.35h1.67l.83-3.35h-1.66Zm2.5 0-.84 3.35h.83l.84-3.35h-.83Z"
251
382
  }
252
383
  ) }),
253
- /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("p", { className: "text-xs text-black/50", children: [
384
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("p", { className: "text-xs text-black/50", children: [
254
385
  "Spree enables seamless crypto payments for real-world goods, travel, and experiences. Enjoy secure, fast transactions and earn rewards.",
255
386
  " ",
256
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("a", { className: "underline", href: "https://www.spree.finance/", target: "_blank", rel: "noreferrer", children: "Learn more" }),
387
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("a", { className: "underline", href: "https://www.spree.finance/", target: "_blank", rel: "noreferrer", children: "Learn more" }),
257
388
  " ",
258
389
  "about Spree."
259
390
  ] })
@@ -261,31 +392,13 @@ var SpreeLegal = () => {
261
392
  };
262
393
 
263
394
  // src/components/CreditCardTab/CreditCardTab.tsx
264
- var import_react7 = require("react");
265
-
266
- // src/hooks/useCards.ts
267
- var import_swr = __toESM(require("swr"), 1);
268
- var useCards = () => {
269
- const { data, isLoading, mutate } = (0, import_swr.default)(`/v1/payments/cards`);
270
- return {
271
- cards: data?.data.filter((c) => c.active) || [],
272
- cardsIsLoading: isLoading,
273
- mutateCards: mutate
274
- };
275
- };
276
-
277
- // src/hooks/useSlapiBalance.ts
278
- var import_swr2 = __toESM(require("swr"), 1);
279
- var useSlapiBalance = () => {
280
- const { data, isLoading, mutate } = (0, import_swr2.default)(`/v1/loyalty/accounts`);
281
- return { balance: data?.detail, isBalanceLoading: isLoading, mutateBalance: mutate };
282
- };
395
+ var import_react13 = require("react");
283
396
 
284
- // src/services/cardPayment.ts
397
+ // src/hooks/useCardPayment.ts
285
398
  var import_nice_modal_react2 = __toESM(require("@ebay/nice-modal-react"), 1);
286
399
 
287
400
  // src/modals/Iframe3ds.tsx
288
- var import_react3 = require("react");
401
+ var import_react4 = require("react");
289
402
  var import_nice_modal_react = __toESM(require("@ebay/nice-modal-react"), 1);
290
403
 
291
404
  // src/services/eventBus.ts
@@ -307,30 +420,30 @@ var DialogPrimitive = __toESM(require("@radix-ui/react-dialog"), 1);
307
420
  var import_lucide_react = require("lucide-react");
308
421
 
309
422
  // src/ui/portal.ts
310
- var import_react2 = __toESM(require("react"), 1);
311
- var PortalContainerContext = import_react2.default.createContext({ container: null });
423
+ var import_react3 = __toESM(require("react"), 1);
424
+ var PortalContainerContext = import_react3.default.createContext({ container: null });
312
425
  function PortalContainerProvider({
313
426
  container,
314
427
  children
315
428
  }) {
316
- return import_react2.default.createElement(PortalContainerContext.Provider, { value: { container } }, children);
429
+ return import_react3.default.createElement(PortalContainerContext.Provider, { value: { container } }, children);
317
430
  }
318
431
  function usePortalContainer() {
319
- return import_react2.default.useContext(PortalContainerContext).container;
432
+ return import_react3.default.useContext(PortalContainerContext).container;
320
433
  }
321
434
 
322
435
  // src/ui/dialog.tsx
323
- var import_jsx_runtime5 = require("react/jsx-runtime");
436
+ var import_jsx_runtime6 = require("react/jsx-runtime");
324
437
  function Dialog({ ...props }) {
325
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(DialogPrimitive.Root, { "data-slot": "dialog", ...props });
438
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(DialogPrimitive.Root, { "data-slot": "dialog", ...props });
326
439
  }
327
440
  function DialogPortal({ ...props }) {
328
441
  const container = usePortalContainer();
329
442
  const safeContainer = container && document.body.contains(container) ? container : void 0;
330
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(DialogPrimitive.Portal, { container: safeContainer, "data-slot": "dialog-portal", ...props });
443
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(DialogPrimitive.Portal, { container: safeContainer, "data-slot": "dialog-portal", ...props });
331
444
  }
332
445
  function DialogOverlay({ className, ...props }) {
333
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
446
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
334
447
  DialogPrimitive.Overlay,
335
448
  {
336
449
  "data-slot": "dialog-overlay",
@@ -348,9 +461,9 @@ function DialogContent({
348
461
  showCloseButton = true,
349
462
  ...props
350
463
  }) {
351
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(DialogPortal, { "data-slot": "dialog-portal", children: [
352
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(DialogOverlay, {}),
353
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
464
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(DialogPortal, { "data-slot": "dialog-portal", children: [
465
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(DialogOverlay, {}),
466
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
354
467
  DialogPrimitive.Content,
355
468
  {
356
469
  "data-slot": "dialog-content",
@@ -361,14 +474,14 @@ function DialogContent({
361
474
  ...props,
362
475
  children: [
363
476
  children,
364
- showCloseButton && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
477
+ showCloseButton && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
365
478
  DialogPrimitive.Close,
366
479
  {
367
480
  "data-slot": "dialog-close",
368
481
  className: "ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
369
482
  children: [
370
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react.XIcon, {}),
371
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "sr-only", children: "Close" })
483
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_lucide_react.XIcon, {}),
484
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "sr-only", children: "Close" })
372
485
  ]
373
486
  }
374
487
  )
@@ -378,7 +491,7 @@ function DialogContent({
378
491
  ] });
379
492
  }
380
493
  function DialogTitle({ className, ...props }) {
381
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
494
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
382
495
  DialogPrimitive.Title,
383
496
  {
384
497
  "data-slot": "dialog-title",
@@ -388,7 +501,7 @@ function DialogTitle({ className, ...props }) {
388
501
  );
389
502
  }
390
503
  function DialogDescription({ className, ...props }) {
391
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
504
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
392
505
  DialogPrimitive.Description,
393
506
  {
394
507
  "data-slot": "dialog-description",
@@ -399,10 +512,10 @@ function DialogDescription({ className, ...props }) {
399
512
  }
400
513
 
401
514
  // src/modals/Iframe3ds.tsx
402
- var import_jsx_runtime6 = require("react/jsx-runtime");
515
+ var import_jsx_runtime7 = require("react/jsx-runtime");
403
516
  var Iframe3ds = import_nice_modal_react.default.create(({ url }) => {
404
517
  const modal = (0, import_nice_modal_react.useModal)();
405
- (0, import_react3.useEffect)(() => {
518
+ (0, import_react4.useEffect)(() => {
406
519
  return bus.on("paymentIntent", (data) => {
407
520
  modal.resolve(data.paymentIntent);
408
521
  modal.remove();
@@ -412,9 +525,9 @@ var Iframe3ds = import_nice_modal_react.default.create(({ url }) => {
412
525
  modal.reject();
413
526
  modal.remove();
414
527
  };
415
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Dialog, { open: modal.visible, onOpenChange: handleClose, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(DialogContent, { className: "max-h-[600px] w-full max-w-[680px] p-0", children: [
416
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(DialogTitle, { className: "hidden", children: "3D Secure Verification" }),
417
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("iframe", { src: url, id: "3ds-iframe", title: "3D Secure Checkout", className: "h-[500px] w-full rounded-lg border-0" })
528
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Dialog, { open: modal.visible, onOpenChange: handleClose, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(DialogContent, { className: "max-h-[600px] w-full max-w-[680px] p-0", children: [
529
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(DialogTitle, { className: "hidden", children: "3D Secure Verification" }),
530
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("iframe", { src: url, id: "3ds-iframe", title: "3D Secure Checkout", className: "h-[500px] w-full rounded-lg border-0" })
418
531
  ] }) });
419
532
  });
420
533
  Iframe3ds.displayName = "Iframe3ds";
@@ -516,32 +629,13 @@ var registerApi = (config2) => {
516
629
 
517
630
  // src/services/slapi.ts
518
631
  var SlapiPaymentService = {
519
- // checkBallance: async ({ coin, amount, slippage }: CheckBallanceParams) => {
520
- // // if no ballance known, return true and check by wallet
521
- // if (!coin.balance) return true;
522
- // const isUSDC = coin.symbol === COIN.USDC;
523
- // if (isUSDC) return coin.balance > amount;
524
- // const inputDecimals = cryptoAssets[COIN.USDC].decimals; // Decimals for USDC
525
- // const outputDecimals = coin.decimals; // Decimals for the input asset (e.g., SOL, BONK)
526
- // const params = {
527
- // inputMint: env.NEXT_PUBLIC_USDC_MAINNET_MINT_ADDRESS, // should be main net
528
- // outputMint: coin.address,
529
- // amount: Math.floor(amount * Math.pow(10, inputDecimals)), // Convert amount to smallest units
530
- // slippage,
531
- // };
532
- // // eslint-disable-next-line @typescript-eslint/no-explicit-any
533
- // const { data } = await jupiterApi.get<any>(`/quote?${qs.stringify(params)}`);
534
- // // Convert back to human-readable form
535
- // const outAmountNumber = data?.outAmount ? Number(data.outAmount) / Math.pow(10, outputDecimals) : null;
536
- // // if no ballance known, return true and check by wallet
537
- // if (!outAmountNumber) return true;
538
- // return coin.balance > outAmountNumber;
539
- // },
540
632
  createPayment: (params) => {
541
633
  const { type, hash, metadata, capture = false } = params;
542
634
  let reqParams;
543
635
  if (type === "CRYPTO" /* CRYPTO */) {
544
636
  reqParams = { type, hash, crypto: params.crypto };
637
+ } else if (type === "CREDIT_CARD" /* CREDIT_CARD */ && params.points && params.points.amount > 0) {
638
+ reqParams = { type: "SPLIT" /* SPLIT */, hash, card: params.card, points: params.points };
545
639
  } else {
546
640
  reqParams = { type, hash, card: params.card };
547
641
  }
@@ -550,132 +644,271 @@ var SlapiPaymentService = {
550
644
  baseVerify: ({ id, txHash }) => {
551
645
  return slapiApi.post(`/v1/base-transactions/transactions/${id}/verify`, { txHash });
552
646
  },
553
- // signEncodedTransaction: async (signTransaction: SignTransaction, encodedTX: string): Promise<string> => {
554
- // const swapTransactionBuf = Buffer.from(encodedTX, 'base64');
555
- // const transaction = VersionedTransaction.deserialize(swapTransactionBuf);
556
- // // Sign and send the transaction
557
- // const signedTransaction = await signTransaction(transaction);
558
- // return Buffer.from(signedTransaction.serialize()).toString('base64');
559
- // },
560
- // executeSolana: (params: { txId: string; signedTx: string }) => {
561
- // const { txId, signedTx } = params;
562
- // return slapiApi.post<string>(`/solana-transactions/transactions/${txId}/execute`, { signedTx });
563
- // },
564
- addCard: (params) => {
565
- const { source, hash } = params;
647
+ addCard: ({ source, hash }) => {
566
648
  return slapiApi.post("/v1/payments/cards", { hash, source }).then((data) => ({ data }));
567
649
  },
568
- validate3DS: (params) => {
569
- const { paymentId } = params;
570
- return slapiApi.post("/v1/payments/validate", { paymentId, type: "CREDIT_CARD" }).then((data) => ({ data }));
650
+ validate3DS: ({ paymentId }) => {
651
+ return slapiApi.post("/v1/payments/validate", { paymentId, type: "CREDIT_CARD" /* CREDIT_CARD */ }).then((data) => ({ data }));
652
+ },
653
+ validatePoints: ({ paymentId, txHash }) => {
654
+ return slapiApi.post("/v1/payments/validate", { txHash, paymentId, type: "POINTS" /* POINTS */ }).then((data) => ({ data }));
655
+ },
656
+ getStatus: (paymentId) => {
657
+ return slapiApi.get(`/v1/payments/${paymentId}/status`);
571
658
  }
572
659
  };
573
660
 
574
- // src/services/cardPayment.ts
575
- var cardPayment = async (params) => {
576
- const { card, redirect3dsURI, hash, capture, metadata, transactionFee } = params;
577
- let cardId = card.id;
578
- if ("token" in card) {
579
- const { data: cardResData } = await SlapiPaymentService.addCard({ hash, source: card.token });
580
- cardId = cardResData.id;
581
- }
582
- const { data: paymentResData } = await SlapiPaymentService.createPayment({
583
- hash,
584
- capture,
585
- metadata,
586
- type: "CREDIT_CARD" /* CREDIT_CARD */,
587
- card: {
588
- cardId,
589
- transactionFee,
590
- returnUrl: `${window.location.origin}${redirect3dsURI}`
661
+ // src/hooks/useCardPayment.ts
662
+ var useCardPayment = () => {
663
+ const { selectedPaymentMethod } = useSpreePaymentMethod();
664
+ const { env } = useSpreePayEnv();
665
+ const { appProps } = useStaticConfig();
666
+ const cardPayment = async (params) => {
667
+ if (selectedPaymentMethod.type !== "CREDIT_CARD" /* CREDIT_CARD */ || !selectedPaymentMethod.method) {
668
+ throw new Error("Unsupported payment method");
591
669
  }
592
- });
593
- if (paymentResData.redirectUrl) {
594
- const paymentIntent = await import_nice_modal_react2.default.show(Iframe3ds, { url: paymentResData.redirectUrl });
595
- if (paymentIntent) {
596
- const { data: validateData } = await SlapiPaymentService.validate3DS({ paymentId: paymentResData.id });
597
- return {
598
- paymentType: "CREDIT_CARD" /* CREDIT_CARD */,
599
- status: validateData.status,
600
- paymentId: paymentResData.id,
601
- txId: paymentResData.txId,
602
- txHash: null
603
- };
670
+ const { hash, capture, metadata } = params;
671
+ const card = selectedPaymentMethod.method;
672
+ let cardId;
673
+ if ("token" in card) {
674
+ const { data: cardResData } = await SlapiPaymentService.addCard({ hash, source: card.token });
675
+ cardId = cardResData.id;
676
+ } else {
677
+ cardId = card.id;
604
678
  }
605
- }
679
+ const transactionFee = getTransactionFee(appProps.amount, appProps.transactionFeePercentage);
680
+ const { data: paymentResData } = await SlapiPaymentService.createPayment({
681
+ hash,
682
+ capture,
683
+ metadata,
684
+ type: "CREDIT_CARD" /* CREDIT_CARD */,
685
+ card: {
686
+ cardId,
687
+ transactionFee,
688
+ returnUrl: `${typeof window !== "undefined" ? window.location.origin : ""}${env.redirect3dsURI}`
689
+ }
690
+ });
691
+ let { status } = paymentResData;
692
+ if (paymentResData.redirectUrl) {
693
+ const paymentIntent = await import_nice_modal_react2.default.show(Iframe3ds, { url: paymentResData.redirectUrl });
694
+ if (paymentIntent) {
695
+ const { data: validateData } = await SlapiPaymentService.validate3DS({ paymentId: paymentResData.id });
696
+ ({ status } = validateData);
697
+ }
698
+ }
699
+ return {
700
+ status,
701
+ paymentType: "CREDIT_CARD" /* CREDIT_CARD */,
702
+ paymentId: paymentResData.id,
703
+ txId: paymentResData.txId,
704
+ txHash: null
705
+ };
706
+ };
707
+ return { cardPayment };
708
+ };
709
+
710
+ // src/hooks/useCards.ts
711
+ var import_swr2 = __toESM(require("swr"), 1);
712
+ var useCards = () => {
713
+ const { data, isLoading, mutate } = (0, import_swr2.default)(`/v1/payments/cards`);
606
714
  return {
607
- paymentType: "CREDIT_CARD" /* CREDIT_CARD */,
608
- status: paymentResData.status,
609
- paymentId: paymentResData.id,
610
- txId: paymentResData.txId,
611
- txHash: null
715
+ cards: data?.data.filter((c) => c.active) || [],
716
+ cardsIsLoading: isLoading,
717
+ mutateCards: mutate
612
718
  };
613
719
  };
614
720
 
615
- // src/components/common/PointsSwitch.tsx
616
- var import_react4 = require("react");
721
+ // src/hooks/useSplitCardPayments.ts
722
+ var import_nice_modal_react3 = __toESM(require("@ebay/nice-modal-react"), 1);
617
723
 
618
- // src/ui/label.tsx
619
- var LabelPrimitive = __toESM(require("@radix-ui/react-label"), 1);
620
- var import_jsx_runtime7 = require("react/jsx-runtime");
621
- function Label({ className, ...props }) {
622
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
623
- LabelPrimitive.Root,
624
- {
625
- "data-slot": "label",
626
- className: cn(
627
- "flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50",
628
- className
629
- ),
630
- ...props
724
+ // src/services/AirWalletService.ts
725
+ var import_airkit = require("@mocanetwork/airkit");
726
+ var import_viem = require("viem");
727
+ var singletonState = null;
728
+ var initPromise = null;
729
+ var cachedKey = null;
730
+ function optionsKey(opts) {
731
+ return `${opts.partnerId}|${opts.mocaChain?.id ?? "unknown"}`;
732
+ }
733
+ async function createAndInit(opts) {
734
+ const air = new import_airkit.AirService({ partnerId: opts.partnerId });
735
+ try {
736
+ await air.init({
737
+ buildEnv: opts.buildEnv ?? import_airkit.BUILD_ENV.SANDBOX,
738
+ enableLogging: opts.enableLogging ?? true,
739
+ skipRehydration: opts.skipRehydration ?? false
740
+ });
741
+ air.preloadWallet().catch(() => {
742
+ });
743
+ const loginRes = await air.login();
744
+ const address = loginRes?.abstractAccountAddress || null;
745
+ const walletClient = address ? (0, import_viem.createWalletClient)({
746
+ transport: (0, import_viem.custom)(air.provider),
747
+ chain: opts.mocaChain,
748
+ account: address
749
+ }) : null;
750
+ return { walletReady: true, address, walletClient, air, chain: opts.mocaChain };
751
+ } catch (e) {
752
+ const msg = e instanceof Error ? e.message : "Unknown error during AirWallet initialization";
753
+ return { walletReady: false, address: null, walletClient: null, air: null, chain: null, error: msg };
754
+ }
755
+ }
756
+ async function getAirWallet(options) {
757
+ const key = optionsKey(options);
758
+ if (singletonState && cachedKey === key) return singletonState;
759
+ if (initPromise && cachedKey === key) return initPromise;
760
+ cachedKey = key;
761
+ initPromise = createAndInit(options).then((state) => {
762
+ singletonState = state;
763
+ return state;
764
+ });
765
+ return initPromise;
766
+ }
767
+ function peekAirWallet() {
768
+ return singletonState;
769
+ }
770
+ async function handleSendErc20(params) {
771
+ const state = singletonState;
772
+ if (!state?.walletClient) {
773
+ console.error("Air wallet is not initialized");
774
+ throw new Error("Air wallet is not initialized");
775
+ }
776
+ if (!params?.recipient) {
777
+ console.error("Recipient address is not set");
778
+ throw new Error("Recipient address is not set");
779
+ }
780
+ if (!params?.token?.address || !params?.token?.decimals) {
781
+ console.error("Token address or decimals not set");
782
+ throw new Error("Token address or decimals not set");
783
+ }
784
+ try {
785
+ const { walletClient } = state;
786
+ const addresses = await walletClient.getAddresses();
787
+ const value = (0, import_viem.parseUnits)(String(params.amount), params.token.decimals);
788
+ const data = (0, import_viem.encodeFunctionData)({
789
+ abi: import_viem.erc20Abi,
790
+ functionName: "transfer",
791
+ args: [params.recipient, value]
792
+ });
793
+ const hash = await walletClient.sendTransaction({
794
+ account: addresses[0],
795
+ to: params.token.address,
796
+ data,
797
+ value: 0n,
798
+ chain: state.chain ?? void 0
799
+ });
800
+ return { txHash: hash };
801
+ } catch (error) {
802
+ if (typeof error === "object" && error !== null && "shortMessage" in error) {
803
+ console.error(error.shortMessage);
804
+ } else {
805
+ console.error("Your wallet balances are insufficient to complete this transaction.");
631
806
  }
632
- );
807
+ }
633
808
  }
634
809
 
635
- // src/ui/switch.tsx
636
- var SwitchPrimitive = __toESM(require("@radix-ui/react-switch"), 1);
637
- var import_jsx_runtime8 = require("react/jsx-runtime");
638
- function Switch({ className, ...props }) {
639
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
640
- SwitchPrimitive.Root,
641
- {
642
- "data-slot": "switch",
643
- className: cn(
644
- "peer data-[state=checked]:bg-primary data-[state=unchecked]:bg-input focus-visible:border-ring focus-visible:ring-ring/50 dark:data-[state=unchecked]:bg-input/80 inline-flex h-[1.15rem] w-8 shrink-0 items-center rounded-full border border-transparent shadow-xs transition-all outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",
645
- className
646
- ),
647
- ...props,
648
- children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
649
- SwitchPrimitive.Thumb,
650
- {
651
- "data-slot": "switch-thumb",
652
- className: "bg-background dark:data-[state=unchecked]:bg-foreground dark:data-[state=checked]:bg-primary-foreground pointer-events-none block size-4 rounded-full ring-0 transition-transform data-[state=checked]:translate-x-[calc(100%-2px)] data-[state=unchecked]:translate-x-0"
653
- }
654
- )
810
+ // src/hooks/useSplitCardPayments.ts
811
+ var REFRESH_INTERVAL = 3 * 1e3;
812
+ var MAX_RETRIES = 10;
813
+ async function longPollPoints(paymentId) {
814
+ let retries = 0;
815
+ while (retries < MAX_RETRIES) {
816
+ const { detail } = await SlapiPaymentService.getStatus(paymentId);
817
+ if (detail.status === "FAILED" /* FAILED */) {
818
+ throw new Error("Something went wrong with the payment");
655
819
  }
656
- );
820
+ if (["AUTHORIZED" /* AUTHORIZED */, "CAPTURED" /* CAPTURED */].includes(detail.status)) {
821
+ return detail.status;
822
+ }
823
+ await new Promise((res) => setTimeout(res, REFRESH_INTERVAL));
824
+ retries++;
825
+ }
826
+ throw new Error("Points Payment polling timed out");
657
827
  }
658
-
659
- // src/components/common/PointsSwitch.tsx
660
- var import_jsx_runtime9 = require("react/jsx-runtime");
661
- var PointsSwitch = (props) => {
662
- const { pointsConversionRatio, disabled = false, value, onChange, pointsTitle } = props;
663
- const { balance } = useSlapiBalance();
664
- const id = (0, import_react4.useId)();
665
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "flex items-center justify-between gap-3", children: [
666
- /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "flex items-center gap-3", children: [
667
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Switch, { checked: value, onCheckedChange: onChange, disabled, id }),
668
- /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(Label, { className: "text-md items-baseline leading-[1.3] font-semibold text-black md:text-xl", htmlFor: id, children: [
669
- "Use Points ",
670
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "text-xs font-medium", children: "Optional" })
671
- ] })
672
- ] }),
673
- balance?.availablePoints ? /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("p", { className: "flex-1 text-right text-sm font-medium text-black", children: [
674
- formatPoints(balance.availablePoints, pointsTitle),
675
- " ",
676
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "text-black/50", children: formatUSD(balance.availablePoints / pointsConversionRatio) })
677
- ] }) : null
678
- ] });
828
+ async function longPollCardStatus(paymentId) {
829
+ let retries = 0;
830
+ let shown3ds = false;
831
+ while (retries < MAX_RETRIES) {
832
+ const { detail } = await SlapiPaymentService.getStatus(paymentId);
833
+ if (detail.status === "FAILED" /* FAILED */) {
834
+ throw new Error(`Something went wrong with the ${detail.validationType} payment`);
835
+ }
836
+ if (detail.validationType === "POINTS") {
837
+ return detail.status;
838
+ }
839
+ if (!shown3ds && detail.card?.redirectUrl) {
840
+ const paymentIntent = await import_nice_modal_react3.default.show(Iframe3ds, { url: detail.card?.redirectUrl });
841
+ shown3ds = true;
842
+ if (paymentIntent) {
843
+ await SlapiPaymentService.validate3DS({ paymentId });
844
+ }
845
+ }
846
+ await new Promise((res) => setTimeout(res, REFRESH_INTERVAL));
847
+ retries++;
848
+ }
849
+ throw new Error("Payment polling timed out");
850
+ }
851
+ var useSplitCardPayments = () => {
852
+ const { selectedPaymentMethod } = useSpreePaymentMethod();
853
+ const { env } = useSpreePayEnv();
854
+ const { appProps, staticConfig } = useStaticConfig();
855
+ const { spreePayConfig } = useSpreePayConfig();
856
+ const splitPayment = async (params) => {
857
+ if (selectedPaymentMethod.type !== "CREDIT_CARD" /* CREDIT_CARD */ || !selectedPaymentMethod.method || !params.points) {
858
+ throw new Error("Unsupported payment method");
859
+ }
860
+ const { hash, capture, metadata, points } = params;
861
+ const card = selectedPaymentMethod.method;
862
+ let cardId;
863
+ if ("token" in card) {
864
+ const { data: cardResData } = await SlapiPaymentService.addCard({ hash, source: card.token });
865
+ cardId = cardResData.id;
866
+ } else {
867
+ cardId = card.id;
868
+ }
869
+ const usdAmount = getSplitAmount(appProps.amount ?? 0, points, staticConfig.pointsConversionRatio);
870
+ const transactionFee = getTransactionFee(usdAmount, appProps.transactionFeePercentage);
871
+ const { data: paymentResData } = await SlapiPaymentService.createPayment({
872
+ hash,
873
+ capture,
874
+ metadata,
875
+ type: "CREDIT_CARD" /* CREDIT_CARD */,
876
+ card: {
877
+ cardId,
878
+ transactionFee,
879
+ returnUrl: `${typeof window !== "undefined" ? window.location.origin : ""}${env.redirect3dsURI}`
880
+ },
881
+ points: {
882
+ amount: points
883
+ }
884
+ });
885
+ await longPollCardStatus(paymentResData.id);
886
+ const wallet = peekAirWallet();
887
+ if (!wallet || !spreePayConfig?.pointsChain) {
888
+ throw new Error("AirWallet not found");
889
+ }
890
+ const transaction = await handleSendErc20({
891
+ amount: params.points,
892
+ token: spreePayConfig.pointsChain.pointsCoin,
893
+ recipient: spreePayConfig.pointsChain.recipientAddress
894
+ });
895
+ if (!transaction) {
896
+ throw new Error("Points transaction failed");
897
+ }
898
+ await SlapiPaymentService.validatePoints({
899
+ paymentId: paymentResData.id,
900
+ txHash: transaction.txHash
901
+ });
902
+ const pointsStatus = await longPollPoints(paymentResData.id);
903
+ return {
904
+ paymentType: "SPLIT" /* SPLIT */,
905
+ status: pointsStatus,
906
+ paymentId: paymentResData.id,
907
+ txId: paymentResData.txId,
908
+ txHash: transaction.txHash
909
+ };
910
+ };
911
+ return { splitPayment };
679
912
  };
680
913
 
681
914
  // src/components/CreditCardTab/CreditCard/CreditCard.tsx
@@ -683,15 +916,8 @@ var import_react6 = require("react");
683
916
  var import_react_stripe_js2 = require("@stripe/react-stripe-js");
684
917
  var import_stripe_js = require("@stripe/stripe-js");
685
918
 
686
- // src/hooks/useConfig.ts
687
- var import_swr3 = __toESM(require("swr"), 1);
688
- var useConfig = () => {
689
- const { data, isLoading } = (0, import_swr3.default)("/v1/tenants/configs/spree-pay");
690
- return { config: data, configIsLoading: isLoading };
691
- };
692
-
693
919
  // src/components/CreditCardTab/CreditCard/CardsList.tsx
694
- var import_jsx_runtime10 = require("react/jsx-runtime");
920
+ var import_jsx_runtime8 = require("react/jsx-runtime");
695
921
  var isRemoveDisabled = true;
696
922
  var CardListItem = ({ card, isSelected, onSelect }) => {
697
923
  const handleSelect = () => {
@@ -701,17 +927,17 @@ var CardListItem = ({ card, isSelected, onSelect }) => {
701
927
  e.stopPropagation();
702
928
  if (isSelected || isRemoveDisabled) return;
703
929
  };
704
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("button", { type: "button", onClick: handleSelect, className: "bg-primary/8 flex h-11 w-full overflow-hidden rounded-md", children: [
705
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
930
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("button", { type: "button", onClick: handleSelect, className: "bg-primary/8 flex h-11 w-full overflow-hidden rounded-md", children: [
931
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
706
932
  "div",
707
933
  {
708
934
  className: cn("flex h-full w-11 items-center justify-center bg-black/10", {
709
935
  "bg-primary": isSelected
710
936
  }),
711
- children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "flex h-5 w-5 items-center justify-center rounded-full bg-white", children: isSelected && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "bg-primary h-2.5 w-2.5 rounded-full" }) })
937
+ children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "flex h-5 w-5 items-center justify-center rounded-full bg-white", children: isSelected && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "bg-primary h-2.5 w-2.5 rounded-full" }) })
712
938
  }
713
939
  ),
714
- /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
940
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
715
941
  "div",
716
942
  {
717
943
  className: cn(
@@ -721,13 +947,13 @@ var CardListItem = ({ card, isSelected, onSelect }) => {
721
947
  }
722
948
  ),
723
949
  children: [
724
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "flex items-center gap-2", children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("p", { className: "text-sm font-medium text-black", children: card.schema }) }),
725
- /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "flex items-center gap-2", children: [
726
- /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("p", { className: "text-sm font-medium text-black/50", children: [
950
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "flex items-center gap-2", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("p", { className: "text-sm font-medium text-black", children: card.schema }) }),
951
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "flex items-center gap-2", children: [
952
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("p", { className: "text-sm font-medium text-black/50", children: [
727
953
  "Ending in ",
728
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { className: "text-black", children: card.lastFourNumbers })
954
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "text-black", children: card.lastFourNumbers })
729
955
  ] }),
730
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
956
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
731
957
  "div",
732
958
  {
733
959
  onClick: handleRemoveCard,
@@ -735,9 +961,9 @@ var CardListItem = ({ card, isSelected, onSelect }) => {
735
961
  "cursor-not-allowed opacity-50": isSelected || isRemoveDisabled
736
962
  // 'cursor-pointer': !isSelected || !isRemoveDisabled,
737
963
  }),
738
- children: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("svg", { xmlns: "http://www.w3.org/2000/svg", width: "20", height: "20", fill: "none", children: [
739
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("mask", { id: "mask0_188_5407", width: "20", height: "21", x: "0", y: "-1", maskUnits: "userSpaceOnUse", children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("path", { fill: "#D9D9D9", d: "M0-.5h20v20H0z" }) }),
740
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("g", { mask: "url(#mask0_188_5407)", children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
964
+ children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("svg", { xmlns: "http://www.w3.org/2000/svg", width: "20", height: "20", fill: "none", children: [
965
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("mask", { id: "mask0_188_5407", width: "20", height: "21", x: "0", y: "-1", maskUnits: "userSpaceOnUse", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("path", { fill: "#D9D9D9", d: "M0-.5h20v20H0z" }) }),
966
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("g", { mask: "url(#mask0_188_5407)", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
741
967
  "path",
742
968
  {
743
969
  fill: "#000",
@@ -757,13 +983,13 @@ var CardListItem = ({ card, isSelected, onSelect }) => {
757
983
  var CardsList = ({ selectedCard, setCard }) => {
758
984
  const { cards, cardsIsLoading } = useCards();
759
985
  if (cardsIsLoading) {
760
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "flex w-full flex-col gap-1", children: [
761
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "bg-primary/8 h-11 animate-pulse rounded-md" }),
762
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "bg-primary/8 h-11 animate-pulse rounded-md" })
986
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "flex w-full flex-col gap-1", children: [
987
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "bg-primary/8 h-11 animate-pulse rounded-md" }),
988
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "bg-primary/8 h-11 animate-pulse rounded-md" })
763
989
  ] });
764
990
  }
765
991
  if (cards.length === 0) return null;
766
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "flex w-full flex-col gap-1", children: cards.map((card) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(CardListItem, { isSelected: selectedCard?.id === card.id, onSelect: setCard, card }, card.id)) });
992
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "flex w-full flex-col gap-1", children: cards.map((card) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(CardListItem, { isSelected: selectedCard?.id === card.id, onSelect: setCard, card }, card.id)) });
767
993
  };
768
994
 
769
995
  // src/components/CreditCardTab/CreditCard/CreditCardForm.tsx
@@ -773,7 +999,7 @@ var import_react_stripe_js = require("@stripe/react-stripe-js");
773
999
  // src/ui/button.tsx
774
1000
  var import_react_slot = require("@radix-ui/react-slot");
775
1001
  var import_class_variance_authority = require("class-variance-authority");
776
- var import_jsx_runtime11 = require("react/jsx-runtime");
1002
+ var import_jsx_runtime9 = require("react/jsx-runtime");
777
1003
  var buttonVariants = (0, import_class_variance_authority.cva)(
778
1004
  "inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-full text-sm transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
779
1005
  {
@@ -808,15 +1034,15 @@ function Button({
808
1034
  ...props
809
1035
  }) {
810
1036
  const Comp = asChild ? import_react_slot.Slot : "button";
811
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(Comp, { "data-slot": "button", className: cn(buttonVariants({ variant, size, className })), ...props });
1037
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Comp, { "data-slot": "button", className: cn(buttonVariants({ variant, size, className })), ...props });
812
1038
  }
813
1039
 
814
1040
  // src/ui/checkbox.tsx
815
1041
  var CheckboxPrimitive = __toESM(require("@radix-ui/react-checkbox"), 1);
816
1042
  var import_lucide_react2 = require("lucide-react");
817
- var import_jsx_runtime12 = require("react/jsx-runtime");
1043
+ var import_jsx_runtime10 = require("react/jsx-runtime");
818
1044
  function Checkbox({ className, ...props }) {
819
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1045
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
820
1046
  CheckboxPrimitive.Root,
821
1047
  {
822
1048
  "data-slot": "checkbox",
@@ -825,20 +1051,37 @@ function Checkbox({ className, ...props }) {
825
1051
  className
826
1052
  ),
827
1053
  ...props,
828
- children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1054
+ children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
829
1055
  CheckboxPrimitive.Indicator,
830
1056
  {
831
1057
  "data-slot": "checkbox-indicator",
832
1058
  className: "flex items-center justify-center text-current transition-none",
833
- children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_lucide_react2.CheckIcon, { className: "size-3.5 text-white" })
1059
+ children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_lucide_react2.CheckIcon, { className: "size-3.5 text-white" })
834
1060
  }
835
1061
  )
836
1062
  }
837
1063
  );
838
1064
  }
839
1065
 
1066
+ // src/ui/label.tsx
1067
+ var LabelPrimitive = __toESM(require("@radix-ui/react-label"), 1);
1068
+ var import_jsx_runtime11 = require("react/jsx-runtime");
1069
+ function Label({ className, ...props }) {
1070
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1071
+ LabelPrimitive.Root,
1072
+ {
1073
+ "data-slot": "label",
1074
+ className: cn(
1075
+ "flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50",
1076
+ className
1077
+ ),
1078
+ ...props
1079
+ }
1080
+ );
1081
+ }
1082
+
840
1083
  // src/components/CreditCardTab/CreditCard/CreditCardForm.tsx
841
- var import_jsx_runtime13 = require("react/jsx-runtime");
1084
+ var import_jsx_runtime12 = require("react/jsx-runtime");
842
1085
  var style = {
843
1086
  base: {
844
1087
  fontSize: "16px",
@@ -896,9 +1139,9 @@ var CreditCardForm = ({ cancel, saveCard }) => {
896
1139
  setCardError("An error occurred while processing your card. Please try again.");
897
1140
  }
898
1141
  };
899
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_jsx_runtime13.Fragment, { children: [
900
- /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "flex w-full flex-col gap-1", children: [
901
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
1142
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_jsx_runtime12.Fragment, { children: [
1143
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "flex w-full flex-col gap-1", children: [
1144
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
902
1145
  import_react_stripe_js.CardNumberElement,
903
1146
  {
904
1147
  options: {
@@ -908,8 +1151,8 @@ var CreditCardForm = ({ cancel, saveCard }) => {
908
1151
  }
909
1152
  }
910
1153
  ),
911
- /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "flex w-full gap-1", children: [
912
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
1154
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "flex w-full gap-1", children: [
1155
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
913
1156
  import_react_stripe_js.CardExpiryElement,
914
1157
  {
915
1158
  options: {
@@ -919,7 +1162,7 @@ var CreditCardForm = ({ cancel, saveCard }) => {
919
1162
  }
920
1163
  }
921
1164
  ),
922
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
1165
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
923
1166
  import_react_stripe_js.CardCvcElement,
924
1167
  {
925
1168
  options: {
@@ -930,32 +1173,32 @@ var CreditCardForm = ({ cancel, saveCard }) => {
930
1173
  }
931
1174
  )
932
1175
  ] }),
933
- cardError && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("p", { className: "text-destructive mt-1 text-sm", children: cardError })
1176
+ cardError && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("p", { className: "text-destructive mt-1 text-sm", children: cardError })
934
1177
  ] }),
935
- /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "flex items-center gap-2", children: [
936
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Checkbox, { disabled: true, checked: true, id: "saveCard" }),
937
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Label, { className: "text-sm font-medium", htmlFor: "saveCard", children: "Save card for future purchases" })
1178
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "flex items-center gap-2", children: [
1179
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(Checkbox, { disabled: true, checked: true, id: "saveCard" }),
1180
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(Label, { className: "text-sm font-medium", htmlFor: "saveCard", children: "Save card for future purchases" })
938
1181
  ] }),
939
- /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "flex w-full justify-end gap-2", children: [
940
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Button, { variant: "secondary", onClick: cancel, children: "Cancel" }),
941
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Button, { onClick: handleSaveCard, children: "Add Card" })
1182
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "flex w-full justify-end gap-2", children: [
1183
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(Button, { variant: "secondary", onClick: cancel, children: "Cancel" }),
1184
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(Button, { onClick: handleSaveCard, children: "Add Card" })
942
1185
  ] })
943
1186
  ] });
944
1187
  };
945
1188
 
946
1189
  // src/components/CreditCardTab/CreditCard/CreditCard.tsx
947
- var import_jsx_runtime14 = require("react/jsx-runtime");
948
- var SripeWrapper = (props) => {
1190
+ var import_jsx_runtime13 = require("react/jsx-runtime");
1191
+ var StripeWrapper = (props) => {
949
1192
  const stripePromise = (0, import_react6.useMemo)(() => (0, import_stripe_js.loadStripe)(props.publicKey), [props.publicKey]);
950
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_react_stripe_js2.Elements, { stripe: stripePromise, children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(CreditCardForm, { cancel: props.onCancel, saveCard: props.saveNewCard }) });
1193
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_react_stripe_js2.Elements, { stripe: stripePromise, children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(CreditCardForm, { cancel: props.onCancel, saveCard: props.saveNewCard }) });
951
1194
  };
952
1195
  var CreditCard = () => {
953
1196
  const [showForm, setShowForm] = (0, import_react6.useState)(false);
954
1197
  const { selectedPaymentMethod, setSelectedPaymentMethod } = useSpreePaymentMethod();
955
1198
  const { mutateCards } = useCards();
956
- const { config: config2 } = useConfig();
1199
+ const { spreePayConfig } = useSpreePayConfig();
957
1200
  const setCard = (card) => {
958
- setSelectedPaymentMethod({ type: "CREDIT_CARD" /* CREDIT_CARD */, method: card });
1201
+ setSelectedPaymentMethod({ ...selectedPaymentMethod, type: "CREDIT_CARD" /* CREDIT_CARD */, method: card });
959
1202
  };
960
1203
  const saveNewCard = (newCard) => {
961
1204
  mutateCards((data) => ({ ...data, data: [...data?.data ?? [], newCard] }), { revalidate: false });
@@ -965,70 +1208,1222 @@ var CreditCard = () => {
965
1208
  const handleCancel = () => {
966
1209
  setShowForm(false);
967
1210
  };
968
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("div", { className: "flex flex-col items-baseline gap-4", children: [
969
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("h3", { className: "text-primary text-xl leading-[34px] font-semibold", children: "Your Credit Cards" }),
970
- !showForm && /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_jsx_runtime14.Fragment, { children: [
971
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
1211
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "flex flex-col items-baseline gap-4", children: [
1212
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("h3", { className: "text-primary text-xl leading-[34px] font-semibold", children: "Your Credit Cards" }),
1213
+ !showForm && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_jsx_runtime13.Fragment, { children: [
1214
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
972
1215
  CardsList,
973
1216
  {
974
1217
  selectedCard: selectedPaymentMethod?.type === "CREDIT_CARD" /* CREDIT_CARD */ ? selectedPaymentMethod.method : null,
975
1218
  setCard
976
1219
  }
977
1220
  ),
978
- config2?.stripePublicKey && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("button", { onClick: () => setShowForm(true), className: "text-sm font-medium text-black hover:underline", children: "Add new card" })
1221
+ spreePayConfig?.stripePublicKey && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("button", { onClick: () => setShowForm(true), className: "text-sm font-medium text-black hover:underline", children: "Add new card" })
979
1222
  ] }),
980
- config2?.stripePublicKey && showForm && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(SripeWrapper, { onCancel: handleCancel, saveNewCard, publicKey: config2.stripePublicKey })
1223
+ spreePayConfig?.stripePublicKey && showForm && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(StripeWrapper, { onCancel: handleCancel, saveNewCard, publicKey: spreePayConfig.stripePublicKey })
981
1224
  ] });
982
1225
  };
983
1226
 
984
- // src/components/CreditCardTab/CreditCardTab.tsx
985
- var import_jsx_runtime15 = require("react/jsx-runtime");
986
- var PointsSelector = ({ isSelected, onSelect, children }) => {
987
- return (
988
- // eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions
989
- /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(
990
- "div",
991
- {
992
- onClick: onSelect,
993
- className: cn("bg-primary/8 cursor-pointer overflow-hidden rounded-md border-1 border-transparent", {
994
- "border-primary": isSelected
995
- }),
996
- children: [
997
- /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { className: cn("flex h-11 w-full", { "bg-black/4": isSelected }), children: [
998
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
999
- "div",
1000
- {
1001
- className: cn("flex h-full w-11 items-center justify-center bg-black/10", {
1002
- "bg-primary": isSelected
1003
- }),
1004
- children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("div", { className: "flex h-5 w-5 items-center justify-center rounded-full bg-white", children: isSelected && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("div", { className: "bg-primary h-2.5 w-2.5 rounded-full" }) })
1005
- }
1006
- ),
1007
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("div", { className: "flex h-full w-full items-center justify-between gap-4 px-3", children })
1008
- ] }),
1009
- isSelected && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("div", { className: "px-4 pt-6 pb-2", children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("p", { children: "Card" }) })
1227
+ // src/components/CreditCardTab/Points/Points.tsx
1228
+ var import_react12 = require("react");
1229
+
1230
+ // src/components/common/PointsSwitch.tsx
1231
+ var import_react7 = require("react");
1232
+
1233
+ // src/hooks/useSlapiBalance.ts
1234
+ var import_swr3 = __toESM(require("swr"), 1);
1235
+ var useSlapiBalance = () => {
1236
+ const { data, isLoading, mutate } = (0, import_swr3.default)(`/v1/loyalty/accounts`);
1237
+ return { balance: data?.detail, isBalanceLoading: isLoading, mutateBalance: mutate };
1238
+ };
1239
+
1240
+ // src/ui/switch.tsx
1241
+ var SwitchPrimitive = __toESM(require("@radix-ui/react-switch"), 1);
1242
+ var import_jsx_runtime14 = require("react/jsx-runtime");
1243
+ function Switch({ className, ...props }) {
1244
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
1245
+ SwitchPrimitive.Root,
1246
+ {
1247
+ "data-slot": "switch",
1248
+ className: cn(
1249
+ "peer data-[state=checked]:bg-primary data-[state=unchecked]:bg-input focus-visible:border-ring focus-visible:ring-ring/50 dark:data-[state=unchecked]:bg-input/80 inline-flex h-[1.15rem] w-8 shrink-0 items-center rounded-full border border-transparent shadow-xs transition-all outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",
1250
+ className
1251
+ ),
1252
+ ...props,
1253
+ children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
1254
+ SwitchPrimitive.Thumb,
1255
+ {
1256
+ "data-slot": "switch-thumb",
1257
+ className: "bg-background dark:data-[state=unchecked]:bg-foreground dark:data-[state=checked]:bg-primary-foreground pointer-events-none block size-4 rounded-full ring-0 transition-transform data-[state=checked]:translate-x-[calc(100%-2px)] data-[state=unchecked]:translate-x-0"
1258
+ }
1259
+ )
1260
+ }
1261
+ );
1262
+ }
1263
+
1264
+ // src/components/common/PointsSwitch.tsx
1265
+ var import_jsx_runtime15 = require("react/jsx-runtime");
1266
+ var PointsSwitch = (props) => {
1267
+ const { disabled = false, value, onChange } = props;
1268
+ const { staticConfig } = useStaticConfig();
1269
+ const { pointsConversionRatio, pointsTitle } = staticConfig;
1270
+ const { balance } = useSlapiBalance();
1271
+ const id = (0, import_react7.useId)();
1272
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { className: "flex items-center justify-between gap-3", children: [
1273
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { className: "flex items-center gap-3", children: [
1274
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(Switch, { checked: value, onCheckedChange: onChange, disabled, id }),
1275
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(Label, { className: "text-md items-baseline leading-[1.3] font-semibold text-black md:text-xl", htmlFor: id, children: [
1276
+ "Use Points ",
1277
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("span", { className: "text-xs font-medium", children: "Optional" })
1278
+ ] })
1279
+ ] }),
1280
+ balance?.availablePoints ? /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("p", { className: "flex-1 text-right text-sm font-medium text-black", children: [
1281
+ formatPoints(balance.availablePoints, pointsTitle),
1282
+ " ",
1283
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("span", { className: "text-black/50", children: formatUSD(balance.availablePoints / pointsConversionRatio) })
1284
+ ] }) : null
1285
+ ] });
1286
+ };
1287
+
1288
+ // src/components/CreditCardTab/Points/SplitBlock.tsx
1289
+ var import_react11 = require("react");
1290
+
1291
+ // src/components/CreditCardTab/Points/PointsSelector.tsx
1292
+ var import_react10 = require("react");
1293
+
1294
+ // src/ui/input.tsx
1295
+ var import_jsx_runtime16 = require("react/jsx-runtime");
1296
+ function Input({ className, type, ...props }) {
1297
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
1298
+ "input",
1299
+ {
1300
+ type,
1301
+ "data-slot": "input",
1302
+ className: cn(
1303
+ "file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 border-input flex h-9 w-full min-w-0 rounded-md border bg-transparent px-3 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
1304
+ "focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]",
1305
+ "aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
1306
+ className
1307
+ ),
1308
+ ...props
1309
+ }
1310
+ );
1311
+ }
1312
+
1313
+ // src/ui/slider.tsx
1314
+ var React12 = __toESM(require("react"), 1);
1315
+
1316
+ // ../../node_modules/@radix-ui/react-slider/dist/index.mjs
1317
+ var React11 = __toESM(require("react"), 1);
1318
+
1319
+ // ../../node_modules/@radix-ui/number/dist/index.mjs
1320
+ function clamp(value, [min, max]) {
1321
+ return Math.min(max, Math.max(min, value));
1322
+ }
1323
+
1324
+ // ../../node_modules/@radix-ui/react-slider/node_modules/@radix-ui/primitive/dist/index.mjs
1325
+ var canUseDOM = !!(typeof window !== "undefined" && window.document && window.document.createElement);
1326
+ function composeEventHandlers(originalEventHandler, ourEventHandler, { checkForDefaultPrevented = true } = {}) {
1327
+ return function handleEvent(event) {
1328
+ originalEventHandler?.(event);
1329
+ if (checkForDefaultPrevented === false || !event.defaultPrevented) {
1330
+ return ourEventHandler?.(event);
1331
+ }
1332
+ };
1333
+ }
1334
+
1335
+ // ../../node_modules/@radix-ui/react-compose-refs/dist/index.mjs
1336
+ var React2 = __toESM(require("react"), 1);
1337
+ function setRef(ref, value) {
1338
+ if (typeof ref === "function") {
1339
+ return ref(value);
1340
+ } else if (ref !== null && ref !== void 0) {
1341
+ ref.current = value;
1342
+ }
1343
+ }
1344
+ function composeRefs(...refs) {
1345
+ return (node) => {
1346
+ let hasCleanup = false;
1347
+ const cleanups = refs.map((ref) => {
1348
+ const cleanup = setRef(ref, node);
1349
+ if (!hasCleanup && typeof cleanup == "function") {
1350
+ hasCleanup = true;
1351
+ }
1352
+ return cleanup;
1353
+ });
1354
+ if (hasCleanup) {
1355
+ return () => {
1356
+ for (let i = 0; i < cleanups.length; i++) {
1357
+ const cleanup = cleanups[i];
1358
+ if (typeof cleanup == "function") {
1359
+ cleanup();
1360
+ } else {
1361
+ setRef(refs[i], null);
1362
+ }
1363
+ }
1364
+ };
1365
+ }
1366
+ };
1367
+ }
1368
+ function useComposedRefs(...refs) {
1369
+ return React2.useCallback(composeRefs(...refs), refs);
1370
+ }
1371
+
1372
+ // ../../node_modules/@radix-ui/react-context/dist/index.mjs
1373
+ var React3 = __toESM(require("react"), 1);
1374
+ var import_jsx_runtime17 = require("react/jsx-runtime");
1375
+ function createContextScope(scopeName, createContextScopeDeps = []) {
1376
+ let defaultContexts = [];
1377
+ function createContext32(rootComponentName, defaultContext) {
1378
+ const BaseContext = React3.createContext(defaultContext);
1379
+ const index = defaultContexts.length;
1380
+ defaultContexts = [...defaultContexts, defaultContext];
1381
+ const Provider = (props) => {
1382
+ const { scope, children, ...context } = props;
1383
+ const Context = scope?.[scopeName]?.[index] || BaseContext;
1384
+ const value = React3.useMemo(() => context, Object.values(context));
1385
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(Context.Provider, { value, children });
1386
+ };
1387
+ Provider.displayName = rootComponentName + "Provider";
1388
+ function useContext22(consumerName, scope) {
1389
+ const Context = scope?.[scopeName]?.[index] || BaseContext;
1390
+ const context = React3.useContext(Context);
1391
+ if (context) return context;
1392
+ if (defaultContext !== void 0) return defaultContext;
1393
+ throw new Error(`\`${consumerName}\` must be used within \`${rootComponentName}\``);
1394
+ }
1395
+ return [Provider, useContext22];
1396
+ }
1397
+ const createScope = () => {
1398
+ const scopeContexts = defaultContexts.map((defaultContext) => {
1399
+ return React3.createContext(defaultContext);
1400
+ });
1401
+ return function useScope(scope) {
1402
+ const contexts = scope?.[scopeName] || scopeContexts;
1403
+ return React3.useMemo(
1404
+ () => ({ [`__scope${scopeName}`]: { ...scope, [scopeName]: contexts } }),
1405
+ [scope, contexts]
1406
+ );
1407
+ };
1408
+ };
1409
+ createScope.scopeName = scopeName;
1410
+ return [createContext32, composeContextScopes(createScope, ...createContextScopeDeps)];
1411
+ }
1412
+ function composeContextScopes(...scopes) {
1413
+ const baseScope = scopes[0];
1414
+ if (scopes.length === 1) return baseScope;
1415
+ const createScope = () => {
1416
+ const scopeHooks = scopes.map((createScope2) => ({
1417
+ useScope: createScope2(),
1418
+ scopeName: createScope2.scopeName
1419
+ }));
1420
+ return function useComposedScopes(overrideScopes) {
1421
+ const nextScopes = scopeHooks.reduce((nextScopes2, { useScope, scopeName }) => {
1422
+ const scopeProps = useScope(overrideScopes);
1423
+ const currentScope = scopeProps[`__scope${scopeName}`];
1424
+ return { ...nextScopes2, ...currentScope };
1425
+ }, {});
1426
+ return React3.useMemo(() => ({ [`__scope${baseScope.scopeName}`]: nextScopes }), [nextScopes]);
1427
+ };
1428
+ };
1429
+ createScope.scopeName = baseScope.scopeName;
1430
+ return createScope;
1431
+ }
1432
+
1433
+ // ../../node_modules/@radix-ui/react-use-controllable-state/dist/index.mjs
1434
+ var React5 = __toESM(require("react"), 1);
1435
+
1436
+ // ../../node_modules/@radix-ui/react-use-layout-effect/dist/index.mjs
1437
+ var React4 = __toESM(require("react"), 1);
1438
+ var useLayoutEffect2 = globalThis?.document ? React4.useLayoutEffect : () => {
1439
+ };
1440
+
1441
+ // ../../node_modules/@radix-ui/react-use-controllable-state/dist/index.mjs
1442
+ var React22 = __toESM(require("react"), 1);
1443
+ var useInsertionEffect = React5[" useInsertionEffect ".trim().toString()] || useLayoutEffect2;
1444
+ function useControllableState({
1445
+ prop,
1446
+ defaultProp,
1447
+ onChange = () => {
1448
+ },
1449
+ caller
1450
+ }) {
1451
+ const [uncontrolledProp, setUncontrolledProp, onChangeRef] = useUncontrolledState({
1452
+ defaultProp,
1453
+ onChange
1454
+ });
1455
+ const isControlled = prop !== void 0;
1456
+ const value = isControlled ? prop : uncontrolledProp;
1457
+ if (true) {
1458
+ const isControlledRef = React5.useRef(prop !== void 0);
1459
+ React5.useEffect(() => {
1460
+ const wasControlled = isControlledRef.current;
1461
+ if (wasControlled !== isControlled) {
1462
+ const from = wasControlled ? "controlled" : "uncontrolled";
1463
+ const to = isControlled ? "controlled" : "uncontrolled";
1464
+ console.warn(
1465
+ `${caller} is changing from ${from} to ${to}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`
1466
+ );
1467
+ }
1468
+ isControlledRef.current = isControlled;
1469
+ }, [isControlled, caller]);
1470
+ }
1471
+ const setValue = React5.useCallback(
1472
+ (nextValue) => {
1473
+ if (isControlled) {
1474
+ const value2 = isFunction(nextValue) ? nextValue(prop) : nextValue;
1475
+ if (value2 !== prop) {
1476
+ onChangeRef.current?.(value2);
1477
+ }
1478
+ } else {
1479
+ setUncontrolledProp(nextValue);
1480
+ }
1481
+ },
1482
+ [isControlled, prop, setUncontrolledProp, onChangeRef]
1483
+ );
1484
+ return [value, setValue];
1485
+ }
1486
+ function useUncontrolledState({
1487
+ defaultProp,
1488
+ onChange
1489
+ }) {
1490
+ const [value, setValue] = React5.useState(defaultProp);
1491
+ const prevValueRef = React5.useRef(value);
1492
+ const onChangeRef = React5.useRef(onChange);
1493
+ useInsertionEffect(() => {
1494
+ onChangeRef.current = onChange;
1495
+ }, [onChange]);
1496
+ React5.useEffect(() => {
1497
+ if (prevValueRef.current !== value) {
1498
+ onChangeRef.current?.(value);
1499
+ prevValueRef.current = value;
1500
+ }
1501
+ }, [value, prevValueRef]);
1502
+ return [value, setValue, onChangeRef];
1503
+ }
1504
+ function isFunction(value) {
1505
+ return typeof value === "function";
1506
+ }
1507
+ var SYNC_STATE = Symbol("RADIX:SYNC_STATE");
1508
+
1509
+ // ../../node_modules/@radix-ui/react-direction/dist/index.mjs
1510
+ var React6 = __toESM(require("react"), 1);
1511
+ var import_jsx_runtime18 = require("react/jsx-runtime");
1512
+ var DirectionContext = React6.createContext(void 0);
1513
+ function useDirection(localDir) {
1514
+ const globalDir = React6.useContext(DirectionContext);
1515
+ return localDir || globalDir || "ltr";
1516
+ }
1517
+
1518
+ // ../../node_modules/@radix-ui/react-use-previous/dist/index.mjs
1519
+ var React7 = __toESM(require("react"), 1);
1520
+ function usePrevious(value) {
1521
+ const ref = React7.useRef({ value, previous: value });
1522
+ return React7.useMemo(() => {
1523
+ if (ref.current.value !== value) {
1524
+ ref.current.previous = ref.current.value;
1525
+ ref.current.value = value;
1526
+ }
1527
+ return ref.current.previous;
1528
+ }, [value]);
1529
+ }
1530
+
1531
+ // ../../node_modules/@radix-ui/react-use-size/dist/index.mjs
1532
+ var React8 = __toESM(require("react"), 1);
1533
+ function useSize(element) {
1534
+ const [size, setSize] = React8.useState(void 0);
1535
+ useLayoutEffect2(() => {
1536
+ if (element) {
1537
+ setSize({ width: element.offsetWidth, height: element.offsetHeight });
1538
+ const resizeObserver = new ResizeObserver((entries) => {
1539
+ if (!Array.isArray(entries)) {
1540
+ return;
1541
+ }
1542
+ if (!entries.length) {
1543
+ return;
1544
+ }
1545
+ const entry = entries[0];
1546
+ let width;
1547
+ let height;
1548
+ if ("borderBoxSize" in entry) {
1549
+ const borderSizeEntry = entry["borderBoxSize"];
1550
+ const borderSize = Array.isArray(borderSizeEntry) ? borderSizeEntry[0] : borderSizeEntry;
1551
+ width = borderSize["inlineSize"];
1552
+ height = borderSize["blockSize"];
1553
+ } else {
1554
+ width = element.offsetWidth;
1555
+ height = element.offsetHeight;
1556
+ }
1557
+ setSize({ width, height });
1558
+ });
1559
+ resizeObserver.observe(element, { box: "border-box" });
1560
+ return () => resizeObserver.unobserve(element);
1561
+ } else {
1562
+ setSize(void 0);
1563
+ }
1564
+ }, [element]);
1565
+ return size;
1566
+ }
1567
+
1568
+ // ../../node_modules/@radix-ui/react-primitive/dist/index.mjs
1569
+ var React9 = __toESM(require("react"), 1);
1570
+ var ReactDOM = __toESM(require("react-dom"), 1);
1571
+ var import_react_slot2 = require("@radix-ui/react-slot");
1572
+ var import_jsx_runtime19 = require("react/jsx-runtime");
1573
+ var NODES = [
1574
+ "a",
1575
+ "button",
1576
+ "div",
1577
+ "form",
1578
+ "h2",
1579
+ "h3",
1580
+ "img",
1581
+ "input",
1582
+ "label",
1583
+ "li",
1584
+ "nav",
1585
+ "ol",
1586
+ "p",
1587
+ "select",
1588
+ "span",
1589
+ "svg",
1590
+ "ul"
1591
+ ];
1592
+ var Primitive = NODES.reduce((primitive, node) => {
1593
+ const Slot2 = (0, import_react_slot2.createSlot)(`Primitive.${node}`);
1594
+ const Node2 = React9.forwardRef((props, forwardedRef) => {
1595
+ const { asChild, ...primitiveProps } = props;
1596
+ const Comp = asChild ? Slot2 : node;
1597
+ if (typeof window !== "undefined") {
1598
+ window[Symbol.for("radix-ui")] = true;
1599
+ }
1600
+ return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(Comp, { ...primitiveProps, ref: forwardedRef });
1601
+ });
1602
+ Node2.displayName = `Primitive.${node}`;
1603
+ return { ...primitive, [node]: Node2 };
1604
+ }, {});
1605
+
1606
+ // ../../node_modules/@radix-ui/react-collection/dist/index.mjs
1607
+ var import_react8 = __toESM(require("react"), 1);
1608
+ var import_react_slot3 = require("@radix-ui/react-slot");
1609
+ var import_jsx_runtime20 = require("react/jsx-runtime");
1610
+ var import_react9 = __toESM(require("react"), 1);
1611
+ var import_react_slot4 = require("@radix-ui/react-slot");
1612
+ var import_jsx_runtime21 = require("react/jsx-runtime");
1613
+ function createCollection(name) {
1614
+ const PROVIDER_NAME = name + "CollectionProvider";
1615
+ const [createCollectionContext, createCollectionScope2] = createContextScope(PROVIDER_NAME);
1616
+ const [CollectionProviderImpl, useCollectionContext] = createCollectionContext(
1617
+ PROVIDER_NAME,
1618
+ { collectionRef: { current: null }, itemMap: /* @__PURE__ */ new Map() }
1619
+ );
1620
+ const CollectionProvider = (props) => {
1621
+ const { scope, children } = props;
1622
+ const ref = import_react8.default.useRef(null);
1623
+ const itemMap = import_react8.default.useRef(/* @__PURE__ */ new Map()).current;
1624
+ return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(CollectionProviderImpl, { scope, itemMap, collectionRef: ref, children });
1625
+ };
1626
+ CollectionProvider.displayName = PROVIDER_NAME;
1627
+ const COLLECTION_SLOT_NAME = name + "CollectionSlot";
1628
+ const CollectionSlotImpl = (0, import_react_slot3.createSlot)(COLLECTION_SLOT_NAME);
1629
+ const CollectionSlot = import_react8.default.forwardRef(
1630
+ (props, forwardedRef) => {
1631
+ const { scope, children } = props;
1632
+ const context = useCollectionContext(COLLECTION_SLOT_NAME, scope);
1633
+ const composedRefs = useComposedRefs(forwardedRef, context.collectionRef);
1634
+ return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(CollectionSlotImpl, { ref: composedRefs, children });
1635
+ }
1636
+ );
1637
+ CollectionSlot.displayName = COLLECTION_SLOT_NAME;
1638
+ const ITEM_SLOT_NAME = name + "CollectionItemSlot";
1639
+ const ITEM_DATA_ATTR = "data-radix-collection-item";
1640
+ const CollectionItemSlotImpl = (0, import_react_slot3.createSlot)(ITEM_SLOT_NAME);
1641
+ const CollectionItemSlot = import_react8.default.forwardRef(
1642
+ (props, forwardedRef) => {
1643
+ const { scope, children, ...itemData } = props;
1644
+ const ref = import_react8.default.useRef(null);
1645
+ const composedRefs = useComposedRefs(forwardedRef, ref);
1646
+ const context = useCollectionContext(ITEM_SLOT_NAME, scope);
1647
+ import_react8.default.useEffect(() => {
1648
+ context.itemMap.set(ref, { ref, ...itemData });
1649
+ return () => void context.itemMap.delete(ref);
1650
+ });
1651
+ return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(CollectionItemSlotImpl, { ...{ [ITEM_DATA_ATTR]: "" }, ref: composedRefs, children });
1652
+ }
1653
+ );
1654
+ CollectionItemSlot.displayName = ITEM_SLOT_NAME;
1655
+ function useCollection2(scope) {
1656
+ const context = useCollectionContext(name + "CollectionConsumer", scope);
1657
+ const getItems = import_react8.default.useCallback(() => {
1658
+ const collectionNode = context.collectionRef.current;
1659
+ if (!collectionNode) return [];
1660
+ const orderedNodes = Array.from(collectionNode.querySelectorAll(`[${ITEM_DATA_ATTR}]`));
1661
+ const items = Array.from(context.itemMap.values());
1662
+ const orderedItems = items.sort(
1663
+ (a, b) => orderedNodes.indexOf(a.ref.current) - orderedNodes.indexOf(b.ref.current)
1664
+ );
1665
+ return orderedItems;
1666
+ }, [context.collectionRef, context.itemMap]);
1667
+ return getItems;
1668
+ }
1669
+ return [
1670
+ { Provider: CollectionProvider, Slot: CollectionSlot, ItemSlot: CollectionItemSlot },
1671
+ useCollection2,
1672
+ createCollectionScope2
1673
+ ];
1674
+ }
1675
+
1676
+ // ../../node_modules/@radix-ui/react-slider/dist/index.mjs
1677
+ var import_jsx_runtime22 = require("react/jsx-runtime");
1678
+ var PAGE_KEYS = ["PageUp", "PageDown"];
1679
+ var ARROW_KEYS = ["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"];
1680
+ var BACK_KEYS = {
1681
+ "from-left": ["Home", "PageDown", "ArrowDown", "ArrowLeft"],
1682
+ "from-right": ["Home", "PageDown", "ArrowDown", "ArrowRight"],
1683
+ "from-bottom": ["Home", "PageDown", "ArrowDown", "ArrowLeft"],
1684
+ "from-top": ["Home", "PageDown", "ArrowUp", "ArrowLeft"]
1685
+ };
1686
+ var SLIDER_NAME = "Slider";
1687
+ var [Collection, useCollection, createCollectionScope] = createCollection(SLIDER_NAME);
1688
+ var [createSliderContext, createSliderScope] = createContextScope(SLIDER_NAME, [
1689
+ createCollectionScope
1690
+ ]);
1691
+ var [SliderProvider, useSliderContext] = createSliderContext(SLIDER_NAME);
1692
+ var Slider = React11.forwardRef(
1693
+ (props, forwardedRef) => {
1694
+ const {
1695
+ name,
1696
+ min = 0,
1697
+ max = 100,
1698
+ step = 1,
1699
+ orientation = "horizontal",
1700
+ disabled = false,
1701
+ minStepsBetweenThumbs = 0,
1702
+ defaultValue = [min],
1703
+ value,
1704
+ onValueChange = () => {
1705
+ },
1706
+ onValueCommit = () => {
1707
+ },
1708
+ inverted = false,
1709
+ form,
1710
+ ...sliderProps
1711
+ } = props;
1712
+ const thumbRefs = React11.useRef(/* @__PURE__ */ new Set());
1713
+ const valueIndexToChangeRef = React11.useRef(0);
1714
+ const isHorizontal = orientation === "horizontal";
1715
+ const SliderOrientation = isHorizontal ? SliderHorizontal : SliderVertical;
1716
+ const [values = [], setValues] = useControllableState({
1717
+ prop: value,
1718
+ defaultProp: defaultValue,
1719
+ onChange: (value2) => {
1720
+ const thumbs = [...thumbRefs.current];
1721
+ thumbs[valueIndexToChangeRef.current]?.focus();
1722
+ onValueChange(value2);
1723
+ }
1724
+ });
1725
+ const valuesBeforeSlideStartRef = React11.useRef(values);
1726
+ function handleSlideStart(value2) {
1727
+ const closestIndex = getClosestValueIndex(values, value2);
1728
+ updateValues(value2, closestIndex);
1729
+ }
1730
+ function handleSlideMove(value2) {
1731
+ updateValues(value2, valueIndexToChangeRef.current);
1732
+ }
1733
+ function handleSlideEnd() {
1734
+ const prevValue = valuesBeforeSlideStartRef.current[valueIndexToChangeRef.current];
1735
+ const nextValue = values[valueIndexToChangeRef.current];
1736
+ const hasChanged = nextValue !== prevValue;
1737
+ if (hasChanged) onValueCommit(values);
1738
+ }
1739
+ function updateValues(value2, atIndex, { commit } = { commit: false }) {
1740
+ const decimalCount = getDecimalCount(step);
1741
+ const snapToStep = roundValue(Math.round((value2 - min) / step) * step + min, decimalCount);
1742
+ const nextValue = clamp(snapToStep, [min, max]);
1743
+ setValues((prevValues = []) => {
1744
+ const nextValues = getNextSortedValues(prevValues, nextValue, atIndex);
1745
+ if (hasMinStepsBetweenValues(nextValues, minStepsBetweenThumbs * step)) {
1746
+ valueIndexToChangeRef.current = nextValues.indexOf(nextValue);
1747
+ const hasChanged = String(nextValues) !== String(prevValues);
1748
+ if (hasChanged && commit) onValueCommit(nextValues);
1749
+ return hasChanged ? nextValues : prevValues;
1750
+ } else {
1751
+ return prevValues;
1752
+ }
1753
+ });
1754
+ }
1755
+ return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
1756
+ SliderProvider,
1757
+ {
1758
+ scope: props.__scopeSlider,
1759
+ name,
1760
+ disabled,
1761
+ min,
1762
+ max,
1763
+ valueIndexToChangeRef,
1764
+ thumbs: thumbRefs.current,
1765
+ values,
1766
+ orientation,
1767
+ form,
1768
+ children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(Collection.Provider, { scope: props.__scopeSlider, children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(Collection.Slot, { scope: props.__scopeSlider, children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
1769
+ SliderOrientation,
1770
+ {
1771
+ "aria-disabled": disabled,
1772
+ "data-disabled": disabled ? "" : void 0,
1773
+ ...sliderProps,
1774
+ ref: forwardedRef,
1775
+ onPointerDown: composeEventHandlers(sliderProps.onPointerDown, () => {
1776
+ if (!disabled) valuesBeforeSlideStartRef.current = values;
1777
+ }),
1778
+ min,
1779
+ max,
1780
+ inverted,
1781
+ onSlideStart: disabled ? void 0 : handleSlideStart,
1782
+ onSlideMove: disabled ? void 0 : handleSlideMove,
1783
+ onSlideEnd: disabled ? void 0 : handleSlideEnd,
1784
+ onHomeKeyDown: () => !disabled && updateValues(min, 0, { commit: true }),
1785
+ onEndKeyDown: () => !disabled && updateValues(max, values.length - 1, { commit: true }),
1786
+ onStepKeyDown: ({ event, direction: stepDirection }) => {
1787
+ if (!disabled) {
1788
+ const isPageKey = PAGE_KEYS.includes(event.key);
1789
+ const isSkipKey = isPageKey || event.shiftKey && ARROW_KEYS.includes(event.key);
1790
+ const multiplier = isSkipKey ? 10 : 1;
1791
+ const atIndex = valueIndexToChangeRef.current;
1792
+ const value2 = values[atIndex];
1793
+ const stepInDirection = step * multiplier * stepDirection;
1794
+ updateValues(value2 + stepInDirection, atIndex, { commit: true });
1795
+ }
1796
+ }
1797
+ }
1798
+ ) }) })
1799
+ }
1800
+ );
1801
+ }
1802
+ );
1803
+ Slider.displayName = SLIDER_NAME;
1804
+ var [SliderOrientationProvider, useSliderOrientationContext] = createSliderContext(SLIDER_NAME, {
1805
+ startEdge: "left",
1806
+ endEdge: "right",
1807
+ size: "width",
1808
+ direction: 1
1809
+ });
1810
+ var SliderHorizontal = React11.forwardRef(
1811
+ (props, forwardedRef) => {
1812
+ const {
1813
+ min,
1814
+ max,
1815
+ dir,
1816
+ inverted,
1817
+ onSlideStart,
1818
+ onSlideMove,
1819
+ onSlideEnd,
1820
+ onStepKeyDown,
1821
+ ...sliderProps
1822
+ } = props;
1823
+ const [slider, setSlider] = React11.useState(null);
1824
+ const composedRefs = useComposedRefs(forwardedRef, (node) => setSlider(node));
1825
+ const rectRef = React11.useRef(void 0);
1826
+ const direction = useDirection(dir);
1827
+ const isDirectionLTR = direction === "ltr";
1828
+ const isSlidingFromLeft = isDirectionLTR && !inverted || !isDirectionLTR && inverted;
1829
+ function getValueFromPointer(pointerPosition) {
1830
+ const rect = rectRef.current || slider.getBoundingClientRect();
1831
+ const input = [0, rect.width];
1832
+ const output = isSlidingFromLeft ? [min, max] : [max, min];
1833
+ const value = linearScale(input, output);
1834
+ rectRef.current = rect;
1835
+ return value(pointerPosition - rect.left);
1836
+ }
1837
+ return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
1838
+ SliderOrientationProvider,
1839
+ {
1840
+ scope: props.__scopeSlider,
1841
+ startEdge: isSlidingFromLeft ? "left" : "right",
1842
+ endEdge: isSlidingFromLeft ? "right" : "left",
1843
+ direction: isSlidingFromLeft ? 1 : -1,
1844
+ size: "width",
1845
+ children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
1846
+ SliderImpl,
1847
+ {
1848
+ dir: direction,
1849
+ "data-orientation": "horizontal",
1850
+ ...sliderProps,
1851
+ ref: composedRefs,
1852
+ style: {
1853
+ ...sliderProps.style,
1854
+ ["--radix-slider-thumb-transform"]: "translateX(-50%)"
1855
+ },
1856
+ onSlideStart: (event) => {
1857
+ const value = getValueFromPointer(event.clientX);
1858
+ onSlideStart?.(value);
1859
+ },
1860
+ onSlideMove: (event) => {
1861
+ const value = getValueFromPointer(event.clientX);
1862
+ onSlideMove?.(value);
1863
+ },
1864
+ onSlideEnd: () => {
1865
+ rectRef.current = void 0;
1866
+ onSlideEnd?.();
1867
+ },
1868
+ onStepKeyDown: (event) => {
1869
+ const slideDirection = isSlidingFromLeft ? "from-left" : "from-right";
1870
+ const isBackKey = BACK_KEYS[slideDirection].includes(event.key);
1871
+ onStepKeyDown?.({ event, direction: isBackKey ? -1 : 1 });
1872
+ }
1873
+ }
1874
+ )
1875
+ }
1876
+ );
1877
+ }
1878
+ );
1879
+ var SliderVertical = React11.forwardRef(
1880
+ (props, forwardedRef) => {
1881
+ const {
1882
+ min,
1883
+ max,
1884
+ inverted,
1885
+ onSlideStart,
1886
+ onSlideMove,
1887
+ onSlideEnd,
1888
+ onStepKeyDown,
1889
+ ...sliderProps
1890
+ } = props;
1891
+ const sliderRef = React11.useRef(null);
1892
+ const ref = useComposedRefs(forwardedRef, sliderRef);
1893
+ const rectRef = React11.useRef(void 0);
1894
+ const isSlidingFromBottom = !inverted;
1895
+ function getValueFromPointer(pointerPosition) {
1896
+ const rect = rectRef.current || sliderRef.current.getBoundingClientRect();
1897
+ const input = [0, rect.height];
1898
+ const output = isSlidingFromBottom ? [max, min] : [min, max];
1899
+ const value = linearScale(input, output);
1900
+ rectRef.current = rect;
1901
+ return value(pointerPosition - rect.top);
1902
+ }
1903
+ return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
1904
+ SliderOrientationProvider,
1905
+ {
1906
+ scope: props.__scopeSlider,
1907
+ startEdge: isSlidingFromBottom ? "bottom" : "top",
1908
+ endEdge: isSlidingFromBottom ? "top" : "bottom",
1909
+ size: "height",
1910
+ direction: isSlidingFromBottom ? 1 : -1,
1911
+ children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
1912
+ SliderImpl,
1913
+ {
1914
+ "data-orientation": "vertical",
1915
+ ...sliderProps,
1916
+ ref,
1917
+ style: {
1918
+ ...sliderProps.style,
1919
+ ["--radix-slider-thumb-transform"]: "translateY(50%)"
1920
+ },
1921
+ onSlideStart: (event) => {
1922
+ const value = getValueFromPointer(event.clientY);
1923
+ onSlideStart?.(value);
1924
+ },
1925
+ onSlideMove: (event) => {
1926
+ const value = getValueFromPointer(event.clientY);
1927
+ onSlideMove?.(value);
1928
+ },
1929
+ onSlideEnd: () => {
1930
+ rectRef.current = void 0;
1931
+ onSlideEnd?.();
1932
+ },
1933
+ onStepKeyDown: (event) => {
1934
+ const slideDirection = isSlidingFromBottom ? "from-bottom" : "from-top";
1935
+ const isBackKey = BACK_KEYS[slideDirection].includes(event.key);
1936
+ onStepKeyDown?.({ event, direction: isBackKey ? -1 : 1 });
1937
+ }
1938
+ }
1939
+ )
1940
+ }
1941
+ );
1942
+ }
1943
+ );
1944
+ var SliderImpl = React11.forwardRef(
1945
+ (props, forwardedRef) => {
1946
+ const {
1947
+ __scopeSlider,
1948
+ onSlideStart,
1949
+ onSlideMove,
1950
+ onSlideEnd,
1951
+ onHomeKeyDown,
1952
+ onEndKeyDown,
1953
+ onStepKeyDown,
1954
+ ...sliderProps
1955
+ } = props;
1956
+ const context = useSliderContext(SLIDER_NAME, __scopeSlider);
1957
+ return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
1958
+ Primitive.span,
1959
+ {
1960
+ ...sliderProps,
1961
+ ref: forwardedRef,
1962
+ onKeyDown: composeEventHandlers(props.onKeyDown, (event) => {
1963
+ if (event.key === "Home") {
1964
+ onHomeKeyDown(event);
1965
+ event.preventDefault();
1966
+ } else if (event.key === "End") {
1967
+ onEndKeyDown(event);
1968
+ event.preventDefault();
1969
+ } else if (PAGE_KEYS.concat(ARROW_KEYS).includes(event.key)) {
1970
+ onStepKeyDown(event);
1971
+ event.preventDefault();
1972
+ }
1973
+ }),
1974
+ onPointerDown: composeEventHandlers(props.onPointerDown, (event) => {
1975
+ const target = event.target;
1976
+ target.setPointerCapture(event.pointerId);
1977
+ event.preventDefault();
1978
+ if (context.thumbs.has(target)) {
1979
+ target.focus();
1980
+ } else {
1981
+ onSlideStart(event);
1982
+ }
1983
+ }),
1984
+ onPointerMove: composeEventHandlers(props.onPointerMove, (event) => {
1985
+ const target = event.target;
1986
+ if (target.hasPointerCapture(event.pointerId)) onSlideMove(event);
1987
+ }),
1988
+ onPointerUp: composeEventHandlers(props.onPointerUp, (event) => {
1989
+ const target = event.target;
1990
+ if (target.hasPointerCapture(event.pointerId)) {
1991
+ target.releasePointerCapture(event.pointerId);
1992
+ onSlideEnd(event);
1993
+ }
1994
+ })
1995
+ }
1996
+ );
1997
+ }
1998
+ );
1999
+ var TRACK_NAME = "SliderTrack";
2000
+ var SliderTrack = React11.forwardRef(
2001
+ (props, forwardedRef) => {
2002
+ const { __scopeSlider, ...trackProps } = props;
2003
+ const context = useSliderContext(TRACK_NAME, __scopeSlider);
2004
+ return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
2005
+ Primitive.span,
2006
+ {
2007
+ "data-disabled": context.disabled ? "" : void 0,
2008
+ "data-orientation": context.orientation,
2009
+ ...trackProps,
2010
+ ref: forwardedRef
2011
+ }
2012
+ );
2013
+ }
2014
+ );
2015
+ SliderTrack.displayName = TRACK_NAME;
2016
+ var RANGE_NAME = "SliderRange";
2017
+ var SliderRange = React11.forwardRef(
2018
+ (props, forwardedRef) => {
2019
+ const { __scopeSlider, ...rangeProps } = props;
2020
+ const context = useSliderContext(RANGE_NAME, __scopeSlider);
2021
+ const orientation = useSliderOrientationContext(RANGE_NAME, __scopeSlider);
2022
+ const ref = React11.useRef(null);
2023
+ const composedRefs = useComposedRefs(forwardedRef, ref);
2024
+ const valuesCount = context.values.length;
2025
+ const percentages = context.values.map(
2026
+ (value) => convertValueToPercentage(value, context.min, context.max)
2027
+ );
2028
+ const offsetStart = valuesCount > 1 ? Math.min(...percentages) : 0;
2029
+ const offsetEnd = 100 - Math.max(...percentages);
2030
+ return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
2031
+ Primitive.span,
2032
+ {
2033
+ "data-orientation": context.orientation,
2034
+ "data-disabled": context.disabled ? "" : void 0,
2035
+ ...rangeProps,
2036
+ ref: composedRefs,
2037
+ style: {
2038
+ ...props.style,
2039
+ [orientation.startEdge]: offsetStart + "%",
2040
+ [orientation.endEdge]: offsetEnd + "%"
2041
+ }
2042
+ }
2043
+ );
2044
+ }
2045
+ );
2046
+ SliderRange.displayName = RANGE_NAME;
2047
+ var THUMB_NAME = "SliderThumb";
2048
+ var SliderThumb = React11.forwardRef(
2049
+ (props, forwardedRef) => {
2050
+ const getItems = useCollection(props.__scopeSlider);
2051
+ const [thumb, setThumb] = React11.useState(null);
2052
+ const composedRefs = useComposedRefs(forwardedRef, (node) => setThumb(node));
2053
+ const index = React11.useMemo(
2054
+ () => thumb ? getItems().findIndex((item) => item.ref.current === thumb) : -1,
2055
+ [getItems, thumb]
2056
+ );
2057
+ return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(SliderThumbImpl, { ...props, ref: composedRefs, index });
2058
+ }
2059
+ );
2060
+ var SliderThumbImpl = React11.forwardRef(
2061
+ (props, forwardedRef) => {
2062
+ const { __scopeSlider, index, name, ...thumbProps } = props;
2063
+ const context = useSliderContext(THUMB_NAME, __scopeSlider);
2064
+ const orientation = useSliderOrientationContext(THUMB_NAME, __scopeSlider);
2065
+ const [thumb, setThumb] = React11.useState(null);
2066
+ const composedRefs = useComposedRefs(forwardedRef, (node) => setThumb(node));
2067
+ const isFormControl = thumb ? context.form || !!thumb.closest("form") : true;
2068
+ const size = useSize(thumb);
2069
+ const value = context.values[index];
2070
+ const percent = value === void 0 ? 0 : convertValueToPercentage(value, context.min, context.max);
2071
+ const label = getLabel(index, context.values.length);
2072
+ const orientationSize = size?.[orientation.size];
2073
+ const thumbInBoundsOffset = orientationSize ? getThumbInBoundsOffset(orientationSize, percent, orientation.direction) : 0;
2074
+ React11.useEffect(() => {
2075
+ if (thumb) {
2076
+ context.thumbs.add(thumb);
2077
+ return () => {
2078
+ context.thumbs.delete(thumb);
2079
+ };
2080
+ }
2081
+ }, [thumb, context.thumbs]);
2082
+ return /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)(
2083
+ "span",
2084
+ {
2085
+ style: {
2086
+ transform: "var(--radix-slider-thumb-transform)",
2087
+ position: "absolute",
2088
+ [orientation.startEdge]: `calc(${percent}% + ${thumbInBoundsOffset}px)`
2089
+ },
2090
+ children: [
2091
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(Collection.ItemSlot, { scope: props.__scopeSlider, children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
2092
+ Primitive.span,
2093
+ {
2094
+ role: "slider",
2095
+ "aria-label": props["aria-label"] || label,
2096
+ "aria-valuemin": context.min,
2097
+ "aria-valuenow": value,
2098
+ "aria-valuemax": context.max,
2099
+ "aria-orientation": context.orientation,
2100
+ "data-orientation": context.orientation,
2101
+ "data-disabled": context.disabled ? "" : void 0,
2102
+ tabIndex: context.disabled ? void 0 : 0,
2103
+ ...thumbProps,
2104
+ ref: composedRefs,
2105
+ style: value === void 0 ? { display: "none" } : props.style,
2106
+ onFocus: composeEventHandlers(props.onFocus, () => {
2107
+ context.valueIndexToChangeRef.current = index;
2108
+ })
2109
+ }
2110
+ ) }),
2111
+ isFormControl && /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
2112
+ SliderBubbleInput,
2113
+ {
2114
+ name: name ?? (context.name ? context.name + (context.values.length > 1 ? "[]" : "") : void 0),
2115
+ form: context.form,
2116
+ value
2117
+ },
2118
+ index
2119
+ )
1010
2120
  ]
1011
2121
  }
1012
- )
2122
+ );
2123
+ }
2124
+ );
2125
+ SliderThumb.displayName = THUMB_NAME;
2126
+ var BUBBLE_INPUT_NAME = "RadioBubbleInput";
2127
+ var SliderBubbleInput = React11.forwardRef(
2128
+ ({ __scopeSlider, value, ...props }, forwardedRef) => {
2129
+ const ref = React11.useRef(null);
2130
+ const composedRefs = useComposedRefs(ref, forwardedRef);
2131
+ const prevValue = usePrevious(value);
2132
+ React11.useEffect(() => {
2133
+ const input = ref.current;
2134
+ if (!input) return;
2135
+ const inputProto = window.HTMLInputElement.prototype;
2136
+ const descriptor = Object.getOwnPropertyDescriptor(inputProto, "value");
2137
+ const setValue = descriptor.set;
2138
+ if (prevValue !== value && setValue) {
2139
+ const event = new Event("input", { bubbles: true });
2140
+ setValue.call(input, value);
2141
+ input.dispatchEvent(event);
2142
+ }
2143
+ }, [prevValue, value]);
2144
+ return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
2145
+ Primitive.input,
2146
+ {
2147
+ style: { display: "none" },
2148
+ ...props,
2149
+ ref: composedRefs,
2150
+ defaultValue: value
2151
+ }
2152
+ );
2153
+ }
2154
+ );
2155
+ SliderBubbleInput.displayName = BUBBLE_INPUT_NAME;
2156
+ function getNextSortedValues(prevValues = [], nextValue, atIndex) {
2157
+ const nextValues = [...prevValues];
2158
+ nextValues[atIndex] = nextValue;
2159
+ return nextValues.sort((a, b) => a - b);
2160
+ }
2161
+ function convertValueToPercentage(value, min, max) {
2162
+ const maxSteps = max - min;
2163
+ const percentPerStep = 100 / maxSteps;
2164
+ const percentage = percentPerStep * (value - min);
2165
+ return clamp(percentage, [0, 100]);
2166
+ }
2167
+ function getLabel(index, totalValues) {
2168
+ if (totalValues > 2) {
2169
+ return `Value ${index + 1} of ${totalValues}`;
2170
+ } else if (totalValues === 2) {
2171
+ return ["Minimum", "Maximum"][index];
2172
+ } else {
2173
+ return void 0;
2174
+ }
2175
+ }
2176
+ function getClosestValueIndex(values, nextValue) {
2177
+ if (values.length === 1) return 0;
2178
+ const distances = values.map((value) => Math.abs(value - nextValue));
2179
+ const closestDistance = Math.min(...distances);
2180
+ return distances.indexOf(closestDistance);
2181
+ }
2182
+ function getThumbInBoundsOffset(width, left, direction) {
2183
+ const halfWidth = width / 2;
2184
+ const halfPercent = 50;
2185
+ const offset = linearScale([0, halfPercent], [0, halfWidth]);
2186
+ return (halfWidth - offset(left) * direction) * direction;
2187
+ }
2188
+ function getStepsBetweenValues(values) {
2189
+ return values.slice(0, -1).map((value, index) => values[index + 1] - value);
2190
+ }
2191
+ function hasMinStepsBetweenValues(values, minStepsBetweenValues) {
2192
+ if (minStepsBetweenValues > 0) {
2193
+ const stepsBetweenValues = getStepsBetweenValues(values);
2194
+ const actualMinStepsBetweenValues = Math.min(...stepsBetweenValues);
2195
+ return actualMinStepsBetweenValues >= minStepsBetweenValues;
2196
+ }
2197
+ return true;
2198
+ }
2199
+ function linearScale(input, output) {
2200
+ return (value) => {
2201
+ if (input[0] === input[1] || output[0] === output[1]) return output[0];
2202
+ const ratio = (output[1] - output[0]) / (input[1] - input[0]);
2203
+ return output[0] + ratio * (value - input[0]);
2204
+ };
2205
+ }
2206
+ function getDecimalCount(value) {
2207
+ return (String(value).split(".")[1] || "").length;
2208
+ }
2209
+ function roundValue(value, decimalCount) {
2210
+ const rounder = Math.pow(10, decimalCount);
2211
+ return Math.round(value * rounder) / rounder;
2212
+ }
2213
+ var Root5 = Slider;
2214
+ var Track = SliderTrack;
2215
+ var Range = SliderRange;
2216
+ var Thumb2 = SliderThumb;
2217
+
2218
+ // ../ui/src/lib/utils.ts
2219
+ var import_clsx2 = require("clsx");
2220
+ var import_tailwind_merge2 = require("tailwind-merge");
2221
+ function cn2(...inputs) {
2222
+ return (0, import_tailwind_merge2.twMerge)((0, import_clsx2.clsx)(inputs));
2223
+ }
2224
+
2225
+ // src/ui/slider.tsx
2226
+ var import_jsx_runtime23 = require("react/jsx-runtime");
2227
+ function Slider2({
2228
+ className,
2229
+ defaultValue,
2230
+ value,
2231
+ min = 0,
2232
+ max = 100,
2233
+ ...props
2234
+ }) {
2235
+ const _values = React12.useMemo(
2236
+ () => Array.isArray(value) ? value : Array.isArray(defaultValue) ? defaultValue : [min, max],
2237
+ [value, defaultValue, min, max]
2238
+ );
2239
+ return /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(
2240
+ Root5,
2241
+ {
2242
+ "data-slot": "slider",
2243
+ defaultValue,
2244
+ value,
2245
+ min,
2246
+ max,
2247
+ className: cn2(
2248
+ "relative flex w-full touch-none items-center select-none data-[disabled]:opacity-50 data-[orientation=vertical]:h-full data-[orientation=vertical]:min-h-44 data-[orientation=vertical]:w-auto data-[orientation=vertical]:flex-col",
2249
+ className
2250
+ ),
2251
+ ...props,
2252
+ children: [
2253
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
2254
+ Track,
2255
+ {
2256
+ "data-slot": "slider-track",
2257
+ className: cn2(
2258
+ "bg-muted relative grow overflow-hidden rounded-full data-[orientation=horizontal]:h-1.5 data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-1.5"
2259
+ ),
2260
+ children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
2261
+ Range,
2262
+ {
2263
+ "data-slot": "slider-range",
2264
+ className: cn2("bg-primary absolute data-[orientation=horizontal]:h-full data-[orientation=vertical]:w-full")
2265
+ }
2266
+ )
2267
+ }
2268
+ ),
2269
+ Array.from({ length: _values.length }, (_, index) => /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
2270
+ Thumb2,
2271
+ {
2272
+ "data-slot": "slider-thumb",
2273
+ className: "border-primary bg-background ring-ring/50 block size-4 shrink-0 rounded-full border shadow-sm transition-[color,box-shadow] hover:ring-4 focus-visible:ring-4 focus-visible:outline-hidden disabled:pointer-events-none disabled:opacity-50"
2274
+ },
2275
+ index
2276
+ ))
2277
+ ]
2278
+ }
2279
+ );
2280
+ }
2281
+
2282
+ // src/components/CreditCardTab/Points/PointsSelector.tsx
2283
+ var import_jsx_runtime24 = require("react/jsx-runtime");
2284
+ var PointsSelector = (props) => {
2285
+ const { isSelected, onSelect, children } = props;
2286
+ const { balance } = useSlapiBalance();
2287
+ const { selectedPaymentMethod, setSelectedPaymentMethod } = useSpreePaymentMethod();
2288
+ const { appProps, staticConfig } = useStaticConfig();
2289
+ const min = 0;
2290
+ const max = Math.min((appProps.amount ?? 0) * staticConfig.pointsConversionRatio, balance?.availablePoints ?? 0);
2291
+ const step = 10;
2292
+ const [splitTokens, setSplitTokens] = (0, import_react10.useState)(0);
2293
+ const splitAmount = getSplitAmount(appProps.amount ?? 0, splitTokens, staticConfig.pointsConversionRatio);
2294
+ const handleCommit = (value) => {
2295
+ setSelectedPaymentMethod({ ...selectedPaymentMethod, splitAmount: value });
2296
+ };
2297
+ return /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(
2298
+ "button",
2299
+ {
2300
+ onClick: onSelect,
2301
+ className: cn("bg-primary/8 cursor-pointer overflow-hidden rounded-md border-1 border-transparent", {
2302
+ "border-primary": isSelected
2303
+ }),
2304
+ children: [
2305
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)("div", { className: cn("flex h-11 w-full", { "bg-black/4": isSelected }), children: [
2306
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
2307
+ "div",
2308
+ {
2309
+ className: cn("flex h-full w-11 items-center justify-center bg-black/10", {
2310
+ "bg-primary": isSelected
2311
+ }),
2312
+ children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { className: "flex h-5 w-5 items-center justify-center rounded-full bg-white", children: isSelected && /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { className: "bg-primary h-2.5 w-2.5 rounded-full" }) })
2313
+ }
2314
+ ),
2315
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { className: "flex h-full w-full items-center justify-between gap-3 px-3", children })
2316
+ ] }),
2317
+ isSelected && /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { className: "px-3 pt-6 pb-2 md:px-4", children: /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)("div", { className: "flex justify-between gap-3", children: [
2318
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)("div", { className: "flex max-w-[100px] flex-col gap-1", children: [
2319
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(Input, { readOnly: true, value: splitTokens, className: "bg-white text-center font-medium" }),
2320
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("p", { className: "text-left text-xs leading-[20px] text-black/45", children: "Points" })
2321
+ ] }),
2322
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { className: "flex w-full items-center pb-6", children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
2323
+ Slider2,
2324
+ {
2325
+ value: [splitTokens],
2326
+ onValueCommit: ([v]) => handleCommit(v),
2327
+ onValueChange: ([v]) => setSplitTokens(v),
2328
+ min,
2329
+ max,
2330
+ step
2331
+ }
2332
+ ) }),
2333
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)("div", { className: "flex max-w-[100px] flex-col gap-1", children: [
2334
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
2335
+ Input,
2336
+ {
2337
+ readOnly: true,
2338
+ value: formatUSD(splitAmount + getTransactionFee(splitAmount, appProps.transactionFeePercentage)),
2339
+ className: "bg-white text-center font-medium"
2340
+ }
2341
+ ),
2342
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("p", { className: "text-left text-xs leading-[20px] text-black/45", children: "Card" })
2343
+ ] })
2344
+ ] }) })
2345
+ ]
2346
+ }
1013
2347
  );
1014
2348
  };
1015
- var CreditCardTab = ({ pointsTitle, pointsConversionRatio }) => {
1016
- const [usePoints, setUsePoints] = (0, import_react7.useState)(false);
1017
- const [selectedPointsType, setSelectedPointsType] = (0, import_react7.useState)(null);
2349
+
2350
+ // src/components/CreditCardTab/Points/SplitBlock.tsx
2351
+ var import_jsx_runtime25 = require("react/jsx-runtime");
2352
+ var SplitBlock = (props) => {
2353
+ const { isSelected, onSelect } = props;
1018
2354
  const { balance, isBalanceLoading } = useSlapiBalance();
2355
+ const { spreePayConfig } = useSpreePayConfig();
2356
+ const [address, setAddress] = (0, import_react11.useState)(null);
2357
+ const { staticConfig } = useStaticConfig();
2358
+ const { pointsConversionRatio, pointsTitle } = staticConfig;
2359
+ const initWallet = (0, import_react11.useCallback)(async (pointsChain) => {
2360
+ if (!pointsChain) {
2361
+ return;
2362
+ }
2363
+ try {
2364
+ const res = await getAirWallet({
2365
+ mocaChain: pointsChain.mocaChain,
2366
+ partnerId: pointsChain.partnerId
2367
+ });
2368
+ setAddress(res.address ?? null);
2369
+ } catch (e) {
2370
+ console.error("Air Wallet init failed:", e);
2371
+ }
2372
+ }, []);
2373
+ (0, import_react11.useEffect)(() => {
2374
+ initWallet(spreePayConfig?.pointsChain);
2375
+ }, [spreePayConfig, initWallet]);
2376
+ return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { className: "flex flex-col gap-1", children: /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(PointsSelector, { onSelect: () => onSelect("air"), isSelected, children: [
2377
+ /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { className: "flex items-center gap-2", children: balance?.availablePoints ? /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("p", { className: "text-sm font-medium text-black", children: [
2378
+ /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { className: "text-black/50", children: "Available" }),
2379
+ " ",
2380
+ formatPoints(balance.availablePoints, pointsTitle),
2381
+ " ",
2382
+ /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { className: "text-black/50", children: formatUSD(balance.availablePoints / pointsConversionRatio) })
2383
+ ] }) : null }),
2384
+ isBalanceLoading ? /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { className: "h-4 w-6 animate-pulse bg-gray-200" }) : !balance?.availablePoints && /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("p", { className: "text-sm font-medium text-black", children: "No points available" }),
2385
+ address && /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { className: "text-sm font-medium text-black", children: address.length > 8 ? `${address.slice(0, 4)}...${address.slice(-4)}` : address })
2386
+ ] }) });
2387
+ };
2388
+
2389
+ // src/components/CreditCardTab/Points/Points.tsx
2390
+ var import_jsx_runtime26 = require("react/jsx-runtime");
2391
+ var Points = () => {
2392
+ const [usePoints, setUsePoints] = (0, import_react12.useState)(false);
2393
+ const [selectedPointsType, setSelectedPointsType] = (0, import_react12.useState)(null);
2394
+ const { setSelectedPaymentMethod, selectedPaymentMethod } = useSpreePaymentMethod();
2395
+ const { spreePayConfig } = useSpreePayConfig();
2396
+ const handleTogglePoints = (enabled) => {
2397
+ setUsePoints(enabled);
2398
+ if (!enabled) {
2399
+ setSelectedPointsType(null);
2400
+ setSelectedPaymentMethod({ ...selectedPaymentMethod, splitAmount: void 0 });
2401
+ }
2402
+ };
2403
+ return /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)(import_jsx_runtime26.Fragment, { children: [
2404
+ /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(PointsSwitch, { disabled: !spreePayConfig?.creditCard.enabled, value: usePoints, onChange: handleTogglePoints }),
2405
+ usePoints && /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(SplitBlock, { isSelected: selectedPointsType === "air", onSelect: setSelectedPointsType })
2406
+ ] });
2407
+ };
2408
+
2409
+ // src/components/CreditCardTab/CreditCardTab.tsx
2410
+ var import_jsx_runtime27 = require("react/jsx-runtime");
2411
+ var CreditCardTab = () => {
1019
2412
  const { selectedPaymentMethod, setSelectedPaymentMethod } = useSpreePaymentMethod();
1020
2413
  const { register } = useSpreePayRegister();
1021
2414
  const { mutateCards } = useCards();
1022
- const { env } = useSpreePayEnv();
1023
- const handlePay = (0, import_react7.useCallback)(
2415
+ const { cardPayment } = useCardPayment();
2416
+ const { splitPayment } = useSplitCardPayments();
2417
+ const handlePay = (0, import_react13.useCallback)(
1024
2418
  async (data) => {
1025
2419
  try {
1026
2420
  if (selectedPaymentMethod.type === "CREDIT_CARD" /* CREDIT_CARD */ && selectedPaymentMethod.method) {
1027
- const res = await cardPayment({
1028
- ...data,
1029
- card: selectedPaymentMethod.method,
1030
- redirect3dsURI: env.redirect3dsURI
1031
- });
2421
+ let res = null;
2422
+ if (selectedPaymentMethod.splitAmount && selectedPaymentMethod.splitAmount > 0) {
2423
+ res = await splitPayment({ ...data, points: selectedPaymentMethod.splitAmount });
2424
+ } else {
2425
+ res = await cardPayment(data);
2426
+ }
1032
2427
  if (["AUTHORIZED" /* AUTHORIZED */, "CAPTURED" /* CAPTURED */].includes(res.status)) {
1033
2428
  return Promise.resolve(res);
1034
2429
  }
@@ -1038,57 +2433,24 @@ var CreditCardTab = ({ pointsTitle, pointsConversionRatio }) => {
1038
2433
  } catch (_) {
1039
2434
  return Promise.reject(new PaymentError("Payment failed", "FAILED" /* FAILED */));
1040
2435
  } finally {
1041
- setSelectedPaymentMethod({ type: "CREDIT_CARD" /* CREDIT_CARD */, method: null });
2436
+ setSelectedPaymentMethod({ ...selectedPaymentMethod, type: "CREDIT_CARD" /* CREDIT_CARD */, method: null });
1042
2437
  mutateCards();
1043
2438
  }
1044
2439
  },
1045
- [setSelectedPaymentMethod, mutateCards, env.redirect3dsURI, selectedPaymentMethod]
2440
+ [mutateCards, selectedPaymentMethod, setSelectedPaymentMethod, cardPayment, splitPayment]
1046
2441
  );
1047
- (0, import_react7.useEffect)(() => {
2442
+ (0, import_react13.useEffect)(() => {
1048
2443
  register(handlePay);
1049
2444
  }, [register, handlePay]);
1050
- return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { children: [
1051
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("div", { className: "border-b-1 border-black/7 px-5 py-5 md:px-7 md:py-6", children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(CreditCard, {}) }),
1052
- /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { className: "flex flex-col gap-6 px-5 py-5 md:px-7 md:py-6", children: [
1053
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
1054
- PointsSwitch,
1055
- {
1056
- disabled: true,
1057
- value: usePoints,
1058
- onChange: setUsePoints,
1059
- pointsTitle,
1060
- pointsConversionRatio
1061
- }
1062
- ),
1063
- usePoints && /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { className: "flex flex-col gap-1", children: [
1064
- /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(PointsSelector, { onSelect: () => setSelectedPointsType("slapi"), isSelected: selectedPointsType === "slapi", children: [
1065
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("div", { className: "flex items-center gap-2", children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("p", { className: "text-sm font-medium text-black", children: "from [Brand] Balance" }) }),
1066
- isBalanceLoading ? /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("div", { className: "h-4 w-6 animate-pulse bg-gray-200" }) : !balance?.availablePoints && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("p", { className: "text-sm font-medium text-black", children: "No points available" }),
1067
- balance?.availablePoints ? /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("p", { className: "text-sm font-medium text-black", children: [
1068
- formatPoints(balance.availablePoints, pointsTitle),
1069
- " ",
1070
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("span", { className: "text-black/50", children: formatUSD(balance.availablePoints / pointsConversionRatio) })
1071
- ] }) : null
1072
- ] }),
1073
- /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(
1074
- PointsSelector,
1075
- {
1076
- onSelect: () => setSelectedPointsType("wallet"),
1077
- isSelected: selectedPointsType === "wallet",
1078
- children: [
1079
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("div", { className: "flex items-center gap-2", children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("p", { className: "text-sm font-medium text-black", children: "from Crypto Wallet" }) }),
1080
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("button", { className: "hover:bg-primary -mr-2 h-[34px] rounded-sm border-1 border-black px-3 text-sm font-medium hover:text-white", children: "Connect a Wallet" })
1081
- ]
1082
- }
1083
- )
1084
- ] })
1085
- ] })
2445
+ return /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)("div", { children: [
2446
+ /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("div", { className: "border-b-1 border-black/7 px-5 py-5 md:px-7 md:py-6", children: /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(CreditCard, {}) }),
2447
+ /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("div", { className: "flex flex-col gap-6 px-5 pt-5 pb-5 md:px-7 md:pt-6 md:pb-7", children: /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(Points, {}) })
1086
2448
  ] });
1087
2449
  };
1088
2450
 
1089
2451
  // src/components/CryptoTab/Crypto/CryptoWrapper.tsx
1090
2452
  var import_react_query = require("@tanstack/react-query");
1091
- var import_nice_modal_react5 = __toESM(require("@ebay/nice-modal-react"), 1);
2453
+ var import_nice_modal_react6 = __toESM(require("@ebay/nice-modal-react"), 1);
1092
2454
  var import_rainbowkit2 = require("@rainbow-me/rainbowkit");
1093
2455
  var import_styles = require("@rainbow-me/rainbowkit/styles.css");
1094
2456
  var import_wallets = require("@rainbow-me/rainbowkit/wallets");
@@ -1096,7 +2458,7 @@ var import_wagmi5 = require("wagmi");
1096
2458
  var import_chains = require("wagmi/chains");
1097
2459
 
1098
2460
  // src/components/CryptoTab/Crypto/Crypto.tsx
1099
- var import_react8 = require("react");
2461
+ var import_react14 = require("react");
1100
2462
  var import_wagmi4 = require("wagmi");
1101
2463
 
1102
2464
  // ../../node_modules/@wagmi/core/dist/esm/utils/getAction.js
@@ -1120,7 +2482,7 @@ function readContract(config2, parameters) {
1120
2482
  }
1121
2483
 
1122
2484
  // ../../node_modules/@wagmi/core/dist/esm/actions/waitForTransactionReceipt.js
1123
- var import_viem = require("viem");
2485
+ var import_viem2 = require("viem");
1124
2486
  var import_actions2 = require("viem/actions");
1125
2487
  async function waitForTransactionReceipt(config2, parameters) {
1126
2488
  const { chainId, timeout = 0, ...rest } = parameters;
@@ -1138,7 +2500,7 @@ async function waitForTransactionReceipt(config2, parameters) {
1138
2500
  maxFeePerGas: txn.type === "eip1559" ? txn.maxFeePerGas : void 0,
1139
2501
  maxPriorityFeePerGas: txn.type === "eip1559" ? txn.maxPriorityFeePerGas : void 0
1140
2502
  });
1141
- const reason = code?.data ? (0, import_viem.hexToString)(`0x${code.data.substring(138)}`) : "unknown reason";
2503
+ const reason = code?.data ? (0, import_viem2.hexToString)(`0x${code.data.substring(138)}`) : "unknown reason";
1142
2504
  throw new Error(reason);
1143
2505
  }
1144
2506
  return {
@@ -1148,10 +2510,10 @@ async function waitForTransactionReceipt(config2, parameters) {
1148
2510
  }
1149
2511
 
1150
2512
  // ../../node_modules/@wagmi/core/dist/esm/exports/index.js
1151
- var import_viem2 = require("viem");
2513
+ var import_viem3 = require("viem");
1152
2514
 
1153
2515
  // src/hooks/useCryptoPayment.ts
1154
- var import_viem3 = require("viem");
2516
+ var import_viem4 = require("viem");
1155
2517
  var import_wagmi = require("wagmi");
1156
2518
 
1157
2519
  // src/config/baseTokens.ts
@@ -1214,14 +2576,14 @@ var useCryptoPayment = () => {
1214
2576
  }
1215
2577
  const allowance = await readContract(config2, {
1216
2578
  address: tokenAddress,
1217
- abi: import_viem3.erc20Abi,
2579
+ abi: import_viem4.erc20Abi,
1218
2580
  functionName: "allowance",
1219
2581
  args: [walletClient.account.address, ONE_INCH_AGGREGATION_ROUTER_V6]
1220
2582
  });
1221
2583
  if (allowance <= 0n) {
1222
2584
  const result = await walletClient.writeContract({
1223
2585
  address: tokenAddress,
1224
- abi: import_viem3.erc20Abi,
2586
+ abi: import_viem4.erc20Abi,
1225
2587
  functionName: "approve",
1226
2588
  args: [ONE_INCH_AGGREGATION_ROUTER_V6, MAX_UINT256]
1227
2589
  });
@@ -1265,13 +2627,13 @@ var useCryptoPayment = () => {
1265
2627
 
1266
2628
  // src/components/CryptoTab/Crypto/ConnectButton.tsx
1267
2629
  var import_rainbowkit = require("@rainbow-me/rainbowkit");
1268
- var import_jsx_runtime16 = require("react/jsx-runtime");
2630
+ var import_jsx_runtime28 = require("react/jsx-runtime");
1269
2631
  var ConnectButton = () => {
1270
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_rainbowkit.ConnectButton.Custom, { children: ({ mounted, chain, account, openAccountModal, openChainModal, openConnectModal }) => {
2632
+ return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(import_rainbowkit.ConnectButton.Custom, { children: ({ mounted, chain, account, openAccountModal, openChainModal, openConnectModal }) => {
1271
2633
  if (!mounted) return null;
1272
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_jsx_runtime16.Fragment, { children: (() => {
2634
+ return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(import_jsx_runtime28.Fragment, { children: (() => {
1273
2635
  if (!mounted || !account || !chain) {
1274
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
2636
+ return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
1275
2637
  "button",
1276
2638
  {
1277
2639
  className: "h-[34px] rounded-md border-1 border-black px-3 text-sm font-medium text-black",
@@ -1281,7 +2643,7 @@ var ConnectButton = () => {
1281
2643
  );
1282
2644
  }
1283
2645
  if (chain.unsupported) {
1284
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
2646
+ return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
1285
2647
  "button",
1286
2648
  {
1287
2649
  className: "h-[34px] rounded-md border-1 border-black px-3 text-sm font-medium text-red-500",
@@ -1290,13 +2652,13 @@ var ConnectButton = () => {
1290
2652
  }
1291
2653
  );
1292
2654
  }
1293
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(
2655
+ return /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)(
1294
2656
  "button",
1295
2657
  {
1296
2658
  className: "flex h-[34px] items-center gap-2 rounded-md border-1 border-black px-1.5 text-sm font-medium text-black",
1297
2659
  onClick: openAccountModal,
1298
2660
  children: [
1299
- chain.hasIcon && /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("div", { className: "h-6 w-6 overflow-hidden rounded-full", style: { background: chain.iconBackground }, children: chain.iconUrl && /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("img", { alt: chain.name ?? "Chain icon", src: chain.iconUrl }) }),
2661
+ chain.hasIcon && /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("div", { className: "h-6 w-6 overflow-hidden rounded-full", style: { background: chain.iconBackground }, children: chain.iconUrl && /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("img", { alt: chain.name ?? "Chain icon", src: chain.iconUrl }) }),
1300
2662
  account.displayName
1301
2663
  ]
1302
2664
  }
@@ -1306,29 +2668,29 @@ var ConnectButton = () => {
1306
2668
  };
1307
2669
 
1308
2670
  // src/config/symbolLogos.tsx
1309
- var import_jsx_runtime17 = require("react/jsx-runtime");
1310
- var MOCA_SVG = /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("svg", { xmlns: "http://www.w3.org/2000/svg", width: "28", height: "28", fill: "none", children: [
1311
- /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("circle", { cx: "14", cy: "14", r: "13.5", fill: "#C15F97" }),
1312
- /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
2671
+ var import_jsx_runtime29 = require("react/jsx-runtime");
2672
+ var MOCA_SVG = /* @__PURE__ */ (0, import_jsx_runtime29.jsxs)("svg", { xmlns: "http://www.w3.org/2000/svg", width: "28", height: "28", fill: "none", children: [
2673
+ /* @__PURE__ */ (0, import_jsx_runtime29.jsx)("circle", { cx: "14", cy: "14", r: "13.5", fill: "#C15F97" }),
2674
+ /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(
1313
2675
  "path",
1314
2676
  {
1315
2677
  fill: "#fff",
1316
2678
  d: "M16.06 6.65c.3 0 .59.16.74.43l6.06 10.5a.85.85 0 1 1-1.47.84L16.06 9.2l-1.51 2.62-.02.03-3.8 6.57a.85.85 0 0 1-1.47-.84l3.57-6.18-1.27-2.2-5.32 9.22a.85.85 0 0 1-1.48-.84l6.07-10.5.06-.1a.85.85 0 0 1 1.4.1l1.52 2.62 1.52-2.62.06-.1c.16-.2.4-.33.67-.33Z"
1317
2679
  }
1318
2680
  ),
1319
- /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("circle", { cx: "16", cy: "14", r: "1.5", fill: "#fff" })
2681
+ /* @__PURE__ */ (0, import_jsx_runtime29.jsx)("circle", { cx: "16", cy: "14", r: "1.5", fill: "#fff" })
1320
2682
  ] });
1321
- var USDC_SVG = /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("svg", { xmlns: "http://www.w3.org/2000/svg", width: "28", height: "28", fill: "none", children: [
1322
- /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("g", { clipPath: "url(#clip0_528_9163)", children: [
1323
- /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("path", { fill: "#2775CA", d: "M14 28c7.76 0 14-6.24 14-14S21.76 0 14 0 0 6.24 0 14s6.24 14 14 14Z" }),
1324
- /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
2683
+ var USDC_SVG = /* @__PURE__ */ (0, import_jsx_runtime29.jsxs)("svg", { xmlns: "http://www.w3.org/2000/svg", width: "28", height: "28", fill: "none", children: [
2684
+ /* @__PURE__ */ (0, import_jsx_runtime29.jsxs)("g", { clipPath: "url(#clip0_528_9163)", children: [
2685
+ /* @__PURE__ */ (0, import_jsx_runtime29.jsx)("path", { fill: "#2775CA", d: "M14 28c7.76 0 14-6.24 14-14S21.76 0 14 0 0 6.24 0 14s6.24 14 14 14Z" }),
2686
+ /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(
1325
2687
  "path",
1326
2688
  {
1327
2689
  fill: "#fff",
1328
2690
  d: "M17.85 16.22c0-2.04-1.23-2.74-3.68-3.04-1.75-.23-2.1-.7-2.1-1.51 0-.82.59-1.34 1.75-1.34 1.05 0 1.64.35 1.93 1.22.06.18.23.3.4.3h.94a.4.4 0 0 0 .41-.42v-.05a2.91 2.91 0 0 0-2.63-2.4v-1.4c0-.23-.17-.4-.46-.46h-.88c-.23 0-.4.17-.46.46v1.35c-1.75.23-2.86 1.4-2.86 2.85 0 1.93 1.16 2.69 3.61 2.98 1.64.29 2.16.64 2.16 1.57 0 .94-.81 1.58-1.92 1.58-1.52 0-2.04-.64-2.22-1.52-.06-.23-.23-.35-.4-.35h-1a.4.4 0 0 0-.4.41v.06c.23 1.46 1.16 2.5 3.08 2.8v1.4c0 .23.18.4.47.47h.88c.23 0 .4-.18.46-.47v-1.4c1.75-.3 2.92-1.52 2.92-3.1Z"
1329
2691
  }
1330
2692
  ),
1331
- /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
2693
+ /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(
1332
2694
  "path",
1333
2695
  {
1334
2696
  fill: "#fff",
@@ -1336,11 +2698,11 @@ var USDC_SVG = /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("svg", { xmlns: "h
1336
2698
  }
1337
2699
  )
1338
2700
  ] }),
1339
- /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("defs", { children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("clipPath", { id: "clip0_528_9163", children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("path", { fill: "#fff", d: "M0 0h28v28H0z" }) }) })
2701
+ /* @__PURE__ */ (0, import_jsx_runtime29.jsx)("defs", { children: /* @__PURE__ */ (0, import_jsx_runtime29.jsx)("clipPath", { id: "clip0_528_9163", children: /* @__PURE__ */ (0, import_jsx_runtime29.jsx)("path", { fill: "#fff", d: "M0 0h28v28H0z" }) }) })
1340
2702
  ] });
1341
- var USDT_SVG = /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("svg", { xmlns: "http://www.w3.org/2000/svg", width: "28", height: "28", fill: "none", children: [
1342
- /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("path", { fill: "#26A17B", d: "M14 28a14 14 0 1 0 0-28 14 14 0 0 0 0 28Z" }),
1343
- /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
2703
+ var USDT_SVG = /* @__PURE__ */ (0, import_jsx_runtime29.jsxs)("svg", { xmlns: "http://www.w3.org/2000/svg", width: "28", height: "28", fill: "none", children: [
2704
+ /* @__PURE__ */ (0, import_jsx_runtime29.jsx)("path", { fill: "#26A17B", d: "M14 28a14 14 0 1 0 0-28 14 14 0 0 0 0 28Z" }),
2705
+ /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(
1344
2706
  "path",
1345
2707
  {
1346
2708
  fill: "#fff",
@@ -1348,23 +2710,23 @@ var USDT_SVG = /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("svg", { xmlns: "h
1348
2710
  }
1349
2711
  )
1350
2712
  ] });
1351
- var WETH_SVG = /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("svg", { xmlns: "http://www.w3.org/2000/svg", fill: "none", width: "28", height: "28", viewBox: "0 0 24 24", children: [
1352
- /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("g", { clipPath: "url(#clip0_528_9173)", children: [
1353
- /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
2713
+ var WETH_SVG = /* @__PURE__ */ (0, import_jsx_runtime29.jsxs)("svg", { xmlns: "http://www.w3.org/2000/svg", fill: "none", width: "28", height: "28", viewBox: "0 0 24 24", children: [
2714
+ /* @__PURE__ */ (0, import_jsx_runtime29.jsxs)("g", { clipPath: "url(#clip0_528_9173)", children: [
2715
+ /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(
1354
2716
  "path",
1355
2717
  {
1356
2718
  fill: "#000",
1357
2719
  d: "M17.14 20.57c0 .95-1.31 2.01-3.39 2.4h-2.59c-4.65 0-8.42-1.07-8.42-2.4 0-1.32 3.77-2.4 8.42-2.4s5.98 1.08 5.98 2.4Z"
1358
2720
  }
1359
2721
  ),
1360
- /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
2722
+ /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(
1361
2723
  "path",
1362
2724
  {
1363
2725
  fill: "#F61F7D",
1364
2726
  d: "M23.31 11c0 5.86-5.18 11.63-11.07 11.63-5.9 0-11.9-6.17-11.9-12.03C.34 4.75 5.12 0 11.01 0s12.3 5.15 12.3 11Z"
1365
2727
  }
1366
2728
  ),
1367
- /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
2729
+ /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(
1368
2730
  "path",
1369
2731
  {
1370
2732
  fill: "#000",
@@ -1373,8 +2735,8 @@ var WETH_SVG = /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("svg", { xmlns: "h
1373
2735
  clipRule: "evenodd"
1374
2736
  }
1375
2737
  ),
1376
- /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("path", { fill: "#fff", d: "M24 12.17a10.8 10.8 0 1 1-21.6 0 10.8 10.8 0 0 1 21.6 0Z" }),
1377
- /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
2738
+ /* @__PURE__ */ (0, import_jsx_runtime29.jsx)("path", { fill: "#fff", d: "M24 12.17a10.8 10.8 0 1 1-21.6 0 10.8 10.8 0 0 1 21.6 0Z" }),
2739
+ /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(
1378
2740
  "path",
1379
2741
  {
1380
2742
  fill: "#000",
@@ -1383,8 +2745,8 @@ var WETH_SVG = /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("svg", { xmlns: "h
1383
2745
  clipRule: "evenodd"
1384
2746
  }
1385
2747
  ),
1386
- /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("path", { fill: "#000", fillRule: "evenodd", d: "M3.02 10.63.7 8.75l.74-.86 2.34 1.87-.75.87Z", clipRule: "evenodd" }),
1387
- /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
2748
+ /* @__PURE__ */ (0, import_jsx_runtime29.jsx)("path", { fill: "#000", fillRule: "evenodd", d: "M3.02 10.63.7 8.75l.74-.86 2.34 1.87-.75.87Z", clipRule: "evenodd" }),
2749
+ /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(
1388
2750
  "path",
1389
2751
  {
1390
2752
  fill: "#000",
@@ -1392,7 +2754,7 @@ var WETH_SVG = /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("svg", { xmlns: "h
1392
2754
  }
1393
2755
  )
1394
2756
  ] }),
1395
- /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("defs", { children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("clipPath", { id: "clip0_528_9173", children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("path", { fill: "#fff", d: "M0 0h24v24H0z" }) }) })
2757
+ /* @__PURE__ */ (0, import_jsx_runtime29.jsx)("defs", { children: /* @__PURE__ */ (0, import_jsx_runtime29.jsx)("clipPath", { id: "clip0_528_9173", children: /* @__PURE__ */ (0, import_jsx_runtime29.jsx)("path", { fill: "#fff", d: "M0 0h24v24H0z" }) }) })
1396
2758
  ] });
1397
2759
  var symbolLogos = {
1398
2760
  MOCA: MOCA_SVG,
@@ -1405,34 +2767,34 @@ function getSymbolLogo(symbol) {
1405
2767
  }
1406
2768
 
1407
2769
  // src/components/CryptoTab/Crypto/Logos.tsx
1408
- var import_jsx_runtime18 = require("react/jsx-runtime");
2770
+ var import_jsx_runtime30 = require("react/jsx-runtime");
1409
2771
  var Logos = () => {
1410
- return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("div", { className: "flex", children: [
1411
- /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: "rounded-full border border-[#F5F7FA]", children: getSymbolLogo("MOCA") }),
1412
- /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: "-ml-2.5 rounded-full border border-[#F5F7FA]", children: getSymbolLogo("USDC") }),
1413
- /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: "-ml-2.5 rounded-full border border-[#F5F7FA]", children: getSymbolLogo("USDT") }),
1414
- /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: "-ml-2.5 rounded-full border border-[#F5F7FA] bg-[#F5F7FA]", children: getSymbolLogo("WETH") })
2772
+ return /* @__PURE__ */ (0, import_jsx_runtime30.jsxs)("div", { className: "flex", children: [
2773
+ /* @__PURE__ */ (0, import_jsx_runtime30.jsx)("div", { className: "rounded-full border border-[#F5F7FA]", children: getSymbolLogo("MOCA") }),
2774
+ /* @__PURE__ */ (0, import_jsx_runtime30.jsx)("div", { className: "-ml-2.5 rounded-full border border-[#F5F7FA]", children: getSymbolLogo("USDC") }),
2775
+ /* @__PURE__ */ (0, import_jsx_runtime30.jsx)("div", { className: "-ml-2.5 rounded-full border border-[#F5F7FA]", children: getSymbolLogo("USDT") }),
2776
+ /* @__PURE__ */ (0, import_jsx_runtime30.jsx)("div", { className: "-ml-2.5 rounded-full border border-[#F5F7FA] bg-[#F5F7FA]", children: getSymbolLogo("WETH") })
1415
2777
  ] });
1416
2778
  };
1417
2779
 
1418
2780
  // src/components/CryptoTab/Crypto/SelectCoinButton.tsx
1419
- var import_nice_modal_react4 = __toESM(require("@ebay/nice-modal-react"), 1);
2781
+ var import_nice_modal_react5 = __toESM(require("@ebay/nice-modal-react"), 1);
1420
2782
 
1421
2783
  // src/modals/CryptoSelectModal.tsx
1422
- var import_nice_modal_react3 = __toESM(require("@ebay/nice-modal-react"), 1);
2784
+ var import_nice_modal_react4 = __toESM(require("@ebay/nice-modal-react"), 1);
1423
2785
 
1424
2786
  // src/hooks/useBaseERC20Token.ts
1425
- var React2 = __toESM(require("react"), 1);
1426
- var import_viem4 = require("viem");
2787
+ var React13 = __toESM(require("react"), 1);
2788
+ var import_viem5 = require("viem");
1427
2789
  var import_wagmi2 = require("wagmi");
1428
2790
  function useBaseERC20Token() {
1429
2791
  const { address } = (0, import_wagmi2.useAccount)();
1430
2792
  const baseClient = (0, import_wagmi2.usePublicClient)({ chainId: BASE_CHAIN_ID });
1431
2793
  const defaultClient = (0, import_wagmi2.usePublicClient)();
1432
- const [rows, setRows] = React2.useState([]);
1433
- const [isLoading, setLoading] = React2.useState(false);
1434
- const [error, setError] = React2.useState(null);
1435
- React2.useEffect(() => {
2794
+ const [rows, setRows] = React13.useState([]);
2795
+ const [isLoading, setLoading] = React13.useState(false);
2796
+ const [error, setError] = React13.useState(null);
2797
+ React13.useEffect(() => {
1436
2798
  let cancelled = false;
1437
2799
  async function run() {
1438
2800
  const client = baseClient ?? defaultClient;
@@ -1445,7 +2807,7 @@ function useBaseERC20Token() {
1445
2807
  const normalizedTokens = [];
1446
2808
  for (const t of BASE_TOKENS) {
1447
2809
  try {
1448
- const addr = (0, import_viem4.getAddress)(t.address);
2810
+ const addr = (0, import_viem5.getAddress)(t.address);
1449
2811
  normalizedTokens.push({ ...t, address: addr });
1450
2812
  } catch {
1451
2813
  }
@@ -1454,7 +2816,7 @@ function useBaseERC20Token() {
1454
2816
  allowFailure: true,
1455
2817
  contracts: normalizedTokens.map((t) => ({
1456
2818
  address: t.address,
1457
- abi: import_viem4.erc20Abi,
2819
+ abi: import_viem5.erc20Abi,
1458
2820
  functionName: "balanceOf",
1459
2821
  args: [address]
1460
2822
  }))
@@ -1465,7 +2827,7 @@ function useBaseERC20Token() {
1465
2827
  const t = normalizedTokens[idx];
1466
2828
  if (r.status === "success") {
1467
2829
  const raw = r.result;
1468
- if (raw > 0n) acc.push({ ...t, raw, formatted: (0, import_viem4.formatUnits)(raw, t.decimals) });
2830
+ if (raw > 0n) acc.push({ ...t, raw, formatted: (0, import_viem5.formatUnits)(raw, t.decimals) });
1469
2831
  }
1470
2832
  }
1471
2833
  if (!cancelled) setRows(acc);
@@ -1506,9 +2868,9 @@ function useBaseNativeToken() {
1506
2868
  }
1507
2869
 
1508
2870
  // src/modals/CryptoSelectModal.tsx
1509
- var import_jsx_runtime19 = require("react/jsx-runtime");
1510
- var CryptoSelectModal = import_nice_modal_react3.default.create(() => {
1511
- const modal = (0, import_nice_modal_react3.useModal)();
2871
+ var import_jsx_runtime31 = require("react/jsx-runtime");
2872
+ var CryptoSelectModal = import_nice_modal_react4.default.create(() => {
2873
+ const modal = (0, import_nice_modal_react4.useModal)();
1512
2874
  const { isLoading, error, erc20Balances } = useBaseERC20Token();
1513
2875
  const { isLoadingNative, nativeError, nativeBalance } = useBaseNativeToken();
1514
2876
  const { setSelectedPaymentMethod } = useSpreePaymentMethod();
@@ -1516,13 +2878,13 @@ var CryptoSelectModal = import_nice_modal_react3.default.create(() => {
1516
2878
  modal.remove();
1517
2879
  setSelectedPaymentMethod({ type: "CRYPTO" /* CRYPTO */, method: coin });
1518
2880
  };
1519
- return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(Dialog, { open: modal.visible, onOpenChange: modal.remove, children: [
1520
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(DialogDescription, { className: "hidden", children: "Crypto Select Modal" }),
1521
- /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(DialogContent, { showCloseButton: false, className: "gap-0 p-0", children: [
1522
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", { className: "flex flex-col gap-6 px-5 py-5 md:px-7 md:py-6", children: /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "flex items-center justify-between gap-4", children: [
1523
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("button", { className: "rounded-md hover:bg-gray-100", onClick: modal.remove, children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("svg", { xmlns: "http://www.w3.org/2000/svg", width: "24", height: "25", fill: "none", children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("path", { stroke: "#000", d: "m15 6.5-6 6 6 6" }) }) }),
1524
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(DialogTitle, { className: "text-primary text-2xl font-semibold", children: "Select a token" }),
1525
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("button", { className: "rounded-md p-1 hover:bg-gray-100", onClick: modal.remove, children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("svg", { xmlns: "http://www.w3.org/2000/svg", width: "16", height: "17", fill: "none", children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
2881
+ return /* @__PURE__ */ (0, import_jsx_runtime31.jsxs)(Dialog, { open: modal.visible, onOpenChange: modal.remove, children: [
2882
+ /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(DialogDescription, { className: "hidden", children: "Crypto Select Modal" }),
2883
+ /* @__PURE__ */ (0, import_jsx_runtime31.jsxs)(DialogContent, { showCloseButton: false, className: "gap-0 p-0", children: [
2884
+ /* @__PURE__ */ (0, import_jsx_runtime31.jsx)("div", { className: "flex flex-col gap-6 px-5 py-5 md:px-7 md:py-6", children: /* @__PURE__ */ (0, import_jsx_runtime31.jsxs)("div", { className: "flex items-center justify-between gap-4", children: [
2885
+ /* @__PURE__ */ (0, import_jsx_runtime31.jsx)("button", { className: "rounded-md hover:bg-gray-100", onClick: modal.remove, children: /* @__PURE__ */ (0, import_jsx_runtime31.jsx)("svg", { xmlns: "http://www.w3.org/2000/svg", width: "24", height: "25", fill: "none", children: /* @__PURE__ */ (0, import_jsx_runtime31.jsx)("path", { stroke: "#000", d: "m15 6.5-6 6 6 6" }) }) }),
2886
+ /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(DialogTitle, { className: "text-primary text-2xl font-semibold", children: "Select a token" }),
2887
+ /* @__PURE__ */ (0, import_jsx_runtime31.jsx)("button", { className: "rounded-md p-1 hover:bg-gray-100", onClick: modal.remove, children: /* @__PURE__ */ (0, import_jsx_runtime31.jsx)("svg", { xmlns: "http://www.w3.org/2000/svg", width: "16", height: "17", fill: "none", children: /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(
1526
2888
  "path",
1527
2889
  {
1528
2890
  fill: "#000",
@@ -1530,19 +2892,19 @@ var CryptoSelectModal = import_nice_modal_react3.default.create(() => {
1530
2892
  }
1531
2893
  ) }) })
1532
2894
  ] }) }),
1533
- /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "flex flex-col gap-4 px-5 py-5 md:px-7 md:py-6", children: [
1534
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("h3", { className: "text-primary text-xl font-semibold", children: "Tokens with wallet balance" }),
1535
- (error || nativeError) && /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("p", { className: "text-center text-sm text-red-500", children: "Something wrong" }),
1536
- /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "flex w-full flex-col gap-1", children: [
1537
- isLoadingNative && /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", { className: "h-11 animate-pulse rounded-md bg-gray-100" }),
1538
- nativeBalance && /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(
2895
+ /* @__PURE__ */ (0, import_jsx_runtime31.jsxs)("div", { className: "flex flex-col gap-4 px-5 py-5 md:px-7 md:py-6", children: [
2896
+ /* @__PURE__ */ (0, import_jsx_runtime31.jsx)("h3", { className: "text-primary text-xl font-semibold", children: "Tokens with wallet balance" }),
2897
+ (error || nativeError) && /* @__PURE__ */ (0, import_jsx_runtime31.jsx)("p", { className: "text-center text-sm text-red-500", children: "Something wrong" }),
2898
+ /* @__PURE__ */ (0, import_jsx_runtime31.jsxs)("div", { className: "flex w-full flex-col gap-1", children: [
2899
+ isLoadingNative && /* @__PURE__ */ (0, import_jsx_runtime31.jsx)("div", { className: "h-11 animate-pulse rounded-md bg-gray-100" }),
2900
+ nativeBalance && /* @__PURE__ */ (0, import_jsx_runtime31.jsxs)(
1539
2901
  "button",
1540
2902
  {
1541
2903
  className: "flex h-11 w-full items-center justify-between gap-4 rounded-sm px-1.5 text-black hover:bg-gray-100",
1542
2904
  onClick: () => handleSelect(nativeBalance),
1543
2905
  children: [
1544
- /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "flex items-center gap-2", children: [
1545
- nativeBalance.logoURI && /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
2906
+ /* @__PURE__ */ (0, import_jsx_runtime31.jsxs)("div", { className: "flex items-center gap-2", children: [
2907
+ nativeBalance.logoURI && /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(
1546
2908
  "img",
1547
2909
  {
1548
2910
  className: "h-8 w-8 shrink-0",
@@ -1550,31 +2912,31 @@ var CryptoSelectModal = import_nice_modal_react3.default.create(() => {
1550
2912
  alt: `${nativeBalance.symbol} logo`
1551
2913
  }
1552
2914
  ),
1553
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("p", { className: "text-sm font-medium", children: nativeBalance.symbol })
2915
+ /* @__PURE__ */ (0, import_jsx_runtime31.jsx)("p", { className: "text-sm font-medium", children: nativeBalance.symbol })
1554
2916
  ] }),
1555
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("p", { className: "text-sm font-medium", children: nativeBalance.formatted })
2917
+ /* @__PURE__ */ (0, import_jsx_runtime31.jsx)("p", { className: "text-sm font-medium", children: nativeBalance.formatted })
1556
2918
  ]
1557
2919
  },
1558
2920
  nativeBalance.symbol
1559
2921
  ),
1560
- isLoading && /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(import_jsx_runtime19.Fragment, { children: [
1561
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", { className: "h-11 animate-pulse rounded-md bg-gray-100" }),
1562
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", { className: "h-11 animate-pulse rounded-md bg-gray-100" }),
1563
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", { className: "h-11 animate-pulse rounded-md bg-gray-100" })
2922
+ isLoading && /* @__PURE__ */ (0, import_jsx_runtime31.jsxs)(import_jsx_runtime31.Fragment, { children: [
2923
+ /* @__PURE__ */ (0, import_jsx_runtime31.jsx)("div", { className: "h-11 animate-pulse rounded-md bg-gray-100" }),
2924
+ /* @__PURE__ */ (0, import_jsx_runtime31.jsx)("div", { className: "h-11 animate-pulse rounded-md bg-gray-100" }),
2925
+ /* @__PURE__ */ (0, import_jsx_runtime31.jsx)("div", { className: "h-11 animate-pulse rounded-md bg-gray-100" })
1564
2926
  ] }),
1565
2927
  erc20Balances.map((coin) => {
1566
2928
  const Icon = getSymbolLogo(coin.symbol);
1567
- return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(
2929
+ return /* @__PURE__ */ (0, import_jsx_runtime31.jsxs)(
1568
2930
  "button",
1569
2931
  {
1570
2932
  className: "flex h-11 w-full items-center justify-between gap-4 rounded-sm px-1.5 text-black hover:bg-gray-100 disabled:cursor-not-allowed disabled:opacity-50",
1571
2933
  onClick: () => handleSelect(coin),
1572
2934
  children: [
1573
- /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "flex items-center gap-2", children: [
2935
+ /* @__PURE__ */ (0, import_jsx_runtime31.jsxs)("div", { className: "flex items-center gap-2", children: [
1574
2936
  Boolean(Icon) && Icon,
1575
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("p", { className: "text-sm font-medium", children: coin.symbol })
2937
+ /* @__PURE__ */ (0, import_jsx_runtime31.jsx)("p", { className: "text-sm font-medium", children: coin.symbol })
1576
2938
  ] }),
1577
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("p", { className: "text-sm font-medium", children: coin.formatted })
2939
+ /* @__PURE__ */ (0, import_jsx_runtime31.jsx)("p", { className: "text-sm font-medium", children: coin.formatted })
1578
2940
  ]
1579
2941
  },
1580
2942
  coin.symbol
@@ -1588,51 +2950,51 @@ var CryptoSelectModal = import_nice_modal_react3.default.create(() => {
1588
2950
  CryptoSelectModal.displayName = "CryptoSelectModal";
1589
2951
 
1590
2952
  // src/components/CryptoTab/Crypto/SelectCoinButton.tsx
1591
- var import_jsx_runtime20 = require("react/jsx-runtime");
2953
+ var import_jsx_runtime32 = require("react/jsx-runtime");
1592
2954
  var SelectCoinButton = () => {
1593
2955
  const openModal = () => {
1594
- import_nice_modal_react4.default.show(CryptoSelectModal);
2956
+ import_nice_modal_react5.default.show(CryptoSelectModal);
1595
2957
  };
1596
- return /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("button", { onClick: openModal, type: "button", className: "bg-primary/8 flex h-11 w-full overflow-hidden rounded-md", children: [
1597
- /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", { className: "bg-primary flex h-full w-11 items-center justify-center", children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", { className: "flex h-5 w-5 items-center justify-center rounded-full bg-white" }) }),
1598
- /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { className: "flex h-full w-full items-center justify-between px-3", children: [
1599
- /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", { className: "flex items-center gap-2", children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("p", { className: "font-medium text-black/50", children: "Select a token" }) }),
1600
- /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("svg", { xmlns: "http://www.w3.org/2000/svg", width: "16", height: "16", fill: "none", children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("path", { stroke: "#000", strokeLinecap: "round", d: "m6 12.43 4-4-4-4" }) })
2958
+ return /* @__PURE__ */ (0, import_jsx_runtime32.jsxs)("button", { onClick: openModal, type: "button", className: "bg-primary/8 flex h-11 w-full overflow-hidden rounded-md", children: [
2959
+ /* @__PURE__ */ (0, import_jsx_runtime32.jsx)("div", { className: "bg-primary flex h-full w-11 items-center justify-center", children: /* @__PURE__ */ (0, import_jsx_runtime32.jsx)("div", { className: "flex h-5 w-5 items-center justify-center rounded-full bg-white" }) }),
2960
+ /* @__PURE__ */ (0, import_jsx_runtime32.jsxs)("div", { className: "flex h-full w-full items-center justify-between px-3", children: [
2961
+ /* @__PURE__ */ (0, import_jsx_runtime32.jsx)("div", { className: "flex items-center gap-2", children: /* @__PURE__ */ (0, import_jsx_runtime32.jsx)("p", { className: "font-medium text-black/50", children: "Select a token" }) }),
2962
+ /* @__PURE__ */ (0, import_jsx_runtime32.jsx)("svg", { xmlns: "http://www.w3.org/2000/svg", width: "16", height: "16", fill: "none", children: /* @__PURE__ */ (0, import_jsx_runtime32.jsx)("path", { stroke: "#000", strokeLinecap: "round", d: "m6 12.43 4-4-4-4" }) })
1601
2963
  ] })
1602
2964
  ] });
1603
2965
  };
1604
2966
 
1605
2967
  // src/components/CryptoTab/Crypto/SelectedCoin.tsx
1606
- var import_jsx_runtime21 = require("react/jsx-runtime");
2968
+ var import_jsx_runtime33 = require("react/jsx-runtime");
1607
2969
  var SelectedCoin = (props) => {
1608
2970
  const { coin, balance, logoURI } = props;
1609
2971
  const Icon = getSymbolLogo(coin);
1610
- return /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: "bg-primary/8 flex h-11 w-full overflow-hidden rounded-md", children: [
1611
- /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: "bg-primary flex h-full w-11 items-center justify-center", children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: "flex h-5 w-5 items-center justify-center rounded-full bg-white", children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: "bg-primary h-2.5 w-2.5 rounded-full" }) }) }),
1612
- /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: "border-primary flex h-full w-full items-center justify-between rounded-r-md border-1 !border-l-0 px-3", children: [
1613
- /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: "flex items-center gap-1", children: [
2972
+ return /* @__PURE__ */ (0, import_jsx_runtime33.jsxs)("div", { className: "bg-primary/8 flex h-11 w-full overflow-hidden rounded-md", children: [
2973
+ /* @__PURE__ */ (0, import_jsx_runtime33.jsx)("div", { className: "bg-primary flex h-full w-11 items-center justify-center", children: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)("div", { className: "flex h-5 w-5 items-center justify-center rounded-full bg-white", children: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)("div", { className: "bg-primary h-2.5 w-2.5 rounded-full" }) }) }),
2974
+ /* @__PURE__ */ (0, import_jsx_runtime33.jsxs)("div", { className: "border-primary flex h-full w-full items-center justify-between rounded-r-md border-1 !border-l-0 px-3", children: [
2975
+ /* @__PURE__ */ (0, import_jsx_runtime33.jsxs)("div", { className: "flex items-center gap-1", children: [
1614
2976
  Icon,
1615
- !Icon && logoURI && /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("img", { className: "mr-1 h-8 w-8 shrink-0", src: logoURI, alt: `${coin} logo` }),
1616
- /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("p", { className: "font-semibold text-black", children: coin }),
1617
- /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("path", { d: "M6 12.4341L10 8.43408L6 4.43408", stroke: "black", strokeLinecap: "round" }) })
2977
+ !Icon && logoURI && /* @__PURE__ */ (0, import_jsx_runtime33.jsx)("img", { className: "mr-1 h-8 w-8 shrink-0", src: logoURI, alt: `${coin} logo` }),
2978
+ /* @__PURE__ */ (0, import_jsx_runtime33.jsx)("p", { className: "font-semibold text-black", children: coin }),
2979
+ /* @__PURE__ */ (0, import_jsx_runtime33.jsx)("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)("path", { d: "M6 12.4341L10 8.43408L6 4.43408", stroke: "black", strokeLinecap: "round" }) })
1618
2980
  ] }),
1619
- /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("p", { className: "text-xs font-medium text-black/50", children: [
2981
+ /* @__PURE__ */ (0, import_jsx_runtime33.jsxs)("p", { className: "text-xs font-medium text-black/50", children: [
1620
2982
  "Wallet balance ",
1621
- /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("span", { className: "text-black", children: balance })
2983
+ /* @__PURE__ */ (0, import_jsx_runtime33.jsx)("span", { className: "text-black", children: balance })
1622
2984
  ] })
1623
2985
  ] })
1624
2986
  ] });
1625
2987
  };
1626
2988
 
1627
2989
  // src/components/CryptoTab/Crypto/Crypto.tsx
1628
- var import_jsx_runtime22 = require("react/jsx-runtime");
2990
+ var import_jsx_runtime34 = require("react/jsx-runtime");
1629
2991
  var Crypto = () => {
1630
2992
  const { address } = (0, import_wagmi4.useAccount)();
1631
2993
  const { selectedPaymentMethod } = useSpreePaymentMethod();
1632
2994
  const { cryptoPayment } = useCryptoPayment();
1633
2995
  const isWalletConnected = Boolean(address);
1634
2996
  const { register } = useSpreePayRegister();
1635
- const handlePay = (0, import_react8.useCallback)(
2997
+ const handlePay = (0, import_react14.useCallback)(
1636
2998
  async (data) => {
1637
2999
  try {
1638
3000
  const res = await cryptoPayment(data);
@@ -1646,17 +3008,17 @@ var Crypto = () => {
1646
3008
  },
1647
3009
  [cryptoPayment]
1648
3010
  );
1649
- (0, import_react8.useEffect)(() => {
3011
+ (0, import_react14.useEffect)(() => {
1650
3012
  register(handlePay);
1651
3013
  }, [register, handlePay]);
1652
- return /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)("div", { className: "flex flex-col items-baseline gap-4", children: [
1653
- /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)("div", { className: "flex w-full items-center justify-between gap-4", children: [
1654
- /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("h3", { className: "text-primary text-xl leading-[1.7] font-semibold", children: "Pay with Crypto" }),
1655
- /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(ConnectButton, {})
3014
+ return /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)("div", { className: "flex flex-col items-baseline gap-4", children: [
3015
+ /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)("div", { className: "flex w-full items-center justify-between gap-4", children: [
3016
+ /* @__PURE__ */ (0, import_jsx_runtime34.jsx)("h3", { className: "text-primary text-xl leading-[1.7] font-semibold", children: "Pay with Crypto" }),
3017
+ /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(ConnectButton, {})
1656
3018
  ] }),
1657
- !isWalletConnected && /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(Logos, {}),
1658
- isWalletConnected && /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)("div", { className: "flex w-full flex-col gap-1", children: [
1659
- selectedPaymentMethod.type === "CRYPTO" /* CRYPTO */ && selectedPaymentMethod.method && /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
3019
+ !isWalletConnected && /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Logos, {}),
3020
+ isWalletConnected && /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)("div", { className: "flex w-full flex-col gap-1", children: [
3021
+ selectedPaymentMethod.type === "CRYPTO" /* CRYPTO */ && selectedPaymentMethod.method && /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
1660
3022
  SelectedCoin,
1661
3023
  {
1662
3024
  coin: selectedPaymentMethod.method.symbol,
@@ -1664,13 +3026,13 @@ var Crypto = () => {
1664
3026
  logoURI: selectedPaymentMethod.method.logoURI
1665
3027
  }
1666
3028
  ),
1667
- /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(SelectCoinButton, {})
3029
+ /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(SelectCoinButton, {})
1668
3030
  ] })
1669
3031
  ] });
1670
3032
  };
1671
3033
 
1672
3034
  // src/components/CryptoTab/Crypto/CryptoWrapper.tsx
1673
- var import_jsx_runtime23 = require("react/jsx-runtime");
3035
+ var import_jsx_runtime35 = require("react/jsx-runtime");
1674
3036
  var queryClient = new import_react_query.QueryClient();
1675
3037
  var connectors = (0, import_rainbowkit2.connectorsForWallets)(
1676
3038
  [
@@ -1688,29 +3050,30 @@ var config = (0, import_wagmi5.createConfig)({
1688
3050
  ssr: true
1689
3051
  });
1690
3052
  var CryptoWrapper = () => {
1691
- return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(import_wagmi5.WagmiProvider, { config, children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(import_react_query.QueryClientProvider, { client: queryClient, children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(import_rainbowkit2.RainbowKitProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(import_nice_modal_react5.default.Provider, { children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(Crypto, {}) }) }) }) });
3053
+ return /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(import_wagmi5.WagmiProvider, { config, children: /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(import_react_query.QueryClientProvider, { client: queryClient, children: /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(import_rainbowkit2.RainbowKitProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(import_nice_modal_react6.default.Provider, { children: /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(Crypto, {}) }) }) }) });
1692
3054
  };
1693
3055
 
1694
3056
  // src/components/CryptoTab/CryptoTab.tsx
1695
- var import_jsx_runtime24 = require("react/jsx-runtime");
1696
- var CryptoTab = (props) => {
1697
- const { pointsTitle, pointsConversionRatio } = props;
1698
- return /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)("div", { children: [
1699
- /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { className: "border-b-1 border-black/7 px-5 py-5 md:px-7 md:py-5", children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(CryptoWrapper, {}) }),
1700
- /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { className: "px-5 py-5 md:px-7 md:py-6", children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(PointsSwitch, { disabled: true, pointsTitle, pointsConversionRatio }) })
3057
+ var import_jsx_runtime36 = require("react/jsx-runtime");
3058
+ var CryptoTab = () => {
3059
+ return /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("div", { children: [
3060
+ /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("div", { className: "border-b-1 border-black/7 px-5 py-5 md:px-7 md:py-5", children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(CryptoWrapper, {}) }),
3061
+ /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("div", { className: "px-5 py-5 md:px-7 md:py-6", children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(PointsSwitch, { disabled: true }) })
1701
3062
  ] });
1702
3063
  };
1703
3064
 
1704
3065
  // src/components/TabButtons.tsx
1705
- var import_jsx_runtime25 = require("react/jsx-runtime");
1706
- var TabButton = ({ isActive, children, onClick }) => {
1707
- return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
3066
+ var import_jsx_runtime37 = require("react/jsx-runtime");
3067
+ var TabButton = ({ isDisabled = true, isActive, children, onClick }) => {
3068
+ return /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(
1708
3069
  "button",
1709
3070
  {
3071
+ disabled: isDisabled,
1710
3072
  onClick,
1711
3073
  className: cn(
1712
3074
  "flex w-[132px] flex-col items-baseline rounded-sm border-1 border-black/50 px-2.5 py-1.5 text-sm text-black",
1713
- { "opacity-50": !isActive },
3075
+ { "opacity-50": !isActive || isDisabled },
3076
+ { "cursor-not-allowed": isDisabled },
1714
3077
  { "bg-primary/7 border-primary text-primary": isActive }
1715
3078
  ),
1716
3079
  children
@@ -1719,84 +3082,99 @@ var TabButton = ({ isActive, children, onClick }) => {
1719
3082
  };
1720
3083
  var TabButtons = (props) => {
1721
3084
  const { value, onChange } = props;
3085
+ const { spreePayConfig } = useSpreePayConfig();
1722
3086
  const handleChange = (type) => () => {
1723
3087
  if (value !== type) {
1724
3088
  onChange({ type, method: null });
1725
3089
  }
1726
3090
  };
1727
- return /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className: "flex gap-2", children: [
1728
- /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(TabButton, { onClick: handleChange("CREDIT_CARD" /* CREDIT_CARD */), isActive: value === "CREDIT_CARD" /* CREDIT_CARD */, children: [
1729
- /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("svg", { xmlns: "http://www.w3.org/2000/svg", width: "24", height: "24", fill: "none", children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
1730
- "path",
1731
- {
1732
- fill: "currentColor",
1733
- d: "M22 6v12c0 .55-.2 1.02-.59 1.41-.39.4-.86.59-1.41.59H4c-.55 0-1.02-.2-1.41-.59-.4-.39-.59-.86-.59-1.41V6c0-.55.2-1.02.59-1.41C2.98 4.19 3.45 4 4 4h16c.55 0 1.02.2 1.41.59.4.39.59.86.59 1.41ZM4 8h16V6H4v2Zm0 4v6h16v-6H4Z"
1734
- }
1735
- ) }),
1736
- /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("p", { className: "text-sm font-medium", children: "Card" })
1737
- ] }),
1738
- /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(TabButton, { onClick: handleChange("CRYPTO" /* CRYPTO */), isActive: value === "CRYPTO" /* CRYPTO */, children: [
1739
- /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("svg", { className: "my-1", xmlns: "http://www.w3.org/2000/svg", width: "30", height: "16", fill: "none", children: [
1740
- /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
1741
- "path",
1742
- {
1743
- fill: "currentColor",
1744
- d: "M14.5 0C19.2 0 23 3.58 23 8s-3.8 8-8.5 8a8.93 8.93 0 0 1-3.35-.65 8 8 0 0 0 2.24-1.44c.36.06.73.09 1.11.09 3.7 0 6.5-2.8 6.5-6s-2.8-6-6.5-6c-.38 0-.75.03-1.11.09A8 8 0 0 0 11.15.65 8.93 8.93 0 0 1 14.5 0Z"
1745
- }
1746
- ),
1747
- /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
1748
- "path",
1749
- {
1750
- fill: "currentColor",
1751
- d: "M21.15 0c4.7 0 8.5 3.58 8.5 8s-3.8 8-8.5 8a8.93 8.93 0 0 1-3.35-.65 8 8 0 0 0 2.24-1.44c.36.06.73.09 1.1.09 3.71 0 6.5-2.8 6.5-6s-2.79-6-6.5-6c-.37 0-.74.03-1.1.09A8 8 0 0 0 17.8.65 8.93 8.93 0 0 1 21.15 0Z"
1752
- }
1753
- ),
1754
- /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("circle", { cx: "8", cy: "8", r: "7", stroke: "currentColor", strokeWidth: "2" })
1755
- ] }),
1756
- /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("p", { className: "text-sm font-medium", children: "Crypto" })
1757
- ] })
3091
+ return /* @__PURE__ */ (0, import_jsx_runtime37.jsxs)("div", { className: "flex gap-2", children: [
3092
+ /* @__PURE__ */ (0, import_jsx_runtime37.jsxs)(
3093
+ TabButton,
3094
+ {
3095
+ isDisabled: !spreePayConfig?.creditCard.enabled,
3096
+ onClick: handleChange("CREDIT_CARD" /* CREDIT_CARD */),
3097
+ isActive: value === "CREDIT_CARD" /* CREDIT_CARD */,
3098
+ children: [
3099
+ /* @__PURE__ */ (0, import_jsx_runtime37.jsx)("svg", { xmlns: "http://www.w3.org/2000/svg", width: "24", height: "24", fill: "none", children: /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(
3100
+ "path",
3101
+ {
3102
+ fill: "currentColor",
3103
+ d: "M22 6v12c0 .55-.2 1.02-.59 1.41-.39.4-.86.59-1.41.59H4c-.55 0-1.02-.2-1.41-.59-.4-.39-.59-.86-.59-1.41V6c0-.55.2-1.02.59-1.41C2.98 4.19 3.45 4 4 4h16c.55 0 1.02.2 1.41.59.4.39.59.86.59 1.41ZM4 8h16V6H4v2Zm0 4v6h16v-6H4Z"
3104
+ }
3105
+ ) }),
3106
+ /* @__PURE__ */ (0, import_jsx_runtime37.jsx)("p", { className: "text-sm font-medium", children: "Card" })
3107
+ ]
3108
+ }
3109
+ ),
3110
+ /* @__PURE__ */ (0, import_jsx_runtime37.jsxs)(
3111
+ TabButton,
3112
+ {
3113
+ isDisabled: !spreePayConfig?.creditCard.enabled,
3114
+ onClick: handleChange("CRYPTO" /* CRYPTO */),
3115
+ isActive: value === "CRYPTO" /* CRYPTO */,
3116
+ children: [
3117
+ /* @__PURE__ */ (0, import_jsx_runtime37.jsxs)("svg", { className: "my-1", xmlns: "http://www.w3.org/2000/svg", width: "30", height: "16", fill: "none", children: [
3118
+ /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(
3119
+ "path",
3120
+ {
3121
+ fill: "currentColor",
3122
+ d: "M14.5 0C19.2 0 23 3.58 23 8s-3.8 8-8.5 8a8.93 8.93 0 0 1-3.35-.65 8 8 0 0 0 2.24-1.44c.36.06.73.09 1.11.09 3.7 0 6.5-2.8 6.5-6s-2.8-6-6.5-6c-.38 0-.75.03-1.11.09A8 8 0 0 0 11.15.65 8.93 8.93 0 0 1 14.5 0Z"
3123
+ }
3124
+ ),
3125
+ /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(
3126
+ "path",
3127
+ {
3128
+ fill: "currentColor",
3129
+ d: "M21.15 0c4.7 0 8.5 3.58 8.5 8s-3.8 8-8.5 8a8.93 8.93 0 0 1-3.35-.65 8 8 0 0 0 2.24-1.44c.36.06.73.09 1.1.09 3.71 0 6.5-2.8 6.5-6s-2.79-6-6.5-6c-.37 0-.74.03-1.1.09A8 8 0 0 0 17.8.65 8.93 8.93 0 0 1 21.15 0Z"
3130
+ }
3131
+ ),
3132
+ /* @__PURE__ */ (0, import_jsx_runtime37.jsx)("circle", { cx: "8", cy: "8", r: "7", stroke: "currentColor", strokeWidth: "2" })
3133
+ ] }),
3134
+ /* @__PURE__ */ (0, import_jsx_runtime37.jsx)("p", { className: "text-sm font-medium", children: "Crypto" })
3135
+ ]
3136
+ }
3137
+ )
1758
3138
  ] });
1759
3139
  };
1760
3140
 
1761
3141
  // src/components/Tabs.tsx
1762
- var import_jsx_runtime26 = require("react/jsx-runtime");
1763
- var Tabs = ({ config: config2 }) => {
3142
+ var import_jsx_runtime38 = require("react/jsx-runtime");
3143
+ var Tabs = () => {
1764
3144
  const { selectedPaymentMethod, setSelectedPaymentMethod } = useSpreePaymentMethod();
1765
- const { pointsConversionRatio, pointsTitle } = config2;
1766
- return /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)("div", { className: "mb-4 rounded-3xl border border-black/25 bg-white", children: [
1767
- /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)("div", { className: "flex w-full flex-col gap-4 border-b-1 border-black/7 px-5 py-5 md:px-7 md:py-6", children: [
1768
- /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("h2", { className: "text-primary text-2xl font-semibold", children: "Choose a Payment Method" }),
1769
- /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(TabButtons, { value: selectedPaymentMethod.type, onChange: setSelectedPaymentMethod })
3145
+ return /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)("div", { className: "mb-4 rounded-3xl border border-black/25 bg-white", children: [
3146
+ /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)("div", { className: "flex w-full flex-col gap-4 border-b-1 border-black/7 px-5 py-5 md:px-7 md:py-6", children: [
3147
+ /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("h2", { className: "text-primary text-2xl font-semibold", children: "Choose a Payment Method" }),
3148
+ /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(TabButtons, { value: selectedPaymentMethod.type, onChange: setSelectedPaymentMethod })
1770
3149
  ] }),
1771
- selectedPaymentMethod.type === "CREDIT_CARD" /* CREDIT_CARD */ && /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(CreditCardTab, { pointsTitle, pointsConversionRatio }),
1772
- selectedPaymentMethod.type === "CRYPTO" /* CRYPTO */ && /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(CryptoTab, { pointsTitle, pointsConversionRatio })
3150
+ selectedPaymentMethod.type === "CREDIT_CARD" /* CREDIT_CARD */ && /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(CreditCardTab, {}),
3151
+ selectedPaymentMethod.type === "CRYPTO" /* CRYPTO */ && /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(CryptoTab, {})
1773
3152
  ] });
1774
3153
  };
1775
3154
 
1776
3155
  // src/SpreePayContent.tsx
1777
- var import_jsx_runtime27 = require("react/jsx-runtime");
1778
- var SpreePayContent = (props) => {
1779
- const { isLoggedIn, config: config2, amount, onProcess, isProcessing } = props;
1780
- return /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)("div", { className: "w-full", children: [
1781
- /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(Tabs, { config: config2 }),
1782
- /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(CheckoutButton, { isLoggedIn, isProcessing, onCheckout: onProcess, amount }),
1783
- /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(SpreeLegal, {})
3156
+ var import_jsx_runtime39 = require("react/jsx-runtime");
3157
+ var SpreePayContent = ({ isLoggedIn }) => {
3158
+ return /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)("div", { className: "w-full", children: [
3159
+ /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(Tabs, {}),
3160
+ /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(CheckoutButton, { isLoggedIn }),
3161
+ /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(SpreeLegal, {})
1784
3162
  ] });
1785
3163
  };
1786
3164
 
1787
3165
  // src/hooks/useKeycloakSSO.ts
1788
- var import_react9 = require("react");
3166
+ var import_react15 = require("react");
1789
3167
  var import_keycloak_js = __toESM(require("keycloak-js"), 1);
1790
3168
  var refreshAheadSeconds = 60;
1791
3169
  function useKeycloakSSO(config2) {
1792
3170
  const { url, realm, clientId, ssoPageURI, enabled } = config2;
1793
- const initRef = (0, import_react9.useRef)(false);
1794
- const kcRef = (0, import_react9.useRef)(null);
1795
- const refreshTimerRef = (0, import_react9.useRef)(null);
1796
- const [error, setError] = (0, import_react9.useState)(null);
1797
- const [isChecking, setIsChecking] = (0, import_react9.useState)(enabled);
1798
- const [accessToken, setAccessToken] = (0, import_react9.useState)(null);
1799
- const scheduleRefresh = (0, import_react9.useCallback)(() => {
3171
+ const initRef = (0, import_react15.useRef)(false);
3172
+ const kcRef = (0, import_react15.useRef)(null);
3173
+ const refreshTimerRef = (0, import_react15.useRef)(null);
3174
+ const [error, setError] = (0, import_react15.useState)(null);
3175
+ const [isChecking, setIsChecking] = (0, import_react15.useState)(enabled);
3176
+ const [accessToken, setAccessToken] = (0, import_react15.useState)(null);
3177
+ const scheduleRefresh = (0, import_react15.useCallback)(() => {
1800
3178
  const kc = kcRef.current;
1801
3179
  if (!kc || !kc.tokenParsed || !kc.tokenParsed.exp) {
1802
3180
  return;
@@ -1817,7 +3195,7 @@ function useKeycloakSSO(config2) {
1817
3195
  });
1818
3196
  }, delayMs);
1819
3197
  }, []);
1820
- (0, import_react9.useEffect)(() => {
3198
+ (0, import_react15.useEffect)(() => {
1821
3199
  if (initRef.current || !enabled) return;
1822
3200
  initRef.current = true;
1823
3201
  setIsChecking(true);
@@ -1852,94 +3230,43 @@ function useKeycloakSSO(config2) {
1852
3230
  }
1853
3231
 
1854
3232
  // src/SpreePay.tsx
1855
- var import_jsx_runtime28 = require("react/jsx-runtime");
1856
- var CONFIG = {
1857
- dev: {
1858
- bookit: {
1859
- slapiUrl: "https://slapi.dev.superlogic.com",
1860
- keyklockUrl: "https://auth.dev.join.bookit.com",
1861
- keyklockClientId: "oneof-next",
1862
- pointsConversionRatio: 100,
1863
- pointsTitle: "AIR SP"
1864
- },
1865
- moca: {
1866
- slapiUrl: "https://slapi.dev.air.shop",
1867
- keyklockUrl: "https://login.dev.air.shop",
1868
- keyklockClientId: "oneof-next",
1869
- pointsConversionRatio: 100,
1870
- pointsTitle: "AIR SP"
1871
- }
1872
- },
1873
- stg: {
1874
- bookit: {
1875
- slapiUrl: "https://slapi.stg.superlogic.com",
1876
- keyklockUrl: "https://auth.stg.join.bookit.com",
1877
- keyklockClientId: "oneof-next",
1878
- pointsConversionRatio: 100,
1879
- pointsTitle: "AIR SP"
1880
- },
1881
- moca: {
1882
- slapiUrl: "https://slapi.stg.air.shop",
1883
- keyklockUrl: "https://login.stg.air.shop",
1884
- keyklockClientId: "oneof-next",
1885
- pointsConversionRatio: 100,
1886
- pointsTitle: "AIR SP"
1887
- }
1888
- },
1889
- prod: {
1890
- bookit: {
1891
- slapiUrl: "https://slapi.superlogic.com",
1892
- keyklockUrl: "https://auth.join.bookit.com",
1893
- keyklockClientId: "oneof-next",
1894
- pointsConversionRatio: 100,
1895
- pointsTitle: "AIR SP"
1896
- },
1897
- moca: {
1898
- slapiUrl: "https://slapi.air.shop",
1899
- keyklockUrl: "https://login.air.shop",
1900
- keyklockClientId: "oneof-next",
1901
- pointsConversionRatio: 100,
1902
- pointsTitle: "AIR SP"
1903
- }
1904
- }
1905
- };
1906
- var SpreePay = ({ className, ...rest }) => {
1907
- const rootRef = (0, import_react10.useRef)(null);
1908
- const [portalEl, setPortalEl] = (0, import_react10.useState)(null);
1909
- (0, import_react10.useLayoutEffect)(() => {
3233
+ var import_jsx_runtime40 = require("react/jsx-runtime");
3234
+ var SpreePayInner = () => {
3235
+ const rootRef = (0, import_react16.useRef)(null);
3236
+ const [portalEl, setPortalEl] = (0, import_react16.useState)(null);
3237
+ (0, import_react16.useLayoutEffect)(() => {
1910
3238
  if (!rootRef.current) return;
1911
3239
  const el = rootRef.current.querySelector(":scope > .sl-spreepay__portal");
1912
3240
  setPortalEl(el ?? null);
1913
3241
  }, []);
1914
3242
  const { env } = useSpreePayEnv();
1915
- const environment = env?.environment || "dev";
3243
+ const { staticConfig, appProps } = useStaticConfig();
1916
3244
  const tenantId = env?.tenantId || "bookit";
1917
- const config2 = CONFIG[environment]?.[tenantId];
1918
3245
  const { isChecking, accessToken } = useKeycloakSSO({
1919
3246
  realm: tenantId,
1920
- url: config2.keyklockUrl,
1921
- clientId: config2.keyklockClientId,
3247
+ url: staticConfig.keycloakUrl,
3248
+ clientId: staticConfig.keycloakClientId,
1922
3249
  ssoPageURI: env?.ssoPageURI,
1923
3250
  enabled: !env?.accessToken
1924
3251
  });
1925
- const slapiFetcher = (0, import_react10.useMemo)(() => {
3252
+ const slapiFetcher = (0, import_react16.useMemo)(() => {
1926
3253
  if (accessToken || env.accessToken) {
1927
3254
  return registerApi({
1928
3255
  accessToken: env.accessToken || accessToken,
1929
3256
  tenantId,
1930
- baseUrl: config2.slapiUrl
3257
+ baseUrl: staticConfig.slapiUrl
1931
3258
  });
1932
3259
  }
1933
- }, [env.accessToken, config2, tenantId, accessToken]);
3260
+ }, [env.accessToken, staticConfig, tenantId, accessToken]);
1934
3261
  const getContent = () => {
1935
3262
  if (isChecking) {
1936
- return /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)("div", { className: "flex w-full flex-col", children: [
1937
- /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("div", { className: "bg-primary/8 mb-4 h-[315px] animate-pulse rounded-3xl" }),
1938
- /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("div", { className: "bg-primary/8 h-[135px] animate-pulse rounded-3xl" }),
1939
- /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(SpreeLegal, {})
3263
+ return /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("div", { className: "flex w-full flex-col", children: [
3264
+ /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("div", { className: "bg-primary/8 mb-4 h-[315px] animate-pulse rounded-3xl" }),
3265
+ /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("div", { className: "bg-primary/8 h-[135px] animate-pulse rounded-3xl" }),
3266
+ /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(SpreeLegal, {})
1940
3267
  ] });
1941
3268
  }
1942
- return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
3269
+ return /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
1943
3270
  import_swr4.SWRConfig,
1944
3271
  {
1945
3272
  value: {
@@ -1948,27 +3275,31 @@ var SpreePay = ({ className, ...rest }) => {
1948
3275
  revalidateOnFocus: false,
1949
3276
  revalidateIfStale: false
1950
3277
  },
1951
- children: /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(PortalContainerProvider, { container: portalEl, children: /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(import_nice_modal_react6.default.Provider, { children: /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(SpreePayContent, { isLoggedIn: Boolean(accessToken || env.accessToken), config: config2, ...rest }) }) })
3278
+ children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(PortalContainerProvider, { container: portalEl, children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(import_nice_modal_react7.default.Provider, { children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(SpreePayContent, { isLoggedIn: Boolean(accessToken || env.accessToken) }) }) })
1952
3279
  }
1953
3280
  );
1954
3281
  };
1955
- return /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)("div", { ref: rootRef, className: cn("sl-spreepay", className), children: [
1956
- /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("div", { className: "sl-spreepay__portal" }),
3282
+ return /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("div", { ref: rootRef, className: cn("sl-spreepay", appProps.className), children: [
3283
+ /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("div", { className: "sl-spreepay__portal" }),
1957
3284
  getContent()
1958
3285
  ] });
1959
3286
  };
3287
+ var SpreePay = (props) => {
3288
+ return /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(StaticConfigProvider, { props, children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(SpreePayInner, {}) });
3289
+ };
1960
3290
 
1961
3291
  // src/hooks/useCapture3DS.ts
1962
- var import_react11 = require("react");
3292
+ var import_react17 = require("react");
1963
3293
  var useCapture3DS = (searchParams) => {
1964
- (0, import_react11.useEffect)(() => {
1965
- if (window?.parent && searchParams?.paymentIntent) {
3294
+ (0, import_react17.useEffect)(() => {
3295
+ if (typeof window !== "undefined" && window.parent && searchParams?.paymentIntent) {
1966
3296
  window.parent.SP_EVENT_BUS?.emit("paymentIntent", { paymentIntent: searchParams.paymentIntent });
1967
3297
  }
1968
3298
  }, [searchParams]);
1969
3299
  };
1970
3300
  // Annotate the CommonJS export names for ESM import in node:
1971
3301
  0 && (module.exports = {
3302
+ PaymentType,
1972
3303
  SpreePay,
1973
3304
  SpreePayProvider,
1974
3305
  useCapture3DS,