@hyperix/hooks 0.1.16 → 0.1.17
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/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/use-active-asset-data.d.ts +8 -0
- package/dist/use-active-asset-data.js +26 -0
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type UseSubscribeState } from "@outofgas/react-stream";
|
|
2
|
+
import type { ActiveAssetDataEvent } from "@nktkas/hyperliquid/api/subscription";
|
|
3
|
+
export type ActiveAssetData = ActiveAssetDataEvent;
|
|
4
|
+
export type UseActiveAssetDataOptions = {
|
|
5
|
+
enabled?: boolean;
|
|
6
|
+
onUpdate?: (event: ActiveAssetDataEvent) => void;
|
|
7
|
+
};
|
|
8
|
+
export declare function useActiveAssetData(coin: string, user: `0x${string}`, options?: UseActiveAssetDataOptions): UseSubscribeState<ActiveAssetData>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { useSubscribe } from "@outofgas/react-stream";
|
|
2
|
+
import { wsClient } from "./config/hl.js";
|
|
3
|
+
export function useActiveAssetData(coin, user, options = {}) {
|
|
4
|
+
const { enabled: enabledOverride, onUpdate } = options;
|
|
5
|
+
const enabled = enabledOverride ?? Boolean(coin && user);
|
|
6
|
+
return useSubscribe({
|
|
7
|
+
key: ["active-asset-data", coin, user],
|
|
8
|
+
enabled,
|
|
9
|
+
subscribe: async ({ onData, onError }) => {
|
|
10
|
+
const subscription = await wsClient.activeAssetData({ coin, user }, (event) => {
|
|
11
|
+
try {
|
|
12
|
+
onUpdate?.(event);
|
|
13
|
+
onData(event);
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
onError(error instanceof Error
|
|
17
|
+
? error
|
|
18
|
+
: new Error("Failed to process active asset data event"));
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
return {
|
|
22
|
+
unsubscribe: () => subscription.unsubscribe(),
|
|
23
|
+
};
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hyperix/hooks",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.17",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@nktkas/hyperliquid": "^0.32.1",
|
|
18
|
-
"@outofgas/react-stream": "0.1.
|
|
18
|
+
"@outofgas/react-stream": "^0.1.4",
|
|
19
19
|
"react": "^19.1.1"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|