@heliofi/deposit-react 0.4.1-alpha.1770389993 → 0.4.4

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.
@@ -54,9 +54,7 @@ export declare const MoonpayCommerceDeposit: (props: MoonpayCommerceDepositReact
54
54
  export declare const MoonpayCommerceDepositProvider: (props: PropsWithChildren) => JSX.Element;
55
55
 
56
56
  config: MoonpayCommerceDepositConfig;
57
- trigger?: React.ComponentType<{
58
- onClick: () => void;
59
- }>;
57
+ trigger?: HTMLElement;
60
58
  }
61
59
 
62
60
 
@@ -1,116 +1,126 @@
1
- import { jsxs as C, jsx as d, Fragment as D } from "react/jsx-runtime";
2
- import { useRef as y, useEffect as a, useState as l, useLayoutEffect as F } from "react";
3
- const g = "v1", k = () => {
1
+ import { jsxs as y, jsx as c, Fragment as b } from "react/jsx-runtime";
2
+ import { useRef as h, useEffect as a, useState as f, useLayoutEffect as k } from "react";
3
+ const P = "v1", T = () => {
4
4
  try {
5
5
  return process.env.VITE_PROD_HOSTNAME || "embed.deposits.hel.io";
6
6
  } catch {
7
7
  return "embed.deposits.hel.io";
8
8
  }
9
- }, P = k(), A = "deposit-embed-script", H = `https://${P}/assets/index-${g}.js`, L = ({ children: e }) => /* @__PURE__ */ C("div", { children: [
9
+ }, A = T(), H = "deposit-embed-script", L = `https://${A}/assets/index-${P}.js`, N = ({ children: e }) => /* @__PURE__ */ y("div", { children: [
10
10
  "Error loading Helio Deposit for React",
11
11
  e ? `: ${e}` : ""
12
12
  ] });
13
13
  process.env.VITE_EMBED_VERSION;
14
14
  process.env.VITE_PROD_HOSTNAME;
15
15
  process.env.VERCEL_ENV;
16
- const O = (e, r) => {
17
- const t = document.createElement("script");
18
- return t.setAttribute("type", "module"), t.setAttribute("id", r), t.setAttribute("src", e), document.body.appendChild(t), t;
19
- }, I = (e) => document.querySelector(
16
+ const I = (e, t) => {
17
+ const n = document.createElement("script");
18
+ return n.setAttribute("type", "module"), n.setAttribute("id", t), n.setAttribute("src", e), document.body.appendChild(n), n;
19
+ }, O = (e) => document.querySelector(
20
20
  `script#${e}`
21
- ), N = ({
21
+ ), V = ({
22
22
  scriptIdentifier: e,
23
- scriptSrc: r
23
+ scriptSrc: t
24
24
  }) => {
25
- const t = w(r, {
25
+ const n = R(t, {
26
26
  embedScriptSource: void 0
27
- }), o = y(!1);
27
+ }), r = h(!1);
28
28
  a(() => {
29
- o.current || (o.current = !0, !I(e) && O(t, e));
30
- }, [t, e]);
31
- }, w = (e, r) => r.embedScriptSource || e, V = ({
29
+ r.current || (r.current = !0, !O(e) && I(n, e));
30
+ }, [n, e]);
31
+ }, R = (e, t) => t.embedScriptSource || e, j = ({
32
32
  type: e,
33
- config: r,
34
- scriptIdentifier: t,
35
- scriptSrc: o,
36
- trigger: u
33
+ config: t,
34
+ scriptIdentifier: n,
35
+ scriptSrc: r,
36
+ trigger: l
37
37
  }) => {
38
- const p = y(null), [E, b] = l(!1);
39
- a(() => b(!0), []);
40
- const [i, M] = l(), [_, m] = l(""), S = w(o, r);
38
+ const i = h(null), [m, d] = f(!1);
39
+ a(() => d(!0), []);
40
+ const [s, M] = f(), [_, E] = f(""), S = R(r, t);
41
41
  return a(() => {
42
- let s = !1;
43
- if (i) return;
44
- const c = () => {
45
- if (s) return;
46
- let n;
47
- if (e === "paylink" ? n = window.helioCheckout : n = window.moonpayCommerceDeposit, !n) {
48
- m(
42
+ let u = !1;
43
+ if (s) return;
44
+ const p = () => {
45
+ if (u) return;
46
+ let o;
47
+ if (e === "paylink" ? o = window.helioCheckout : o = window.moonpayCommerceDeposit, !o) {
48
+ E(
49
49
  e === "paylink" ? "Unable to load MoonPay Commerce Checkout - missing init function on window.helioCheckout" : "Unable to load Helio Deposit - missing init function on window.moonpayCommerceDeposit"
50
50
  );
51
51
  return;
52
52
  }
53
- M(() => n);
54
- }, f = (n) => {
55
- const h = () => m("Error loading script tag");
56
- return n.addEventListener("load", c), n.addEventListener("error", h), () => {
57
- s = !0, n.removeEventListener("load", c), n.removeEventListener("error", h);
53
+ M(() => o);
54
+ }, v = (o) => {
55
+ const D = () => E("Error loading script tag");
56
+ return o.addEventListener("load", p), o.addEventListener("error", D), () => {
57
+ u = !0, o.removeEventListener("load", p), o.removeEventListener("error", D);
58
58
  };
59
- }, v = I(t);
60
- if (v) {
59
+ }, C = O(n);
60
+ if (C) {
61
61
  if (e === "paylink" && window.helioCheckout || e === "deposit" && window.moonpayCommerceDeposit) {
62
- c();
62
+ p();
63
63
  return;
64
64
  }
65
- return f(v);
65
+ return v(C);
66
66
  }
67
- const T = O(
67
+ const F = I(
68
68
  S,
69
- t
69
+ n
70
70
  );
71
- return f(T);
72
- }, [i, S, o, t, e]), F(() => {
73
- if (!(!i || !E)) {
74
- if (!p.current) {
75
- m(
71
+ return v(F);
72
+ }, [s, S, r, n, e]), k(() => {
73
+ if (!(!s || !m)) {
74
+ if (!i.current) {
75
+ E(
76
76
  e === "paylink" ? "Missing element to mount MoonPay Commerce Checkout" : "Missing element to mount Helio Deposit"
77
77
  );
78
78
  return;
79
79
  }
80
- if (!u)
80
+ if (!l)
81
81
  if (e === "paylink") {
82
- const s = r;
83
- i(p.current, s);
82
+ const u = t;
83
+ s(i.current, u);
84
84
  } else {
85
- const s = i, c = r;
86
- s(p.current, c);
85
+ const u = s, p = t;
86
+ u(i.current, p);
87
87
  }
88
88
  }
89
- }, [i, E, r, e, u]), { divRef: p, initFn: i, error: _, type: e };
90
- }, R = {
91
- scriptIdentifier: A,
92
- scriptSrc: H
93
- }, j = ({
89
+ }, [s, m, t, e, l]), { divRef: i, initFn: s, error: _, type: e };
90
+ }, w = {
91
+ scriptIdentifier: H,
92
+ scriptSrc: L
93
+ }, x = ({
94
94
  config: e,
95
- trigger: r
95
+ trigger: t
96
96
  }) => {
97
- const { divRef: t, initFn: o, error: u } = V({
97
+ const { divRef: n, initFn: r, error: l } = j({
98
98
  type: "deposit",
99
- trigger: r,
99
+ trigger: t,
100
100
  config: e,
101
- ...R
102
- });
103
- return u ? /* @__PURE__ */ d(L, { children: u }) : o ? r ? /* @__PURE__ */ C(D, { children: [
104
- /* @__PURE__ */ d("div", { ref: t }),
105
- /* @__PURE__ */ d(
106
- r,
101
+ ...w
102
+ }), i = h(null);
103
+ return a(() => {
104
+ const d = i.current;
105
+ if (!(!d || !t))
106
+ return d.appendChild(t), () => {
107
+ d.contains(t) && d.removeChild(t);
108
+ };
109
+ }, [t, !!r]), l ? /* @__PURE__ */ c(N, { children: l }) : r ? t ? /* @__PURE__ */ y(b, { children: [
110
+ /* @__PURE__ */ c("div", { ref: n }),
111
+ /* @__PURE__ */ c(
112
+ "button",
107
113
  {
108
- onClick: () => o(t.current, { ...e, display: "modal" })
114
+ onClick: () => r(n.current, { ...e, display: "modal" }),
115
+ className: "hel-bg-transparent hel-border-none hel-outline-none hel-p-0 hel-m-0",
116
+ id: "moonpay-commerce-deposit-trigger",
117
+ type: "button",
118
+ children: /* @__PURE__ */ c("span", { ref: i })
109
119
  }
110
120
  )
111
- ] }) : /* @__PURE__ */ d("div", { ref: t }) : null;
112
- }, $ = (e) => /* @__PURE__ */ d(j, { ...e }), B = (e) => (N(R), /* @__PURE__ */ d(D, { children: e.children }));
121
+ ] }) : /* @__PURE__ */ c("div", { ref: n }) : null;
122
+ }, U = (e) => /* @__PURE__ */ c(x, { ...e }), $ = (e) => (V(w), /* @__PURE__ */ c(b, { children: e.children }));
113
123
  export {
114
- $ as MoonpayCommerceDeposit,
115
- B as MoonpayCommerceDepositProvider
124
+ U as MoonpayCommerceDeposit,
125
+ $ as MoonpayCommerceDepositProvider
116
126
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@heliofi/deposit-react",
3
3
  "private": false,
4
- "version": "0.4.1-alpha.1770389993",
4
+ "version": "0.4.4",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "dev": "vite",