@heliofi/deposit-react 0.3.0 → 0.4.0-alpha.0

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