@t402/vue 2.3.0 → 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 +131 -0
- package/dist/cjs/index.cjs +239 -13
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +301 -1
- package/dist/esm/index.d.ts +301 -1
- package/dist/esm/index.js +237 -14
- package/dist/esm/index.js.map +1 -1
- package/package.json +4 -4
package/dist/esm/index.d.ts
CHANGED
|
@@ -483,6 +483,306 @@ interface UseAsyncPaymentReturn<T> {
|
|
|
483
483
|
*/
|
|
484
484
|
declare function useAsyncPayment<T>(options: UseAsyncPaymentOptions<T>): UseAsyncPaymentReturn<T>;
|
|
485
485
|
|
|
486
|
+
interface GaslessPaymentOptions {
|
|
487
|
+
/** Gasless payment function */
|
|
488
|
+
payFn: (params: {
|
|
489
|
+
to: string;
|
|
490
|
+
amount: bigint;
|
|
491
|
+
token?: string;
|
|
492
|
+
}) => Promise<{
|
|
493
|
+
userOpHash: string;
|
|
494
|
+
sender: string;
|
|
495
|
+
sponsored: boolean;
|
|
496
|
+
wait: () => Promise<{
|
|
497
|
+
txHash: string;
|
|
498
|
+
success: boolean;
|
|
499
|
+
}>;
|
|
500
|
+
}>;
|
|
501
|
+
/** Callback on successful payment confirmation */
|
|
502
|
+
onSuccess?: (receipt: {
|
|
503
|
+
txHash: string;
|
|
504
|
+
success: boolean;
|
|
505
|
+
}) => void;
|
|
506
|
+
/** Callback on payment error */
|
|
507
|
+
onError?: (error: Error) => void;
|
|
508
|
+
/** Whether to automatically wait for receipt after submission */
|
|
509
|
+
autoWait?: boolean;
|
|
510
|
+
}
|
|
511
|
+
interface GaslessPaymentReturn {
|
|
512
|
+
/** Execute a gasless payment */
|
|
513
|
+
pay: (params: {
|
|
514
|
+
to: string;
|
|
515
|
+
amount: bigint;
|
|
516
|
+
token?: string;
|
|
517
|
+
}) => Promise<void>;
|
|
518
|
+
/** Current payment status */
|
|
519
|
+
status: Ref<PaymentStatus>;
|
|
520
|
+
/** UserOperation hash after submission */
|
|
521
|
+
userOpHash: Ref<string | null>;
|
|
522
|
+
/** Transaction hash after confirmation */
|
|
523
|
+
txHash: Ref<string | null>;
|
|
524
|
+
/** Whether gas was sponsored */
|
|
525
|
+
sponsored: Ref<boolean | null>;
|
|
526
|
+
/** Error message if failed */
|
|
527
|
+
error: Ref<string | null>;
|
|
528
|
+
/** Whether payment is in progress */
|
|
529
|
+
isLoading: ComputedRef<boolean>;
|
|
530
|
+
/** Whether payment succeeded */
|
|
531
|
+
isSuccess: ComputedRef<boolean>;
|
|
532
|
+
/** Whether payment failed */
|
|
533
|
+
isError: ComputedRef<boolean>;
|
|
534
|
+
/** Reset state */
|
|
535
|
+
reset: () => void;
|
|
536
|
+
}
|
|
537
|
+
/**
|
|
538
|
+
* Composable for gasless ERC-4337 payments via WDK.
|
|
539
|
+
*
|
|
540
|
+
* @param options - Configuration including the gasless payment function and callbacks.
|
|
541
|
+
* @returns State and methods for managing gasless payments.
|
|
542
|
+
*
|
|
543
|
+
* @example
|
|
544
|
+
* ```vue
|
|
545
|
+
* <script setup>
|
|
546
|
+
* import { useGaslessPayment } from "@t402/vue";
|
|
547
|
+
*
|
|
548
|
+
* const { pay, isLoading, isSuccess, txHash, sponsored, error } = useGaslessPayment({
|
|
549
|
+
* payFn: (params) => gaslessClient.pay(params),
|
|
550
|
+
* onSuccess: (receipt) => console.log("Confirmed:", receipt.txHash),
|
|
551
|
+
* autoWait: true,
|
|
552
|
+
* });
|
|
553
|
+
* </script>
|
|
554
|
+
*
|
|
555
|
+
* <template>
|
|
556
|
+
* <button @click="pay({ to: '0x...', amount: 1000000n })" :disabled="isLoading">
|
|
557
|
+
* {{ isLoading ? "Processing..." : "Pay Gasless" }}
|
|
558
|
+
* </button>
|
|
559
|
+
* </template>
|
|
560
|
+
* ```
|
|
561
|
+
*/
|
|
562
|
+
declare function useGaslessPayment(options: GaslessPaymentOptions): GaslessPaymentReturn;
|
|
563
|
+
|
|
564
|
+
type BridgeStatus = 'idle' | 'quoting' | 'bridging' | 'waiting' | 'success' | 'error';
|
|
565
|
+
interface BridgePaymentOptions {
|
|
566
|
+
/** Bridge function */
|
|
567
|
+
bridgeFn: (params: {
|
|
568
|
+
fromChain: string;
|
|
569
|
+
toChain: string;
|
|
570
|
+
amount: bigint;
|
|
571
|
+
recipient: string;
|
|
572
|
+
slippageTolerance?: number;
|
|
573
|
+
}) => Promise<{
|
|
574
|
+
txHash: string;
|
|
575
|
+
messageGuid: string;
|
|
576
|
+
fromChain: string;
|
|
577
|
+
toChain: string;
|
|
578
|
+
amountSent: bigint;
|
|
579
|
+
waitForDelivery: (options?: {
|
|
580
|
+
timeout?: number;
|
|
581
|
+
}) => Promise<{
|
|
582
|
+
success: boolean;
|
|
583
|
+
status: string;
|
|
584
|
+
dstTxHash?: string;
|
|
585
|
+
}>;
|
|
586
|
+
}>;
|
|
587
|
+
/** Optional auto-bridge function for automatic source chain selection */
|
|
588
|
+
autoBridgeFn?: (params: {
|
|
589
|
+
toChain: string;
|
|
590
|
+
amount: bigint;
|
|
591
|
+
recipient: string;
|
|
592
|
+
preferredSourceChain?: string;
|
|
593
|
+
slippageTolerance?: number;
|
|
594
|
+
}) => Promise<{
|
|
595
|
+
txHash: string;
|
|
596
|
+
messageGuid: string;
|
|
597
|
+
fromChain: string;
|
|
598
|
+
toChain: string;
|
|
599
|
+
amountSent: bigint;
|
|
600
|
+
waitForDelivery: (options?: {
|
|
601
|
+
timeout?: number;
|
|
602
|
+
}) => Promise<{
|
|
603
|
+
success: boolean;
|
|
604
|
+
status: string;
|
|
605
|
+
dstTxHash?: string;
|
|
606
|
+
}>;
|
|
607
|
+
}>;
|
|
608
|
+
/** Callback on successful delivery */
|
|
609
|
+
onSuccess?: (result: {
|
|
610
|
+
txHash: string;
|
|
611
|
+
dstTxHash?: string;
|
|
612
|
+
fromChain: string;
|
|
613
|
+
toChain: string;
|
|
614
|
+
}) => void;
|
|
615
|
+
/** Callback on error */
|
|
616
|
+
onError?: (error: Error) => void;
|
|
617
|
+
/** Whether to automatically wait for delivery (default: false) */
|
|
618
|
+
autoWaitForDelivery?: boolean;
|
|
619
|
+
}
|
|
620
|
+
interface BridgePaymentReturn {
|
|
621
|
+
/** Execute a bridge from a specific chain */
|
|
622
|
+
bridge: (params: {
|
|
623
|
+
fromChain: string;
|
|
624
|
+
toChain: string;
|
|
625
|
+
amount: bigint;
|
|
626
|
+
recipient: string;
|
|
627
|
+
slippageTolerance?: number;
|
|
628
|
+
}) => Promise<void>;
|
|
629
|
+
/** Execute an auto-bridge with automatic source chain selection */
|
|
630
|
+
autoBridge: (params: {
|
|
631
|
+
toChain: string;
|
|
632
|
+
amount: bigint;
|
|
633
|
+
recipient: string;
|
|
634
|
+
preferredSourceChain?: string;
|
|
635
|
+
slippageTolerance?: number;
|
|
636
|
+
}) => Promise<void>;
|
|
637
|
+
/** Current status */
|
|
638
|
+
status: Ref<BridgeStatus>;
|
|
639
|
+
/** Source chain transaction hash */
|
|
640
|
+
txHash: Ref<string | null>;
|
|
641
|
+
/** LayerZero message GUID */
|
|
642
|
+
messageGuid: Ref<string | null>;
|
|
643
|
+
/** Destination chain transaction hash */
|
|
644
|
+
dstTxHash: Ref<string | null>;
|
|
645
|
+
/** Error message if failed */
|
|
646
|
+
error: Ref<string | null>;
|
|
647
|
+
/** Whether bridge is in progress */
|
|
648
|
+
isLoading: ComputedRef<boolean>;
|
|
649
|
+
/** Whether bridge succeeded */
|
|
650
|
+
isSuccess: ComputedRef<boolean>;
|
|
651
|
+
/** Whether bridge failed */
|
|
652
|
+
isError: ComputedRef<boolean>;
|
|
653
|
+
/** Reset state */
|
|
654
|
+
reset: () => void;
|
|
655
|
+
}
|
|
656
|
+
/**
|
|
657
|
+
* Composable for cross-chain USDT0 bridging via WDK.
|
|
658
|
+
*
|
|
659
|
+
* @param options - Configuration including bridge functions and callbacks.
|
|
660
|
+
* @returns State and methods for managing bridge operations.
|
|
661
|
+
*
|
|
662
|
+
* @example
|
|
663
|
+
* ```vue
|
|
664
|
+
* <script setup>
|
|
665
|
+
* import { useBridgePayment } from "@t402/vue";
|
|
666
|
+
*
|
|
667
|
+
* const { autoBridge, isLoading, isSuccess, txHash, error } = useBridgePayment({
|
|
668
|
+
* bridgeFn: (params) => bridgeClient.bridge(params),
|
|
669
|
+
* autoBridgeFn: (params) => bridgeClient.autoBridge(params),
|
|
670
|
+
* onSuccess: (result) => console.log("Bridged:", result),
|
|
671
|
+
* });
|
|
672
|
+
* </script>
|
|
673
|
+
*
|
|
674
|
+
* <template>
|
|
675
|
+
* <button
|
|
676
|
+
* @click="autoBridge({ toChain: 'arbitrum', amount: 100_000000n, recipient: '0x...' })"
|
|
677
|
+
* :disabled="isLoading"
|
|
678
|
+
* >
|
|
679
|
+
* {{ isLoading ? "Bridging..." : "Bridge USDT0" }}
|
|
680
|
+
* </button>
|
|
681
|
+
* </template>
|
|
682
|
+
* ```
|
|
683
|
+
*/
|
|
684
|
+
declare function useBridgePayment(options: BridgePaymentOptions): BridgePaymentReturn;
|
|
685
|
+
|
|
686
|
+
type MultiSigStatus = 'idle' | 'initiating' | 'collecting' | 'submitting' | 'success' | 'error';
|
|
687
|
+
interface MultiSigPaymentOptions {
|
|
688
|
+
/** Initiate a multi-sig payment requiring threshold signatures */
|
|
689
|
+
initiateFn: (params: {
|
|
690
|
+
to: string;
|
|
691
|
+
amount: bigint;
|
|
692
|
+
token?: string;
|
|
693
|
+
}) => Promise<{
|
|
694
|
+
requestId: string;
|
|
695
|
+
userOpHash: string;
|
|
696
|
+
threshold: number;
|
|
697
|
+
collectedCount: number;
|
|
698
|
+
isReady: boolean;
|
|
699
|
+
}>;
|
|
700
|
+
/** Submit the transaction after collecting enough signatures */
|
|
701
|
+
submitFn: (requestId: string) => Promise<{
|
|
702
|
+
userOpHash: string;
|
|
703
|
+
wait: () => Promise<{
|
|
704
|
+
txHash: string;
|
|
705
|
+
success: boolean;
|
|
706
|
+
}>;
|
|
707
|
+
}>;
|
|
708
|
+
/** Callback on successful submission and confirmation */
|
|
709
|
+
onSuccess?: (receipt: {
|
|
710
|
+
txHash: string;
|
|
711
|
+
success: boolean;
|
|
712
|
+
}) => void;
|
|
713
|
+
/** Callback on error */
|
|
714
|
+
onError?: (error: Error) => void;
|
|
715
|
+
/** Whether to automatically wait for receipt after submission */
|
|
716
|
+
autoWait?: boolean;
|
|
717
|
+
}
|
|
718
|
+
interface MultiSigPaymentReturn {
|
|
719
|
+
/** Initiate a multi-sig payment */
|
|
720
|
+
initiate: (params: {
|
|
721
|
+
to: string;
|
|
722
|
+
amount: bigint;
|
|
723
|
+
token?: string;
|
|
724
|
+
}) => Promise<void>;
|
|
725
|
+
/** Submit the transaction (when enough signatures are collected) */
|
|
726
|
+
submit: () => Promise<void>;
|
|
727
|
+
/** Current status */
|
|
728
|
+
status: Ref<MultiSigStatus>;
|
|
729
|
+
/** Active request ID */
|
|
730
|
+
requestId: Ref<string | null>;
|
|
731
|
+
/** UserOperation hash */
|
|
732
|
+
userOpHash: Ref<string | null>;
|
|
733
|
+
/** Transaction hash after confirmation */
|
|
734
|
+
txHash: Ref<string | null>;
|
|
735
|
+
/** Required signature threshold */
|
|
736
|
+
threshold: Ref<number>;
|
|
737
|
+
/** Number of collected signatures */
|
|
738
|
+
collectedCount: Ref<number>;
|
|
739
|
+
/** Whether enough signatures are collected */
|
|
740
|
+
isReady: Ref<boolean>;
|
|
741
|
+
/** Error message if failed */
|
|
742
|
+
error: Ref<string | null>;
|
|
743
|
+
/** Whether operation is in progress */
|
|
744
|
+
isLoading: ComputedRef<boolean>;
|
|
745
|
+
/** Whether operation succeeded */
|
|
746
|
+
isSuccess: ComputedRef<boolean>;
|
|
747
|
+
/** Whether operation failed */
|
|
748
|
+
isError: ComputedRef<boolean>;
|
|
749
|
+
/** Reset state */
|
|
750
|
+
reset: () => void;
|
|
751
|
+
}
|
|
752
|
+
/**
|
|
753
|
+
* Composable for multi-sig Safe payments via WDK.
|
|
754
|
+
*
|
|
755
|
+
* @param options - Configuration including initiate/submit functions and callbacks.
|
|
756
|
+
* @returns State and methods for managing multi-sig payment lifecycle.
|
|
757
|
+
*
|
|
758
|
+
* @example
|
|
759
|
+
* ```vue
|
|
760
|
+
* <script setup>
|
|
761
|
+
* import { useMultiSigPayment } from "@t402/vue";
|
|
762
|
+
*
|
|
763
|
+
* const { initiate, submit, status, isReady, threshold, collectedCount, error } =
|
|
764
|
+
* useMultiSigPayment({
|
|
765
|
+
* initiateFn: (params) => multiSigClient.initiatePayment(params),
|
|
766
|
+
* submitFn: (requestId) => multiSigClient.submitRequest(requestId),
|
|
767
|
+
* onSuccess: (receipt) => console.log("Confirmed:", receipt.txHash),
|
|
768
|
+
* autoWait: true,
|
|
769
|
+
* });
|
|
770
|
+
* </script>
|
|
771
|
+
*
|
|
772
|
+
* <template>
|
|
773
|
+
* <div>
|
|
774
|
+
* <button v-if="status === 'idle'" @click="initiate({ to: '0x...', amount: 1000000n })">
|
|
775
|
+
* Initiate Payment
|
|
776
|
+
* </button>
|
|
777
|
+
* <p v-if="status === 'collecting'">Collecting: {{ collectedCount }}/{{ threshold }}</p>
|
|
778
|
+
* <button v-if="isReady" @click="submit">Submit Transaction</button>
|
|
779
|
+
* <p v-if="error">Error: {{ error }}</p>
|
|
780
|
+
* </div>
|
|
781
|
+
* </template>
|
|
782
|
+
* ```
|
|
783
|
+
*/
|
|
784
|
+
declare function useMultiSigPayment(options: MultiSigPaymentOptions): MultiSigPaymentReturn;
|
|
785
|
+
|
|
486
786
|
/** EVM Chain IDs (CAIP-2 format: eip155:chainId) */
|
|
487
787
|
declare const EVM_CHAIN_IDS: {
|
|
488
788
|
readonly ETHEREUM_MAINNET: "1";
|
|
@@ -597,4 +897,4 @@ declare function formatTokenAmount(amount: string, decimals?: number, maxDecimal
|
|
|
597
897
|
*/
|
|
598
898
|
declare function getAssetDisplayName(asset: string): string;
|
|
599
899
|
|
|
600
|
-
export { AddressDisplay, type AddressDisplayProps, EVM_CHAIN_IDS, PaymentButton, type PaymentButtonProps, PaymentDetails, type PaymentDetailsProps, type PaymentState, type PaymentStatus, PaymentStatusDisplay, type PaymentStatusDisplayProps, SOLANA_NETWORK_REFS, Spinner, type SpinnerProps, TON_NETWORK_REFS, TRON_NETWORK_REFS, choosePaymentRequirement, formatTokenAmount, getAssetDisplayName, getNetworkDisplayName, getPreferredNetworks, isEvmNetwork, isSvmNetwork, isTestnetNetwork, isTonNetwork, isTronNetwork, normalizePaymentRequirements, spinnerStyles, truncateAddress, useAsyncPayment, usePaymentRequired, usePaymentStatus };
|
|
900
|
+
export { AddressDisplay, type AddressDisplayProps, EVM_CHAIN_IDS, PaymentButton, type PaymentButtonProps, PaymentDetails, type PaymentDetailsProps, type PaymentState, type PaymentStatus, PaymentStatusDisplay, type PaymentStatusDisplayProps, SOLANA_NETWORK_REFS, Spinner, type SpinnerProps, TON_NETWORK_REFS, TRON_NETWORK_REFS, choosePaymentRequirement, formatTokenAmount, getAssetDisplayName, getNetworkDisplayName, getPreferredNetworks, isEvmNetwork, isSvmNetwork, isTestnetNetwork, isTonNetwork, isTronNetwork, normalizePaymentRequirements, spinnerStyles, truncateAddress, useAsyncPayment, useBridgePayment, useGaslessPayment, useMultiSigPayment, usePaymentRequired, usePaymentStatus };
|
package/dist/esm/index.js
CHANGED
|
@@ -292,17 +292,17 @@ function getNetworkDisplayName(network) {
|
|
|
292
292
|
return EVM_CHAIN_NAMES[chainId] ?? `Chain ${chainId}`;
|
|
293
293
|
}
|
|
294
294
|
if (network.startsWith("solana:")) {
|
|
295
|
-
const
|
|
296
|
-
return
|
|
295
|
+
const ref9 = network.split(":")[1];
|
|
296
|
+
return ref9 === SOLANA_NETWORK_REFS.DEVNET ? "Solana Devnet" : "Solana";
|
|
297
297
|
}
|
|
298
298
|
if (network.startsWith("ton:")) {
|
|
299
|
-
const
|
|
300
|
-
return
|
|
299
|
+
const ref9 = network.split(":")[1];
|
|
300
|
+
return ref9 === TON_NETWORK_REFS.TESTNET ? "TON Testnet" : "TON";
|
|
301
301
|
}
|
|
302
302
|
if (network.startsWith("tron:")) {
|
|
303
|
-
const
|
|
304
|
-
if (
|
|
305
|
-
if (
|
|
303
|
+
const ref9 = network.split(":")[1];
|
|
304
|
+
if (ref9 === TRON_NETWORK_REFS.NILE) return "TRON Nile";
|
|
305
|
+
if (ref9 === TRON_NETWORK_REFS.SHASTA) return "TRON Shasta";
|
|
306
306
|
return "TRON";
|
|
307
307
|
}
|
|
308
308
|
return network;
|
|
@@ -314,16 +314,16 @@ function isTestnetNetwork(network) {
|
|
|
314
314
|
return TESTNET_CHAIN_IDS.has(chainId);
|
|
315
315
|
}
|
|
316
316
|
if (network.startsWith("solana:")) {
|
|
317
|
-
const
|
|
318
|
-
return
|
|
317
|
+
const ref9 = network.split(":")[1];
|
|
318
|
+
return ref9 === SOLANA_NETWORK_REFS.DEVNET;
|
|
319
319
|
}
|
|
320
320
|
if (network.startsWith("ton:")) {
|
|
321
|
-
const
|
|
322
|
-
return
|
|
321
|
+
const ref9 = network.split(":")[1];
|
|
322
|
+
return ref9 === TON_NETWORK_REFS.TESTNET;
|
|
323
323
|
}
|
|
324
324
|
if (network.startsWith("tron:")) {
|
|
325
|
-
const
|
|
326
|
-
return
|
|
325
|
+
const ref9 = network.split(":")[1];
|
|
326
|
+
return ref9 === TRON_NETWORK_REFS.NILE || ref9 === TRON_NETWORK_REFS.SHASTA;
|
|
327
327
|
}
|
|
328
328
|
return false;
|
|
329
329
|
}
|
|
@@ -714,7 +714,230 @@ function useAsyncPayment(options) {
|
|
|
714
714
|
reset
|
|
715
715
|
};
|
|
716
716
|
}
|
|
717
|
+
function useGaslessPayment(options) {
|
|
718
|
+
const { payFn, onSuccess, onError, autoWait = true } = options;
|
|
719
|
+
const status = ref("idle");
|
|
720
|
+
const userOpHash = ref(null);
|
|
721
|
+
const txHash = ref(null);
|
|
722
|
+
const sponsored = ref(null);
|
|
723
|
+
const error = ref(null);
|
|
724
|
+
const isLoading = computed(() => status.value === "loading");
|
|
725
|
+
const isSuccess = computed(() => status.value === "success");
|
|
726
|
+
const isError = computed(() => status.value === "error");
|
|
727
|
+
const pay = async (params) => {
|
|
728
|
+
status.value = "loading";
|
|
729
|
+
error.value = null;
|
|
730
|
+
userOpHash.value = null;
|
|
731
|
+
txHash.value = null;
|
|
732
|
+
sponsored.value = null;
|
|
733
|
+
try {
|
|
734
|
+
const result = await payFn(params);
|
|
735
|
+
userOpHash.value = result.userOpHash;
|
|
736
|
+
sponsored.value = result.sponsored;
|
|
737
|
+
if (autoWait) {
|
|
738
|
+
const receipt = await result.wait();
|
|
739
|
+
txHash.value = receipt.txHash;
|
|
740
|
+
status.value = "success";
|
|
741
|
+
onSuccess?.(receipt);
|
|
742
|
+
} else {
|
|
743
|
+
status.value = "success";
|
|
744
|
+
onSuccess?.({ txHash: result.userOpHash, success: true });
|
|
745
|
+
}
|
|
746
|
+
} catch (err) {
|
|
747
|
+
const errorMessage = err instanceof Error ? err.message : "Gasless payment failed";
|
|
748
|
+
error.value = errorMessage;
|
|
749
|
+
status.value = "error";
|
|
750
|
+
onError?.(err instanceof Error ? err : new Error(errorMessage));
|
|
751
|
+
}
|
|
752
|
+
};
|
|
753
|
+
const reset = () => {
|
|
754
|
+
status.value = "idle";
|
|
755
|
+
userOpHash.value = null;
|
|
756
|
+
txHash.value = null;
|
|
757
|
+
sponsored.value = null;
|
|
758
|
+
error.value = null;
|
|
759
|
+
};
|
|
760
|
+
return {
|
|
761
|
+
pay,
|
|
762
|
+
status,
|
|
763
|
+
userOpHash,
|
|
764
|
+
txHash,
|
|
765
|
+
sponsored,
|
|
766
|
+
error,
|
|
767
|
+
isLoading,
|
|
768
|
+
isSuccess,
|
|
769
|
+
isError,
|
|
770
|
+
reset
|
|
771
|
+
};
|
|
772
|
+
}
|
|
773
|
+
function useBridgePayment(options) {
|
|
774
|
+
const { bridgeFn, autoBridgeFn, onSuccess, onError, autoWaitForDelivery = false } = options;
|
|
775
|
+
const status = ref("idle");
|
|
776
|
+
const txHash = ref(null);
|
|
777
|
+
const messageGuid = ref(null);
|
|
778
|
+
const dstTxHash = ref(null);
|
|
779
|
+
const error = ref(null);
|
|
780
|
+
const isLoading = computed(
|
|
781
|
+
() => status.value === "bridging" || status.value === "quoting" || status.value === "waiting"
|
|
782
|
+
);
|
|
783
|
+
const isSuccess = computed(() => status.value === "success");
|
|
784
|
+
const isError = computed(() => status.value === "error");
|
|
785
|
+
const executeBridge = async (bridgeCall) => {
|
|
786
|
+
status.value = "bridging";
|
|
787
|
+
error.value = null;
|
|
788
|
+
txHash.value = null;
|
|
789
|
+
messageGuid.value = null;
|
|
790
|
+
dstTxHash.value = null;
|
|
791
|
+
try {
|
|
792
|
+
const result = await bridgeCall();
|
|
793
|
+
txHash.value = result.txHash;
|
|
794
|
+
messageGuid.value = result.messageGuid;
|
|
795
|
+
if (autoWaitForDelivery) {
|
|
796
|
+
status.value = "waiting";
|
|
797
|
+
const delivery = await result.waitForDelivery();
|
|
798
|
+
if (delivery.dstTxHash) dstTxHash.value = delivery.dstTxHash;
|
|
799
|
+
status.value = "success";
|
|
800
|
+
onSuccess?.({
|
|
801
|
+
txHash: result.txHash,
|
|
802
|
+
dstTxHash: delivery.dstTxHash,
|
|
803
|
+
fromChain: result.fromChain,
|
|
804
|
+
toChain: result.toChain
|
|
805
|
+
});
|
|
806
|
+
} else {
|
|
807
|
+
status.value = "success";
|
|
808
|
+
onSuccess?.({
|
|
809
|
+
txHash: result.txHash,
|
|
810
|
+
fromChain: result.fromChain,
|
|
811
|
+
toChain: result.toChain
|
|
812
|
+
});
|
|
813
|
+
}
|
|
814
|
+
} catch (err) {
|
|
815
|
+
const errorMessage = err instanceof Error ? err.message : "Bridge operation failed";
|
|
816
|
+
error.value = errorMessage;
|
|
817
|
+
status.value = "error";
|
|
818
|
+
onError?.(err instanceof Error ? err : new Error(errorMessage));
|
|
819
|
+
}
|
|
820
|
+
};
|
|
821
|
+
const bridge = async (params) => {
|
|
822
|
+
await executeBridge(() => bridgeFn(params));
|
|
823
|
+
};
|
|
824
|
+
const autoBridge = async (params) => {
|
|
825
|
+
const fn = autoBridgeFn ?? (() => {
|
|
826
|
+
throw new Error("autoBridgeFn not provided");
|
|
827
|
+
});
|
|
828
|
+
await executeBridge(() => fn(params));
|
|
829
|
+
};
|
|
830
|
+
const reset = () => {
|
|
831
|
+
status.value = "idle";
|
|
832
|
+
txHash.value = null;
|
|
833
|
+
messageGuid.value = null;
|
|
834
|
+
dstTxHash.value = null;
|
|
835
|
+
error.value = null;
|
|
836
|
+
};
|
|
837
|
+
return {
|
|
838
|
+
bridge,
|
|
839
|
+
autoBridge,
|
|
840
|
+
status,
|
|
841
|
+
txHash,
|
|
842
|
+
messageGuid,
|
|
843
|
+
dstTxHash,
|
|
844
|
+
error,
|
|
845
|
+
isLoading,
|
|
846
|
+
isSuccess,
|
|
847
|
+
isError,
|
|
848
|
+
reset
|
|
849
|
+
};
|
|
850
|
+
}
|
|
851
|
+
function useMultiSigPayment(options) {
|
|
852
|
+
const { initiateFn, submitFn, onSuccess, onError, autoWait = true } = options;
|
|
853
|
+
const status = ref("idle");
|
|
854
|
+
const requestId = ref(null);
|
|
855
|
+
const userOpHash = ref(null);
|
|
856
|
+
const txHash = ref(null);
|
|
857
|
+
const threshold = ref(0);
|
|
858
|
+
const collectedCount = ref(0);
|
|
859
|
+
const isReady = ref(false);
|
|
860
|
+
const error = ref(null);
|
|
861
|
+
const isLoading = computed(() => status.value === "initiating" || status.value === "submitting");
|
|
862
|
+
const isSuccess = computed(() => status.value === "success");
|
|
863
|
+
const isError = computed(() => status.value === "error");
|
|
864
|
+
const initiate = async (params) => {
|
|
865
|
+
status.value = "initiating";
|
|
866
|
+
error.value = null;
|
|
867
|
+
requestId.value = null;
|
|
868
|
+
userOpHash.value = null;
|
|
869
|
+
txHash.value = null;
|
|
870
|
+
try {
|
|
871
|
+
const result = await initiateFn(params);
|
|
872
|
+
requestId.value = result.requestId;
|
|
873
|
+
userOpHash.value = result.userOpHash;
|
|
874
|
+
threshold.value = result.threshold;
|
|
875
|
+
collectedCount.value = result.collectedCount;
|
|
876
|
+
isReady.value = result.isReady;
|
|
877
|
+
status.value = "collecting";
|
|
878
|
+
} catch (err) {
|
|
879
|
+
const errorMessage = err instanceof Error ? err.message : "Failed to initiate multi-sig payment";
|
|
880
|
+
error.value = errorMessage;
|
|
881
|
+
status.value = "error";
|
|
882
|
+
onError?.(err instanceof Error ? err : new Error(errorMessage));
|
|
883
|
+
}
|
|
884
|
+
};
|
|
885
|
+
const submit = async () => {
|
|
886
|
+
if (!requestId.value) {
|
|
887
|
+
const err = new Error("No active request to submit");
|
|
888
|
+
error.value = err.message;
|
|
889
|
+
status.value = "error";
|
|
890
|
+
onError?.(err);
|
|
891
|
+
return;
|
|
892
|
+
}
|
|
893
|
+
status.value = "submitting";
|
|
894
|
+
error.value = null;
|
|
895
|
+
try {
|
|
896
|
+
const result = await submitFn(requestId.value);
|
|
897
|
+
if (autoWait) {
|
|
898
|
+
const receipt = await result.wait();
|
|
899
|
+
txHash.value = receipt.txHash;
|
|
900
|
+
status.value = "success";
|
|
901
|
+
onSuccess?.(receipt);
|
|
902
|
+
} else {
|
|
903
|
+
status.value = "success";
|
|
904
|
+
onSuccess?.({ txHash: result.userOpHash, success: true });
|
|
905
|
+
}
|
|
906
|
+
} catch (err) {
|
|
907
|
+
const errorMessage = err instanceof Error ? err.message : "Failed to submit multi-sig transaction";
|
|
908
|
+
error.value = errorMessage;
|
|
909
|
+
status.value = "error";
|
|
910
|
+
onError?.(err instanceof Error ? err : new Error(errorMessage));
|
|
911
|
+
}
|
|
912
|
+
};
|
|
913
|
+
const reset = () => {
|
|
914
|
+
status.value = "idle";
|
|
915
|
+
requestId.value = null;
|
|
916
|
+
userOpHash.value = null;
|
|
917
|
+
txHash.value = null;
|
|
918
|
+
threshold.value = 0;
|
|
919
|
+
collectedCount.value = 0;
|
|
920
|
+
isReady.value = false;
|
|
921
|
+
error.value = null;
|
|
922
|
+
};
|
|
923
|
+
return {
|
|
924
|
+
initiate,
|
|
925
|
+
submit,
|
|
926
|
+
status,
|
|
927
|
+
requestId,
|
|
928
|
+
userOpHash,
|
|
929
|
+
txHash,
|
|
930
|
+
threshold,
|
|
931
|
+
collectedCount,
|
|
932
|
+
isReady,
|
|
933
|
+
error,
|
|
934
|
+
isLoading,
|
|
935
|
+
isSuccess,
|
|
936
|
+
isError,
|
|
937
|
+
reset
|
|
938
|
+
};
|
|
939
|
+
}
|
|
717
940
|
|
|
718
|
-
export { AddressDisplay, EVM_CHAIN_IDS, PaymentButton, PaymentDetails, PaymentStatusDisplay, SOLANA_NETWORK_REFS, Spinner, TON_NETWORK_REFS, TRON_NETWORK_REFS, choosePaymentRequirement, formatTokenAmount, getAssetDisplayName, getNetworkDisplayName, getPreferredNetworks, isEvmNetwork, isSvmNetwork, isTestnetNetwork, isTonNetwork, isTronNetwork, normalizePaymentRequirements, spinnerStyles, truncateAddress, useAsyncPayment, usePaymentRequired, usePaymentStatus };
|
|
941
|
+
export { AddressDisplay, EVM_CHAIN_IDS, PaymentButton, PaymentDetails, PaymentStatusDisplay, SOLANA_NETWORK_REFS, Spinner, TON_NETWORK_REFS, TRON_NETWORK_REFS, choosePaymentRequirement, formatTokenAmount, getAssetDisplayName, getNetworkDisplayName, getPreferredNetworks, isEvmNetwork, isSvmNetwork, isTestnetNetwork, isTonNetwork, isTronNetwork, normalizePaymentRequirements, spinnerStyles, truncateAddress, useAsyncPayment, useBridgePayment, useGaslessPayment, useMultiSigPayment, usePaymentRequired, usePaymentStatus };
|
|
719
942
|
//# sourceMappingURL=index.js.map
|
|
720
943
|
//# sourceMappingURL=index.js.map
|