@connect-xyz/withdraw-react 0.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 +140 -0
- package/dist/index.d.ts +221 -0
- package/dist/index.js +37 -0
- package/package.json +27 -0
package/README.md
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# @connect-xyz/withdraw-react
|
|
2
|
+
|
|
3
|
+
A React SDK that enables frontend React applications to seamlessly integrate with the Connect Withdraw product.
|
|
4
|
+
|
|
5
|
+
Connect Withdraw provides a secure way for end users to withdraw their funds. Learn more in the [Connect Withdraw documentation](https://docs.zerohash.com/docs/withdraw).
|
|
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 @connect-xyz/withdraw-react
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Getting Started
|
|
19
|
+
|
|
20
|
+
Follow these simple steps to integrate Withdraw into your React application:
|
|
21
|
+
|
|
22
|
+
### 1. Import the Withdraw Component
|
|
23
|
+
|
|
24
|
+
```tsx
|
|
25
|
+
import { Withdraw } from '@connect-xyz/withdraw-react';
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### 2. Add the Withdraw Component to Your App
|
|
29
|
+
|
|
30
|
+
```tsx
|
|
31
|
+
function App() {
|
|
32
|
+
const jwt = 'your-jwt-token'; // Obtain this from your backend authentication
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<Withdraw
|
|
36
|
+
jwt={jwt}
|
|
37
|
+
env="production" // or "sandbox" for testing
|
|
38
|
+
/>
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### 3. Configure Event Callbacks (Optional)
|
|
44
|
+
|
|
45
|
+
Listen to events from the Withdraw SDK to handle user interactions:
|
|
46
|
+
|
|
47
|
+
```tsx
|
|
48
|
+
function App() {
|
|
49
|
+
const jwt = 'your-jwt-token';
|
|
50
|
+
|
|
51
|
+
const handleError = ({ errorCode, reason }) => {
|
|
52
|
+
console.log('Withdraw error occurred:', errorCode, 'Reason:', reason);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const handleClose = () => {
|
|
56
|
+
console.log('Withdraw widget closed');
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const handleWithdrawal = ({ data }) => {
|
|
60
|
+
console.log('Withdrawal data:', data);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const handleEvent = ({ type, data }) => {
|
|
64
|
+
console.log('Withdraw event:', type, 'Data:', data);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<Withdraw
|
|
69
|
+
jwt={jwt}
|
|
70
|
+
env="production"
|
|
71
|
+
onError={handleError}
|
|
72
|
+
onClose={handleClose}
|
|
73
|
+
onWithdrawal={handleWithdrawal}
|
|
74
|
+
onEvent={handleEvent}
|
|
75
|
+
/>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
For detailed information about callback events and their payloads, see the [Connect SDKs Callbacks documentation](https://docs.zerohash.com/docs/front-end-callbacks).
|
|
81
|
+
|
|
82
|
+
## Complete Example
|
|
83
|
+
|
|
84
|
+
Here's a full example of integrating Connect Withdraw into your React application:
|
|
85
|
+
|
|
86
|
+
```tsx
|
|
87
|
+
import React from 'react';
|
|
88
|
+
import { Withdraw } from '@connect-xyz/withdraw-react';
|
|
89
|
+
|
|
90
|
+
function App() {
|
|
91
|
+
// JWT token should be obtained from your backend
|
|
92
|
+
const jwt = 'your-jwt-token';
|
|
93
|
+
|
|
94
|
+
// Choose environment: "production" for live apps, "sandbox" for testing
|
|
95
|
+
const environment = 'production';
|
|
96
|
+
|
|
97
|
+
return (
|
|
98
|
+
<div className="App">
|
|
99
|
+
<h1>My Crypto App</h1>
|
|
100
|
+
|
|
101
|
+
<Withdraw
|
|
102
|
+
jwt={jwt}
|
|
103
|
+
env={environment}
|
|
104
|
+
onError={({ errorCode, reason }) => {
|
|
105
|
+
console.log('Error:', errorCode, 'Reason:', reason);
|
|
106
|
+
}}
|
|
107
|
+
onClose={() => {
|
|
108
|
+
console.log('Withdraw widget closed');
|
|
109
|
+
}}
|
|
110
|
+
onWithdrawal={({ data }) => {
|
|
111
|
+
console.log('Withdrawal successful:', data);
|
|
112
|
+
}}
|
|
113
|
+
onEvent={({ type, data }) => {
|
|
114
|
+
console.log('Event type:', type, 'Event data:', data);
|
|
115
|
+
}}
|
|
116
|
+
/>
|
|
117
|
+
</div>
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export default App;
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## API Reference
|
|
125
|
+
|
|
126
|
+
### Withdraw Component Props
|
|
127
|
+
|
|
128
|
+
| Prop | Type | Required | Default | Description |
|
|
129
|
+
| -------------- | --------------------------------- | -------- | -------------- | -------------------------------------------------- |
|
|
130
|
+
| `jwt` | `string` | Yes | - | JWT token for authentication with Connect Withdraw |
|
|
131
|
+
| `env` | `"production" \| "sandbox"` | No | `"production"` | Target environment |
|
|
132
|
+
| `theme` | `"auto" \| "light" \| "dark"` | No | `"auto"` | Theme mode for the interface |
|
|
133
|
+
| `onError` | `({ errorCode, reason }) => void` | No | - | Callback for error events |
|
|
134
|
+
| `onClose` | `() => void` | No | - | Callback when the widget is closed |
|
|
135
|
+
| `onWithdrawal` | `({ data }) => void` | No | - | Callback for withdrawal completed |
|
|
136
|
+
| `onEvent` | `({ type, data }) => void` | No | - | Callback for general events |
|
|
137
|
+
|
|
138
|
+
## More Information & Support
|
|
139
|
+
|
|
140
|
+
For comprehensive documentation or support about Connect Withdraw, visit our [Documentation Page](https://docs.zerohash.com/docs/withdraw).
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
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
|
+
* Common callback function types shared across all Connect apps
|
|
17
|
+
* @template TEvent - The event type for onEvent callback
|
|
18
|
+
*/
|
|
19
|
+
declare type CommonCallbacks<TEvent = AppEvent> = {
|
|
20
|
+
/** Called when an error occurs */
|
|
21
|
+
onError?: (error: ErrorPayload) => void;
|
|
22
|
+
/** Called when the component is closed */
|
|
23
|
+
onClose?: () => void;
|
|
24
|
+
/** Called when a general event occurs */
|
|
25
|
+
onEvent?: (event: TEvent) => void;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Available environments for the Connect Withdraw service.
|
|
30
|
+
*
|
|
31
|
+
* - `"sandbox"` - Certificate/testing environment for integration and testing
|
|
32
|
+
* - `"production"` - Live production environment for real applications
|
|
33
|
+
*/
|
|
34
|
+
declare type Environment = 'sandbox' | 'production';
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Generic error codes for all Connect applications
|
|
38
|
+
*/
|
|
39
|
+
declare enum ErrorCode {
|
|
40
|
+
/** Network connectivity error */
|
|
41
|
+
NETWORK_ERROR = 'network_error',
|
|
42
|
+
/** Authentication or session expired error */
|
|
43
|
+
AUTH_ERROR = 'auth_error',
|
|
44
|
+
/** Resource not found error */
|
|
45
|
+
NOT_FOUND_ERROR = 'not_found_error',
|
|
46
|
+
/** Validation error from user input */
|
|
47
|
+
VALIDATION_ERROR = 'validation_error',
|
|
48
|
+
/** Server error (5xx) */
|
|
49
|
+
SERVER_ERROR = 'server_error',
|
|
50
|
+
/** Client error (4xx) */
|
|
51
|
+
CLIENT_ERROR = 'client_error',
|
|
52
|
+
/** Unknown or unexpected error */
|
|
53
|
+
UNKNOWN_ERROR = 'unknown_error',
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Generic error payload structure for error callbacks
|
|
58
|
+
*/
|
|
59
|
+
declare type ErrorPayload = {
|
|
60
|
+
/** Error code indicating the type of error */
|
|
61
|
+
errorCode: ErrorCode;
|
|
62
|
+
/** Human-readable reason for the error */
|
|
63
|
+
reason: string;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Theme mode for the Connect Withdraw interface.
|
|
68
|
+
*
|
|
69
|
+
* - `"auto"` - Automatically detect system preference (light/dark mode)
|
|
70
|
+
* - `"light"` - Force light theme
|
|
71
|
+
* - `"dark"` - Force dark theme
|
|
72
|
+
*/
|
|
73
|
+
declare type Theme = 'auto' | 'light' | 'dark';
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* A React wrapper component for the Connect Withdraw product.
|
|
77
|
+
*
|
|
78
|
+
* @param props - Component properties
|
|
79
|
+
* @param jwt - JWT token for authentication (required)
|
|
80
|
+
* @param env - Target environment ("sandbox" | "production", defaults to "production")
|
|
81
|
+
* @param theme - Theme mode ("auto" | "light" | "dark", defaults to "auto")
|
|
82
|
+
* @param onError - Callback function for error handling
|
|
83
|
+
* @param onClose - Callback function for close events
|
|
84
|
+
* @param onWithdrawal - Callback function for withdrawal events
|
|
85
|
+
* @param onEvent - Callback function for general events
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```tsx
|
|
89
|
+
* // Basic usage with production environment (default)
|
|
90
|
+
* <Withdraw jwt="your-jwt-token" />
|
|
91
|
+
*
|
|
92
|
+
* // Using sandbox environment for testing
|
|
93
|
+
* <Withdraw jwt="your-jwt-token" env="sandbox" />
|
|
94
|
+
*
|
|
95
|
+
* // Force dark theme
|
|
96
|
+
* <Withdraw jwt="your-jwt-token" theme="dark" />
|
|
97
|
+
*
|
|
98
|
+
* // With callback functions
|
|
99
|
+
* <Withdraw
|
|
100
|
+
* jwt="your-jwt-token"
|
|
101
|
+
* theme="auto"
|
|
102
|
+
* onError={({ errorCode, reason }) => console.error('Withdraw error:', errorCode, 'Reason:', reason)}
|
|
103
|
+
* onClose={() => console.log('Withdraw closed')}
|
|
104
|
+
* onWithdrawal={({ data }) => console.log('Withdrawal completed:', data.withdrawalId, 'Status:', data.status.value)}
|
|
105
|
+
* onEvent={({ type, data }) => console.log('Event:', type, 'Withdrawal ID:', data.withdrawalId)}
|
|
106
|
+
* />
|
|
107
|
+
* ```
|
|
108
|
+
*
|
|
109
|
+
* @returns React component that renders the Connect Withdraw interface
|
|
110
|
+
*/
|
|
111
|
+
export declare const Withdraw: default_2.FC<WithdrawWrapperProps>;
|
|
112
|
+
|
|
113
|
+
declare type WithdrawalCompletedPayload = {
|
|
114
|
+
/** Data associated with the withdrawal */
|
|
115
|
+
data: {
|
|
116
|
+
/** Unique identifier for the withdrawal */
|
|
117
|
+
withdrawalId: string;
|
|
118
|
+
/** Current status of the withdrawal */
|
|
119
|
+
status: WithdrawalStatus;
|
|
120
|
+
/** Asset identifier (e.g., 'btc', 'eth') */
|
|
121
|
+
assetId: string;
|
|
122
|
+
/** Network identifier (e.g., 'bitcoin', 'ethereum') */
|
|
123
|
+
networkId: string;
|
|
124
|
+
/** Amount being withdrawn */
|
|
125
|
+
amount?: string;
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Withdrawal initiated event data
|
|
131
|
+
*/
|
|
132
|
+
declare type WithdrawalInitiatedEventData = {
|
|
133
|
+
/** Unique identifier for the withdrawal */
|
|
134
|
+
withdrawalId: string;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
declare type WithdrawalStatus = {
|
|
138
|
+
/** Status value */
|
|
139
|
+
value: string;
|
|
140
|
+
/** Human-readable details about the status */
|
|
141
|
+
details: string;
|
|
142
|
+
/** Timestamp when the status occurred (ISO 8601 format) */
|
|
143
|
+
occurredAt: string;
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Callback function types for Connect Withdraw components
|
|
148
|
+
* Extends common callbacks with withdraw-specific callbacks
|
|
149
|
+
*/
|
|
150
|
+
declare type WithdrawCallbacks = CommonCallbacks<WithdrawEvent> & {
|
|
151
|
+
/** Called when a withdrawal action occurs */
|
|
152
|
+
onWithdrawal?: (withdrawal: WithdrawalCompletedPayload) => void;
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Withdraw event structure
|
|
157
|
+
*/
|
|
158
|
+
declare type WithdrawEvent = AppEvent<WithdrawEventType, WithdrawalInitiatedEventData>;
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Withdraw event type literals
|
|
162
|
+
*/
|
|
163
|
+
declare type WithdrawEventType = 'withdrawal.initiated' | 'withdrawal.submitted' | 'withdrawal.completed';
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Props for the Withdraw component
|
|
167
|
+
*/
|
|
168
|
+
declare interface WithdrawWrapperProps extends WithdrawCallbacks {
|
|
169
|
+
/**
|
|
170
|
+
* JWT token used for authentication with the Connect Withdraw service.
|
|
171
|
+
* This token should be obtained from your authentication system and
|
|
172
|
+
* contain the necessary claims for user identification and authorization.
|
|
173
|
+
*
|
|
174
|
+
* @example "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
|
|
175
|
+
*/
|
|
176
|
+
jwt: string;
|
|
177
|
+
/**
|
|
178
|
+
* Target environment.
|
|
179
|
+
*
|
|
180
|
+
* @default "production"
|
|
181
|
+
*
|
|
182
|
+
* Available environments:
|
|
183
|
+
* - `"sandbox"` - Certificate/testing environment for integration testing
|
|
184
|
+
* - `"production"` - Live production environment for real applications
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* ```tsx
|
|
188
|
+
* // Use production (default)
|
|
189
|
+
* <Withdraw jwt={token} />
|
|
190
|
+
*
|
|
191
|
+
* // Use sandbox for testing
|
|
192
|
+
* <Withdraw jwt={token} env="sandbox" />
|
|
193
|
+
* ```
|
|
194
|
+
*/
|
|
195
|
+
env?: Environment;
|
|
196
|
+
/**
|
|
197
|
+
* Theme mode.
|
|
198
|
+
*
|
|
199
|
+
* @default "auto"
|
|
200
|
+
*
|
|
201
|
+
* Available themes:
|
|
202
|
+
* - `"auto"` - Automatically detect system preference (light/dark mode)
|
|
203
|
+
* - `"light"` - Force light theme
|
|
204
|
+
* - `"dark"` - Force dark theme
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* ```tsx
|
|
208
|
+
* // Auto-detect system preference (default)
|
|
209
|
+
* <Withdraw jwt={token} />
|
|
210
|
+
*
|
|
211
|
+
* // Force dark theme
|
|
212
|
+
* <Withdraw jwt={token} theme="dark" />
|
|
213
|
+
*
|
|
214
|
+
* // Force light theme
|
|
215
|
+
* <Withdraw jwt={token} theme="light" />
|
|
216
|
+
* ```
|
|
217
|
+
*/
|
|
218
|
+
theme?: Theme;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
export { }
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import l, { useRef as w, useEffect as u } from "react";
|
|
2
|
+
const h = {
|
|
3
|
+
sandbox: "https://sdk.sandbox.connect.xyz/withdraw-web/index.js",
|
|
4
|
+
production: "https://sdk.connect.xyz/withdraw-web/index.js"
|
|
5
|
+
}, x = "connect-withdraw-script", a = "connect-withdraw", y = (c = "production") => h[c], R = ({
|
|
6
|
+
jwt: c,
|
|
7
|
+
env: r = "production",
|
|
8
|
+
theme: f,
|
|
9
|
+
onError: n,
|
|
10
|
+
onClose: o,
|
|
11
|
+
onEvent: s,
|
|
12
|
+
onWithdrawal: i,
|
|
13
|
+
...m
|
|
14
|
+
}) => {
|
|
15
|
+
const d = w(null);
|
|
16
|
+
return u(() => {
|
|
17
|
+
const t = d.current;
|
|
18
|
+
t && (n && (t.onError = n), o && (t.onClose = o), s && (t.onEvent = s), i && (t.onWithdrawal = i));
|
|
19
|
+
}, [n, o, s, i]), u(() => {
|
|
20
|
+
const t = y(r), p = `${x}-${r}`;
|
|
21
|
+
if (document.getElementById(p))
|
|
22
|
+
return;
|
|
23
|
+
const e = document.createElement("script");
|
|
24
|
+
e.id = p, e.src = t, e.type = "module", e.async = !0, e.onerror = () => {
|
|
25
|
+
console.error(`Failed to load the script for ${a} from ${r} environment.`);
|
|
26
|
+
}, document.head.appendChild(e);
|
|
27
|
+
}, [r]), l.createElement(a, {
|
|
28
|
+
ref: d,
|
|
29
|
+
jwt: c,
|
|
30
|
+
env: r,
|
|
31
|
+
theme: f,
|
|
32
|
+
...m
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
export {
|
|
36
|
+
R as Withdraw
|
|
37
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@connect-xyz/withdraw-react",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
"./package.json": "./package.json",
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"!**/*.tsbuildinfo"
|
|
19
|
+
],
|
|
20
|
+
"nx": {
|
|
21
|
+
"name": "withdraw-react"
|
|
22
|
+
},
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"react": ">=18.0.0",
|
|
25
|
+
"react-dom": ">=18.0.0"
|
|
26
|
+
}
|
|
27
|
+
}
|