@zerohash-sdk/csp-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 +152 -0
- package/dist/index.js +40 -0
- package/package.json +29 -0
package/README.md
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# @zerohash-sdk/csp-crypto-withdrawals-react
|
|
2
|
+
|
|
3
|
+
A React SDK that enables frontend React applications to seamlessly integrate with the Connect CSP Crypto Withdrawals product.
|
|
4
|
+
|
|
5
|
+
Connect CSP 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/csp-crypto-withdrawals-react
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Getting Started
|
|
19
|
+
|
|
20
|
+
### 1. Import the CspCryptoWithdrawals Component
|
|
21
|
+
|
|
22
|
+
```tsx
|
|
23
|
+
import { CspCryptoWithdrawals } from '@zerohash-sdk/csp-crypto-withdrawals-react';
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### 2. Add the CspCryptoWithdrawals 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
|
+
<CspCryptoWithdrawals
|
|
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
|
+
<CspCryptoWithdrawals
|
|
50
|
+
jwt={jwt}
|
|
51
|
+
env="prod"
|
|
52
|
+
theme="auto"
|
|
53
|
+
onCompleted={({ withdrawalRequestId, assetSymbol, amount, networkFee, withdrawalFee }) => {
|
|
54
|
+
console.log('Withdrawal completed:', withdrawalRequestId, amount, 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 { CspCryptoWithdrawals } from '@zerohash-sdk/csp-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
|
+
<CspCryptoWithdrawals
|
|
81
|
+
jwt={jwt}
|
|
82
|
+
env="prod"
|
|
83
|
+
theme="auto"
|
|
84
|
+
onCompleted={({ withdrawalRequestId, assetSymbol, amount, networkFee, withdrawalFee }) => {
|
|
85
|
+
console.log('Withdrawal:', withdrawalRequestId, amount, assetSymbol, networkFee, withdrawalFee);
|
|
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
|
+
### CspCryptoWithdrawals 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, assetSymbol, amount, networkFee, withdrawalFee }) => 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,152 @@
|
|
|
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 CSP Crypto Withdrawals product.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```tsx
|
|
20
|
+
* <CspCryptoWithdrawals
|
|
21
|
+
* jwt="your-jwt-token"
|
|
22
|
+
* theme="auto"
|
|
23
|
+
* onLoaded={() => console.log('CSP Crypto Withdrawals loaded and ready')}
|
|
24
|
+
* onCompleted={(data) => console.log('Withdrawal complete', data)}
|
|
25
|
+
* onClose={() => console.log('CSP Crypto Withdrawals closed')}
|
|
26
|
+
* onError={({ errorCode, reason }) => console.error('Error:', errorCode, reason)}
|
|
27
|
+
* onEvent={(event) => console.log('Event:', event)}
|
|
28
|
+
* />
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare const CspCryptoWithdrawals: default_2.FC<CspCryptoWithdrawalsProps>;
|
|
32
|
+
|
|
33
|
+
declare type CspCryptoWithdrawalsCompletedData = {
|
|
34
|
+
/** ID of the withdrawal request */
|
|
35
|
+
withdrawalRequestId: string;
|
|
36
|
+
/** Symbol of the asset being withdrawn (e.g. 'BTC') */
|
|
37
|
+
assetSymbol: string;
|
|
38
|
+
/** Amount being withdrawn as a string */
|
|
39
|
+
amount: string;
|
|
40
|
+
/** Network fee as a string */
|
|
41
|
+
networkFee: string;
|
|
42
|
+
/** Withdrawal fee as a string */
|
|
43
|
+
withdrawalFee: string;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* CSP Crypto Withdrawals event structure
|
|
48
|
+
*/
|
|
49
|
+
declare type CspCryptoWithdrawalsEvent = AppEvent<CspCryptoWithdrawalsEventType>;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* CSP Crypto Withdrawals event type literals
|
|
53
|
+
*/
|
|
54
|
+
declare type CspCryptoWithdrawalsEventType = string;
|
|
55
|
+
|
|
56
|
+
declare interface CspCryptoWithdrawalsProps {
|
|
57
|
+
/**
|
|
58
|
+
* JWT token used for authentication with the Connect CSP Crypto Withdrawals service.
|
|
59
|
+
*
|
|
60
|
+
* @example "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
|
|
61
|
+
*/
|
|
62
|
+
jwt: string;
|
|
63
|
+
/**
|
|
64
|
+
* Target environment for the Connect CSP Crypto Withdrawals service.
|
|
65
|
+
*
|
|
66
|
+
* @default "prod"
|
|
67
|
+
*/
|
|
68
|
+
env?: Environment;
|
|
69
|
+
/**
|
|
70
|
+
* Theme mode for the Connect CSP Crypto Withdrawals interface.
|
|
71
|
+
*
|
|
72
|
+
* @default "auto"
|
|
73
|
+
*/
|
|
74
|
+
theme?: Theme;
|
|
75
|
+
/**
|
|
76
|
+
* Callback invoked when the CSP crypto withdrawal flow is successfully completed.
|
|
77
|
+
*
|
|
78
|
+
* @param data - Details about the completed withdrawal
|
|
79
|
+
*/
|
|
80
|
+
onCompleted?: (data: CspCryptoWithdrawalsCompletedData) => void;
|
|
81
|
+
/**
|
|
82
|
+
* Callback invoked when an error occurs during the CSP crypto withdrawal flow.
|
|
83
|
+
*
|
|
84
|
+
* @param error - Error details including error code and reason
|
|
85
|
+
*/
|
|
86
|
+
onError?: (error: ErrorPayload) => void;
|
|
87
|
+
/**
|
|
88
|
+
* Callback invoked when the user closes the CSP crypto withdrawals widget.
|
|
89
|
+
*/
|
|
90
|
+
onClose?: () => void;
|
|
91
|
+
/**
|
|
92
|
+
* Callback invoked when the CSP crypto withdrawals widget has finished loading and is ready.
|
|
93
|
+
*/
|
|
94
|
+
onLoaded?: () => void;
|
|
95
|
+
/**
|
|
96
|
+
* Callback invoked for general application events during the CSP crypto withdrawals flow.
|
|
97
|
+
*
|
|
98
|
+
* @param event - Event object containing the event type and associated data
|
|
99
|
+
*/
|
|
100
|
+
onEvent?: (event: CspCryptoWithdrawalsEvent) => void;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Available environments for the Connect CSP Crypto Withdrawals service.
|
|
105
|
+
*
|
|
106
|
+
* - `"local"` - Local development environment
|
|
107
|
+
* - `"dev"` - Development environment for early-stage testing
|
|
108
|
+
* - `"cert"` - Certificate/staging environment for integration testing
|
|
109
|
+
* - `"prod"` - Live production environment for real applications
|
|
110
|
+
*/
|
|
111
|
+
declare type Environment = 'local' | 'dev' | 'cert' | 'prod';
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Generic error codes for all Connect applications
|
|
115
|
+
*/
|
|
116
|
+
declare enum ErrorCode {
|
|
117
|
+
/** Network connectivity error */
|
|
118
|
+
NETWORK_ERROR = 'network_error',
|
|
119
|
+
/** Authentication or session expired error */
|
|
120
|
+
AUTH_ERROR = 'auth_error',
|
|
121
|
+
/** Resource not found error */
|
|
122
|
+
NOT_FOUND_ERROR = 'not_found_error',
|
|
123
|
+
/** Validation error from user input */
|
|
124
|
+
VALIDATION_ERROR = 'validation_error',
|
|
125
|
+
/** Server error (5xx) */
|
|
126
|
+
SERVER_ERROR = 'server_error',
|
|
127
|
+
/** Client error (4xx) */
|
|
128
|
+
CLIENT_ERROR = 'client_error',
|
|
129
|
+
/** Unknown or unexpected error */
|
|
130
|
+
UNKNOWN_ERROR = 'unknown_error',
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Generic error payload structure for error callbacks
|
|
135
|
+
*/
|
|
136
|
+
declare type ErrorPayload = {
|
|
137
|
+
/** Error code indicating the type of error */
|
|
138
|
+
errorCode: ErrorCode;
|
|
139
|
+
/** Human-readable reason for the error */
|
|
140
|
+
reason: string;
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Theme mode for the Connect CSP Crypto Withdrawals interface.
|
|
145
|
+
*
|
|
146
|
+
* - `"auto"` - Automatically detect system preference (light/dark mode)
|
|
147
|
+
* - `"light"` - Force light theme
|
|
148
|
+
* - `"dark"` - Force dark theme
|
|
149
|
+
*/
|
|
150
|
+
declare type Theme = 'auto' | 'light' | 'dark';
|
|
151
|
+
|
|
152
|
+
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/csp-crypto-withdrawals-web/index.js",
|
|
4
|
+
dev: "https://connect-sdk.dev.0hash.com/csp-crypto-withdrawals-web/index.js",
|
|
5
|
+
cert: "https://sdk.sandbox.connect.xyz/csp-crypto-withdrawals-web/index.js",
|
|
6
|
+
prod: "https://sdk.connect.xyz/csp-crypto-withdrawals-web/index.js"
|
|
7
|
+
}, x = "zerohash-csp-crypto-withdrawals-script", h = "zerohash-csp-crypto-withdrawals", b = (e = "prod") => y[e], R = ({
|
|
8
|
+
jwt: e,
|
|
9
|
+
env: c = "prod",
|
|
10
|
+
theme: w,
|
|
11
|
+
onCompleted: s,
|
|
12
|
+
onError: o,
|
|
13
|
+
onClose: p,
|
|
14
|
+
onLoaded: n,
|
|
15
|
+
onEvent: i,
|
|
16
|
+
...f
|
|
17
|
+
}) => {
|
|
18
|
+
const d = m(null);
|
|
19
|
+
return l(() => {
|
|
20
|
+
const t = d.current;
|
|
21
|
+
t && (s && (t.onCompleted = s), o && (t.onError = o), p && (t.onClose = p), n && (t.onLoaded = n), i && (t.onEvent = i));
|
|
22
|
+
}, [s, o, p, n, i]), l(() => {
|
|
23
|
+
const t = b(c), a = `${x}-${c}`;
|
|
24
|
+
if (document.getElementById(a))
|
|
25
|
+
return;
|
|
26
|
+
const r = document.createElement("script");
|
|
27
|
+
r.id = a, r.src = t, r.type = "module", r.async = !0, r.onerror = () => {
|
|
28
|
+
console.error(`Failed to load the script for ${h} from ${c} environment.`);
|
|
29
|
+
}, document.head.appendChild(r);
|
|
30
|
+
}, [c]), u.createElement(h, {
|
|
31
|
+
ref: d,
|
|
32
|
+
jwt: e,
|
|
33
|
+
env: c,
|
|
34
|
+
theme: w,
|
|
35
|
+
...f
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
export {
|
|
39
|
+
R as CspCryptoWithdrawals
|
|
40
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@zerohash-sdk/csp-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": "csp-crypto-withdrawals-react"
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"react": ">=18.0.0",
|
|
27
|
+
"react-dom": ">=18.0.0"
|
|
28
|
+
}
|
|
29
|
+
}
|