@hyperix/hooks 0.1.19 → 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 +34 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/use-perp-meta.d.ts +211 -2
- package/dist/use-perp-meta.js +3 -3
- package/dist/use-portfolio.d.ts +5 -0
- package/dist/use-portfolio.js +11 -0
- package/package.json +1 -1
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";
|
package/dist/use-perp-meta.d.ts
CHANGED
|
@@ -2,8 +2,7 @@ import type { AllPerpMetasData } from "./use-all-perp-metas.js";
|
|
|
2
2
|
import { type UseAllPerpMetasOptions } from "./use-all-perp-metas.js";
|
|
3
3
|
export type PerpMeta = AllPerpMetasData[number]["universe"][number];
|
|
4
4
|
export declare function usePerpMeta(coin: string, options?: UseAllPerpMetasOptions): {
|
|
5
|
-
|
|
6
|
-
meta: {
|
|
5
|
+
data: {
|
|
7
6
|
szDecimals: number;
|
|
8
7
|
name: string;
|
|
9
8
|
maxLeverage: number;
|
|
@@ -14,4 +13,214 @@ export declare function usePerpMeta(coin: string, options?: UseAllPerpMetasOptio
|
|
|
14
13
|
growthMode?: "enabled";
|
|
15
14
|
lastGrowthModeChangeTime?: string;
|
|
16
15
|
} | undefined;
|
|
16
|
+
error: Error;
|
|
17
|
+
isError: true;
|
|
18
|
+
isPending: false;
|
|
19
|
+
isLoading: false;
|
|
20
|
+
isLoadingError: false;
|
|
21
|
+
isRefetchError: true;
|
|
22
|
+
isSuccess: false;
|
|
23
|
+
isPlaceholderData: false;
|
|
24
|
+
status: "error";
|
|
25
|
+
dataUpdatedAt: number;
|
|
26
|
+
errorUpdatedAt: number;
|
|
27
|
+
failureCount: number;
|
|
28
|
+
failureReason: Error | null;
|
|
29
|
+
errorUpdateCount: number;
|
|
30
|
+
isFetched: boolean;
|
|
31
|
+
isFetchedAfterMount: boolean;
|
|
32
|
+
isFetching: boolean;
|
|
33
|
+
isInitialLoading: boolean;
|
|
34
|
+
isPaused: boolean;
|
|
35
|
+
isRefetching: boolean;
|
|
36
|
+
isStale: boolean;
|
|
37
|
+
isEnabled: boolean;
|
|
38
|
+
refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<import("@nktkas/hyperliquid").AllPerpMetasResponse, Error>>;
|
|
39
|
+
fetchStatus: import("@tanstack/query-core").FetchStatus;
|
|
40
|
+
promise: Promise<import("@nktkas/hyperliquid").AllPerpMetasResponse>;
|
|
41
|
+
} | {
|
|
42
|
+
data: {
|
|
43
|
+
szDecimals: number;
|
|
44
|
+
name: string;
|
|
45
|
+
maxLeverage: number;
|
|
46
|
+
marginTableId: number;
|
|
47
|
+
onlyIsolated?: true;
|
|
48
|
+
isDelisted?: true;
|
|
49
|
+
marginMode?: "strictIsolated" | "noCross";
|
|
50
|
+
growthMode?: "enabled";
|
|
51
|
+
lastGrowthModeChangeTime?: string;
|
|
52
|
+
} | undefined;
|
|
53
|
+
error: null;
|
|
54
|
+
isError: false;
|
|
55
|
+
isPending: false;
|
|
56
|
+
isLoading: false;
|
|
57
|
+
isLoadingError: false;
|
|
58
|
+
isRefetchError: false;
|
|
59
|
+
isSuccess: true;
|
|
60
|
+
isPlaceholderData: false;
|
|
61
|
+
status: "success";
|
|
62
|
+
dataUpdatedAt: number;
|
|
63
|
+
errorUpdatedAt: number;
|
|
64
|
+
failureCount: number;
|
|
65
|
+
failureReason: Error | null;
|
|
66
|
+
errorUpdateCount: number;
|
|
67
|
+
isFetched: boolean;
|
|
68
|
+
isFetchedAfterMount: boolean;
|
|
69
|
+
isFetching: boolean;
|
|
70
|
+
isInitialLoading: boolean;
|
|
71
|
+
isPaused: boolean;
|
|
72
|
+
isRefetching: boolean;
|
|
73
|
+
isStale: boolean;
|
|
74
|
+
isEnabled: boolean;
|
|
75
|
+
refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<import("@nktkas/hyperliquid").AllPerpMetasResponse, Error>>;
|
|
76
|
+
fetchStatus: import("@tanstack/query-core").FetchStatus;
|
|
77
|
+
promise: Promise<import("@nktkas/hyperliquid").AllPerpMetasResponse>;
|
|
78
|
+
} | {
|
|
79
|
+
data: {
|
|
80
|
+
szDecimals: number;
|
|
81
|
+
name: string;
|
|
82
|
+
maxLeverage: number;
|
|
83
|
+
marginTableId: number;
|
|
84
|
+
onlyIsolated?: true;
|
|
85
|
+
isDelisted?: true;
|
|
86
|
+
marginMode?: "strictIsolated" | "noCross";
|
|
87
|
+
growthMode?: "enabled";
|
|
88
|
+
lastGrowthModeChangeTime?: string;
|
|
89
|
+
} | undefined;
|
|
90
|
+
error: Error;
|
|
91
|
+
isError: true;
|
|
92
|
+
isPending: false;
|
|
93
|
+
isLoading: false;
|
|
94
|
+
isLoadingError: true;
|
|
95
|
+
isRefetchError: false;
|
|
96
|
+
isSuccess: false;
|
|
97
|
+
isPlaceholderData: false;
|
|
98
|
+
status: "error";
|
|
99
|
+
dataUpdatedAt: number;
|
|
100
|
+
errorUpdatedAt: number;
|
|
101
|
+
failureCount: number;
|
|
102
|
+
failureReason: Error | null;
|
|
103
|
+
errorUpdateCount: number;
|
|
104
|
+
isFetched: boolean;
|
|
105
|
+
isFetchedAfterMount: boolean;
|
|
106
|
+
isFetching: boolean;
|
|
107
|
+
isInitialLoading: boolean;
|
|
108
|
+
isPaused: boolean;
|
|
109
|
+
isRefetching: boolean;
|
|
110
|
+
isStale: boolean;
|
|
111
|
+
isEnabled: boolean;
|
|
112
|
+
refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<import("@nktkas/hyperliquid").AllPerpMetasResponse, Error>>;
|
|
113
|
+
fetchStatus: import("@tanstack/query-core").FetchStatus;
|
|
114
|
+
promise: Promise<import("@nktkas/hyperliquid").AllPerpMetasResponse>;
|
|
115
|
+
} | {
|
|
116
|
+
data: {
|
|
117
|
+
szDecimals: number;
|
|
118
|
+
name: string;
|
|
119
|
+
maxLeverage: number;
|
|
120
|
+
marginTableId: number;
|
|
121
|
+
onlyIsolated?: true;
|
|
122
|
+
isDelisted?: true;
|
|
123
|
+
marginMode?: "strictIsolated" | "noCross";
|
|
124
|
+
growthMode?: "enabled";
|
|
125
|
+
lastGrowthModeChangeTime?: string;
|
|
126
|
+
} | undefined;
|
|
127
|
+
error: null;
|
|
128
|
+
isError: false;
|
|
129
|
+
isPending: true;
|
|
130
|
+
isLoading: true;
|
|
131
|
+
isLoadingError: false;
|
|
132
|
+
isRefetchError: false;
|
|
133
|
+
isSuccess: false;
|
|
134
|
+
isPlaceholderData: false;
|
|
135
|
+
status: "pending";
|
|
136
|
+
dataUpdatedAt: number;
|
|
137
|
+
errorUpdatedAt: number;
|
|
138
|
+
failureCount: number;
|
|
139
|
+
failureReason: Error | null;
|
|
140
|
+
errorUpdateCount: number;
|
|
141
|
+
isFetched: boolean;
|
|
142
|
+
isFetchedAfterMount: boolean;
|
|
143
|
+
isFetching: boolean;
|
|
144
|
+
isInitialLoading: boolean;
|
|
145
|
+
isPaused: boolean;
|
|
146
|
+
isRefetching: boolean;
|
|
147
|
+
isStale: boolean;
|
|
148
|
+
isEnabled: boolean;
|
|
149
|
+
refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<import("@nktkas/hyperliquid").AllPerpMetasResponse, Error>>;
|
|
150
|
+
fetchStatus: import("@tanstack/query-core").FetchStatus;
|
|
151
|
+
promise: Promise<import("@nktkas/hyperliquid").AllPerpMetasResponse>;
|
|
152
|
+
} | {
|
|
153
|
+
data: {
|
|
154
|
+
szDecimals: number;
|
|
155
|
+
name: string;
|
|
156
|
+
maxLeverage: number;
|
|
157
|
+
marginTableId: number;
|
|
158
|
+
onlyIsolated?: true;
|
|
159
|
+
isDelisted?: true;
|
|
160
|
+
marginMode?: "strictIsolated" | "noCross";
|
|
161
|
+
growthMode?: "enabled";
|
|
162
|
+
lastGrowthModeChangeTime?: string;
|
|
163
|
+
} | undefined;
|
|
164
|
+
error: null;
|
|
165
|
+
isError: false;
|
|
166
|
+
isPending: true;
|
|
167
|
+
isLoadingError: false;
|
|
168
|
+
isRefetchError: false;
|
|
169
|
+
isSuccess: false;
|
|
170
|
+
isPlaceholderData: false;
|
|
171
|
+
status: "pending";
|
|
172
|
+
dataUpdatedAt: number;
|
|
173
|
+
errorUpdatedAt: number;
|
|
174
|
+
failureCount: number;
|
|
175
|
+
failureReason: Error | null;
|
|
176
|
+
errorUpdateCount: number;
|
|
177
|
+
isFetched: boolean;
|
|
178
|
+
isFetchedAfterMount: boolean;
|
|
179
|
+
isFetching: boolean;
|
|
180
|
+
isLoading: boolean;
|
|
181
|
+
isInitialLoading: boolean;
|
|
182
|
+
isPaused: boolean;
|
|
183
|
+
isRefetching: boolean;
|
|
184
|
+
isStale: boolean;
|
|
185
|
+
isEnabled: boolean;
|
|
186
|
+
refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<import("@nktkas/hyperliquid").AllPerpMetasResponse, Error>>;
|
|
187
|
+
fetchStatus: import("@tanstack/query-core").FetchStatus;
|
|
188
|
+
promise: Promise<import("@nktkas/hyperliquid").AllPerpMetasResponse>;
|
|
189
|
+
} | {
|
|
190
|
+
data: {
|
|
191
|
+
szDecimals: number;
|
|
192
|
+
name: string;
|
|
193
|
+
maxLeverage: number;
|
|
194
|
+
marginTableId: number;
|
|
195
|
+
onlyIsolated?: true;
|
|
196
|
+
isDelisted?: true;
|
|
197
|
+
marginMode?: "strictIsolated" | "noCross";
|
|
198
|
+
growthMode?: "enabled";
|
|
199
|
+
lastGrowthModeChangeTime?: string;
|
|
200
|
+
} | undefined;
|
|
201
|
+
isError: false;
|
|
202
|
+
error: null;
|
|
203
|
+
isPending: false;
|
|
204
|
+
isLoading: false;
|
|
205
|
+
isLoadingError: false;
|
|
206
|
+
isRefetchError: false;
|
|
207
|
+
isSuccess: true;
|
|
208
|
+
isPlaceholderData: true;
|
|
209
|
+
status: "success";
|
|
210
|
+
dataUpdatedAt: number;
|
|
211
|
+
errorUpdatedAt: number;
|
|
212
|
+
failureCount: number;
|
|
213
|
+
failureReason: Error | null;
|
|
214
|
+
errorUpdateCount: number;
|
|
215
|
+
isFetched: boolean;
|
|
216
|
+
isFetchedAfterMount: boolean;
|
|
217
|
+
isFetching: boolean;
|
|
218
|
+
isInitialLoading: boolean;
|
|
219
|
+
isPaused: boolean;
|
|
220
|
+
isRefetching: boolean;
|
|
221
|
+
isStale: boolean;
|
|
222
|
+
isEnabled: boolean;
|
|
223
|
+
refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<import("@nktkas/hyperliquid").AllPerpMetasResponse, Error>>;
|
|
224
|
+
fetchStatus: import("@tanstack/query-core").FetchStatus;
|
|
225
|
+
promise: Promise<import("@nktkas/hyperliquid").AllPerpMetasResponse>;
|
|
17
226
|
};
|
package/dist/use-perp-meta.js
CHANGED
|
@@ -2,12 +2,12 @@ import { useMemo } from "react";
|
|
|
2
2
|
import { useAllPerpMetas, } from "./use-all-perp-metas.js";
|
|
3
3
|
export function usePerpMeta(coin, options = {}) {
|
|
4
4
|
const allPerpMetasState = useAllPerpMetas(options);
|
|
5
|
-
const
|
|
5
|
+
const data = useMemo(() => {
|
|
6
6
|
const universes = allPerpMetasState.data?.flatMap((perpMeta) => perpMeta.universe) ?? [];
|
|
7
7
|
return universes.find((universe) => universe.name === coin);
|
|
8
8
|
}, [coin, allPerpMetasState.data]);
|
|
9
9
|
return {
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
...allPerpMetasState,
|
|
11
|
+
data,
|
|
12
12
|
};
|
|
13
13
|
}
|
|
@@ -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
|
+
}
|