@zerohash-sdk/crypto-account-link-react 1.10.5 → 1.12.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.
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { jsxs as W, jsx as y } from "react/jsx-runtime";
2
- import D, { useEffect as I, useState as L, useCallback as j, useRef as M } from "react";
1
+ import { jsxs as W, jsx as d } from "react/jsx-runtime";
2
+ import M, { useEffect as B, useState as L, useCallback as j, useRef as D } from "react";
3
3
  const $ = {
4
4
  dev: "https://grafana-faro-collector.dev.0hash.com/collect",
5
5
  cert: "https://grafana-faro-collector.cert.zerohash.com/collect",
@@ -15,43 +15,43 @@ const $ = {
15
15
  if (t.length < 2)
16
16
  return null;
17
17
  try {
18
- const o = t[1].replace(/-/g, "+").replace(/_/g, "/"), r = o + "===".slice(0, (4 - o.length % 4) % 4), c = typeof atob < "u" ? atob(r) : Buffer.from(r, "base64").toString("utf-8"), a = JSON.parse(c)?.payload?.region;
19
- if (typeof a != "string")
18
+ const o = t[1].replace(/-/g, "+").replace(/_/g, "/"), r = o + "===".slice(0, (4 - o.length % 4) % 4), c = typeof atob < "u" ? atob(r) : Buffer.from(r, "base64").toString("utf-8"), n = JSON.parse(c)?.payload?.region;
19
+ if (typeof n != "string")
20
20
  return null;
21
- const n = a.toLowerCase();
22
- return n === "us" || n === "eu" ? n : null;
21
+ const a = n.toLowerCase();
22
+ return a === "us" || a === "eu" ? a : null;
23
23
  } catch {
24
24
  return null;
25
25
  }
26
- }, B = (e, t) => V(t) !== "eu" ? e : e === "cert" ? "eu-cert" : e === "prod" ? "eu-prod" : e, P = (e) => {
26
+ }, I = (e, t) => V(t) !== "eu" ? e : e === "cert" ? "eu-cert" : e === "prod" ? "eu-prod" : e, P = (e) => {
27
27
  if (!e || typeof e != "string")
28
28
  return {};
29
29
  const t = e.split(".");
30
30
  if (t.length < 2)
31
31
  return {};
32
32
  try {
33
- const o = t[1].replace(/-/g, "+").replace(/_/g, "/"), r = o + "===".slice(0, (4 - o.length % 4) % 4), c = typeof atob < "u" ? atob(r) : Buffer.from(r, "base64").toString("utf-8"), i = JSON.parse(c), a = i?.payload ?? {}, n = (s) => typeof s == "string" && s.length > 0 ? s : void 0;
33
+ const o = t[1].replace(/-/g, "+").replace(/_/g, "/"), r = o + "===".slice(0, (4 - o.length % 4) % 4), c = typeof atob < "u" ? atob(r) : Buffer.from(r, "base64").toString("utf-8"), i = JSON.parse(c), n = i?.payload ?? {}, a = (s) => typeof s == "string" && s.length > 0 ? s : void 0;
34
34
  return {
35
- participantCode: n(a.participant_code),
36
- platformName: n(a.platform_name),
37
- platformCode: n(i.platform_code),
38
- region: n(a.region)
35
+ participantCode: a(n.participant_code),
36
+ platformName: a(n.platform_name),
37
+ platformCode: a(i.platform_code),
38
+ region: a(n.region)
39
39
  };
40
40
  } catch {
41
41
  return {};
42
42
  }
43
43
  }, z = (e, t, o) => {
44
- const r = B(t, o);
44
+ const r = I(t, o);
45
45
  return e[r] ?? e[t] ?? e.prod;
46
- }, J = (e, t, o) => {
47
- const r = B(t, o);
46
+ }, H = (e, t, o) => {
47
+ const r = I(t, o);
48
48
  return e[r] ?? e[t];
49
- }, x = () => {
50
- }, H = () => {
49
+ }, O = () => {
50
+ }, J = () => {
51
51
  const e = new Uint8Array(8);
52
52
  return globalThis.crypto.getRandomValues(e), Array.from(e, (t) => t.toString(16).padStart(2, "0")).join("");
53
53
  }, G = (e, t) => {
54
- const o = H(), r = globalThis.__ZH_WEB_SDK_VERSION__, c = {};
54
+ const o = J(), r = globalThis.__ZH_WEB_SDK_VERSION__, c = {};
55
55
  e.claims.participantCode && (c.participant_code = e.claims.participantCode), e.claims.platformName && (c.platform_name = e.claims.platformName), e.claims.platformCode && (c.platform_code = e.claims.platformCode), e.claims.region && (c.region = e.claims.region), r && (c.zh_web_sdk_version = r);
56
56
  const i = {
57
57
  meta: {
@@ -91,49 +91,49 @@ const $ = {
91
91
  } catch {
92
92
  }
93
93
  }, Z = (e) => {
94
- const { webComponentTag: t, appName: o, appVersion: r, scriptUrls: c, fallbackScriptUrls: i, collectorUrls: a, env: n, jwt: s, timeoutMs: g = 15e3, onLoad: _, onError: f } = e;
94
+ const { webComponentTag: t, appName: o, appVersion: r, scriptUrls: c, fallbackScriptUrls: i, collectorUrls: n, env: a, jwt: s, timeoutMs: h = 15e3, onLoad: _, onError: m } = e;
95
95
  if (typeof document > "u")
96
- return x;
97
- const d = `${t}-script-${n}`;
98
- if (customElements.get(t) || document.getElementById(d))
99
- return x;
100
- const b = P(s), k = e.report ?? ((p) => K(a && J(a, n, s), p, r));
101
- let m = !1, N = 0, v;
102
- const S = () => {
96
+ return O;
97
+ const p = `${t}-script-${a}`;
98
+ if (customElements.get(t) || document.getElementById(p))
99
+ return O;
100
+ const R = P(s), S = e.report ?? ((u) => K(n && H(n, a, s), u, r));
101
+ let g = !1, w = 0, v;
102
+ const k = () => {
103
103
  v !== void 0 && clearTimeout(v);
104
- }, C = (p, h, l) => {
105
- if (m)
104
+ }, x = (u, y, l) => {
105
+ if (g)
106
106
  return;
107
- const U = Math.round(performance.now() - N), E = {
107
+ const U = Math.round(performance.now() - w), E = {
108
108
  webComponentTag: t,
109
109
  appName: o,
110
- env: n,
111
- scriptUrl: h,
112
- reason: p,
110
+ env: a,
111
+ scriptUrl: y,
112
+ reason: u,
113
113
  triedFallback: l,
114
114
  elapsedMs: U,
115
- claims: b
115
+ claims: R
116
116
  };
117
- k(E);
118
- const O = l ? void 0 : z(i ?? {}, n, s);
119
- if (O && O !== h) {
120
- T(O, !0);
117
+ S(E);
118
+ const C = l ? void 0 : z(i ?? {}, a, s);
119
+ if (C && C !== y) {
120
+ N(C, !0);
121
121
  return;
122
122
  }
123
- m = !0, S(), document.getElementById(d)?.remove(), f?.(E);
124
- }, T = (p, h) => {
125
- S(), N = performance.now();
123
+ g = !0, k(), document.getElementById(p)?.remove(), m?.(E);
124
+ }, N = (u, y) => {
125
+ k(), w = performance.now();
126
126
  const l = document.createElement("script");
127
- l.id = d, l.src = p, l.type = "module", l.async = !0, l.onload = () => {
127
+ l.id = p, l.src = u, l.type = "module", l.async = !0, l.onload = () => {
128
128
  setTimeout(() => {
129
- m || (customElements.get(t) ? (m = !0, S(), _?.()) : C("not-defined", p, h));
129
+ g || (customElements.get(t) ? (g = !0, k(), _?.()) : x("not-defined", u, y));
130
130
  }, 0);
131
- }, l.onerror = () => C("network", p, h), v = setTimeout(() => C("timeout", p, h), g), document.getElementById(d)?.remove(), document.head.appendChild(l);
132
- }, w = z(c, n, s);
133
- return w ? (T(w, !1), () => {
134
- m = !0, S();
135
- }) : x;
136
- }, u = {
131
+ }, l.onerror = () => x("network", u, y), v = setTimeout(() => x("timeout", u, y), h), document.getElementById(p)?.remove(), document.head.appendChild(l);
132
+ }, T = z(c, a, s);
133
+ return T ? (N(T, !1), () => {
134
+ g = !0, k();
135
+ }) : O;
136
+ }, f = {
137
137
  local: "http://localhost:5173",
138
138
  dev: "https://sdk-cdn.dev.0hash.com",
139
139
  cert: "https://sdk-cdn.cert.zerohash.com",
@@ -141,25 +141,26 @@ const $ = {
141
141
  "eu-cert": "https://sdk-cdn.cert.zerohash.eu",
142
142
  "eu-prod": "https://sdk-cdn.zerohash.eu"
143
143
  }, q = "https://sdk-cdn.gating.0hash.com", Q = (e, t, o = {}) => {
144
- const { eu: r = !1, legacyAliases: c = !1, local: i = u.local } = o, a = (s) => `${s}/${e}/${t}`, n = {
145
- local: a(i),
146
- dev: a(u.dev),
147
- gating: a(q),
148
- cert: a(u.cert),
149
- prod: a(u.prod)
144
+ const { eu: r = !1, legacyAliases: c = !1, local: i = f.local } = o, n = (s) => `${s}/${e}/${t}`, a = {
145
+ local: n(i),
146
+ dev: n(f.dev),
147
+ gating: n(q),
148
+ cert: n(f.cert),
149
+ prod: n(f.prod)
150
150
  };
151
- return c && (n.sandbox = a(u.cert), n.production = a(u.prod)), r && (n["eu-cert"] = a(u["eu-cert"]), n["eu-prod"] = a(u["eu-prod"])), n;
151
+ return c && (a.sandbox = n(f.cert), a.production = n(f.prod)), r && (a["eu-cert"] = n(f["eu-cert"]), a["eu-prod"] = n(f["eu-prod"])), a;
152
152
  };
153
153
  var F;
154
154
  (function(e) {
155
155
  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";
156
156
  })(F || (F = {}));
157
- const R = {
157
+ const b = {
158
158
  evergreen: "#00381D",
159
159
  green: "#CCFFD0",
160
160
  offBlack: "#1C1B1C",
161
161
  grayLight: "#EBEBE9"
162
- }, X = ({ onRetry: e }) => W("div", { role: "alert", style: {
162
+ }, X = ({ onRetry: e, onClose: t }) => W("div", { role: "alert", style: {
163
+ position: "relative",
163
164
  display: "flex",
164
165
  flexDirection: "column",
165
166
  alignItems: "center",
@@ -169,55 +170,66 @@ const R = {
169
170
  padding: "32px 24px",
170
171
  textAlign: "center",
171
172
  fontFamily: "inherit",
172
- color: R.offBlack,
173
+ color: b.offBlack,
173
174
  background: "#FFFFFF",
174
- border: `1px solid ${R.grayLight}`,
175
+ border: `1px solid ${b.grayLight}`,
175
176
  borderRadius: "12px"
176
- }, 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: R.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: {
177
+ }, children: [t && d("button", { type: "button", onClick: t, "aria-label": "Close", style: {
178
+ position: "absolute",
179
+ top: "12px",
180
+ right: "12px",
181
+ display: "flex",
182
+ padding: "4px",
183
+ color: b.offBlack,
184
+ background: "none",
185
+ border: "none",
186
+ cursor: "pointer",
187
+ lineHeight: 0
188
+ }, children: d("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", "aria-hidden": "true", children: d("path", { d: "M18 6L6 18M6 6l12 12", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }) }) }), d("svg", { width: "32", height: "32", viewBox: "0 0 24 24", fill: "none", "aria-hidden": "true", children: d("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" }) }), d("p", { style: { margin: 0, fontSize: "16px", fontWeight: 600 }, children: "Something went wrong" }), d("p", { style: { margin: 0, fontSize: "14px", opacity: 0.75 }, children: "We couldn't load this content. Please check your internet connection and try again." }), d("button", { type: "button", onClick: e, style: {
177
189
  marginTop: "8px",
178
190
  padding: "8px 20px",
179
191
  fontSize: "14px",
180
192
  fontWeight: 600,
181
193
  fontFamily: "inherit",
182
- color: R.green,
183
- background: R.evergreen,
194
+ color: b.green,
195
+ background: b.evergreen,
184
196
  border: "none",
185
197
  borderRadius: "8px",
186
198
  cursor: "pointer"
187
199
  }, children: "Try again" })] }), Y = (e, t) => {
188
- I(() => {
200
+ B(() => {
189
201
  const o = e.current;
190
202
  if (o)
191
203
  for (const [r, c] of Object.entries(t))
192
204
  c !== void 0 && (o[r] = c);
193
205
  });
194
206
  }, ee = (e) => {
195
- const { webComponentTag: t, appName: o, appVersion: r, scriptUrls: c, fallbackScriptUrls: i, collectorUrls: a, env: n, jwt: s, timeoutMs: g } = e, [_, f] = L(!1), [d, b] = L(0);
196
- I(() => (f(!1), Z({
207
+ const { webComponentTag: t, appName: o, appVersion: r, scriptUrls: c, fallbackScriptUrls: i, collectorUrls: n, env: a, jwt: s, timeoutMs: h } = e, [_, m] = L(!1), [p, R] = L(0);
208
+ B(() => (m(!1), Z({
197
209
  webComponentTag: t,
198
210
  appName: o ?? t,
199
211
  appVersion: r,
200
212
  scriptUrls: c,
201
213
  fallbackScriptUrls: i,
202
- collectorUrls: a ?? $,
203
- env: n,
214
+ collectorUrls: n ?? $,
215
+ env: a,
204
216
  jwt: s,
205
- timeoutMs: g,
206
- onError: () => f(!0)
217
+ timeoutMs: h,
218
+ onError: () => m(!0)
207
219
  })), [
208
220
  t,
209
221
  o,
210
222
  r,
211
223
  c,
212
224
  i,
213
- a,
214
225
  n,
226
+ a,
215
227
  s,
216
- g,
217
- d
228
+ h,
229
+ p
218
230
  ]);
219
- const k = j(() => b((m) => m + 1), []);
220
- return { loadFailed: _, retry: k };
231
+ const S = j(() => R((g) => g + 1), []);
232
+ return { loadFailed: _, retry: S };
221
233
  }, te = Q("crypto-account-link-web", "index.js", { eu: !0 }), A = "zerohash-crypto-account-link", ne = ({
222
234
  jwt: e,
223
235
  env: t = "prod",
@@ -225,22 +237,28 @@ const R = {
225
237
  isPayouts: r = !1,
226
238
  onCompleted: c,
227
239
  onError: i,
228
- onClose: a,
229
- onLoaded: n,
240
+ onClose: n,
241
+ onLoaded: a,
230
242
  onExternalAccountCreated: s,
231
- onEvent: g,
243
+ onEvent: h,
232
244
  ..._
233
245
  }) => {
234
- const f = M(null);
235
- Y(f, { theme: o, onCompleted: c, onError: i, onClose: a, onLoaded: n, onExternalAccountCreated: s, onEvent: g });
236
- const { loadFailed: d, retry: b } = ee({
246
+ const m = D(null);
247
+ Y(m, { theme: o, onCompleted: c, onError: i, onClose: n, onLoaded: a, onExternalAccountCreated: s, onEvent: h });
248
+ const { loadFailed: p, retry: R } = ee({
237
249
  webComponentTag: A,
238
250
  scriptUrls: te,
239
251
  env: t,
240
252
  jwt: e
241
253
  });
242
- return d ? /* @__PURE__ */ y(X, { onRetry: b }) : D.createElement(A, {
243
- ref: f,
254
+ return p ? /* @__PURE__ */ d(
255
+ X,
256
+ {
257
+ onRetry: R,
258
+ onClose: n
259
+ }
260
+ ) : M.createElement(A, {
261
+ ref: m,
244
262
  jwt: e,
245
263
  env: t,
246
264
  theme: o,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zerohash-sdk/crypto-account-link-react",
3
- "version": "1.10.5",
3
+ "version": "1.12.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -297,7 +297,12 @@ export const CryptoAccountLink: React.FC<CryptoAccountLinkProps> = ({
297
297
  });
298
298
 
299
299
  if (loadFailed) {
300
- return <ScriptLoadFallback onRetry={retry} />;
300
+ return (
301
+ <ScriptLoadFallback
302
+ onRetry={retry}
303
+ onClose={onClose}
304
+ />
305
+ );
301
306
  }
302
307
 
303
308
  return React.createElement(WEB_COMPONENT_TAG, {