@zerohash-sdk/fund-withdrawals-react 0.5.1 → 0.5.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.
Files changed (2) hide show
  1. package/dist/index.js +137 -129
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,43 +1,6 @@
1
- import { jsxs as j, jsx as y } from "react/jsx-runtime";
2
- import U, { useEffect as B, useState as T, useCallback as A, useRef as M } from "react";
3
- const b = {
4
- evergreen: "#00381D",
5
- green: "#CCFFD0",
6
- offBlack: "#1C1B1C",
7
- grayLight: "#EBEBE9"
8
- }, D = ({ onRetry: e }) => j("div", { role: "alert", style: {
9
- display: "flex",
10
- flexDirection: "column",
11
- alignItems: "center",
12
- gap: "8px",
13
- maxWidth: "360px",
14
- margin: "0 auto",
15
- padding: "32px 24px",
16
- textAlign: "center",
17
- fontFamily: "inherit",
18
- color: b.offBlack,
19
- background: "#FFFFFF",
20
- border: `1px solid ${b.grayLight}`,
21
- borderRadius: "12px"
22
- }, children: [y("svg", { width: "32", height: "32", viewBox: "0 0 24 24", fill: "none", "aria-hidden": "true", children: y("path", { d: "M12 9v4m0 4h.01M10.29 3.86L1.82 18a2 2 0 001.71 3h16.94a2 2 0 001.71-3L13.71 3.86a2 2 0 00-3.42 0z", stroke: b.evergreen, strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }) }), y("p", { style: { margin: 0, fontSize: "16px", fontWeight: 600 }, children: "Something went wrong" }), y("p", { style: { margin: 0, fontSize: "14px", opacity: 0.75 }, children: "We couldn't load this content. Please check your internet connection and try again." }), y("button", { type: "button", onClick: e, style: {
23
- marginTop: "8px",
24
- padding: "8px 20px",
25
- fontSize: "14px",
26
- fontWeight: 600,
27
- fontFamily: "inherit",
28
- color: b.green,
29
- background: b.evergreen,
30
- border: "none",
31
- borderRadius: "8px",
32
- cursor: "pointer"
33
- }, children: "Try again" })] }), V = (e, t) => {
34
- B(() => {
35
- const o = e.current;
36
- if (o)
37
- for (const [r, n] of Object.entries(t))
38
- n !== void 0 && (o[r] = n);
39
- });
40
- }, J = {
1
+ import { jsxs as W, jsx as _ } from "react/jsx-runtime";
2
+ import j, { useEffect as B, useState as z, useCallback as D, useRef as M } from "react";
3
+ const $ = {
41
4
  dev: "https://grafana-faro-collector.dev.0hash.com/collect",
42
5
  cert: "https://grafana-faro-collector.cert.zerohash.com/collect",
43
6
  prod: "https://grafana-faro-collector.zerohash.com/collect",
@@ -45,55 +8,55 @@ const b = {
45
8
  "eu-prod": "https://grafana-faro-collector.zerohash.eu/collect",
46
9
  sandbox: "https://grafana-faro-collector.cert.zerohash.com/collect",
47
10
  production: "https://grafana-faro-collector.zerohash.com/collect"
48
- }, P = (e) => {
11
+ }, V = (e) => {
49
12
  if (!e || typeof e != "string")
50
13
  return null;
51
14
  const t = e.split(".");
52
15
  if (t.length < 2)
53
16
  return null;
54
17
  try {
55
- const o = t[1].replace(/-/g, "+").replace(/_/g, "/"), r = o + "===".slice(0, (4 - o.length % 4) % 4), n = typeof atob < "u" ? atob(r) : Buffer.from(r, "base64").toString("utf-8"), s = JSON.parse(n)?.payload?.region;
56
- if (typeof s != "string")
18
+ const o = t[1].replace(/-/g, "+").replace(/_/g, "/"), r = o + "===".slice(0, (4 - o.length % 4) % 4), a = typeof atob < "u" ? atob(r) : Buffer.from(r, "base64").toString("utf-8"), c = JSON.parse(a)?.payload?.region;
19
+ if (typeof c != "string")
57
20
  return null;
58
- const a = s.toLowerCase();
59
- return a === "us" || a === "eu" ? a : null;
21
+ const n = c.toLowerCase();
22
+ return n === "us" || n === "eu" ? n : null;
60
23
  } catch {
61
24
  return null;
62
25
  }
63
- }, I = (e, t) => P(t) !== "eu" ? e : e === "cert" ? "eu-cert" : e === "prod" ? "eu-prod" : e, $ = (e) => {
26
+ }, I = (e, t) => V(t) !== "eu" ? e : e === "cert" ? "eu-cert" : e === "prod" ? "eu-prod" : e, J = (e) => {
64
27
  if (!e || typeof e != "string")
65
28
  return {};
66
29
  const t = e.split(".");
67
30
  if (t.length < 2)
68
31
  return {};
69
32
  try {
70
- const o = t[1].replace(/-/g, "+").replace(/_/g, "/"), r = o + "===".slice(0, (4 - o.length % 4) % 4), n = typeof atob < "u" ? atob(r) : Buffer.from(r, "base64").toString("utf-8"), i = JSON.parse(n), s = i?.payload ?? {}, a = (c) => typeof c == "string" && c.length > 0 ? c : void 0;
33
+ const o = t[1].replace(/-/g, "+").replace(/_/g, "/"), r = o + "===".slice(0, (4 - o.length % 4) % 4), a = typeof atob < "u" ? atob(r) : Buffer.from(r, "base64").toString("utf-8"), i = JSON.parse(a), c = i?.payload ?? {}, n = (s) => typeof s == "string" && s.length > 0 ? s : void 0;
71
34
  return {
72
- participantCode: a(s.participant_code),
73
- platformName: a(s.platform_name),
74
- platformCode: a(i.platform_code),
75
- region: a(s.region)
35
+ participantCode: n(c.participant_code),
36
+ platformName: n(c.platform_name),
37
+ platformCode: n(i.platform_code),
38
+ region: n(c.region)
76
39
  };
77
40
  } catch {
78
41
  return {};
79
42
  }
80
- }, z = (e, t, o) => {
43
+ }, F = (e, t, o) => {
81
44
  const r = I(t, o);
82
45
  return e[r] ?? e[t] ?? e.prod;
83
- }, K = (e, t, o) => {
46
+ }, P = (e, t, o) => {
84
47
  const r = I(t, o);
85
48
  return e[r] ?? e[t];
86
- }, k = () => {
49
+ }, O = () => {
87
50
  }, H = () => {
88
51
  const e = new Uint8Array(8);
89
52
  return globalThis.crypto.getRandomValues(e), Array.from(e, (t) => t.toString(16).padStart(2, "0")).join("");
90
- }, G = (e, t) => {
91
- const o = H(), r = globalThis.__ZH_WEB_SDK_VERSION__, n = {};
92
- e.claims.participantCode && (n.participant_code = e.claims.participantCode), e.claims.platformName && (n.platform_name = e.claims.platformName), e.claims.platformCode && (n.platform_code = e.claims.platformCode), e.claims.region && (n.region = e.claims.region), r && (n.zh_web_sdk_version = r);
53
+ }, K = (e, t) => {
54
+ const o = H(), r = globalThis.__ZH_WEB_SDK_VERSION__, a = {};
55
+ e.claims.participantCode && (a.participant_code = e.claims.participantCode), e.claims.platformName && (a.platform_name = e.claims.platformName), e.claims.platformCode && (a.platform_code = e.claims.platformCode), e.claims.region && (a.region = e.claims.region), r && (a.zh_web_sdk_version = r);
93
56
  const i = {
94
57
  meta: {
95
58
  app: { name: e.appName, version: t ?? "unknown", environment: e.env },
96
- session: { id: o, attributes: n },
59
+ session: { id: o, attributes: a },
97
60
  browser: typeof navigator < "u" ? { userAgent: navigator.userAgent } : void 0,
98
61
  page: typeof window < "u" ? { url: window.location.origin } : void 0
99
62
  },
@@ -113,132 +76,177 @@ const b = {
113
76
  ]
114
77
  };
115
78
  return { sessionId: o, payload: i };
116
- }, Z = (e, t, o) => {
79
+ }, G = (e, t, o) => {
117
80
  if (!e || typeof fetch > "u")
118
81
  return;
119
- const { sessionId: r, payload: n } = G(t, o);
82
+ const { sessionId: r, payload: a } = K(t, o);
120
83
  try {
121
84
  fetch(e, {
122
85
  method: "POST",
123
86
  headers: { "Content-Type": "application/json", "x-faro-session-id": r },
124
- body: JSON.stringify(n),
87
+ body: JSON.stringify(a),
125
88
  keepalive: !0
126
89
  }).catch(() => {
127
90
  });
128
91
  } catch {
129
92
  }
130
- }, q = (e) => {
131
- const { webComponentTag: t, appName: o, appVersion: r, scriptUrls: n, fallbackScriptUrls: i, collectorUrls: s, env: a, jwt: c, timeoutMs: f = 15e3, onLoad: m, onError: g } = e;
93
+ }, Z = (e) => {
94
+ const { webComponentTag: t, appName: o, appVersion: r, scriptUrls: a, fallbackScriptUrls: i, collectorUrls: c, env: n, jwt: s, timeoutMs: m = 15e3, onLoad: g, onError: h } = e;
132
95
  if (typeof document > "u")
133
- return k;
134
- const d = `${t}-script-${a}`;
96
+ return O;
97
+ const d = `${t}-script-${n}`;
135
98
  if (customElements.get(t) || document.getElementById(d))
136
- return k;
137
- const _ = $(c), R = e.report ?? ((p) => Z(s && K(s, a, c), p, r));
138
- let u = !1, C = 0, x;
139
- const w = () => {
140
- x !== void 0 && clearTimeout(x);
141
- }, S = (p, h, l) => {
142
- if (u)
99
+ return O;
100
+ const S = J(s), v = e.report ?? ((p) => G(c && P(c, n, s), p, r));
101
+ let f = !1, x = 0, w;
102
+ const R = () => {
103
+ w !== void 0 && clearTimeout(w);
104
+ }, C = (p, y, l) => {
105
+ if (f)
143
106
  return;
144
- const W = Math.round(performance.now() - C), N = {
107
+ const U = Math.round(performance.now() - x), T = {
145
108
  webComponentTag: t,
146
109
  appName: o,
147
- env: a,
148
- scriptUrl: h,
110
+ env: n,
111
+ scriptUrl: y,
149
112
  reason: p,
150
113
  triedFallback: l,
151
- elapsedMs: W,
152
- claims: _
114
+ elapsedMs: U,
115
+ claims: S
153
116
  };
154
- R(N);
155
- const v = l ? void 0 : z(i ?? {}, a, c);
156
- if (v && v !== h) {
157
- O(v, !0);
117
+ v(T);
118
+ const k = l ? void 0 : F(i ?? {}, n, s);
119
+ if (k && k !== y) {
120
+ E(k, !0);
158
121
  return;
159
122
  }
160
- u = !0, w(), document.getElementById(d)?.remove(), g?.(N);
161
- }, O = (p, h) => {
162
- w(), C = performance.now();
123
+ f = !0, R(), document.getElementById(d)?.remove(), h?.(T);
124
+ }, E = (p, y) => {
125
+ R(), x = performance.now();
163
126
  const l = document.createElement("script");
164
127
  l.id = d, l.src = p, l.type = "module", l.async = !0, l.onload = () => {
165
128
  setTimeout(() => {
166
- u || (customElements.get(t) ? (u = !0, w(), m?.()) : S("not-defined", p, h));
129
+ f || (customElements.get(t) ? (f = !0, R(), g?.()) : C("not-defined", p, y));
167
130
  }, 0);
168
- }, l.onerror = () => S("network", p, h), x = setTimeout(() => S("timeout", p, h), f), document.getElementById(d)?.remove(), document.head.appendChild(l);
169
- }, E = z(n, a, c);
170
- return E ? (O(E, !1), () => {
171
- u = !0, w();
172
- }) : k;
131
+ }, l.onerror = () => C("network", p, y), w = setTimeout(() => C("timeout", p, y), m), document.getElementById(d)?.remove(), document.head.appendChild(l);
132
+ }, N = F(a, n, s);
133
+ return N ? (E(N, !1), () => {
134
+ f = !0, R();
135
+ }) : O;
136
+ }, u = {
137
+ local: "http://localhost:5173",
138
+ dev: "https://sdk-cdn.dev.0hash.com",
139
+ cert: "https://sdk-cdn.cert.zerohash.com",
140
+ prod: "https://sdk-cdn.zerohash.com",
141
+ "eu-cert": "https://sdk-cdn.cert.zerohash.eu",
142
+ "eu-prod": "https://sdk-cdn.zerohash.eu"
143
+ }, q = (e, t, o = {}) => {
144
+ const { eu: r = !1, legacyAliases: a = !1, local: i = u.local } = o, c = (s) => `${s}/${e}/${t}`, n = {
145
+ local: c(i),
146
+ dev: c(u.dev),
147
+ cert: c(u.cert),
148
+ prod: c(u.prod)
149
+ };
150
+ return a && (n.sandbox = c(u.cert), n.production = c(u.prod)), r && (n["eu-cert"] = c(u["eu-cert"]), n["eu-prod"] = c(u["eu-prod"])), n;
173
151
  };
174
- var F;
152
+ var L;
175
153
  (function(e) {
176
154
  e.NETWORK_ERROR = "network_error", e.AUTH_ERROR = "auth_error", e.NOT_FOUND_ERROR = "not_found_error", e.VALIDATION_ERROR = "validation_error", e.SERVER_ERROR = "server_error", e.CLIENT_ERROR = "client_error", e.UNKNOWN_ERROR = "unknown_error";
177
- })(F || (F = {}));
178
- const Q = (e) => {
179
- const { webComponentTag: t, appName: o, appVersion: r, scriptUrls: n, fallbackScriptUrls: i, collectorUrls: s, env: a, jwt: c, timeoutMs: f } = e, [m, g] = T(!1), [d, _] = T(0);
180
- B(() => (g(!1), q({
155
+ })(L || (L = {}));
156
+ const b = {
157
+ evergreen: "#00381D",
158
+ green: "#CCFFD0",
159
+ offBlack: "#1C1B1C",
160
+ grayLight: "#EBEBE9"
161
+ }, Q = ({ onRetry: e }) => W("div", { role: "alert", style: {
162
+ display: "flex",
163
+ flexDirection: "column",
164
+ alignItems: "center",
165
+ gap: "8px",
166
+ maxWidth: "360px",
167
+ margin: "0 auto",
168
+ padding: "32px 24px",
169
+ textAlign: "center",
170
+ fontFamily: "inherit",
171
+ color: b.offBlack,
172
+ background: "#FFFFFF",
173
+ border: `1px solid ${b.grayLight}`,
174
+ borderRadius: "12px"
175
+ }, children: [_("svg", { width: "32", height: "32", viewBox: "0 0 24 24", fill: "none", "aria-hidden": "true", children: _("path", { d: "M12 9v4m0 4h.01M10.29 3.86L1.82 18a2 2 0 001.71 3h16.94a2 2 0 001.71-3L13.71 3.86a2 2 0 00-3.42 0z", stroke: b.evergreen, strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }) }), _("p", { style: { margin: 0, fontSize: "16px", fontWeight: 600 }, children: "Something went wrong" }), _("p", { style: { margin: 0, fontSize: "14px", opacity: 0.75 }, children: "We couldn't load this content. Please check your internet connection and try again." }), _("button", { type: "button", onClick: e, style: {
176
+ marginTop: "8px",
177
+ padding: "8px 20px",
178
+ fontSize: "14px",
179
+ fontWeight: 600,
180
+ fontFamily: "inherit",
181
+ color: b.green,
182
+ background: b.evergreen,
183
+ border: "none",
184
+ borderRadius: "8px",
185
+ cursor: "pointer"
186
+ }, children: "Try again" })] }), X = (e, t) => {
187
+ B(() => {
188
+ const o = e.current;
189
+ if (o)
190
+ for (const [r, a] of Object.entries(t))
191
+ a !== void 0 && (o[r] = a);
192
+ });
193
+ }, Y = (e) => {
194
+ const { webComponentTag: t, appName: o, appVersion: r, scriptUrls: a, fallbackScriptUrls: i, collectorUrls: c, env: n, jwt: s, timeoutMs: m } = e, [g, h] = z(!1), [d, S] = z(0);
195
+ B(() => (h(!1), Z({
181
196
  webComponentTag: t,
182
197
  appName: o ?? t,
183
198
  appVersion: r,
184
- scriptUrls: n,
199
+ scriptUrls: a,
185
200
  fallbackScriptUrls: i,
186
- collectorUrls: s ?? J,
187
- env: a,
188
- jwt: c,
189
- timeoutMs: f,
190
- onError: () => g(!0)
201
+ collectorUrls: c ?? $,
202
+ env: n,
203
+ jwt: s,
204
+ timeoutMs: m,
205
+ onError: () => h(!0)
191
206
  })), [
192
207
  t,
193
208
  o,
194
209
  r,
195
- n,
196
- i,
197
- s,
198
210
  a,
211
+ i,
199
212
  c,
200
- f,
213
+ n,
214
+ s,
215
+ m,
201
216
  d
202
217
  ]);
203
- const R = A(() => _((u) => u + 1), []);
204
- return { loadFailed: m, retry: R };
205
- }, X = {
206
- local: "http://localhost:5173/fund-withdrawals-web/index.js",
207
- dev: "https://connect-sdk.dev.0hash.com/fund-withdrawals-web/index.js",
208
- cert: "https://sdk.sandbox.connect.xyz/fund-withdrawals-web/index.js",
209
- prod: "https://sdk.connect.xyz/fund-withdrawals-web/index.js",
210
- "eu-cert": "https://sdk-cdn.cert.zerohash.eu/fund-withdrawals-web/index.js",
211
- "eu-prod": "https://sdk-cdn.zerohash.eu/fund-withdrawals-web/index.js"
212
- }, L = "zerohash-fund-withdrawals", te = ({
218
+ const v = D(() => S((f) => f + 1), []);
219
+ return { loadFailed: g, retry: v };
220
+ }, ee = q("fund-withdrawals-web", "index.js", { eu: !0 }), A = "zerohash-fund-withdrawals", re = ({
213
221
  jwt: e,
214
222
  env: t = "prod",
215
223
  theme: o,
216
224
  isPayouts: r = !1,
217
- onCompleted: n,
225
+ onCompleted: a,
218
226
  onError: i,
219
- onClose: s,
220
- onLoaded: a,
221
- onEvent: c,
222
- ...f
227
+ onClose: c,
228
+ onLoaded: n,
229
+ onEvent: s,
230
+ ...m
223
231
  }) => {
224
- const m = M(null);
225
- V(m, { isPayouts: r, theme: o, onCompleted: n, onError: i, onClose: s, onLoaded: a, onEvent: c });
226
- const { loadFailed: g, retry: d } = Q({
227
- webComponentTag: L,
228
- scriptUrls: X,
232
+ const g = M(null);
233
+ X(g, { isPayouts: r, theme: o, onCompleted: a, onError: i, onClose: c, onLoaded: n, onEvent: s });
234
+ const { loadFailed: h, retry: d } = Y({
235
+ webComponentTag: A,
236
+ scriptUrls: ee,
229
237
  // fallbackScriptUrls: FALLBACK_SCRIPT_URLS, // enable once the host is confirmed (AUTH-3095)
230
238
  env: t,
231
239
  jwt: e
232
240
  });
233
- return g ? /* @__PURE__ */ y(D, { onRetry: d }) : U.createElement(L, {
234
- ref: m,
241
+ return h ? /* @__PURE__ */ _(Q, { onRetry: d }) : j.createElement(A, {
242
+ ref: g,
235
243
  jwt: e,
236
244
  env: t,
237
245
  theme: o,
238
246
  "is-payouts": r ? "true" : "false",
239
- ...f
247
+ ...m
240
248
  });
241
249
  };
242
250
  export {
243
- te as FundWithdrawals
251
+ re as FundWithdrawals
244
252
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zerohash-sdk/fund-withdrawals-react",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",