@zerohash-sdk/csp-fiat-withdrawals-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 +7 -0
- package/dist/index.d.ts +152 -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,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 Zerohash CSP Fiat Withdrawals 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 fiat 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
|
+
* <CspFiatWithdrawals jwt="your-jwt-token" />
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @returns React component that renders the Zerohash CSP Fiat Withdrawals interface
|
|
34
|
+
*/
|
|
35
|
+
export declare const CspFiatWithdrawals: default_2.FC<CspFiatWithdrawalsProps>;
|
|
36
|
+
|
|
37
|
+
declare type CspFiatWithdrawalsCompletedData = {
|
|
38
|
+
/** Amount withdrawn as a string */
|
|
39
|
+
amountWithdrawn: string;
|
|
40
|
+
/** Symbol of the fiat currency that was withdrawn (e.g. 'USD') */
|
|
41
|
+
assetSymbol: string;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* CSP fiat withdrawals event structure
|
|
46
|
+
*/
|
|
47
|
+
declare type CspFiatWithdrawalsEvent = AppEvent<CspFiatWithdrawalsEventType>;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* CSP fiat withdrawals event type literals
|
|
51
|
+
*/
|
|
52
|
+
declare type CspFiatWithdrawalsEventType = string;
|
|
53
|
+
|
|
54
|
+
declare interface CspFiatWithdrawalsProps {
|
|
55
|
+
/**
|
|
56
|
+
* JWT token used for authentication with the Zerohash CSP Fiat Withdrawals service.
|
|
57
|
+
* This token should be obtained from your backend and contain the necessary
|
|
58
|
+
* claims for user identification and authorization.
|
|
59
|
+
*
|
|
60
|
+
* @example "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
|
|
61
|
+
*/
|
|
62
|
+
jwt: string;
|
|
63
|
+
/**
|
|
64
|
+
* Target environment for the Zerohash CSP Fiat Withdrawals service.
|
|
65
|
+
*
|
|
66
|
+
* @default "prod"
|
|
67
|
+
*/
|
|
68
|
+
env?: Environment;
|
|
69
|
+
/**
|
|
70
|
+
* Theme mode for the Zerohash CSP Fiat Withdrawals interface.
|
|
71
|
+
*
|
|
72
|
+
* @default "auto"
|
|
73
|
+
*/
|
|
74
|
+
theme?: Theme;
|
|
75
|
+
/**
|
|
76
|
+
* Callback invoked when the CSP fiat withdrawals flow is successfully completed.
|
|
77
|
+
*
|
|
78
|
+
* @param data - Details about the completed withdrawal, including amount withdrawn and asset symbol
|
|
79
|
+
*/
|
|
80
|
+
onCompleted?: (data: CspFiatWithdrawalsCompletedData) => void;
|
|
81
|
+
/**
|
|
82
|
+
* Callback invoked when an error occurs during the CSP fiat withdrawals 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 fiat withdrawals widget.
|
|
89
|
+
*/
|
|
90
|
+
onClose?: () => void;
|
|
91
|
+
/**
|
|
92
|
+
* Callback invoked when the CSP fiat withdrawals widget has finished loading and is ready.
|
|
93
|
+
*/
|
|
94
|
+
onLoaded?: () => void;
|
|
95
|
+
/**
|
|
96
|
+
* Callback invoked for general application events during the CSP fiat withdrawals flow.
|
|
97
|
+
*
|
|
98
|
+
* @param event - Event object containing the event type and associated data
|
|
99
|
+
*/
|
|
100
|
+
onEvent?: (event: CspFiatWithdrawalsEvent) => void;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Available environments for the Zerohash CSP Fiat 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 Zerohash CSP Fiat 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 x = {
|
|
3
|
+
local: "http://localhost:5173/csp-fiat-withdrawals-web/index.js",
|
|
4
|
+
dev: "https://connect-sdk.dev.0hash.com/csp-fiat-withdrawals-web/index.js",
|
|
5
|
+
cert: "https://sdk.sandbox.connect.xyz/csp-fiat-withdrawals-web/index.js",
|
|
6
|
+
prod: "https://sdk.connect.xyz/csp-fiat-withdrawals-web/index.js"
|
|
7
|
+
}, b = "zerohash-csp-fiat-withdrawals-script", h = "zerohash-csp-fiat-withdrawals", y = (r = "prod") => x[r], R = ({
|
|
8
|
+
jwt: r,
|
|
9
|
+
env: s = "prod",
|
|
10
|
+
theme: f,
|
|
11
|
+
onCompleted: c,
|
|
12
|
+
onError: i,
|
|
13
|
+
onClose: a,
|
|
14
|
+
onLoaded: n,
|
|
15
|
+
onEvent: o,
|
|
16
|
+
...w
|
|
17
|
+
}) => {
|
|
18
|
+
const d = m(null);
|
|
19
|
+
return l(() => {
|
|
20
|
+
const t = d.current;
|
|
21
|
+
t && (c && (t.onCompleted = c), i && (t.onError = i), a && (t.onClose = a), n && (t.onLoaded = n), o && (t.onEvent = o));
|
|
22
|
+
}, [c, i, a, n, o]), l(() => {
|
|
23
|
+
const t = y(s), p = `${b}-${s}`;
|
|
24
|
+
if (document.getElementById(p))
|
|
25
|
+
return;
|
|
26
|
+
const e = document.createElement("script");
|
|
27
|
+
e.id = p, e.src = t, e.type = "module", e.async = !0, e.onerror = () => {
|
|
28
|
+
console.error(`Failed to load the script for ${h} from ${s} environment.`);
|
|
29
|
+
}, document.head.appendChild(e);
|
|
30
|
+
}, [s]), u.createElement(h, {
|
|
31
|
+
ref: d,
|
|
32
|
+
jwt: r,
|
|
33
|
+
env: s,
|
|
34
|
+
theme: f,
|
|
35
|
+
...w
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
export {
|
|
39
|
+
R as CspFiatWithdrawals
|
|
40
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@zerohash-sdk/csp-fiat-withdrawals-react",
|
|
3
|
+
"version": "0.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-fiat-withdrawals-react"
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"react": ">=18.0.0",
|
|
27
|
+
"react-dom": ">=18.0.0"
|
|
28
|
+
}
|
|
29
|
+
}
|