@zerohash-sdk/csp-fiat-withdrawals-react 0.1.0 → 0.1.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 (3) hide show
  1. package/README.md +74 -3
  2. package/dist/index.js +25 -25
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,7 +1,78 @@
1
1
  # @zerohash-sdk/csp-fiat-withdrawals-react
2
2
 
3
- This library was generated with [Nx](https://nx.dev).
3
+ A React SDK for embedding the Zerohash CSP Fiat Withdrawals flow into web applications. Lets users withdraw fiat (USD) from their account to a linked bank account via ACH.
4
4
 
5
- ## Running unit tests
5
+ ## Requirements
6
6
 
7
- Run `nx test @zerohash-sdk/csp-fiat-withdrawals-react` to execute the unit tests via [Vitest](https://vitest.dev/).
7
+ - React 18.0.0 or higher
8
+ - React DOM 18.0.0 or higher
9
+
10
+ ## Installation
11
+
12
+ ```bash
13
+ npm install @zerohash-sdk/csp-fiat-withdrawals-react
14
+ ```
15
+
16
+ ## Getting Started
17
+
18
+ ### 1. Import the CspFiatWithdrawals component
19
+
20
+ ```tsx
21
+ import { CspFiatWithdrawals } from '@zerohash-sdk/csp-fiat-withdrawals-react';
22
+ ```
23
+
24
+ ### 2. Add it to your app
25
+
26
+ ```tsx
27
+ function App() {
28
+ const jwt = 'your-jwt-token'; // Obtain this from your backend
29
+
30
+ return (
31
+ <CspFiatWithdrawals
32
+ jwt={jwt}
33
+ env="prod" // or "cert" for testing
34
+ theme="auto"
35
+ />
36
+ );
37
+ }
38
+ ```
39
+
40
+ ### 3. Configure event callbacks (optional)
41
+
42
+ ```tsx
43
+ <CspFiatWithdrawals
44
+ jwt={jwt}
45
+ env="prod"
46
+ theme="auto"
47
+ onCompleted={({ amountWithdrawn, assetSymbol }) => {
48
+ console.log(`Withdrew ${amountWithdrawn} ${assetSymbol}`);
49
+ }}
50
+ onError={({ errorCode, reason }) => {
51
+ console.error(errorCode, reason);
52
+ }}
53
+ onClose={() => console.log('Widget closed')}
54
+ onEvent={(event) => console.log('Event:', event)}
55
+ onLoaded={() => console.log('Widget ready')}
56
+ />
57
+ ```
58
+
59
+ ## API Reference
60
+
61
+ ### CspFiatWithdrawals Component Props
62
+
63
+ | Prop | Type | Required | Default | Description |
64
+ | ------------- | -------------------------------------------- | -------- | -------- | -------------------------------------------- |
65
+ | `jwt` | `string` | Yes | - | JWT token for authentication with Connect |
66
+ | `env` | `"prod" \| "cert" \| "dev" \| "local"` | No | `"prod"` | Target environment |
67
+ | `theme` | `"auto" \| "light" \| "dark"` | No | `"auto"` | Theme mode for the interface |
68
+ | `onCompleted` | `({ amountWithdrawn, assetSymbol }) => void` | No | - | Callback when the withdrawal flow completes |
69
+ | `onError` | `({ errorCode, reason }) => void` | No | - | Callback for error events |
70
+ | `onClose` | `() => void` | No | - | Callback when the widget is closed |
71
+ | `onEvent` | `(event) => void` | No | - | Callback for general events |
72
+ | `onLoaded` | `() => void` | No | - | Callback when the widget is loaded and ready |
73
+
74
+ `onCompleted` payload shape: `{ amountWithdrawn: string; assetSymbol: string }` (asset is always `'USD'`).
75
+
76
+ ## More Information & Support
77
+
78
+ For comprehensive documentation, visit the [Zerohash Documentation Page](https://docs.zerohash.com/).
package/dist/index.js CHANGED
@@ -1,37 +1,37 @@
1
- import u, { useRef as m, useEffect as l } from "react";
1
+ import u, { useRef as m, useEffect as f } from "react";
2
2
  const x = {
3
3
  local: "http://localhost:5173/csp-fiat-withdrawals-web/index.js",
4
4
  dev: "https://connect-sdk.dev.0hash.com/csp-fiat-withdrawals-web/index.js",
5
5
  cert: "https://sdk.sandbox.connect.xyz/csp-fiat-withdrawals-web/index.js",
6
6
  prod: "https://sdk.connect.xyz/csp-fiat-withdrawals-web/index.js"
7
- }, b = "zerohash-csp-fiat-withdrawals-script", h = "zerohash-csp-fiat-withdrawals", y = (r = "prod") => x[r], R = ({
8
- jwt: r,
9
- env: s = "prod",
10
- theme: f,
11
- onCompleted: c,
12
- onError: i,
13
- onClose: a,
7
+ }, b = "zerohash-csp-fiat-withdrawals-script", h = "zerohash-csp-fiat-withdrawals", y = (c = "prod") => x[c], R = ({
8
+ jwt: c,
9
+ env: r = "prod",
10
+ theme: e,
11
+ onCompleted: i,
12
+ onError: a,
13
+ onClose: o,
14
14
  onLoaded: n,
15
- onEvent: o,
15
+ onEvent: d,
16
16
  ...w
17
17
  }) => {
18
- const d = m(null);
19
- return l(() => {
20
- const t = d.current;
21
- t && (c && (t.onCompleted = c), i && (t.onError = i), a && (t.onClose = a), n && (t.onLoaded = n), o && (t.onEvent = o));
22
- }, [c, i, a, n, o]), l(() => {
23
- const t = y(s), p = `${b}-${s}`;
24
- if (document.getElementById(p))
18
+ const p = m(null);
19
+ return f(() => {
20
+ const t = p.current;
21
+ t && (e !== void 0 && (t.theme = e), i && (t.onCompleted = i), a && (t.onError = a), o && (t.onClose = o), n && (t.onLoaded = n), d && (t.onEvent = d));
22
+ }, [e, i, a, o, n, d]), f(() => {
23
+ const t = y(r), l = `${b}-${r}`;
24
+ if (document.getElementById(l))
25
25
  return;
26
- const e = document.createElement("script");
27
- e.id = p, e.src = t, e.type = "module", e.async = !0, e.onerror = () => {
28
- console.error(`Failed to load the script for ${h} from ${s} environment.`);
29
- }, document.head.appendChild(e);
30
- }, [s]), u.createElement(h, {
31
- ref: d,
32
- jwt: r,
33
- env: s,
34
- theme: f,
26
+ const s = document.createElement("script");
27
+ s.id = l, s.src = t, s.type = "module", s.async = !0, s.onerror = () => {
28
+ console.error(`Failed to load the script for ${h} from ${r} environment.`);
29
+ }, document.head.appendChild(s);
30
+ }, [r]), u.createElement(h, {
31
+ ref: p,
32
+ jwt: c,
33
+ env: r,
34
+ theme: e,
35
35
  ...w
36
36
  });
37
37
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zerohash-sdk/csp-fiat-withdrawals-react",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",