@zerohash-sdk/crypto-deposits-react 0.1.1 → 0.2.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.d.ts CHANGED
@@ -45,8 +45,43 @@ declare interface CryptoDepositsProps {
45
45
  onLoaded?: () => void;
46
46
  /** Callback invoked for general application events during the crypto deposit flow. */
47
47
  onEvent?: (event: CryptoDepositsEvent) => void;
48
+ /**
49
+ * Callback invoked with the status of a deposit funded from a connected
50
+ * external account. Non-terminal: it can fire more than once per deposit, and
51
+ * the outcome is read off `status`.
52
+ */
53
+ onDeposit?: (deposit: DepositCompletedPayload) => void;
48
54
  }
49
55
 
56
+ /**
57
+ * Deposit completed payload — emitted by SDKs that drive a deposit through
58
+ * the integrations flow. Lives on `CommonCallbacks` because both Auth and
59
+ * any SDK embedding `@zerohash/integrations-flow` (e.g. fund with `useAuth`)
60
+ * resolve through the same deposit-status hook.
61
+ */
62
+ declare type DepositCompletedPayload = {
63
+ data: {
64
+ depositId: string;
65
+ status: DepositStatus;
66
+ assetId: string;
67
+ networkId: string;
68
+ amount?: string;
69
+ accountMatchingValidation?: {
70
+ status: 'PENDING' | 'VALID' | 'INVALID' | 'ERROR';
71
+ reason?: string;
72
+ };
73
+ };
74
+ };
75
+
76
+ /**
77
+ * Deposit status object — shared across SDKs that surface deposit completion.
78
+ */
79
+ declare type DepositStatus = {
80
+ value: string;
81
+ details: string;
82
+ occurredAt: string;
83
+ };
84
+
50
85
  /**
51
86
  * Available environments for the Connect Crypto Deposits service.
52
87
  *
package/dist/index.js CHANGED
@@ -91,49 +91,49 @@ const $ = {
91
91
  } catch {
92
92
  }
93
93
  }, Z = (e) => {
94
- const { webComponentTag: t, appName: o, appVersion: r, scriptUrls: a, fallbackScriptUrls: i, collectorUrls: s, env: n, jwt: c, timeoutMs: f = 15e3, onLoad: _, onError: g } = e;
94
+ const { webComponentTag: t, appName: o, appVersion: r, scriptUrls: a, fallbackScriptUrls: i, collectorUrls: s, env: n, jwt: c, timeoutMs: g = 15e3, onLoad: h, onError: y } = e;
95
95
  if (typeof document > "u")
96
96
  return O;
97
- const h = `${t}-script-${n}`;
98
- if (customElements.get(t) || document.getElementById(h))
97
+ const p = `${t}-script-${n}`;
98
+ if (customElements.get(t) || document.getElementById(p))
99
99
  return O;
100
- const S = P(c), k = e.report ?? ((p) => K(s && H(s, n, c), p, r));
100
+ const S = P(c), k = e.report ?? ((u) => K(s && H(s, n, c), u, r));
101
101
  let m = !1, w = 0, v;
102
102
  const R = () => {
103
103
  v !== void 0 && clearTimeout(v);
104
- }, C = (p, y, l) => {
104
+ }, C = (u, b, l) => {
105
105
  if (m)
106
106
  return;
107
107
  const U = Math.round(performance.now() - w), E = {
108
108
  webComponentTag: t,
109
109
  appName: o,
110
110
  env: n,
111
- scriptUrl: y,
112
- reason: p,
111
+ scriptUrl: b,
112
+ reason: u,
113
113
  triedFallback: l,
114
114
  elapsedMs: U,
115
115
  claims: S
116
116
  };
117
117
  k(E);
118
118
  const x = l ? void 0 : z(i ?? {}, n, c);
119
- if (x && x !== y) {
119
+ if (x && x !== b) {
120
120
  N(x, !0);
121
121
  return;
122
122
  }
123
- m = !0, R(), document.getElementById(h)?.remove(), g?.(E);
124
- }, N = (p, y) => {
123
+ m = !0, R(), document.getElementById(p)?.remove(), y?.(E);
124
+ }, N = (u, b) => {
125
125
  R(), w = performance.now();
126
126
  const l = document.createElement("script");
127
- l.id = h, 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, R(), _?.()) : C("not-defined", p, y));
129
+ m || (customElements.get(t) ? (m = !0, R(), h?.()) : C("not-defined", u, b));
130
130
  }, 0);
131
- }, l.onerror = () => C("network", p, y), v = setTimeout(() => C("timeout", p, y), f), document.getElementById(h)?.remove(), document.head.appendChild(l);
131
+ }, l.onerror = () => C("network", u, b), v = setTimeout(() => C("timeout", u, b), g), document.getElementById(p)?.remove(), document.head.appendChild(l);
132
132
  }, T = z(a, n, c);
133
133
  return T ? (N(T, !1), () => {
134
134
  m = !0, R();
135
135
  }) : O;
136
- }, u = {
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,20 +141,20 @@ 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: a = !1, local: i = u.local } = o, s = (c) => `${c}/${e}/${t}`, n = {
144
+ const { eu: r = !1, legacyAliases: a = !1, local: i = f.local } = o, s = (c) => `${c}/${e}/${t}`, n = {
145
145
  local: s(i),
146
- dev: s(u.dev),
146
+ dev: s(f.dev),
147
147
  gating: s(q),
148
- cert: s(u.cert),
149
- prod: s(u.prod)
148
+ cert: s(f.cert),
149
+ prod: s(f.prod)
150
150
  };
151
- return a && (n.sandbox = s(u.cert), n.production = s(u.prod)), r && (n["eu-cert"] = s(u["eu-cert"]), n["eu-prod"] = s(u["eu-prod"])), n;
151
+ return a && (n.sandbox = s(f.cert), n.production = s(f.prod)), r && (n["eu-cert"] = s(f["eu-cert"]), n["eu-prod"] = s(f["eu-prod"])), n;
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 b = {
157
+ const _ = {
158
158
  evergreen: "#00381D",
159
159
  green: "#CCFFD0",
160
160
  offBlack: "#1C1B1C",
@@ -170,9 +170,9 @@ const b = {
170
170
  padding: "32px 24px",
171
171
  textAlign: "center",
172
172
  fontFamily: "inherit",
173
- color: b.offBlack,
173
+ color: _.offBlack,
174
174
  background: "#FFFFFF",
175
- border: `1px solid ${b.grayLight}`,
175
+ border: `1px solid ${_.grayLight}`,
176
176
  borderRadius: "12px"
177
177
  }, children: [t && d("button", { type: "button", onClick: t, "aria-label": "Close", style: {
178
178
  position: "absolute",
@@ -180,19 +180,19 @@ const b = {
180
180
  right: "12px",
181
181
  display: "flex",
182
182
  padding: "4px",
183
- color: b.offBlack,
183
+ color: _.offBlack,
184
184
  background: "none",
185
185
  border: "none",
186
186
  cursor: "pointer",
187
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: {
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: _.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: {
189
189
  marginTop: "8px",
190
190
  padding: "8px 20px",
191
191
  fontSize: "14px",
192
192
  fontWeight: 600,
193
193
  fontFamily: "inherit",
194
- color: b.green,
195
- background: b.evergreen,
194
+ color: _.green,
195
+ background: _.evergreen,
196
196
  border: "none",
197
197
  borderRadius: "8px",
198
198
  cursor: "pointer"
@@ -204,8 +204,8 @@ const b = {
204
204
  a !== void 0 && (o[r] = a);
205
205
  });
206
206
  }, ee = (e) => {
207
- const { webComponentTag: t, appName: o, appVersion: r, scriptUrls: a, fallbackScriptUrls: i, collectorUrls: s, env: n, jwt: c, timeoutMs: f } = e, [_, g] = L(!1), [h, S] = L(0);
208
- A(() => (g(!1), Z({
207
+ const { webComponentTag: t, appName: o, appVersion: r, scriptUrls: a, fallbackScriptUrls: i, collectorUrls: s, env: n, jwt: c, timeoutMs: g } = e, [h, y] = L(!1), [p, S] = L(0);
208
+ A(() => (y(!1), Z({
209
209
  webComponentTag: t,
210
210
  appName: o ?? t,
211
211
  appVersion: r,
@@ -214,8 +214,8 @@ const b = {
214
214
  collectorUrls: s ?? $,
215
215
  env: n,
216
216
  jwt: c,
217
- timeoutMs: f,
218
- onError: () => g(!0)
217
+ timeoutMs: g,
218
+ onError: () => y(!0)
219
219
  })), [
220
220
  t,
221
221
  o,
@@ -225,11 +225,11 @@ const b = {
225
225
  s,
226
226
  n,
227
227
  c,
228
- f,
229
- h
228
+ g,
229
+ p
230
230
  ]);
231
231
  const k = M(() => S((m) => m + 1), []);
232
- return { loadFailed: _, retry: k };
232
+ return { loadFailed: h, retry: k };
233
233
  }, te = Q("crypto-deposits-web", "index.js", { eu: !0 }), B = "zerohash-crypto-deposits", ne = ({
234
234
  jwt: e,
235
235
  env: t = "prod",
@@ -239,22 +239,23 @@ const b = {
239
239
  onClose: i,
240
240
  onLoaded: s,
241
241
  onEvent: n,
242
- ...c
242
+ onDeposit: c,
243
+ ...g
243
244
  }) => {
244
- const f = j(null);
245
- Y(f, { theme: o, onCompleted: r, onError: a, onClose: i, onLoaded: s, onEvent: n });
246
- const { loadFailed: _, retry: g } = ee({
245
+ const h = j(null);
246
+ Y(h, { theme: o, onCompleted: r, onError: a, onClose: i, onLoaded: s, onEvent: n, onDeposit: c });
247
+ const { loadFailed: y, retry: p } = ee({
247
248
  webComponentTag: B,
248
249
  scriptUrls: te,
249
250
  env: t,
250
251
  jwt: e
251
252
  });
252
- return _ ? /* @__PURE__ */ d(X, { onRetry: g }) : D.createElement(B, {
253
- ref: f,
253
+ return y ? /* @__PURE__ */ d(X, { onRetry: p }) : D.createElement(B, {
254
+ ref: h,
254
255
  jwt: e,
255
256
  env: t,
256
257
  theme: o,
257
- ...c
258
+ ...g
258
259
  });
259
260
  };
260
261
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zerohash-sdk/crypto-deposits-react",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",