@sodax/dapp-kit 0.0.1-rc.22 → 0.0.1-rc.24

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.
Files changed (42) hide show
  1. package/dist/hooks/backend/index.d.ts +17 -0
  2. package/dist/hooks/backend/index.d.ts.map +1 -0
  3. package/dist/hooks/backend/useBackendAllMoneyMarketAssets.d.ts +37 -0
  4. package/dist/hooks/backend/useBackendAllMoneyMarketAssets.d.ts.map +1 -0
  5. package/dist/hooks/backend/useBackendAllMoneyMarketBorrowers.d.ts +45 -0
  6. package/dist/hooks/backend/useBackendAllMoneyMarketBorrowers.d.ts.map +1 -0
  7. package/dist/hooks/backend/useBackendIntentByHash.d.ts +36 -0
  8. package/dist/hooks/backend/useBackendIntentByHash.d.ts.map +1 -0
  9. package/dist/hooks/backend/useBackendIntentByTxHash.d.ts +35 -0
  10. package/dist/hooks/backend/useBackendIntentByTxHash.d.ts.map +1 -0
  11. package/dist/hooks/backend/useBackendMoneyMarketAsset.d.ts +38 -0
  12. package/dist/hooks/backend/useBackendMoneyMarketAsset.d.ts.map +1 -0
  13. package/dist/hooks/backend/useBackendMoneyMarketAssetBorrowers.d.ts +47 -0
  14. package/dist/hooks/backend/useBackendMoneyMarketAssetBorrowers.d.ts.map +1 -0
  15. package/dist/hooks/backend/useBackendMoneyMarketAssetSuppliers.d.ts +47 -0
  16. package/dist/hooks/backend/useBackendMoneyMarketAssetSuppliers.d.ts.map +1 -0
  17. package/dist/hooks/backend/useBackendMoneyMarketPosition.d.ts +37 -0
  18. package/dist/hooks/backend/useBackendMoneyMarketPosition.d.ts.map +1 -0
  19. package/dist/hooks/backend/useBackendOrderbook.d.ts +46 -0
  20. package/dist/hooks/backend/useBackendOrderbook.d.ts.map +1 -0
  21. package/dist/hooks/bridge/useGetBridgeableTokens.d.ts +1 -1
  22. package/dist/hooks/bridge/useGetBridgeableTokens.d.ts.map +1 -1
  23. package/dist/hooks/index.d.ts +1 -0
  24. package/dist/hooks/index.d.ts.map +1 -1
  25. package/dist/index.js +139 -0
  26. package/dist/index.js.map +1 -1
  27. package/dist/index.mjs +131 -1
  28. package/dist/index.mjs.map +1 -1
  29. package/package.json +2 -2
  30. package/src/hooks/backend/README.md +135 -0
  31. package/src/hooks/backend/index.ts +23 -0
  32. package/src/hooks/backend/useBackendAllMoneyMarketAssets.ts +49 -0
  33. package/src/hooks/backend/useBackendAllMoneyMarketBorrowers.ts +61 -0
  34. package/src/hooks/backend/useBackendIntentByHash.ts +53 -0
  35. package/src/hooks/backend/useBackendIntentByTxHash.ts +52 -0
  36. package/src/hooks/backend/useBackendMoneyMarketAsset.ts +57 -0
  37. package/src/hooks/backend/useBackendMoneyMarketAssetBorrowers.ts +67 -0
  38. package/src/hooks/backend/useBackendMoneyMarketAssetSuppliers.ts +67 -0
  39. package/src/hooks/backend/useBackendMoneyMarketPosition.ts +56 -0
  40. package/src/hooks/backend/useBackendOrderbook.ts +63 -0
  41. package/src/hooks/bridge/useGetBridgeableTokens.ts +1 -1
  42. package/src/hooks/index.ts +1 -0
@@ -0,0 +1,61 @@
1
+ // packages/dapp-kit/src/hooks/backend/useAllMoneyMarketBorrowers.ts
2
+ import { useQuery, type UseQueryResult } from '@tanstack/react-query';
3
+ import type { MoneyMarketBorrowers } from '@sodax/sdk';
4
+ import { useSodaxContext } from '../shared/useSodaxContext';
5
+
6
+ /**
7
+ * Hook for fetching all money market borrowers from the backend API.
8
+ *
9
+ * This hook provides access to the list of all borrowers across all money market assets,
10
+ * with pagination support. The data is automatically fetched and cached using React Query.
11
+ *
12
+ * @param {Object} params - Pagination parameters for fetching all borrowers
13
+ * @param {string} params.offset - The offset for pagination (number as string)
14
+ * @param {string} params.limit - The limit for pagination (number as string)
15
+ *
16
+ * @returns {UseQueryResult<MoneyMarketBorrowers | undefined>} A query result object containing:
17
+ * - data: The all borrowers data when available
18
+ * - isLoading: Boolean indicating if the request is in progress
19
+ * - error: Error object if the request failed
20
+ * - refetch: Function to manually trigger a data refresh
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * const { data: borrowers, isLoading, error } = useAllMoneyMarketBorrowers({
25
+ * offset: '0',
26
+ * limit: '50'
27
+ * });
28
+ *
29
+ * if (isLoading) return <div>Loading borrowers...</div>;
30
+ * if (error) return <div>Error: {error.message}</div>;
31
+ * if (borrowers) {
32
+ * console.log('Total borrowers:', borrowers.total);
33
+ * console.log('Borrowers:', borrowers.borrowers);
34
+ * }
35
+ * ```
36
+ *
37
+ * @remarks
38
+ * - The query is disabled when params are undefined or invalid
39
+ * - Uses React Query for efficient caching and state management
40
+ * - Automatically handles error states and loading indicators
41
+ * - Supports pagination through offset and limit parameters
42
+ * - Returns borrowers across all money market assets
43
+ */
44
+ export const useBackendAllMoneyMarketBorrowers = (
45
+ params: { offset: string; limit: string } | undefined,
46
+ ): UseQueryResult<MoneyMarketBorrowers | undefined> => {
47
+ const { sodax } = useSodaxContext();
48
+
49
+ return useQuery({
50
+ queryKey: ['backend', 'moneymarket', 'borrowers', 'all', params],
51
+ queryFn: async (): Promise<MoneyMarketBorrowers | undefined> => {
52
+ if (!params || !params.offset || !params.limit) {
53
+ return undefined;
54
+ }
55
+
56
+ return sodax.backendApiService.getAllMoneyMarketBorrowers(params);
57
+ },
58
+ enabled: !!params && !!params.offset && !!params.limit,
59
+ retry: 3,
60
+ });
61
+ };
@@ -0,0 +1,53 @@
1
+ // packages/dapp-kit/src/hooks/backend/useIntentByHash.ts
2
+ import { useQuery, type UseQueryResult } from '@tanstack/react-query';
3
+ import type { IntentResponse } from '@sodax/sdk';
4
+ import { useSodaxContext } from '../shared/useSodaxContext';
5
+
6
+ /**
7
+ * Hook for fetching intent details by intent hash from the backend API.
8
+ *
9
+ * This hook provides access to intent data using the intent hash directly,
10
+ * including intent details, events, and transaction information. The data is automatically
11
+ * fetched and cached using React Query.
12
+ *
13
+ * @param {string | undefined} intentHash - The intent hash to fetch intent for. If undefined, the query will be disabled.
14
+ *
15
+ * @returns {UseQueryResult<IntentResponse | undefined>} A query result object containing:
16
+ * - data: The intent response data when available
17
+ * - isLoading: Boolean indicating if the request is in progress
18
+ * - error: Error object if the request failed
19
+ * - refetch: Function to manually trigger a data refresh
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * const { data: intent, isLoading, error } = useIntentByHash('0xabc...');
24
+ *
25
+ * if (isLoading) return <div>Loading intent...</div>;
26
+ * if (error) return <div>Error: {error.message}</div>;
27
+ * if (intent) {
28
+ * console.log('Intent found:', intent.intentHash);
29
+ * console.log('Open status:', intent.open);
30
+ * }
31
+ * ```
32
+ *
33
+ * @remarks
34
+ * - The query is disabled when intentHash is undefined or empty
35
+ * - Uses React Query for efficient caching and state management
36
+ * - Automatically handles error states and loading indicators
37
+ */
38
+ export const useBackendIntentByHash = (intentHash: string | undefined): UseQueryResult<IntentResponse | undefined> => {
39
+ const { sodax } = useSodaxContext();
40
+
41
+ return useQuery({
42
+ queryKey: ['backend', 'intent', 'hash', intentHash],
43
+ queryFn: async (): Promise<IntentResponse | undefined> => {
44
+ if (!intentHash) {
45
+ return undefined;
46
+ }
47
+
48
+ return sodax.backendApiService.getIntentByHash(intentHash);
49
+ },
50
+ enabled: !!intentHash && intentHash.length > 0,
51
+ retry: 3,
52
+ });
53
+ };
@@ -0,0 +1,52 @@
1
+ // packages/dapp-kit/src/hooks/backend/useIntentByTxHash.ts
2
+ import { useQuery, type UseQueryResult } from '@tanstack/react-query';
3
+ import type { IntentResponse } from '@sodax/sdk';
4
+ import { useSodaxContext } from '../shared/useSodaxContext';
5
+
6
+ /**
7
+ * Hook for fetching intent details by transaction hash from the backend API.
8
+ *
9
+ * This hook provides access to intent data associated with a specific transaction hash,
10
+ * including intent details, events, and transaction information. The data is automatically
11
+ * fetched and cached using React Query.
12
+ *
13
+ * @param {string | undefined} txHash - The transaction hash to fetch intent for. If undefined, the query will be disabled.
14
+ *
15
+ * @returns {UseQueryResult<IntentResponse | undefined>} A query result object containing:
16
+ * - data: The intent response data when available
17
+ * - isLoading: Boolean indicating if the request is in progress
18
+ * - error: Error object if the request failed
19
+ * - refetch: Function to manually trigger a data refresh
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * const { data: intent, isLoading, error } = useIntentByTxHash('0x123...');
24
+ *
25
+ * if (isLoading) return <div>Loading intent...</div>;
26
+ * if (error) return <div>Error: {error.message}</div>;
27
+ * if (intent) {
28
+ * console.log('Intent found:', intent.intentHash);
29
+ * }
30
+ * ```
31
+ *
32
+ * @remarks
33
+ * - The query is disabled when txHash is undefined or empty
34
+ * - Uses React Query for efficient caching and state management
35
+ * - Automatically handles error states and loading indicators
36
+ */
37
+ export const useBackendIntentByTxHash = (txHash: string | undefined): UseQueryResult<IntentResponse | undefined> => {
38
+ const { sodax } = useSodaxContext();
39
+
40
+ return useQuery({
41
+ queryKey: ['backend', 'intent', 'txHash', txHash],
42
+ queryFn: async (): Promise<IntentResponse | undefined> => {
43
+ if (!txHash) {
44
+ return undefined;
45
+ }
46
+
47
+ return sodax.backendApiService.getIntentByTxHash(txHash);
48
+ },
49
+ enabled: !!txHash && txHash.length > 0,
50
+ retry: 3,
51
+ });
52
+ };
@@ -0,0 +1,57 @@
1
+ // packages/dapp-kit/src/hooks/backend/useMoneyMarketAsset.ts
2
+ import { useQuery, type UseQueryResult } from '@tanstack/react-query';
3
+ import type { MoneyMarketAsset } from '@sodax/sdk';
4
+ import { useSodaxContext } from '../shared/useSodaxContext';
5
+
6
+ /**
7
+ * Hook for fetching specific money market asset details from the backend API.
8
+ *
9
+ * This hook provides access to detailed information for a specific money market asset,
10
+ * including reserve information, liquidity rates, borrow rates, and market statistics.
11
+ * The data is automatically fetched and cached using React Query.
12
+ *
13
+ * @param {string | undefined} reserveAddress - The reserve contract address. If undefined, the query will be disabled.
14
+ *
15
+ * @returns {UseQueryResult<MoneyMarketAsset | undefined>} A query result object containing:
16
+ * - data: The money market asset data when available
17
+ * - isLoading: Boolean indicating if the request is in progress
18
+ * - error: Error object if the request failed
19
+ * - refetch: Function to manually trigger a data refresh
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * const { data: asset, isLoading, error } = useMoneyMarketAsset('0xabc...');
24
+ *
25
+ * if (isLoading) return <div>Loading asset...</div>;
26
+ * if (error) return <div>Error: {error.message}</div>;
27
+ * if (asset) {
28
+ * console.log('Asset symbol:', asset.symbol);
29
+ * console.log('Liquidity rate:', asset.liquidityRate);
30
+ * console.log('Variable borrow rate:', asset.variableBorrowRate);
31
+ * }
32
+ * ```
33
+ *
34
+ * @remarks
35
+ * - The query is disabled when reserveAddress is undefined or empty
36
+ * - Uses React Query for efficient caching and state management
37
+ * - Automatically handles error states and loading indicators
38
+ * - Returns comprehensive asset information for the specified reserve
39
+ */
40
+ export const useBackendMoneyMarketAsset = (
41
+ reserveAddress: string | undefined,
42
+ ): UseQueryResult<MoneyMarketAsset | undefined> => {
43
+ const { sodax } = useSodaxContext();
44
+
45
+ return useQuery({
46
+ queryKey: ['backend', 'moneymarket', 'asset', reserveAddress],
47
+ queryFn: async (): Promise<MoneyMarketAsset | undefined> => {
48
+ if (!reserveAddress) {
49
+ return undefined;
50
+ }
51
+
52
+ return sodax.backendApiService.getMoneyMarketAsset(reserveAddress);
53
+ },
54
+ enabled: !!reserveAddress && reserveAddress.length > 0,
55
+ retry: 3,
56
+ });
57
+ };
@@ -0,0 +1,67 @@
1
+ // packages/dapp-kit/src/hooks/backend/useMoneyMarketAssetBorrowers.ts
2
+ import { useQuery, type UseQueryResult } from '@tanstack/react-query';
3
+ import type { MoneyMarketAssetBorrowers } from '@sodax/sdk';
4
+ import { useSodaxContext } from '../shared/useSodaxContext';
5
+
6
+ /**
7
+ * Hook for fetching borrowers for a specific money market asset from the backend API.
8
+ *
9
+ * This hook provides access to the list of borrowers for a specific money market asset,
10
+ * with pagination support. The data is automatically fetched and cached using React Query.
11
+ *
12
+ * @param {Object} params - Parameters for fetching asset borrowers
13
+ * @param {string | undefined} params.reserveAddress - The reserve contract address. If undefined, the query will be disabled.
14
+ * @param {string} params.offset - The offset for pagination (number as string)
15
+ * @param {string} params.limit - The limit for pagination (number as string)
16
+ *
17
+ * @returns {UseQueryResult<MoneyMarketAssetBorrowers | undefined>} A query result object containing:
18
+ * - data: The asset borrowers data when available
19
+ * - isLoading: Boolean indicating if the request is in progress
20
+ * - error: Error object if the request failed
21
+ * - refetch: Function to manually trigger a data refresh
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * const { data: borrowers, isLoading, error } = useMoneyMarketAssetBorrowers({
26
+ * reserveAddress: '0xabc...',
27
+ * offset: '0',
28
+ * limit: '20'
29
+ * });
30
+ *
31
+ * if (isLoading) return <div>Loading borrowers...</div>;
32
+ * if (error) return <div>Error: {error.message}</div>;
33
+ * if (borrowers) {
34
+ * console.log('Total borrowers:', borrowers.total);
35
+ * console.log('Borrowers:', borrowers.borrowers);
36
+ * }
37
+ * ```
38
+ *
39
+ * @remarks
40
+ * - The query is disabled when reserveAddress is undefined or empty
41
+ * - Uses React Query for efficient caching and state management
42
+ * - Automatically handles error states and loading indicators
43
+ * - Supports pagination through offset and limit parameters
44
+ */
45
+ export const useBackendMoneyMarketAssetBorrowers = (params: {
46
+ reserveAddress: string | undefined;
47
+ offset: string;
48
+ limit: string;
49
+ }): UseQueryResult<MoneyMarketAssetBorrowers | undefined> => {
50
+ const { sodax } = useSodaxContext();
51
+
52
+ return useQuery({
53
+ queryKey: ['backend', 'moneymarket', 'asset', 'borrowers', params],
54
+ queryFn: async (): Promise<MoneyMarketAssetBorrowers | undefined> => {
55
+ if (!params.reserveAddress || !params.offset || !params.limit) {
56
+ return undefined;
57
+ }
58
+
59
+ return sodax.backendApiService.getMoneyMarketAssetBorrowers(params.reserveAddress, {
60
+ offset: params.offset,
61
+ limit: params.limit,
62
+ });
63
+ },
64
+ enabled: !!params.reserveAddress && !!params.offset && !!params.limit,
65
+ retry: 3,
66
+ });
67
+ };
@@ -0,0 +1,67 @@
1
+ // packages/dapp-kit/src/hooks/backend/useMoneyMarketAssetSuppliers.ts
2
+ import { useQuery, type UseQueryResult } from '@tanstack/react-query';
3
+ import type { MoneyMarketAssetSuppliers } from '@sodax/sdk';
4
+ import { useSodaxContext } from '../shared/useSodaxContext';
5
+
6
+ /**
7
+ * Hook for fetching suppliers for a specific money market asset from the backend API.
8
+ *
9
+ * This hook provides access to the list of suppliers for a specific money market asset,
10
+ * with pagination support. The data is automatically fetched and cached using React Query.
11
+ *
12
+ * @param {Object} params - Parameters for fetching asset suppliers
13
+ * @param {string | undefined} params.reserveAddress - The reserve contract address. If undefined, the query will be disabled.
14
+ * @param {string} params.offset - The offset for pagination (number as string)
15
+ * @param {string} params.limit - The limit for pagination (number as string)
16
+ *
17
+ * @returns {UseQueryResult<MoneyMarketAssetSuppliers | undefined>} A query result object containing:
18
+ * - data: The asset suppliers data when available
19
+ * - isLoading: Boolean indicating if the request is in progress
20
+ * - error: Error object if the request failed
21
+ * - refetch: Function to manually trigger a data refresh
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * const { data: suppliers, isLoading, error } = useMoneyMarketAssetSuppliers({
26
+ * reserveAddress: '0xabc...',
27
+ * offset: '0',
28
+ * limit: '20'
29
+ * });
30
+ *
31
+ * if (isLoading) return <div>Loading suppliers...</div>;
32
+ * if (error) return <div>Error: {error.message}</div>;
33
+ * if (suppliers) {
34
+ * console.log('Total suppliers:', suppliers.total);
35
+ * console.log('Suppliers:', suppliers.suppliers);
36
+ * }
37
+ * ```
38
+ *
39
+ * @remarks
40
+ * - The query is disabled when reserveAddress is undefined or empty
41
+ * - Uses React Query for efficient caching and state management
42
+ * - Automatically handles error states and loading indicators
43
+ * - Supports pagination through offset and limit parameters
44
+ */
45
+ export const useBackendMoneyMarketAssetSuppliers = (params: {
46
+ reserveAddress: string | undefined;
47
+ offset: string;
48
+ limit: string;
49
+ }): UseQueryResult<MoneyMarketAssetSuppliers | undefined> => {
50
+ const { sodax } = useSodaxContext();
51
+
52
+ return useQuery({
53
+ queryKey: ['backend', 'moneymarket', 'asset', 'suppliers', params],
54
+ queryFn: async (): Promise<MoneyMarketAssetSuppliers | undefined> => {
55
+ if (!params.reserveAddress || !params.offset || !params.limit) {
56
+ return undefined;
57
+ }
58
+
59
+ return sodax.backendApiService.getMoneyMarketAssetSuppliers(params.reserveAddress, {
60
+ offset: params.offset,
61
+ limit: params.limit,
62
+ });
63
+ },
64
+ enabled: !!params.reserveAddress && !!params.offset && !!params.limit,
65
+ retry: 3,
66
+ });
67
+ };
@@ -0,0 +1,56 @@
1
+ // packages/dapp-kit/src/hooks/backend/useMoneyMarketPosition.ts
2
+ import { useQuery, type UseQueryResult } from '@tanstack/react-query';
3
+ import type { MoneyMarketPosition } from '@sodax/sdk';
4
+ import { useSodaxContext } from '../shared/useSodaxContext';
5
+
6
+ /**
7
+ * Hook for fetching money market position for a specific user from the backend API.
8
+ *
9
+ * This hook provides access to a user's money market positions, including their
10
+ * aToken balances, variable debt token balances, and associated reserve information.
11
+ * The data is automatically fetched and cached using React Query.
12
+ *
13
+ * @param {string | undefined} userAddress - The user's wallet address. If undefined, the query will be disabled.
14
+ *
15
+ * @returns {UseQueryResult<MoneyMarketPosition | undefined>} A query result object containing:
16
+ * - data: The money market position data when available
17
+ * - isLoading: Boolean indicating if the request is in progress
18
+ * - error: Error object if the request failed
19
+ * - refetch: Function to manually trigger a data refresh
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * const { data: position, isLoading, error } = useMoneyMarketPosition('0x123...');
24
+ *
25
+ * if (isLoading) return <div>Loading position...</div>;
26
+ * if (error) return <div>Error: {error.message}</div>;
27
+ * if (position) {
28
+ * console.log('User address:', position.userAddress);
29
+ * console.log('Positions:', position.positions);
30
+ * }
31
+ * ```
32
+ *
33
+ * @remarks
34
+ * - The query is disabled when userAddress is undefined or empty
35
+ * - Uses React Query for efficient caching and state management
36
+ * - Automatically handles error states and loading indicators
37
+ * - Includes user's aToken and debt token balances across all reserves
38
+ */
39
+ export const useBackendMoneyMarketPosition = (
40
+ userAddress: string | undefined,
41
+ ): UseQueryResult<MoneyMarketPosition | undefined> => {
42
+ const { sodax } = useSodaxContext();
43
+
44
+ return useQuery({
45
+ queryKey: ['backend', 'moneymarket', 'position', userAddress],
46
+ queryFn: async (): Promise<MoneyMarketPosition | undefined> => {
47
+ if (!userAddress) {
48
+ return undefined;
49
+ }
50
+
51
+ return sodax.backendApiService.getMoneyMarketPosition(userAddress);
52
+ },
53
+ enabled: !!userAddress && userAddress.length > 0,
54
+ retry: 3,
55
+ });
56
+ };
@@ -0,0 +1,63 @@
1
+ // packages/dapp-kit/src/hooks/backend/useOrderbook.ts
2
+ import { useQuery, type UseQueryResult } from '@tanstack/react-query';
3
+ import type { OrderbookResponse } from '@sodax/sdk';
4
+ import { useSodaxContext } from '../shared/useSodaxContext';
5
+
6
+ /**
7
+ * Hook for fetching the solver orderbook from the backend API.
8
+ *
9
+ * This hook provides access to the solver orderbook data, including intent states
10
+ * and intent data for all available intents. The data is automatically fetched
11
+ * and cached using React Query with pagination support.
12
+ *
13
+ * @param {Object} params - Pagination parameters for the orderbook
14
+ * @param {string} params.offset - The offset for pagination (number as string)
15
+ * @param {string} params.limit - The limit for pagination (number as string)
16
+ *
17
+ * @returns {UseQueryResult<OrderbookResponse | undefined>} A query result object containing:
18
+ * - data: The orderbook response data when available
19
+ * - isLoading: Boolean indicating if the request is in progress
20
+ * - error: Error object if the request failed
21
+ * - refetch: Function to manually trigger a data refresh
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * const { data: orderbook, isLoading, error } = useOrderbook({
26
+ * offset: '0',
27
+ * limit: '10'
28
+ * });
29
+ *
30
+ * if (isLoading) return <div>Loading orderbook...</div>;
31
+ * if (error) return <div>Error: {error.message}</div>;
32
+ * if (orderbook) {
33
+ * console.log('Total intents:', orderbook.total);
34
+ * console.log('Intents:', orderbook.data);
35
+ * }
36
+ * ```
37
+ *
38
+ * @remarks
39
+ * - The query is disabled when params are undefined or invalid
40
+ * - Uses React Query for efficient caching and state management
41
+ * - Automatically handles error states and loading indicators
42
+ * - Stale time of 30 seconds for real-time orderbook data
43
+ * - Supports pagination through offset and limit parameters
44
+ */
45
+ export const useBackendOrderbook = (
46
+ params: { offset: string; limit: string } | undefined,
47
+ ): UseQueryResult<OrderbookResponse | undefined> => {
48
+ const { sodax } = useSodaxContext();
49
+
50
+ return useQuery({
51
+ queryKey: ['backend', 'solver', 'orderbook', params],
52
+ queryFn: async (): Promise<OrderbookResponse | undefined> => {
53
+ if (!params || !params.offset || !params.limit) {
54
+ return undefined;
55
+ }
56
+
57
+ return sodax.backendApiService.getOrderbook(params);
58
+ },
59
+ enabled: !!params && !!params.offset && !!params.limit,
60
+ staleTime: 30 * 1000, // 30 seconds for real-time data
61
+ retry: 3,
62
+ });
63
+ };
@@ -1,5 +1,5 @@
1
1
  import { useQuery, type UseQueryResult } from '@tanstack/react-query';
2
- import { type XToken, type SpokeChainId } from '@sodax/sdk';
2
+ import type { XToken, SpokeChainId } from '@sodax/sdk';
3
3
  import { useSodaxContext } from '../shared';
4
4
 
5
5
  /**
@@ -2,4 +2,5 @@ export * from './shared';
2
2
  export * from './provider';
3
3
  export * from './mm';
4
4
  export * from './swap';
5
+ export * from './backend';
5
6
  export * from './bridge';