@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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sodax/dapp-kit",
3
3
  "license": "MIT",
4
- "version": "1.0.0-rc.8",
4
+ "version": "1.0.1-beta-rc1",
5
5
  "description": "dapp-kit of New World",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -16,8 +16,8 @@
16
16
  },
17
17
  "dependencies": {
18
18
  "viem": "2.29.2",
19
- "@sodax/sdk": "1.0.0-rc.8",
20
- "@sodax/types": "1.0.0-rc.8"
19
+ "@sodax/sdk": "1.0.1-beta-rc1",
20
+ "@sodax/types": "1.0.1-beta-rc1"
21
21
  },
22
22
  "devDependencies": {
23
23
  "@types/react": "18.3.1",
@@ -1,5 +1,12 @@
1
1
  import { useSodaxContext } from '../shared/useSodaxContext';
2
- import type { BridgeError, BridgeErrorCode, SpokeTxHash, HubTxHash, Result, CreateBridgeIntentParams } from '@sodax/sdk';
2
+ import type {
3
+ BridgeError,
4
+ BridgeErrorCode,
5
+ SpokeTxHash,
6
+ HubTxHash,
7
+ Result,
8
+ CreateBridgeIntentParams,
9
+ } from '@sodax/sdk';
3
10
  import { useMutation, type UseMutationResult } from '@tanstack/react-query';
4
11
  import type { SpokeProvider } from '@sodax/sdk';
5
12
 
@@ -1,15 +1,15 @@
1
- import type { XToken } from '@sodax/types';
2
-
3
- export const MIGRATION_MODE_ICX_SODA = 'icxsoda';
4
- export const MIGRATION_MODE_BNUSD = 'bnusd';
5
-
6
- export type MigrationMode = typeof MIGRATION_MODE_ICX_SODA | typeof MIGRATION_MODE_BNUSD;
7
-
8
- export interface MigrationIntentParams {
9
- token: XToken | undefined;
10
- amount: string | undefined;
11
- sourceAddress: string | undefined;
12
- migrationMode?: MigrationMode;
13
- toToken?: XToken;
14
- destinationAddress?: string;
15
- }
1
+ import type { XToken } from '@sodax/types';
2
+
3
+ export const MIGRATION_MODE_ICX_SODA = 'icxsoda';
4
+ export const MIGRATION_MODE_BNUSD = 'bnusd';
5
+
6
+ export type MigrationMode = typeof MIGRATION_MODE_ICX_SODA | typeof MIGRATION_MODE_BNUSD;
7
+
8
+ export interface MigrationIntentParams {
9
+ token: XToken | undefined;
10
+ amount: string | undefined;
11
+ sourceAddress: string | undefined;
12
+ migrationMode?: MigrationMode;
13
+ toToken?: XToken;
14
+ destinationAddress?: string;
15
+ }
@@ -24,9 +24,7 @@ import { useSodaxContext } from '../shared/useSodaxContext';
24
24
  * - isLoading: Loading state indicator.
25
25
  * - error: Any error that occurred during data fetching.
26
26
  */
27
- export function useAToken(
28
- aToken: Address | undefined,
29
- ): UseQueryResult<XToken, Error> {
27
+ export function useAToken(aToken: Address | undefined): UseQueryResult<XToken, Error> {
30
28
  const { sodax } = useSodaxContext();
31
29
 
32
30
  return useQuery({
@@ -56,7 +56,7 @@ export function useSpokeProvider(
56
56
  if (!spokeChainId) return undefined;
57
57
  if (!xChainType) return undefined;
58
58
  if (!rpcConfig) return undefined;
59
-
59
+
60
60
  if (xChainType === 'EVM') {
61
61
  if (spokeChainId === SONIC_MAINNET_CHAIN_ID) {
62
62
  return new SonicSpokeProvider(
@@ -2,4 +2,4 @@ export * from './useSodaxContext';
2
2
  export * from './useEstimateGas';
3
3
  export * from './useDeriveUserWalletAddress';
4
4
  export * from './useStellarTrustlineCheck';
5
- export * from './useRequestTrustline';
5
+ export * from './useRequestTrustline';
@@ -1,5 +1,4 @@
1
- // packages/dapp-kit/src/hooks/shared/useDeriveUserWalletAddress.ts
2
- import { deriveUserWalletAddress, type SpokeProvider } from '@sodax/sdk';
1
+ import { deriveUserWalletAddress, type SpokeProvider, type SpokeChainId } from '@sodax/sdk';
3
2
  import { useQuery, type UseQueryResult } from '@tanstack/react-query';
4
3
  import { useSodaxContext } from './useSodaxContext';
5
4
  import type { Address } from 'viem';
@@ -7,38 +6,48 @@ import type { Address } from 'viem';
7
6
  /**
8
7
  * Hook for deriving user wallet address for hub abstraction.
9
8
  *
10
- * This hook derives the user's abstracted wallet address for the hub chain.
11
- * If the spoke chain is the same as the hub chain, it returns the original wallet address.
12
- * Otherwise, it returns the abstracted wallet address for cross-chain operations.
9
+ * This hook derives the user's abstracted wallet address for the hub chain based on the spoke chain ID and address.
10
+ * If the spoke chain is the same as the hub chain, it returns the encoded spoke address.
11
+ * Otherwise, it derives and returns the abstracted wallet address for cross-chain operations.
13
12
  *
14
- * @param spokeProvider - The spoke provider instance for the origin chain
15
- * @param walletAddress - Optional user wallet address on spoke chain. If not provided, will fetch from spokeProvider
13
+ * The query is automatically enabled when both `spokeChainId` and `spokeAddress` are provided.
14
+ * This is a deterministic operation, so the result is cached and not refetched automatically.
15
+ *
16
+ * @param spokeChainId - Optional spoke chain ID. If not provided, the query will be disabled.
17
+ * @param spokeAddress - Optional user wallet address on the spoke chain. If not provided, the query will be disabled.
16
18
  * @returns A React Query result object containing:
17
- * - data: The derived user wallet address when available
19
+ * - data: The derived user wallet address (Address) when available
18
20
  * - isLoading: Loading state indicator
19
- * - error: Any error that occurred during derivation
21
+ * - error: Any error that occurred during derivation (Error)
20
22
  *
21
23
  * @example
22
24
  * ```typescript
23
- * const { data: derivedAddress, isLoading, error } = useDeriveUserWalletAddress(spokeProvider, userAddress);
25
+ * const { data: derivedAddress, isLoading, error } = useDeriveUserWalletAddress(spokeChainId, userAddress);
26
+ *
27
+ * if (isLoading) return <div>Deriving address...</div>;
28
+ * if (error) return <div>Error: {error.message}</div>;
29
+ * if (derivedAddress) return <div>Derived Address: {derivedAddress}</div>;
24
30
  * ```
25
31
  */
26
32
  export function useDeriveUserWalletAddress(
27
- spokeProvider: SpokeProvider | undefined,
28
- walletAddress?: string | undefined,
33
+ spokeChainId?: SpokeChainId | SpokeProvider | undefined,
34
+ spokeAddress?: string | undefined,
29
35
  ): UseQueryResult<Address, Error> {
30
36
  const { sodax } = useSodaxContext();
31
37
 
32
38
  return useQuery({
33
- queryKey: ['deriveUserWalletAddress', spokeProvider?.chainConfig.chain.id, walletAddress],
39
+ queryKey: ['deriveUserWalletAddress', spokeChainId, spokeAddress],
34
40
  queryFn: async (): Promise<Address> => {
35
- if (!spokeProvider) {
36
- throw new Error('Spoke provider is required');
41
+ if (!spokeChainId || !spokeAddress) {
42
+ throw new Error('Spoke chain id and address are required');
37
43
  }
38
44
 
39
- return await deriveUserWalletAddress(spokeProvider, sodax.hubProvider, walletAddress);
45
+ // Determine if spokeChainId is a SpokeProvider object or SpokeChainId value
46
+ spokeChainId = typeof spokeChainId === 'object' ? spokeChainId.chainConfig.chain.id : spokeChainId;
47
+
48
+ return await deriveUserWalletAddress(sodax.hubProvider, spokeChainId, spokeAddress);
40
49
  },
41
- enabled: !!spokeProvider,
50
+ enabled: !!spokeChainId && !!spokeAddress,
42
51
  refetchInterval: false, // This is a deterministic operation, no need to refetch
43
52
  });
44
53
  }
@@ -38,7 +38,7 @@ export function useCancelSwap(
38
38
  if (!spokeProvider) {
39
39
  throw new Error('Spoke provider not found');
40
40
  }
41
- return sodax.swap.cancelIntent(intent, spokeProvider, raw);
41
+ return sodax.swaps.cancelIntent(intent, spokeProvider, raw);
42
42
  },
43
43
  });
44
44
  }
@@ -42,7 +42,7 @@ export const useQuote = (
42
42
  payload: SolverIntentQuoteRequest | undefined,
43
43
  ): UseQueryResult<Result<SolverIntentQuoteResponse, SolverErrorResponse> | undefined> => {
44
44
  const { sodax } = useSodaxContext();
45
-
45
+
46
46
  // Create a serializable query key by converting BigInt to string
47
47
  const queryKey = useMemo(() => {
48
48
  if (!payload) return ['quote', undefined];
@@ -61,7 +61,7 @@ export const useQuote = (
61
61
  if (!payload) {
62
62
  return undefined;
63
63
  }
64
- return sodax.swap.getQuote(payload);
64
+ return sodax.swaps.getQuote(payload);
65
65
  },
66
66
  enabled: !!payload,
67
67
  refetchInterval: 3000,
@@ -37,7 +37,7 @@ export const useStatus = (
37
37
  return useQuery({
38
38
  queryKey: [intent_tx_hash],
39
39
  queryFn: async () => {
40
- return sodax.swap.getStatus({ intent_tx_hash });
40
+ return sodax.swaps.getStatus({ intent_tx_hash });
41
41
  },
42
42
  refetchInterval: 3000, // 3s
43
43
  });
@@ -47,7 +47,7 @@ export function useSwap(
47
47
  if (!spokeProvider) {
48
48
  throw new Error('Spoke provider not found');
49
49
  }
50
- return sodax.swap.swap({
50
+ return sodax.swaps.swap({
51
51
  intentParams: params,
52
52
  spokeProvider,
53
53
  });
@@ -33,7 +33,7 @@ export function useSwapAllowance(
33
33
  if (!spokeProvider || !params) {
34
34
  return false;
35
35
  }
36
- const allowance = await sodax.swap.isAllowanceValid({
36
+ const allowance = await sodax.swaps.isAllowanceValid({
37
37
  intentParams: params,
38
38
  spokeProvider,
39
39
  });
@@ -44,7 +44,7 @@ export function useSwapApprove(
44
44
  throw new Error('Swap Params not found');
45
45
  }
46
46
 
47
- const allowance = await sodax.swap.approve({
47
+ const allowance = await sodax.swaps.approve({
48
48
  intentParams: params,
49
49
  spokeProvider,
50
50
  });