@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.
- package/README.md +74 -3
- package/dist/index.js +25 -25
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,7 +1,78 @@
|
|
|
1
1
|
# @zerohash-sdk/csp-fiat-withdrawals-react
|
|
2
2
|
|
|
3
|
-
|
|
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
|
-
##
|
|
5
|
+
## Requirements
|
|
6
6
|
|
|
7
|
-
|
|
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
|
|
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 = (
|
|
8
|
-
jwt:
|
|
9
|
-
env:
|
|
10
|
-
theme:
|
|
11
|
-
onCompleted:
|
|
12
|
-
onError:
|
|
13
|
-
onClose:
|
|
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:
|
|
15
|
+
onEvent: d,
|
|
16
16
|
...w
|
|
17
17
|
}) => {
|
|
18
|
-
const
|
|
19
|
-
return
|
|
20
|
-
const t =
|
|
21
|
-
t && (
|
|
22
|
-
}, [
|
|
23
|
-
const t = y(
|
|
24
|
-
if (document.getElementById(
|
|
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
|
|
27
|
-
|
|
28
|
-
console.error(`Failed to load the script for ${h} from ${
|
|
29
|
-
}, document.head.appendChild(
|
|
30
|
-
}, [
|
|
31
|
-
ref:
|
|
32
|
-
jwt:
|
|
33
|
-
env:
|
|
34
|
-
theme:
|
|
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
|
};
|