@t402/react 2.3.1 → 2.4.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 +27 -36
- package/dist/cjs/index.cjs +259 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +305 -1
- package/dist/esm/index.d.ts +305 -1
- package/dist/esm/index.js +257 -1
- package/dist/esm/index.js.map +1 -1
- package/package.json +4 -4
package/dist/cjs/index.d.cts
CHANGED
|
@@ -431,6 +431,310 @@ interface UseAsyncPaymentResult<T> {
|
|
|
431
431
|
*/
|
|
432
432
|
declare function useAsyncPayment<T>(options: UseAsyncPaymentOptions<T>): UseAsyncPaymentResult<T>;
|
|
433
433
|
|
|
434
|
+
interface GaslessPaymentOptions {
|
|
435
|
+
/** Gasless payment function */
|
|
436
|
+
payFn: (params: {
|
|
437
|
+
to: string;
|
|
438
|
+
amount: bigint;
|
|
439
|
+
token?: string;
|
|
440
|
+
}) => Promise<{
|
|
441
|
+
userOpHash: string;
|
|
442
|
+
sender: string;
|
|
443
|
+
sponsored: boolean;
|
|
444
|
+
wait: () => Promise<{
|
|
445
|
+
txHash: string;
|
|
446
|
+
success: boolean;
|
|
447
|
+
}>;
|
|
448
|
+
}>;
|
|
449
|
+
/** Callback on successful payment confirmation */
|
|
450
|
+
onSuccess?: (receipt: {
|
|
451
|
+
txHash: string;
|
|
452
|
+
success: boolean;
|
|
453
|
+
}) => void;
|
|
454
|
+
/** Callback on payment error */
|
|
455
|
+
onError?: (error: Error) => void;
|
|
456
|
+
/** Whether to automatically wait for receipt after submission */
|
|
457
|
+
autoWait?: boolean;
|
|
458
|
+
}
|
|
459
|
+
interface GaslessPaymentResult {
|
|
460
|
+
/** Execute a gasless payment */
|
|
461
|
+
pay: (params: {
|
|
462
|
+
to: string;
|
|
463
|
+
amount: bigint;
|
|
464
|
+
token?: string;
|
|
465
|
+
}) => Promise<void>;
|
|
466
|
+
/** Current payment status */
|
|
467
|
+
status: PaymentStatus$1;
|
|
468
|
+
/** UserOperation hash after submission */
|
|
469
|
+
userOpHash: string | null;
|
|
470
|
+
/** Transaction hash after confirmation */
|
|
471
|
+
txHash: string | null;
|
|
472
|
+
/** Whether gas was sponsored */
|
|
473
|
+
sponsored: boolean | null;
|
|
474
|
+
/** Error message if failed */
|
|
475
|
+
error: string | null;
|
|
476
|
+
/** Whether payment is in progress */
|
|
477
|
+
isLoading: boolean;
|
|
478
|
+
/** Whether payment succeeded */
|
|
479
|
+
isSuccess: boolean;
|
|
480
|
+
/** Whether payment failed */
|
|
481
|
+
isError: boolean;
|
|
482
|
+
/** Reset state */
|
|
483
|
+
reset: () => void;
|
|
484
|
+
}
|
|
485
|
+
/**
|
|
486
|
+
* Hook for gasless ERC-4337 payments via WDK.
|
|
487
|
+
*
|
|
488
|
+
* @param options - Configuration including the gasless payment function and callbacks.
|
|
489
|
+
* @returns State and methods for managing gasless payments.
|
|
490
|
+
*
|
|
491
|
+
* @example
|
|
492
|
+
* ```tsx
|
|
493
|
+
* import { useGaslessPayment } from "@t402/react";
|
|
494
|
+
*
|
|
495
|
+
* function GaslessPayButton({ client }) {
|
|
496
|
+
* const { pay, isLoading, isSuccess, txHash, sponsored, error } = useGaslessPayment({
|
|
497
|
+
* payFn: (params) => client.pay(params),
|
|
498
|
+
* onSuccess: (receipt) => console.log("Confirmed:", receipt.txHash),
|
|
499
|
+
* autoWait: true,
|
|
500
|
+
* });
|
|
501
|
+
*
|
|
502
|
+
* return (
|
|
503
|
+
* <button onClick={() => pay({ to: "0x...", amount: 1000000n })} disabled={isLoading}>
|
|
504
|
+
* {isLoading ? "Processing..." : "Pay Gasless"}
|
|
505
|
+
* </button>
|
|
506
|
+
* );
|
|
507
|
+
* }
|
|
508
|
+
* ```
|
|
509
|
+
*/
|
|
510
|
+
declare function useGaslessPayment(options: GaslessPaymentOptions): GaslessPaymentResult;
|
|
511
|
+
|
|
512
|
+
type BridgeStatus = 'idle' | 'quoting' | 'bridging' | 'waiting' | 'success' | 'error';
|
|
513
|
+
interface BridgePaymentOptions {
|
|
514
|
+
/** Bridge function */
|
|
515
|
+
bridgeFn: (params: {
|
|
516
|
+
fromChain: string;
|
|
517
|
+
toChain: string;
|
|
518
|
+
amount: bigint;
|
|
519
|
+
recipient: string;
|
|
520
|
+
slippageTolerance?: number;
|
|
521
|
+
}) => Promise<{
|
|
522
|
+
txHash: string;
|
|
523
|
+
messageGuid: string;
|
|
524
|
+
fromChain: string;
|
|
525
|
+
toChain: string;
|
|
526
|
+
amountSent: bigint;
|
|
527
|
+
waitForDelivery: (options?: {
|
|
528
|
+
timeout?: number;
|
|
529
|
+
}) => Promise<{
|
|
530
|
+
success: boolean;
|
|
531
|
+
status: string;
|
|
532
|
+
dstTxHash?: string;
|
|
533
|
+
}>;
|
|
534
|
+
}>;
|
|
535
|
+
/** Optional auto-bridge function for automatic source chain selection */
|
|
536
|
+
autoBridgeFn?: (params: {
|
|
537
|
+
toChain: string;
|
|
538
|
+
amount: bigint;
|
|
539
|
+
recipient: string;
|
|
540
|
+
preferredSourceChain?: string;
|
|
541
|
+
slippageTolerance?: number;
|
|
542
|
+
}) => Promise<{
|
|
543
|
+
txHash: string;
|
|
544
|
+
messageGuid: string;
|
|
545
|
+
fromChain: string;
|
|
546
|
+
toChain: string;
|
|
547
|
+
amountSent: bigint;
|
|
548
|
+
waitForDelivery: (options?: {
|
|
549
|
+
timeout?: number;
|
|
550
|
+
}) => Promise<{
|
|
551
|
+
success: boolean;
|
|
552
|
+
status: string;
|
|
553
|
+
dstTxHash?: string;
|
|
554
|
+
}>;
|
|
555
|
+
}>;
|
|
556
|
+
/** Callback on successful delivery */
|
|
557
|
+
onSuccess?: (result: {
|
|
558
|
+
txHash: string;
|
|
559
|
+
dstTxHash?: string;
|
|
560
|
+
fromChain: string;
|
|
561
|
+
toChain: string;
|
|
562
|
+
}) => void;
|
|
563
|
+
/** Callback on error */
|
|
564
|
+
onError?: (error: Error) => void;
|
|
565
|
+
/** Whether to automatically wait for delivery (default: false) */
|
|
566
|
+
autoWaitForDelivery?: boolean;
|
|
567
|
+
}
|
|
568
|
+
interface BridgePaymentResult {
|
|
569
|
+
/** Execute a bridge from a specific chain */
|
|
570
|
+
bridge: (params: {
|
|
571
|
+
fromChain: string;
|
|
572
|
+
toChain: string;
|
|
573
|
+
amount: bigint;
|
|
574
|
+
recipient: string;
|
|
575
|
+
slippageTolerance?: number;
|
|
576
|
+
}) => Promise<void>;
|
|
577
|
+
/** Execute an auto-bridge with automatic source chain selection */
|
|
578
|
+
autoBridge: (params: {
|
|
579
|
+
toChain: string;
|
|
580
|
+
amount: bigint;
|
|
581
|
+
recipient: string;
|
|
582
|
+
preferredSourceChain?: string;
|
|
583
|
+
slippageTolerance?: number;
|
|
584
|
+
}) => Promise<void>;
|
|
585
|
+
/** Current status */
|
|
586
|
+
status: BridgeStatus;
|
|
587
|
+
/** Source chain transaction hash */
|
|
588
|
+
txHash: string | null;
|
|
589
|
+
/** LayerZero message GUID */
|
|
590
|
+
messageGuid: string | null;
|
|
591
|
+
/** Destination chain transaction hash */
|
|
592
|
+
dstTxHash: string | null;
|
|
593
|
+
/** Error message if failed */
|
|
594
|
+
error: string | null;
|
|
595
|
+
/** Whether bridge is in progress */
|
|
596
|
+
isLoading: boolean;
|
|
597
|
+
/** Whether bridge succeeded */
|
|
598
|
+
isSuccess: boolean;
|
|
599
|
+
/** Whether bridge failed */
|
|
600
|
+
isError: boolean;
|
|
601
|
+
/** Reset state */
|
|
602
|
+
reset: () => void;
|
|
603
|
+
}
|
|
604
|
+
/**
|
|
605
|
+
* Hook for cross-chain USDT0 bridging via WDK.
|
|
606
|
+
*
|
|
607
|
+
* @param options - Configuration including bridge functions and callbacks.
|
|
608
|
+
* @returns State and methods for managing bridge operations.
|
|
609
|
+
*
|
|
610
|
+
* @example
|
|
611
|
+
* ```tsx
|
|
612
|
+
* import { useBridgePayment } from "@t402/react";
|
|
613
|
+
*
|
|
614
|
+
* function BridgeButton({ bridgeClient }) {
|
|
615
|
+
* const { autoBridge, isLoading, isSuccess, txHash, error } = useBridgePayment({
|
|
616
|
+
* bridgeFn: (params) => bridgeClient.bridge(params),
|
|
617
|
+
* autoBridgeFn: (params) => bridgeClient.autoBridge(params),
|
|
618
|
+
* onSuccess: (result) => console.log("Bridged:", result),
|
|
619
|
+
* });
|
|
620
|
+
*
|
|
621
|
+
* return (
|
|
622
|
+
* <button
|
|
623
|
+
* onClick={() => autoBridge({ toChain: "arbitrum", amount: 100_000000n, recipient: "0x..." })}
|
|
624
|
+
* disabled={isLoading}
|
|
625
|
+
* >
|
|
626
|
+
* {isLoading ? "Bridging..." : "Bridge USDT0"}
|
|
627
|
+
* </button>
|
|
628
|
+
* );
|
|
629
|
+
* }
|
|
630
|
+
* ```
|
|
631
|
+
*/
|
|
632
|
+
declare function useBridgePayment(options: BridgePaymentOptions): BridgePaymentResult;
|
|
633
|
+
|
|
634
|
+
type MultiSigStatus = 'idle' | 'initiating' | 'collecting' | 'submitting' | 'success' | 'error';
|
|
635
|
+
interface MultiSigPaymentOptions {
|
|
636
|
+
/** Initiate a multi-sig payment requiring threshold signatures */
|
|
637
|
+
initiateFn: (params: {
|
|
638
|
+
to: string;
|
|
639
|
+
amount: bigint;
|
|
640
|
+
token?: string;
|
|
641
|
+
}) => Promise<{
|
|
642
|
+
requestId: string;
|
|
643
|
+
userOpHash: string;
|
|
644
|
+
threshold: number;
|
|
645
|
+
collectedCount: number;
|
|
646
|
+
isReady: boolean;
|
|
647
|
+
}>;
|
|
648
|
+
/** Submit the transaction after collecting enough signatures */
|
|
649
|
+
submitFn: (requestId: string) => Promise<{
|
|
650
|
+
userOpHash: string;
|
|
651
|
+
wait: () => Promise<{
|
|
652
|
+
txHash: string;
|
|
653
|
+
success: boolean;
|
|
654
|
+
}>;
|
|
655
|
+
}>;
|
|
656
|
+
/** Callback on successful submission and confirmation */
|
|
657
|
+
onSuccess?: (receipt: {
|
|
658
|
+
txHash: string;
|
|
659
|
+
success: boolean;
|
|
660
|
+
}) => void;
|
|
661
|
+
/** Callback on error */
|
|
662
|
+
onError?: (error: Error) => void;
|
|
663
|
+
/** Whether to automatically wait for receipt after submission */
|
|
664
|
+
autoWait?: boolean;
|
|
665
|
+
}
|
|
666
|
+
interface MultiSigPaymentResult {
|
|
667
|
+
/** Initiate a multi-sig payment */
|
|
668
|
+
initiate: (params: {
|
|
669
|
+
to: string;
|
|
670
|
+
amount: bigint;
|
|
671
|
+
token?: string;
|
|
672
|
+
}) => Promise<void>;
|
|
673
|
+
/** Submit the transaction (when enough signatures are collected) */
|
|
674
|
+
submit: () => Promise<void>;
|
|
675
|
+
/** Current status */
|
|
676
|
+
status: MultiSigStatus;
|
|
677
|
+
/** Active request ID */
|
|
678
|
+
requestId: string | null;
|
|
679
|
+
/** UserOperation hash */
|
|
680
|
+
userOpHash: string | null;
|
|
681
|
+
/** Transaction hash after confirmation */
|
|
682
|
+
txHash: string | null;
|
|
683
|
+
/** Required signature threshold */
|
|
684
|
+
threshold: number;
|
|
685
|
+
/** Number of collected signatures */
|
|
686
|
+
collectedCount: number;
|
|
687
|
+
/** Whether enough signatures are collected */
|
|
688
|
+
isReady: boolean;
|
|
689
|
+
/** Error message if failed */
|
|
690
|
+
error: string | null;
|
|
691
|
+
/** Whether operation is in progress */
|
|
692
|
+
isLoading: boolean;
|
|
693
|
+
/** Whether operation succeeded */
|
|
694
|
+
isSuccess: boolean;
|
|
695
|
+
/** Whether operation failed */
|
|
696
|
+
isError: boolean;
|
|
697
|
+
/** Reset state */
|
|
698
|
+
reset: () => void;
|
|
699
|
+
}
|
|
700
|
+
/**
|
|
701
|
+
* Hook for multi-sig Safe payments via WDK.
|
|
702
|
+
*
|
|
703
|
+
* @param options - Configuration including initiate/submit functions and callbacks.
|
|
704
|
+
* @returns State and methods for managing multi-sig payment lifecycle.
|
|
705
|
+
*
|
|
706
|
+
* @example
|
|
707
|
+
* ```tsx
|
|
708
|
+
* import { useMultiSigPayment } from "@t402/react";
|
|
709
|
+
*
|
|
710
|
+
* function MultiSigPayButton({ multiSigClient }) {
|
|
711
|
+
* const { initiate, submit, status, isReady, threshold, collectedCount, error } =
|
|
712
|
+
* useMultiSigPayment({
|
|
713
|
+
* initiateFn: (params) => multiSigClient.initiatePayment(params),
|
|
714
|
+
* submitFn: (requestId) => multiSigClient.submitRequest(requestId),
|
|
715
|
+
* onSuccess: (receipt) => console.log("Confirmed:", receipt.txHash),
|
|
716
|
+
* autoWait: true,
|
|
717
|
+
* });
|
|
718
|
+
*
|
|
719
|
+
* return (
|
|
720
|
+
* <div>
|
|
721
|
+
* {status === "idle" && (
|
|
722
|
+
* <button onClick={() => initiate({ to: "0x...", amount: 1000000n })}>
|
|
723
|
+
* Initiate Payment
|
|
724
|
+
* </button>
|
|
725
|
+
* )}
|
|
726
|
+
* {status === "collecting" && (
|
|
727
|
+
* <p>Collecting signatures: {collectedCount}/{threshold}</p>
|
|
728
|
+
* )}
|
|
729
|
+
* {isReady && <button onClick={submit}>Submit Transaction</button>}
|
|
730
|
+
* {error && <p>Error: {error}</p>}
|
|
731
|
+
* </div>
|
|
732
|
+
* );
|
|
733
|
+
* }
|
|
734
|
+
* ```
|
|
735
|
+
*/
|
|
736
|
+
declare function useMultiSigPayment(options: MultiSigPaymentOptions): MultiSigPaymentResult;
|
|
737
|
+
|
|
434
738
|
declare const PaymentContext: react.Context<PaymentContextValue | null>;
|
|
435
739
|
/**
|
|
436
740
|
* Payment context provider for t402 payment state management.
|
|
@@ -590,4 +894,4 @@ declare function formatTokenAmount(amount: string, decimals?: number, maxDecimal
|
|
|
590
894
|
*/
|
|
591
895
|
declare function getAssetDisplayName(asset: string): string;
|
|
592
896
|
|
|
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 };
|
|
897
|
+
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, useBridgePayment, useGaslessPayment, useMultiSigPayment, usePaymentContext, usePaymentRequired, usePaymentStatus };
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -431,6 +431,310 @@ interface UseAsyncPaymentResult<T> {
|
|
|
431
431
|
*/
|
|
432
432
|
declare function useAsyncPayment<T>(options: UseAsyncPaymentOptions<T>): UseAsyncPaymentResult<T>;
|
|
433
433
|
|
|
434
|
+
interface GaslessPaymentOptions {
|
|
435
|
+
/** Gasless payment function */
|
|
436
|
+
payFn: (params: {
|
|
437
|
+
to: string;
|
|
438
|
+
amount: bigint;
|
|
439
|
+
token?: string;
|
|
440
|
+
}) => Promise<{
|
|
441
|
+
userOpHash: string;
|
|
442
|
+
sender: string;
|
|
443
|
+
sponsored: boolean;
|
|
444
|
+
wait: () => Promise<{
|
|
445
|
+
txHash: string;
|
|
446
|
+
success: boolean;
|
|
447
|
+
}>;
|
|
448
|
+
}>;
|
|
449
|
+
/** Callback on successful payment confirmation */
|
|
450
|
+
onSuccess?: (receipt: {
|
|
451
|
+
txHash: string;
|
|
452
|
+
success: boolean;
|
|
453
|
+
}) => void;
|
|
454
|
+
/** Callback on payment error */
|
|
455
|
+
onError?: (error: Error) => void;
|
|
456
|
+
/** Whether to automatically wait for receipt after submission */
|
|
457
|
+
autoWait?: boolean;
|
|
458
|
+
}
|
|
459
|
+
interface GaslessPaymentResult {
|
|
460
|
+
/** Execute a gasless payment */
|
|
461
|
+
pay: (params: {
|
|
462
|
+
to: string;
|
|
463
|
+
amount: bigint;
|
|
464
|
+
token?: string;
|
|
465
|
+
}) => Promise<void>;
|
|
466
|
+
/** Current payment status */
|
|
467
|
+
status: PaymentStatus$1;
|
|
468
|
+
/** UserOperation hash after submission */
|
|
469
|
+
userOpHash: string | null;
|
|
470
|
+
/** Transaction hash after confirmation */
|
|
471
|
+
txHash: string | null;
|
|
472
|
+
/** Whether gas was sponsored */
|
|
473
|
+
sponsored: boolean | null;
|
|
474
|
+
/** Error message if failed */
|
|
475
|
+
error: string | null;
|
|
476
|
+
/** Whether payment is in progress */
|
|
477
|
+
isLoading: boolean;
|
|
478
|
+
/** Whether payment succeeded */
|
|
479
|
+
isSuccess: boolean;
|
|
480
|
+
/** Whether payment failed */
|
|
481
|
+
isError: boolean;
|
|
482
|
+
/** Reset state */
|
|
483
|
+
reset: () => void;
|
|
484
|
+
}
|
|
485
|
+
/**
|
|
486
|
+
* Hook for gasless ERC-4337 payments via WDK.
|
|
487
|
+
*
|
|
488
|
+
* @param options - Configuration including the gasless payment function and callbacks.
|
|
489
|
+
* @returns State and methods for managing gasless payments.
|
|
490
|
+
*
|
|
491
|
+
* @example
|
|
492
|
+
* ```tsx
|
|
493
|
+
* import { useGaslessPayment } from "@t402/react";
|
|
494
|
+
*
|
|
495
|
+
* function GaslessPayButton({ client }) {
|
|
496
|
+
* const { pay, isLoading, isSuccess, txHash, sponsored, error } = useGaslessPayment({
|
|
497
|
+
* payFn: (params) => client.pay(params),
|
|
498
|
+
* onSuccess: (receipt) => console.log("Confirmed:", receipt.txHash),
|
|
499
|
+
* autoWait: true,
|
|
500
|
+
* });
|
|
501
|
+
*
|
|
502
|
+
* return (
|
|
503
|
+
* <button onClick={() => pay({ to: "0x...", amount: 1000000n })} disabled={isLoading}>
|
|
504
|
+
* {isLoading ? "Processing..." : "Pay Gasless"}
|
|
505
|
+
* </button>
|
|
506
|
+
* );
|
|
507
|
+
* }
|
|
508
|
+
* ```
|
|
509
|
+
*/
|
|
510
|
+
declare function useGaslessPayment(options: GaslessPaymentOptions): GaslessPaymentResult;
|
|
511
|
+
|
|
512
|
+
type BridgeStatus = 'idle' | 'quoting' | 'bridging' | 'waiting' | 'success' | 'error';
|
|
513
|
+
interface BridgePaymentOptions {
|
|
514
|
+
/** Bridge function */
|
|
515
|
+
bridgeFn: (params: {
|
|
516
|
+
fromChain: string;
|
|
517
|
+
toChain: string;
|
|
518
|
+
amount: bigint;
|
|
519
|
+
recipient: string;
|
|
520
|
+
slippageTolerance?: number;
|
|
521
|
+
}) => Promise<{
|
|
522
|
+
txHash: string;
|
|
523
|
+
messageGuid: string;
|
|
524
|
+
fromChain: string;
|
|
525
|
+
toChain: string;
|
|
526
|
+
amountSent: bigint;
|
|
527
|
+
waitForDelivery: (options?: {
|
|
528
|
+
timeout?: number;
|
|
529
|
+
}) => Promise<{
|
|
530
|
+
success: boolean;
|
|
531
|
+
status: string;
|
|
532
|
+
dstTxHash?: string;
|
|
533
|
+
}>;
|
|
534
|
+
}>;
|
|
535
|
+
/** Optional auto-bridge function for automatic source chain selection */
|
|
536
|
+
autoBridgeFn?: (params: {
|
|
537
|
+
toChain: string;
|
|
538
|
+
amount: bigint;
|
|
539
|
+
recipient: string;
|
|
540
|
+
preferredSourceChain?: string;
|
|
541
|
+
slippageTolerance?: number;
|
|
542
|
+
}) => Promise<{
|
|
543
|
+
txHash: string;
|
|
544
|
+
messageGuid: string;
|
|
545
|
+
fromChain: string;
|
|
546
|
+
toChain: string;
|
|
547
|
+
amountSent: bigint;
|
|
548
|
+
waitForDelivery: (options?: {
|
|
549
|
+
timeout?: number;
|
|
550
|
+
}) => Promise<{
|
|
551
|
+
success: boolean;
|
|
552
|
+
status: string;
|
|
553
|
+
dstTxHash?: string;
|
|
554
|
+
}>;
|
|
555
|
+
}>;
|
|
556
|
+
/** Callback on successful delivery */
|
|
557
|
+
onSuccess?: (result: {
|
|
558
|
+
txHash: string;
|
|
559
|
+
dstTxHash?: string;
|
|
560
|
+
fromChain: string;
|
|
561
|
+
toChain: string;
|
|
562
|
+
}) => void;
|
|
563
|
+
/** Callback on error */
|
|
564
|
+
onError?: (error: Error) => void;
|
|
565
|
+
/** Whether to automatically wait for delivery (default: false) */
|
|
566
|
+
autoWaitForDelivery?: boolean;
|
|
567
|
+
}
|
|
568
|
+
interface BridgePaymentResult {
|
|
569
|
+
/** Execute a bridge from a specific chain */
|
|
570
|
+
bridge: (params: {
|
|
571
|
+
fromChain: string;
|
|
572
|
+
toChain: string;
|
|
573
|
+
amount: bigint;
|
|
574
|
+
recipient: string;
|
|
575
|
+
slippageTolerance?: number;
|
|
576
|
+
}) => Promise<void>;
|
|
577
|
+
/** Execute an auto-bridge with automatic source chain selection */
|
|
578
|
+
autoBridge: (params: {
|
|
579
|
+
toChain: string;
|
|
580
|
+
amount: bigint;
|
|
581
|
+
recipient: string;
|
|
582
|
+
preferredSourceChain?: string;
|
|
583
|
+
slippageTolerance?: number;
|
|
584
|
+
}) => Promise<void>;
|
|
585
|
+
/** Current status */
|
|
586
|
+
status: BridgeStatus;
|
|
587
|
+
/** Source chain transaction hash */
|
|
588
|
+
txHash: string | null;
|
|
589
|
+
/** LayerZero message GUID */
|
|
590
|
+
messageGuid: string | null;
|
|
591
|
+
/** Destination chain transaction hash */
|
|
592
|
+
dstTxHash: string | null;
|
|
593
|
+
/** Error message if failed */
|
|
594
|
+
error: string | null;
|
|
595
|
+
/** Whether bridge is in progress */
|
|
596
|
+
isLoading: boolean;
|
|
597
|
+
/** Whether bridge succeeded */
|
|
598
|
+
isSuccess: boolean;
|
|
599
|
+
/** Whether bridge failed */
|
|
600
|
+
isError: boolean;
|
|
601
|
+
/** Reset state */
|
|
602
|
+
reset: () => void;
|
|
603
|
+
}
|
|
604
|
+
/**
|
|
605
|
+
* Hook for cross-chain USDT0 bridging via WDK.
|
|
606
|
+
*
|
|
607
|
+
* @param options - Configuration including bridge functions and callbacks.
|
|
608
|
+
* @returns State and methods for managing bridge operations.
|
|
609
|
+
*
|
|
610
|
+
* @example
|
|
611
|
+
* ```tsx
|
|
612
|
+
* import { useBridgePayment } from "@t402/react";
|
|
613
|
+
*
|
|
614
|
+
* function BridgeButton({ bridgeClient }) {
|
|
615
|
+
* const { autoBridge, isLoading, isSuccess, txHash, error } = useBridgePayment({
|
|
616
|
+
* bridgeFn: (params) => bridgeClient.bridge(params),
|
|
617
|
+
* autoBridgeFn: (params) => bridgeClient.autoBridge(params),
|
|
618
|
+
* onSuccess: (result) => console.log("Bridged:", result),
|
|
619
|
+
* });
|
|
620
|
+
*
|
|
621
|
+
* return (
|
|
622
|
+
* <button
|
|
623
|
+
* onClick={() => autoBridge({ toChain: "arbitrum", amount: 100_000000n, recipient: "0x..." })}
|
|
624
|
+
* disabled={isLoading}
|
|
625
|
+
* >
|
|
626
|
+
* {isLoading ? "Bridging..." : "Bridge USDT0"}
|
|
627
|
+
* </button>
|
|
628
|
+
* );
|
|
629
|
+
* }
|
|
630
|
+
* ```
|
|
631
|
+
*/
|
|
632
|
+
declare function useBridgePayment(options: BridgePaymentOptions): BridgePaymentResult;
|
|
633
|
+
|
|
634
|
+
type MultiSigStatus = 'idle' | 'initiating' | 'collecting' | 'submitting' | 'success' | 'error';
|
|
635
|
+
interface MultiSigPaymentOptions {
|
|
636
|
+
/** Initiate a multi-sig payment requiring threshold signatures */
|
|
637
|
+
initiateFn: (params: {
|
|
638
|
+
to: string;
|
|
639
|
+
amount: bigint;
|
|
640
|
+
token?: string;
|
|
641
|
+
}) => Promise<{
|
|
642
|
+
requestId: string;
|
|
643
|
+
userOpHash: string;
|
|
644
|
+
threshold: number;
|
|
645
|
+
collectedCount: number;
|
|
646
|
+
isReady: boolean;
|
|
647
|
+
}>;
|
|
648
|
+
/** Submit the transaction after collecting enough signatures */
|
|
649
|
+
submitFn: (requestId: string) => Promise<{
|
|
650
|
+
userOpHash: string;
|
|
651
|
+
wait: () => Promise<{
|
|
652
|
+
txHash: string;
|
|
653
|
+
success: boolean;
|
|
654
|
+
}>;
|
|
655
|
+
}>;
|
|
656
|
+
/** Callback on successful submission and confirmation */
|
|
657
|
+
onSuccess?: (receipt: {
|
|
658
|
+
txHash: string;
|
|
659
|
+
success: boolean;
|
|
660
|
+
}) => void;
|
|
661
|
+
/** Callback on error */
|
|
662
|
+
onError?: (error: Error) => void;
|
|
663
|
+
/** Whether to automatically wait for receipt after submission */
|
|
664
|
+
autoWait?: boolean;
|
|
665
|
+
}
|
|
666
|
+
interface MultiSigPaymentResult {
|
|
667
|
+
/** Initiate a multi-sig payment */
|
|
668
|
+
initiate: (params: {
|
|
669
|
+
to: string;
|
|
670
|
+
amount: bigint;
|
|
671
|
+
token?: string;
|
|
672
|
+
}) => Promise<void>;
|
|
673
|
+
/** Submit the transaction (when enough signatures are collected) */
|
|
674
|
+
submit: () => Promise<void>;
|
|
675
|
+
/** Current status */
|
|
676
|
+
status: MultiSigStatus;
|
|
677
|
+
/** Active request ID */
|
|
678
|
+
requestId: string | null;
|
|
679
|
+
/** UserOperation hash */
|
|
680
|
+
userOpHash: string | null;
|
|
681
|
+
/** Transaction hash after confirmation */
|
|
682
|
+
txHash: string | null;
|
|
683
|
+
/** Required signature threshold */
|
|
684
|
+
threshold: number;
|
|
685
|
+
/** Number of collected signatures */
|
|
686
|
+
collectedCount: number;
|
|
687
|
+
/** Whether enough signatures are collected */
|
|
688
|
+
isReady: boolean;
|
|
689
|
+
/** Error message if failed */
|
|
690
|
+
error: string | null;
|
|
691
|
+
/** Whether operation is in progress */
|
|
692
|
+
isLoading: boolean;
|
|
693
|
+
/** Whether operation succeeded */
|
|
694
|
+
isSuccess: boolean;
|
|
695
|
+
/** Whether operation failed */
|
|
696
|
+
isError: boolean;
|
|
697
|
+
/** Reset state */
|
|
698
|
+
reset: () => void;
|
|
699
|
+
}
|
|
700
|
+
/**
|
|
701
|
+
* Hook for multi-sig Safe payments via WDK.
|
|
702
|
+
*
|
|
703
|
+
* @param options - Configuration including initiate/submit functions and callbacks.
|
|
704
|
+
* @returns State and methods for managing multi-sig payment lifecycle.
|
|
705
|
+
*
|
|
706
|
+
* @example
|
|
707
|
+
* ```tsx
|
|
708
|
+
* import { useMultiSigPayment } from "@t402/react";
|
|
709
|
+
*
|
|
710
|
+
* function MultiSigPayButton({ multiSigClient }) {
|
|
711
|
+
* const { initiate, submit, status, isReady, threshold, collectedCount, error } =
|
|
712
|
+
* useMultiSigPayment({
|
|
713
|
+
* initiateFn: (params) => multiSigClient.initiatePayment(params),
|
|
714
|
+
* submitFn: (requestId) => multiSigClient.submitRequest(requestId),
|
|
715
|
+
* onSuccess: (receipt) => console.log("Confirmed:", receipt.txHash),
|
|
716
|
+
* autoWait: true,
|
|
717
|
+
* });
|
|
718
|
+
*
|
|
719
|
+
* return (
|
|
720
|
+
* <div>
|
|
721
|
+
* {status === "idle" && (
|
|
722
|
+
* <button onClick={() => initiate({ to: "0x...", amount: 1000000n })}>
|
|
723
|
+
* Initiate Payment
|
|
724
|
+
* </button>
|
|
725
|
+
* )}
|
|
726
|
+
* {status === "collecting" && (
|
|
727
|
+
* <p>Collecting signatures: {collectedCount}/{threshold}</p>
|
|
728
|
+
* )}
|
|
729
|
+
* {isReady && <button onClick={submit}>Submit Transaction</button>}
|
|
730
|
+
* {error && <p>Error: {error}</p>}
|
|
731
|
+
* </div>
|
|
732
|
+
* );
|
|
733
|
+
* }
|
|
734
|
+
* ```
|
|
735
|
+
*/
|
|
736
|
+
declare function useMultiSigPayment(options: MultiSigPaymentOptions): MultiSigPaymentResult;
|
|
737
|
+
|
|
434
738
|
declare const PaymentContext: react.Context<PaymentContextValue | null>;
|
|
435
739
|
/**
|
|
436
740
|
* Payment context provider for t402 payment state management.
|
|
@@ -590,4 +894,4 @@ declare function formatTokenAmount(amount: string, decimals?: number, maxDecimal
|
|
|
590
894
|
*/
|
|
591
895
|
declare function getAssetDisplayName(asset: string): string;
|
|
592
896
|
|
|
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 };
|
|
897
|
+
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, useBridgePayment, useGaslessPayment, useMultiSigPayment, usePaymentContext, usePaymentRequired, usePaymentStatus };
|