@heliofi/checkout-react 4.0.2 → 4.0.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.
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Helio Checkout React
1
+ # MoonPay Commerce Checkout React
2
2
 
3
3
  - Documentation please visit https://docs.hel.io/docs/checkout-widget
4
4
  - Demo: https://demo.hel.io
@@ -1,14 +1,13 @@
1
1
  import { BlockchainSymbol } from '@heliofi/common';
2
- import { JSX as JSX_2 } from 'react/jsx-runtime';
3
2
 
4
3
  mainButtonTitle?: string;
5
4
  payButtonTitle?: string;
6
5
  }
7
6
 
8
-
7
+
9
8
 
10
9
 
11
- export declare const HelioCheckout: (props: HelioCheckoutReactProps) => JSX_2.Element;
10
+ export declare const HelioCheckout: (props: HelioCheckoutReactProps) => JSX.Element;
12
11
 
13
12
  config: HelioEmbedConfig;
14
13
  }
@@ -22,6 +21,7 @@ export declare const HelioCheckout: (props: HelioCheckoutReactProps) => JSX_2.El
22
21
  primaryPaymentMethod?: PrimaryPaymentMethod;
23
22
  theme?: HelioEmbedTheme;
24
23
  stretchFullWidth?: boolean;
24
+ /** deprecated - paystream is no longer supported */
25
25
  paymentType?: EmbedPaymentType;
26
26
  platform?: WidgetPlatform;
27
27
  display?: DisplayType;
@@ -1,10 +1,10 @@
1
- import { jsxs as k, jsx as n } from "react/jsx-runtime";
2
- import { Component as b, useRef as g, useState as c, useEffect as E, useLayoutEffect as I } from "react";
3
- const m = ({ children: e }) => /* @__PURE__ */ k("div", { children: [
4
- "Error loading Helio Checkout for React",
1
+ import { jsxs as b, jsx as c } from "react/jsx-runtime";
2
+ import { Component as g, useRef as O, useState as m, useEffect as v, useLayoutEffect as _ } from "react";
3
+ const S = ({ children: e }) => /* @__PURE__ */ b("div", { children: [
4
+ "Error loading MoonPay Commerce Checkout for React",
5
5
  e ? `: ${e}` : ""
6
6
  ] });
7
- class L extends b {
7
+ class D extends g {
8
8
  constructor(t) {
9
9
  super(t), this.state = { hasError: !1 };
10
10
  }
@@ -12,51 +12,85 @@ class L extends b {
12
12
  return { hasError: !0 };
13
13
  }
14
14
  render() {
15
- return this.state.hasError ? /* @__PURE__ */ n(m, {}) : this.props.children;
15
+ return this.state.hasError ? /* @__PURE__ */ c(S, {}) : this.props.children;
16
16
  }
17
17
  }
18
- const w = "https://embed.hel.io/assets/index-v1.js", p = "helio-checkout-react-v1", x = (e = w) => {
19
- const t = document.createElement("script");
20
- return t.setAttribute("type", "module"), t.setAttribute("id", p), t.setAttribute("src", e), document.body.appendChild(t), t;
21
- }, F = ({ config: e }) => {
22
- const t = g(null), [u, C] = c(!1), [o, S] = c(), [d, s] = c("");
23
- return E(() => C(!0), []), E(() => {
24
- let l = !1;
18
+ process.env.VITE_EMBED_VERSION;
19
+ process.env.VITE_PROD_HOSTNAME;
20
+ process.env.VERCEL_ENV;
21
+ const F = (e, t) => {
22
+ const r = document.createElement("script");
23
+ return r.setAttribute("type", "module"), r.setAttribute("id", t), r.setAttribute("src", e), document.body.appendChild(r), r;
24
+ }, M = (e) => document.querySelector(
25
+ `script#${e}`
26
+ ), R = (e, t) => t.embedScriptSource || e, L = ({
27
+ type: e,
28
+ config: t,
29
+ scriptIdentifier: r,
30
+ scriptSrc: u,
31
+ trigger: l
32
+ }) => {
33
+ const d = O(null), [p, y] = m(!1);
34
+ v(() => y(!0), []);
35
+ const [o, k] = m(), [w, a] = m(""), E = R(u, t);
36
+ return v(() => {
37
+ let i = !1;
25
38
  if (o) return;
26
- const i = () => {
27
- if (l) return;
28
- const r = window.helioCheckout;
29
- if (!r) {
30
- s(
31
- "Unable to load helio checkout - missing init function on window.helioCheckout"
39
+ const s = () => {
40
+ if (i) return;
41
+ let n;
42
+ if (e === "paylink" ? n = window.helioCheckout : n = window.moonpayCommerceDeposit, !n) {
43
+ a(
44
+ 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"
32
45
  );
33
46
  return;
34
47
  }
35
- S(() => r);
36
- }, a = (r) => {
37
- const f = () => s("Error loading script tag");
38
- return r.addEventListener("load", i), r.addEventListener("error", f), () => {
39
- l = !0, r.removeEventListener("load", i), r.removeEventListener("error", f);
48
+ k(() => n);
49
+ }, f = (n) => {
50
+ const C = () => a("Error loading script tag");
51
+ return n.addEventListener("load", s), n.addEventListener("error", C), () => {
52
+ i = !0, n.removeEventListener("load", s), n.removeEventListener("error", C);
40
53
  };
41
- }, h = document.querySelector(
42
- `script#${p}`
43
- );
54
+ }, h = M(r);
44
55
  if (h) {
45
- window.helioCheckout ? i() : a(h);
46
- return;
56
+ if (e === "paylink" && window.helioCheckout || e === "deposit" && window.moonpayCommerceDeposit) {
57
+ s();
58
+ return;
59
+ }
60
+ return f(h);
47
61
  }
48
- const v = x(e.embedScriptSource);
49
- return a(v);
50
- }, [o, e.embedScriptSource]), I(() => {
51
- if (!(!o || !u)) {
52
- if (!t.current) {
53
- s("Missing element to mount Helio checkout");
62
+ const I = F(
63
+ E,
64
+ r
65
+ );
66
+ return f(I);
67
+ }, [o, E, u, r, e]), _(() => {
68
+ if (!(!o || !p)) {
69
+ if (!d.current) {
70
+ a(
71
+ e === "paylink" ? "Missing element to mount MoonPay Commerce Checkout" : "Missing element to mount Helio Deposit"
72
+ );
54
73
  return;
55
74
  }
56
- o(t.current, e);
75
+ if (!l)
76
+ if (e === "paylink") {
77
+ const i = t;
78
+ o(d.current, i);
79
+ } else {
80
+ const i = o, s = t;
81
+ i(d.current, s);
82
+ }
57
83
  }
58
- }, [o, u, e]), d ? /* @__PURE__ */ n(m, { children: d }) : o ? /* @__PURE__ */ n("div", { ref: t }) : null;
59
- }, R = (e) => /* @__PURE__ */ n(L, { children: /* @__PURE__ */ n(F, { config: e.config }) }), j = (e) => /* @__PURE__ */ n(R, { config: e.config });
84
+ }, [o, p, t, e, l]), { divRef: d, initFn: o, error: w, type: e };
85
+ }, H = "https://embed.hel.io/assets/index-v1.js", T = "helio-checkout-react-v1", x = ({ config: e }) => {
86
+ const { divRef: t, initFn: r, error: u } = L({
87
+ type: "paylink",
88
+ config: e,
89
+ scriptIdentifier: T,
90
+ scriptSrc: H
91
+ });
92
+ return u ? /* @__PURE__ */ c(S, { children: u }) : r ? /* @__PURE__ */ c("div", { ref: t }) : null;
93
+ }, A = (e) => /* @__PURE__ */ c(D, { children: /* @__PURE__ */ c(x, { config: e.config }) }), P = (e) => /* @__PURE__ */ c(A, { config: e.config });
60
94
  export {
61
- j as HelioCheckout
95
+ P as HelioCheckout
62
96
  };
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@heliofi/checkout-react",
3
3
  "private": false,
4
- "version": "4.0.2",
4
+ "version": "4.0.4",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "dev": "vite",
8
- "build": "vite build",
8
+ "build": "tsc && vite build",
9
9
  "build:vercel": "tsc && vite build --config vite-vercel.config.ts",
10
10
  "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
11
11
  "lint:strict": "yarn lint",
12
- "lint:fix": "yarn lint --fix",
12
+ "lint:fix": "yarn lint --fix && yarn format",
13
13
  "format": "prettier -w .",
14
14
  "format:check": "prettier -c .",
15
15
  "preview": "vite preview",
@@ -36,21 +36,21 @@
36
36
  "react-dom": ">=18.2.0 <20"
37
37
  },
38
38
  "devDependencies": {
39
- "@testing-library/dom": "^9.3.3",
39
+ "@testing-library/dom": "9.3.3",
40
40
  "@testing-library/jest-dom": "5.16.5",
41
- "@testing-library/react": "^14.0.0",
42
- "@types/react": ">=18.2.0 <20",
43
- "@types/react-dom": ">=18.2.0 <20",
44
- "@typescript-eslint/eslint-plugin": "^6.0.0",
45
- "@typescript-eslint/parser": "^6.0.0",
46
- "@vitejs/plugin-react": "^4.3.2",
41
+ "@testing-library/react": "14.0.0",
42
+ "@types/react": "18.2.0",
43
+ "@types/react-dom": "18.2.0",
44
+ "@typescript-eslint/eslint-plugin": "6.7.4",
45
+ "@typescript-eslint/parser": "6.7.4",
46
+ "@vitejs/plugin-react": "4.3.2",
47
47
  "eslint": "8.45.0",
48
- "eslint-plugin-react": "^7.33.2",
49
- "eslint-plugin-react-hooks": "^4.6.0",
50
- "jsdom": "^23.0.1",
48
+ "eslint-plugin-react": "7.37.5",
49
+ "eslint-plugin-react-hooks": "4.6.0",
50
+ "jsdom": "23.0.1",
51
51
  "typescript": "5.1.6",
52
52
  "vite": "5.4.8",
53
- "vite-plugin-dts": "^3.7.1",
53
+ "vite-plugin-dts": "3.7.1",
54
54
  "vitest": "3.2.4"
55
55
  }
56
56
  }