@zerohash-sdk/fund-react 1.11.4 → 1.13.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/README.md CHANGED
@@ -108,6 +108,12 @@ function App() {
108
108
  console.log('Funded:', amount, assetSymbol, 'on', network);
109
109
  console.log('Deposit address:', depositAddress);
110
110
  }}
111
+ onFailed={({ assetSymbol, amount, transactionId }) => {
112
+ console.log('Deposit failed:', transactionId, amount, assetSymbol);
113
+ }}
114
+ onDeposit={({ data }) => {
115
+ console.log('External-source deposit:', data.depositId, data.status.value);
116
+ }}
111
117
  onError={({ errorCode, reason }) => {
112
118
  console.log('Error:', errorCode, 'Reason:', reason);
113
119
  }}
@@ -132,17 +138,19 @@ export default App;
132
138
 
133
139
  ### Fund Component Props
134
140
 
135
- | Prop | Type | Required | Default | Description |
136
- | ------------- | ------------------------------------------------------------ | -------- | -------- | -------------------------------------------------- |
137
- | `jwt` | `string` | Yes | - | JWT token for authentication with Connect |
138
- | `env` | `"prod" \| "cert" \| "dev" \| "local"` | No | `"prod"` | Target environment |
139
- | `theme` | `"auto" \| "light" \| "dark"` | No | `"auto"` | Theme mode for the interface |
140
- | `isPay` | `boolean` | No | `false` | Run the SDK in Pay mode (see notes below) |
141
- | `onCompleted` | `({ assetSymbol, amount, network, depositAddress }) => void` | No | - | Callback when the fund flow completes successfully |
142
- | `onError` | `({ errorCode, reason }) => void` | No | - | Callback for error events |
143
- | `onClose` | `() => void` | No | - | Callback when the widget is closed |
144
- | `onEvent` | `({ type, data }) => void` | No | - | Callback for general events |
145
- | `onLoaded` | `() => void` | No | - | Callback when the widget is loaded and ready |
141
+ | Prop | Type | Required | Default | Description |
142
+ | ------------- | ------------------------------------------------------------ | -------- | -------- | --------------------------------------------------------------------------------------------------------------- |
143
+ | `jwt` | `string` | Yes | - | JWT token for authentication with Connect |
144
+ | `env` | `"prod" \| "cert" \| "dev" \| "local"` | No | `"prod"` | Target environment |
145
+ | `theme` | `"auto" \| "light" \| "dark"` | No | `"auto"` | Theme mode for the interface |
146
+ | `isPay` | `boolean` | No | `false` | Run the SDK in Pay mode (see notes below) |
147
+ | `onCompleted` | `({ assetSymbol, amount, network, depositAddress }) => void` | No | - | Callback when the fund flow completes successfully |
148
+ | `onFailed` | `({ assetSymbol, amount, network, depositAddress }) => void` | No | - | Callback when a deposit ends in a failed state |
149
+ | `onDeposit` | `(deposit) => void` | No | - | Deposit-status updates for the external-source ("connect an account") path; may fire more than once per deposit |
150
+ | `onError` | `({ errorCode, reason }) => void` | No | - | Callback for error events |
151
+ | `onClose` | `() => void` | No | - | Callback when the widget is closed |
152
+ | `onEvent` | `({ type, data }) => void` | No | - | Callback for general events |
153
+ | `onLoaded` | `() => void` | No | - | Callback when the widget is loaded and ready |
146
154
 
147
155
  ### Pay mode (`isPay`)
148
156
 
@@ -151,6 +159,23 @@ When `isPay` is `true`, the Fund SDK runs in Pay mode:
151
159
  - Uses the `pay-sdk` app id and the `app:internal:pay` scope when calling trade-api.
152
160
  - Signs the `account_funding_pay` terms agreement.
153
161
 
162
+ ### The two deposit paths report different fields
163
+
164
+ `onCompleted` / `onFailed` and `onDeposit` do not carry the same shape, so read
165
+ whichever the path you support actually delivers:
166
+
167
+ | | `onCompleted` / `onFailed` (manual, Pay) | `onDeposit` (external source) |
168
+ | ---------- | ---------------------------------------- | ----------------------------------------------------- |
169
+ | identifier | `transactionId`, `fundId` | `depositId` |
170
+ | asset | `assetSymbol` (e.g. `BTC.BITCOIN`) | `assetId` (asset key, e.g. `usdc`) |
171
+ | network | `network` | `networkId` |
172
+ | amount | `amount`, `notionalAmount` | `amount` |
173
+ | outcome | which callback fired | `status.value` (+ `accountMatchingValidation.status`) |
174
+
175
+ There is no `transactionId` on an `onDeposit` payload — an external-source deposit is
176
+ identified by `depositId`. If you need one code path for both, key off the identifier
177
+ each provides rather than assuming a shared field name.
178
+
154
179
  ## More Information & Support
155
180
 
156
181
  For comprehensive documentation or support about Connect, visit our [Documentation Page](https://docs.zerohash.com/).
package/dist/index.d.ts CHANGED
@@ -12,6 +12,35 @@ declare type AppEvent<TType extends string = string, TData = Record<string, unkn
12
12
  data: TData;
13
13
  };
14
14
 
15
+ /**
16
+ * Deposit completed payload — emitted by SDKs that drive a deposit through
17
+ * the integrations flow. Lives on `CommonCallbacks` because both Auth and
18
+ * any SDK embedding `@zerohash/integrations-flow` (e.g. fund with `useAuth`)
19
+ * resolve through the same deposit-status hook.
20
+ */
21
+ declare type DepositCompletedPayload = {
22
+ data: {
23
+ depositId: string;
24
+ status: DepositStatus;
25
+ assetId: string;
26
+ networkId: string;
27
+ amount?: string;
28
+ accountMatchingValidation?: {
29
+ status: 'PENDING' | 'VALID' | 'INVALID' | 'ERROR';
30
+ reason?: string;
31
+ };
32
+ };
33
+ };
34
+
35
+ /**
36
+ * Deposit status object — shared across SDKs that surface deposit completion.
37
+ */
38
+ declare type DepositStatus = {
39
+ value: string;
40
+ details: string;
41
+ occurredAt: string;
42
+ };
43
+
15
44
  /**
16
45
  * Available environments for the Connect Fund service.
17
46
  *
@@ -210,6 +239,20 @@ declare interface FundProps {
210
239
  * @param data - Details about the failed transaction (transactionId, fundId, amount…)
211
240
  */
212
241
  onFailed?: (data: FundCompletedData) => void;
242
+ /**
243
+ * Callback invoked when a deposit made from an external funding source
244
+ * changes status. This is the "auth as a feature" path; the manual-deposit and
245
+ * Pay paths report through `onCompleted`/`onFailed` instead.
246
+ *
247
+ * A status notification, not a single terminal event: it can fire more than
248
+ * once for one deposit, including while account matching is still verifying.
249
+ * Read `deposit.data.status.value` (`PROCESSED` = funded, `FAILED` = not) and
250
+ * `deposit.data.accountMatchingValidation?.status` (`PENDING` = not finished
251
+ * yet) rather than assuming any call is the last one.
252
+ *
253
+ * @param deposit - The deposit and its current status
254
+ */
255
+ onDeposit?: (deposit: DepositCompletedPayload) => void;
213
256
  /** Invoked when the user taps "Provide info" on the travel-rule pending screen; open the Travel Rule SDK scoped to `depositId`. */
214
257
  onProvideInfo?: (data: FundProvideInfoData) => void;
215
258
  /**
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { jsxs as W, jsx as _ } from "react/jsx-runtime";
2
- import D, { useEffect as I, useState as z, useCallback as j, useRef as M } from "react";
1
+ import { jsxs as W, jsx as p } from "react/jsx-runtime";
2
+ import M, { useEffect as A, 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",
@@ -23,7 +23,7 @@ const $ = {
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, J = (e) => {
26
+ }, I = (e, t) => V(t) !== "eu" ? e : e === "cert" ? "eu-cert" : e === "prod" ? "eu-prod" : e, H = (e) => {
27
27
  if (!e || typeof e != "string")
28
28
  return {};
29
29
  const t = e.split(".");
@@ -40,18 +40,18 @@ const $ = {
40
40
  } catch {
41
41
  return {};
42
42
  }
43
- }, F = (e, t, o) => {
44
- const r = B(t, o);
43
+ }, z = (e, t, o) => {
44
+ const r = I(t, o);
45
45
  return e[r] ?? e[t] ?? e.prod;
46
- }, P = (e, t, o) => {
47
- const r = B(t, o);
46
+ }, J = (e, t, o) => {
47
+ const r = I(t, o);
48
48
  return e[r] ?? e[t];
49
- }, x = () => {
50
- }, H = () => {
49
+ }, w = () => {
50
+ }, P = () => {
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__, n = {};
54
+ const o = P(), r = globalThis.__ZH_WEB_SDK_VERSION__, n = {};
55
55
  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);
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: n, fallbackScriptUrls: i, collectorUrls: c, env: a, jwt: s, timeoutMs: m = 15e3, onLoad: b, onError: g } = e;
94
+ const { webComponentTag: t, appName: o, appVersion: r, scriptUrls: n, fallbackScriptUrls: i, collectorUrls: c, env: a, jwt: s, timeoutMs: g = 15e3, onLoad: h, onError: y } = e;
95
95
  if (typeof document > "u")
96
- return x;
97
- const p = `${t}-script-${a}`;
98
- if (customElements.get(t) || document.getElementById(p))
99
- return x;
100
- const h = J(s), R = e.report ?? ((u) => K(c && P(c, a, s), u, r));
101
- let d = !1, N = 0, C;
96
+ return w;
97
+ const u = `${t}-script-${a}`;
98
+ if (customElements.get(t) || document.getElementById(u))
99
+ return w;
100
+ const S = H(s), b = e.report ?? ((f) => K(c && J(c, a, s), f, r));
101
+ let d = !1, k = 0, x;
102
102
  const v = () => {
103
- C !== void 0 && clearTimeout(C);
104
- }, k = (u, y, l) => {
103
+ x !== void 0 && clearTimeout(x);
104
+ }, C = (f, _, l) => {
105
105
  if (d)
106
106
  return;
107
- const U = Math.round(performance.now() - N), E = {
107
+ const U = Math.round(performance.now() - k), E = {
108
108
  webComponentTag: t,
109
109
  appName: o,
110
110
  env: a,
111
- scriptUrl: y,
112
- reason: u,
111
+ scriptUrl: _,
112
+ reason: f,
113
113
  triedFallback: l,
114
114
  elapsedMs: U,
115
- claims: h
115
+ claims: S
116
116
  };
117
- R(E);
118
- const O = l ? void 0 : F(i ?? {}, a, s);
119
- if (O && O !== y) {
120
- T(O, !0);
117
+ b(E);
118
+ const O = l ? void 0 : z(i ?? {}, a, s);
119
+ if (O && O !== _) {
120
+ N(O, !0);
121
121
  return;
122
122
  }
123
- d = !0, v(), document.getElementById(p)?.remove(), g?.(E);
124
- }, T = (u, y) => {
125
- v(), N = performance.now();
123
+ d = !0, v(), document.getElementById(u)?.remove(), y?.(E);
124
+ }, N = (f, _) => {
125
+ v(), k = performance.now();
126
126
  const l = document.createElement("script");
127
- l.id = p, l.src = u, l.type = "module", l.async = !0, l.onload = () => {
127
+ l.id = u, l.src = f, l.type = "module", l.async = !0, l.onload = () => {
128
128
  setTimeout(() => {
129
- d || (customElements.get(t) ? (d = !0, v(), b?.()) : k("not-defined", u, y));
129
+ d || (customElements.get(t) ? (d = !0, v(), h?.()) : C("not-defined", f, _));
130
130
  }, 0);
131
- }, l.onerror = () => k("network", u, y), C = setTimeout(() => k("timeout", u, y), m), document.getElementById(p)?.remove(), document.head.appendChild(l);
132
- }, w = F(n, a, s);
133
- return w ? (T(w, !1), () => {
131
+ }, l.onerror = () => C("network", f, _), x = setTimeout(() => C("timeout", f, _), g), document.getElementById(u)?.remove(), document.head.appendChild(l);
132
+ }, T = z(n, a, s);
133
+ return T ? (N(T, !1), () => {
134
134
  d = !0, v();
135
- }) : x;
136
- }, f = {
135
+ }) : w;
136
+ }, m = {
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: n = !1, local: i = f.local } = o, c = (s) => `${s}/${e}/${t}`, a = {
144
+ const { eu: r = !1, legacyAliases: n = !1, local: i = m.local } = o, c = (s) => `${s}/${e}/${t}`, a = {
145
145
  local: c(i),
146
- dev: c(f.dev),
146
+ dev: c(m.dev),
147
147
  gating: c(q),
148
- cert: c(f.cert),
149
- prod: c(f.prod)
148
+ cert: c(m.cert),
149
+ prod: c(m.prod)
150
150
  };
151
- return n && (a.sandbox = c(f.cert), a.production = c(f.prod)), r && (a["eu-cert"] = c(f["eu-cert"]), a["eu-prod"] = c(f["eu-prod"])), a;
151
+ return n && (a.sandbox = c(m.cert), a.production = c(m.prod)), r && (a["eu-cert"] = c(m["eu-cert"]), a["eu-prod"] = c(m["eu-prod"])), a;
152
152
  };
153
- var L;
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
- })(L || (L = {}));
157
- const S = {
156
+ })(F || (F = {}));
157
+ const R = {
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,31 +170,42 @@ const S = {
169
170
  padding: "32px 24px",
170
171
  textAlign: "center",
171
172
  fontFamily: "inherit",
172
- color: S.offBlack,
173
+ color: R.offBlack,
173
174
  background: "#FFFFFF",
174
- border: `1px solid ${S.grayLight}`,
175
+ border: `1px solid ${R.grayLight}`,
175
176
  borderRadius: "12px"
176
- }, 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: S.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: {
177
+ }, children: [t && p("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: R.offBlack,
184
+ background: "none",
185
+ border: "none",
186
+ cursor: "pointer",
187
+ lineHeight: 0
188
+ }, children: p("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", "aria-hidden": "true", children: p("path", { d: "M18 6L6 18M6 6l12 12", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }) }) }), p("svg", { width: "32", height: "32", viewBox: "0 0 24 24", fill: "none", "aria-hidden": "true", children: p("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" }) }), p("p", { style: { margin: 0, fontSize: "16px", fontWeight: 600 }, children: "Something went wrong" }), p("p", { style: { margin: 0, fontSize: "14px", opacity: 0.75 }, children: "We couldn't load this content. Please check your internet connection and try again." }), p("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: S.green,
183
- background: S.evergreen,
194
+ color: R.green,
195
+ background: R.evergreen,
184
196
  border: "none",
185
197
  borderRadius: "8px",
186
198
  cursor: "pointer"
187
199
  }, children: "Try again" })] }), Y = (e, t) => {
188
- I(() => {
200
+ A(() => {
189
201
  const o = e.current;
190
202
  if (o)
191
203
  for (const [r, n] of Object.entries(t))
192
204
  n !== void 0 && (o[r] = n);
193
205
  });
194
206
  }, ee = (e) => {
195
- const { webComponentTag: t, appName: o, appVersion: r, scriptUrls: n, fallbackScriptUrls: i, collectorUrls: c, env: a, jwt: s, timeoutMs: m } = e, [b, g] = z(!1), [p, h] = z(0);
196
- I(() => (g(!1), Z({
207
+ const { webComponentTag: t, appName: o, appVersion: r, scriptUrls: n, fallbackScriptUrls: i, collectorUrls: c, env: a, jwt: s, timeoutMs: g } = e, [h, y] = L(!1), [u, S] = L(0);
208
+ A(() => (y(!1), Z({
197
209
  webComponentTag: t,
198
210
  appName: o ?? t,
199
211
  appVersion: r,
@@ -202,8 +214,8 @@ const S = {
202
214
  collectorUrls: c ?? $,
203
215
  env: a,
204
216
  jwt: s,
205
- timeoutMs: m,
206
- onError: () => g(!0)
217
+ timeoutMs: g,
218
+ onError: () => y(!0)
207
219
  })), [
208
220
  t,
209
221
  o,
@@ -213,12 +225,12 @@ const S = {
213
225
  c,
214
226
  a,
215
227
  s,
216
- m,
217
- p
228
+ g,
229
+ u
218
230
  ]);
219
- const R = j(() => h((d) => d + 1), []);
220
- return { loadFailed: b, retry: R };
221
- }, te = Q("fund-web", "index.js", { eu: !0 }), A = "zerohash-fund", ne = ({
231
+ const b = j(() => S((d) => d + 1), []);
232
+ return { loadFailed: h, retry: b };
233
+ }, te = Q("fund-web", "index.js", { eu: !0 }), B = "zerohash-fund", ne = ({
222
234
  jwt: e,
223
235
  env: t = "prod",
224
236
  theme: o,
@@ -226,40 +238,48 @@ const S = {
226
238
  isPay: n = !1,
227
239
  onCompleted: i,
228
240
  onFailed: c,
229
- onProvideInfo: a,
230
- onError: s,
231
- onClose: m,
232
- onLoaded: b,
233
- onEvent: g,
234
- ...p
241
+ onDeposit: a,
242
+ onProvideInfo: s,
243
+ onError: g,
244
+ onClose: h,
245
+ onLoaded: y,
246
+ onEvent: u,
247
+ ...S
235
248
  }) => {
236
- const h = M(null);
237
- Y(h, {
249
+ const b = D(null);
250
+ Y(b, {
238
251
  isPay: n,
239
252
  theme: o,
240
253
  branding: r,
241
254
  onCompleted: i,
242
255
  onFailed: c,
243
- onProvideInfo: a,
244
- onError: s,
245
- onClose: m,
246
- onLoaded: b,
247
- onEvent: g
256
+ onDeposit: a,
257
+ onProvideInfo: s,
258
+ onError: g,
259
+ onClose: h,
260
+ onLoaded: y,
261
+ onEvent: u
248
262
  });
249
- const { loadFailed: R, retry: d } = ee({
250
- webComponentTag: A,
263
+ const { loadFailed: d, retry: k } = ee({
264
+ webComponentTag: B,
251
265
  scriptUrls: te,
252
266
  // fallbackScriptUrls: FALLBACK_SCRIPT_URLS, // enable once the host is confirmed (AUTH-3095)
253
267
  env: t,
254
268
  jwt: e
255
269
  });
256
- return R ? /* @__PURE__ */ _(X, { onRetry: d }) : D.createElement(A, {
257
- ref: h,
270
+ return d ? /* @__PURE__ */ p(
271
+ X,
272
+ {
273
+ onRetry: k,
274
+ onClose: h
275
+ }
276
+ ) : M.createElement(B, {
277
+ ref: b,
258
278
  jwt: e,
259
279
  env: t,
260
280
  theme: o,
261
281
  ispay: n ? "true" : void 0,
262
- ...p
282
+ ...S
263
283
  });
264
284
  };
265
285
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zerohash-sdk/fund-react",
3
- "version": "1.11.4",
3
+ "version": "1.13.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",