@hyperix/hooks 0.1.20 → 0.1.21

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 CHANGED
@@ -6,6 +6,40 @@ React hooks for the local workspace.
6
6
 
7
7
  This package is intended for source-first usage inside the monorepo. Consumers should reference it with `"workspace:*"` and let the app bundler resolve the TypeScript source.
8
8
 
9
+ ## Demo
10
+
11
+ ```tsx
12
+ import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
13
+ import { usePortfolio } from "@hyperix/hooks";
14
+
15
+ const queryClient = new QueryClient();
16
+
17
+ function PortfolioDemo() {
18
+ const { data, isPending, error } = usePortfolio("0x1234567890abcdef1234567890abcdef12345678");
19
+
20
+ if (isPending) {
21
+ return <div>Loading portfolio...</div>;
22
+ }
23
+
24
+ if (error) {
25
+ return <div>Failed to load portfolio: {error.message}</div>;
26
+ }
27
+
28
+ const perpDay = data?.find(([period]) => period === "perpDay")?.[1];
29
+ const latestPnl = Number(perpDay?.pnlHistory.at(-1)?.[1] ?? 0);
30
+
31
+ return <pre>{JSON.stringify({ latestPnl, periods: data?.map(([period]) => period) }, null, 2)}</pre>;
32
+ }
33
+
34
+ export function App() {
35
+ return (
36
+ <QueryClientProvider client={queryClient}>
37
+ <PortfolioDemo />
38
+ </QueryClientProvider>
39
+ );
40
+ }
41
+ ```
42
+
9
43
  ## Tests
10
44
 
11
45
  ```bash
package/dist/index.d.ts CHANGED
@@ -13,6 +13,7 @@ export * from "./use-order-history.js";
13
13
  export * from "./use-perp-market.js";
14
14
  export * from "./use-perp-markets.js";
15
15
  export * from "./use-perp-meta.js";
16
+ export * from "./use-portfolio.js";
16
17
  export * from "./use-positions.js";
17
18
  export * from "./use-spot-meta.js";
18
19
  export * from "./use-symbol-converter.js";
package/dist/index.js CHANGED
@@ -13,6 +13,7 @@ export * from "./use-order-history.js";
13
13
  export * from "./use-perp-market.js";
14
14
  export * from "./use-perp-markets.js";
15
15
  export * from "./use-perp-meta.js";
16
+ export * from "./use-portfolio.js";
16
17
  export * from "./use-positions.js";
17
18
  export * from "./use-spot-meta.js";
18
19
  export * from "./use-symbol-converter.js";
@@ -0,0 +1,5 @@
1
+ import { type UseQueryOptions, type UseQueryResult } from "@tanstack/react-query";
2
+ import type { PortfolioResponse } from "@nktkas/hyperliquid/api/info";
3
+ export type PortfolioData = PortfolioResponse;
4
+ export type UsePortfolioOptions = Omit<UseQueryOptions<PortfolioData, Error, PortfolioData, ["portfolio", `0x${string}`]>, "queryKey" | "queryFn">;
5
+ export declare function usePortfolio(user: `0x${string}`, options?: UsePortfolioOptions): UseQueryResult<PortfolioData, Error>;
@@ -0,0 +1,11 @@
1
+ import { useQuery } from "@tanstack/react-query";
2
+ import { infoClient } from "./config/hl.js";
3
+ export function usePortfolio(user, options = {}) {
4
+ const enabled = options.enabled ?? Boolean(user);
5
+ return useQuery({
6
+ queryKey: ["portfolio", user],
7
+ queryFn: () => infoClient.portfolio({ user }),
8
+ ...options,
9
+ enabled,
10
+ });
11
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperix/hooks",
3
- "version": "0.1.20",
3
+ "version": "0.1.21",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",