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