@0xmonaco/react 0.8.14 → 0.8.15
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/useProfile/useProfile.js +3 -3
- package/dist/hooks/useTradeFeed/useTradeFeed.js +1 -1
- package/dist/hooks/useUserBalances/useUserBalances.js +8 -8
- package/dist/hooks/useUserMovements/useUserMovements.d.ts +4 -4
- package/dist/hooks/useUserMovements/useUserMovements.js +23 -23
- package/dist/hooks/useUserOrders/useUserOrders.js +14 -14
- package/dist/hooks/useVault/types.d.ts +3 -1
- package/dist/hooks/useVault/useVault.js +6 -0
- package/package.json +3 -3
package/dist/coverage.d.ts
CHANGED
package/dist/coverage.js
CHANGED
|
@@ -33,6 +33,7 @@ export const COVERED = {
|
|
|
33
33
|
get_user_profile: "useProfile",
|
|
34
34
|
get_withdrawal: "useVault (retryWithdrawal)",
|
|
35
35
|
initiate_withdrawal: "useVault (withdraw)",
|
|
36
|
+
list_pending_withdrawals: "useVault (listPendingWithdrawals)",
|
|
36
37
|
list_conditional_orders: "useTrade",
|
|
37
38
|
list_funding_history: "useMarket",
|
|
38
39
|
list_position_history: "usePositions",
|
|
@@ -51,9 +51,9 @@ export const useProfile = () => {
|
|
|
51
51
|
try {
|
|
52
52
|
const [userProfileResult, balancesResult, movementsResult, ordersResult] = await Promise.allSettled([
|
|
53
53
|
sdk.profile.getProfile(),
|
|
54
|
-
sdk.profile.getUserBalances({
|
|
55
|
-
sdk.profile.getPaginatedUserMovements({ page: 1,
|
|
56
|
-
sdk.trading.getPaginatedOrders({ page: 1,
|
|
54
|
+
sdk.profile.getUserBalances({ pageSize: DEFAULT_PAGE_SIZE, page: 1 }),
|
|
55
|
+
sdk.profile.getPaginatedUserMovements({ page: 1, pageSize: DEFAULT_PAGE_SIZE }),
|
|
56
|
+
sdk.trading.getPaginatedOrders({ page: 1, pageSize: DEFAULT_PAGE_SIZE }),
|
|
57
57
|
]);
|
|
58
58
|
const userProfile = getSettledValueOrThrow(userProfileResult);
|
|
59
59
|
const balances = getFulfilledValue(balancesResult);
|
|
@@ -19,7 +19,7 @@ export function useTradeFeed(tradingPairId) {
|
|
|
19
19
|
if (!sdk?.ws || !sdk?.trades || !tradingPairId) {
|
|
20
20
|
return;
|
|
21
21
|
}
|
|
22
|
-
const fetchInitialTrades = () => sdk.trades.getTrades(tradingPairId, {
|
|
22
|
+
const fetchInitialTrades = () => sdk.trades.getTrades(tradingPairId, { pageSize: MAX_TRADES });
|
|
23
23
|
const subscribeToWs = (handler) => sdk.ws.trades(tradingPairId, handler);
|
|
24
24
|
return subscribe(tradingPairId, fetchInitialTrades, subscribeToWs);
|
|
25
25
|
}, [sdk?.ws, sdk?.trades, tradingPairId, subscribe]);
|
|
@@ -8,12 +8,12 @@ export function updateBalanceFromEvent(balance, event) {
|
|
|
8
8
|
const totalBalanceRaw = totalBalanceRawFromEvent(balance, event);
|
|
9
9
|
return {
|
|
10
10
|
...balance,
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
availableBalance: event.data.available,
|
|
12
|
+
availableBalanceRaw: event.data.availableRaw,
|
|
13
|
+
lockedBalance: event.data.locked,
|
|
14
|
+
lockedBalanceRaw: event.data.lockedRaw,
|
|
15
|
+
totalBalance: totalBalance,
|
|
16
|
+
totalBalanceRaw: totalBalanceRaw,
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
19
|
function parseDecimal(value) {
|
|
@@ -68,7 +68,7 @@ function totalBalanceFromEvent(balance, event) {
|
|
|
68
68
|
if (eventExtraTotal && decimalGreaterThanZero(eventExtraTotal)) {
|
|
69
69
|
return event.data.total;
|
|
70
70
|
}
|
|
71
|
-
const previousMarginTotal = decimalDifference(balance.
|
|
71
|
+
const previousMarginTotal = decimalDifference(balance.totalBalance, balance.availableBalance, balance.lockedBalance);
|
|
72
72
|
if (!previousMarginTotal || !decimalGreaterThanZero(previousMarginTotal)) {
|
|
73
73
|
return event.data.total;
|
|
74
74
|
}
|
|
@@ -82,7 +82,7 @@ function totalBalanceRawFromEvent(balance, event) {
|
|
|
82
82
|
if (eventExtraTotalRaw && decimalGreaterThanZero(eventExtraTotalRaw)) {
|
|
83
83
|
return event.data.totalRaw;
|
|
84
84
|
}
|
|
85
|
-
const previousMarginTotalRaw = decimalDifference(balance.
|
|
85
|
+
const previousMarginTotalRaw = decimalDifference(balance.totalBalanceRaw, balance.availableBalanceRaw, balance.lockedBalanceRaw);
|
|
86
86
|
if (!previousMarginTotalRaw || !decimalGreaterThanZero(previousMarginTotalRaw)) {
|
|
87
87
|
return event.data.totalRaw;
|
|
88
88
|
}
|
|
@@ -10,9 +10,9 @@ import type { UseUserMovementsOptions, UseUserMovementsReturn } from "./types";
|
|
|
10
10
|
*
|
|
11
11
|
* @param options - Optional filter and pagination options
|
|
12
12
|
* @param options.maxMovements - Maximum number of movements to keep in state (default: 50)
|
|
13
|
-
* @param options.
|
|
14
|
-
* @param options.
|
|
15
|
-
* @param options.
|
|
16
|
-
* @param options.
|
|
13
|
+
* @param options.pageSize - Number of items per page for the API call (default: maxMovements)
|
|
14
|
+
* @param options.entryType - Filter by entry type (CREDIT, DEBIT, LOCK, UNLOCK, FEE)
|
|
15
|
+
* @param options.transactionType - Filter by transaction type (DEPOSIT, WITHDRAWAL, TRADE, etc.)
|
|
16
|
+
* @param options.assetId - Filter by asset ID (UUID)
|
|
17
17
|
*/
|
|
18
18
|
export declare function useUserMovements(options?: UseUserMovementsOptions): UseUserMovementsReturn;
|
|
@@ -10,26 +10,26 @@ function ledgerMovementToEvent(movement, userId) {
|
|
|
10
10
|
userId,
|
|
11
11
|
data: {
|
|
12
12
|
id: movement.id,
|
|
13
|
-
entryType: movement.
|
|
14
|
-
transactionType: movement.
|
|
13
|
+
entryType: movement.entryType,
|
|
14
|
+
transactionType: movement.transactionType,
|
|
15
15
|
tokenAddress: movement.token,
|
|
16
16
|
symbol: movement.symbol ?? undefined,
|
|
17
17
|
decimals: movement.decimals,
|
|
18
18
|
amount: movement.amount,
|
|
19
|
-
amountRaw: movement.
|
|
20
|
-
balanceBefore: movement.
|
|
21
|
-
balanceBeforeRaw: movement.
|
|
22
|
-
balanceAfter: movement.
|
|
23
|
-
balanceAfterRaw: movement.
|
|
24
|
-
lockedBefore: movement.
|
|
25
|
-
lockedBeforeRaw: movement.
|
|
26
|
-
lockedAfter: movement.
|
|
27
|
-
lockedAfterRaw: movement.
|
|
28
|
-
referenceId: movement.
|
|
29
|
-
referenceType: movement.
|
|
19
|
+
amountRaw: movement.amountRaw,
|
|
20
|
+
balanceBefore: movement.balanceBefore ?? undefined,
|
|
21
|
+
balanceBeforeRaw: movement.balanceBeforeRaw ?? undefined,
|
|
22
|
+
balanceAfter: movement.balanceAfter ?? undefined,
|
|
23
|
+
balanceAfterRaw: movement.balanceAfterRaw ?? undefined,
|
|
24
|
+
lockedBefore: movement.lockedBefore ?? undefined,
|
|
25
|
+
lockedBeforeRaw: movement.lockedBeforeRaw ?? undefined,
|
|
26
|
+
lockedAfter: movement.lockedAfter ?? undefined,
|
|
27
|
+
lockedAfterRaw: movement.lockedAfterRaw ?? undefined,
|
|
28
|
+
referenceId: movement.referenceId ?? undefined,
|
|
29
|
+
referenceType: movement.referenceType ?? undefined,
|
|
30
30
|
description: movement.description ?? undefined,
|
|
31
|
-
txHash: movement.
|
|
32
|
-
createdAt: movement.
|
|
31
|
+
txHash: movement.txHash ?? undefined,
|
|
32
|
+
createdAt: movement.createdAt ?? undefined,
|
|
33
33
|
},
|
|
34
34
|
};
|
|
35
35
|
}
|
|
@@ -44,22 +44,22 @@ function ledgerMovementToEvent(movement, userId) {
|
|
|
44
44
|
*
|
|
45
45
|
* @param options - Optional filter and pagination options
|
|
46
46
|
* @param options.maxMovements - Maximum number of movements to keep in state (default: 50)
|
|
47
|
-
* @param options.
|
|
48
|
-
* @param options.
|
|
49
|
-
* @param options.
|
|
50
|
-
* @param options.
|
|
47
|
+
* @param options.pageSize - Number of items per page for the API call (default: maxMovements)
|
|
48
|
+
* @param options.entryType - Filter by entry type (CREDIT, DEBIT, LOCK, UNLOCK, FEE)
|
|
49
|
+
* @param options.transactionType - Filter by transaction type (DEPOSIT, WITHDRAWAL, TRADE, etc.)
|
|
50
|
+
* @param options.assetId - Filter by asset ID (UUID)
|
|
51
51
|
*/
|
|
52
52
|
export function useUserMovements(options = {}) {
|
|
53
53
|
const { sdk } = useMonacoSDK();
|
|
54
54
|
const { authenticationStatus } = useMonacoContext();
|
|
55
|
-
const { maxMovements = 50,
|
|
55
|
+
const { maxMovements = 50, pageSize, entryType, transactionType, assetId } = options;
|
|
56
56
|
const [movements, setMovements] = useState([]);
|
|
57
57
|
const [loading, setLoading] = useState(false);
|
|
58
58
|
const [error, setError] = useState(null);
|
|
59
59
|
const [subscribed, setSubscribed] = useState(false);
|
|
60
60
|
const clearError = useCallback(() => setError(null), []);
|
|
61
61
|
const sliceSize = Number.isFinite(maxMovements) && maxMovements > 0 ? maxMovements : 50;
|
|
62
|
-
const requestLimit =
|
|
62
|
+
const requestLimit = pageSize ?? Math.min(Math.max(Math.round(sliceSize), 1), 100);
|
|
63
63
|
// Derive userId reactively — authenticationStatus changes on login/logout, triggering a re-render
|
|
64
64
|
const userId = authenticationStatus === "authenticated" ? sdk?.getAuthState()?.user.id : undefined;
|
|
65
65
|
useEffect(() => {
|
|
@@ -73,7 +73,7 @@ export function useUserMovements(options = {}) {
|
|
|
73
73
|
// Fetch initial movements via REST API, then subscribe to WebSocket updates
|
|
74
74
|
let unsubscribe;
|
|
75
75
|
sdk.profile
|
|
76
|
-
.getPaginatedUserMovements({
|
|
76
|
+
.getPaginatedUserMovements({ pageSize: requestLimit, entryType, transactionType, assetId })
|
|
77
77
|
.then(async (response) => {
|
|
78
78
|
// Combine latest_movements (from the live engine cache) with movements (from PostgreSQL)
|
|
79
79
|
// latest_movements contains real-time data that may not yet be in PostgreSQL
|
|
@@ -117,6 +117,6 @@ export function useUserMovements(options = {}) {
|
|
|
117
117
|
unsubscribe?.();
|
|
118
118
|
setSubscribed(false);
|
|
119
119
|
};
|
|
120
|
-
}, [sdk?.ws, sdk?.profile, userId, sliceSize, requestLimit,
|
|
120
|
+
}, [sdk?.ws, sdk?.profile, userId, sliceSize, requestLimit, entryType, transactionType, assetId]);
|
|
121
121
|
return { movements, loading, subscribed, error, clearError };
|
|
122
122
|
}
|
|
@@ -23,7 +23,7 @@ export function useUserOrders(maxOrders = 50) {
|
|
|
23
23
|
try {
|
|
24
24
|
const response = await sdk.trading.getPaginatedOrders({
|
|
25
25
|
page: 1,
|
|
26
|
-
|
|
26
|
+
pageSize: maxOrders,
|
|
27
27
|
});
|
|
28
28
|
// Combine latest_orders (from the live engine cache) with orders (from PostgreSQL)
|
|
29
29
|
// latest_orders contains real-time data that may not yet be in PostgreSQL
|
|
@@ -123,18 +123,18 @@ function orderFromEvent(event) {
|
|
|
123
123
|
return null;
|
|
124
124
|
return {
|
|
125
125
|
id: event.orderId,
|
|
126
|
-
|
|
127
|
-
|
|
126
|
+
tradingPairId: tradingPairId,
|
|
127
|
+
orderType: (data.orderType || "LIMIT"),
|
|
128
128
|
side: (data.side || "BUY"),
|
|
129
129
|
price: data.price,
|
|
130
130
|
quantity: data.quantity || "0",
|
|
131
|
-
|
|
132
|
-
|
|
131
|
+
filledQuantity: "0",
|
|
132
|
+
averageFillPrice: undefined,
|
|
133
133
|
status: data.status,
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
134
|
+
tradingMode: (data.tradingMode || "SPOT"),
|
|
135
|
+
timeInForce: data.timeInForce,
|
|
136
|
+
createdAt: event.timestamp,
|
|
137
|
+
updatedAt: event.timestamp,
|
|
138
138
|
};
|
|
139
139
|
}
|
|
140
140
|
/**
|
|
@@ -170,8 +170,8 @@ function updateOrderFromEvent(order, event) {
|
|
|
170
170
|
}
|
|
171
171
|
}
|
|
172
172
|
// Get filled quantity from different event types
|
|
173
|
-
let filledQuantity = order.
|
|
174
|
-
let avgFillPrice = order.
|
|
173
|
+
let filledQuantity = order.filledQuantity;
|
|
174
|
+
let avgFillPrice = order.averageFillPrice;
|
|
175
175
|
if ("totalFilled" in data && data.totalFilled) {
|
|
176
176
|
filledQuantity = data.totalFilled;
|
|
177
177
|
}
|
|
@@ -184,8 +184,8 @@ function updateOrderFromEvent(order, event) {
|
|
|
184
184
|
return {
|
|
185
185
|
...order,
|
|
186
186
|
status: newStatus,
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
187
|
+
filledQuantity: filledQuantity,
|
|
188
|
+
averageFillPrice: avgFillPrice,
|
|
189
|
+
updatedAt: event.timestamp,
|
|
190
190
|
};
|
|
191
191
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { TransactionResult, WithdrawalSource, WithdrawResult } from "@0xmonaco/types";
|
|
1
|
+
import type { ListPendingWithdrawalsParams, ListPendingWithdrawalsResponse, TransactionResult, WithdrawalSource, WithdrawResult } from "@0xmonaco/types";
|
|
2
2
|
export interface UseVaultReturn {
|
|
3
3
|
/** Approve the vault to spend tokens */
|
|
4
4
|
approve: (assetId: string, amount: bigint, autoWait?: boolean) => Promise<TransactionResult>;
|
|
@@ -8,6 +8,8 @@ export interface UseVaultReturn {
|
|
|
8
8
|
withdraw: (assetId: string, amount: bigint, autoWait?: boolean, source?: WithdrawalSource) => Promise<WithdrawResult>;
|
|
9
9
|
/** Retry a withdrawal whose on-chain submission never landed — does NOT create a new one */
|
|
10
10
|
retryWithdrawal: (withdrawalIndex: number, autoWait?: boolean) => Promise<WithdrawResult>;
|
|
11
|
+
/** List the caller's pending withdrawals (awaiting on-chain confirmation), newest first */
|
|
12
|
+
listPendingWithdrawals: (params?: ListPendingWithdrawalsParams) => Promise<ListPendingWithdrawalsResponse>;
|
|
11
13
|
/** Get the allowance for a token */
|
|
12
14
|
getAllowance: (assetId: string) => Promise<bigint>;
|
|
13
15
|
/** Check if a token needs approval for an amount */
|
|
@@ -37,6 +37,11 @@ export const useVault = () => {
|
|
|
37
37
|
}
|
|
38
38
|
return await sdk.vault.retryWithdrawal(withdrawalIndex, autoWait);
|
|
39
39
|
}, [sdk]);
|
|
40
|
+
const listPendingWithdrawals = useCallback(async (params) => {
|
|
41
|
+
if (!sdk)
|
|
42
|
+
throw new Error("SDK not available");
|
|
43
|
+
return await sdk.withdrawals.listPendingWithdrawals(params);
|
|
44
|
+
}, [sdk]);
|
|
40
45
|
const getAllowance = useCallback(async (assetId) => {
|
|
41
46
|
if (!sdk)
|
|
42
47
|
throw new Error("SDK not available");
|
|
@@ -59,6 +64,7 @@ export const useVault = () => {
|
|
|
59
64
|
deposit,
|
|
60
65
|
withdraw,
|
|
61
66
|
retryWithdrawal,
|
|
67
|
+
listPendingWithdrawals,
|
|
62
68
|
// Approval and allowance queries
|
|
63
69
|
getAllowance,
|
|
64
70
|
needsApproval,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xmonaco/react",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.15",
|
|
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.15",
|
|
24
|
+
"@0xmonaco/types": "0.8.15"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@types/react": "^19.1.12",
|