@zerohash-sdk/fiat-deposits-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-deposits-react
2
+
3
+ A React SDK that enables frontend React applications to seamlessly integrate with the Connect Fiat Deposits product.
4
+
5
+ Connect Fiat Deposits provides a secure, customizable flow for depositing 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-deposits-react
16
+ ```
17
+
18
+ ## Getting Started
19
+
20
+ ### 1. Import the FiatDeposits Component
21
+
22
+ ```tsx
23
+ import { FiatDeposits } from '@zerohash-sdk/fiat-deposits-react';
24
+ ```
25
+
26
+ ### 2. Add the FiatDeposits 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
+ <FiatDeposits
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
+ <FiatDeposits
50
+ jwt={jwt}
51
+ env="prod"
52
+ theme="auto"
53
+ onCompleted={({ amountDeposited, assetSymbol }) => {
54
+ console.log('Deposit completed:', amountDeposited, 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 { FiatDeposits } from '@zerohash-sdk/fiat-deposits-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
+ <FiatDeposits
81
+ jwt={jwt}
82
+ env="prod"
83
+ theme="auto"
84
+ onCompleted={({ amountDeposited, assetSymbol }) => {
85
+ console.log('Deposited:', amountDeposited, 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
+ ### FiatDeposits 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` | `({ amountDeposited, assetSymbol }) => void` | No | - | Callback when the deposit 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 Deposits 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 Deposits 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 deposit 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
+ * <FiatDeposits jwt="your-jwt-token" />
72
+ *
73
+ * // Using cert environment for testing
74
+ * <FiatDeposits jwt="your-jwt-token" env="cert" />
75
+ *
76
+ * // Force dark theme
77
+ * <FiatDeposits jwt="your-jwt-token" theme="dark" />
78
+ *
79
+ * // With callback functions
80
+ * <FiatDeposits
81
+ * jwt="your-jwt-token"
82
+ * theme="auto"
83
+ * onLoaded={() => console.log('Fiat deposits loaded and ready')}
84
+ * onCompleted={({ amountDeposited }) => console.log('Deposited', amountDeposited)}
85
+ * onClose={() => console.log('Fiat deposits 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 Deposits interface
92
+ */
93
+ export declare const FiatDeposits: default_2.FC<FiatDepositsProps>;
94
+
95
+ declare type FiatDepositsCompletedData = {
96
+ amountDeposited: string;
97
+ assetSymbol: string;
98
+ };
99
+
100
+ declare type FiatDepositsEvent = AppEvent<FiatDepositsEventType>;
101
+
102
+ declare type FiatDepositsEventType = string;
103
+
104
+ declare interface FiatDepositsProps {
105
+ /**
106
+ * JWT token used for authentication with the Connect Fiat Deposits 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 Deposits 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
+ * <FiatDeposits jwt={token} />
128
+ *
129
+ * // Use cert for testing
130
+ * <FiatDeposits jwt={token} env="cert" />
131
+ * ```
132
+ */
133
+ env?: Environment;
134
+ /**
135
+ * Theme mode for the Connect Fiat Deposits 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
+ * <FiatDeposits jwt={token} />
148
+ *
149
+ * // Force dark theme
150
+ * <FiatDeposits jwt={token} theme="dark" />
151
+ * ```
152
+ */
153
+ theme?: Theme;
154
+ /**
155
+ * Callback invoked when the fiat deposit flow is successfully completed.
156
+ *
157
+ * @param data - Details about the completed deposit, including amount deposited
158
+ *
159
+ * @example
160
+ * ```tsx
161
+ * <FiatDeposits
162
+ * jwt={token}
163
+ * onCompleted={({ amountDeposited }) =>
164
+ * console.log(`Deposited ${amountDeposited}`)
165
+ * }
166
+ * />
167
+ * ```
168
+ */
169
+ onCompleted?: (data: FiatDepositsCompletedData) => void;
170
+ /**
171
+ * Callback invoked when an error occurs during the fiat deposit flow.
172
+ *
173
+ * @param error - Error details including error code and reason
174
+ *
175
+ * @example
176
+ * ```tsx
177
+ * <FiatDeposits
178
+ * jwt={token}
179
+ * onError={({ errorCode, reason }) =>
180
+ * console.error('Fiat deposit error:', errorCode, reason)
181
+ * }
182
+ * />
183
+ * ```
184
+ */
185
+ onError?: (error: ErrorPayload) => void;
186
+ /**
187
+ * Callback invoked when the user closes the fiat deposit widget.
188
+ *
189
+ * @example
190
+ * ```tsx
191
+ * <FiatDeposits
192
+ * jwt={token}
193
+ * onClose={() => setShowFiatDeposits(false)}
194
+ * />
195
+ * ```
196
+ */
197
+ onClose?: () => void;
198
+ /**
199
+ * Callback invoked when the fiat deposit widget has finished loading and is ready.
200
+ *
201
+ * @example
202
+ * ```tsx
203
+ * <FiatDeposits
204
+ * jwt={token}
205
+ * onLoaded={() => setIsLoading(false)}
206
+ * />
207
+ * ```
208
+ */
209
+ onLoaded?: () => void;
210
+ /**
211
+ * Callback invoked for general application events during the fiat deposit flow.
212
+ *
213
+ * @param event - Event object containing the event type and associated data
214
+ *
215
+ * @example
216
+ * ```tsx
217
+ * <FiatDeposits
218
+ * jwt={token}
219
+ * onEvent={(event) => console.log('Fiat deposit event:', event)}
220
+ * />
221
+ * ```
222
+ */
223
+ onEvent?: (event: FiatDepositsEvent) => void;
224
+ }
225
+
226
+ /**
227
+ * Theme mode for the Connect Fiat Deposits 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 m, { useRef as x, useEffect as f } from "react";
2
+ const b = {
3
+ local: "http://localhost:5173/fiat-deposits-web/index.js",
4
+ dev: "https://connect-sdk.dev.0hash.com/fiat-deposits-web/index.js",
5
+ cert: "https://sdk.sandbox.connect.xyz/fiat-deposits-web/index.js",
6
+ prod: "https://sdk.connect.xyz/fiat-deposits-web/index.js"
7
+ }, y = "zerohash-fiat-deposits-script", l = "zerohash-fiat-deposits", I = (r = "prod") => b[r], j = ({
8
+ jwt: r,
9
+ env: s = "prod",
10
+ theme: h,
11
+ onCompleted: c,
12
+ onError: o,
13
+ onClose: i,
14
+ onLoaded: n,
15
+ onEvent: d,
16
+ ...u
17
+ }) => {
18
+ const p = x(null);
19
+ return f(() => {
20
+ const t = p.current;
21
+ t && (c && (t.onCompleted = c), o && (t.onError = o), i && (t.onClose = i), n && (t.onLoaded = n), d && (t.onEvent = d));
22
+ }, [c, o, i, n, d]), f(() => {
23
+ const t = I(s), a = `${y}-${s}`;
24
+ if (document.getElementById(a))
25
+ return;
26
+ const e = document.createElement("script");
27
+ e.id = a, e.src = t, e.type = "module", e.async = !0, e.onerror = () => {
28
+ console.error(`Failed to load the script for ${l} from ${s} environment.`);
29
+ }, document.head.appendChild(e);
30
+ }, [s]), m.createElement(l, {
31
+ ref: p,
32
+ jwt: r,
33
+ env: s,
34
+ theme: h,
35
+ ...u
36
+ });
37
+ };
38
+ export {
39
+ j as FiatDeposits
40
+ };
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@zerohash-sdk/fiat-deposits-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-deposits-react"
24
+ },
25
+ "peerDependencies": {
26
+ "react": ">=18.0.0",
27
+ "react-dom": ">=18.0.0"
28
+ }
29
+ }