@t402/react 2.0.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/dist/cjs/index.cjs +737 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.cts +593 -0
- package/dist/esm/index.d.ts +593 -0
- package/dist/esm/index.js +709 -0
- package/dist/esm/index.js.map +1 -0
- package/package.json +76 -0
|
@@ -0,0 +1,593 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { PaymentRequirements, PaymentRequired } from '@t402/core/types';
|
|
3
|
+
export { PaymentRequired, PaymentRequirements } from '@t402/core/types';
|
|
4
|
+
import * as react from 'react';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Payment status states
|
|
8
|
+
*/
|
|
9
|
+
type PaymentStatus$1 = "idle" | "loading" | "success" | "error";
|
|
10
|
+
/**
|
|
11
|
+
* Payment context state
|
|
12
|
+
*/
|
|
13
|
+
interface PaymentState {
|
|
14
|
+
/** Current payment status */
|
|
15
|
+
status: PaymentStatus$1;
|
|
16
|
+
/** Error message if status is 'error' */
|
|
17
|
+
error: string | null;
|
|
18
|
+
/** The payment required response from server */
|
|
19
|
+
paymentRequired: PaymentRequired | null;
|
|
20
|
+
/** Currently selected payment requirement */
|
|
21
|
+
selectedRequirement: PaymentRequirements | null;
|
|
22
|
+
/** Whether we're in testnet mode */
|
|
23
|
+
isTestnet: boolean;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Payment context actions
|
|
27
|
+
*/
|
|
28
|
+
interface PaymentActions {
|
|
29
|
+
/** Set the payment required data */
|
|
30
|
+
setPaymentRequired: (data: PaymentRequired) => void;
|
|
31
|
+
/** Select a specific payment requirement */
|
|
32
|
+
selectRequirement: (requirement: PaymentRequirements) => void;
|
|
33
|
+
/** Set the payment status */
|
|
34
|
+
setStatus: (status: PaymentStatus$1) => void;
|
|
35
|
+
/** Set an error message */
|
|
36
|
+
setError: (error: string | null) => void;
|
|
37
|
+
/** Reset the payment state */
|
|
38
|
+
reset: () => void;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Complete payment context value
|
|
42
|
+
*/
|
|
43
|
+
interface PaymentContextValue extends PaymentState, PaymentActions {
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Props for PaymentProvider
|
|
47
|
+
*/
|
|
48
|
+
interface PaymentProviderProps {
|
|
49
|
+
/** Child components */
|
|
50
|
+
children: React.ReactNode;
|
|
51
|
+
/** Initial payment required data */
|
|
52
|
+
initialPaymentRequired?: PaymentRequired;
|
|
53
|
+
/** Whether to default to testnet mode */
|
|
54
|
+
testnet?: boolean;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Props for PaymentButton component
|
|
58
|
+
*/
|
|
59
|
+
interface PaymentButtonProps {
|
|
60
|
+
/** Click handler */
|
|
61
|
+
onClick?: () => void | Promise<void>;
|
|
62
|
+
/** Whether the button is disabled */
|
|
63
|
+
disabled?: boolean;
|
|
64
|
+
/** Whether the button is in loading state */
|
|
65
|
+
loading?: boolean;
|
|
66
|
+
/** Button text */
|
|
67
|
+
children?: React.ReactNode;
|
|
68
|
+
/** Additional CSS class names */
|
|
69
|
+
className?: string;
|
|
70
|
+
/** Button variant */
|
|
71
|
+
variant?: "primary" | "secondary" | "outline";
|
|
72
|
+
/** Button size */
|
|
73
|
+
size?: "sm" | "md" | "lg";
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Props for PaymentStatus component
|
|
77
|
+
*/
|
|
78
|
+
interface PaymentStatusProps {
|
|
79
|
+
/** Current status */
|
|
80
|
+
status: PaymentStatus$1;
|
|
81
|
+
/** Message to display */
|
|
82
|
+
message?: string;
|
|
83
|
+
/** Additional CSS class names */
|
|
84
|
+
className?: string;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Props for PaymentDetails component
|
|
88
|
+
*/
|
|
89
|
+
interface PaymentDetailsProps {
|
|
90
|
+
/** Payment requirements to display */
|
|
91
|
+
requirement: PaymentRequirements;
|
|
92
|
+
/** Whether to show the network name */
|
|
93
|
+
showNetwork?: boolean;
|
|
94
|
+
/** Whether to show the asset */
|
|
95
|
+
showAsset?: boolean;
|
|
96
|
+
/** Whether to show the recipient address */
|
|
97
|
+
showRecipient?: boolean;
|
|
98
|
+
/** Additional CSS class names */
|
|
99
|
+
className?: string;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Props for Spinner component
|
|
103
|
+
*/
|
|
104
|
+
interface SpinnerProps {
|
|
105
|
+
/** Spinner size */
|
|
106
|
+
size?: "sm" | "md" | "lg";
|
|
107
|
+
/** Additional CSS class names */
|
|
108
|
+
className?: string;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Props for AddressDisplay component
|
|
112
|
+
*/
|
|
113
|
+
interface AddressDisplayProps {
|
|
114
|
+
/** The address to display */
|
|
115
|
+
address: string;
|
|
116
|
+
/** Number of characters to show at start */
|
|
117
|
+
startChars?: number;
|
|
118
|
+
/** Number of characters to show at end */
|
|
119
|
+
endChars?: number;
|
|
120
|
+
/** Whether to show copy button */
|
|
121
|
+
copyable?: boolean;
|
|
122
|
+
/** Additional CSS class names */
|
|
123
|
+
className?: string;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* A simple loading spinner component.
|
|
128
|
+
*
|
|
129
|
+
* @param props - Component props.
|
|
130
|
+
* @returns The spinner element.
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```tsx
|
|
134
|
+
* import { Spinner } from "@t402/react";
|
|
135
|
+
*
|
|
136
|
+
* function LoadingState() {
|
|
137
|
+
* return (
|
|
138
|
+
* <div>
|
|
139
|
+
* <Spinner size="md" />
|
|
140
|
+
* <span>Loading...</span>
|
|
141
|
+
* </div>
|
|
142
|
+
* );
|
|
143
|
+
* }
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
declare function Spinner({ size, className }: SpinnerProps): react_jsx_runtime.JSX.Element;
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* A payment button component with loading state support.
|
|
150
|
+
*
|
|
151
|
+
* @param props - Component props.
|
|
152
|
+
* @returns The button element.
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* ```tsx
|
|
156
|
+
* import { PaymentButton } from "@t402/react";
|
|
157
|
+
*
|
|
158
|
+
* function PaymentFlow() {
|
|
159
|
+
* const [loading, setLoading] = useState(false);
|
|
160
|
+
*
|
|
161
|
+
* const handlePayment = async () => {
|
|
162
|
+
* setLoading(true);
|
|
163
|
+
* await processPayment();
|
|
164
|
+
* setLoading(false);
|
|
165
|
+
* };
|
|
166
|
+
*
|
|
167
|
+
* return (
|
|
168
|
+
* <PaymentButton
|
|
169
|
+
* onClick={handlePayment}
|
|
170
|
+
* loading={loading}
|
|
171
|
+
* variant="primary"
|
|
172
|
+
* size="lg"
|
|
173
|
+
* >
|
|
174
|
+
* Pay $10.00
|
|
175
|
+
* </PaymentButton>
|
|
176
|
+
* );
|
|
177
|
+
* }
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
declare function PaymentButton({ onClick, disabled, loading, children, className, variant, size, }: PaymentButtonProps): react_jsx_runtime.JSX.Element;
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* A component to display payment status with appropriate styling.
|
|
184
|
+
*
|
|
185
|
+
* @param props - Component props.
|
|
186
|
+
* @returns The status display element.
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* ```tsx
|
|
190
|
+
* import { PaymentStatus } from "@t402/react";
|
|
191
|
+
*
|
|
192
|
+
* function PaymentFlow() {
|
|
193
|
+
* const [status, setStatus] = useState("idle");
|
|
194
|
+
*
|
|
195
|
+
* return (
|
|
196
|
+
* <PaymentStatus
|
|
197
|
+
* status={status}
|
|
198
|
+
* message={status === "loading" ? "Processing payment..." : undefined}
|
|
199
|
+
* />
|
|
200
|
+
* );
|
|
201
|
+
* }
|
|
202
|
+
* ```
|
|
203
|
+
*/
|
|
204
|
+
declare function PaymentStatus({ status, message, className }: PaymentStatusProps): react_jsx_runtime.JSX.Element;
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* A component to display payment requirement details.
|
|
208
|
+
*
|
|
209
|
+
* @param props - Component props.
|
|
210
|
+
* @returns The payment details element.
|
|
211
|
+
*
|
|
212
|
+
* @example
|
|
213
|
+
* ```tsx
|
|
214
|
+
* import { PaymentDetails } from "@t402/react";
|
|
215
|
+
*
|
|
216
|
+
* function PaymentFlow({ requirement }) {
|
|
217
|
+
* return (
|
|
218
|
+
* <PaymentDetails
|
|
219
|
+
* requirement={requirement}
|
|
220
|
+
* showNetwork={true}
|
|
221
|
+
* showAsset={true}
|
|
222
|
+
* showRecipient={true}
|
|
223
|
+
* />
|
|
224
|
+
* );
|
|
225
|
+
* }
|
|
226
|
+
* ```
|
|
227
|
+
*/
|
|
228
|
+
declare function PaymentDetails({ requirement, showNetwork, showAsset, showRecipient, className, }: PaymentDetailsProps): react_jsx_runtime.JSX.Element;
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* A component to display blockchain addresses with optional copy functionality.
|
|
232
|
+
*
|
|
233
|
+
* @param props - Component props.
|
|
234
|
+
* @returns The address display element.
|
|
235
|
+
*
|
|
236
|
+
* @example
|
|
237
|
+
* ```tsx
|
|
238
|
+
* import { AddressDisplay } from "@t402/react";
|
|
239
|
+
*
|
|
240
|
+
* function WalletInfo() {
|
|
241
|
+
* return (
|
|
242
|
+
* <AddressDisplay
|
|
243
|
+
* address="0x1234567890abcdef1234567890abcdef12345678"
|
|
244
|
+
* copyable={true}
|
|
245
|
+
* startChars={6}
|
|
246
|
+
* endChars={4}
|
|
247
|
+
* />
|
|
248
|
+
* );
|
|
249
|
+
* }
|
|
250
|
+
* ```
|
|
251
|
+
*/
|
|
252
|
+
declare function AddressDisplay({ address, startChars, endChars, copyable, className, }: AddressDisplayProps): react_jsx_runtime.JSX.Element;
|
|
253
|
+
|
|
254
|
+
interface UsePaymentRequiredOptions {
|
|
255
|
+
/** Callback when payment is successful */
|
|
256
|
+
onSuccess?: (response: Response) => void;
|
|
257
|
+
/** Callback when payment fails */
|
|
258
|
+
onError?: (error: Error) => void;
|
|
259
|
+
}
|
|
260
|
+
interface UsePaymentRequiredResult {
|
|
261
|
+
/** The payment required data from a 402 response */
|
|
262
|
+
paymentRequired: PaymentRequired | null;
|
|
263
|
+
/** Current status of the fetch operation */
|
|
264
|
+
status: PaymentStatus$1;
|
|
265
|
+
/** Error message if status is 'error' */
|
|
266
|
+
error: string | null;
|
|
267
|
+
/** Fetch a resource and capture 402 response */
|
|
268
|
+
fetchResource: (url: string, options?: RequestInit) => Promise<Response | null>;
|
|
269
|
+
/** Reset the state */
|
|
270
|
+
reset: () => void;
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Hook to fetch a resource and capture 402 Payment Required responses.
|
|
274
|
+
*
|
|
275
|
+
* @param options - Configuration options.
|
|
276
|
+
* @returns State and methods for handling 402 responses.
|
|
277
|
+
*
|
|
278
|
+
* @example
|
|
279
|
+
* ```tsx
|
|
280
|
+
* import { usePaymentRequired } from "@t402/react";
|
|
281
|
+
*
|
|
282
|
+
* function ProtectedResource() {
|
|
283
|
+
* const { paymentRequired, status, fetchResource } = usePaymentRequired({
|
|
284
|
+
* onSuccess: (response) => console.log("Access granted!"),
|
|
285
|
+
* });
|
|
286
|
+
*
|
|
287
|
+
* const handleFetch = async () => {
|
|
288
|
+
* const response = await fetchResource("/api/protected");
|
|
289
|
+
* if (response && response.ok) {
|
|
290
|
+
* const data = await response.json();
|
|
291
|
+
* // Handle successful response
|
|
292
|
+
* }
|
|
293
|
+
* };
|
|
294
|
+
*
|
|
295
|
+
* if (paymentRequired) {
|
|
296
|
+
* return <PaymentUI data={paymentRequired} />;
|
|
297
|
+
* }
|
|
298
|
+
*
|
|
299
|
+
* return <button onClick={handleFetch}>Access Resource</button>;
|
|
300
|
+
* }
|
|
301
|
+
* ```
|
|
302
|
+
*/
|
|
303
|
+
declare function usePaymentRequired(options?: UsePaymentRequiredOptions): UsePaymentRequiredResult;
|
|
304
|
+
|
|
305
|
+
interface StatusMessage {
|
|
306
|
+
/** Message text */
|
|
307
|
+
text: string;
|
|
308
|
+
/** Message type */
|
|
309
|
+
type: "info" | "success" | "error" | "warning";
|
|
310
|
+
/** Optional auto-dismiss timeout in ms */
|
|
311
|
+
timeout?: number;
|
|
312
|
+
}
|
|
313
|
+
interface UsePaymentStatusResult {
|
|
314
|
+
/** Current payment status */
|
|
315
|
+
status: PaymentStatus$1;
|
|
316
|
+
/** Current status message */
|
|
317
|
+
message: StatusMessage | null;
|
|
318
|
+
/** Set the status */
|
|
319
|
+
setStatus: (status: PaymentStatus$1, message?: string) => void;
|
|
320
|
+
/** Set a success message */
|
|
321
|
+
setSuccess: (message: string, timeout?: number) => void;
|
|
322
|
+
/** Set an error message */
|
|
323
|
+
setError: (message: string) => void;
|
|
324
|
+
/** Set an info message */
|
|
325
|
+
setInfo: (message: string, timeout?: number) => void;
|
|
326
|
+
/** Set a warning message */
|
|
327
|
+
setWarning: (message: string, timeout?: number) => void;
|
|
328
|
+
/** Clear the current message */
|
|
329
|
+
clearMessage: () => void;
|
|
330
|
+
/** Reset to idle state */
|
|
331
|
+
reset: () => void;
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Hook for managing payment status and status messages.
|
|
335
|
+
*
|
|
336
|
+
* @returns State and methods for status management.
|
|
337
|
+
*
|
|
338
|
+
* @example
|
|
339
|
+
* ```tsx
|
|
340
|
+
* import { usePaymentStatus } from "@t402/react";
|
|
341
|
+
*
|
|
342
|
+
* function PaymentFlow() {
|
|
343
|
+
* const {
|
|
344
|
+
* status,
|
|
345
|
+
* message,
|
|
346
|
+
* setStatus,
|
|
347
|
+
* setSuccess,
|
|
348
|
+
* setError,
|
|
349
|
+
* } = usePaymentStatus();
|
|
350
|
+
*
|
|
351
|
+
* const handlePayment = async () => {
|
|
352
|
+
* setStatus("loading", "Processing payment...");
|
|
353
|
+
* try {
|
|
354
|
+
* await processPayment();
|
|
355
|
+
* setSuccess("Payment successful!", 3000);
|
|
356
|
+
* } catch (err) {
|
|
357
|
+
* setError("Payment failed. Please try again.");
|
|
358
|
+
* }
|
|
359
|
+
* };
|
|
360
|
+
*
|
|
361
|
+
* return (
|
|
362
|
+
* <div>
|
|
363
|
+
* {message && <StatusMessage message={message} />}
|
|
364
|
+
* <button onClick={handlePayment} disabled={status === "loading"}>
|
|
365
|
+
* Pay Now
|
|
366
|
+
* </button>
|
|
367
|
+
* </div>
|
|
368
|
+
* );
|
|
369
|
+
* }
|
|
370
|
+
* ```
|
|
371
|
+
*/
|
|
372
|
+
declare function usePaymentStatus(): UsePaymentStatusResult;
|
|
373
|
+
|
|
374
|
+
interface UseAsyncPaymentOptions<T> {
|
|
375
|
+
/** The async payment function to execute */
|
|
376
|
+
paymentFn: () => Promise<T>;
|
|
377
|
+
/** Callback on successful payment */
|
|
378
|
+
onSuccess?: (result: T) => void;
|
|
379
|
+
/** Callback on payment error */
|
|
380
|
+
onError?: (error: Error) => void;
|
|
381
|
+
/** Callback when payment starts */
|
|
382
|
+
onStart?: () => void;
|
|
383
|
+
}
|
|
384
|
+
interface UseAsyncPaymentResult<T> {
|
|
385
|
+
/** Execute the payment */
|
|
386
|
+
execute: () => Promise<T | null>;
|
|
387
|
+
/** Current payment status */
|
|
388
|
+
status: PaymentStatus$1;
|
|
389
|
+
/** Result of successful payment */
|
|
390
|
+
result: T | null;
|
|
391
|
+
/** Error message if payment failed */
|
|
392
|
+
error: string | null;
|
|
393
|
+
/** Whether payment is in progress */
|
|
394
|
+
isLoading: boolean;
|
|
395
|
+
/** Whether payment succeeded */
|
|
396
|
+
isSuccess: boolean;
|
|
397
|
+
/** Whether payment failed */
|
|
398
|
+
isError: boolean;
|
|
399
|
+
/** Reset the state */
|
|
400
|
+
reset: () => void;
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* Hook for managing async payment operations with loading states.
|
|
404
|
+
*
|
|
405
|
+
* @param options - Configuration including the payment function and callbacks.
|
|
406
|
+
* @returns State and methods for managing the async payment.
|
|
407
|
+
*
|
|
408
|
+
* @example
|
|
409
|
+
* ```tsx
|
|
410
|
+
* import { useAsyncPayment } from "@t402/react";
|
|
411
|
+
*
|
|
412
|
+
* function PaymentButton({ paymentPayload }) {
|
|
413
|
+
* const { execute, isLoading, isSuccess, error } = useAsyncPayment({
|
|
414
|
+
* paymentFn: async () => {
|
|
415
|
+
* const response = await fetch("/api/protected", {
|
|
416
|
+
* headers: { "X-Payment": paymentPayload },
|
|
417
|
+
* });
|
|
418
|
+
* return response.json();
|
|
419
|
+
* },
|
|
420
|
+
* onSuccess: (data) => console.log("Payment succeeded:", data),
|
|
421
|
+
* onError: (err) => console.error("Payment failed:", err),
|
|
422
|
+
* });
|
|
423
|
+
*
|
|
424
|
+
* return (
|
|
425
|
+
* <button onClick={execute} disabled={isLoading}>
|
|
426
|
+
* {isLoading ? "Processing..." : "Pay Now"}
|
|
427
|
+
* </button>
|
|
428
|
+
* );
|
|
429
|
+
* }
|
|
430
|
+
* ```
|
|
431
|
+
*/
|
|
432
|
+
declare function useAsyncPayment<T>(options: UseAsyncPaymentOptions<T>): UseAsyncPaymentResult<T>;
|
|
433
|
+
|
|
434
|
+
declare const PaymentContext: react.Context<PaymentContextValue | null>;
|
|
435
|
+
/**
|
|
436
|
+
* Payment context provider for t402 payment state management.
|
|
437
|
+
*
|
|
438
|
+
* @param props - Provider props including children and initial state.
|
|
439
|
+
* @returns The provider component wrapping children.
|
|
440
|
+
*
|
|
441
|
+
* @example
|
|
442
|
+
* ```tsx
|
|
443
|
+
* import { PaymentProvider } from "@t402/react";
|
|
444
|
+
*
|
|
445
|
+
* function App() {
|
|
446
|
+
* return (
|
|
447
|
+
* <PaymentProvider testnet={true}>
|
|
448
|
+
* <PaymentFlow />
|
|
449
|
+
* </PaymentProvider>
|
|
450
|
+
* );
|
|
451
|
+
* }
|
|
452
|
+
* ```
|
|
453
|
+
*/
|
|
454
|
+
declare function PaymentProvider({ children, initialPaymentRequired, testnet, }: PaymentProviderProps): react_jsx_runtime.JSX.Element;
|
|
455
|
+
/**
|
|
456
|
+
* Hook to access the payment context.
|
|
457
|
+
*
|
|
458
|
+
* @returns The payment context value.
|
|
459
|
+
* @throws Error if used outside of PaymentProvider.
|
|
460
|
+
*
|
|
461
|
+
* @example
|
|
462
|
+
* ```tsx
|
|
463
|
+
* import { usePaymentContext } from "@t402/react";
|
|
464
|
+
*
|
|
465
|
+
* function PaymentFlow() {
|
|
466
|
+
* const { status, selectedRequirement, setStatus } = usePaymentContext();
|
|
467
|
+
*
|
|
468
|
+
* const handlePayment = async () => {
|
|
469
|
+
* setStatus("loading");
|
|
470
|
+
* // ... payment logic
|
|
471
|
+
* };
|
|
472
|
+
*
|
|
473
|
+
* return <button onClick={handlePayment}>Pay</button>;
|
|
474
|
+
* }
|
|
475
|
+
* ```
|
|
476
|
+
*/
|
|
477
|
+
declare function usePaymentContext(): PaymentContextValue;
|
|
478
|
+
|
|
479
|
+
/** EVM Chain IDs (CAIP-2 format: eip155:chainId) */
|
|
480
|
+
declare const EVM_CHAIN_IDS: {
|
|
481
|
+
readonly ETHEREUM_MAINNET: "1";
|
|
482
|
+
readonly BASE_MAINNET: "8453";
|
|
483
|
+
readonly BASE_SEPOLIA: "84532";
|
|
484
|
+
readonly ARBITRUM_MAINNET: "42161";
|
|
485
|
+
readonly ARBITRUM_SEPOLIA: "421614";
|
|
486
|
+
};
|
|
487
|
+
/** Solana Network References (CAIP-2 format: solana:genesisHash) */
|
|
488
|
+
declare const SOLANA_NETWORK_REFS: {
|
|
489
|
+
readonly MAINNET: "5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp";
|
|
490
|
+
readonly DEVNET: "EtWTRABZaYq6iMfeYKouRu166VU2xqa1";
|
|
491
|
+
};
|
|
492
|
+
/** TON Network References (CAIP-2 format: ton:workchain) */
|
|
493
|
+
declare const TON_NETWORK_REFS: {
|
|
494
|
+
readonly MAINNET: "-239";
|
|
495
|
+
readonly TESTNET: "-3";
|
|
496
|
+
};
|
|
497
|
+
/** TRON Network References */
|
|
498
|
+
declare const TRON_NETWORK_REFS: {
|
|
499
|
+
readonly MAINNET: "mainnet";
|
|
500
|
+
readonly NILE: "nile";
|
|
501
|
+
readonly SHASTA: "shasta";
|
|
502
|
+
};
|
|
503
|
+
/**
|
|
504
|
+
* Normalizes payment requirements into an array.
|
|
505
|
+
*
|
|
506
|
+
* @param paymentRequirements - A single requirement or array of requirements.
|
|
507
|
+
* @returns An array of payment requirements.
|
|
508
|
+
*/
|
|
509
|
+
declare function normalizePaymentRequirements(paymentRequirements: PaymentRequirements | PaymentRequirements[]): PaymentRequirements[];
|
|
510
|
+
/**
|
|
511
|
+
* Returns preferred networks for payment selection.
|
|
512
|
+
*
|
|
513
|
+
* @param testnet - Whether to prefer testnet networks.
|
|
514
|
+
* @returns Ordered list of preferred networks (CAIP-2 format).
|
|
515
|
+
*/
|
|
516
|
+
declare function getPreferredNetworks(testnet: boolean): string[];
|
|
517
|
+
/**
|
|
518
|
+
* Selects the most appropriate payment requirement.
|
|
519
|
+
*
|
|
520
|
+
* @param paymentRequirements - Available payment requirements.
|
|
521
|
+
* @param testnet - Whether to prefer testnet networks.
|
|
522
|
+
* @returns The selected payment requirement.
|
|
523
|
+
*/
|
|
524
|
+
declare function choosePaymentRequirement(paymentRequirements: PaymentRequirements | PaymentRequirements[], testnet: boolean): PaymentRequirements;
|
|
525
|
+
/**
|
|
526
|
+
* Determines if the network is EVM-based.
|
|
527
|
+
*
|
|
528
|
+
* @param network - The network identifier (CAIP-2 format).
|
|
529
|
+
* @returns True if the network is EVM-based.
|
|
530
|
+
*/
|
|
531
|
+
declare function isEvmNetwork(network: string): boolean;
|
|
532
|
+
/**
|
|
533
|
+
* Determines if the network is Solana-based.
|
|
534
|
+
*
|
|
535
|
+
* @param network - The network identifier (CAIP-2 format).
|
|
536
|
+
* @returns True if the network is Solana-based.
|
|
537
|
+
*/
|
|
538
|
+
declare function isSvmNetwork(network: string): boolean;
|
|
539
|
+
/**
|
|
540
|
+
* Determines if the network is TON-based.
|
|
541
|
+
*
|
|
542
|
+
* @param network - The network identifier (CAIP-2 format).
|
|
543
|
+
* @returns True if the network is TON-based.
|
|
544
|
+
*/
|
|
545
|
+
declare function isTonNetwork(network: string): boolean;
|
|
546
|
+
/**
|
|
547
|
+
* Determines if the network is TRON-based.
|
|
548
|
+
*
|
|
549
|
+
* @param network - The network identifier (CAIP-2 format).
|
|
550
|
+
* @returns True if the network is TRON-based.
|
|
551
|
+
*/
|
|
552
|
+
declare function isTronNetwork(network: string): boolean;
|
|
553
|
+
/**
|
|
554
|
+
* Gets a human-readable display name for a network.
|
|
555
|
+
*
|
|
556
|
+
* @param network - The network identifier (CAIP-2 format).
|
|
557
|
+
* @returns A display name suitable for UI use.
|
|
558
|
+
*/
|
|
559
|
+
declare function getNetworkDisplayName(network: string): string;
|
|
560
|
+
/**
|
|
561
|
+
* Determines if the network is a testnet.
|
|
562
|
+
*
|
|
563
|
+
* @param network - The network identifier (CAIP-2 format).
|
|
564
|
+
* @returns True if the network is a testnet.
|
|
565
|
+
*/
|
|
566
|
+
declare function isTestnetNetwork(network: string): boolean;
|
|
567
|
+
/**
|
|
568
|
+
* Truncates an address for display.
|
|
569
|
+
*
|
|
570
|
+
* @param address - The full address.
|
|
571
|
+
* @param startChars - Number of characters to show at start (default: 6).
|
|
572
|
+
* @param endChars - Number of characters to show at end (default: 4).
|
|
573
|
+
* @returns The truncated address.
|
|
574
|
+
*/
|
|
575
|
+
declare function truncateAddress(address: string, startChars?: number, endChars?: number): string;
|
|
576
|
+
/**
|
|
577
|
+
* Formats a token amount for display.
|
|
578
|
+
*
|
|
579
|
+
* @param amount - The amount as a string (in smallest unit).
|
|
580
|
+
* @param decimals - The token decimals (default: 6 for USDT).
|
|
581
|
+
* @param maxDecimals - Maximum decimal places to show (default: 2).
|
|
582
|
+
* @returns The formatted amount.
|
|
583
|
+
*/
|
|
584
|
+
declare function formatTokenAmount(amount: string, decimals?: number, maxDecimals?: number): string;
|
|
585
|
+
/**
|
|
586
|
+
* Gets the asset display name.
|
|
587
|
+
*
|
|
588
|
+
* @param asset - The asset identifier (e.g., "usdt", "usdt0").
|
|
589
|
+
* @returns A display name suitable for UI use.
|
|
590
|
+
*/
|
|
591
|
+
declare function getAssetDisplayName(asset: string): string;
|
|
592
|
+
|
|
593
|
+
export { AddressDisplay, type AddressDisplayProps, EVM_CHAIN_IDS, type PaymentActions, PaymentButton, type PaymentButtonProps, PaymentContext, type PaymentContextValue, PaymentDetails, type PaymentDetailsProps, PaymentProvider, type PaymentProviderProps, type PaymentState, type PaymentStatus$1 as PaymentStatus, PaymentStatus as PaymentStatusDisplay, type PaymentStatusProps, SOLANA_NETWORK_REFS, Spinner, type SpinnerProps, TON_NETWORK_REFS, TRON_NETWORK_REFS, choosePaymentRequirement, formatTokenAmount, getAssetDisplayName, getNetworkDisplayName, getPreferredNetworks, isEvmNetwork, isSvmNetwork, isTestnetNetwork, isTonNetwork, isTronNetwork, normalizePaymentRequirements, truncateAddress, useAsyncPayment, usePaymentContext, usePaymentRequired, usePaymentStatus };
|