@sodax/dapp-kit 1.0.0-rc.3 → 1.0.0-rc.4

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.3",
4
+ "version": "1.0.0-rc.4",
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.3",
20
- "@sodax/types": "1.0.0-rc.3"
19
+ "@sodax/sdk": "1.0.0-rc.4",
20
+ "@sodax/types": "1.0.0-rc.4"
21
21
  },
22
22
  "devDependencies": {
23
23
  "@types/react": "18.3.1",
@@ -6,3 +6,4 @@ export * from './useUserReservesData';
6
6
  export * from './useReservesData';
7
7
  export * from './useMMAllowance';
8
8
  export * from './useMMApprove';
9
+ export * from './useAToken';
@@ -0,0 +1,47 @@
1
+ import type { Address, XToken } from '@sodax/sdk';
2
+ import { useQuery, type UseQueryResult } from '@tanstack/react-query';
3
+ import { useSodaxContext } from '../shared/useSodaxContext';
4
+
5
+ /**
6
+ * React hook for fetching an AToken's ERC20 metadata from the Sodax money market.
7
+ *
8
+ * Fetches and caches the metadata (name, symbol, decimals, address) for a given aToken address and chain using React Query.
9
+ * This metadata is typically required for rendering balances and labels in UI components.
10
+ *
11
+ * @param {Address | undefined} aToken - The aToken contract address to look up. Should be an EVM address.
12
+ * @param {ChainId | undefined} chainId - The EVM chain ID for the aToken.
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * const { data: aToken, isLoading, error } = useAToken(aTokenAddress, chainId);
17
+ * if (aToken) {
18
+ * console.log(aToken.symbol); // 'aETH'
19
+ * }
20
+ * ```
21
+ *
22
+ * @returns {UseQueryResult<Erc20Token, Error>} A React Query result object containing:
23
+ * - data: The aToken ERC20 metadata when available.
24
+ * - isLoading: Loading state indicator.
25
+ * - error: Any error that occurred during data fetching.
26
+ */
27
+ export function useAToken(
28
+ aToken: Address | undefined,
29
+ ): UseQueryResult<XToken, Error> {
30
+ const { sodax } = useSodaxContext();
31
+
32
+ return useQuery({
33
+ queryKey: ['aToken', sodax.hubProvider.chainConfig.chain.id, aToken],
34
+ queryFn: async () => {
35
+ if (!aToken) {
36
+ throw new Error('aToken address or hub provider is not defined');
37
+ }
38
+
39
+ const aTokenData = await sodax.moneyMarket.data.getATokenData(aToken);
40
+ return {
41
+ ...aTokenData,
42
+ xChainId: sodax.hubProvider.chainConfig.chain.id,
43
+ };
44
+ },
45
+ enabled: !!aToken,
46
+ });
47
+ }