atlas-react-widget 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.js CHANGED
@@ -1,4 +1,4 @@
1
- import se, { useState as D, useRef as W, useEffect as T, useCallback as te } from "react";
1
+ import se, { useState as D, useRef as W, useEffect as A, useCallback as te } from "react";
2
2
  var F = { exports: {} }, R = {};
3
3
  /**
4
4
  * @license React
@@ -14,7 +14,7 @@ function ne() {
14
14
  if (J) return R;
15
15
  J = 1;
16
16
  var o = Symbol.for("react.transitional.element"), f = Symbol.for("react.fragment");
17
- function d(c, l, u) {
17
+ function d(i, l, u) {
18
18
  var r = null;
19
19
  if (u !== void 0 && (r = "" + u), l.key !== void 0 && (r = "" + l.key), "key" in l) {
20
20
  u = {};
@@ -23,7 +23,7 @@ function ne() {
23
23
  } else u = l;
24
24
  return l = u.ref, {
25
25
  $$typeof: o,
26
- type: c,
26
+ type: i,
27
27
  key: r,
28
28
  ref: l !== void 0 ? l : null,
29
29
  props: u
@@ -107,7 +107,7 @@ function le() {
107
107
  ), f(e);
108
108
  }
109
109
  }
110
- function c(e) {
110
+ function i(e) {
111
111
  if (e === y) return "<>";
112
112
  if (typeof e == "object" && e !== null && e.$$typeof === $)
113
113
  return "<...>";
@@ -119,7 +119,7 @@ function le() {
119
119
  }
120
120
  }
121
121
  function l() {
122
- var e = A.A;
122
+ var e = T.A;
123
123
  return e === null ? null : e.getOwner();
124
124
  }
125
125
  function u() {
@@ -144,22 +144,22 @@ function le() {
144
144
  configurable: !0
145
145
  });
146
146
  }
147
- function g() {
147
+ function N() {
148
148
  var e = o(this.type);
149
149
  return z[e] || (z[e] = !0, console.error(
150
150
  "Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
151
151
  )), e = this.props.ref, e !== void 0 ? e : null;
152
152
  }
153
- function P(e, s, p, C, N, w, S, L) {
154
- return p = w.ref, e = {
153
+ function P(e, s, p, C, w, g, S, L) {
154
+ return p = g.ref, e = {
155
155
  $$typeof: m,
156
156
  type: e,
157
157
  key: s,
158
- props: w,
159
- _owner: N
158
+ props: g,
159
+ _owner: w
160
160
  }, (p !== void 0 ? p : null) !== null ? Object.defineProperty(e, "ref", {
161
161
  enumerable: !1,
162
- get: g
162
+ get: N
163
163
  }) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
164
164
  configurable: !1,
165
165
  enumerable: !1,
@@ -182,7 +182,7 @@ function le() {
182
182
  value: L
183
183
  }), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
184
184
  }
185
- function i(e, s, p, C, N, w, S, L) {
185
+ function c(e, s, p, C, w, g, S, L) {
186
186
  var j = s.children;
187
187
  if (j !== void 0)
188
188
  if (C)
@@ -224,8 +224,8 @@ React keys must be passed directly to JSX without using spread:
224
224
  ), P(
225
225
  e,
226
226
  j,
227
+ g,
227
228
  w,
228
- N,
229
229
  l(),
230
230
  p,
231
231
  S,
@@ -235,7 +235,7 @@ React keys must be passed directly to JSX without using spread:
235
235
  function v(e) {
236
236
  typeof e == "object" && e !== null && e.$$typeof === m && e._store && (e._store.validated = 1);
237
237
  }
238
- var h = se, m = Symbol.for("react.transitional.element"), n = Symbol.for("react.portal"), y = Symbol.for("react.fragment"), b = Symbol.for("react.strict_mode"), x = Symbol.for("react.profiler"), E = Symbol.for("react.consumer"), G = Symbol.for("react.context"), Z = Symbol.for("react.forward_ref"), B = Symbol.for("react.suspense"), X = Symbol.for("react.suspense_list"), Q = Symbol.for("react.memo"), $ = Symbol.for("react.lazy"), K = Symbol.for("react.activity"), ee = Symbol.for("react.client.reference"), A = h.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, Y = Object.prototype.hasOwnProperty, ae = Array.isArray, O = console.createTask ? console.createTask : function() {
238
+ var h = se, m = Symbol.for("react.transitional.element"), n = Symbol.for("react.portal"), y = Symbol.for("react.fragment"), b = Symbol.for("react.strict_mode"), x = Symbol.for("react.profiler"), E = Symbol.for("react.consumer"), G = Symbol.for("react.context"), Z = Symbol.for("react.forward_ref"), B = Symbol.for("react.suspense"), X = Symbol.for("react.suspense_list"), Q = Symbol.for("react.memo"), $ = Symbol.for("react.lazy"), K = Symbol.for("react.activity"), ee = Symbol.for("react.client.reference"), T = h.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, Y = Object.prototype.hasOwnProperty, ae = Array.isArray, O = console.createTask ? console.createTask : function() {
239
239
  return null;
240
240
  };
241
241
  h = {
@@ -246,30 +246,30 @@ React keys must be passed directly to JSX without using spread:
246
246
  var M, z = {}, V = h.react_stack_bottom_frame.bind(
247
247
  h,
248
248
  u
249
- )(), U = O(c(u)), H = {};
250
- k.Fragment = y, k.jsx = function(e, s, p, C, N) {
251
- var w = 1e4 > A.recentlyCreatedOwnerStacks++;
252
- return i(
249
+ )(), U = O(i(u)), H = {};
250
+ k.Fragment = y, k.jsx = function(e, s, p, C, w) {
251
+ var g = 1e4 > T.recentlyCreatedOwnerStacks++;
252
+ return c(
253
253
  e,
254
254
  s,
255
255
  p,
256
256
  !1,
257
257
  C,
258
- N,
259
- w ? Error("react-stack-top-frame") : V,
260
- w ? O(c(e)) : U
258
+ w,
259
+ g ? Error("react-stack-top-frame") : V,
260
+ g ? O(i(e)) : U
261
261
  );
262
- }, k.jsxs = function(e, s, p, C, N) {
263
- var w = 1e4 > A.recentlyCreatedOwnerStacks++;
264
- return i(
262
+ }, k.jsxs = function(e, s, p, C, w) {
263
+ var g = 1e4 > T.recentlyCreatedOwnerStacks++;
264
+ return c(
265
265
  e,
266
266
  s,
267
267
  p,
268
268
  !0,
269
269
  C,
270
- N,
271
- w ? Error("react-stack-top-frame") : V,
272
- w ? O(c(e)) : U
270
+ w,
271
+ g ? Error("react-stack-top-frame") : V,
272
+ g ? O(i(e)) : U
273
273
  );
274
274
  };
275
275
  }()), k;
@@ -277,26 +277,26 @@ React keys must be passed directly to JSX without using spread:
277
277
  process.env.NODE_ENV === "production" ? F.exports = ne() : F.exports = le();
278
278
  var a = F.exports;
279
279
  const oe = (o, f) => {
280
- const [d, c] = D({
280
+ const [d, i] = D({
281
281
  status: "idle",
282
282
  message: "Ready to pay"
283
283
  }), [l, u] = D({
284
284
  isValid: !1,
285
285
  isLoading: !0
286
286
  }), r = W(null), t = W(null);
287
- T(() => {
287
+ A(() => {
288
288
  (async () => {
289
289
  if (!o) {
290
290
  u({
291
291
  isValid: !1,
292
292
  isLoading: !1
293
- }), c({
293
+ }), i({
294
294
  status: "error",
295
295
  message: "No auth key provided"
296
296
  });
297
297
  return;
298
298
  }
299
- u((m) => ({ ...m, isLoading: !0 })), c({
299
+ u((m) => ({ ...m, isLoading: !0 })), i({
300
300
  status: "loading",
301
301
  message: "Loading payment information..."
302
302
  });
@@ -312,8 +312,11 @@ const oe = (o, f) => {
312
312
  })
313
313
  }
314
314
  )).json();
315
- if (!n.valid)
316
- throw new Error(n.error || "Invalid auth key");
315
+ n.valid || i({
316
+ status: "error",
317
+ message: "Failed to initialize payment",
318
+ error: n.error || "Invalid Auth Key"
319
+ });
317
320
  const y = await fetch(
318
321
  "https://api.atlascard.xyz/api/credentials/get",
319
322
  {
@@ -336,7 +339,7 @@ const oe = (o, f) => {
336
339
  isValid: !0,
337
340
  isLoading: !1
338
341
  };
339
- u(x), c({
342
+ u(x), i({
340
343
  status: "ready",
341
344
  message: "Ready to process payment"
342
345
  });
@@ -344,20 +347,20 @@ const oe = (o, f) => {
344
347
  console.error("Payment initialization error:", m), u({
345
348
  isValid: !1,
346
349
  isLoading: !1
347
- }), c({
350
+ }), i({
348
351
  status: "error",
349
352
  message: "Failed to initialize payment",
350
353
  error: m instanceof Error ? m.message : "Unknown error"
351
354
  });
352
355
  }
353
356
  })();
354
- }, [o, f]), T(() => {
357
+ }, [o, f]), A(() => {
355
358
  const h = (m) => {
356
359
  if (m.origin !== "https://atlascard.xyz") return;
357
360
  const n = m.data;
358
361
  switch (n.type) {
359
362
  case "payment_result":
360
- n.status === "success" ? (c({
363
+ n.status === "success" ? (i({
361
364
  status: "success",
362
365
  message: "Payment successful!",
363
366
  transactionHash: n.transactionHash
@@ -371,7 +374,7 @@ const oe = (o, f) => {
371
374
  }), t.current = null), r.current && setTimeout(() => {
372
375
  var y;
373
376
  (y = r.current) == null || y.close(), r.current = null;
374
- }, 3e3)) : (c({
377
+ }, 3e3)) : (i({
375
378
  status: "error",
376
379
  message: n.error || "Payment failed",
377
380
  error: n.error
@@ -383,7 +386,7 @@ const oe = (o, f) => {
383
386
  }, 3e3));
384
387
  break;
385
388
  case "payment_error":
386
- c({
389
+ i({
387
390
  status: "error",
388
391
  message: n.error || "Payment failed",
389
392
  error: n.error
@@ -392,7 +395,7 @@ const oe = (o, f) => {
392
395
  ), t.current = null), r.current && (r.current.close(), r.current = null);
393
396
  break;
394
397
  case "close_popup":
395
- r.current && (r.current.close(), r.current = null), d.status === "popup_open" && (c({
398
+ r.current && (r.current.close(), r.current = null), d.status === "popup_open" && (i({
396
399
  status: "ready",
397
400
  message: "Payment cancelled"
398
401
  }), t.current && (t.current.reject(
@@ -402,11 +405,11 @@ const oe = (o, f) => {
402
405
  }
403
406
  };
404
407
  return window.addEventListener("message", h), () => window.removeEventListener("message", h);
405
- }, [l, d.status]), T(() => {
408
+ }, [l, d.status]), A(() => {
406
409
  if (!r.current) return;
407
410
  const h = setInterval(() => {
408
411
  var m;
409
- (m = r.current) != null && m.closed && (clearInterval(h), d.status === "popup_open" && (c({
412
+ (m = r.current) != null && m.closed && (clearInterval(h), d.status === "popup_open" && (i({
410
413
  status: "ready",
411
414
  message: "Payment cancelled"
412
415
  }), t.current && (t.current.reject(
@@ -415,7 +418,7 @@ const oe = (o, f) => {
415
418
  }, 500);
416
419
  return () => clearInterval(h);
417
420
  }, [d.status]);
418
- const g = te(
421
+ const N = te(
419
422
  async (h, m) => {
420
423
  if (!l.isValid || !l.credentials)
421
424
  throw new Error("Payment data not validated");
@@ -436,13 +439,13 @@ const oe = (o, f) => {
436
439
  );
437
440
  if (!b) {
438
441
  const x = "Please allow popups to complete the payment";
439
- throw c({
442
+ throw i({
440
443
  status: "error",
441
444
  message: x,
442
445
  error: x
443
446
  }), new Error(x);
444
447
  }
445
- r.current = b, c({
448
+ r.current = b, i({
446
449
  status: "popup_open",
447
450
  message: "Complete payment in the popup window"
448
451
  });
@@ -454,19 +457,19 @@ const oe = (o, f) => {
454
457
  if (!l.isValid)
455
458
  throw new Error("Payment data not validated");
456
459
  return new Promise((n, y) => {
457
- t.current = { resolve: n, reject: y }, g(h, m).catch(y);
460
+ t.current = { resolve: n, reject: y }, N(h, m).catch(y);
458
461
  });
459
462
  },
460
463
  status: d,
461
464
  paymentData: l,
462
465
  closePopup: () => {
463
- r.current && (r.current.close(), r.current = null), d.status === "popup_open" && c({
466
+ r.current && (r.current.close(), r.current = null), d.status === "popup_open" && i({
464
467
  status: "ready",
465
468
  message: "Payment cancelled"
466
469
  }), t.current && (t.current.reject(new Error("Payment cancelled")), t.current = null);
467
470
  },
468
471
  reset: () => {
469
- c({ status: "idle", message: "Ready to pay" }), u({
472
+ i({ status: "idle", message: "Ready to pay" }), u({
470
473
  isValid: !1,
471
474
  isLoading: !0
472
475
  }), r.current && (r.current.close(), r.current = null), t.current && (t.current.reject(new Error("Payment reset")), t.current = null);
@@ -515,14 +518,14 @@ const oe = (o, f) => {
515
518
  authKey: o,
516
519
  merchantPaymentAddress: f,
517
520
  amount: d = "0",
518
- paymentType: c = "one_time_payment",
521
+ paymentType: i = "one_time_payment",
519
522
  onSuccess: l,
520
523
  onError: u,
521
524
  className: r = "",
522
525
  buttonText: t = "PAY NOW",
523
- disabled: g = !1
526
+ disabled: N = !1
524
527
  }) => {
525
- const { processPayment: P, status: i, paymentData: v, closePopup: h, reset: m } = oe(o, c), n = async (x) => {
528
+ const { processPayment: P, status: c, paymentData: v, closePopup: h, reset: m } = oe(o, i), n = async (x) => {
526
529
  if (x.preventDefault(), !(!(v != null && v.isValid) || parseFloat(d) <= 0))
527
530
  try {
528
531
  const E = await P(f, d);
@@ -533,30 +536,30 @@ const oe = (o, f) => {
533
536
  }, y = () => {
534
537
  m();
535
538
  };
536
- T(() => {
537
- i.status === "success" && i.transactionHash && (l == null || l({
539
+ A(() => {
540
+ c.status === "success" && c.transactionHash && (l == null || l({
538
541
  success: !0,
539
- transactionHash: i.transactionHash,
542
+ transactionHash: c.transactionHash,
540
543
  amount: d,
541
544
  merchant: f,
542
- type: c,
545
+ type: i,
543
546
  paymentData: v
544
547
  }));
545
- }, [i.status, i.transactionHash]), T(() => {
546
- i.status === "error" && i.error && (u == null || u(new Error(i.error)));
547
- }, [i.status, i.error]);
548
+ }, [c.status, c.transactionHash]), A(() => {
549
+ c.status === "error" && c.error && (u == null || u(new Error(c.error)));
550
+ }, [c.status, c.error]);
548
551
  const b = (x) => x === "delegate" ? "Recurring Payment" : "One-time Payment";
549
552
  return v ? v.isLoading ? /* @__PURE__ */ a.jsx("div", { className: `atlas-container ${r}`, children: /* @__PURE__ */ a.jsxs("div", { className: "atlas-loading", children: [
550
553
  /* @__PURE__ */ a.jsx("div", { className: "atlas-spinner" }),
551
554
  /* @__PURE__ */ a.jsx("p", { children: "Loading payment information..." })
552
- ] }) }) : !v.isValid && i.status === "error" ? /* @__PURE__ */ a.jsx("div", { className: `atlas-container ${r}`, children: /* @__PURE__ */ a.jsxs("div", { className: "atlas-error-state", children: [
555
+ ] }) }) : !v.isValid && c.status === "error" ? /* @__PURE__ */ a.jsx("div", { className: `atlas-container ${r}`, children: /* @__PURE__ */ a.jsxs("div", { className: "atlas-error-state", children: [
553
556
  /* @__PURE__ */ a.jsx("div", { className: "atlas-error-icon", children: "⚠️" }),
554
557
  /* @__PURE__ */ a.jsx("h3", { children: "Payment Setup Failed" }),
555
- /* @__PURE__ */ a.jsx("p", { children: i.error || "Unable to initialize payment" }),
558
+ /* @__PURE__ */ a.jsx("p", { children: c.error || "Unable to initialize payment" }),
556
559
  /* @__PURE__ */ a.jsx("button", { onClick: m, className: "atlas-secondary-button", children: "Try Again" })
557
560
  ] }) }) : /* @__PURE__ */ a.jsxs("div", { className: `atlas-container ${r}`, children: [
558
561
  /* @__PURE__ */ a.jsxs("div", { className: "atlas-header", children: [
559
- /* @__PURE__ */ a.jsx("div", { className: "atlas-payment-type-badge", children: b(c) }),
562
+ /* @__PURE__ */ a.jsx("div", { className: "atlas-payment-type-badge", children: b(i) }),
560
563
  /* @__PURE__ */ a.jsxs("div", { className: "atlas-total", children: [
561
564
  "Pay ",
562
565
  /* @__PURE__ */ a.jsxs("span", { children: [
@@ -600,7 +603,7 @@ const oe = (o, f) => {
600
603
  /* @__PURE__ */ a.jsx("span", { className: "atlas-amount-token", children: "USDC" })
601
604
  ] })
602
605
  ] }) }),
603
- i.status === "popup_open" && /* @__PURE__ */ a.jsxs("div", { className: "atlas-popup-status", children: [
606
+ c.status === "popup_open" && /* @__PURE__ */ a.jsxs("div", { className: "atlas-popup-status", children: [
604
607
  /* @__PURE__ */ a.jsx("div", { className: "atlas-popup-icon", children: "🪟" }),
605
608
  /* @__PURE__ */ a.jsxs("div", { className: "atlas-popup-content", children: [
606
609
  /* @__PURE__ */ a.jsx("h4", { children: "Complete Payment in Popup" }),
@@ -631,18 +634,18 @@ const oe = (o, f) => {
631
634
  ] })
632
635
  ] }),
633
636
  /* @__PURE__ */ a.jsxs("div", { className: "atlas-form-actions", children: [
634
- i.status === "ready" && /* @__PURE__ */ a.jsx(
637
+ c.status === "ready" && /* @__PURE__ */ a.jsx(
635
638
  "button",
636
639
  {
637
640
  type: "submit",
638
641
  className: "atlas-pay-button",
639
- disabled: !v.isValid || parseFloat(d) <= 0 || g,
642
+ disabled: !v.isValid || parseFloat(d) <= 0 || N,
640
643
  children: t
641
644
  }
642
645
  ),
643
- i.status !== "ready" && i.status !== "idle" && i.status !== "popup_open" && /* @__PURE__ */ a.jsxs("div", { className: "atlas-status-wrapper", children: [
644
- /* @__PURE__ */ a.jsx(ie, { status: i }),
645
- i.status === "success" && /* @__PURE__ */ a.jsx(
646
+ c.status !== "ready" && c.status !== "idle" && c.status !== "popup_open" && /* @__PURE__ */ a.jsxs("div", { className: "atlas-status-wrapper", children: [
647
+ /* @__PURE__ */ a.jsx(ie, { status: c }),
648
+ c.status === "success" && /* @__PURE__ */ a.jsx(
646
649
  "button",
647
650
  {
648
651
  type: "button",
@@ -678,24 +681,24 @@ const oe = (o, f) => {
678
681
  authKey: o,
679
682
  merchantPaymentAddress: f,
680
683
  onSuccess: d,
681
- onError: c,
684
+ onError: i,
682
685
  className: l = "",
683
686
  buttonText: u = "Pay Now",
684
687
  amount: r = "0",
685
688
  paymentType: t = "one_time_payment",
686
- disabled: g = !1
689
+ disabled: N = !1
687
690
  // chainId = 8453,
688
691
  }) => {
689
- const [P, i] = D(!1), v = (n) => {
690
- d == null || d(n), setTimeout(() => i(!1), 2e3);
692
+ const [P, c] = D(!1), v = (n) => {
693
+ d == null || d(n), setTimeout(() => c(!1), 2e3);
691
694
  }, h = (n) => {
692
- c == null || c(n);
695
+ i == null || i(n);
693
696
  }, m = () => {
694
697
  if (!o) {
695
698
  alert("Payment configuration error: No auth key provided");
696
699
  return;
697
700
  }
698
- i(!0);
701
+ c(!0);
699
702
  };
700
703
  return /* @__PURE__ */ a.jsxs(a.Fragment, { children: [
701
704
  /* @__PURE__ */ a.jsx(
@@ -703,7 +706,7 @@ const oe = (o, f) => {
703
706
  {
704
707
  className: `atlas-payment-button ${l}`,
705
708
  onClick: m,
706
- disabled: g || !o,
709
+ disabled: N || !o,
707
710
  children: u
708
711
  }
709
712
  ),
@@ -711,7 +714,7 @@ const oe = (o, f) => {
711
714
  "div",
712
715
  {
713
716
  className: "atlas-modal-overlay",
714
- onClick: () => i(!1),
717
+ onClick: () => c(!1),
715
718
  children: /* @__PURE__ */ a.jsxs("div", { className: "atlas-modal", onClick: (n) => n.stopPropagation(), children: [
716
719
  /* @__PURE__ */ a.jsxs("div", { className: "atlas-modal-header", children: [
717
720
  /* @__PURE__ */ a.jsxs("div", { className: "atlas-modal-header2", children: [
@@ -722,7 +725,7 @@ const oe = (o, f) => {
722
725
  "button",
723
726
  {
724
727
  className: "atlas-modal-close",
725
- onClick: () => i(!1),
728
+ onClick: () => c(!1),
726
729
  children: "×"
727
730
  }
728
731
  )
@@ -737,7 +740,7 @@ const oe = (o, f) => {
737
740
  onSuccess: v,
738
741
  onError: h,
739
742
  buttonText: u,
740
- disabled: g
743
+ disabled: N
741
744
  }
742
745
  ) })
743
746
  ] })