@0xmonaco/react 0.8.21 → 0.8.22
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/coverage.d.ts +1 -0
- package/dist/coverage.js +1 -0
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.js +1 -0
- package/dist/hooks/usePositionPnlHistory/index.d.ts +2 -0
- package/dist/hooks/usePositionPnlHistory/index.js +1 -0
- package/dist/hooks/usePositionPnlHistory/types.d.ts +15 -0
- package/dist/hooks/usePositionPnlHistory/types.js +0 -0
- package/dist/hooks/usePositionPnlHistory/usePositionPnlHistory.d.ts +12 -0
- package/dist/hooks/usePositionPnlHistory/usePositionPnlHistory.js +59 -0
- package/package.json +3 -3
package/dist/coverage.d.ts
CHANGED
package/dist/coverage.js
CHANGED
|
@@ -27,6 +27,7 @@ export const COVERED = {
|
|
|
27
27
|
get_perp_market_config: "useMarket",
|
|
28
28
|
get_perp_market_summary: "useMarket",
|
|
29
29
|
get_position: "usePositions",
|
|
30
|
+
get_position_pnl_history: "usePositionPnlHistory",
|
|
30
31
|
get_position_risk: "usePositions",
|
|
31
32
|
get_trades: "useTradeFeed",
|
|
32
33
|
get_user_balance_by_asset: "useProfile",
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export * from "./useMarket";
|
|
|
4
4
|
export * from "./useMonaco";
|
|
5
5
|
export * from "./useOHLCV";
|
|
6
6
|
export * from "./useOrderbook";
|
|
7
|
+
export * from "./usePositionPnlHistory";
|
|
7
8
|
export * from "./usePositions";
|
|
8
9
|
export * from "./useProfile";
|
|
9
10
|
export * from "./useTokenLifecycle";
|
package/dist/hooks/index.js
CHANGED
|
@@ -4,6 +4,7 @@ export * from "./useMarket";
|
|
|
4
4
|
export * from "./useMonaco";
|
|
5
5
|
export * from "./useOHLCV";
|
|
6
6
|
export * from "./useOrderbook";
|
|
7
|
+
export * from "./usePositionPnlHistory";
|
|
7
8
|
export * from "./usePositions";
|
|
8
9
|
export * from "./useProfile";
|
|
9
10
|
export * from "./useTokenLifecycle";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { usePositionPnlHistory } from "./usePositionPnlHistory";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { GetPositionPnlHistoryParams, PositionPnlPoint } from "@0xmonaco/types";
|
|
2
|
+
export interface UsePositionPnlHistoryParams extends GetPositionPnlHistoryParams {
|
|
3
|
+
/** Position UUID to chart; pass null/undefined to defer fetching */
|
|
4
|
+
positionId: string | null | undefined;
|
|
5
|
+
}
|
|
6
|
+
export interface UsePositionPnlHistoryReturn {
|
|
7
|
+
/** Forward-filled PnL state samples, oldest first */
|
|
8
|
+
data: PositionPnlPoint[];
|
|
9
|
+
/** True while a fetch is in flight */
|
|
10
|
+
loading: boolean;
|
|
11
|
+
/** Last fetch error, if any */
|
|
12
|
+
error: Error | null;
|
|
13
|
+
/** Re-run the fetch with the current parameters */
|
|
14
|
+
refetch: () => Promise<void>;
|
|
15
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { UsePositionPnlHistoryParams, UsePositionPnlHistoryReturn } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Hook for fetching a position's bucketed PnL history.
|
|
4
|
+
*
|
|
5
|
+
* Fetches the forward-filled PnL state samples for one owned position at the
|
|
6
|
+
* requested interval and refetches whenever the position or window changes.
|
|
7
|
+
* `cumFundingPaid`/`cumFees` are cost-positive on the wire — negate at render
|
|
8
|
+
* time to display funding as a signed PnL contribution.
|
|
9
|
+
*
|
|
10
|
+
* @param params - positionId plus the interval and optional start/end times
|
|
11
|
+
*/
|
|
12
|
+
export declare function usePositionPnlHistory(params: UsePositionPnlHistoryParams): UsePositionPnlHistoryReturn;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
2
|
+
import { useMonacoSDK } from "../useMonaco";
|
|
3
|
+
/**
|
|
4
|
+
* Hook for fetching a position's bucketed PnL history.
|
|
5
|
+
*
|
|
6
|
+
* Fetches the forward-filled PnL state samples for one owned position at the
|
|
7
|
+
* requested interval and refetches whenever the position or window changes.
|
|
8
|
+
* `cumFundingPaid`/`cumFees` are cost-positive on the wire — negate at render
|
|
9
|
+
* time to display funding as a signed PnL contribution.
|
|
10
|
+
*
|
|
11
|
+
* @param params - positionId plus the interval and optional start/end times
|
|
12
|
+
*/
|
|
13
|
+
export function usePositionPnlHistory(params) {
|
|
14
|
+
const { positionId, interval, startTime, endTime } = params;
|
|
15
|
+
const { sdk } = useMonacoSDK();
|
|
16
|
+
const [data, setData] = useState([]);
|
|
17
|
+
const [loading, setLoading] = useState(false);
|
|
18
|
+
const [error, setError] = useState(null);
|
|
19
|
+
// Only the newest in-flight request may touch state: a slower response for
|
|
20
|
+
// an older position/window must not overwrite a newer result.
|
|
21
|
+
const requestSeq = useRef(0);
|
|
22
|
+
const fetchHistory = useCallback(async () => {
|
|
23
|
+
const seq = ++requestSeq.current;
|
|
24
|
+
if (!sdk?.positions || !positionId) {
|
|
25
|
+
setData([]);
|
|
26
|
+
setLoading(false);
|
|
27
|
+
setError(null);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
setLoading(true);
|
|
31
|
+
setError(null);
|
|
32
|
+
try {
|
|
33
|
+
const response = await sdk.positions.getPositionPnlHistory(positionId, {
|
|
34
|
+
interval,
|
|
35
|
+
startTime,
|
|
36
|
+
endTime,
|
|
37
|
+
});
|
|
38
|
+
if (seq !== requestSeq.current)
|
|
39
|
+
return;
|
|
40
|
+
setData(response.data);
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
if (seq !== requestSeq.current)
|
|
44
|
+
return;
|
|
45
|
+
// Drop prior data so a stale series is never shown under a fresh error.
|
|
46
|
+
setData([]);
|
|
47
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
48
|
+
}
|
|
49
|
+
finally {
|
|
50
|
+
if (seq === requestSeq.current) {
|
|
51
|
+
setLoading(false);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}, [sdk, positionId, interval, startTime, endTime]);
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
void fetchHistory();
|
|
57
|
+
}, [fetchHistory]);
|
|
58
|
+
return { data, loading, error, refetch: fetchHistory };
|
|
59
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xmonaco/react",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.22",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"lint": "biome lint ."
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@0xmonaco/core": "0.8.
|
|
24
|
-
"@0xmonaco/types": "0.8.
|
|
23
|
+
"@0xmonaco/core": "0.8.22",
|
|
24
|
+
"@0xmonaco/types": "0.8.22"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@types/react": "^19.1.12",
|