@pear-protocol/symmio-client 0.2.6 → 0.2.7
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/react/index.d.mts +25 -1
- package/dist/react/index.d.ts +25 -1
- package/dist/react/index.js +156 -46
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +155 -48
- package/dist/react/index.mjs.map +1 -1
- package/dist/react/provider.js +11 -5
- package/dist/react/provider.js.map +1 -1
- package/dist/react/provider.mjs +12 -6
- package/dist/react/provider.mjs.map +1 -1
- package/package.json +3 -2
package/dist/react/index.d.mts
CHANGED
|
@@ -7,6 +7,7 @@ import * as _tanstack_react_query from '@tanstack/react-query';
|
|
|
7
7
|
import * as _tanstack_query_core from '@tanstack/query-core';
|
|
8
8
|
import * as node_modules__pear_protocol_symm_core_dist_types from 'node_modules/@pear-protocol/symm-core/dist/types';
|
|
9
9
|
import * as _pear_protocol_symm_shared from '@pear-protocol/symm-shared';
|
|
10
|
+
import * as zustand from 'zustand';
|
|
10
11
|
import 'react/jsx-runtime';
|
|
11
12
|
|
|
12
13
|
type SymmContextValue = {
|
|
@@ -910,4 +911,27 @@ declare const symmKeys: {
|
|
|
910
911
|
|
|
911
912
|
declare function getSymmErrorMessage(error: unknown): string;
|
|
912
913
|
|
|
913
|
-
|
|
914
|
+
type SymmWsState = {
|
|
915
|
+
isConnected: boolean;
|
|
916
|
+
setConnected: (isConnected: boolean) => void;
|
|
917
|
+
};
|
|
918
|
+
declare const useSymmWsStore: zustand.UseBoundStore<zustand.StoreApi<SymmWsState>>;
|
|
919
|
+
|
|
920
|
+
type MarkPrices = Record<string, number>;
|
|
921
|
+
type BinanceMarkPriceState = {
|
|
922
|
+
markPrices: MarkPrices;
|
|
923
|
+
subscribeSymbol: (symmSymbol: string, binanceSymbol: string) => void;
|
|
924
|
+
unsubscribeSymbol: (symmSymbol: string, binanceSymbol: string) => void;
|
|
925
|
+
};
|
|
926
|
+
declare const useBinanceMarkPriceStore: zustand.UseBoundStore<zustand.StoreApi<BinanceMarkPriceState>>;
|
|
927
|
+
|
|
928
|
+
type SymmAuthState = {
|
|
929
|
+
tokensByKey: Record<string, string>;
|
|
930
|
+
setToken: (address: Address, chainId: number, token: string) => void;
|
|
931
|
+
getToken: (address: Address, chainId: number) => string | null;
|
|
932
|
+
clearToken: (address: Address, chainId: number) => void;
|
|
933
|
+
clearAll: () => void;
|
|
934
|
+
};
|
|
935
|
+
declare const useSymmAuthStore: zustand.UseBoundStore<zustand.StoreApi<SymmAuthState>>;
|
|
936
|
+
|
|
937
|
+
export { type SymmChartSelection, type SymmChartSelectionInput, type SymmChartTokenSelection, type SymmContextValue, type SymmDelegationState, type SymmInstantTradeActionArgs, type SymmInstantTradeRequest, type SymmPerformanceOverlay, type SymmQueryConfig, type SymmTokenMetadata, type UseSymmAuthParams, type UseSymmChartCandlesReturn, type UseSymmDelegationParams, type UseSymmHedgerMarketsParams, type UseSymmTokenSelectionMetadataReturn, type UseSymmTpslOrdersParams, getSymmErrorMessage, symmKeys, useBinanceMarkPriceStore, useSymmAccountData, useSymmAccountSummary, useSymmAccounts, useSymmAccountsApi, useSymmAccountsLength, useSymmAccountsWithPositions, useSymmApproval, useSymmAuth, useSymmAuthStore, useSymmAvailableMargin, useSymmBalances, useSymmCancelClose, useSymmChartCandles, useSymmChartSelection, useSymmCloseOrder, useSymmCollateral, useSymmContext, useSymmCoreClient, useSymmDelegation, useSymmDeposit, useSymmFunding, useSymmFundingHistory, useSymmFundingPayments, useSymmHedgerMarketById, useSymmHedgerMarketBySymbol, useSymmHedgerMarkets, useSymmInstantTrade, useSymmLockedParams, useSymmMarkets, useSymmNotifications, useSymmOpenOrders, useSymmPendingIds, useSymmPendingInstantOpens, useSymmPerformanceOverlays, useSymmPortfolio, useSymmPositions, useSymmSignature, useSymmTokenSelectionMetadata, useSymmTpsl, useSymmTpslOrders, useSymmTrade, useSymmTradeHistory, useSymmTriggerConfig, useSymmTriggerOrders, useSymmTwap, useSymmTwapOrder, useSymmWithdraw, useSymmWs, useSymmWsStore };
|
package/dist/react/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ import * as _tanstack_react_query from '@tanstack/react-query';
|
|
|
7
7
|
import * as _tanstack_query_core from '@tanstack/query-core';
|
|
8
8
|
import * as node_modules__pear_protocol_symm_core_dist_types from 'node_modules/@pear-protocol/symm-core/dist/types';
|
|
9
9
|
import * as _pear_protocol_symm_shared from '@pear-protocol/symm-shared';
|
|
10
|
+
import * as zustand from 'zustand';
|
|
10
11
|
import 'react/jsx-runtime';
|
|
11
12
|
|
|
12
13
|
type SymmContextValue = {
|
|
@@ -910,4 +911,27 @@ declare const symmKeys: {
|
|
|
910
911
|
|
|
911
912
|
declare function getSymmErrorMessage(error: unknown): string;
|
|
912
913
|
|
|
913
|
-
|
|
914
|
+
type SymmWsState = {
|
|
915
|
+
isConnected: boolean;
|
|
916
|
+
setConnected: (isConnected: boolean) => void;
|
|
917
|
+
};
|
|
918
|
+
declare const useSymmWsStore: zustand.UseBoundStore<zustand.StoreApi<SymmWsState>>;
|
|
919
|
+
|
|
920
|
+
type MarkPrices = Record<string, number>;
|
|
921
|
+
type BinanceMarkPriceState = {
|
|
922
|
+
markPrices: MarkPrices;
|
|
923
|
+
subscribeSymbol: (symmSymbol: string, binanceSymbol: string) => void;
|
|
924
|
+
unsubscribeSymbol: (symmSymbol: string, binanceSymbol: string) => void;
|
|
925
|
+
};
|
|
926
|
+
declare const useBinanceMarkPriceStore: zustand.UseBoundStore<zustand.StoreApi<BinanceMarkPriceState>>;
|
|
927
|
+
|
|
928
|
+
type SymmAuthState = {
|
|
929
|
+
tokensByKey: Record<string, string>;
|
|
930
|
+
setToken: (address: Address, chainId: number, token: string) => void;
|
|
931
|
+
getToken: (address: Address, chainId: number) => string | null;
|
|
932
|
+
clearToken: (address: Address, chainId: number) => void;
|
|
933
|
+
clearAll: () => void;
|
|
934
|
+
};
|
|
935
|
+
declare const useSymmAuthStore: zustand.UseBoundStore<zustand.StoreApi<SymmAuthState>>;
|
|
936
|
+
|
|
937
|
+
export { type SymmChartSelection, type SymmChartSelectionInput, type SymmChartTokenSelection, type SymmContextValue, type SymmDelegationState, type SymmInstantTradeActionArgs, type SymmInstantTradeRequest, type SymmPerformanceOverlay, type SymmQueryConfig, type SymmTokenMetadata, type UseSymmAuthParams, type UseSymmChartCandlesReturn, type UseSymmDelegationParams, type UseSymmHedgerMarketsParams, type UseSymmTokenSelectionMetadataReturn, type UseSymmTpslOrdersParams, getSymmErrorMessage, symmKeys, useBinanceMarkPriceStore, useSymmAccountData, useSymmAccountSummary, useSymmAccounts, useSymmAccountsApi, useSymmAccountsLength, useSymmAccountsWithPositions, useSymmApproval, useSymmAuth, useSymmAuthStore, useSymmAvailableMargin, useSymmBalances, useSymmCancelClose, useSymmChartCandles, useSymmChartSelection, useSymmCloseOrder, useSymmCollateral, useSymmContext, useSymmCoreClient, useSymmDelegation, useSymmDeposit, useSymmFunding, useSymmFundingHistory, useSymmFundingPayments, useSymmHedgerMarketById, useSymmHedgerMarketBySymbol, useSymmHedgerMarkets, useSymmInstantTrade, useSymmLockedParams, useSymmMarkets, useSymmNotifications, useSymmOpenOrders, useSymmPendingIds, useSymmPendingInstantOpens, useSymmPerformanceOverlays, useSymmPortfolio, useSymmPositions, useSymmSignature, useSymmTokenSelectionMetadata, useSymmTpsl, useSymmTpslOrders, useSymmTrade, useSymmTradeHistory, useSymmTriggerConfig, useSymmTriggerOrders, useSymmTwap, useSymmTwapOrder, useSymmWithdraw, useSymmWs, useSymmWsStore };
|
package/dist/react/index.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
var react = require('react');
|
|
5
5
|
var symmCore = require('@pear-protocol/symm-core');
|
|
6
6
|
var reactQuery = require('@tanstack/react-query');
|
|
7
|
+
var zustand = require('zustand');
|
|
7
8
|
var jsxRuntime = require('react/jsx-runtime');
|
|
8
9
|
var viem = require('viem');
|
|
9
10
|
|
|
@@ -54,6 +55,10 @@ var symmKeys = {
|
|
|
54
55
|
delegation: (account, target, selectors, chainId) => ["symm", "delegation", account, target, selectors, chainId],
|
|
55
56
|
chartMetadata: (symbolsKey, positionKey) => ["symm", "chartMetadata", symbolsKey, positionKey]
|
|
56
57
|
};
|
|
58
|
+
var useSymmWsStore = zustand.create((set) => ({
|
|
59
|
+
isConnected: false,
|
|
60
|
+
setConnected: (isConnected) => set({ isConnected })
|
|
61
|
+
}));
|
|
57
62
|
|
|
58
63
|
// src/react/hooks/use-symm-ws.ts
|
|
59
64
|
function asUnsubscribeFn(value) {
|
|
@@ -61,18 +66,19 @@ function asUnsubscribeFn(value) {
|
|
|
61
66
|
}
|
|
62
67
|
function useSymmWs(params) {
|
|
63
68
|
const queryClient = reactQuery.useQueryClient();
|
|
69
|
+
const isConnected = useSymmWsStore((state) => state.isConnected);
|
|
70
|
+
const setConnected = useSymmWsStore((state) => state.setConnected);
|
|
64
71
|
const { symmCoreClient, accountAddress, chainId } = params;
|
|
65
|
-
const [isConnected, setIsConnected] = react.useState(false);
|
|
66
72
|
react.useEffect(() => {
|
|
67
73
|
if (!symmCoreClient || !accountAddress) {
|
|
68
|
-
|
|
74
|
+
setConnected(false);
|
|
69
75
|
return;
|
|
70
76
|
}
|
|
71
77
|
const ws = symmCoreClient.ws;
|
|
72
78
|
const addr = accountAddress;
|
|
73
79
|
const unsubscribers = [];
|
|
74
|
-
const removeOnConnect = ws.onConnect(() =>
|
|
75
|
-
const removeOnDisconnect = ws.onDisconnect(() =>
|
|
80
|
+
const removeOnConnect = ws.onConnect(() => setConnected(true));
|
|
81
|
+
const removeOnDisconnect = ws.onDisconnect(() => setConnected(false));
|
|
76
82
|
unsubscribers.push(removeOnConnect, removeOnDisconnect);
|
|
77
83
|
const positionsUnsub = asUnsubscribeFn(ws.subscribeToPositions(addr, chainId, () => {
|
|
78
84
|
queryClient.invalidateQueries({
|
|
@@ -143,7 +149,7 @@ function useSymmWs(params) {
|
|
|
143
149
|
ws.unsubscribeAll();
|
|
144
150
|
}
|
|
145
151
|
};
|
|
146
|
-
}, [symmCoreClient, accountAddress, chainId, queryClient]);
|
|
152
|
+
}, [symmCoreClient, accountAddress, chainId, queryClient, setConnected]);
|
|
147
153
|
return { isConnected };
|
|
148
154
|
}
|
|
149
155
|
var noopRefreshAuth = async () => null;
|
|
@@ -371,20 +377,60 @@ async function fetchAccessToken(walletClient, signerAddress, accountAddress, cha
|
|
|
371
377
|
writeStoredToken(accountAddress, chainId, cachedToken);
|
|
372
378
|
return accessToken;
|
|
373
379
|
}
|
|
380
|
+
function symmAuthTokenKey(address, chainId) {
|
|
381
|
+
return `${address.toLowerCase()}:${chainId}`;
|
|
382
|
+
}
|
|
383
|
+
var useSymmAuthStore = zustand.create((set, get) => ({
|
|
384
|
+
tokensByKey: {},
|
|
385
|
+
setToken: (address, chainId, token) => {
|
|
386
|
+
const key = symmAuthTokenKey(address, chainId);
|
|
387
|
+
set((state) => ({
|
|
388
|
+
tokensByKey: {
|
|
389
|
+
...state.tokensByKey,
|
|
390
|
+
[key]: token
|
|
391
|
+
}
|
|
392
|
+
}));
|
|
393
|
+
},
|
|
394
|
+
getToken: (address, chainId) => {
|
|
395
|
+
const key = symmAuthTokenKey(address, chainId);
|
|
396
|
+
return get().tokensByKey[key] ?? null;
|
|
397
|
+
},
|
|
398
|
+
clearToken: (address, chainId) => {
|
|
399
|
+
const key = symmAuthTokenKey(address, chainId);
|
|
400
|
+
set((state) => {
|
|
401
|
+
if (!(key in state.tokensByKey)) return state;
|
|
402
|
+
const next = { ...state.tokensByKey };
|
|
403
|
+
delete next[key];
|
|
404
|
+
return { tokensByKey: next };
|
|
405
|
+
});
|
|
406
|
+
},
|
|
407
|
+
clearAll: () => {
|
|
408
|
+
set({ tokensByKey: {} });
|
|
409
|
+
}
|
|
410
|
+
}));
|
|
374
411
|
|
|
375
412
|
// src/react/hooks/use-symm-auth.ts
|
|
376
413
|
function useSymmAuth(params) {
|
|
377
414
|
const { address, chainId, walletClient, siweDomain } = params;
|
|
378
|
-
const
|
|
415
|
+
const accessToken = useSymmAuthStore(
|
|
416
|
+
(state) => address ? state.tokensByKey[symmAuthTokenKey(address, chainId)] ?? null : null
|
|
417
|
+
);
|
|
418
|
+
const setToken = useSymmAuthStore((state) => state.setToken);
|
|
419
|
+
const getToken = useSymmAuthStore((state) => state.getToken);
|
|
420
|
+
const clearToken = useSymmAuthStore((state) => state.clearToken);
|
|
379
421
|
const previousAddressRef = react.useRef(address);
|
|
380
422
|
const previousChainIdRef = react.useRef(chainId);
|
|
381
423
|
const refreshAuth = react.useCallback(
|
|
382
424
|
async (accountAddress) => {
|
|
383
425
|
if (!walletClient || !address) return null;
|
|
384
426
|
const resolvedAccountAddress = accountAddress ?? address;
|
|
427
|
+
const inMemory = getToken(resolvedAccountAddress, chainId);
|
|
428
|
+
if (inMemory) {
|
|
429
|
+
return inMemory;
|
|
430
|
+
}
|
|
385
431
|
const cached = getCachedToken(resolvedAccountAddress, chainId);
|
|
386
432
|
if (cached) {
|
|
387
|
-
|
|
433
|
+
setToken(resolvedAccountAddress, chainId, cached);
|
|
388
434
|
return cached;
|
|
389
435
|
}
|
|
390
436
|
try {
|
|
@@ -395,21 +441,21 @@ function useSymmAuth(params) {
|
|
|
395
441
|
chainId,
|
|
396
442
|
siweDomain
|
|
397
443
|
);
|
|
398
|
-
|
|
444
|
+
setToken(resolvedAccountAddress, chainId, token);
|
|
399
445
|
return token;
|
|
400
446
|
} catch {
|
|
401
|
-
|
|
447
|
+
clearToken(resolvedAccountAddress, chainId);
|
|
402
448
|
return null;
|
|
403
449
|
}
|
|
404
450
|
},
|
|
405
|
-
[walletClient, address, chainId, siweDomain]
|
|
451
|
+
[walletClient, address, chainId, siweDomain, getToken, setToken, clearToken]
|
|
406
452
|
);
|
|
407
453
|
const clearAuth = react.useCallback(() => {
|
|
408
454
|
if (address) {
|
|
409
455
|
clearCachedToken(address, chainId);
|
|
456
|
+
clearToken(address, chainId);
|
|
410
457
|
}
|
|
411
|
-
|
|
412
|
-
}, [address, chainId]);
|
|
458
|
+
}, [address, chainId, clearToken]);
|
|
413
459
|
react.useEffect(() => {
|
|
414
460
|
const previousAddress = previousAddressRef.current;
|
|
415
461
|
const previousChainId = previousChainIdRef.current;
|
|
@@ -418,15 +464,19 @@ function useSymmAuth(params) {
|
|
|
418
464
|
previousAddressRef.current = address;
|
|
419
465
|
previousChainIdRef.current = chainId;
|
|
420
466
|
if (!address || !walletClient) {
|
|
421
|
-
setAccessToken(null);
|
|
422
467
|
return;
|
|
423
468
|
}
|
|
424
469
|
if (previousAddress && (addressChanged || chainChanged)) {
|
|
425
470
|
clearCachedToken(previousAddress, previousChainId);
|
|
471
|
+
clearToken(previousAddress, previousChainId);
|
|
426
472
|
}
|
|
427
473
|
const cached = getCachedToken(address, chainId);
|
|
428
|
-
|
|
429
|
-
|
|
474
|
+
if (cached) {
|
|
475
|
+
setToken(address, chainId, cached);
|
|
476
|
+
} else {
|
|
477
|
+
clearToken(address, chainId);
|
|
478
|
+
}
|
|
479
|
+
}, [address, walletClient, chainId, setToken, clearToken]);
|
|
430
480
|
return {
|
|
431
481
|
accessToken,
|
|
432
482
|
authToken: accessToken,
|
|
@@ -1040,7 +1090,7 @@ function useSymmInstantTrade(params) {
|
|
|
1040
1090
|
if (selectors.length === 0) {
|
|
1041
1091
|
throw new Error("at least one delegation selector is required");
|
|
1042
1092
|
}
|
|
1043
|
-
const accessToken = await refreshAuth(accountAddress);
|
|
1093
|
+
const accessToken = useSymmAuthStore.getState().getToken(accountAddress, chainId) ?? await refreshAuth(accountAddress);
|
|
1044
1094
|
if (!accessToken) {
|
|
1045
1095
|
throw new Error("failed to refresh instant-trading auth");
|
|
1046
1096
|
}
|
|
@@ -1439,7 +1489,7 @@ function useSymmCancelClose() {
|
|
|
1439
1489
|
if (!symmCoreClient) {
|
|
1440
1490
|
throw new Error("symm-core client not available");
|
|
1441
1491
|
}
|
|
1442
|
-
const resolvedAuthToken = authToken ?? ctxAuthToken ?? (accountAddress ? await refreshAuth(accountAddress) : null);
|
|
1492
|
+
const resolvedAuthToken = authToken ?? (accountAddress ? useSymmAuthStore.getState().getToken(accountAddress, chainId) : null) ?? ctxAuthToken ?? (accountAddress ? await refreshAuth(accountAddress) : null);
|
|
1443
1493
|
if (!resolvedAuthToken) {
|
|
1444
1494
|
throw new Error("auth token is required to cancel a pending close");
|
|
1445
1495
|
}
|
|
@@ -25200,7 +25250,7 @@ function useSymmPendingInstantOpens(params) {
|
|
|
25200
25250
|
...params.query,
|
|
25201
25251
|
queryKey: symmKeys.pendingInstantOpens(accountAddress, chainId),
|
|
25202
25252
|
queryFn: async () => {
|
|
25203
|
-
const authToken = providedAuthToken ?? ctxAuthToken ?? await refreshAuth(accountAddress);
|
|
25253
|
+
const authToken = providedAuthToken ?? useSymmAuthStore.getState().getToken(accountAddress, chainId) ?? ctxAuthToken ?? await refreshAuth(accountAddress);
|
|
25204
25254
|
if (!authToken) {
|
|
25205
25255
|
throw new Error("failed to acquire auth token for pending instant opens");
|
|
25206
25256
|
}
|
|
@@ -25712,6 +25762,74 @@ function getBinanceWsManager() {
|
|
|
25712
25762
|
return _instance;
|
|
25713
25763
|
}
|
|
25714
25764
|
|
|
25765
|
+
// src/react/stores/use-binance-mark-price-store.ts
|
|
25766
|
+
var refCounts = /* @__PURE__ */ new Map();
|
|
25767
|
+
var streamUnsubs = /* @__PURE__ */ new Map();
|
|
25768
|
+
var streamSymbols = /* @__PURE__ */ new Map();
|
|
25769
|
+
function normalizeBinanceSymbol(symbol) {
|
|
25770
|
+
return symbol.toUpperCase().trim();
|
|
25771
|
+
}
|
|
25772
|
+
function getNextRefCount(binanceSymbol) {
|
|
25773
|
+
return (refCounts.get(binanceSymbol) ?? 0) + 1;
|
|
25774
|
+
}
|
|
25775
|
+
function getPrevRefCount(binanceSymbol) {
|
|
25776
|
+
return Math.max(0, (refCounts.get(binanceSymbol) ?? 0) - 1);
|
|
25777
|
+
}
|
|
25778
|
+
var useBinanceMarkPriceStore = zustand.create((set) => ({
|
|
25779
|
+
markPrices: {},
|
|
25780
|
+
subscribeSymbol: (symmSymbol, rawBinanceSymbol) => {
|
|
25781
|
+
const binanceSymbol = normalizeBinanceSymbol(rawBinanceSymbol);
|
|
25782
|
+
const nextRefCount = getNextRefCount(binanceSymbol);
|
|
25783
|
+
refCounts.set(binanceSymbol, nextRefCount);
|
|
25784
|
+
const symbols = streamSymbols.get(binanceSymbol) ?? /* @__PURE__ */ new Set();
|
|
25785
|
+
symbols.add(symmSymbol);
|
|
25786
|
+
streamSymbols.set(binanceSymbol, symbols);
|
|
25787
|
+
if (nextRefCount === 1) {
|
|
25788
|
+
const wsManager = getBinanceWsManager();
|
|
25789
|
+
const unsubscribe = wsManager.subscribeMarkPrice(binanceSymbol, (data) => {
|
|
25790
|
+
const canonicalSymbol = normalizeBinanceSymbol(data.symbol);
|
|
25791
|
+
const mappedSymbols = streamSymbols.get(canonicalSymbol);
|
|
25792
|
+
if (!mappedSymbols || mappedSymbols.size === 0) return;
|
|
25793
|
+
set((state) => {
|
|
25794
|
+
const nextMarkPrices = { ...state.markPrices };
|
|
25795
|
+
mappedSymbols.forEach((mappedSymbol) => {
|
|
25796
|
+
nextMarkPrices[mappedSymbol] = data.markPrice;
|
|
25797
|
+
});
|
|
25798
|
+
return { markPrices: nextMarkPrices };
|
|
25799
|
+
});
|
|
25800
|
+
});
|
|
25801
|
+
streamUnsubs.set(binanceSymbol, unsubscribe);
|
|
25802
|
+
}
|
|
25803
|
+
},
|
|
25804
|
+
unsubscribeSymbol: (symmSymbol, rawBinanceSymbol) => {
|
|
25805
|
+
const binanceSymbol = normalizeBinanceSymbol(rawBinanceSymbol);
|
|
25806
|
+
const symbols = streamSymbols.get(binanceSymbol);
|
|
25807
|
+
if (symbols) {
|
|
25808
|
+
symbols.delete(symmSymbol);
|
|
25809
|
+
if (symbols.size === 0) {
|
|
25810
|
+
streamSymbols.delete(binanceSymbol);
|
|
25811
|
+
} else {
|
|
25812
|
+
streamSymbols.set(binanceSymbol, symbols);
|
|
25813
|
+
}
|
|
25814
|
+
}
|
|
25815
|
+
const nextRefCount = getPrevRefCount(binanceSymbol);
|
|
25816
|
+
if (nextRefCount === 0) {
|
|
25817
|
+
const unsubscribe = streamUnsubs.get(binanceSymbol);
|
|
25818
|
+
if (unsubscribe) unsubscribe();
|
|
25819
|
+
streamUnsubs.delete(binanceSymbol);
|
|
25820
|
+
refCounts.delete(binanceSymbol);
|
|
25821
|
+
} else {
|
|
25822
|
+
refCounts.set(binanceSymbol, nextRefCount);
|
|
25823
|
+
}
|
|
25824
|
+
set((state) => {
|
|
25825
|
+
if (state.markPrices[symmSymbol] == null) return state;
|
|
25826
|
+
const nextMarkPrices = { ...state.markPrices };
|
|
25827
|
+
delete nextMarkPrices[symmSymbol];
|
|
25828
|
+
return { markPrices: nextMarkPrices };
|
|
25829
|
+
});
|
|
25830
|
+
}
|
|
25831
|
+
}));
|
|
25832
|
+
|
|
25715
25833
|
// src/react/hooks/use-symm-token-selection-metadata.ts
|
|
25716
25834
|
async function fetchTickerSnapshot(symbol) {
|
|
25717
25835
|
const resolution = resolveBinanceSymbol(symbol);
|
|
@@ -25753,9 +25871,9 @@ function useSymmTokenSelectionMetadata(selection, options = {}) {
|
|
|
25753
25871
|
),
|
|
25754
25872
|
[selectedSymbols]
|
|
25755
25873
|
);
|
|
25756
|
-
const
|
|
25757
|
-
|
|
25758
|
-
);
|
|
25874
|
+
const liveMarkPrices = useBinanceMarkPriceStore((state) => state.markPrices);
|
|
25875
|
+
const subscribeSymbol = useBinanceMarkPriceStore((state) => state.subscribeSymbol);
|
|
25876
|
+
const unsubscribeSymbol = useBinanceMarkPriceStore((state) => state.unsubscribeSymbol);
|
|
25759
25877
|
const query = reactQuery.useQuery({
|
|
25760
25878
|
queryKey: ["symm", "chart-metadata", symbolsKey],
|
|
25761
25879
|
queryFn: async () => {
|
|
@@ -25783,36 +25901,25 @@ function useSymmTokenSelectionMetadata(selection, options = {}) {
|
|
|
25783
25901
|
});
|
|
25784
25902
|
react.useEffect(() => {
|
|
25785
25903
|
if (!enabled || isUnsupported || selectedSymbols.length === 0) {
|
|
25786
|
-
setLiveMarkPrices({});
|
|
25787
25904
|
return;
|
|
25788
25905
|
}
|
|
25789
|
-
|
|
25790
|
-
|
|
25791
|
-
|
|
25792
|
-
if (current[symbol] != null) {
|
|
25793
|
-
next[symbol] = current[symbol];
|
|
25794
|
-
}
|
|
25795
|
-
}
|
|
25796
|
-
return next;
|
|
25797
|
-
});
|
|
25798
|
-
const wsManager = getBinanceWsManager();
|
|
25799
|
-
const unsubscribes = Array.from(symbolToBinanceMap.entries()).map(
|
|
25800
|
-
([symbol, binanceSymbol]) => wsManager.subscribeMarkPrice(binanceSymbol, (data) => {
|
|
25801
|
-
setLiveMarkPrices((current) => {
|
|
25802
|
-
if (current[symbol] === data.markPrice) return current;
|
|
25803
|
-
return {
|
|
25804
|
-
...current,
|
|
25805
|
-
[symbol]: data.markPrice
|
|
25806
|
-
};
|
|
25807
|
-
});
|
|
25808
|
-
})
|
|
25906
|
+
const symbolEntries = Array.from(symbolToBinanceMap.entries());
|
|
25907
|
+
symbolEntries.forEach(
|
|
25908
|
+
([symbol, binanceSymbol]) => subscribeSymbol(symbol, binanceSymbol)
|
|
25809
25909
|
);
|
|
25810
25910
|
return () => {
|
|
25811
|
-
|
|
25812
|
-
|
|
25813
|
-
|
|
25911
|
+
symbolEntries.forEach(
|
|
25912
|
+
([symbol, binanceSymbol]) => unsubscribeSymbol(symbol, binanceSymbol)
|
|
25913
|
+
);
|
|
25814
25914
|
};
|
|
25815
|
-
}, [
|
|
25915
|
+
}, [
|
|
25916
|
+
enabled,
|
|
25917
|
+
isUnsupported,
|
|
25918
|
+
selectedSymbols.length,
|
|
25919
|
+
symbolToBinanceMap,
|
|
25920
|
+
subscribeSymbol,
|
|
25921
|
+
unsubscribeSymbol
|
|
25922
|
+
]);
|
|
25816
25923
|
return react.useMemo(() => {
|
|
25817
25924
|
const tickerSnapshots = query.data?.tickerSnapshots ?? {};
|
|
25818
25925
|
const longMeta = {};
|
|
@@ -26255,6 +26362,7 @@ function getSymmErrorMessage(error) {
|
|
|
26255
26362
|
exports.SymmProvider = SymmProvider;
|
|
26256
26363
|
exports.getSymmErrorMessage = getSymmErrorMessage;
|
|
26257
26364
|
exports.symmKeys = symmKeys;
|
|
26365
|
+
exports.useBinanceMarkPriceStore = useBinanceMarkPriceStore;
|
|
26258
26366
|
exports.useSymmAccountData = useSymmAccountData;
|
|
26259
26367
|
exports.useSymmAccountSummary = useSymmAccountSummary;
|
|
26260
26368
|
exports.useSymmAccounts = useSymmAccounts;
|
|
@@ -26263,6 +26371,7 @@ exports.useSymmAccountsLength = useSymmAccountsLength;
|
|
|
26263
26371
|
exports.useSymmAccountsWithPositions = useSymmAccountsWithPositions;
|
|
26264
26372
|
exports.useSymmApproval = useSymmApproval;
|
|
26265
26373
|
exports.useSymmAuth = useSymmAuth;
|
|
26374
|
+
exports.useSymmAuthStore = useSymmAuthStore;
|
|
26266
26375
|
exports.useSymmAvailableMargin = useSymmAvailableMargin;
|
|
26267
26376
|
exports.useSymmBalances = useSymmBalances;
|
|
26268
26377
|
exports.useSymmCancelClose = useSymmCancelClose;
|
|
@@ -26302,5 +26411,6 @@ exports.useSymmTwap = useSymmTwap;
|
|
|
26302
26411
|
exports.useSymmTwapOrder = useSymmTwapOrder;
|
|
26303
26412
|
exports.useSymmWithdraw = useSymmWithdraw;
|
|
26304
26413
|
exports.useSymmWs = useSymmWs;
|
|
26414
|
+
exports.useSymmWsStore = useSymmWsStore;
|
|
26305
26415
|
//# sourceMappingURL=index.js.map
|
|
26306
26416
|
//# sourceMappingURL=index.js.map
|