@voyage_ai/v402-web-ts 0.1.1 → 0.1.3
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/dist/index.d.mts +14 -2
- package/dist/index.d.ts +14 -2
- package/dist/index.js +156 -106
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +139 -88
- package/dist/index.mjs.map +1 -1
- package/dist/react/index.d.mts +62 -52
- package/dist/react/index.d.ts +62 -52
- package/dist/react/index.js +901 -227
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +884 -203
- package/dist/react/index.mjs.map +1 -1
- package/dist/react/styles.css +1 -168
- package/package.json +33 -10
- package/dist/react/components/PaymentButton.tsx +0 -119
- package/dist/react/components/WalletConnect.tsx +0 -152
- package/dist/react/hooks/usePayment.ts +0 -109
- package/dist/react/hooks/usePaymentInfo.ts +0 -94
- package/dist/react/hooks/useWallet.ts +0 -174
- package/dist/react/hooks/useWalletStore.ts +0 -61
- package/dist/react/index.ts +0 -42
- package/dist/react/store/walletStore.ts +0 -181
- package/dist/react/styles/inline-styles.ts +0 -227
package/dist/react/index.d.ts
CHANGED
|
@@ -29,6 +29,8 @@ interface UseWalletReturn {
|
|
|
29
29
|
isConnecting: boolean;
|
|
30
30
|
error: string | null;
|
|
31
31
|
connect: (networkType: NetworkType) => Promise<void>;
|
|
32
|
+
switchNetwork: (networkType: NetworkType) => Promise<void>;
|
|
33
|
+
ensureNetwork: (networkType: NetworkType) => Promise<void>;
|
|
32
34
|
disconnect: () => void;
|
|
33
35
|
clearError: () => void;
|
|
34
36
|
}
|
|
@@ -55,6 +57,38 @@ interface UseWalletReturn {
|
|
|
55
57
|
*/
|
|
56
58
|
declare function useWallet(): UseWalletReturn;
|
|
57
59
|
|
|
60
|
+
interface UsePageNetworkOptions {
|
|
61
|
+
/** 是否自动切换网络(默认 true) */
|
|
62
|
+
autoSwitch?: boolean;
|
|
63
|
+
/** 是否在组件挂载时立即切换(默认 true) */
|
|
64
|
+
switchOnMount?: boolean;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* 页面级网络管理 Hook
|
|
68
|
+
*
|
|
69
|
+
* 用于确保页面始终连接到期望的网络
|
|
70
|
+
* 自动处理网络切换,保持其他网络的缓存不受影响
|
|
71
|
+
*
|
|
72
|
+
* @param expectedNetwork - 页面期望的网络类型(NetworkType,如 EVM、SVM)
|
|
73
|
+
* @param options - 配置选项
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```tsx
|
|
77
|
+
* // EVM 页面
|
|
78
|
+
* function EvmPage() {
|
|
79
|
+
* const { address, isConnecting } = usePageNetwork(NetworkType.EVM);
|
|
80
|
+
* return <div>{isConnecting ? 'Connecting...' : address}</div>;
|
|
81
|
+
* }
|
|
82
|
+
*
|
|
83
|
+
* // SVM 页面
|
|
84
|
+
* function SvmPage() {
|
|
85
|
+
* const { address, isConnecting } = usePageNetwork(NetworkType.SVM);
|
|
86
|
+
* return <div>{isConnecting ? 'Connecting...' : address}</div>;
|
|
87
|
+
* }
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
declare function usePageNetwork(expectedNetwork: NetworkType, options?: UsePageNetworkOptions): UseWalletReturn;
|
|
91
|
+
|
|
58
92
|
/**
|
|
59
93
|
* usePayment Hook
|
|
60
94
|
*
|
|
@@ -143,6 +177,7 @@ interface UsePaymentInfoReturn {
|
|
|
143
177
|
*
|
|
144
178
|
* @param endpoint - API endpoint to fetch payment info from
|
|
145
179
|
* @param merchantId - @see our website to apply
|
|
180
|
+
* @param additionalParams - Optional additional parameters to send with the request (default: {})
|
|
146
181
|
*
|
|
147
182
|
* @example
|
|
148
183
|
* ```tsx
|
|
@@ -159,8 +194,20 @@ interface UsePaymentInfoReturn {
|
|
|
159
194
|
* );
|
|
160
195
|
* }
|
|
161
196
|
* ```
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* ```tsx
|
|
200
|
+
* // With additional parameters
|
|
201
|
+
* function PaymentInfo() {
|
|
202
|
+
* const { paymentInfo } = usePaymentInfo(
|
|
203
|
+
* 'merchant-id',
|
|
204
|
+
* '/api/protected',
|
|
205
|
+
* { userId: '123', customField: 'value' }
|
|
206
|
+
* );
|
|
207
|
+
* }
|
|
208
|
+
* ```
|
|
162
209
|
*/
|
|
163
|
-
declare function usePaymentInfo(merchantId: string, endpoint?: string): UsePaymentInfoReturn;
|
|
210
|
+
declare function usePaymentInfo(merchantId: string, endpoint?: string, additionalParams?: Record<string, any>): UsePaymentInfoReturn;
|
|
164
211
|
|
|
165
212
|
/**
|
|
166
213
|
* WalletConnect Component
|
|
@@ -193,56 +240,19 @@ interface WalletConnectProps {
|
|
|
193
240
|
*/
|
|
194
241
|
declare function WalletConnect({ supportedNetworks, className, onConnect, onDisconnect, }: WalletConnectProps): React.JSX.Element;
|
|
195
242
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
* Note: This is a simple wrapper. For complex payment flows,
|
|
201
|
-
* use the SDK directly with usePayment hook for full control.
|
|
202
|
-
*/
|
|
203
|
-
|
|
204
|
-
interface PaymentButtonProps {
|
|
205
|
-
endpoint: string;
|
|
206
|
-
className?: string;
|
|
207
|
-
disabled?: boolean;
|
|
208
|
-
onSuccess?: (result: any) => void;
|
|
209
|
-
onError?: (error: string) => void;
|
|
210
|
-
onStart?: () => void;
|
|
211
|
-
onFinish?: () => void;
|
|
212
|
-
children?: React.ReactNode;
|
|
243
|
+
interface HeaderInfo {
|
|
244
|
+
title?: string;
|
|
245
|
+
subtitle?: string;
|
|
246
|
+
tooltipText?: string;
|
|
213
247
|
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
*
|
|
224
|
-
* function CustomPayment() {
|
|
225
|
-
* const { networkType } = useWallet();
|
|
226
|
-
* const { isProcessing, setIsProcessing, setResult, setError } = usePayment();
|
|
227
|
-
*
|
|
228
|
-
* const handlePay = async () => {
|
|
229
|
-
* setIsProcessing(true);
|
|
230
|
-
* try {
|
|
231
|
-
* // Your custom logic before payment
|
|
232
|
-
* const response = await handleSvmPayment(...);
|
|
233
|
-
* const data = await response.json();
|
|
234
|
-
*
|
|
235
|
-
* // Your custom logic after payment
|
|
236
|
-
* setResult(data);
|
|
237
|
-
* } catch (err) {
|
|
238
|
-
* setError(err.message);
|
|
239
|
-
* } finally {
|
|
240
|
-
* setIsProcessing(false);
|
|
241
|
-
* }
|
|
242
|
-
* };
|
|
243
|
-
* }
|
|
244
|
-
* ```
|
|
245
|
-
*/
|
|
246
|
-
declare function PaymentButton({ endpoint, className, disabled, onSuccess, onError, onStart, onFinish, children, }: PaymentButtonProps): React.JSX.Element;
|
|
248
|
+
interface V402CheckoutProps {
|
|
249
|
+
merchantId: string;
|
|
250
|
+
headerInfo?: HeaderInfo;
|
|
251
|
+
isModal?: boolean;
|
|
252
|
+
onPaymentComplete?: (response: any) => void;
|
|
253
|
+
additionalParams?: Record<string, any>;
|
|
254
|
+
expectedNetwork?: NetworkType;
|
|
255
|
+
}
|
|
256
|
+
declare function V402Checkout({ merchantId, headerInfo, isModal, onPaymentComplete, additionalParams, expectedNetwork, }: V402CheckoutProps): React.JSX.Element;
|
|
247
257
|
|
|
248
|
-
export {
|
|
258
|
+
export { type UsePageNetworkOptions, type UsePaymentInfoReturn, type UsePaymentReturn, type UseWalletReturn, V402Checkout, type V402CheckoutProps, WalletConnect, type WalletConnectProps, usePageNetwork, usePayment, usePaymentInfo, useWallet };
|