@heliofi/deposit-react 0.2.1 → 0.2.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.
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
-
2
+
3
3
 
4
4
 
5
5
 
@@ -16,13 +16,13 @@ export declare const MoonpayCommerceDeposit: (props: MoonpayCommerceDepositReact
16
16
  themeMode?: DepositThemeMode;
17
17
  variant?: DepositVariant;
18
18
  loadingText?: React.ReactNode;
19
- trigger?: (props: {
20
- onClick: () => void;
21
- }) => React.ReactNode;
22
19
  debug?: boolean;
23
20
  }
24
21
 
25
22
  config: MoonpayCommerceDepositConfig;
23
+ trigger?: React.ComponentType<{
24
+ onClick: () => void;
25
+ }>;
26
26
  }
27
27
 
28
28
  export { }
@@ -1,56 +1,70 @@
1
- import { jsxs as g, jsx as f } from "react/jsx-runtime";
2
- import { useRef as y, useState as i, useEffect as E, useLayoutEffect as I } from "react";
3
- const C = "v1", R = () => {
1
+ import { jsxs as E, jsx as i, Fragment as y } from "react/jsx-runtime";
2
+ import { useRef as C, useState as u, useEffect as p, useLayoutEffect as I } from "react";
3
+ const R = "v1", b = () => {
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
- }, b = R(), l = "deposit-embed-script", M = `https://${b}/assets/index-${C}.js`, O = ({ children: t }) => /* @__PURE__ */ g("div", { children: [
9
+ }, M = b(), g = "deposit-embed-script", O = `https://${M}/assets/index-${R}.js`, _ = ({ children: e }) => /* @__PURE__ */ E("div", { children: [
10
10
  "Error loading Helio Deposit for React",
11
- t ? `: ${t}` : ""
12
- ] }), _ = (t = M) => {
13
- const e = document.createElement("script");
14
- return e.setAttribute("type", "module"), e.setAttribute("id", l), e.setAttribute("src", t), document.body.appendChild(e), e;
15
- }, h = (t) => {
16
- const e = y(null), [c, D] = i(!1), [o, v] = i(), [u, n] = i("");
17
- return E(() => D(!0), []), E(() => {
18
- let d = !1;
19
- if (o) return;
20
- const s = () => {
21
- if (d) return;
22
- const r = window.moonpayCommerceDeposit;
23
- if (!r) {
24
- n(
11
+ e ? `: ${e}` : ""
12
+ ] }), h = (e = O) => {
13
+ const t = document.createElement("script");
14
+ return t.setAttribute("type", "module"), t.setAttribute("id", g), t.setAttribute("src", e), document.body.appendChild(t), t;
15
+ }, T = (e) => {
16
+ const t = C(null), [d, D] = u(!1), [r, v] = u(), [m, s] = u("");
17
+ if (p(() => D(!0), []), p(() => {
18
+ let o = !1;
19
+ if (r) return;
20
+ const c = () => {
21
+ if (o) return;
22
+ const n = window.moonpayCommerceDeposit;
23
+ if (!n) {
24
+ s(
25
25
  "Unable to load Helio Deposit - missing init function on window.moonpayCommerceDeposit"
26
26
  );
27
27
  return;
28
28
  }
29
- v(() => r);
30
- }, m = (r) => {
31
- const a = () => n("Error loading script tag");
32
- return r.addEventListener("load", s), r.addEventListener("error", a), () => {
33
- d = !0, r.removeEventListener("load", s), r.removeEventListener("error", a);
29
+ v(() => n);
30
+ }, a = (n) => {
31
+ const l = () => s("Error loading script tag");
32
+ return n.addEventListener("load", c), n.addEventListener("error", l), () => {
33
+ o = !0, n.removeEventListener("load", c), n.removeEventListener("error", l);
34
34
  };
35
- }, p = document.querySelector(
36
- `script#${l}`
35
+ }, f = document.querySelector(
36
+ `script#${g}`
37
37
  );
38
- if (p) {
39
- window.moonpayCommerceDeposit ? s() : m(p);
38
+ if (f) {
39
+ window.moonpayCommerceDeposit ? c() : a(f);
40
40
  return;
41
41
  }
42
- const S = _();
43
- return m(S);
44
- }, [o]), I(() => {
45
- if (!(!o || !c)) {
46
- if (!e.current) {
47
- n("Missing element to mount Helio Deposit");
42
+ const S = h();
43
+ return a(S);
44
+ }, [r]), I(() => {
45
+ if (!(!r || !d)) {
46
+ if (!t.current) {
47
+ s("Missing element to mount Helio Deposit");
48
48
  return;
49
49
  }
50
- o(e.current, t.config);
50
+ e.trigger || r(t.current, e.config);
51
51
  }
52
- }, [o, c, t.config]), u ? /* @__PURE__ */ f(O, { children: u }) : o ? /* @__PURE__ */ f("div", { ref: e }) : null;
52
+ }, [r, d, e.config, e.trigger]), m) return /* @__PURE__ */ i(_, { children: m });
53
+ if (!r) return null;
54
+ if (e.trigger) {
55
+ const o = e.trigger;
56
+ return /* @__PURE__ */ E(y, { children: [
57
+ /* @__PURE__ */ i("div", { ref: t }),
58
+ /* @__PURE__ */ i(
59
+ o,
60
+ {
61
+ onClick: () => r(t.current, { ...e.config, display: "modal" })
62
+ }
63
+ )
64
+ ] });
65
+ }
66
+ return /* @__PURE__ */ i("div", { ref: t });
53
67
  };
54
68
  export {
55
- h as MoonpayCommerceDeposit
69
+ T as MoonpayCommerceDeposit
56
70
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@heliofi/deposit-react",
3
3
  "private": false,
4
- "version": "0.2.1",
4
+ "version": "0.2.2",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "dev": "vite",