@voyage_ai/v402-web-ts 0.1.1 → 0.1.2

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.
@@ -1,119 +0,0 @@
1
- /**
2
- * PaymentButton Component
3
- *
4
- * Pre-built payment button component with inline styles
5
- * Note: This is a simple wrapper. For complex payment flows,
6
- * use the SDK directly with usePayment hook for full control.
7
- */
8
-
9
- 'use client';
10
-
11
- import React, {useState} from 'react';
12
- import {useWallet} from '../hooks/useWalletStore';
13
- import {usePayment} from '../hooks/usePayment';
14
- import {handlePayment} from '../../utils';
15
- import {getErrorStyle, getPayButtonStyle} from '../styles/inline-styles';
16
-
17
- export interface PaymentButtonProps {
18
- endpoint: string;
19
- className?: string;
20
- disabled?: boolean;
21
- onSuccess?: (result: any) => void;
22
- onError?: (error: string) => void;
23
- onStart?: () => void;
24
- onFinish?: () => void;
25
- children?: React.ReactNode;
26
- }
27
-
28
- /**
29
- * Simple pre-built payment button
30
- *
31
- * For complex payment flows, use the SDK directly:
32
- *
33
- * @example
34
- * ```tsx
35
- * import { useWallet, usePayment } from '../react';
36
- * import { handleSvmPayment } from '@/app/sdk';
37
- *
38
- * function CustomPayment() {
39
- * const { networkType } = useWallet();
40
- * const { isProcessing, setIsProcessing, setResult, setError } = usePayment();
41
- *
42
- * const handlePay = async () => {
43
- * setIsProcessing(true);
44
- * try {
45
- * // Your custom logic before payment
46
- * const response = await handleSvmPayment(...);
47
- * const data = await response.json();
48
- *
49
- * // Your custom logic after payment
50
- * setResult(data);
51
- * } catch (err) {
52
- * setError(err.message);
53
- * } finally {
54
- * setIsProcessing(false);
55
- * }
56
- * };
57
- * }
58
- * ```
59
- */
60
- export function PaymentButton({
61
- endpoint,
62
- className = '',
63
- disabled = false,
64
- onSuccess,
65
- onError,
66
- onStart,
67
- onFinish,
68
- children = 'Pay Now',
69
- }: PaymentButtonProps) {
70
- const {networkType} = useWallet();
71
- const {isProcessing, setIsProcessing, setResult, setError, error} = usePayment();
72
- const [isHovered, setIsHovered] = useState(false);
73
-
74
- const handleClick = async () => {
75
- if (!networkType) {
76
- const errorMsg = 'Please connect wallet first';
77
- setError(errorMsg);
78
- onError?.(errorMsg);
79
- return;
80
- }
81
-
82
- try {
83
- onStart?.();
84
- setIsProcessing(true);
85
- setError(null);
86
-
87
- const result = await handlePayment(endpoint, networkType);
88
-
89
- setResult(result);
90
- onSuccess?.(result);
91
- } catch (err: any) {
92
- const errorMsg = err.message || 'Payment failed';
93
- setError(errorMsg);
94
- onError?.(errorMsg);
95
- } finally {
96
- setIsProcessing(false);
97
- onFinish?.();
98
- }
99
- };
100
-
101
- const isDisabled = disabled || isProcessing || !networkType;
102
-
103
- return (
104
- <>
105
- <button
106
- style={getPayButtonStyle(isDisabled, isHovered)}
107
- className={className}
108
- onClick={handleClick}
109
- disabled={isDisabled}
110
- onMouseEnter={() => setIsHovered(true)}
111
- onMouseLeave={() => setIsHovered(false)}
112
- >
113
- {isProcessing ? 'Processing...' : children}
114
- </button>
115
- {error && <p style={getErrorStyle()}>{error}</p>}
116
- </>
117
- );
118
- }
119
-