@sodax/dapp-kit 1.0.0-rc.8 → 1.0.1-beta-rc1

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 CHANGED
@@ -24,23 +24,30 @@ declare function useEstimateGas<T extends SpokeProvider = SpokeProvider>(spokePr
24
24
  /**
25
25
  * Hook for deriving user wallet address for hub abstraction.
26
26
  *
27
- * This hook derives the user's abstracted wallet address for the hub chain.
28
- * If the spoke chain is the same as the hub chain, it returns the original wallet address.
29
- * Otherwise, it returns the abstracted wallet address for cross-chain operations.
27
+ * This hook derives the user's abstracted wallet address for the hub chain based on the spoke chain ID and address.
28
+ * If the spoke chain is the same as the hub chain, it returns the encoded spoke address.
29
+ * Otherwise, it derives and returns the abstracted wallet address for cross-chain operations.
30
30
  *
31
- * @param spokeProvider - The spoke provider instance for the origin chain
32
- * @param walletAddress - Optional user wallet address on spoke chain. If not provided, will fetch from spokeProvider
31
+ * The query is automatically enabled when both `spokeChainId` and `spokeAddress` are provided.
32
+ * This is a deterministic operation, so the result is cached and not refetched automatically.
33
+ *
34
+ * @param spokeChainId - Optional spoke chain ID. If not provided, the query will be disabled.
35
+ * @param spokeAddress - Optional user wallet address on the spoke chain. If not provided, the query will be disabled.
33
36
  * @returns A React Query result object containing:
34
- * - data: The derived user wallet address when available
37
+ * - data: The derived user wallet address (Address) when available
35
38
  * - isLoading: Loading state indicator
36
- * - error: Any error that occurred during derivation
39
+ * - error: Any error that occurred during derivation (Error)
37
40
  *
38
41
  * @example
39
42
  * ```typescript
40
- * const { data: derivedAddress, isLoading, error } = useDeriveUserWalletAddress(spokeProvider, userAddress);
43
+ * const { data: derivedAddress, isLoading, error } = useDeriveUserWalletAddress(spokeChainId, userAddress);
44
+ *
45
+ * if (isLoading) return <div>Deriving address...</div>;
46
+ * if (error) return <div>Error: {error.message}</div>;
47
+ * if (derivedAddress) return <div>Derived Address: {derivedAddress}</div>;
41
48
  * ```
42
49
  */
43
- declare function useDeriveUserWalletAddress(spokeProvider: SpokeProvider | undefined, walletAddress?: string | undefined): UseQueryResult<Address, Error>;
50
+ declare function useDeriveUserWalletAddress(spokeChainId?: SpokeChainId | SpokeProvider | undefined, spokeAddress?: string | undefined): UseQueryResult<Address, Error>;
44
51
 
45
52
  /**
46
53
  * React hook to check if a Stellar account has a sufficient trustline for a given token and amount.
package/dist/index.d.ts CHANGED
@@ -24,23 +24,30 @@ declare function useEstimateGas<T extends SpokeProvider = SpokeProvider>(spokePr
24
24
  /**
25
25
  * Hook for deriving user wallet address for hub abstraction.
26
26
  *
27
- * This hook derives the user's abstracted wallet address for the hub chain.
28
- * If the spoke chain is the same as the hub chain, it returns the original wallet address.
29
- * Otherwise, it returns the abstracted wallet address for cross-chain operations.
27
+ * This hook derives the user's abstracted wallet address for the hub chain based on the spoke chain ID and address.
28
+ * If the spoke chain is the same as the hub chain, it returns the encoded spoke address.
29
+ * Otherwise, it derives and returns the abstracted wallet address for cross-chain operations.
30
30
  *
31
- * @param spokeProvider - The spoke provider instance for the origin chain
32
- * @param walletAddress - Optional user wallet address on spoke chain. If not provided, will fetch from spokeProvider
31
+ * The query is automatically enabled when both `spokeChainId` and `spokeAddress` are provided.
32
+ * This is a deterministic operation, so the result is cached and not refetched automatically.
33
+ *
34
+ * @param spokeChainId - Optional spoke chain ID. If not provided, the query will be disabled.
35
+ * @param spokeAddress - Optional user wallet address on the spoke chain. If not provided, the query will be disabled.
33
36
  * @returns A React Query result object containing:
34
- * - data: The derived user wallet address when available
37
+ * - data: The derived user wallet address (Address) when available
35
38
  * - isLoading: Loading state indicator
36
- * - error: Any error that occurred during derivation
39
+ * - error: Any error that occurred during derivation (Error)
37
40
  *
38
41
  * @example
39
42
  * ```typescript
40
- * const { data: derivedAddress, isLoading, error } = useDeriveUserWalletAddress(spokeProvider, userAddress);
43
+ * const { data: derivedAddress, isLoading, error } = useDeriveUserWalletAddress(spokeChainId, userAddress);
44
+ *
45
+ * if (isLoading) return <div>Deriving address...</div>;
46
+ * if (error) return <div>Error: {error.message}</div>;
47
+ * if (derivedAddress) return <div>Derived Address: {derivedAddress}</div>;
41
48
  * ```
42
49
  */
43
- declare function useDeriveUserWalletAddress(spokeProvider: SpokeProvider | undefined, walletAddress?: string | undefined): UseQueryResult<Address, Error>;
50
+ declare function useDeriveUserWalletAddress(spokeChainId?: SpokeChainId | SpokeProvider | undefined, spokeAddress?: string | undefined): UseQueryResult<Address, Error>;
44
51
 
45
52
  /**
46
53
  * React hook to check if a Stellar account has a sufficient trustline for a given token and amount.
package/dist/index.js CHANGED
@@ -30,17 +30,18 @@ function useEstimateGas(spokeProvider) {
30
30
  }
31
31
  });
32
32
  }
33
- function useDeriveUserWalletAddress(spokeProvider, walletAddress) {
33
+ function useDeriveUserWalletAddress(spokeChainId, spokeAddress) {
34
34
  const { sodax } = useSodaxContext();
35
35
  return reactQuery.useQuery({
36
- queryKey: ["deriveUserWalletAddress", spokeProvider?.chainConfig.chain.id, walletAddress],
36
+ queryKey: ["deriveUserWalletAddress", spokeChainId, spokeAddress],
37
37
  queryFn: async () => {
38
- if (!spokeProvider) {
39
- throw new Error("Spoke provider is required");
38
+ if (!spokeChainId || !spokeAddress) {
39
+ throw new Error("Spoke chain id and address are required");
40
40
  }
41
- return await sdk.deriveUserWalletAddress(spokeProvider, sodax.hubProvider, walletAddress);
41
+ spokeChainId = typeof spokeChainId === "object" ? spokeChainId.chainConfig.chain.id : spokeChainId;
42
+ return await sdk.deriveUserWalletAddress(sodax.hubProvider, spokeChainId, spokeAddress);
42
43
  },
43
- enabled: !!spokeProvider,
44
+ enabled: !!spokeChainId && !!spokeAddress,
44
45
  refetchInterval: false
45
46
  // This is a deterministic operation, no need to refetch
46
47
  });
@@ -402,7 +403,7 @@ var useQuote = (payload) => {
402
403
  if (!payload) {
403
404
  return void 0;
404
405
  }
405
- return sodax.swap.getQuote(payload);
406
+ return sodax.swaps.getQuote(payload);
406
407
  },
407
408
  enabled: !!payload,
408
409
  refetchInterval: 3e3
@@ -416,7 +417,7 @@ function useSwap(spokeProvider) {
416
417
  if (!spokeProvider) {
417
418
  throw new Error("Spoke provider not found");
418
419
  }
419
- return sodax.swap.swap({
420
+ return sodax.swaps.swap({
420
421
  intentParams: params,
421
422
  spokeProvider
422
423
  });
@@ -431,7 +432,7 @@ var useStatus = (intent_tx_hash) => {
431
432
  return reactQuery.useQuery({
432
433
  queryKey: [intent_tx_hash],
433
434
  queryFn: async () => {
434
- return sodax.swap.getStatus({ intent_tx_hash });
435
+ return sodax.swaps.getStatus({ intent_tx_hash });
435
436
  },
436
437
  refetchInterval: 3e3
437
438
  // 3s
@@ -445,7 +446,7 @@ function useSwapAllowance(params, spokeProvider) {
445
446
  if (!spokeProvider || !params) {
446
447
  return false;
447
448
  }
448
- const allowance = await sodax.swap.isAllowanceValid({
449
+ const allowance = await sodax.swaps.isAllowanceValid({
449
450
  intentParams: params,
450
451
  spokeProvider
451
452
  });
@@ -474,7 +475,7 @@ function useSwapApprove(params, spokeProvider) {
474
475
  if (!params2) {
475
476
  throw new Error("Swap Params not found");
476
477
  }
477
- const allowance = await sodax.swap.approve({
478
+ const allowance = await sodax.swaps.approve({
478
479
  intentParams: params2,
479
480
  spokeProvider
480
481
  });
@@ -501,7 +502,7 @@ function useCancelSwap(spokeProvider) {
501
502
  if (!spokeProvider) {
502
503
  throw new Error("Spoke provider not found");
503
504
  }
504
- return sodax.swap.cancelIntent(intent, spokeProvider, raw);
505
+ return sodax.swaps.cancelIntent(intent, spokeProvider, raw);
505
506
  }
506
507
  });
507
508
  }