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