@zerohash-sdk/fund-withdrawals-react 0.3.1 → 0.4.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 +217 -40
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,67 +1,244 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
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 = {
|
|
41
|
+
dev: "https://grafana-faro-collector.dev.0hash.com/collect",
|
|
42
|
+
cert: "https://grafana-faro-collector.cert.zerohash.com/collect",
|
|
43
|
+
prod: "https://grafana-faro-collector.zerohash.com/collect",
|
|
44
|
+
"eu-cert": "https://grafana-faro-collector.cert.zerohash.eu/collect",
|
|
45
|
+
"eu-prod": "https://grafana-faro-collector.zerohash.eu/collect",
|
|
46
|
+
sandbox: "https://grafana-faro-collector.cert.zerohash.com/collect",
|
|
47
|
+
production: "https://grafana-faro-collector.zerohash.com/collect"
|
|
48
|
+
}, P = (e) => {
|
|
3
49
|
if (!e || typeof e != "string")
|
|
4
50
|
return null;
|
|
5
51
|
const t = e.split(".");
|
|
6
52
|
if (t.length < 2)
|
|
7
53
|
return null;
|
|
8
54
|
try {
|
|
9
|
-
const
|
|
10
|
-
if (typeof
|
|
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")
|
|
11
57
|
return null;
|
|
12
|
-
const
|
|
13
|
-
return
|
|
58
|
+
const a = s.toLowerCase();
|
|
59
|
+
return a === "us" || a === "eu" ? a : null;
|
|
14
60
|
} catch {
|
|
15
61
|
return null;
|
|
16
62
|
}
|
|
17
|
-
},
|
|
18
|
-
|
|
63
|
+
}, I = (e, t) => P(t) !== "eu" ? e : e === "cert" ? "eu-cert" : e === "prod" ? "eu-prod" : e, $ = (e) => {
|
|
64
|
+
if (!e || typeof e != "string")
|
|
65
|
+
return {};
|
|
66
|
+
const t = e.split(".");
|
|
67
|
+
if (t.length < 2)
|
|
68
|
+
return {};
|
|
69
|
+
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;
|
|
71
|
+
return {
|
|
72
|
+
participantCode: a(s.participant_code),
|
|
73
|
+
platformName: a(s.platform_name),
|
|
74
|
+
platformCode: a(i.platform_code),
|
|
75
|
+
region: a(s.region)
|
|
76
|
+
};
|
|
77
|
+
} catch {
|
|
78
|
+
return {};
|
|
79
|
+
}
|
|
80
|
+
}, z = (e, t, o) => {
|
|
81
|
+
const r = I(t, o);
|
|
82
|
+
return e[r] ?? e[t] ?? e.prod;
|
|
83
|
+
}, K = (e, t, o) => {
|
|
84
|
+
const r = I(t, o);
|
|
85
|
+
return e[r] ?? e[t];
|
|
86
|
+
}, k = () => {
|
|
87
|
+
}, H = () => {
|
|
88
|
+
const e = new Uint8Array(8);
|
|
89
|
+
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);
|
|
93
|
+
const i = {
|
|
94
|
+
meta: {
|
|
95
|
+
app: { name: e.appName, version: t ?? "unknown", environment: e.env },
|
|
96
|
+
session: { id: o, attributes: n },
|
|
97
|
+
browser: typeof navigator < "u" ? { userAgent: navigator.userAgent } : void 0,
|
|
98
|
+
page: typeof window < "u" ? { url: window.location.origin } : void 0
|
|
99
|
+
},
|
|
100
|
+
logs: [
|
|
101
|
+
{
|
|
102
|
+
message: `Failed to load the script for ${e.webComponentTag} from ${e.env} environment.`,
|
|
103
|
+
level: "error",
|
|
104
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
105
|
+
context: {
|
|
106
|
+
web_component: e.webComponentTag,
|
|
107
|
+
script_url: e.scriptUrl,
|
|
108
|
+
reason: e.reason,
|
|
109
|
+
tried_fallback: String(e.triedFallback),
|
|
110
|
+
elapsed_ms: String(e.elapsedMs)
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
]
|
|
114
|
+
};
|
|
115
|
+
return { sessionId: o, payload: i };
|
|
116
|
+
}, Z = (e, t, o) => {
|
|
117
|
+
if (!e || typeof fetch > "u")
|
|
118
|
+
return;
|
|
119
|
+
const { sessionId: r, payload: n } = G(t, o);
|
|
120
|
+
try {
|
|
121
|
+
fetch(e, {
|
|
122
|
+
method: "POST",
|
|
123
|
+
headers: { "Content-Type": "application/json", "x-faro-session-id": r },
|
|
124
|
+
body: JSON.stringify(n),
|
|
125
|
+
keepalive: !0
|
|
126
|
+
}).catch(() => {
|
|
127
|
+
});
|
|
128
|
+
} catch {
|
|
129
|
+
}
|
|
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;
|
|
132
|
+
if (typeof document > "u")
|
|
133
|
+
return k;
|
|
134
|
+
const d = `${t}-script-${a}`;
|
|
135
|
+
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)
|
|
143
|
+
return;
|
|
144
|
+
const W = Math.round(performance.now() - C), N = {
|
|
145
|
+
webComponentTag: t,
|
|
146
|
+
appName: o,
|
|
147
|
+
env: a,
|
|
148
|
+
scriptUrl: h,
|
|
149
|
+
reason: p,
|
|
150
|
+
triedFallback: l,
|
|
151
|
+
elapsedMs: W,
|
|
152
|
+
claims: _
|
|
153
|
+
};
|
|
154
|
+
R(N);
|
|
155
|
+
const v = l ? void 0 : z(i ?? {}, a, c);
|
|
156
|
+
if (v && v !== h) {
|
|
157
|
+
O(v, !0);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
u = !0, w(), document.getElementById(d)?.remove(), g?.(N);
|
|
161
|
+
}, O = (p, h) => {
|
|
162
|
+
w(), C = performance.now();
|
|
163
|
+
const l = document.createElement("script");
|
|
164
|
+
l.id = d, l.src = p, l.type = "module", l.async = !0, l.onload = () => {
|
|
165
|
+
setTimeout(() => {
|
|
166
|
+
u || (customElements.get(t) ? (u = !0, w(), m?.()) : S("not-defined", p, h));
|
|
167
|
+
}, 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;
|
|
173
|
+
};
|
|
174
|
+
var F;
|
|
19
175
|
(function(e) {
|
|
20
176
|
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";
|
|
21
|
-
})(
|
|
22
|
-
const
|
|
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({
|
|
181
|
+
webComponentTag: t,
|
|
182
|
+
appName: o ?? t,
|
|
183
|
+
appVersion: r,
|
|
184
|
+
scriptUrls: n,
|
|
185
|
+
fallbackScriptUrls: i,
|
|
186
|
+
collectorUrls: s ?? J,
|
|
187
|
+
env: a,
|
|
188
|
+
jwt: c,
|
|
189
|
+
timeoutMs: f,
|
|
190
|
+
onError: () => g(!0)
|
|
191
|
+
})), [
|
|
192
|
+
t,
|
|
193
|
+
o,
|
|
194
|
+
r,
|
|
195
|
+
n,
|
|
196
|
+
i,
|
|
197
|
+
s,
|
|
198
|
+
a,
|
|
199
|
+
c,
|
|
200
|
+
f,
|
|
201
|
+
d
|
|
202
|
+
]);
|
|
203
|
+
const R = A(() => _((u) => u + 1), []);
|
|
204
|
+
return { loadFailed: m, retry: R };
|
|
205
|
+
}, X = {
|
|
23
206
|
local: "http://localhost:5173/fund-withdrawals-web/index.js",
|
|
24
207
|
dev: "https://connect-sdk.dev.0hash.com/fund-withdrawals-web/index.js",
|
|
25
208
|
cert: "https://sdk.sandbox.connect.xyz/fund-withdrawals-web/index.js",
|
|
26
209
|
prod: "https://sdk.connect.xyz/fund-withdrawals-web/index.js",
|
|
27
210
|
"eu-cert": "https://sdk-cdn.cert.zerohash.eu/fund-withdrawals-web/index.js",
|
|
28
211
|
"eu-prod": "https://sdk-cdn.zerohash.eu/fund-withdrawals-web/index.js"
|
|
29
|
-
},
|
|
30
|
-
const r = E(e, t);
|
|
31
|
-
return l[r] ?? l[e] ?? l.prod;
|
|
32
|
-
}, x = ({
|
|
212
|
+
}, L = "zerohash-fund-withdrawals", te = ({
|
|
33
213
|
jwt: e,
|
|
34
214
|
env: t = "prod",
|
|
35
|
-
theme:
|
|
36
|
-
isPayouts:
|
|
37
|
-
onCompleted:
|
|
38
|
-
onError:
|
|
39
|
-
onClose:
|
|
40
|
-
onLoaded:
|
|
41
|
-
onEvent:
|
|
42
|
-
...
|
|
215
|
+
theme: o,
|
|
216
|
+
isPayouts: r = !1,
|
|
217
|
+
onCompleted: n,
|
|
218
|
+
onError: i,
|
|
219
|
+
onClose: s,
|
|
220
|
+
onLoaded: a,
|
|
221
|
+
onEvent: c,
|
|
222
|
+
...f
|
|
43
223
|
}) => {
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}, document.head.appendChild(d);
|
|
56
|
-
}, [t, e]), g.createElement(w, {
|
|
57
|
-
ref: f,
|
|
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,
|
|
229
|
+
// fallbackScriptUrls: FALLBACK_SCRIPT_URLS, // enable once the host is confirmed (AUTH-3095)
|
|
230
|
+
env: t,
|
|
231
|
+
jwt: e
|
|
232
|
+
});
|
|
233
|
+
return g ? /* @__PURE__ */ y(D, { onRetry: d }) : U.createElement(L, {
|
|
234
|
+
ref: m,
|
|
58
235
|
jwt: e,
|
|
59
236
|
env: t,
|
|
60
|
-
theme:
|
|
61
|
-
"is-payouts":
|
|
62
|
-
...
|
|
237
|
+
theme: o,
|
|
238
|
+
"is-payouts": r ? "true" : "false",
|
|
239
|
+
...f
|
|
63
240
|
});
|
|
64
241
|
};
|
|
65
242
|
export {
|
|
66
|
-
|
|
243
|
+
te as FundWithdrawals
|
|
67
244
|
};
|