@zerohash-sdk/fiat-withdrawals-react 1.1.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 ADDED
@@ -0,0 +1,116 @@
1
+ # @zerohash-sdk/fiat-withdrawals-react
2
+
3
+ A React SDK that enables frontend React applications to seamlessly integrate with the Connect Fiat Withdrawals product.
4
+
5
+ Connect Fiat Withdrawals provides a secure, customizable flow for withdrawing fiat currency directly within your application.
6
+
7
+ ## Requirements
8
+
9
+ - React 18.0.0 or higher
10
+ - React DOM 18.0.0 or higher
11
+
12
+ ## Installation
13
+
14
+ ```bash
15
+ npm install @zerohash-sdk/fiat-withdrawals-react
16
+ ```
17
+
18
+ ## Getting Started
19
+
20
+ ### 1. Import the FiatWithdrawals Component
21
+
22
+ ```tsx
23
+ import { FiatWithdrawals } from '@zerohash-sdk/fiat-withdrawals-react';
24
+ ```
25
+
26
+ ### 2. Add the FiatWithdrawals Component to Your App
27
+
28
+ ```tsx
29
+ function App() {
30
+ const jwt = 'your-jwt-token'; // Obtain this from your backend
31
+
32
+ return (
33
+ <FiatWithdrawals
34
+ jwt={jwt}
35
+ env="prod" // or "cert" for testing
36
+ theme="auto" // 'auto' (default), 'light', or 'dark'
37
+ />
38
+ );
39
+ }
40
+ ```
41
+
42
+ ### 3. Configure Event Callbacks (Optional)
43
+
44
+ ```tsx
45
+ function App() {
46
+ const jwt = 'your-jwt-token';
47
+
48
+ return (
49
+ <FiatWithdrawals
50
+ jwt={jwt}
51
+ env="prod"
52
+ theme="auto"
53
+ onCompleted={({ amountWithdrawn, assetSymbol }) => {
54
+ console.log('Withdrawal completed:', amountWithdrawn, assetSymbol);
55
+ }}
56
+ onError={({ errorCode, reason }) => {
57
+ console.log('Error:', errorCode, 'Reason:', reason);
58
+ }}
59
+ onClose={() => console.log('Widget closed')}
60
+ onEvent={({ type, data }) => console.log('Event:', type, data)}
61
+ onLoaded={() => console.log('Widget loaded and ready')}
62
+ />
63
+ );
64
+ }
65
+ ```
66
+
67
+ ## Complete Example
68
+
69
+ ```tsx
70
+ import React from 'react';
71
+ import { FiatWithdrawals } from '@zerohash-sdk/fiat-withdrawals-react';
72
+
73
+ function App() {
74
+ const jwt = 'your-jwt-token';
75
+
76
+ return (
77
+ <div className="App">
78
+ <h1>My App</h1>
79
+
80
+ <FiatWithdrawals
81
+ jwt={jwt}
82
+ env="prod"
83
+ theme="auto"
84
+ onCompleted={({ amountWithdrawn, assetSymbol }) => {
85
+ console.log('Withdrawn:', amountWithdrawn, assetSymbol);
86
+ }}
87
+ onError={({ errorCode, reason }) => console.log('Error:', errorCode, reason)}
88
+ onClose={() => console.log('Widget closed')}
89
+ onEvent={({ type, data }) => console.log('Event type:', type, 'Event data:', data)}
90
+ onLoaded={() => console.log('Widget loaded and ready')}
91
+ />
92
+ </div>
93
+ );
94
+ }
95
+
96
+ export default App;
97
+ ```
98
+
99
+ ## API Reference
100
+
101
+ ### FiatWithdrawals Component Props
102
+
103
+ | Prop | Type | Required | Default | Description |
104
+ | ------------- | -------------------------------------------- | -------- | -------- | -------------------------------------------------------- |
105
+ | `jwt` | `string` | Yes | - | JWT token for authentication with Connect |
106
+ | `env` | `"prod" \| "cert" \| "dev" \| "local"` | No | `"prod"` | Target environment |
107
+ | `theme` | `"auto" \| "light" \| "dark"` | No | `"auto"` | Theme mode for the interface |
108
+ | `onCompleted` | `({ amountWithdrawn, assetSymbol }) => void` | No | - | Callback when the withdrawal flow completes successfully |
109
+ | `onError` | `({ errorCode, reason }) => void` | No | - | Callback for error events |
110
+ | `onClose` | `() => void` | No | - | Callback when the widget is closed |
111
+ | `onEvent` | `({ type, data }) => void` | No | - | Callback for general events |
112
+ | `onLoaded` | `() => void` | No | - | Callback when the widget is loaded and ready |
113
+
114
+ ## More Information & Support
115
+
116
+ For comprehensive documentation or support about Connect, visit our [Documentation Page](https://docs.zerohash.com/).
@@ -0,0 +1,235 @@
1
+ import { default as default_2 } from 'react';
2
+
3
+ /**
4
+ * Generic app event structure
5
+ * @template TType - Event type string
6
+ * @template TData - Event data payload
7
+ */
8
+ declare type AppEvent<TType extends string = string, TData = Record<string, unknown>> = {
9
+ /** The type of event that occurred */
10
+ type: TType;
11
+ /** Data associated with the event */
12
+ data: TData;
13
+ };
14
+
15
+ /**
16
+ * Available environments for the Connect Fiat Withdrawals service.
17
+ *
18
+ * - `"local"` - Local development environment (http://localhost:4205)
19
+ * - `"dev"` - Development environment for early-stage testing
20
+ * - `"cert"` - Certificate/staging environment for integration testing
21
+ * - `"prod"` - Live production environment for real applications
22
+ */
23
+ declare type Environment = 'local' | 'dev' | 'cert' | 'prod';
24
+
25
+ /**
26
+ * Generic error codes for all Connect applications
27
+ */
28
+ declare enum ErrorCode {
29
+ /** Network connectivity error */
30
+ NETWORK_ERROR = 'network_error',
31
+ /** Authentication or session expired error */
32
+ AUTH_ERROR = 'auth_error',
33
+ /** Resource not found error */
34
+ NOT_FOUND_ERROR = 'not_found_error',
35
+ /** Validation error from user input */
36
+ VALIDATION_ERROR = 'validation_error',
37
+ /** Server error (5xx) */
38
+ SERVER_ERROR = 'server_error',
39
+ /** Client error (4xx) */
40
+ CLIENT_ERROR = 'client_error',
41
+ /** Unknown or unexpected error */
42
+ UNKNOWN_ERROR = 'unknown_error',
43
+ }
44
+
45
+ /**
46
+ * Generic error payload structure for error callbacks
47
+ */
48
+ declare type ErrorPayload = {
49
+ /** Error code indicating the type of error */
50
+ errorCode: ErrorCode;
51
+ /** Human-readable reason for the error */
52
+ reason: string;
53
+ };
54
+
55
+ /**
56
+ * A React wrapper component for the Connect Fiat Withdrawals product.
57
+ *
58
+ * @param props - Component properties
59
+ * @param jwt - JWT token for authentication (required)
60
+ * @param env - Target environment ("local" | "dev" | "cert" | "prod", defaults to "prod")
61
+ * @param theme - Theme mode ("auto" | "light" | "dark", defaults to "auto")
62
+ * @param onCompleted - Callback invoked when the withdrawal flow is successfully completed
63
+ * @param onError - Callback invoked when an error occurs
64
+ * @param onClose - Callback invoked when the user closes the widget
65
+ * @param onLoaded - Callback invoked when the widget has finished loading
66
+ * @param onEvent - Callback invoked for general application events
67
+ *
68
+ * @example
69
+ * ```tsx
70
+ * // Basic usage with production environment (default)
71
+ * <FiatWithdrawals jwt="your-jwt-token" />
72
+ *
73
+ * // Using cert environment for testing
74
+ * <FiatWithdrawals jwt="your-jwt-token" env="cert" />
75
+ *
76
+ * // Force dark theme
77
+ * <FiatWithdrawals jwt="your-jwt-token" theme="dark" />
78
+ *
79
+ * // With callback functions
80
+ * <FiatWithdrawals
81
+ * jwt="your-jwt-token"
82
+ * theme="auto"
83
+ * onLoaded={() => console.log('Fiat withdrawals loaded and ready')}
84
+ * onCompleted={({ amountWithdrawn }) => console.log('Withdrawn', amountWithdrawn)}
85
+ * onClose={() => console.log('Fiat withdrawals closed')}
86
+ * onError={({ errorCode, reason }) => console.error('Error:', errorCode, reason)}
87
+ * onEvent={(event) => console.log('Event:', event)}
88
+ * />
89
+ * ```
90
+ *
91
+ * @returns React component that renders the Connect Fiat Withdrawals interface
92
+ */
93
+ export declare const FiatWithdrawals: default_2.FC<FiatWithdrawalsProps>;
94
+
95
+ declare type FiatWithdrawalsCompletedData = {
96
+ amountWithdrawn: string;
97
+ assetSymbol: string;
98
+ };
99
+
100
+ declare type FiatWithdrawalsEvent = AppEvent<FiatWithdrawalsEventType>;
101
+
102
+ declare type FiatWithdrawalsEventType = string;
103
+
104
+ declare interface FiatWithdrawalsProps {
105
+ /**
106
+ * JWT token used for authentication with the Connect Fiat Withdrawals service.
107
+ * This token should be obtained from your backend and contain the necessary
108
+ * claims for user identification and authorization.
109
+ *
110
+ * @example "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
111
+ */
112
+ jwt: string;
113
+ /**
114
+ * Target environment for the Connect Fiat Withdrawals service.
115
+ *
116
+ * @default "prod"
117
+ *
118
+ * Available environments:
119
+ * - `"local"` - Local development environment
120
+ * - `"dev"` - Development environment
121
+ * - `"cert"` - Certificate/staging environment for integration testing
122
+ * - `"prod"` - Live production environment for real applications
123
+ *
124
+ * @example
125
+ * ```tsx
126
+ * // Use production (default)
127
+ * <FiatWithdrawals jwt={token} />
128
+ *
129
+ * // Use cert for testing
130
+ * <FiatWithdrawals jwt={token} env="cert" />
131
+ * ```
132
+ */
133
+ env?: Environment;
134
+ /**
135
+ * Theme mode for the Connect Fiat Withdrawals interface.
136
+ *
137
+ * @default "auto"
138
+ *
139
+ * Available themes:
140
+ * - `"auto"` - Automatically detect system preference (light/dark mode)
141
+ * - `"light"` - Force light theme
142
+ * - `"dark"` - Force dark theme
143
+ *
144
+ * @example
145
+ * ```tsx
146
+ * // Auto-detect system preference (default)
147
+ * <FiatWithdrawals jwt={token} />
148
+ *
149
+ * // Force dark theme
150
+ * <FiatWithdrawals jwt={token} theme="dark" />
151
+ * ```
152
+ */
153
+ theme?: Theme;
154
+ /**
155
+ * Callback invoked when the fiat withdrawal flow is successfully completed.
156
+ *
157
+ * @param data - Details about the completed withdrawal, including amount withdrawn
158
+ *
159
+ * @example
160
+ * ```tsx
161
+ * <FiatWithdrawals
162
+ * jwt={token}
163
+ * onCompleted={({ amountWithdrawn }) =>
164
+ * console.log(`Withdrawn ${amountWithdrawn}`)
165
+ * }
166
+ * />
167
+ * ```
168
+ */
169
+ onCompleted?: (data: FiatWithdrawalsCompletedData) => void;
170
+ /**
171
+ * Callback invoked when an error occurs during the fiat withdrawal flow.
172
+ *
173
+ * @param error - Error details including error code and reason
174
+ *
175
+ * @example
176
+ * ```tsx
177
+ * <FiatWithdrawals
178
+ * jwt={token}
179
+ * onError={({ errorCode, reason }) =>
180
+ * console.error('Fiat withdrawal error:', errorCode, reason)
181
+ * }
182
+ * />
183
+ * ```
184
+ */
185
+ onError?: (error: ErrorPayload) => void;
186
+ /**
187
+ * Callback invoked when the user closes the fiat withdrawal widget.
188
+ *
189
+ * @example
190
+ * ```tsx
191
+ * <FiatWithdrawals
192
+ * jwt={token}
193
+ * onClose={() => setShowFiatWithdrawals(false)}
194
+ * />
195
+ * ```
196
+ */
197
+ onClose?: () => void;
198
+ /**
199
+ * Callback invoked when the fiat withdrawal widget has finished loading and is ready.
200
+ *
201
+ * @example
202
+ * ```tsx
203
+ * <FiatWithdrawals
204
+ * jwt={token}
205
+ * onLoaded={() => setIsLoading(false)}
206
+ * />
207
+ * ```
208
+ */
209
+ onLoaded?: () => void;
210
+ /**
211
+ * Callback invoked for general application events during the fiat withdrawal flow.
212
+ *
213
+ * @param event - Event object containing the event type and associated data
214
+ *
215
+ * @example
216
+ * ```tsx
217
+ * <FiatWithdrawals
218
+ * jwt={token}
219
+ * onEvent={(event) => console.log('Fiat withdrawal event:', event)}
220
+ * />
221
+ * ```
222
+ */
223
+ onEvent?: (event: FiatWithdrawalsEvent) => void;
224
+ }
225
+
226
+ /**
227
+ * Theme mode for the Connect Fiat Withdrawals interface.
228
+ *
229
+ * - `"auto"` - Automatically detect system preference (light/dark mode)
230
+ * - `"light"` - Force light theme
231
+ * - `"dark"` - Force dark theme
232
+ */
233
+ declare type Theme = 'auto' | 'light' | 'dark';
234
+
235
+ export { }
package/dist/index.js ADDED
@@ -0,0 +1,40 @@
1
+ import u, { useRef as m, useEffect as h } from "react";
2
+ const x = {
3
+ local: "http://localhost:5173/fiat-withdrawals-web/index.js",
4
+ dev: "https://connect-sdk.dev.0hash.com/fiat-withdrawals-web/index.js",
5
+ cert: "https://sdk.sandbox.connect.xyz/fiat-withdrawals-web/index.js",
6
+ prod: "https://sdk.connect.xyz/fiat-withdrawals-web/index.js"
7
+ }, b = "zerohash-fiat-withdrawals-script", f = "zerohash-fiat-withdrawals", y = (s = "prod") => x[s], R = ({
8
+ jwt: s,
9
+ env: r = "prod",
10
+ theme: p,
11
+ onCompleted: c,
12
+ onError: i,
13
+ onClose: a,
14
+ onLoaded: n,
15
+ onEvent: o,
16
+ ...w
17
+ }) => {
18
+ const d = m(null);
19
+ return h(() => {
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]), h(() => {
23
+ const t = y(r), l = `${b}-${r}`;
24
+ if (document.getElementById(l))
25
+ return;
26
+ const e = document.createElement("script");
27
+ e.id = l, e.src = t, e.type = "module", e.async = !0, e.onerror = () => {
28
+ console.error(`Failed to load the script for ${f} from ${r} environment.`);
29
+ }, document.head.appendChild(e);
30
+ }, [r]), u.createElement(f, {
31
+ ref: d,
32
+ jwt: s,
33
+ env: r,
34
+ theme: p,
35
+ ...w
36
+ });
37
+ };
38
+ export {
39
+ R as FiatWithdrawals
40
+ };
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@zerohash-sdk/fiat-withdrawals-react",
3
+ "version": "1.1.0",
4
+ "private": false,
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "license": "MIT",
10
+ "exports": {
11
+ "./package.json": "./package.json",
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "import": "./dist/index.js",
15
+ "default": "./dist/index.js"
16
+ }
17
+ },
18
+ "files": [
19
+ "dist",
20
+ "!**/*.tsbuildinfo"
21
+ ],
22
+ "nx": {
23
+ "name": "fiat-withdrawals-react"
24
+ },
25
+ "peerDependencies": {
26
+ "react": ">=18.0.0",
27
+ "react-dom": ">=18.0.0"
28
+ }
29
+ }